mpc85xx_cds.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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/interrupt.h>
  27. #include <linux/fsl_devices.h>
  28. #include <linux/of_platform.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/pci-bridge.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 <sysdev/fsl_pci.h>
  46. /* CADMUS info */
  47. /* xxx - galak, move into device tree */
  48. #define CADMUS_BASE (0xf8004000)
  49. #define CADMUS_SIZE (256)
  50. #define CM_VER (0)
  51. #define CM_CSR (1)
  52. #define CM_RST (2)
  53. static int cds_pci_slot = 2;
  54. static volatile u8 *cadmus;
  55. #ifdef CONFIG_PCI
  56. #define ARCADIA_HOST_BRIDGE_IDSEL 17
  57. #define ARCADIA_2ND_BRIDGE_IDSEL 3
  58. static int mpc85xx_exclude_device(struct pci_controller *hose,
  59. u_char bus, u_char devfn)
  60. {
  61. /* We explicitly do not go past the Tundra 320 Bridge */
  62. if ((bus == 1) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  63. return PCIBIOS_DEVICE_NOT_FOUND;
  64. if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  65. return PCIBIOS_DEVICE_NOT_FOUND;
  66. else
  67. return PCIBIOS_SUCCESSFUL;
  68. }
  69. static void mpc85xx_cds_restart(char *cmd)
  70. {
  71. struct pci_dev *dev;
  72. u_char tmp;
  73. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
  74. NULL))) {
  75. /* Use the VIA Super Southbridge to force a PCI reset */
  76. pci_read_config_byte(dev, 0x47, &tmp);
  77. pci_write_config_byte(dev, 0x47, tmp | 1);
  78. /* Flush the outbound PCI write queues */
  79. pci_read_config_byte(dev, 0x47, &tmp);
  80. /*
  81. * At this point, the harware reset should have triggered.
  82. * However, if it doesn't work for some mysterious reason,
  83. * just fall through to the default reset below.
  84. */
  85. pci_dev_put(dev);
  86. }
  87. /*
  88. * If we can't find the VIA chip (maybe the P2P bridge is disabled)
  89. * or the VIA chip reset didn't work, just use the default reset.
  90. */
  91. fsl_rstcr_restart(NULL);
  92. }
  93. static void __init mpc85xx_cds_pci_irq_fixup(struct pci_dev *dev)
  94. {
  95. u_char c;
  96. if (dev->vendor == PCI_VENDOR_ID_VIA) {
  97. switch (dev->device) {
  98. case PCI_DEVICE_ID_VIA_82C586_1:
  99. /*
  100. * U-Boot does not set the enable bits
  101. * for the IDE device. Force them on here.
  102. */
  103. pci_read_config_byte(dev, 0x40, &c);
  104. c |= 0x03; /* IDE: Chip Enable Bits */
  105. pci_write_config_byte(dev, 0x40, c);
  106. /*
  107. * Since only primary interface works, force the
  108. * IDE function to standard primary IDE interrupt
  109. * w/ 8259 offset
  110. */
  111. dev->irq = 14;
  112. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  113. break;
  114. /*
  115. * Force legacy USB interrupt routing
  116. */
  117. case PCI_DEVICE_ID_VIA_82C586_2:
  118. /* There are two USB controllers.
  119. * Identify them by functon number
  120. */
  121. if (PCI_FUNC(dev->devfn) == 3)
  122. dev->irq = 11;
  123. else
  124. dev->irq = 10;
  125. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  126. default:
  127. break;
  128. }
  129. }
  130. }
  131. static void __devinit skip_fake_bridge(struct pci_dev *dev)
  132. {
  133. /* Make it an error to skip the fake bridge
  134. * in pci_setup_device() in probe.c */
  135. dev->hdr_type = 0x7f;
  136. }
  137. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x3fff, skip_fake_bridge);
  138. DECLARE_PCI_FIXUP_EARLY(0x3fff, 0x1957, skip_fake_bridge);
  139. DECLARE_PCI_FIXUP_EARLY(0xff3f, 0x5719, skip_fake_bridge);
  140. #ifdef CONFIG_PPC_I8259
  141. static void mpc85xx_8259_cascade_handler(unsigned int irq,
  142. struct irq_desc *desc)
  143. {
  144. unsigned int cascade_irq = i8259_irq();
  145. if (cascade_irq != NO_IRQ)
  146. /* handle an interrupt from the 8259 */
  147. generic_handle_irq(cascade_irq);
  148. /* check for any interrupts from the shared IRQ line */
  149. handle_fasteoi_irq(irq, desc);
  150. }
  151. static irqreturn_t mpc85xx_8259_cascade_action(int irq, void *dev_id)
  152. {
  153. return IRQ_HANDLED;
  154. }
  155. static struct irqaction mpc85xxcds_8259_irqaction = {
  156. .handler = mpc85xx_8259_cascade_action,
  157. .flags = IRQF_SHARED,
  158. .name = "8259 cascade",
  159. };
  160. #endif /* PPC_I8259 */
  161. #endif /* CONFIG_PCI */
  162. static void __init mpc85xx_cds_pic_init(void)
  163. {
  164. struct mpic *mpic;
  165. struct resource r;
  166. struct device_node *np = NULL;
  167. np = of_find_node_by_type(np, "open-pic");
  168. if (np == NULL) {
  169. printk(KERN_ERR "Could not find open-pic node\n");
  170. return;
  171. }
  172. if (of_address_to_resource(np, 0, &r)) {
  173. printk(KERN_ERR "Failed to map mpic register space\n");
  174. of_node_put(np);
  175. return;
  176. }
  177. mpic = mpic_alloc(np, r.start,
  178. MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
  179. 0, 256, " OpenPIC ");
  180. BUG_ON(mpic == NULL);
  181. /* Return the mpic node */
  182. of_node_put(np);
  183. mpic_init(mpic);
  184. }
  185. #if defined(CONFIG_PPC_I8259) && defined(CONFIG_PCI)
  186. static int mpc85xx_cds_8259_attach(void)
  187. {
  188. int ret;
  189. struct device_node *np = NULL;
  190. struct device_node *cascade_node = NULL;
  191. int cascade_irq;
  192. /* Initialize the i8259 controller */
  193. for_each_node_by_type(np, "interrupt-controller")
  194. if (of_device_is_compatible(np, "chrp,iic")) {
  195. cascade_node = np;
  196. break;
  197. }
  198. if (cascade_node == NULL) {
  199. printk(KERN_DEBUG "Could not find i8259 PIC\n");
  200. return -ENODEV;
  201. }
  202. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  203. if (cascade_irq == NO_IRQ) {
  204. printk(KERN_ERR "Failed to map cascade interrupt\n");
  205. return -ENXIO;
  206. }
  207. i8259_init(cascade_node, 0);
  208. of_node_put(cascade_node);
  209. /*
  210. * Hook the interrupt to make sure desc->action is never NULL.
  211. * This is required to ensure that the interrupt does not get
  212. * disabled when the last user of the shared IRQ line frees their
  213. * interrupt.
  214. */
  215. if ((ret = setup_irq(cascade_irq, &mpc85xxcds_8259_irqaction))) {
  216. printk(KERN_ERR "Failed to setup cascade interrupt\n");
  217. return ret;
  218. }
  219. /* Success. Connect our low-level cascade handler. */
  220. set_irq_handler(cascade_irq, mpc85xx_8259_cascade_handler);
  221. return 0;
  222. }
  223. machine_device_initcall(mpc85xx_cds, mpc85xx_cds_8259_attach);
  224. #endif /* CONFIG_PPC_I8259 */
  225. /*
  226. * Setup the architecture
  227. */
  228. static void __init mpc85xx_cds_setup_arch(void)
  229. {
  230. #ifdef CONFIG_PCI
  231. struct device_node *np;
  232. #endif
  233. if (ppc_md.progress)
  234. ppc_md.progress("mpc85xx_cds_setup_arch()", 0);
  235. cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
  236. cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
  237. if (ppc_md.progress) {
  238. char buf[40];
  239. snprintf(buf, 40, "CDS Version = 0x%x in slot %d\n",
  240. cadmus[CM_VER], cds_pci_slot);
  241. ppc_md.progress(buf, 0);
  242. }
  243. #ifdef CONFIG_PCI
  244. for_each_node_by_type(np, "pci") {
  245. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  246. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  247. struct resource rsrc;
  248. of_address_to_resource(np, 0, &rsrc);
  249. if ((rsrc.start & 0xfffff) == 0x8000)
  250. fsl_add_bridge(np, 1);
  251. else
  252. fsl_add_bridge(np, 0);
  253. }
  254. }
  255. ppc_md.pci_irq_fixup = mpc85xx_cds_pci_irq_fixup;
  256. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  257. #endif
  258. }
  259. static void mpc85xx_cds_show_cpuinfo(struct seq_file *m)
  260. {
  261. uint pvid, svid, phid1;
  262. pvid = mfspr(SPRN_PVR);
  263. svid = mfspr(SPRN_SVR);
  264. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  265. seq_printf(m, "Machine\t\t: MPC85xx CDS (0x%x)\n", cadmus[CM_VER]);
  266. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  267. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  268. /* Display cpu Pll setting */
  269. phid1 = mfspr(SPRN_HID1);
  270. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  271. }
  272. /*
  273. * Called very early, device-tree isn't unflattened
  274. */
  275. static int __init mpc85xx_cds_probe(void)
  276. {
  277. unsigned long root = of_get_flat_dt_root();
  278. return of_flat_dt_is_compatible(root, "MPC85xxCDS");
  279. }
  280. static struct of_device_id __initdata of_bus_ids[] = {
  281. { .type = "soc", },
  282. { .compatible = "soc", },
  283. { .compatible = "simple-bus", },
  284. { .compatible = "gianfar", },
  285. {},
  286. };
  287. static int __init declare_of_platform_devices(void)
  288. {
  289. return of_platform_bus_probe(NULL, of_bus_ids, NULL);
  290. }
  291. machine_device_initcall(mpc85xx_cds, declare_of_platform_devices);
  292. define_machine(mpc85xx_cds) {
  293. .name = "MPC85xx CDS",
  294. .probe = mpc85xx_cds_probe,
  295. .setup_arch = mpc85xx_cds_setup_arch,
  296. .init_IRQ = mpc85xx_cds_pic_init,
  297. .show_cpuinfo = mpc85xx_cds_show_cpuinfo,
  298. .get_irq = mpic_get_irq,
  299. #ifdef CONFIG_PCI
  300. .restart = mpc85xx_cds_restart,
  301. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  302. #else
  303. .restart = fsl_rstcr_restart,
  304. #endif
  305. .calibrate_decr = generic_calibrate_decr,
  306. .progress = udbg_progress,
  307. };