pci.c 12 KB

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