pci.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * linux/arch/mips/txx9/pci.c
  3. *
  4. * Based on linux/arch/mips/txx9/rbtx4927/setup.c,
  5. * linux/arch/mips/txx9/rbtx4938/setup.c,
  6. * and RBTX49xx patch from CELF patch archive.
  7. *
  8. * Copyright 2001-2005 MontaVista Software Inc.
  9. * Copyright (C) 1996, 97, 2001, 04 Ralf Baechle (ralf@linux-mips.org)
  10. * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file "COPYING" in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/io.h>
  19. #include <asm/txx9/generic.h>
  20. #include <asm/txx9/pci.h>
  21. #ifdef CONFIG_TOSHIBA_FPCIB0
  22. #include <linux/interrupt.h>
  23. #include <asm/i8259.h>
  24. #include <asm/txx9/smsc_fdc37m81x.h>
  25. #endif
  26. static int __init
  27. early_read_config_word(struct pci_controller *hose,
  28. int top_bus, int bus, int devfn, int offset, u16 *value)
  29. {
  30. struct pci_dev fake_dev;
  31. struct pci_bus fake_bus;
  32. fake_dev.bus = &fake_bus;
  33. fake_dev.sysdata = hose;
  34. fake_dev.devfn = devfn;
  35. fake_bus.number = bus;
  36. fake_bus.sysdata = hose;
  37. fake_bus.ops = hose->pci_ops;
  38. if (bus != top_bus)
  39. /* Fake a parent bus structure. */
  40. fake_bus.parent = &fake_bus;
  41. else
  42. fake_bus.parent = NULL;
  43. return pci_read_config_word(&fake_dev, offset, value);
  44. }
  45. int __init txx9_pci66_check(struct pci_controller *hose, int top_bus,
  46. int current_bus)
  47. {
  48. u32 pci_devfn;
  49. unsigned short vid;
  50. int cap66 = -1;
  51. u16 stat;
  52. /* It seems SLC90E66 needs some time after PCI reset... */
  53. mdelay(80);
  54. printk(KERN_INFO "PCI: Checking 66MHz capabilities...\n");
  55. for (pci_devfn = 0; pci_devfn < 0xff; pci_devfn++) {
  56. if (PCI_FUNC(pci_devfn))
  57. continue;
  58. if (early_read_config_word(hose, top_bus, current_bus,
  59. pci_devfn, PCI_VENDOR_ID, &vid) !=
  60. PCIBIOS_SUCCESSFUL)
  61. continue;
  62. if (vid == 0xffff)
  63. continue;
  64. /* check 66MHz capability */
  65. if (cap66 < 0)
  66. cap66 = 1;
  67. if (cap66) {
  68. early_read_config_word(hose, top_bus, current_bus,
  69. pci_devfn, PCI_STATUS, &stat);
  70. if (!(stat & PCI_STATUS_66MHZ)) {
  71. printk(KERN_DEBUG
  72. "PCI: %02x:%02x not 66MHz capable.\n",
  73. current_bus, pci_devfn);
  74. cap66 = 0;
  75. break;
  76. }
  77. }
  78. }
  79. return cap66 > 0;
  80. }
  81. static struct resource primary_pci_mem_res[2] = {
  82. { .name = "PCI MEM" },
  83. { .name = "PCI MMIO" },
  84. };
  85. static struct resource primary_pci_io_res = { .name = "PCI IO" };
  86. struct pci_controller txx9_primary_pcic = {
  87. .mem_resource = &primary_pci_mem_res[0],
  88. .io_resource = &primary_pci_io_res,
  89. };
  90. #ifdef CONFIG_64BIT
  91. int txx9_pci_mem_high __initdata = 1;
  92. #else
  93. int txx9_pci_mem_high __initdata;
  94. #endif
  95. /*
  96. * allocate pci_controller and resources.
  97. * mem_base, io_base: physical addresss. 0 for auto assignment.
  98. * mem_size and io_size means max size on auto assignment.
  99. * pcic must be &txx9_primary_pcic or NULL.
  100. */
  101. struct pci_controller *__init
  102. txx9_alloc_pci_controller(struct pci_controller *pcic,
  103. unsigned long mem_base, unsigned long mem_size,
  104. unsigned long io_base, unsigned long io_size)
  105. {
  106. struct pcic {
  107. struct pci_controller c;
  108. struct resource r_mem[2];
  109. struct resource r_io;
  110. } *new = NULL;
  111. int min_size = 0x10000;
  112. if (!pcic) {
  113. new = kzalloc(sizeof(*new), GFP_KERNEL);
  114. if (!new)
  115. return NULL;
  116. new->r_mem[0].name = "PCI mem";
  117. new->r_mem[1].name = "PCI mmio";
  118. new->r_io.name = "PCI io";
  119. new->c.mem_resource = new->r_mem;
  120. new->c.io_resource = &new->r_io;
  121. pcic = &new->c;
  122. } else
  123. BUG_ON(pcic != &txx9_primary_pcic);
  124. pcic->io_resource->flags = IORESOURCE_IO;
  125. /*
  126. * for auto assignment, first search a (big) region for PCI
  127. * MEM, then search a region for PCI IO.
  128. */
  129. if (mem_base) {
  130. pcic->mem_resource[0].start = mem_base;
  131. pcic->mem_resource[0].end = mem_base + mem_size - 1;
  132. if (request_resource(&iomem_resource, &pcic->mem_resource[0]))
  133. goto free_and_exit;
  134. } else {
  135. unsigned long min = 0, max = 0x20000000; /* low 512MB */
  136. if (!mem_size) {
  137. /* default size for auto assignment */
  138. if (txx9_pci_mem_high)
  139. mem_size = 0x20000000; /* mem:512M(max) */
  140. else
  141. mem_size = 0x08000000; /* mem:128M(max) */
  142. }
  143. if (txx9_pci_mem_high) {
  144. min = 0x20000000;
  145. max = 0xe0000000;
  146. }
  147. /* search free region for PCI MEM */
  148. for (; mem_size >= min_size; mem_size /= 2) {
  149. if (allocate_resource(&iomem_resource,
  150. &pcic->mem_resource[0],
  151. mem_size, min, max,
  152. mem_size, NULL, NULL) == 0)
  153. break;
  154. }
  155. if (mem_size < min_size)
  156. goto free_and_exit;
  157. }
  158. pcic->mem_resource[1].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  159. if (io_base) {
  160. pcic->mem_resource[1].start = io_base;
  161. pcic->mem_resource[1].end = io_base + io_size - 1;
  162. if (request_resource(&iomem_resource, &pcic->mem_resource[1]))
  163. goto release_and_exit;
  164. } else {
  165. if (!io_size)
  166. /* default size for auto assignment */
  167. io_size = 0x01000000; /* io:16M(max) */
  168. /* search free region for PCI IO in low 512MB */
  169. for (; io_size >= min_size; io_size /= 2) {
  170. if (allocate_resource(&iomem_resource,
  171. &pcic->mem_resource[1],
  172. io_size, 0, 0x20000000,
  173. io_size, NULL, NULL) == 0)
  174. break;
  175. }
  176. if (io_size < min_size)
  177. goto release_and_exit;
  178. io_base = pcic->mem_resource[1].start;
  179. }
  180. pcic->mem_resource[0].flags = IORESOURCE_MEM;
  181. if (pcic == &txx9_primary_pcic &&
  182. mips_io_port_base == (unsigned long)-1) {
  183. /* map ioport 0 to PCI I/O space address 0 */
  184. set_io_port_base(IO_BASE + pcic->mem_resource[1].start);
  185. pcic->io_resource->start = 0;
  186. pcic->io_offset = 0; /* busaddr == ioaddr */
  187. pcic->io_map_base = IO_BASE + pcic->mem_resource[1].start;
  188. } else {
  189. /* physaddr to ioaddr */
  190. pcic->io_resource->start =
  191. io_base - (mips_io_port_base - IO_BASE);
  192. pcic->io_offset = io_base - (mips_io_port_base - IO_BASE);
  193. pcic->io_map_base = mips_io_port_base;
  194. }
  195. pcic->io_resource->end = pcic->io_resource->start + io_size - 1;
  196. pcic->mem_offset = 0; /* busaddr == physaddr */
  197. printk(KERN_INFO "PCI: IO 0x%08llx-0x%08llx MEM 0x%08llx-0x%08llx\n",
  198. (unsigned long long)pcic->mem_resource[1].start,
  199. (unsigned long long)pcic->mem_resource[1].end,
  200. (unsigned long long)pcic->mem_resource[0].start,
  201. (unsigned long long)pcic->mem_resource[0].end);
  202. /* register_pci_controller() will request MEM resource */
  203. release_resource(&pcic->mem_resource[0]);
  204. return pcic;
  205. release_and_exit:
  206. release_resource(&pcic->mem_resource[0]);
  207. free_and_exit:
  208. kfree(new);
  209. printk(KERN_ERR "PCI: Failed to allocate resources.\n");
  210. return NULL;
  211. }
  212. static int __init
  213. txx9_arch_pci_init(void)
  214. {
  215. PCIBIOS_MIN_IO = 0x8000; /* reseve legacy I/O space */
  216. return 0;
  217. }
  218. arch_initcall(txx9_arch_pci_init);
  219. /* IRQ/IDSEL mapping */
  220. int txx9_pci_option =
  221. #ifdef CONFIG_PICMG_PCI_BACKPLANE_DEFAULT
  222. TXX9_PCI_OPT_PICMG |
  223. #endif
  224. TXX9_PCI_OPT_CLK_AUTO;
  225. enum txx9_pci_err_action txx9_pci_err_action = TXX9_PCI_ERR_REPORT;
  226. #ifdef CONFIG_TOSHIBA_FPCIB0
  227. static irqreturn_t i8259_interrupt(int irq, void *dev_id)
  228. {
  229. int isairq;
  230. isairq = i8259_irq();
  231. if (unlikely(isairq <= I8259A_IRQ_BASE))
  232. return IRQ_NONE;
  233. generic_handle_irq(isairq);
  234. return IRQ_HANDLED;
  235. }
  236. static int __init
  237. txx9_i8259_irq_setup(int irq)
  238. {
  239. int err;
  240. init_i8259_irqs();
  241. err = request_irq(irq, &i8259_interrupt, IRQF_DISABLED|IRQF_SHARED,
  242. "cascade(i8259)", (void *)(long)irq);
  243. if (!err)
  244. printk(KERN_INFO "PCI-ISA bridge PIC (irq %d)\n", irq);
  245. return err;
  246. }
  247. static void __init quirk_slc90e66_bridge(struct pci_dev *dev)
  248. {
  249. int irq; /* PCI/ISA Bridge interrupt */
  250. u8 reg_64;
  251. u32 reg_b0;
  252. u8 reg_e1;
  253. irq = pcibios_map_irq(dev, PCI_SLOT(dev->devfn), 1); /* INTA */
  254. if (!irq)
  255. return;
  256. txx9_i8259_irq_setup(irq);
  257. pci_read_config_byte(dev, 0x64, &reg_64);
  258. pci_read_config_dword(dev, 0xb0, &reg_b0);
  259. pci_read_config_byte(dev, 0xe1, &reg_e1);
  260. /* serial irq control */
  261. reg_64 = 0xd0;
  262. /* serial irq pin */
  263. reg_b0 |= 0x00010000;
  264. /* ide irq on isa14 */
  265. reg_e1 &= 0xf0;
  266. reg_e1 |= 0x0d;
  267. pci_write_config_byte(dev, 0x64, reg_64);
  268. pci_write_config_dword(dev, 0xb0, reg_b0);
  269. pci_write_config_byte(dev, 0xe1, reg_e1);
  270. smsc_fdc37m81x_init(0x3f0);
  271. smsc_fdc37m81x_config_beg();
  272. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_DNUM,
  273. SMSC_FDC37M81X_KBD);
  274. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_INT, 1);
  275. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_INT2, 12);
  276. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_ACTIVE,
  277. 1);
  278. smsc_fdc37m81x_config_end();
  279. }
  280. static void quirk_slc90e66_ide(struct pci_dev *dev)
  281. {
  282. unsigned char dat;
  283. int regs[2] = {0x41, 0x43};
  284. int i;
  285. /* SMSC SLC90E66 IDE uses irq 14, 15 (default) */
  286. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 14);
  287. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &dat);
  288. printk(KERN_INFO "PCI: %s: IRQ %02x", pci_name(dev), dat);
  289. /* enable SMSC SLC90E66 IDE */
  290. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  291. pci_read_config_byte(dev, regs[i], &dat);
  292. pci_write_config_byte(dev, regs[i], dat | 0x80);
  293. pci_read_config_byte(dev, regs[i], &dat);
  294. printk(KERN_CONT " IDETIM%d %02x", i, dat);
  295. }
  296. pci_read_config_byte(dev, 0x5c, &dat);
  297. /*
  298. * !!! DO NOT REMOVE THIS COMMENT IT IS REQUIRED BY SMSC !!!
  299. *
  300. * This line of code is intended to provide the user with a work
  301. * around solution to the anomalies cited in SMSC's anomaly sheet
  302. * entitled, "SLC90E66 Functional Rev.J_0.1 Anomalies"".
  303. *
  304. * !!! DO NOT REMOVE THIS COMMENT IT IS REQUIRED BY SMSC !!!
  305. */
  306. dat |= 0x01;
  307. pci_write_config_byte(dev, regs[i], dat);
  308. pci_read_config_byte(dev, 0x5c, &dat);
  309. printk(KERN_CONT " REG5C %02x", dat);
  310. printk(KERN_CONT "\n");
  311. }
  312. #endif /* CONFIG_TOSHIBA_FPCIB0 */
  313. static void final_fixup(struct pci_dev *dev)
  314. {
  315. unsigned char bist;
  316. /* Do build-in self test */
  317. if (pci_read_config_byte(dev, PCI_BIST, &bist) == PCIBIOS_SUCCESSFUL &&
  318. (bist & PCI_BIST_CAPABLE)) {
  319. unsigned long timeout;
  320. pci_set_power_state(dev, PCI_D0);
  321. printk(KERN_INFO "PCI: %s BIST...", pci_name(dev));
  322. pci_write_config_byte(dev, PCI_BIST, PCI_BIST_START);
  323. timeout = jiffies + HZ * 2; /* timeout after 2 sec */
  324. do {
  325. pci_read_config_byte(dev, PCI_BIST, &bist);
  326. if (time_after(jiffies, timeout))
  327. break;
  328. } while (bist & PCI_BIST_START);
  329. if (bist & (PCI_BIST_CODE_MASK | PCI_BIST_START))
  330. printk(KERN_CONT "failed. (0x%x)\n", bist);
  331. else
  332. printk(KERN_CONT "OK.\n");
  333. }
  334. }
  335. #ifdef CONFIG_TOSHIBA_FPCIB0
  336. #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460
  337. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0,
  338. quirk_slc90e66_bridge);
  339. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_1,
  340. quirk_slc90e66_ide);
  341. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_1,
  342. quirk_slc90e66_ide);
  343. #endif
  344. DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, final_fixup);
  345. DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, final_fixup);
  346. int pcibios_plat_dev_init(struct pci_dev *dev)
  347. {
  348. return 0;
  349. }
  350. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  351. {
  352. return txx9_board_vec->pci_map_irq(dev, slot, pin);
  353. }
  354. char * (*txx9_board_pcibios_setup)(char *str) __devinitdata;
  355. char *__devinit txx9_pcibios_setup(char *str)
  356. {
  357. if (txx9_board_pcibios_setup && !txx9_board_pcibios_setup(str))
  358. return NULL;
  359. if (!strcmp(str, "picmg")) {
  360. /* PICMG compliant backplane (TOSHIBA JMB-PICMG-ATX
  361. (5V or 3.3V), JMB-PICMG-L2 (5V only), etc.) */
  362. txx9_pci_option |= TXX9_PCI_OPT_PICMG;
  363. return NULL;
  364. } else if (!strcmp(str, "nopicmg")) {
  365. /* non-PICMG compliant backplane (TOSHIBA
  366. RBHBK4100,RBHBK4200, Interface PCM-PCM05, etc.) */
  367. txx9_pci_option &= ~TXX9_PCI_OPT_PICMG;
  368. return NULL;
  369. } else if (!strncmp(str, "clk=", 4)) {
  370. char *val = str + 4;
  371. txx9_pci_option &= ~TXX9_PCI_OPT_CLK_MASK;
  372. if (strcmp(val, "33") == 0)
  373. txx9_pci_option |= TXX9_PCI_OPT_CLK_33;
  374. else if (strcmp(val, "66") == 0)
  375. txx9_pci_option |= TXX9_PCI_OPT_CLK_66;
  376. else /* "auto" */
  377. txx9_pci_option |= TXX9_PCI_OPT_CLK_AUTO;
  378. return NULL;
  379. } else if (!strncmp(str, "err=", 4)) {
  380. if (!strcmp(str + 4, "panic"))
  381. txx9_pci_err_action = TXX9_PCI_ERR_PANIC;
  382. else if (!strcmp(str + 4, "ignore"))
  383. txx9_pci_err_action = TXX9_PCI_ERR_IGNORE;
  384. return NULL;
  385. }
  386. return str;
  387. }