/arch/powerpc/platforms/85xx/mpc85xx_cds.c

http://github.com/mirrors/linux · C · 395 lines · 264 code · 60 blank · 71 comment · 34 complexity · 2367034f4e74edd7ff0cfe1641980ff6 MD5 · raw file

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