mpc7448_hpc2.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * mpc7448_hpc2.c
  3. *
  4. * Board setup routines for the Freescale mpc7448hpc2(taiga) platform
  5. *
  6. * Author: Jacob Pan
  7. * jacob.pan@freescale.com
  8. * Author: Xianghua Xiao
  9. * x.xiao@freescale.com
  10. * Maintainer: Roy Zang <tie-fei.zang@freescale.com>
  11. * Add Flat Device Tree support fot mpc7448hpc2 board
  12. *
  13. * Copyright 2004-2006 Freescale Semiconductor, Inc.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/config.h>
  21. #include <linux/stddef.h>
  22. #include <linux/kernel.h>
  23. #include <linux/pci.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/console.h>
  26. #include <linux/delay.h>
  27. #include <linux/irq.h>
  28. #include <linux/ide.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/serial.h>
  32. #include <linux/tty.h>
  33. #include <linux/serial_core.h>
  34. #include <asm/system.h>
  35. #include <asm/time.h>
  36. #include <asm/machdep.h>
  37. #include <asm/prom.h>
  38. #include <asm/udbg.h>
  39. #include <asm/tsi108.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/reg.h>
  42. #include <mm/mmu_decl.h>
  43. #include "mpc7448_hpc2.h"
  44. #include <asm/tsi108_irq.h>
  45. #include <asm/mpic.h>
  46. #undef DEBUG
  47. #ifdef DEBUG
  48. #define DBG(fmt...) do { printk(fmt); } while(0)
  49. #else
  50. #define DBG(fmt...) do { } while(0)
  51. #endif
  52. #ifndef CONFIG_PCI
  53. isa_io_base = MPC7448_HPC2_ISA_IO_BASE;
  54. isa_mem_base = MPC7448_HPC2_ISA_MEM_BASE;
  55. pci_dram_offset = MPC7448_HPC2_PCI_MEM_OFFSET;
  56. #endif
  57. extern int tsi108_setup_pci(struct device_node *dev);
  58. extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
  59. extern void tsi108_pci_int_init(void);
  60. extern void tsi108_irq_cascade(unsigned int irq, struct irq_desc *desc,
  61. struct pt_regs *regs);
  62. int mpc7448_hpc2_exclude_device(u_char bus, u_char devfn)
  63. {
  64. if (bus == 0 && PCI_SLOT(devfn) == 0)
  65. return PCIBIOS_DEVICE_NOT_FOUND;
  66. else
  67. return PCIBIOS_SUCCESSFUL;
  68. }
  69. /*
  70. * find pci slot by devfn in interrupt map of OF tree
  71. */
  72. u8 find_slot_by_devfn(unsigned int *interrupt_map, unsigned int devfn)
  73. {
  74. int i;
  75. unsigned int tmp;
  76. for (i = 0; i < 4; i++){
  77. tmp = interrupt_map[i*4*7];
  78. if ((tmp >> 11) == (devfn >> 3))
  79. return i;
  80. }
  81. return i;
  82. }
  83. /*
  84. * Scans the interrupt map for pci device
  85. */
  86. void mpc7448_hpc2_fixup_irq(struct pci_dev *dev)
  87. {
  88. struct pci_controller *hose;
  89. struct device_node *node;
  90. const unsigned int *interrupt;
  91. int busnr;
  92. int len;
  93. u8 slot;
  94. u8 pin;
  95. /* Lookup the hose */
  96. busnr = dev->bus->number;
  97. hose = pci_bus_to_hose(busnr);
  98. if (!hose)
  99. printk(KERN_ERR "No pci hose found\n");
  100. /* Check it has an OF node associated */
  101. node = (struct device_node *) hose->arch_data;
  102. if (!node)
  103. printk(KERN_ERR "No pci node found\n");
  104. interrupt = get_property(node, "interrupt-map", &len);
  105. slot = find_slot_by_devfn(interrupt, dev->devfn);
  106. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  107. if (pin == 0 || pin > 4)
  108. pin = 1;
  109. pin--;
  110. dev->irq = interrupt[slot*4*7 + pin*7 + 5];
  111. DBG("TSI_PCI: dev->irq = 0x%x\n", dev->irq);
  112. }
  113. /* temporary pci irq map fixup*/
  114. void __init mpc7448_hpc2_pcibios_fixup(void)
  115. {
  116. struct pci_dev *dev = NULL;
  117. for_each_pci_dev(dev) {
  118. mpc7448_hpc2_fixup_irq(dev);
  119. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  120. }
  121. }
  122. static void __init mpc7448_hpc2_setup_arch(void)
  123. {
  124. struct device_node *cpu;
  125. struct device_node *np;
  126. if (ppc_md.progress)
  127. ppc_md.progress("mpc7448_hpc2_setup_arch():set_bridge", 0);
  128. cpu = of_find_node_by_type(NULL, "cpu");
  129. if (cpu != 0) {
  130. const unsigned int *fp;
  131. fp = get_property(cpu, "clock-frequency", NULL);
  132. if (fp != 0)
  133. loops_per_jiffy = *fp / HZ;
  134. else
  135. loops_per_jiffy = 50000000 / HZ;
  136. of_node_put(cpu);
  137. }
  138. tsi108_csr_vir_base = get_vir_csrbase();
  139. #ifdef CONFIG_ROOT_NFS
  140. ROOT_DEV = Root_NFS;
  141. #else
  142. ROOT_DEV = Root_HDA1;
  143. #endif
  144. #ifdef CONFIG_BLK_DEV_INITRD
  145. ROOT_DEV = Root_RAM0;
  146. #endif
  147. /* setup PCI host bridge */
  148. #ifdef CONFIG_PCI
  149. for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
  150. tsi108_setup_pci(np);
  151. ppc_md.pci_exclude_device = mpc7448_hpc2_exclude_device;
  152. if (ppc_md.progress)
  153. ppc_md.progress("tsi108: resources set", 0x100);
  154. #endif
  155. printk(KERN_INFO "MPC7448HPC2 (TAIGA) Platform\n");
  156. printk(KERN_INFO
  157. "Jointly ported by Freescale and Tundra Semiconductor\n");
  158. printk(KERN_INFO
  159. "Enabling L2 cache then enabling the HID0 prefetch engine.\n");
  160. }
  161. /*
  162. * Interrupt setup and service. Interrrupts on the mpc7448_hpc2 come
  163. * from the four external INT pins, PCI interrupts are routed via
  164. * PCI interrupt control registers, it generates internal IRQ23
  165. *
  166. * Interrupt routing on the Taiga Board:
  167. * TSI108:PB_INT[0] -> CPU0:INT#
  168. * TSI108:PB_INT[1] -> CPU0:MCP#
  169. * TSI108:PB_INT[2] -> N/C
  170. * TSI108:PB_INT[3] -> N/C
  171. */
  172. static void __init mpc7448_hpc2_init_IRQ(void)
  173. {
  174. struct mpic *mpic;
  175. phys_addr_t mpic_paddr = 0;
  176. unsigned int cascade_pci_irq;
  177. struct device_node *tsi_pci;
  178. struct device_node *tsi_pic;
  179. tsi_pic = of_find_node_by_type(NULL, "open-pic");
  180. if (tsi_pic) {
  181. unsigned int size;
  182. void *prop = get_property(tsi_pic, "reg", &size);
  183. mpic_paddr = of_translate_address(tsi_pic, prop);
  184. }
  185. if (mpic_paddr == 0) {
  186. printk("%s: No tsi108 PIC found !\n", __FUNCTION__);
  187. return;
  188. }
  189. DBG("%s: tsi108pic phys_addr = 0x%x\n", __FUNCTION__,
  190. (u32) mpic_paddr);
  191. mpic = mpic_alloc(tsi_pic, mpic_paddr,
  192. MPIC_PRIMARY | MPIC_BIG_ENDIAN | MPIC_WANTS_RESET |
  193. MPIC_SPV_EOI | MPIC_NO_PTHROU_DIS | MPIC_REGSET_TSI108,
  194. 0, /* num_sources used */
  195. 0, /* num_sources used */
  196. "Tsi108_PIC");
  197. BUG_ON(mpic == NULL); /* XXXX */
  198. mpic_init(mpic);
  199. tsi_pci = of_find_node_by_type(NULL, "pci");
  200. if (tsi_pci == 0) {
  201. printk("%s: No tsi108 pci node found !\n", __FUNCTION__);
  202. return;
  203. }
  204. cascade_pci_irq = irq_of_parse_and_map(tsi_pci, 0);
  205. set_irq_data(cascade_pci_irq, mpic);
  206. set_irq_chained_handler(cascade_pci_irq, tsi108_irq_cascade);
  207. tsi108_pci_int_init();
  208. /* Configure MPIC outputs to CPU0 */
  209. tsi108_write_reg(TSI108_MPIC_OFFSET + 0x30c, 0);
  210. of_node_put(tsi_pic);
  211. }
  212. void mpc7448_hpc2_show_cpuinfo(struct seq_file *m)
  213. {
  214. seq_printf(m, "vendor\t\t: Freescale Semiconductor\n");
  215. seq_printf(m, "machine\t\t: MPC7448hpc2\n");
  216. }
  217. void mpc7448_hpc2_restart(char *cmd)
  218. {
  219. local_irq_disable();
  220. /* Set exception prefix high - to the firmware */
  221. _nmask_and_or_msr(0, MSR_IP);
  222. for (;;) ; /* Spin until reset happens */
  223. }
  224. void mpc7448_hpc2_power_off(void)
  225. {
  226. local_irq_disable();
  227. for (;;) ; /* No way to shut power off with software */
  228. }
  229. void mpc7448_hpc2_halt(void)
  230. {
  231. mpc7448_hpc2_power_off();
  232. }
  233. /*
  234. * Called very early, device-tree isn't unflattened
  235. */
  236. static int __init mpc7448_hpc2_probe(void)
  237. {
  238. unsigned long root = of_get_flat_dt_root();
  239. if (!of_flat_dt_is_compatible(root, "mpc74xx"))
  240. return 0;
  241. return 1;
  242. }
  243. static int mpc7448_machine_check_exception(struct pt_regs *regs)
  244. {
  245. extern void tsi108_clear_pci_cfg_error(void);
  246. const struct exception_table_entry *entry;
  247. /* Are we prepared to handle this fault */
  248. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  249. tsi108_clear_pci_cfg_error();
  250. regs->msr |= MSR_RI;
  251. regs->nip = entry->fixup;
  252. return 1;
  253. }
  254. return 0;
  255. }
  256. define_machine(mpc7448_hpc2){
  257. .name = "MPC7448 HPC2",
  258. .probe = mpc7448_hpc2_probe,
  259. .setup_arch = mpc7448_hpc2_setup_arch,
  260. .init_IRQ = mpc7448_hpc2_init_IRQ,
  261. .show_cpuinfo = mpc7448_hpc2_show_cpuinfo,
  262. .get_irq = mpic_get_irq,
  263. .pcibios_fixup = mpc7448_hpc2_pcibios_fixup,
  264. .restart = mpc7448_hpc2_restart,
  265. .calibrate_decr = generic_calibrate_decr,
  266. .machine_check_exception= mpc7448_machine_check_exception,
  267. .progress = udbg_progress,
  268. };