pci.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * MPC86XX pci setup code
  3. *
  4. * Recode: ZHANG WEI <wei.zhang@freescale.com>
  5. * Initial author: Xianghua Xiao <x.xiao@freescale.com>
  6. *
  7. * Copyright 2006 Freescale Semiconductor Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/types.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/serial.h>
  19. #include <asm/system.h>
  20. #include <asm/atomic.h>
  21. #include <asm/io.h>
  22. #include <asm/prom.h>
  23. #include <asm/immap_86xx.h>
  24. #include <asm/pci-bridge.h>
  25. #include <sysdev/fsl_soc.h>
  26. #include "mpc86xx.h"
  27. #undef DEBUG
  28. #ifdef DEBUG
  29. #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args)
  30. #else
  31. #define DBG(fmt, args...)
  32. #endif
  33. struct pcie_outbound_window_regs {
  34. uint pexotar; /* 0x.0 - PCI Express outbound translation address register */
  35. uint pexotear; /* 0x.4 - PCI Express outbound translation extended address register */
  36. uint pexowbar; /* 0x.8 - PCI Express outbound window base address register */
  37. char res1[4];
  38. uint pexowar; /* 0x.10 - PCI Express outbound window attributes register */
  39. char res2[12];
  40. };
  41. struct pcie_inbound_window_regs {
  42. uint pexitar; /* 0x.0 - PCI Express inbound translation address register */
  43. char res1[4];
  44. uint pexiwbar; /* 0x.8 - PCI Express inbound window base address register */
  45. uint pexiwbear; /* 0x.c - PCI Express inbound window base extended address register */
  46. uint pexiwar; /* 0x.10 - PCI Express inbound window attributes register */
  47. char res2[12];
  48. };
  49. static void __init setup_pcie_atmu(struct pci_controller *hose, struct resource *rsrc)
  50. {
  51. volatile struct ccsr_pex *pcie;
  52. volatile struct pcie_outbound_window_regs *pcieow;
  53. volatile struct pcie_inbound_window_regs *pcieiw;
  54. int i = 0;
  55. DBG("PCIE memory map start 0x%x, size 0x%x\n", rsrc->start,
  56. rsrc->end - rsrc->start + 1);
  57. pcie = ioremap(rsrc->start, rsrc->end - rsrc->start + 1);
  58. /* Disable all windows (except pexowar0 since its ignored) */
  59. pcie->pexowar1 = 0;
  60. pcie->pexowar2 = 0;
  61. pcie->pexowar3 = 0;
  62. pcie->pexowar4 = 0;
  63. pcie->pexiwar1 = 0;
  64. pcie->pexiwar2 = 0;
  65. pcie->pexiwar3 = 0;
  66. pcieow = (struct pcie_outbound_window_regs *)&pcie->pexotar1;
  67. pcieiw = (struct pcie_inbound_window_regs *)&pcie->pexitar1;
  68. /* Setup outbound MEM window */
  69. for(i = 0; i < 3; i++)
  70. if (hose->mem_resources[i].flags & IORESOURCE_MEM){
  71. DBG("PCIE MEM resource start 0x%08x, size 0x%08x.\n",
  72. hose->mem_resources[i].start,
  73. hose->mem_resources[i].end
  74. - hose->mem_resources[i].start + 1);
  75. pcieow->pexotar = (hose->mem_resources[i].start) >> 12
  76. & 0x000fffff;
  77. pcieow->pexotear = 0;
  78. pcieow->pexowbar = (hose->mem_resources[i].start) >> 12
  79. & 0x000fffff;
  80. /* Enable, Mem R/W */
  81. pcieow->pexowar = 0x80044000 |
  82. (__ilog2(hose->mem_resources[i].end
  83. - hose->mem_resources[i].start + 1)
  84. - 1);
  85. pcieow++;
  86. }
  87. /* Setup outbound IO window */
  88. if (hose->io_resource.flags & IORESOURCE_IO){
  89. DBG("PCIE IO resource start 0x%08x, size 0x%08x, phy base 0x%08x.\n",
  90. hose->io_resource.start,
  91. hose->io_resource.end - hose->io_resource.start + 1,
  92. hose->io_base_phys);
  93. pcieow->pexotar = (hose->io_resource.start) >> 12 & 0x000fffff;
  94. pcieow->pexotear = 0;
  95. pcieow->pexowbar = (hose->io_base_phys) >> 12 & 0x000fffff;
  96. /* Enable, IO R/W */
  97. pcieow->pexowar = 0x80088000 | (__ilog2(hose->io_resource.end
  98. - hose->io_resource.start + 1) - 1);
  99. }
  100. /* Setup 2G inbound Memory Window @ 0 */
  101. pcieiw->pexitar = 0x00000000;
  102. pcieiw->pexiwbar = 0x00000000;
  103. /* Enable, Prefetch, Local Mem, Snoop R/W, 2G */
  104. pcieiw->pexiwar = 0xa0f5501e;
  105. }
  106. static void __init
  107. mpc86xx_setup_pcie(struct pci_controller *hose, u32 pcie_offset, u32 pcie_size)
  108. {
  109. volatile struct ccsr_pex *pcie;
  110. u16 cmd;
  111. unsigned int temps;
  112. DBG("PCIE host controller register offset 0x%08x, size 0x%08x.\n",
  113. pcie_offset, pcie_size);
  114. pcie = ioremap(pcie_offset, pcie_size);
  115. early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
  116. cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  117. | PCI_COMMAND_IO;
  118. early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
  119. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  120. /* PCIE Bus, Fix the MPC8641D host bridge's location to bus 0xFF. */
  121. early_read_config_dword(hose, 0, 0, PCI_PRIMARY_BUS, &temps);
  122. temps = (temps & 0xff000000) | (0xff) | (0x0 << 8) | (0xfe << 16);
  123. early_write_config_dword(hose, 0, 0, PCI_PRIMARY_BUS, temps);
  124. }
  125. int __init add_bridge(struct device_node *dev)
  126. {
  127. int len;
  128. struct pci_controller *hose;
  129. struct resource rsrc;
  130. int *bus_range;
  131. int has_address = 0;
  132. int primary = 0;
  133. DBG("Adding PCIE host bridge %s\n", dev->full_name);
  134. /* Fetch host bridge registers address */
  135. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  136. /* Get bus range if any */
  137. bus_range = (int *) get_property(dev, "bus-range", &len);
  138. if (bus_range == NULL || len < 2 * sizeof(int))
  139. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  140. " bus 0\n", dev->full_name);
  141. hose = pcibios_alloc_controller();
  142. if (!hose)
  143. return -ENOMEM;
  144. hose->arch_data = dev;
  145. hose->set_cfg_type = 1;
  146. /* last_busno = 0xfe cause by MPC8641 PCIE bug */
  147. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  148. hose->last_busno = bus_range ? bus_range[1] : 0xfe;
  149. setup_indirect_pcie(hose, rsrc.start, rsrc.start + 0x4);
  150. /* Setup the PCIE host controller. */
  151. mpc86xx_setup_pcie(hose, rsrc.start, rsrc.end - rsrc.start + 1);
  152. if ((rsrc.start & 0xfffff) == 0x8000)
  153. primary = 1;
  154. printk(KERN_INFO "Found MPC86xx PCIE host bridge at 0x%08lx. "
  155. "Firmware bus number: %d->%d\n",
  156. rsrc.start, hose->first_busno, hose->last_busno);
  157. DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  158. hose, hose->cfg_addr, hose->cfg_data);
  159. /* Interpret the "ranges" property */
  160. /* This also maps the I/O region and sets isa_io/mem_base */
  161. pci_process_bridge_OF_ranges(hose, dev, primary);
  162. /* Setup PEX window registers */
  163. setup_pcie_atmu(hose, &rsrc);
  164. return 0;
  165. }
  166. static void __devinit quirk_ali1575(struct pci_dev *dev)
  167. {
  168. unsigned short temp;
  169. /*
  170. * ALI1575 interrupts route table setup:
  171. *
  172. * IRQ pin IRQ#
  173. * PIRQA ---- 3
  174. * PIRQB ---- 4
  175. * PIRQC ---- 5
  176. * PIRQD ---- 6
  177. * PIRQE ---- 9
  178. * PIRQF ---- 10
  179. * PIRQG ---- 11
  180. * PIRQH ---- 12
  181. *
  182. * interrupts for PCI slot0 -- PIRQA / PIRQB / PIRQC / PIRQD
  183. * PCI slot1 -- PIRQB / PIRQC / PIRQD / PIRQA
  184. */
  185. pci_write_config_dword(dev, 0x48, 0xb9317542);
  186. /* USB 1.1 OHCI controller 1, interrupt: PIRQE */
  187. pci_write_config_byte(dev, 0x86, 0x0c);
  188. /* USB 1.1 OHCI controller 2, interrupt: PIRQF */
  189. pci_write_config_byte(dev, 0x87, 0x0d);
  190. /* USB 1.1 OHCI controller 3, interrupt: PIRQH */
  191. pci_write_config_byte(dev, 0x88, 0x0f);
  192. /* USB 2.0 controller, interrupt: PIRQ7 */
  193. pci_write_config_byte(dev, 0x74, 0x06);
  194. /* Audio controller, interrupt: PIRQE */
  195. pci_write_config_byte(dev, 0x8a, 0x0c);
  196. /* Modem controller, interrupt: PIRQF */
  197. pci_write_config_byte(dev, 0x8b, 0x0d);
  198. /* HD audio controller, interrupt: PIRQG */
  199. pci_write_config_byte(dev, 0x8c, 0x0e);
  200. /* Serial ATA interrupt: PIRQD */
  201. pci_write_config_byte(dev, 0x8d, 0x0b);
  202. /* SMB interrupt: PIRQH */
  203. pci_write_config_byte(dev, 0x8e, 0x0f);
  204. /* PMU ACPI SCI interrupt: PIRQH */
  205. pci_write_config_byte(dev, 0x8f, 0x0f);
  206. /* Primary PATA IDE IRQ: 14
  207. * Secondary PATA IDE IRQ: 15
  208. */
  209. pci_write_config_byte(dev, 0x44, 0x3d);
  210. pci_write_config_byte(dev, 0x75, 0x0f);
  211. /* Set IRQ14 and IRQ15 to legacy IRQs */
  212. pci_read_config_word(dev, 0x46, &temp);
  213. temp |= 0xc000;
  214. pci_write_config_word(dev, 0x46, temp);
  215. /* Set i8259 interrupt trigger
  216. * IRQ 3: Level
  217. * IRQ 4: Level
  218. * IRQ 5: Level
  219. * IRQ 6: Level
  220. * IRQ 7: Level
  221. * IRQ 9: Level
  222. * IRQ 10: Level
  223. * IRQ 11: Level
  224. * IRQ 12: Level
  225. * IRQ 14: Edge
  226. * IRQ 15: Edge
  227. */
  228. outb(0xfa, 0x4d0);
  229. outb(0x1e, 0x4d1);
  230. }
  231. static void __devinit quirk_uli5288(struct pci_dev *dev)
  232. {
  233. unsigned char c;
  234. pci_read_config_byte(dev,0x83,&c);
  235. c |= 0x80;
  236. pci_write_config_byte(dev, 0x83, c);
  237. pci_write_config_byte(dev, 0x09, 0x01);
  238. pci_write_config_byte(dev, 0x0a, 0x06);
  239. pci_read_config_byte(dev,0x83,&c);
  240. c &= 0x7f;
  241. pci_write_config_byte(dev, 0x83, c);
  242. pci_read_config_byte(dev,0x84,&c);
  243. c |= 0x01;
  244. pci_write_config_byte(dev, 0x84, c);
  245. }
  246. static void __devinit quirk_uli5229(struct pci_dev *dev)
  247. {
  248. unsigned short temp;
  249. pci_write_config_word(dev, 0x04, 0x0405);
  250. pci_read_config_word(dev, 0x4a, &temp);
  251. temp |= 0x1000;
  252. pci_write_config_word(dev, 0x4a, temp);
  253. }
  254. static void __devinit early_uli5249(struct pci_dev *dev)
  255. {
  256. unsigned char temp;
  257. pci_write_config_word(dev, 0x04, 0x0007);
  258. pci_read_config_byte(dev, 0x7c, &temp);
  259. pci_write_config_byte(dev, 0x7c, 0x80);
  260. pci_write_config_byte(dev, 0x09, 0x01);
  261. pci_write_config_byte(dev, 0x7c, temp);
  262. dev->class |= 0x1;
  263. }
  264. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_ali1575);
  265. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
  266. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
  267. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);