mpc85xx_cds.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * MPC85xx setup and early boot code plus other random bits.
  3. *
  4. * Maintained by Kumar Gala (see MAINTAINERS for contact information)
  5. *
  6. * Copyright 2005 Freescale Semiconductor Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/reboot.h>
  18. #include <linux/pci.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/major.h>
  21. #include <linux/console.h>
  22. #include <linux/delay.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/initrd.h>
  25. #include <linux/module.h>
  26. #include <linux/fsl_devices.h>
  27. #include <asm/system.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/page.h>
  30. #include <asm/atomic.h>
  31. #include <asm/time.h>
  32. #include <asm/io.h>
  33. #include <asm/machdep.h>
  34. #include <asm/ipic.h>
  35. #include <asm/bootinfo.h>
  36. #include <asm/pci-bridge.h>
  37. #include <asm/mpc85xx.h>
  38. #include <asm/irq.h>
  39. #include <mm/mmu_decl.h>
  40. #include <asm/prom.h>
  41. #include <asm/udbg.h>
  42. #include <asm/mpic.h>
  43. #include <asm/i8259.h>
  44. #include <sysdev/fsl_soc.h>
  45. #include "mpc85xx.h"
  46. #ifndef CONFIG_PCI
  47. unsigned long isa_io_base = 0;
  48. unsigned long isa_mem_base = 0;
  49. #endif
  50. static int cds_pci_slot = 2;
  51. static volatile u8 *cadmus;
  52. #ifdef CONFIG_PCI
  53. #define ARCADIA_HOST_BRIDGE_IDSEL 17
  54. #define ARCADIA_2ND_BRIDGE_IDSEL 3
  55. extern int mpc85xx_pci2_busno;
  56. static int mpc85xx_exclude_device(u_char bus, u_char devfn)
  57. {
  58. if (bus == 0 && PCI_SLOT(devfn) == 0)
  59. return PCIBIOS_DEVICE_NOT_FOUND;
  60. if (mpc85xx_pci2_busno)
  61. if (bus == (mpc85xx_pci2_busno) && PCI_SLOT(devfn) == 0)
  62. return PCIBIOS_DEVICE_NOT_FOUND;
  63. /* We explicitly do not go past the Tundra 320 Bridge */
  64. if ((bus == 1) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  65. return PCIBIOS_DEVICE_NOT_FOUND;
  66. if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  67. return PCIBIOS_DEVICE_NOT_FOUND;
  68. else
  69. return PCIBIOS_SUCCESSFUL;
  70. }
  71. static void __init mpc85xx_cds_pcibios_fixup(void)
  72. {
  73. struct pci_dev *dev;
  74. u_char c;
  75. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  76. PCI_DEVICE_ID_VIA_82C586_1, NULL))) {
  77. /*
  78. * U-Boot does not set the enable bits
  79. * for the IDE device. Force them on here.
  80. */
  81. pci_read_config_byte(dev, 0x40, &c);
  82. c |= 0x03; /* IDE: Chip Enable Bits */
  83. pci_write_config_byte(dev, 0x40, c);
  84. /*
  85. * Since only primary interface works, force the
  86. * IDE function to standard primary IDE interrupt
  87. * w/ 8259 offset
  88. */
  89. dev->irq = 14;
  90. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  91. pci_dev_put(dev);
  92. }
  93. /*
  94. * Force legacy USB interrupt routing
  95. */
  96. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  97. PCI_DEVICE_ID_VIA_82C586_2, NULL))) {
  98. dev->irq = 10;
  99. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 10);
  100. pci_dev_put(dev);
  101. }
  102. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  103. PCI_DEVICE_ID_VIA_82C586_2, dev))) {
  104. dev->irq = 11;
  105. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  106. pci_dev_put(dev);
  107. }
  108. /* Now map all the PCI irqs */
  109. dev = NULL;
  110. for_each_pci_dev(dev)
  111. pci_read_irq_line(dev);
  112. }
  113. #ifdef CONFIG_PPC_I8259
  114. #warning The i8259 PIC support is currently broken
  115. static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
  116. {
  117. unsigned int cascade_irq = i8259_irq();
  118. if (cascade_irq != NO_IRQ)
  119. generic_handle_irq(cascade_irq);
  120. desc->chip->eoi(irq);
  121. }
  122. #endif /* PPC_I8259 */
  123. #endif /* CONFIG_PCI */
  124. static void __init mpc85xx_cds_pic_init(void)
  125. {
  126. struct mpic *mpic;
  127. struct resource r;
  128. struct device_node *np = NULL;
  129. #ifdef CONFIG_PPC_I8259
  130. struct device_node *cascade_node = NULL;
  131. int cascade_irq;
  132. #endif
  133. np = of_find_node_by_type(np, "open-pic");
  134. if (np == NULL) {
  135. printk(KERN_ERR "Could not find open-pic node\n");
  136. return;
  137. }
  138. if (of_address_to_resource(np, 0, &r)) {
  139. printk(KERN_ERR "Failed to map mpic register space\n");
  140. of_node_put(np);
  141. return;
  142. }
  143. mpic = mpic_alloc(np, r.start,
  144. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  145. 4, 0, " OpenPIC ");
  146. BUG_ON(mpic == NULL);
  147. /* Return the mpic node */
  148. of_node_put(np);
  149. mpic_assign_isu(mpic, 0, r.start + 0x10200);
  150. mpic_assign_isu(mpic, 1, r.start + 0x10280);
  151. mpic_assign_isu(mpic, 2, r.start + 0x10300);
  152. mpic_assign_isu(mpic, 3, r.start + 0x10380);
  153. mpic_assign_isu(mpic, 4, r.start + 0x10400);
  154. mpic_assign_isu(mpic, 5, r.start + 0x10480);
  155. mpic_assign_isu(mpic, 6, r.start + 0x10500);
  156. mpic_assign_isu(mpic, 7, r.start + 0x10580);
  157. /* Used only for 8548 so far, but no harm in
  158. * allocating them for everyone */
  159. mpic_assign_isu(mpic, 8, r.start + 0x10600);
  160. mpic_assign_isu(mpic, 9, r.start + 0x10680);
  161. mpic_assign_isu(mpic, 10, r.start + 0x10700);
  162. mpic_assign_isu(mpic, 11, r.start + 0x10780);
  163. /* External Interrupts */
  164. mpic_assign_isu(mpic, 12, r.start + 0x10000);
  165. mpic_assign_isu(mpic, 13, r.start + 0x10080);
  166. mpic_assign_isu(mpic, 14, r.start + 0x10100);
  167. mpic_init(mpic);
  168. #ifdef CONFIG_PPC_I8259
  169. /* Initialize the i8259 controller */
  170. for_each_node_by_type(np, "interrupt-controller")
  171. if (of_device_is_compatible(np, "chrp,iic")) {
  172. cascade_node = np;
  173. break;
  174. }
  175. if (cascade_node == NULL) {
  176. printk(KERN_DEBUG "Could not find i8259 PIC\n");
  177. return;
  178. }
  179. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  180. if (cascade_irq == NO_IRQ) {
  181. printk(KERN_ERR "Failed to map cascade interrupt\n");
  182. return;
  183. }
  184. i8259_init(cascade_node, 0);
  185. of_node_put(cascade_node);
  186. set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
  187. #endif /* CONFIG_PPC_I8259 */
  188. }
  189. /*
  190. * Setup the architecture
  191. */
  192. static void __init mpc85xx_cds_setup_arch(void)
  193. {
  194. struct device_node *cpu;
  195. #ifdef CONFIG_PCI
  196. struct device_node *np;
  197. #endif
  198. if (ppc_md.progress)
  199. ppc_md.progress("mpc85xx_cds_setup_arch()", 0);
  200. cpu = of_find_node_by_type(NULL, "cpu");
  201. if (cpu != 0) {
  202. const unsigned int *fp;
  203. fp = of_get_property(cpu, "clock-frequency", NULL);
  204. if (fp != 0)
  205. loops_per_jiffy = *fp / HZ;
  206. else
  207. loops_per_jiffy = 500000000 / HZ;
  208. of_node_put(cpu);
  209. }
  210. cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
  211. cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
  212. if (ppc_md.progress) {
  213. char buf[40];
  214. snprintf(buf, 40, "CDS Version = 0x%x in slot %d\n",
  215. cadmus[CM_VER], cds_pci_slot);
  216. ppc_md.progress(buf, 0);
  217. }
  218. #ifdef CONFIG_PCI
  219. for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
  220. add_bridge(np);
  221. ppc_md.pcibios_fixup = mpc85xx_cds_pcibios_fixup;
  222. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  223. #endif
  224. }
  225. static void mpc85xx_cds_show_cpuinfo(struct seq_file *m)
  226. {
  227. uint pvid, svid, phid1;
  228. uint memsize = total_memory;
  229. pvid = mfspr(SPRN_PVR);
  230. svid = mfspr(SPRN_SVR);
  231. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  232. seq_printf(m, "Machine\t\t: MPC85xx CDS (0x%x)\n", cadmus[CM_VER]);
  233. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  234. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  235. /* Display cpu Pll setting */
  236. phid1 = mfspr(SPRN_HID1);
  237. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  238. /* Display the amount of memory */
  239. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  240. }
  241. /*
  242. * Called very early, device-tree isn't unflattened
  243. */
  244. static int __init mpc85xx_cds_probe(void)
  245. {
  246. unsigned long root = of_get_flat_dt_root();
  247. return of_flat_dt_is_compatible(root, "MPC85xxCDS");
  248. }
  249. define_machine(mpc85xx_cds) {
  250. .name = "MPC85xx CDS",
  251. .probe = mpc85xx_cds_probe,
  252. .setup_arch = mpc85xx_cds_setup_arch,
  253. .init_IRQ = mpc85xx_cds_pic_init,
  254. .show_cpuinfo = mpc85xx_cds_show_cpuinfo,
  255. .get_irq = mpic_get_irq,
  256. .restart = mpc85xx_restart,
  257. .calibrate_decr = generic_calibrate_decr,
  258. .progress = udbg_progress,
  259. };