mpc85xx_cds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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, 2011-2012 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/interrupt.h>
  26. #include <linux/fsl_devices.h>
  27. #include <linux/of_platform.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/page.h>
  30. #include <linux/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/pci-bridge.h>
  36. #include <asm/irq.h>
  37. #include <mm/mmu_decl.h>
  38. #include <asm/prom.h>
  39. #include <asm/udbg.h>
  40. #include <asm/mpic.h>
  41. #include <asm/i8259.h>
  42. #include <sysdev/fsl_soc.h>
  43. #include <sysdev/fsl_pci.h>
  44. #include "mpc85xx.h"
  45. /*
  46. * The CDS board contains an FPGA/CPLD called "Cadmus", which collects
  47. * various logic and performs system control functions.
  48. * Here is the FPGA/CPLD register map.
  49. */
  50. struct cadmus_reg {
  51. u8 cm_ver; /* Board version */
  52. u8 cm_csr; /* General control/status */
  53. u8 cm_rst; /* Reset control */
  54. u8 cm_hsclk; /* High speed clock */
  55. u8 cm_hsxclk; /* High speed clock extended */
  56. u8 cm_led; /* LED data */
  57. u8 cm_pci; /* PCI control/status */
  58. u8 cm_dma; /* DMA control */
  59. u8 res[248]; /* Total 256 bytes */
  60. };
  61. static struct cadmus_reg *cadmus;
  62. #ifdef CONFIG_PCI
  63. #define ARCADIA_HOST_BRIDGE_IDSEL 17
  64. #define ARCADIA_2ND_BRIDGE_IDSEL 3
  65. static int mpc85xx_exclude_device(struct pci_controller *hose,
  66. u_char bus, u_char devfn)
  67. {
  68. /* We explicitly do not go past the Tundra 320 Bridge */
  69. if ((bus == 1) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  70. return PCIBIOS_DEVICE_NOT_FOUND;
  71. if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
  72. return PCIBIOS_DEVICE_NOT_FOUND;
  73. else
  74. return PCIBIOS_SUCCESSFUL;
  75. }
  76. static int mpc85xx_cds_restart(struct notifier_block *this,
  77. unsigned long mode, void *cmd)
  78. {
  79. struct pci_dev *dev;
  80. u_char tmp;
  81. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
  82. NULL))) {
  83. /* Use the VIA Super Southbridge to force a PCI reset */
  84. pci_read_config_byte(dev, 0x47, &tmp);
  85. pci_write_config_byte(dev, 0x47, tmp | 1);
  86. /* Flush the outbound PCI write queues */
  87. pci_read_config_byte(dev, 0x47, &tmp);
  88. /*
  89. * At this point, the hardware reset should have triggered.
  90. * However, if it doesn't work for some mysterious reason,
  91. * just fall through to the default reset below.
  92. */
  93. pci_dev_put(dev);
  94. }
  95. /*
  96. * If we can't find the VIA chip (maybe the P2P bridge is
  97. * disabled) or the VIA chip reset didn't work, just return
  98. * and let default reset sequence happen.
  99. */
  100. return NOTIFY_DONE;
  101. }
  102. static int mpc85xx_cds_restart_register(void)
  103. {
  104. static struct notifier_block restart_handler;
  105. restart_handler.notifier_call = mpc85xx_cds_restart;
  106. restart_handler.priority = 192;
  107. return register_restart_handler(&restart_handler);
  108. }
  109. machine_arch_initcall(mpc85xx_cds, mpc85xx_cds_restart_register);
  110. static void __init mpc85xx_cds_pci_irq_fixup(struct pci_dev *dev)
  111. {
  112. u_char c;
  113. if (dev->vendor == PCI_VENDOR_ID_VIA) {
  114. switch (dev->device) {
  115. case PCI_DEVICE_ID_VIA_82C586_1:
  116. /*
  117. * U-Boot does not set the enable bits
  118. * for the IDE device. Force them on here.
  119. */
  120. pci_read_config_byte(dev, 0x40, &c);
  121. c |= 0x03; /* IDE: Chip Enable Bits */
  122. pci_write_config_byte(dev, 0x40, c);
  123. /*
  124. * Since only primary interface works, force the
  125. * IDE function to standard primary IDE interrupt
  126. * w/ 8259 offset
  127. */
  128. dev->irq = 14;
  129. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  130. break;
  131. /*
  132. * Force legacy USB interrupt routing
  133. */
  134. case PCI_DEVICE_ID_VIA_82C586_2:
  135. /* There are two USB controllers.
  136. * Identify them by functon number
  137. */
  138. if (PCI_FUNC(dev->devfn) == 3)
  139. dev->irq = 11;
  140. else
  141. dev->irq = 10;
  142. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  143. default:
  144. break;
  145. }
  146. }
  147. }
  148. static void skip_fake_bridge(struct pci_dev *dev)
  149. {
  150. /* Make it an error to skip the fake bridge
  151. * in pci_setup_device() in probe.c */
  152. dev->hdr_type = 0x7f;
  153. }
  154. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x3fff, skip_fake_bridge);
  155. DECLARE_PCI_FIXUP_EARLY(0x3fff, 0x1957, skip_fake_bridge);
  156. DECLARE_PCI_FIXUP_EARLY(0xff3f, 0x5719, skip_fake_bridge);
  157. #define PCI_DEVICE_ID_IDT_TSI310 0x01a7
  158. /*
  159. * Fix Tsi310 PCI-X bridge resource.
  160. * Force the bridge to open a window from 0x0000-0x1fff in PCI I/O space.
  161. * This allows legacy I/O(i8259, etc) on the VIA southbridge to be accessed.
  162. */
  163. void mpc85xx_cds_fixup_bus(struct pci_bus *bus)
  164. {
  165. struct pci_dev *dev = bus->self;
  166. struct resource *res = bus->resource[0];
  167. if (dev != NULL &&
  168. dev->vendor == PCI_VENDOR_ID_IBM &&
  169. dev->device == PCI_DEVICE_ID_IDT_TSI310) {
  170. if (res) {
  171. res->start = 0;
  172. res->end = 0x1fff;
  173. res->flags = IORESOURCE_IO;
  174. pr_info("mpc85xx_cds: PCI bridge resource fixup applied\n");
  175. pr_info("mpc85xx_cds: %pR\n", res);
  176. }
  177. }
  178. fsl_pcibios_fixup_bus(bus);
  179. }
  180. #ifdef CONFIG_PPC_I8259
  181. static void mpc85xx_8259_cascade_handler(struct irq_desc *desc)
  182. {
  183. unsigned int cascade_irq = i8259_irq();
  184. if (cascade_irq)
  185. /* handle an interrupt from the 8259 */
  186. generic_handle_irq(cascade_irq);
  187. /* check for any interrupts from the shared IRQ line */
  188. handle_fasteoi_irq(desc);
  189. }
  190. static irqreturn_t mpc85xx_8259_cascade_action(int irq, void *dev_id)
  191. {
  192. return IRQ_HANDLED;
  193. }
  194. static struct irqaction mpc85xxcds_8259_irqaction = {
  195. .handler = mpc85xx_8259_cascade_action,
  196. .flags = IRQF_SHARED | IRQF_NO_THREAD,
  197. .name = "8259 cascade",
  198. };
  199. #endif /* PPC_I8259 */
  200. #endif /* CONFIG_PCI */
  201. static void __init mpc85xx_cds_pic_init(void)
  202. {
  203. struct mpic *mpic;
  204. mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN,
  205. 0, 256, " OpenPIC ");
  206. BUG_ON(mpic == NULL);
  207. mpic_init(mpic);
  208. }
  209. #if defined(CONFIG_PPC_I8259) && defined(CONFIG_PCI)
  210. static int mpc85xx_cds_8259_attach(void)
  211. {
  212. int ret;
  213. struct device_node *np = NULL;
  214. struct device_node *cascade_node = NULL;
  215. int cascade_irq;
  216. /* Initialize the i8259 controller */
  217. for_each_node_by_type(np, "interrupt-controller")
  218. if (of_device_is_compatible(np, "chrp,iic")) {
  219. cascade_node = np;
  220. break;
  221. }
  222. if (cascade_node == NULL) {
  223. printk(KERN_DEBUG "Could not find i8259 PIC\n");
  224. return -ENODEV;
  225. }
  226. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  227. if (!cascade_irq) {
  228. printk(KERN_ERR "Failed to map cascade interrupt\n");
  229. return -ENXIO;
  230. }
  231. i8259_init(cascade_node, 0);
  232. of_node_put(cascade_node);
  233. /*
  234. * Hook the interrupt to make sure desc->action is never NULL.
  235. * This is required to ensure that the interrupt does not get
  236. * disabled when the last user of the shared IRQ line frees their
  237. * interrupt.
  238. */
  239. if ((ret = setup_irq(cascade_irq, &mpc85xxcds_8259_irqaction))) {
  240. printk(KERN_ERR "Failed to setup cascade interrupt\n");
  241. return ret;
  242. }
  243. /* Success. Connect our low-level cascade handler. */
  244. irq_set_handler(cascade_irq, mpc85xx_8259_cascade_handler);
  245. return 0;
  246. }
  247. machine_device_initcall(mpc85xx_cds, mpc85xx_cds_8259_attach);
  248. #endif /* CONFIG_PPC_I8259 */
  249. static void mpc85xx_cds_pci_assign_primary(void)
  250. {
  251. #ifdef CONFIG_PCI
  252. struct device_node *np;
  253. if (fsl_pci_primary)
  254. return;
  255. /*
  256. * MPC85xx_CDS has ISA bridge but unfortunately there is no
  257. * isa node in device tree. We now looking for i8259 node as
  258. * a workaround for such a broken device tree. This routine
  259. * is for complying to all device trees.
  260. */
  261. np = of_find_node_by_name(NULL, "i8259");
  262. while ((fsl_pci_primary = of_get_parent(np))) {
  263. of_node_put(np);
  264. np = fsl_pci_primary;
  265. if ((of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  266. of_device_is_compatible(np, "fsl,mpc8548-pcie")) &&
  267. of_device_is_available(np))
  268. return;
  269. }
  270. #endif
  271. }
  272. /*
  273. * Setup the architecture
  274. */
  275. static void __init mpc85xx_cds_setup_arch(void)
  276. {
  277. struct device_node *np;
  278. int cds_pci_slot;
  279. if (ppc_md.progress)
  280. ppc_md.progress("mpc85xx_cds_setup_arch()", 0);
  281. np = of_find_compatible_node(NULL, NULL, "fsl,mpc8548cds-fpga");
  282. if (!np) {
  283. pr_err("Could not find FPGA node.\n");
  284. return;
  285. }
  286. cadmus = of_iomap(np, 0);
  287. of_node_put(np);
  288. if (!cadmus) {
  289. pr_err("Fail to map FPGA area.\n");
  290. return;
  291. }
  292. if (ppc_md.progress) {
  293. char buf[40];
  294. cds_pci_slot = ((in_8(&cadmus->cm_csr) >> 6) & 0x3) + 1;
  295. snprintf(buf, 40, "CDS Version = 0x%x in slot %d\n",
  296. in_8(&cadmus->cm_ver), cds_pci_slot);
  297. ppc_md.progress(buf, 0);
  298. }
  299. #ifdef CONFIG_PCI
  300. ppc_md.pci_irq_fixup = mpc85xx_cds_pci_irq_fixup;
  301. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  302. #endif
  303. mpc85xx_cds_pci_assign_primary();
  304. fsl_pci_assign_primary();
  305. }
  306. static void mpc85xx_cds_show_cpuinfo(struct seq_file *m)
  307. {
  308. uint pvid, svid, phid1;
  309. pvid = mfspr(SPRN_PVR);
  310. svid = mfspr(SPRN_SVR);
  311. seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
  312. seq_printf(m, "Machine\t\t: MPC85xx CDS (0x%x)\n",
  313. in_8(&cadmus->cm_ver));
  314. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  315. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  316. /* Display cpu Pll setting */
  317. phid1 = mfspr(SPRN_HID1);
  318. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  319. }
  320. /*
  321. * Called very early, device-tree isn't unflattened
  322. */
  323. static int __init mpc85xx_cds_probe(void)
  324. {
  325. return of_machine_is_compatible("MPC85xxCDS");
  326. }
  327. machine_arch_initcall(mpc85xx_cds, mpc85xx_common_publish_devices);
  328. define_machine(mpc85xx_cds) {
  329. .name = "MPC85xx CDS",
  330. .probe = mpc85xx_cds_probe,
  331. .setup_arch = mpc85xx_cds_setup_arch,
  332. .init_IRQ = mpc85xx_cds_pic_init,
  333. .show_cpuinfo = mpc85xx_cds_show_cpuinfo,
  334. .get_irq = mpic_get_irq,
  335. #ifdef CONFIG_PCI
  336. .pcibios_fixup_bus = mpc85xx_cds_fixup_bus,
  337. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  338. #endif
  339. .calibrate_decr = generic_calibrate_decr,
  340. .progress = udbg_progress,
  341. };