pci.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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 address. 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 %pR MEM %pR\n",
  199. &pcic->mem_resource[1], &pcic->mem_resource[0]);
  200. /* register_pci_controller() will request MEM resource */
  201. release_resource(&pcic->mem_resource[0]);
  202. return pcic;
  203. release_and_exit:
  204. release_resource(&pcic->mem_resource[0]);
  205. free_and_exit:
  206. kfree(new);
  207. printk(KERN_ERR "PCI: Failed to allocate resources.\n");
  208. return NULL;
  209. }
  210. static int __init
  211. txx9_arch_pci_init(void)
  212. {
  213. PCIBIOS_MIN_IO = 0x8000; /* reseve legacy I/O space */
  214. return 0;
  215. }
  216. arch_initcall(txx9_arch_pci_init);
  217. /* IRQ/IDSEL mapping */
  218. int txx9_pci_option =
  219. #ifdef CONFIG_PICMG_PCI_BACKPLANE_DEFAULT
  220. TXX9_PCI_OPT_PICMG |
  221. #endif
  222. TXX9_PCI_OPT_CLK_AUTO;
  223. enum txx9_pci_err_action txx9_pci_err_action = TXX9_PCI_ERR_REPORT;
  224. #ifdef CONFIG_TOSHIBA_FPCIB0
  225. static irqreturn_t i8259_interrupt(int irq, void *dev_id)
  226. {
  227. int isairq;
  228. isairq = i8259_irq();
  229. if (unlikely(isairq <= I8259A_IRQ_BASE))
  230. return IRQ_NONE;
  231. generic_handle_irq(isairq);
  232. return IRQ_HANDLED;
  233. }
  234. static int __init
  235. txx9_i8259_irq_setup(int irq)
  236. {
  237. int err;
  238. init_i8259_irqs();
  239. err = request_irq(irq, &i8259_interrupt, IRQF_DISABLED|IRQF_SHARED,
  240. "cascade(i8259)", (void *)(long)irq);
  241. if (!err)
  242. printk(KERN_INFO "PCI-ISA bridge PIC (irq %d)\n", irq);
  243. return err;
  244. }
  245. static void __init quirk_slc90e66_bridge(struct pci_dev *dev)
  246. {
  247. int irq; /* PCI/ISA Bridge interrupt */
  248. u8 reg_64;
  249. u32 reg_b0;
  250. u8 reg_e1;
  251. irq = pcibios_map_irq(dev, PCI_SLOT(dev->devfn), 1); /* INTA */
  252. if (!irq)
  253. return;
  254. txx9_i8259_irq_setup(irq);
  255. pci_read_config_byte(dev, 0x64, &reg_64);
  256. pci_read_config_dword(dev, 0xb0, &reg_b0);
  257. pci_read_config_byte(dev, 0xe1, &reg_e1);
  258. /* serial irq control */
  259. reg_64 = 0xd0;
  260. /* serial irq pin */
  261. reg_b0 |= 0x00010000;
  262. /* ide irq on isa14 */
  263. reg_e1 &= 0xf0;
  264. reg_e1 |= 0x0d;
  265. pci_write_config_byte(dev, 0x64, reg_64);
  266. pci_write_config_dword(dev, 0xb0, reg_b0);
  267. pci_write_config_byte(dev, 0xe1, reg_e1);
  268. smsc_fdc37m81x_init(0x3f0);
  269. smsc_fdc37m81x_config_beg();
  270. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_DNUM,
  271. SMSC_FDC37M81X_KBD);
  272. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_INT, 1);
  273. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_INT2, 12);
  274. smsc_fdc37m81x_config_set(SMSC_FDC37M81X_ACTIVE,
  275. 1);
  276. smsc_fdc37m81x_config_end();
  277. }
  278. static void quirk_slc90e66_ide(struct pci_dev *dev)
  279. {
  280. unsigned char dat;
  281. int regs[2] = {0x41, 0x43};
  282. int i;
  283. /* SMSC SLC90E66 IDE uses irq 14, 15 (default) */
  284. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 14);
  285. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &dat);
  286. printk(KERN_INFO "PCI: %s: IRQ %02x", pci_name(dev), dat);
  287. /* enable SMSC SLC90E66 IDE */
  288. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  289. pci_read_config_byte(dev, regs[i], &dat);
  290. pci_write_config_byte(dev, regs[i], dat | 0x80);
  291. pci_read_config_byte(dev, regs[i], &dat);
  292. printk(KERN_CONT " IDETIM%d %02x", i, dat);
  293. }
  294. pci_read_config_byte(dev, 0x5c, &dat);
  295. /*
  296. * !!! DO NOT REMOVE THIS COMMENT IT IS REQUIRED BY SMSC !!!
  297. *
  298. * This line of code is intended to provide the user with a work
  299. * around solution to the anomalies cited in SMSC's anomaly sheet
  300. * entitled, "SLC90E66 Functional Rev.J_0.1 Anomalies"".
  301. *
  302. * !!! DO NOT REMOVE THIS COMMENT IT IS REQUIRED BY SMSC !!!
  303. */
  304. dat |= 0x01;
  305. pci_write_config_byte(dev, regs[i], dat);
  306. pci_read_config_byte(dev, 0x5c, &dat);
  307. printk(KERN_CONT " REG5C %02x", dat);
  308. printk(KERN_CONT "\n");
  309. }
  310. #endif /* CONFIG_TOSHIBA_FPCIB0 */
  311. static void tc35815_fixup(struct pci_dev *dev)
  312. {
  313. /* This device may have PM registers but not they are not suported. */
  314. if (dev->pm_cap) {
  315. dev_info(&dev->dev, "PM disabled\n");
  316. dev->pm_cap = 0;
  317. }
  318. }
  319. static void final_fixup(struct pci_dev *dev)
  320. {
  321. unsigned char bist;
  322. /* Do build-in self test */
  323. if (pci_read_config_byte(dev, PCI_BIST, &bist) == PCIBIOS_SUCCESSFUL &&
  324. (bist & PCI_BIST_CAPABLE)) {
  325. unsigned long timeout;
  326. pci_set_power_state(dev, PCI_D0);
  327. printk(KERN_INFO "PCI: %s BIST...", pci_name(dev));
  328. pci_write_config_byte(dev, PCI_BIST, PCI_BIST_START);
  329. timeout = jiffies + HZ * 2; /* timeout after 2 sec */
  330. do {
  331. pci_read_config_byte(dev, PCI_BIST, &bist);
  332. if (time_after(jiffies, timeout))
  333. break;
  334. } while (bist & PCI_BIST_START);
  335. if (bist & (PCI_BIST_CODE_MASK | PCI_BIST_START))
  336. printk(KERN_CONT "failed. (0x%x)\n", bist);
  337. else
  338. printk(KERN_CONT "OK.\n");
  339. }
  340. }
  341. #ifdef CONFIG_TOSHIBA_FPCIB0
  342. #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460
  343. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0,
  344. quirk_slc90e66_bridge);
  345. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_1,
  346. quirk_slc90e66_ide);
  347. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_1,
  348. quirk_slc90e66_ide);
  349. #endif
  350. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TOSHIBA_2,
  351. PCI_DEVICE_ID_TOSHIBA_TC35815_NWU, tc35815_fixup);
  352. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TOSHIBA_2,
  353. PCI_DEVICE_ID_TOSHIBA_TC35815_TX4939, tc35815_fixup);
  354. DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, final_fixup);
  355. DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, final_fixup);
  356. int pcibios_plat_dev_init(struct pci_dev *dev)
  357. {
  358. return 0;
  359. }
  360. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  361. {
  362. return txx9_board_vec->pci_map_irq(dev, slot, pin);
  363. }
  364. char * (*txx9_board_pcibios_setup)(char *str) __devinitdata;
  365. char *__devinit txx9_pcibios_setup(char *str)
  366. {
  367. if (txx9_board_pcibios_setup && !txx9_board_pcibios_setup(str))
  368. return NULL;
  369. if (!strcmp(str, "picmg")) {
  370. /* PICMG compliant backplane (TOSHIBA JMB-PICMG-ATX
  371. (5V or 3.3V), JMB-PICMG-L2 (5V only), etc.) */
  372. txx9_pci_option |= TXX9_PCI_OPT_PICMG;
  373. return NULL;
  374. } else if (!strcmp(str, "nopicmg")) {
  375. /* non-PICMG compliant backplane (TOSHIBA
  376. RBHBK4100,RBHBK4200, Interface PCM-PCM05, etc.) */
  377. txx9_pci_option &= ~TXX9_PCI_OPT_PICMG;
  378. return NULL;
  379. } else if (!strncmp(str, "clk=", 4)) {
  380. char *val = str + 4;
  381. txx9_pci_option &= ~TXX9_PCI_OPT_CLK_MASK;
  382. if (strcmp(val, "33") == 0)
  383. txx9_pci_option |= TXX9_PCI_OPT_CLK_33;
  384. else if (strcmp(val, "66") == 0)
  385. txx9_pci_option |= TXX9_PCI_OPT_CLK_66;
  386. else /* "auto" */
  387. txx9_pci_option |= TXX9_PCI_OPT_CLK_AUTO;
  388. return NULL;
  389. } else if (!strncmp(str, "err=", 4)) {
  390. if (!strcmp(str + 4, "panic"))
  391. txx9_pci_err_action = TXX9_PCI_ERR_PANIC;
  392. else if (!strcmp(str + 4, "ignore"))
  393. txx9_pci_err_action = TXX9_PCI_ERR_IGNORE;
  394. return NULL;
  395. }
  396. return str;
  397. }