fsl_uli1575.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * ULI M1575 setup code - specific to Freescale boards
  3. *
  4. * Copyright 2007 Freescale Semiconductor Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/mc146818rtc.h>
  16. #include <asm/system.h>
  17. #include <asm/pci-bridge.h>
  18. #define ULI_PIRQA 0x08
  19. #define ULI_PIRQB 0x09
  20. #define ULI_PIRQC 0x0a
  21. #define ULI_PIRQD 0x0b
  22. #define ULI_PIRQE 0x0c
  23. #define ULI_PIRQF 0x0d
  24. #define ULI_PIRQG 0x0e
  25. #define ULI_8259_NONE 0x00
  26. #define ULI_8259_IRQ1 0x08
  27. #define ULI_8259_IRQ3 0x02
  28. #define ULI_8259_IRQ4 0x04
  29. #define ULI_8259_IRQ5 0x05
  30. #define ULI_8259_IRQ6 0x07
  31. #define ULI_8259_IRQ7 0x06
  32. #define ULI_8259_IRQ9 0x01
  33. #define ULI_8259_IRQ10 0x03
  34. #define ULI_8259_IRQ11 0x09
  35. #define ULI_8259_IRQ12 0x0b
  36. #define ULI_8259_IRQ14 0x0d
  37. #define ULI_8259_IRQ15 0x0f
  38. u8 uli_pirq_to_irq[8] = {
  39. ULI_8259_IRQ9, /* PIRQA */
  40. ULI_8259_IRQ10, /* PIRQB */
  41. ULI_8259_IRQ11, /* PIRQC */
  42. ULI_8259_IRQ12, /* PIRQD */
  43. ULI_8259_IRQ5, /* PIRQE */
  44. ULI_8259_IRQ6, /* PIRQF */
  45. ULI_8259_IRQ7, /* PIRQG */
  46. ULI_8259_NONE, /* PIRQH */
  47. };
  48. /* Bridge */
  49. static void __devinit early_uli5249(struct pci_dev *dev)
  50. {
  51. unsigned char temp;
  52. if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
  53. !machine_is(mpc8572_ds))
  54. return;
  55. pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO |
  56. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  57. /* read/write lock */
  58. pci_read_config_byte(dev, 0x7c, &temp);
  59. pci_write_config_byte(dev, 0x7c, 0x80);
  60. /* set as P2P bridge */
  61. pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
  62. dev->class |= 0x1;
  63. /* restore lock */
  64. pci_write_config_byte(dev, 0x7c, temp);
  65. }
  66. static void __devinit quirk_uli1575(struct pci_dev *dev)
  67. {
  68. int i;
  69. if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
  70. !machine_is(mpc8572_ds))
  71. return;
  72. /*
  73. * ULI1575 interrupts route setup
  74. */
  75. /* ULI1575 IRQ mapping conf register maps PIRQx to IRQn */
  76. for (i = 0; i < 4; i++) {
  77. u8 val = uli_pirq_to_irq[i*2] | (uli_pirq_to_irq[i*2+1] << 4);
  78. pci_write_config_byte(dev, 0x48 + i, val);
  79. }
  80. /* USB 1.1 OHCI controller 1: dev 28, func 0 - IRQ12 */
  81. pci_write_config_byte(dev, 0x86, ULI_PIRQD);
  82. /* USB 1.1 OHCI controller 2: dev 28, func 1 - IRQ9 */
  83. pci_write_config_byte(dev, 0x87, ULI_PIRQA);
  84. /* USB 1.1 OHCI controller 3: dev 28, func 2 - IRQ10 */
  85. pci_write_config_byte(dev, 0x88, ULI_PIRQB);
  86. /* Lan controller: dev 27, func 0 - IRQ6 */
  87. pci_write_config_byte(dev, 0x89, ULI_PIRQF);
  88. /* AC97 Audio controller: dev 29, func 0 - IRQ6 */
  89. pci_write_config_byte(dev, 0x8a, ULI_PIRQF);
  90. /* Modem controller: dev 29, func 1 - IRQ6 */
  91. pci_write_config_byte(dev, 0x8b, ULI_PIRQF);
  92. /* HD Audio controller: dev 29, func 2 - IRQ6 */
  93. pci_write_config_byte(dev, 0x8c, ULI_PIRQF);
  94. /* SATA controller: dev 31, func 1 - IRQ5 */
  95. pci_write_config_byte(dev, 0x8d, ULI_PIRQE);
  96. /* SMB interrupt: dev 30, func 1 - IRQ7 */
  97. pci_write_config_byte(dev, 0x8e, ULI_PIRQG);
  98. /* PMU ACPI SCI interrupt: dev 30, func 2 - IRQ7 */
  99. pci_write_config_byte(dev, 0x8f, ULI_PIRQG);
  100. /* USB 2.0 controller: dev 28, func 3 */
  101. pci_write_config_byte(dev, 0x74, ULI_8259_IRQ11);
  102. /* Primary PATA IDE IRQ: 14
  103. * Secondary PATA IDE IRQ: 15
  104. */
  105. pci_write_config_byte(dev, 0x44, 0x30 | ULI_8259_IRQ14);
  106. pci_write_config_byte(dev, 0x75, ULI_8259_IRQ15);
  107. }
  108. static void __devinit quirk_final_uli1575(struct pci_dev *dev)
  109. {
  110. /* Set i8259 interrupt trigger
  111. * IRQ 3: Level
  112. * IRQ 4: Level
  113. * IRQ 5: Level
  114. * IRQ 6: Level
  115. * IRQ 7: Level
  116. * IRQ 9: Level
  117. * IRQ 10: Level
  118. * IRQ 11: Level
  119. * IRQ 12: Level
  120. * IRQ 14: Edge
  121. * IRQ 15: Edge
  122. */
  123. if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
  124. !machine_is(mpc8572_ds))
  125. return;
  126. outb(0xfa, 0x4d0);
  127. outb(0x1e, 0x4d1);
  128. /* setup RTC */
  129. CMOS_WRITE(RTC_SET, RTC_CONTROL);
  130. CMOS_WRITE(RTC_24H, RTC_CONTROL);
  131. /* ensure month, date, and week alarm fields are ignored */
  132. CMOS_WRITE(0, RTC_VALID);
  133. outb_p(0x7c, 0x72);
  134. outb_p(RTC_ALARM_DONT_CARE, 0x73);
  135. outb_p(0x7d, 0x72);
  136. outb_p(RTC_ALARM_DONT_CARE, 0x73);
  137. }
  138. /* SATA */
  139. static void __devinit quirk_uli5288(struct pci_dev *dev)
  140. {
  141. unsigned char c;
  142. unsigned int d;
  143. if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
  144. !machine_is(mpc8572_ds))
  145. return;
  146. /* read/write lock */
  147. pci_read_config_byte(dev, 0x83, &c);
  148. pci_write_config_byte(dev, 0x83, c|0x80);
  149. pci_read_config_dword(dev, PCI_CLASS_REVISION, &d);
  150. d = (d & 0xff) | (PCI_CLASS_STORAGE_SATA_AHCI << 8);
  151. pci_write_config_dword(dev, PCI_CLASS_REVISION, d);
  152. /* restore lock */
  153. pci_write_config_byte(dev, 0x83, c);
  154. /* disable emulated PATA mode enabled */
  155. pci_read_config_byte(dev, 0x84, &c);
  156. pci_write_config_byte(dev, 0x84, c & ~0x01);
  157. }
  158. /* PATA */
  159. static void __devinit quirk_uli5229(struct pci_dev *dev)
  160. {
  161. unsigned short temp;
  162. if (!machine_is(mpc86xx_hpcn) && !machine_is(mpc8544_ds) &&
  163. !machine_is(mpc8572_ds))
  164. return;
  165. pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE |
  166. PCI_COMMAND_MASTER | PCI_COMMAND_IO);
  167. /* Enable Native IRQ 14/15 */
  168. pci_read_config_word(dev, 0x4a, &temp);
  169. pci_write_config_word(dev, 0x4a, temp | 0x1000);
  170. }
  171. /* We have to do a dummy read on the P2P for the RTC to work, WTF */
  172. static void __devinit quirk_final_uli5249(struct pci_dev *dev)
  173. {
  174. int i;
  175. u8 *dummy;
  176. struct pci_bus *bus = dev->bus;
  177. resource_size_t end = 0;
  178. for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCES+3; i++) {
  179. unsigned long flags = pci_resource_flags(dev, i);
  180. if ((flags & (IORESOURCE_MEM|IORESOURCE_PREFETCH)) == IORESOURCE_MEM)
  181. end = pci_resource_end(dev, i);
  182. }
  183. for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  184. if ((bus->resource[i]) &&
  185. (bus->resource[i]->flags & IORESOURCE_MEM)) {
  186. if (bus->resource[i]->end == end)
  187. dummy = ioremap(bus->resource[i]->start, 0x4);
  188. else
  189. dummy = ioremap(bus->resource[i]->end - 3, 0x4);
  190. if (dummy) {
  191. in_8(dummy);
  192. iounmap(dummy);
  193. }
  194. break;
  195. }
  196. }
  197. }
  198. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);
  199. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
  200. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
  201. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
  202. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5249, quirk_final_uli5249);
  203. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575);
  204. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
  205. static void __devinit hpcd_quirk_uli1575(struct pci_dev *dev)
  206. {
  207. u32 temp32;
  208. if (!machine_is(mpc86xx_hpcd))
  209. return;
  210. /* Disable INTx */
  211. pci_read_config_dword(dev, 0x48, &temp32);
  212. pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
  213. /* Enable sideband interrupt */
  214. pci_read_config_dword(dev, 0x90, &temp32);
  215. pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
  216. }
  217. static void __devinit hpcd_quirk_uli5288(struct pci_dev *dev)
  218. {
  219. unsigned char c;
  220. unsigned short temp;
  221. if (!machine_is(mpc86xx_hpcd))
  222. return;
  223. /* Interrupt Disable, Needed when SATA disabled */
  224. pci_read_config_word(dev, PCI_COMMAND, &temp);
  225. temp |= 1<<10;
  226. pci_write_config_word(dev, PCI_COMMAND, temp);
  227. pci_read_config_byte(dev, 0x83, &c);
  228. c |= 0x80;
  229. pci_write_config_byte(dev, 0x83, c);
  230. pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
  231. pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
  232. pci_read_config_byte(dev, 0x83, &c);
  233. c &= 0x7f;
  234. pci_write_config_byte(dev, 0x83, c);
  235. }
  236. /*
  237. * Since 8259PIC was disabled on the board, the IDE device can not
  238. * use the legacy IRQ, we need to let the IDE device work under
  239. * native mode and use the interrupt line like other PCI devices.
  240. * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
  241. * as the interrupt for IDE device.
  242. */
  243. static void __devinit hpcd_quirk_uli5229(struct pci_dev *dev)
  244. {
  245. unsigned char c;
  246. if (!machine_is(mpc86xx_hpcd))
  247. return;
  248. pci_read_config_byte(dev, 0x4b, &c);
  249. c |= 0x10;
  250. pci_write_config_byte(dev, 0x4b, c);
  251. }
  252. /*
  253. * SATA interrupt pin bug fix
  254. * There's a chip bug for 5288, The interrupt pin should be 2,
  255. * not the read only value 1, So it use INTB#, not INTA# which
  256. * actually used by the IDE device 5229.
  257. * As of this bug, during the PCI initialization, 5288 read the
  258. * irq of IDE device from the device tree, this function fix this
  259. * bug by re-assigning a correct irq to 5288.
  260. *
  261. */
  262. static void __devinit hpcd_final_uli5288(struct pci_dev *dev)
  263. {
  264. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  265. struct device_node *hosenode = hose ? hose->dn : NULL;
  266. struct of_irq oirq;
  267. int virq, pin = 2;
  268. u32 laddr[3];
  269. if (!machine_is(mpc86xx_hpcd))
  270. return;
  271. if (!hosenode)
  272. return;
  273. laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
  274. laddr[1] = laddr[2] = 0;
  275. of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
  276. virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
  277. oirq.size);
  278. dev->irq = virq;
  279. }
  280. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, hpcd_quirk_uli1575);
  281. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, hpcd_quirk_uli5288);
  282. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, hpcd_quirk_uli5229);
  283. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, hpcd_final_uli5288);
  284. int uli_exclude_device(struct pci_controller *hose,
  285. u_char bus, u_char devfn)
  286. {
  287. if (bus == (hose->first_busno + 2)) {
  288. /* exclude Modem controller */
  289. if ((PCI_SLOT(devfn) == 29) && (PCI_FUNC(devfn) == 1))
  290. return PCIBIOS_DEVICE_NOT_FOUND;
  291. /* exclude HD Audio controller */
  292. if ((PCI_SLOT(devfn) == 29) && (PCI_FUNC(devfn) == 2))
  293. return PCIBIOS_DEVICE_NOT_FOUND;
  294. }
  295. return PCIBIOS_SUCCESSFUL;
  296. }