blob: 53d5851a6c977986789d6f7e73d88ab038504325 [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;
Kumar Galaa712b652008-07-02 10:00:56 -050061 struct device_node *np;
Jon Loeligerd93daf82007-03-20 11:19:10 -050062#ifdef CONFIG_PPC_I8259
63 struct device_node *cascade_node = NULL;
64 int cascade_irq;
65#endif
Haiying Wang06be64a2008-11-13 07:46:12 -060066 unsigned long root = of_get_flat_dt_root();
Jon Loeligerd93daf82007-03-20 11:19:10 -050067
Jason Jinb93eeba2008-07-08 09:21:08 +080068 np = of_find_node_by_type(NULL, "open-pic");
Jon Loeligerd93daf82007-03-20 11:19:10 -050069 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
Haiying Wang06be64a2008-11-13 07:46:12 -060080 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
81 mpic = mpic_alloc(np, r.start,
82 MPIC_PRIMARY |
83 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
84 0, 256, " OpenPIC ");
85 } else {
86 mpic = mpic_alloc(np, r.start,
Jason Jin741edc42008-05-23 16:32:48 +080087 MPIC_PRIMARY | MPIC_WANTS_RESET |
Kumar Gala3c10c9c2008-10-28 18:01:39 +000088 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
89 MPIC_SINGLE_DEST_CPU,
Kumar Galab533f8a2007-07-03 02:35:35 -050090 0, 256, " OpenPIC ");
Haiying Wang06be64a2008-11-13 07:46:12 -060091 }
92
Jon Loeligerd93daf82007-03-20 11:19:10 -050093 BUG_ON(mpic == NULL);
Kumar Galaa712b652008-07-02 10:00:56 -050094 of_node_put(np);
Jon Loeligerd93daf82007-03-20 11:19:10 -050095
Jon Loeligerd93daf82007-03-20 11:19:10 -050096 mpic_init(mpic);
97
98#ifdef CONFIG_PPC_I8259
99 /* Initialize the i8259 controller */
100 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000101 if (of_device_is_compatible(np, "chrp,iic")) {
Jon Loeligerd93daf82007-03-20 11:19:10 -0500102 cascade_node = np;
103 break;
104 }
105
106 if (cascade_node == NULL) {
107 printk(KERN_DEBUG "Could not find i8259 PIC\n");
108 return;
109 }
110
111 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
112 if (cascade_irq == NO_IRQ) {
113 printk(KERN_ERR "Failed to map cascade interrupt\n");
114 return;
115 }
116
Kumar Gala7f503822007-08-17 09:26:40 -0500117 DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500118
119 i8259_init(cascade_node, 0);
120 of_node_put(cascade_node);
121
Kumar Gala7f503822007-08-17 09:26:40 -0500122 set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500123#endif /* CONFIG_PPC_I8259 */
124}
125
Roy Zangf16dab92007-07-13 18:05:08 +0800126#ifdef CONFIG_PCI
Kumar Gala7f503822007-08-17 09:26:40 -0500127static int primary_phb_addr;
Kumar Galab66510c2007-08-16 23:55:55 -0500128extern int uli_exclude_device(struct pci_controller *hose,
129 u_char bus, u_char devfn);
Roy Zangf16dab92007-07-13 18:05:08 +0800130
Kumar Galab66510c2007-08-16 23:55:55 -0500131static int mpc85xx_exclude_device(struct pci_controller *hose,
132 u_char bus, u_char devfn)
Roy Zangf16dab92007-07-13 18:05:08 +0800133{
Kumar Gala7f503822007-08-17 09:26:40 -0500134 struct device_node* node;
Kumar Galab66510c2007-08-16 23:55:55 -0500135 struct resource rsrc;
Roy Zangf16dab92007-07-13 18:05:08 +0800136
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100137 node = hose->dn;
Kumar Galab66510c2007-08-16 23:55:55 -0500138 of_address_to_resource(node, 0, &rsrc);
Roy Zangf16dab92007-07-13 18:05:08 +0800139
Kumar Gala7f503822007-08-17 09:26:40 -0500140 if ((rsrc.start & 0xfffff) == primary_phb_addr) {
Kumar Galab66510c2007-08-16 23:55:55 -0500141 return uli_exclude_device(hose, bus, devfn);
142 }
143
144 return PCIBIOS_SUCCESSFUL;
Roy Zangf16dab92007-07-13 18:05:08 +0800145}
Roy Zangf16dab92007-07-13 18:05:08 +0800146#endif /* CONFIG_PCI */
Jon Loeligerd93daf82007-03-20 11:19:10 -0500147
148/*
149 * Setup the architecture
150 */
Kumar Gala8bd39472008-11-19 09:25:29 -0600151#ifdef CONFIG_SMP
152extern void __init mpc85xx_smp_init(void);
153#endif
Kumar Gala7f503822007-08-17 09:26:40 -0500154static void __init mpc85xx_ds_setup_arch(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -0500155{
Roy Zangf16dab92007-07-13 18:05:08 +0800156#ifdef CONFIG_PCI
157 struct device_node *np;
158#endif
159
Jon Loeligerd93daf82007-03-20 11:19:10 -0500160 if (ppc_md.progress)
Kumar Gala7f503822007-08-17 09:26:40 -0500161 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500162
Roy Zangf16dab92007-07-13 18:05:08 +0800163#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500164 for_each_node_by_type(np, "pci") {
165 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
Kumar Gala01af9502009-04-15 14:38:40 -0500166 of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
167 of_device_is_compatible(np, "fsl,p2020-pcie")) {
Kumar Galac9438af2007-10-04 00:28:43 -0500168 struct resource rsrc;
169 of_address_to_resource(np, 0, &rsrc);
170 if ((rsrc.start & 0xfffff) == primary_phb_addr)
171 fsl_add_bridge(np, 1);
172 else
173 fsl_add_bridge(np, 0);
174 }
Roy Zangf16dab92007-07-13 18:05:08 +0800175 }
Kumar Galac9438af2007-10-04 00:28:43 -0500176
Kumar Galab66510c2007-08-16 23:55:55 -0500177 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
Roy Zangf16dab92007-07-13 18:05:08 +0800178#endif
179
Kumar Gala8bd39472008-11-19 09:25:29 -0600180#ifdef CONFIG_SMP
181 mpc85xx_smp_init();
182#endif
183
Kumar Gala7f503822007-08-17 09:26:40 -0500184 printk("MPC85xx DS board from Freescale Semiconductor\n");
Jon Loeligerd93daf82007-03-20 11:19:10 -0500185}
186
Jon Loeligerd93daf82007-03-20 11:19:10 -0500187/*
188 * Called very early, device-tree isn't unflattened
189 */
190static int __init mpc8544_ds_probe(void)
191{
192 unsigned long root = of_get_flat_dt_root();
193
Kumar Gala7f503822007-08-17 09:26:40 -0500194 if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
195#ifdef CONFIG_PCI
196 primary_phb_addr = 0xb000;
197#endif
198 return 1;
Kumar Gala7f503822007-08-17 09:26:40 -0500199 }
Kumar Gala01af9502009-04-15 14:38:40 -0500200
201 return 0;
Jon Loeligerd93daf82007-03-20 11:19:10 -0500202}
203
Kumar Galaa712b652008-07-02 10:00:56 -0500204static struct of_device_id __initdata mpc85xxds_ids[] = {
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100205 { .type = "soc", },
206 { .compatible = "soc", },
Kim Phillipscf0d19f2008-07-29 15:29:24 -0500207 { .compatible = "simple-bus", },
Anton Vorontsov84ba4a52009-03-19 21:01:48 +0300208 { .compatible = "gianfar", },
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100209 {},
210};
211
212static int __init mpc85xxds_publish_devices(void)
213{
214 return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
215}
216machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
Jason Jin741edc42008-05-23 16:32:48 +0800217machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices);
Kumar Gala01af9502009-04-15 14:38:40 -0500218machine_device_initcall(p2020_ds, mpc85xxds_publish_devices);
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100219
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500220/*
221 * Called very early, device-tree isn't unflattened
222 */
223static int __init mpc8572_ds_probe(void)
224{
225 unsigned long root = of_get_flat_dt_root();
226
227 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
228#ifdef CONFIG_PCI
229 primary_phb_addr = 0x8000;
230#endif
231 return 1;
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500232 }
Kumar Gala01af9502009-04-15 14:38:40 -0500233
234 return 0;
235}
236
237/*
238 * Called very early, device-tree isn't unflattened
239 */
240static int __init p2020_ds_probe(void)
241{
242 unsigned long root = of_get_flat_dt_root();
243
244 if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
245#ifdef CONFIG_PCI
246 primary_phb_addr = 0x9000;
247#endif
248 return 1;
249 }
250
251 return 0;
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500252}
253
Jon Loeligerd93daf82007-03-20 11:19:10 -0500254define_machine(mpc8544_ds) {
255 .name = "MPC8544 DS",
256 .probe = mpc8544_ds_probe,
Kumar Gala7f503822007-08-17 09:26:40 -0500257 .setup_arch = mpc85xx_ds_setup_arch,
258 .init_IRQ = mpc85xx_ds_pic_init,
Kumar Gala2af85692007-09-10 14:30:33 -0500259#ifdef CONFIG_PCI
Roy Zangf16dab92007-07-13 18:05:08 +0800260 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Kumar Gala2af85692007-09-10 14:30:33 -0500261#endif
Jon Loeligerd93daf82007-03-20 11:19:10 -0500262 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500263 .restart = fsl_rstcr_restart,
Jon Loeligerd93daf82007-03-20 11:19:10 -0500264 .calibrate_decr = generic_calibrate_decr,
265 .progress = udbg_progress,
266};
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500267
268define_machine(mpc8572_ds) {
269 .name = "MPC8572 DS",
270 .probe = mpc8572_ds_probe,
271 .setup_arch = mpc85xx_ds_setup_arch,
272 .init_IRQ = mpc85xx_ds_pic_init,
273#ifdef CONFIG_PCI
274 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
275#endif
276 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500277 .restart = fsl_rstcr_restart,
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500278 .calibrate_decr = generic_calibrate_decr,
279 .progress = udbg_progress,
280};
Kumar Gala01af9502009-04-15 14:38:40 -0500281
282define_machine(p2020_ds) {
283 .name = "P2020 DS",
284 .probe = p2020_ds_probe,
285 .setup_arch = mpc85xx_ds_setup_arch,
286 .init_IRQ = mpc85xx_ds_pic_init,
287#ifdef CONFIG_PCI
288 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
289#endif
290 .get_irq = mpic_get_irq,
291 .restart = fsl_rstcr_restart,
292 .calibrate_decr = generic_calibrate_decr,
293 .progress = udbg_progress,
294};