pci.c 12 KB

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