blob: dfd8b4ad9b2854835ad27b9fe794a60b20537a81 [file] [log] [blame]
Jon Loeligerd93daf82007-03-20 11:19:10 -05001/*
Kumar Gala7f503822007-08-17 09:26:40 -05002 * MPC85xx DS Board Setup
Jon Loeligerd93daf82007-03-20 11:19:10 -05003 *
4 * Author Xianghua Xiao (x.xiao@freescale.com)
Roy Zangf16dab92007-07-13 18:05:08 +08005 * Roy Zang <tie-fei.zang@freescale.com>
6 * - Add PCI/PCI Exprees support
Jon Loeligerd93daf82007-03-20 11:19:10 -05007 * Copyright 2007 Freescale Semiconductor Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/stddef.h>
16#include <linux/kernel.h>
Roy Zangf16dab92007-07-13 18:05:08 +080017#include <linux/pci.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050018#include <linux/kdev_t.h>
19#include <linux/delay.h>
20#include <linux/seq_file.h>
Roy Zangf16dab92007-07-13 18:05:08 +080021#include <linux/interrupt.h>
Sebastian Siewior1028d4f2008-03-15 00:01:30 +010022#include <linux/of_platform.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050023
24#include <asm/system.h>
25#include <asm/time.h>
26#include <asm/machdep.h>
Roy Zangf16dab92007-07-13 18:05:08 +080027#include <asm/pci-bridge.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050028#include <mm/mmu_decl.h>
29#include <asm/prom.h>
30#include <asm/udbg.h>
31#include <asm/mpic.h>
32#include <asm/i8259.h>
33
34#include <sysdev/fsl_soc.h>
Roy Zangf16dab92007-07-13 18:05:08 +080035#include <sysdev/fsl_pci.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050036
37#undef DEBUG
38
39#ifdef DEBUG
Harvey Harrisone48b1b42008-03-29 08:21:07 +110040#define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
Jon Loeligerd93daf82007-03-20 11:19:10 -050041#else
42#define DBG(fmt, args...)
43#endif
44
Roy Zangf16dab92007-07-13 18:05:08 +080045#ifdef CONFIG_PPC_I8259
Kumar Gala7f503822007-08-17 09:26:40 -050046static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
Roy Zangf16dab92007-07-13 18:05:08 +080047{
48 unsigned int cascade_irq = i8259_irq();
49
50 if (cascade_irq != NO_IRQ) {
51 generic_handle_irq(cascade_irq);
52 }
53 desc->chip->eoi(irq);
54}
55#endif /* CONFIG_PPC_I8259 */
Jon Loeligerd93daf82007-03-20 11:19:10 -050056
Kumar Gala7f503822007-08-17 09:26:40 -050057void __init mpc85xx_ds_pic_init(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -050058{
59 struct mpic *mpic;
60 struct resource r;
61 struct device_node *np = NULL;
62#ifdef CONFIG_PPC_I8259
63 struct device_node *cascade_node = NULL;
64 int cascade_irq;
65#endif
66
67 np = of_find_node_by_type(np, "open-pic");
68
69 if (np == NULL) {
70 printk(KERN_ERR "Could not find open-pic node\n");
71 return;
72 }
73
74 if (of_address_to_resource(np, 0, &r)) {
75 printk(KERN_ERR "Failed to map mpic register space\n");
76 of_node_put(np);
77 return;
78 }
79
Jon Loeligerd93daf82007-03-20 11:19:10 -050080 mpic = mpic_alloc(np, r.start,
81 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
Kumar Galab533f8a2007-07-03 02:35:35 -050082 0, 256, " OpenPIC ");
Jon Loeligerd93daf82007-03-20 11:19:10 -050083 BUG_ON(mpic == NULL);
84
Jon Loeligerd93daf82007-03-20 11:19:10 -050085 mpic_init(mpic);
86
87#ifdef CONFIG_PPC_I8259
88 /* Initialize the i8259 controller */
89 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +100090 if (of_device_is_compatible(np, "chrp,iic")) {
Jon Loeligerd93daf82007-03-20 11:19:10 -050091 cascade_node = np;
92 break;
93 }
94
95 if (cascade_node == NULL) {
96 printk(KERN_DEBUG "Could not find i8259 PIC\n");
97 return;
98 }
99
100 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
101 if (cascade_irq == NO_IRQ) {
102 printk(KERN_ERR "Failed to map cascade interrupt\n");
103 return;
104 }
105
Kumar Gala7f503822007-08-17 09:26:40 -0500106 DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500107
108 i8259_init(cascade_node, 0);
109 of_node_put(cascade_node);
110
Kumar Gala7f503822007-08-17 09:26:40 -0500111 set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500112#endif /* CONFIG_PPC_I8259 */
113}
114
Roy Zangf16dab92007-07-13 18:05:08 +0800115#ifdef CONFIG_PCI
Kumar Gala7f503822007-08-17 09:26:40 -0500116static int primary_phb_addr;
Kumar Galab66510c2007-08-16 23:55:55 -0500117extern int uses_fsl_uli_m1575;
118extern int uli_exclude_device(struct pci_controller *hose,
119 u_char bus, u_char devfn);
Roy Zangf16dab92007-07-13 18:05:08 +0800120
Kumar Galab66510c2007-08-16 23:55:55 -0500121static int mpc85xx_exclude_device(struct pci_controller *hose,
122 u_char bus, u_char devfn)
Roy Zangf16dab92007-07-13 18:05:08 +0800123{
Kumar Gala7f503822007-08-17 09:26:40 -0500124 struct device_node* node;
Kumar Galab66510c2007-08-16 23:55:55 -0500125 struct resource rsrc;
Roy Zangf16dab92007-07-13 18:05:08 +0800126
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100127 node = hose->dn;
Kumar Galab66510c2007-08-16 23:55:55 -0500128 of_address_to_resource(node, 0, &rsrc);
Roy Zangf16dab92007-07-13 18:05:08 +0800129
Kumar Gala7f503822007-08-17 09:26:40 -0500130 if ((rsrc.start & 0xfffff) == primary_phb_addr) {
Kumar Galab66510c2007-08-16 23:55:55 -0500131 return uli_exclude_device(hose, bus, devfn);
132 }
133
134 return PCIBIOS_SUCCESSFUL;
Roy Zangf16dab92007-07-13 18:05:08 +0800135}
Roy Zangf16dab92007-07-13 18:05:08 +0800136#endif /* CONFIG_PCI */
Jon Loeligerd93daf82007-03-20 11:19:10 -0500137
138/*
139 * Setup the architecture
140 */
Kumar Gala7f503822007-08-17 09:26:40 -0500141static void __init mpc85xx_ds_setup_arch(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -0500142{
Roy Zangf16dab92007-07-13 18:05:08 +0800143#ifdef CONFIG_PCI
144 struct device_node *np;
145#endif
146
Jon Loeligerd93daf82007-03-20 11:19:10 -0500147 if (ppc_md.progress)
Kumar Gala7f503822007-08-17 09:26:40 -0500148 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500149
Roy Zangf16dab92007-07-13 18:05:08 +0800150#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500151 for_each_node_by_type(np, "pci") {
152 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
153 of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
154 struct resource rsrc;
155 of_address_to_resource(np, 0, &rsrc);
156 if ((rsrc.start & 0xfffff) == primary_phb_addr)
157 fsl_add_bridge(np, 1);
158 else
159 fsl_add_bridge(np, 0);
160 }
Roy Zangf16dab92007-07-13 18:05:08 +0800161 }
Kumar Galac9438af2007-10-04 00:28:43 -0500162
Kumar Galab66510c2007-08-16 23:55:55 -0500163 uses_fsl_uli_m1575 = 1;
164 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
Roy Zangf16dab92007-07-13 18:05:08 +0800165#endif
166
Kumar Gala7f503822007-08-17 09:26:40 -0500167 printk("MPC85xx DS board from Freescale Semiconductor\n");
Jon Loeligerd93daf82007-03-20 11:19:10 -0500168}
169
Jon Loeligerd93daf82007-03-20 11:19:10 -0500170/*
171 * Called very early, device-tree isn't unflattened
172 */
173static int __init mpc8544_ds_probe(void)
174{
175 unsigned long root = of_get_flat_dt_root();
176
Kumar Gala7f503822007-08-17 09:26:40 -0500177 if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
178#ifdef CONFIG_PCI
179 primary_phb_addr = 0xb000;
180#endif
181 return 1;
182 } else {
183 return 0;
184 }
Jon Loeligerd93daf82007-03-20 11:19:10 -0500185}
186
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100187static struct of_device_id mpc85xxds_ids[] = {
188 { .type = "soc", },
189 { .compatible = "soc", },
190 {},
191};
192
193static int __init mpc85xxds_publish_devices(void)
194{
195 return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
196}
197machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
198
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500199/*
200 * Called very early, device-tree isn't unflattened
201 */
202static int __init mpc8572_ds_probe(void)
203{
204 unsigned long root = of_get_flat_dt_root();
205
206 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
207#ifdef CONFIG_PCI
208 primary_phb_addr = 0x8000;
209#endif
210 return 1;
211 } else {
212 return 0;
213 }
214}
215
Jon Loeligerd93daf82007-03-20 11:19:10 -0500216define_machine(mpc8544_ds) {
217 .name = "MPC8544 DS",
218 .probe = mpc8544_ds_probe,
Kumar Gala7f503822007-08-17 09:26:40 -0500219 .setup_arch = mpc85xx_ds_setup_arch,
220 .init_IRQ = mpc85xx_ds_pic_init,
Kumar Gala2af85692007-09-10 14:30:33 -0500221#ifdef CONFIG_PCI
Roy Zangf16dab92007-07-13 18:05:08 +0800222 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Kumar Gala2af85692007-09-10 14:30:33 -0500223#endif
Jon Loeligerd93daf82007-03-20 11:19:10 -0500224 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500225 .restart = fsl_rstcr_restart,
Jon Loeligerd93daf82007-03-20 11:19:10 -0500226 .calibrate_decr = generic_calibrate_decr,
227 .progress = udbg_progress,
228};
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500229
230define_machine(mpc8572_ds) {
231 .name = "MPC8572 DS",
232 .probe = mpc8572_ds_probe,
233 .setup_arch = mpc85xx_ds_setup_arch,
234 .init_IRQ = mpc85xx_ds_pic_init,
235#ifdef CONFIG_PCI
236 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
237#endif
238 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500239 .restart = fsl_rstcr_restart,
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500240 .calibrate_decr = generic_calibrate_decr,
241 .progress = udbg_progress,
242};