mpc85xx_cds.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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/config.h>
  14. #include <linux/stddef.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/reboot.h>
  19. #include <linux/pci.h>
  20. #include <linux/kdev_t.h>
  21. #include <linux/major.h>
  22. #include <linux/console.h>
  23. #include <linux/delay.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/root_dev.h>
  26. #include <linux/initrd.h>
  27. #include <linux/module.h>
  28. #include <linux/fsl_devices.h>
  29. #include <asm/system.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/page.h>
  32. #include <asm/atomic.h>
  33. #include <asm/time.h>
  34. #include <asm/io.h>
  35. #include <asm/machdep.h>
  36. #include <asm/ipic.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/pci-bridge.h>
  39. #include <asm/mpc85xx.h>
  40. #include <asm/irq.h>
  41. #include <mm/mmu_decl.h>
  42. #include <asm/prom.h>
  43. #include <asm/udbg.h>
  44. #include <asm/mpic.h>
  45. #include <asm/i8259.h>
  46. #include <sysdev/fsl_soc.h>
  47. #include "mpc85xx.h"
  48. #ifndef CONFIG_PCI
  49. unsigned long isa_io_base = 0;
  50. unsigned long isa_mem_base = 0;
  51. #endif
  52. static int cds_pci_slot = 2;
  53. static volatile u8 *cadmus;
  54. /*
  55. * Internal interrupts are all Level Sensitive, and Positive Polarity
  56. *
  57. * Note: Likely, this table and the following function should be
  58. * obtained and derived from the OF Device Tree.
  59. */
  60. static u_char mpc85xx_cds_openpic_initsenses[] __initdata = {
  61. MPC85XX_INTERNAL_IRQ_SENSES,
  62. #if defined(CONFIG_PCI)
  63. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* Ext 0: PCI slot 0 */
  64. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext 1: PCI slot 1 */
  65. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext 2: PCI slot 2 */
  66. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext 3: PCI slot 3 */
  67. #else
  68. 0x0, /* External 0: */
  69. 0x0, /* External 1: */
  70. 0x0, /* External 2: */
  71. 0x0, /* External 3: */
  72. #endif
  73. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* External 5: PHY */
  74. 0x0, /* External 6: */
  75. 0x0, /* External 7: */
  76. 0x0, /* External 8: */
  77. 0x0, /* External 9: */
  78. 0x0, /* External 10: */
  79. #ifdef CONFIG_PCI
  80. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext 11: PCI2 slot 0 */
  81. #else
  82. 0x0, /* External 11: */
  83. #endif
  84. };
  85. #ifdef CONFIG_PCI
  86. /*
  87. * interrupt routing
  88. */
  89. int
  90. mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  91. {
  92. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  93. if (!hose->index)
  94. {
  95. /* Handle PCI1 interrupts */
  96. char pci_irq_table[][4] =
  97. /*
  98. * PCI IDSEL/INTPIN->INTLINE
  99. * A B C D
  100. */
  101. /* Note IRQ assignment for slots is based on which slot the elysium is
  102. * in -- in this setup elysium is in slot #2 (this PIRQA as first
  103. * interrupt on slot */
  104. {
  105. { 0, 1, 2, 3 }, /* 16 - PMC */
  106. { 0, 1, 2, 3 }, /* 17 P2P (Tsi320) */
  107. { 0, 1, 2, 3 }, /* 18 - Slot 1 */
  108. { 1, 2, 3, 0 }, /* 19 - Slot 2 */
  109. { 2, 3, 0, 1 }, /* 20 - Slot 3 */
  110. { 3, 0, 1, 2 }, /* 21 - Slot 4 */
  111. };
  112. const long min_idsel = 16, max_idsel = 21, irqs_per_slot = 4;
  113. int i, j;
  114. for (i = 0; i < 6; i++)
  115. for (j = 0; j < 4; j++)
  116. pci_irq_table[i][j] =
  117. ((pci_irq_table[i][j] + 5 -
  118. cds_pci_slot) & 0x3) + PIRQ0A;
  119. return PCI_IRQ_TABLE_LOOKUP;
  120. } else {
  121. /* Handle PCI2 interrupts (if we have one) */
  122. char pci_irq_table[][4] =
  123. {
  124. /*
  125. * We only have one slot and one interrupt
  126. * going to PIRQA - PIRQD */
  127. { PIRQ1A, PIRQ1A, PIRQ1A, PIRQ1A }, /* 21 - slot 0 */
  128. };
  129. const long min_idsel = 21, max_idsel = 21, irqs_per_slot = 4;
  130. return PCI_IRQ_TABLE_LOOKUP;
  131. }
  132. }
  133. #define ARCADIA_HOST_BRIDGE_IDSEL 17
  134. #define ARCADIA_2ND_BRIDGE_IDSEL 3
  135. extern int mpc85xx_pci2_busno;
  136. int
  137. mpc85xx_exclude_device(u_char bus, u_char devfn)
  138. {
  139. if (bus == 0 && PCI_SLOT(devfn) == 0)
  140. return PCIBIOS_DEVICE_NOT_FOUND;
  141. if (mpc85xx_pci2_busno)
  142. if (bus == (mpc85xx_pci2_busno) && PCI_SLOT(devfn) == 0)
  143. return PCIBIOS_DEVICE_NOT_FOUND;
  144. /* We explicitly do not go past the Tundra 320 Bridge */
  145. if ((bus == 1) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  146. return PCIBIOS_DEVICE_NOT_FOUND;
  147. if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  148. return PCIBIOS_DEVICE_NOT_FOUND;
  149. else
  150. return PCIBIOS_SUCCESSFUL;
  151. }
  152. void __init
  153. mpc85xx_cds_pcibios_fixup(void)
  154. {
  155. struct pci_dev *dev;
  156. u_char c;
  157. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  158. PCI_DEVICE_ID_VIA_82C586_1, NULL))) {
  159. /*
  160. * U-Boot does not set the enable bits
  161. * for the IDE device. Force them on here.
  162. */
  163. pci_read_config_byte(dev, 0x40, &c);
  164. c |= 0x03; /* IDE: Chip Enable Bits */
  165. pci_write_config_byte(dev, 0x40, c);
  166. /*
  167. * Since only primary interface works, force the
  168. * IDE function to standard primary IDE interrupt
  169. * w/ 8259 offset
  170. */
  171. dev->irq = 14;
  172. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  173. pci_dev_put(dev);
  174. }
  175. /*
  176. * Force legacy USB interrupt routing
  177. */
  178. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  179. PCI_DEVICE_ID_VIA_82C586_2, NULL))) {
  180. dev->irq = 10;
  181. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 10);
  182. pci_dev_put(dev);
  183. }
  184. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  185. PCI_DEVICE_ID_VIA_82C586_2, dev))) {
  186. dev->irq = 11;
  187. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  188. pci_dev_put(dev);
  189. }
  190. }
  191. #endif /* CONFIG_PCI */
  192. void __init mpc85xx_cds_pic_init(void)
  193. {
  194. struct mpic *mpic1;
  195. phys_addr_t OpenPIC_PAddr;
  196. /* Determine the Physical Address of the OpenPIC regs */
  197. OpenPIC_PAddr = get_immrbase() + MPC85xx_OPENPIC_OFFSET;
  198. mpic1 = mpic_alloc(OpenPIC_PAddr,
  199. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  200. 4, MPC85xx_OPENPIC_IRQ_OFFSET, 0, 250,
  201. mpc85xx_cds_openpic_initsenses,
  202. sizeof(mpc85xx_cds_openpic_initsenses), " OpenPIC ");
  203. BUG_ON(mpic1 == NULL);
  204. mpic_assign_isu(mpic1, 0, OpenPIC_PAddr + 0x10200);
  205. mpic_assign_isu(mpic1, 1, OpenPIC_PAddr + 0x10280);
  206. mpic_assign_isu(mpic1, 2, OpenPIC_PAddr + 0x10300);
  207. mpic_assign_isu(mpic1, 3, OpenPIC_PAddr + 0x10380);
  208. mpic_assign_isu(mpic1, 4, OpenPIC_PAddr + 0x10400);
  209. mpic_assign_isu(mpic1, 5, OpenPIC_PAddr + 0x10480);
  210. mpic_assign_isu(mpic1, 6, OpenPIC_PAddr + 0x10500);
  211. mpic_assign_isu(mpic1, 7, OpenPIC_PAddr + 0x10580);
  212. /* dummy mappings to get to 48 */
  213. mpic_assign_isu(mpic1, 8, OpenPIC_PAddr + 0x10600);
  214. mpic_assign_isu(mpic1, 9, OpenPIC_PAddr + 0x10680);
  215. mpic_assign_isu(mpic1, 10, OpenPIC_PAddr + 0x10700);
  216. mpic_assign_isu(mpic1, 11, OpenPIC_PAddr + 0x10780);
  217. /* External ints */
  218. mpic_assign_isu(mpic1, 12, OpenPIC_PAddr + 0x10000);
  219. mpic_assign_isu(mpic1, 13, OpenPIC_PAddr + 0x10080);
  220. mpic_assign_isu(mpic1, 14, OpenPIC_PAddr + 0x10100);
  221. mpic_init(mpic1);
  222. #ifdef CONFIG_PCI
  223. mpic_setup_cascade(PIRQ0A, i8259_irq_cascade, NULL);
  224. i8259_init(0,0);
  225. #endif
  226. }
  227. /*
  228. * Setup the architecture
  229. */
  230. static void __init
  231. mpc85xx_cds_setup_arch(void)
  232. {
  233. struct device_node *cpu;
  234. #ifdef CONFIG_PCI
  235. struct device_node *np;
  236. #endif
  237. if (ppc_md.progress)
  238. ppc_md.progress("mpc85xx_cds_setup_arch()", 0);
  239. cpu = of_find_node_by_type(NULL, "cpu");
  240. if (cpu != 0) {
  241. unsigned int *fp;
  242. fp = (int *)get_property(cpu, "clock-frequency", NULL);
  243. if (fp != 0)
  244. loops_per_jiffy = *fp / HZ;
  245. else
  246. loops_per_jiffy = 500000000 / HZ;
  247. of_node_put(cpu);
  248. }
  249. cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
  250. cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
  251. if (ppc_md.progress) {
  252. char buf[40];
  253. snprintf(buf, 40, "CDS Version = 0x%x in slot %d\n",
  254. cadmus[CM_VER], cds_pci_slot);
  255. ppc_md.progress(buf, 0);
  256. }
  257. #ifdef CONFIG_PCI
  258. for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
  259. add_bridge(np);
  260. ppc_md.pcibios_fixup = mpc85xx_cds_pcibios_fixup;
  261. ppc_md.pci_swizzle = common_swizzle;
  262. ppc_md.pci_map_irq = mpc85xx_map_irq;
  263. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  264. #endif
  265. #ifdef CONFIG_ROOT_NFS
  266. ROOT_DEV = Root_NFS;
  267. #else
  268. ROOT_DEV = Root_HDA1;
  269. #endif
  270. }
  271. void
  272. mpc85xx_cds_show_cpuinfo(struct seq_file *m)
  273. {
  274. uint pvid, svid, phid1;
  275. uint memsize = total_memory;
  276. pvid = mfspr(SPRN_PVR);
  277. svid = mfspr(SPRN_SVR);
  278. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  279. seq_printf(m, "Machine\t\t: MPC85xx CDS (0x%x)\n", cadmus[CM_VER]);
  280. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  281. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  282. /* Display cpu Pll setting */
  283. phid1 = mfspr(SPRN_HID1);
  284. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  285. /* Display the amount of memory */
  286. seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
  287. }
  288. /*
  289. * Called very early, device-tree isn't unflattened
  290. */
  291. static int __init mpc85xx_cds_probe(void)
  292. {
  293. /* We always match for now, eventually we should look at
  294. * the flat dev tree to ensure this is the board we are
  295. * supposed to run on
  296. */
  297. return 1;
  298. }
  299. define_machine(mpc85xx_cds) {
  300. .name = "MPC85xx CDS",
  301. .probe = mpc85xx_cds_probe,
  302. .setup_arch = mpc85xx_cds_setup_arch,
  303. .init_IRQ = mpc85xx_cds_pic_init,
  304. .show_cpuinfo = mpc85xx_cds_show_cpuinfo,
  305. .get_irq = mpic_get_irq,
  306. .restart = mpc85xx_restart,
  307. .calibrate_decr = generic_calibrate_decr,
  308. .progress = udbg_progress,
  309. };