mpc86xx_hpcn.c 11 KB

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