mpc86xx_hpcn.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * MPC86xx HPCN board specific routines
  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/stddef.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/kdev_t.h>
  18. #include <linux/delay.h>
  19. #include <linux/seq_file.h>
  20. #include <asm/system.h>
  21. #include <asm/time.h>
  22. #include <asm/machdep.h>
  23. #include <asm/pci-bridge.h>
  24. #include <asm/mpc86xx.h>
  25. #include <asm/prom.h>
  26. #include <mm/mmu_decl.h>
  27. #include <asm/udbg.h>
  28. #include <asm/i8259.h>
  29. #include <asm/mpic.h>
  30. #include <sysdev/fsl_pci.h>
  31. #include <sysdev/fsl_soc.h>
  32. #include "mpc86xx.h"
  33. #include "mpc8641_hpcn.h"
  34. #undef DEBUG
  35. #ifdef DEBUG
  36. #define DBG(fmt...) do { printk(KERN_ERR fmt); } while(0)
  37. #else
  38. #define DBG(fmt...) do { } while(0)
  39. #endif
  40. #ifdef CONFIG_PCI
  41. static void mpc86xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
  42. {
  43. unsigned int cascade_irq = i8259_irq();
  44. if (cascade_irq != NO_IRQ)
  45. generic_handle_irq(cascade_irq);
  46. desc->chip->eoi(irq);
  47. }
  48. #endif /* CONFIG_PCI */
  49. void __init
  50. mpc86xx_hpcn_init_irq(void)
  51. {
  52. struct mpic *mpic1;
  53. struct device_node *np;
  54. struct resource res;
  55. #ifdef CONFIG_PCI
  56. struct device_node *cascade_node = NULL;
  57. int cascade_irq;
  58. #endif
  59. /* Determine PIC address. */
  60. np = of_find_node_by_type(NULL, "open-pic");
  61. if (np == NULL)
  62. return;
  63. of_address_to_resource(np, 0, &res);
  64. /* Alloc mpic structure and per isu has 16 INT entries. */
  65. mpic1 = mpic_alloc(np, res.start,
  66. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  67. 0, 256, " MPIC ");
  68. BUG_ON(mpic1 == NULL);
  69. mpic_init(mpic1);
  70. #ifdef CONFIG_PCI
  71. /* Initialize i8259 controller */
  72. for_each_node_by_type(np, "interrupt-controller")
  73. if (of_device_is_compatible(np, "chrp,iic")) {
  74. cascade_node = np;
  75. break;
  76. }
  77. if (cascade_node == NULL) {
  78. printk(KERN_DEBUG "mpc86xxhpcn: no ISA interrupt controller\n");
  79. return;
  80. }
  81. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  82. if (cascade_irq == NO_IRQ) {
  83. printk(KERN_ERR "mpc86xxhpcn: failed to map cascade interrupt");
  84. return;
  85. }
  86. DBG("mpc86xxhpcn: cascade mapped to irq %d\n", cascade_irq);
  87. i8259_init(cascade_node, 0);
  88. of_node_put(cascade_node);
  89. set_irq_chained_handler(cascade_irq, mpc86xx_8259_cascade);
  90. #endif
  91. }
  92. #ifdef CONFIG_PCI
  93. enum pirq{PIRQA = 8, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH};
  94. const unsigned char uli1575_irq_route_table[16] = {
  95. 0, /* 0: Reserved */
  96. 0x8, /* 1: 0b1000 */
  97. 0, /* 2: Reserved */
  98. 0x2, /* 3: 0b0010 */
  99. 0x4, /* 4: 0b0100 */
  100. 0x5, /* 5: 0b0101 */
  101. 0x7, /* 6: 0b0111 */
  102. 0x6, /* 7: 0b0110 */
  103. 0, /* 8: Reserved */
  104. 0x1, /* 9: 0b0001 */
  105. 0x3, /* 10: 0b0011 */
  106. 0x9, /* 11: 0b1001 */
  107. 0xb, /* 12: 0b1011 */
  108. 0, /* 13: Reserved */
  109. 0xd, /* 14, 0b1101 */
  110. 0xf, /* 15, 0b1111 */
  111. };
  112. static int __devinit
  113. get_pci_irq_from_of(struct pci_controller *hose, int slot, int pin)
  114. {
  115. struct of_irq oirq;
  116. u32 laddr[3];
  117. struct device_node *hosenode = hose ? hose->arch_data : NULL;
  118. if (!hosenode) return -EINVAL;
  119. laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(slot, 0) << 8);
  120. laddr[1] = laddr[2] = 0;
  121. of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
  122. DBG("mpc86xx_hpcn: pci irq addr %x, slot %d, pin %d, irq %d\n",
  123. laddr[0], slot, pin, oirq.specifier[0]);
  124. return oirq.specifier[0];
  125. }
  126. static void __devinit quirk_uli1575(struct pci_dev *dev)
  127. {
  128. unsigned short temp;
  129. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  130. unsigned char irq2pin[16], c;
  131. unsigned long pirq_map_word = 0;
  132. u32 irq;
  133. int i;
  134. /*
  135. * ULI1575 interrupts route setup
  136. */
  137. memset(irq2pin, 0, 16); /* Initialize default value 0 */
  138. /*
  139. * PIRQA -> PIRQD mapping read from OF-tree
  140. *
  141. * interrupts for PCI slot0 -- PIRQA / PIRQB / PIRQC / PIRQD
  142. * PCI slot1 -- PIRQB / PIRQC / PIRQD / PIRQA
  143. */
  144. for (i = 0; i < 4; i++){
  145. irq = get_pci_irq_from_of(hose, 17, i + 1);
  146. if (irq > 0 && irq < 16)
  147. irq2pin[irq] = PIRQA + i;
  148. else
  149. printk(KERN_WARNING "ULI1575 device"
  150. "(slot %d, pin %d) irq %d is invalid.\n",
  151. 17, i, irq);
  152. }
  153. /*
  154. * PIRQE -> PIRQF mapping set manually
  155. *
  156. * IRQ pin IRQ#
  157. * PIRQE ---- 9
  158. * PIRQF ---- 10
  159. * PIRQG ---- 11
  160. * PIRQH ---- 12
  161. */
  162. for (i = 0; i < 4; i++) irq2pin[i + 9] = PIRQE + i;
  163. /* Set IRQ-PIRQ Mapping to ULI1575 */
  164. for (i = 0; i < 16; i++)
  165. if (irq2pin[i])
  166. pirq_map_word |= (uli1575_irq_route_table[i] & 0xf)
  167. << ((irq2pin[i] - PIRQA) * 4);
  168. /* ULI1575 IRQ mapping conf register default value is 0xb9317542 */
  169. DBG("Setup ULI1575 IRQ mapping configuration register value = 0x%x\n",
  170. pirq_map_word);
  171. pci_write_config_dword(dev, 0x48, pirq_map_word);
  172. #define ULI1575_SET_DEV_IRQ(slot, pin, reg) \
  173. do { \
  174. int irq; \
  175. irq = get_pci_irq_from_of(hose, slot, pin); \
  176. if (irq > 0 && irq < 16) \
  177. pci_write_config_byte(dev, reg, irq2pin[irq]); \
  178. else \
  179. printk(KERN_WARNING "ULI1575 device" \
  180. "(slot %d, pin %d) irq %d is invalid.\n", \
  181. slot, pin, irq); \
  182. } while(0)
  183. /* USB 1.1 OHCI controller 1, slot 28, pin 1 */
  184. ULI1575_SET_DEV_IRQ(28, 1, 0x86);
  185. /* USB 1.1 OHCI controller 2, slot 28, pin 2 */
  186. ULI1575_SET_DEV_IRQ(28, 2, 0x87);
  187. /* USB 1.1 OHCI controller 3, slot 28, pin 3 */
  188. ULI1575_SET_DEV_IRQ(28, 3, 0x88);
  189. /* USB 2.0 controller, slot 28, pin 4 */
  190. irq = get_pci_irq_from_of(hose, 28, 4);
  191. if (irq >= 0 && irq <=15)
  192. pci_write_config_dword(dev, 0x74, uli1575_irq_route_table[irq]);
  193. /* Audio controller, slot 29, pin 1 */
  194. ULI1575_SET_DEV_IRQ(29, 1, 0x8a);
  195. /* Modem controller, slot 29, pin 2 */
  196. ULI1575_SET_DEV_IRQ(29, 2, 0x8b);
  197. /* HD audio controller, slot 29, pin 3 */
  198. ULI1575_SET_DEV_IRQ(29, 3, 0x8c);
  199. /* SMB interrupt: slot 30, pin 1 */
  200. ULI1575_SET_DEV_IRQ(30, 1, 0x8e);
  201. /* PMU ACPI SCI interrupt: slot 30, pin 2 */
  202. ULI1575_SET_DEV_IRQ(30, 2, 0x8f);
  203. /* Serial ATA interrupt: slot 31, pin 1 */
  204. ULI1575_SET_DEV_IRQ(31, 1, 0x8d);
  205. /* Primary PATA IDE IRQ: 14
  206. * Secondary PATA IDE IRQ: 15
  207. */
  208. pci_write_config_byte(dev, 0x44, 0x30 | uli1575_irq_route_table[14]);
  209. pci_write_config_byte(dev, 0x75, uli1575_irq_route_table[15]);
  210. /* Set IRQ14 and IRQ15 to legacy IRQs */
  211. pci_read_config_word(dev, 0x46, &temp);
  212. temp |= 0xc000;
  213. pci_write_config_word(dev, 0x46, temp);
  214. /* Set i8259 interrupt trigger
  215. * IRQ 3: Level
  216. * IRQ 4: Level
  217. * IRQ 5: Level
  218. * IRQ 6: Level
  219. * IRQ 7: Level
  220. * IRQ 9: Level
  221. * IRQ 10: Level
  222. * IRQ 11: Level
  223. * IRQ 12: Level
  224. * IRQ 14: Edge
  225. * IRQ 15: Edge
  226. */
  227. outb(0xfa, 0x4d0);
  228. outb(0x1e, 0x4d1);
  229. #undef ULI1575_SET_DEV_IRQ
  230. /* Disable the HD interface and enable the AC97 interface. */
  231. pci_read_config_byte(dev, 0xb8, &c);
  232. c &= 0x7f;
  233. pci_write_config_byte(dev, 0xb8, c);
  234. }
  235. static void __devinit quirk_uli5288(struct pci_dev *dev)
  236. {
  237. unsigned char c;
  238. pci_read_config_byte(dev,0x83,&c);
  239. c |= 0x80;
  240. pci_write_config_byte(dev, 0x83, c);
  241. pci_write_config_byte(dev, 0x09, 0x01);
  242. pci_write_config_byte(dev, 0x0a, 0x06);
  243. pci_read_config_byte(dev,0x83,&c);
  244. c &= 0x7f;
  245. pci_write_config_byte(dev, 0x83, c);
  246. pci_read_config_byte(dev,0x84,&c);
  247. c |= 0x01;
  248. pci_write_config_byte(dev, 0x84, c);
  249. }
  250. static void __devinit quirk_uli5229(struct pci_dev *dev)
  251. {
  252. unsigned short temp;
  253. pci_write_config_word(dev, 0x04, 0x0405);
  254. dev->class &= ~0x5;
  255. pci_read_config_word(dev, 0x4a, &temp);
  256. temp |= 0x1000;
  257. pci_write_config_word(dev, 0x4a, temp);
  258. }
  259. static void __devinit early_uli5249(struct pci_dev *dev)
  260. {
  261. unsigned char temp;
  262. pci_write_config_word(dev, 0x04, 0x0007);
  263. pci_read_config_byte(dev, 0x7c, &temp);
  264. pci_write_config_byte(dev, 0x7c, 0x80);
  265. pci_write_config_byte(dev, 0x09, 0x01);
  266. pci_write_config_byte(dev, 0x7c, temp);
  267. dev->class |= 0x1;
  268. }
  269. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
  270. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
  271. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
  272. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);
  273. #endif /* CONFIG_PCI */
  274. static void __init
  275. mpc86xx_hpcn_setup_arch(void)
  276. {
  277. struct device_node *np;
  278. if (ppc_md.progress)
  279. ppc_md.progress("mpc86xx_hpcn_setup_arch()", 0);
  280. np = of_find_node_by_type(NULL, "cpu");
  281. if (np != 0) {
  282. const unsigned int *fp;
  283. fp = of_get_property(np, "clock-frequency", NULL);
  284. if (fp != 0)
  285. loops_per_jiffy = *fp / HZ;
  286. else
  287. loops_per_jiffy = 50000000 / HZ;
  288. of_node_put(np);
  289. }
  290. #ifdef CONFIG_PCI
  291. for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;) {
  292. struct resource rsrc;
  293. of_address_to_resource(np, 0, &rsrc);
  294. if ((rsrc.start & 0xfffff) == 0x8000)
  295. fsl_add_bridge(np, 1);
  296. else
  297. fsl_add_bridge(np, 0);
  298. }
  299. #endif
  300. printk("MPC86xx HPCN board from Freescale Semiconductor\n");
  301. #ifdef CONFIG_SMP
  302. mpc86xx_smp_init();
  303. #endif
  304. }
  305. void
  306. mpc86xx_hpcn_show_cpuinfo(struct seq_file *m)
  307. {
  308. struct device_node *root;
  309. uint memsize = total_memory;
  310. const char *model = "";
  311. uint svid = mfspr(SPRN_SVR);
  312. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  313. root = of_find_node_by_path("/");
  314. if (root)
  315. model = of_get_property(root, "model", NULL);
  316. seq_printf(m, "Machine\t\t: %s\n", model);
  317. of_node_put(root);
  318. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  319. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  320. }
  321. /*
  322. * Called very early, device-tree isn't unflattened
  323. */
  324. static int __init mpc86xx_hpcn_probe(void)
  325. {
  326. unsigned long root = of_get_flat_dt_root();
  327. if (of_flat_dt_is_compatible(root, "mpc86xx"))
  328. return 1; /* Looks good */
  329. return 0;
  330. }
  331. void
  332. mpc86xx_restart(char *cmd)
  333. {
  334. void __iomem *rstcr;
  335. rstcr = ioremap(get_immrbase() + MPC86XX_RSTCR_OFFSET, 0x100);
  336. local_irq_disable();
  337. /* Assert reset request to Reset Control Register */
  338. out_be32(rstcr, 0x2);
  339. /* not reached */
  340. }
  341. long __init
  342. mpc86xx_time_init(void)
  343. {
  344. unsigned int temp;
  345. /* Set the time base to zero */
  346. mtspr(SPRN_TBWL, 0);
  347. mtspr(SPRN_TBWU, 0);
  348. temp = mfspr(SPRN_HID0);
  349. temp |= HID0_TBEN;
  350. mtspr(SPRN_HID0, temp);
  351. asm volatile("isync");
  352. return 0;
  353. }
  354. define_machine(mpc86xx_hpcn) {
  355. .name = "MPC86xx HPCN",
  356. .probe = mpc86xx_hpcn_probe,
  357. .setup_arch = mpc86xx_hpcn_setup_arch,
  358. .init_IRQ = mpc86xx_hpcn_init_irq,
  359. .show_cpuinfo = mpc86xx_hpcn_show_cpuinfo,
  360. .get_irq = mpic_get_irq,
  361. .restart = mpc86xx_restart,
  362. .time_init = mpc86xx_time_init,
  363. .calibrate_decr = generic_calibrate_decr,
  364. .progress = udbg_progress,
  365. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  366. };