mpc7448_hpc2.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * mpc7448_hpc2.c
  3. *
  4. * Board setup routines for the Freescale 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 file is licensed under
  16. * the terms of the GNU General Public License version 2. This program
  17. * is licensed "as is" without any warranty of any kind, whether express
  18. * or implied.
  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 int tsi108_irq_cascade(struct pt_regs *regs, void *unused);
  61. /*
  62. * Define all of the IRQ senses and polarities. Taken from the
  63. * mpc7448hpc manual.
  64. * Note: Likely, this table and the following function should be
  65. * obtained and derived from the OF Device Tree.
  66. */
  67. static u_char mpc7448_hpc2_pic_initsenses[] __initdata = {
  68. /* External on-board sources */
  69. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* INT[0] XINT0 from FPGA */
  70. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* INT[1] XINT1 from FPGA */
  71. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* INT[2] PHY_INT from both GIGE */
  72. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* INT[3] RESERVED */
  73. /* Internal Tsi108/109 interrupt sources */
  74. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  75. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  76. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  77. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  78. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* DMA0 */
  79. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* DMA1 */
  80. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* DMA2 */
  81. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* DMA3 */
  82. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* UART0 */
  83. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* UART1 */
  84. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* I2C */
  85. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* GPIO */
  86. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* GIGE0 */
  87. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* GIGE1 */
  88. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  89. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* HLP */
  90. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* SDC */
  91. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Processor IF */
  92. (IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE), /* Reserved IRQ */
  93. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* PCI/X block */
  94. };
  95. int mpc7448_hpc2_exclude_device(u_char bus, u_char devfn)
  96. {
  97. if (bus == 0 && PCI_SLOT(devfn) == 0)
  98. return PCIBIOS_DEVICE_NOT_FOUND;
  99. else
  100. return PCIBIOS_SUCCESSFUL;
  101. }
  102. /*
  103. * find pci slot by devfn in interrupt map of OF tree
  104. */
  105. u8 find_slot_by_devfn(unsigned int *interrupt_map, unsigned int devfn)
  106. {
  107. int i;
  108. unsigned int tmp;
  109. for (i = 0; i < 4; i++){
  110. tmp = interrupt_map[i*4*7];
  111. if ((tmp >> 11) == (devfn >> 3))
  112. return i;
  113. }
  114. return i;
  115. }
  116. /*
  117. * Scans the interrupt map for pci device
  118. */
  119. void mpc7448_hpc2_fixup_irq(struct pci_dev *dev)
  120. {
  121. struct pci_controller *hose;
  122. struct device_node *node;
  123. unsigned int *interrupt;
  124. int busnr;
  125. int len;
  126. u8 slot;
  127. u8 pin;
  128. /* Lookup the hose */
  129. busnr = dev->bus->number;
  130. hose = pci_bus_to_hose(busnr);
  131. if (!hose)
  132. printk(KERN_ERR "No pci hose found\n");
  133. /* Check it has an OF node associated */
  134. node = (struct device_node *) hose->arch_data;
  135. if (!node)
  136. printk(KERN_ERR "No pci node found\n");
  137. interrupt = (unsigned int *) get_property(node, "interrupt-map", &len);
  138. slot = find_slot_by_devfn(interrupt, dev->devfn);
  139. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  140. if (pin == 0 || pin > 4)
  141. pin = 1;
  142. pin--;
  143. dev->irq = interrupt[slot*4*7 + pin*7 + 5];
  144. DBG("TSI_PCI: dev->irq = 0x%x\n", dev->irq);
  145. }
  146. /* temporary pci irq map fixup*/
  147. void __init mpc7448_hpc2_pcibios_fixup(void)
  148. {
  149. struct pci_dev *dev = NULL;
  150. for_each_pci_dev(dev) {
  151. mpc7448_hpc2_fixup_irq(dev);
  152. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  153. }
  154. }
  155. static void __init mpc7448_hpc2_setup_arch(void)
  156. {
  157. struct device_node *cpu;
  158. struct device_node *np;
  159. if (ppc_md.progress)
  160. ppc_md.progress("mpc7448_hpc2_setup_arch():set_bridge", 0);
  161. cpu = of_find_node_by_type(NULL, "cpu");
  162. if (cpu != 0) {
  163. unsigned int *fp;
  164. fp = (int *)get_property(cpu, "clock-frequency", NULL);
  165. if (fp != 0)
  166. loops_per_jiffy = *fp / HZ;
  167. else
  168. loops_per_jiffy = 50000000 / HZ;
  169. of_node_put(cpu);
  170. }
  171. tsi108_csr_vir_base = get_vir_csrbase();
  172. #ifdef CONFIG_ROOT_NFS
  173. ROOT_DEV = Root_NFS;
  174. #else
  175. ROOT_DEV = Root_HDA1;
  176. #endif
  177. #ifdef CONFIG_BLK_DEV_INITRD
  178. ROOT_DEV = Root_RAM0;
  179. #endif
  180. /* setup PCI host bridge */
  181. #ifdef CONFIG_PCI
  182. for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
  183. tsi108_setup_pci(np);
  184. ppc_md.pci_exclude_device = mpc7448_hpc2_exclude_device;
  185. if (ppc_md.progress)
  186. ppc_md.progress("tsi108: resources set", 0x100);
  187. #endif
  188. printk(KERN_INFO "MPC7448HPC2 (TAIGA) Platform\n");
  189. printk(KERN_INFO
  190. "Jointly ported by Freescale and Tundra Semiconductor\n");
  191. printk(KERN_INFO
  192. "Enabling L2 cache then enabling the HID0 prefetch engine.\n");
  193. }
  194. /*
  195. * Interrupt setup and service. Interrrupts on the mpc7448_hpc2 come
  196. * from the four external INT pins, PCI interrupts are routed via
  197. * PCI interrupt control registers, it generates internal IRQ23
  198. *
  199. * Interrupt routing on the Taiga Board:
  200. * TSI108:PB_INT[0] -> CPU0:INT#
  201. * TSI108:PB_INT[1] -> CPU0:MCP#
  202. * TSI108:PB_INT[2] -> N/C
  203. * TSI108:PB_INT[3] -> N/C
  204. */
  205. static void __init mpc7448_hpc2_init_IRQ(void)
  206. {
  207. struct mpic *mpic;
  208. phys_addr_t mpic_paddr = 0;
  209. struct device_node *tsi_pic;
  210. tsi_pic = of_find_node_by_type(NULL, "open-pic");
  211. if (tsi_pic) {
  212. unsigned int size;
  213. void *prop = get_property(tsi_pic, "reg", &size);
  214. mpic_paddr = of_translate_address(tsi_pic, prop);
  215. }
  216. if (mpic_paddr == 0) {
  217. printk("%s: No tsi108 PIC found !\n", __FUNCTION__);
  218. return;
  219. }
  220. DBG("%s: tsi108pic phys_addr = 0x%x\n", __FUNCTION__,
  221. (u32) mpic_paddr);
  222. mpic = mpic_alloc(mpic_paddr,
  223. MPIC_PRIMARY | MPIC_BIG_ENDIAN | MPIC_WANTS_RESET |
  224. MPIC_SPV_EOI | MPIC_MOD_ID(MPIC_ID_TSI108),
  225. 0, /* num_sources used */
  226. TSI108_IRQ_BASE,
  227. 0, /* num_sources used */
  228. NR_IRQS - 4 /* XXXX */,
  229. mpc7448_hpc2_pic_initsenses,
  230. sizeof(mpc7448_hpc2_pic_initsenses), "Tsi108_PIC");
  231. BUG_ON(mpic == NULL); /* XXXX */
  232. mpic_init(mpic);
  233. mpic_setup_cascade(IRQ_TSI108_PCI, tsi108_irq_cascade, mpic);
  234. tsi108_pci_int_init();
  235. /* Configure MPIC outputs to CPU0 */
  236. tsi108_write_reg(TSI108_MPIC_OFFSET + 0x30c, 0);
  237. }
  238. void mpc7448_hpc2_show_cpuinfo(struct seq_file *m)
  239. {
  240. seq_printf(m, "vendor\t\t: Freescale Semiconductor\n");
  241. seq_printf(m, "machine\t\t: MPC7448hpc2\n");
  242. }
  243. void mpc7448_hpc2_restart(char *cmd)
  244. {
  245. local_irq_disable();
  246. /* Set exception prefix high - to the firmware */
  247. _nmask_and_or_msr(0, MSR_IP);
  248. for (;;) ; /* Spin until reset happens */
  249. }
  250. void mpc7448_hpc2_power_off(void)
  251. {
  252. local_irq_disable();
  253. for (;;) ; /* No way to shut power off with software */
  254. }
  255. void mpc7448_hpc2_halt(void)
  256. {
  257. mpc7448_hpc2_power_off();
  258. }
  259. /*
  260. * Called very early, device-tree isn't unflattened
  261. */
  262. static int __init mpc7448_hpc2_probe(void)
  263. {
  264. unsigned long root = of_get_flat_dt_root();
  265. if (!of_flat_dt_is_compatible(root, "mpc74xx"))
  266. return 0;
  267. return 1;
  268. }
  269. static int mpc7448_machine_check_exception(struct pt_regs *regs)
  270. {
  271. extern void tsi108_clear_pci_cfg_error(void);
  272. const struct exception_table_entry *entry;
  273. /* Are we prepared to handle this fault */
  274. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  275. tsi108_clear_pci_cfg_error();
  276. regs->msr |= MSR_RI;
  277. regs->nip = entry->fixup;
  278. return 1;
  279. }
  280. return 0;
  281. }
  282. define_machine(mpc7448_hpc2){
  283. .name = "MPC7448 HPC2",
  284. .probe = mpc7448_hpc2_probe,
  285. .setup_arch = mpc7448_hpc2_setup_arch,
  286. .init_IRQ = mpc7448_hpc2_init_IRQ,
  287. .show_cpuinfo = mpc7448_hpc2_show_cpuinfo,
  288. .get_irq = mpic_get_irq,
  289. .pcibios_fixup = mpc7448_hpc2_pcibios_fixup,
  290. .restart = mpc7448_hpc2_restart,
  291. .calibrate_decr = generic_calibrate_decr,
  292. .machine_check_exception= mpc7448_machine_check_exception,
  293. .progress = udbg_progress,
  294. };