mpc86xx_hpcn.c 10 KB

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