pci.c 12 KB

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