pci.c 9.3 KB

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