mpc86xx_hpcn.c 11 KB

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