blob: d60bb2beeb55106e7313f5eafbe21529cfc70098 [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>
Jon Loeligerd93daf82007-03-20 11:19:10 -050022
23#include <asm/system.h>
24#include <asm/time.h>
25#include <asm/machdep.h>
Roy Zangf16dab92007-07-13 18:05:08 +080026#include <asm/pci-bridge.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050027#include <asm/mpc85xx.h>
28#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#include "mpc85xx.h"
37
38#undef DEBUG
39
40#ifdef DEBUG
41#define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args)
42#else
43#define DBG(fmt, args...)
44#endif
45
Roy Zangf16dab92007-07-13 18:05:08 +080046#ifdef CONFIG_PPC_I8259
Kumar Gala7f503822007-08-17 09:26:40 -050047static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
Roy Zangf16dab92007-07-13 18:05:08 +080048{
49 unsigned int cascade_irq = i8259_irq();
50
51 if (cascade_irq != NO_IRQ) {
52 generic_handle_irq(cascade_irq);
53 }
54 desc->chip->eoi(irq);
55}
56#endif /* CONFIG_PPC_I8259 */
Jon Loeligerd93daf82007-03-20 11:19:10 -050057
Kumar Gala7f503822007-08-17 09:26:40 -050058void __init mpc85xx_ds_pic_init(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -050059{
60 struct mpic *mpic;
61 struct resource r;
62 struct device_node *np = NULL;
63#ifdef CONFIG_PPC_I8259
64 struct device_node *cascade_node = NULL;
65 int cascade_irq;
66#endif
67
68 np = of_find_node_by_type(np, "open-pic");
69
70 if (np == NULL) {
71 printk(KERN_ERR "Could not find open-pic node\n");
72 return;
73 }
74
75 if (of_address_to_resource(np, 0, &r)) {
76 printk(KERN_ERR "Failed to map mpic register space\n");
77 of_node_put(np);
78 return;
79 }
80
Jon Loeligerd93daf82007-03-20 11:19:10 -050081 mpic = mpic_alloc(np, r.start,
82 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
Kumar Galab533f8a2007-07-03 02:35:35 -050083 0, 256, " OpenPIC ");
Jon Loeligerd93daf82007-03-20 11:19:10 -050084 BUG_ON(mpic == NULL);
85
Jon Loeligerd93daf82007-03-20 11:19:10 -050086 mpic_init(mpic);
87
88#ifdef CONFIG_PPC_I8259
89 /* Initialize the i8259 controller */
90 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +100091 if (of_device_is_compatible(np, "chrp,iic")) {
Jon Loeligerd93daf82007-03-20 11:19:10 -050092 cascade_node = np;
93 break;
94 }
95
96 if (cascade_node == NULL) {
97 printk(KERN_DEBUG "Could not find i8259 PIC\n");
98 return;
99 }
100
101 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
102 if (cascade_irq == NO_IRQ) {
103 printk(KERN_ERR "Failed to map cascade interrupt\n");
104 return;
105 }
106
Kumar Gala7f503822007-08-17 09:26:40 -0500107 DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500108
109 i8259_init(cascade_node, 0);
110 of_node_put(cascade_node);
111
Kumar Gala7f503822007-08-17 09:26:40 -0500112 set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500113#endif /* CONFIG_PPC_I8259 */
114}
115
Roy Zangf16dab92007-07-13 18:05:08 +0800116#ifdef CONFIG_PCI
Kumar Gala7f503822007-08-17 09:26:40 -0500117static int primary_phb_addr;
Kumar Galab66510c2007-08-16 23:55:55 -0500118extern int uses_fsl_uli_m1575;
119extern int uli_exclude_device(struct pci_controller *hose,
120 u_char bus, u_char devfn);
Roy Zangf16dab92007-07-13 18:05:08 +0800121
Kumar Galab66510c2007-08-16 23:55:55 -0500122static int mpc85xx_exclude_device(struct pci_controller *hose,
123 u_char bus, u_char devfn)
Roy Zangf16dab92007-07-13 18:05:08 +0800124{
Kumar Gala7f503822007-08-17 09:26:40 -0500125 struct device_node* node;
Kumar Galab66510c2007-08-16 23:55:55 -0500126 struct resource rsrc;
Roy Zangf16dab92007-07-13 18:05:08 +0800127
Kumar Galab66510c2007-08-16 23:55:55 -0500128 node = (struct device_node *)hose->arch_data;
129 of_address_to_resource(node, 0, &rsrc);
Roy Zangf16dab92007-07-13 18:05:08 +0800130
Kumar Gala7f503822007-08-17 09:26:40 -0500131 if ((rsrc.start & 0xfffff) == primary_phb_addr) {
Kumar Galab66510c2007-08-16 23:55:55 -0500132 return uli_exclude_device(hose, bus, devfn);
133 }
134
135 return PCIBIOS_SUCCESSFUL;
Roy Zangf16dab92007-07-13 18:05:08 +0800136}
Roy Zangf16dab92007-07-13 18:05:08 +0800137#endif /* CONFIG_PCI */
Jon Loeligerd93daf82007-03-20 11:19:10 -0500138
139/*
140 * Setup the architecture
141 */
Kumar Gala7f503822007-08-17 09:26:40 -0500142static void __init mpc85xx_ds_setup_arch(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -0500143{
Roy Zangf16dab92007-07-13 18:05:08 +0800144#ifdef CONFIG_PCI
145 struct device_node *np;
146#endif
147
Jon Loeligerd93daf82007-03-20 11:19:10 -0500148 if (ppc_md.progress)
Kumar Gala7f503822007-08-17 09:26:40 -0500149 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500150
Roy Zangf16dab92007-07-13 18:05:08 +0800151#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500152 for_each_node_by_type(np, "pci") {
153 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
154 of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
155 struct resource rsrc;
156 of_address_to_resource(np, 0, &rsrc);
157 if ((rsrc.start & 0xfffff) == primary_phb_addr)
158 fsl_add_bridge(np, 1);
159 else
160 fsl_add_bridge(np, 0);
161 }
Roy Zangf16dab92007-07-13 18:05:08 +0800162 }
Kumar Galac9438af2007-10-04 00:28:43 -0500163
Kumar Galab66510c2007-08-16 23:55:55 -0500164 uses_fsl_uli_m1575 = 1;
165 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
Roy Zangf16dab92007-07-13 18:05:08 +0800166#endif
167
Kumar Gala7f503822007-08-17 09:26:40 -0500168 printk("MPC85xx DS board from Freescale Semiconductor\n");
Jon Loeligerd93daf82007-03-20 11:19:10 -0500169}
170
Jon Loeligerd93daf82007-03-20 11:19:10 -0500171/*
172 * Called very early, device-tree isn't unflattened
173 */
174static int __init mpc8544_ds_probe(void)
175{
176 unsigned long root = of_get_flat_dt_root();
177
Kumar Gala7f503822007-08-17 09:26:40 -0500178 if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
179#ifdef CONFIG_PCI
180 primary_phb_addr = 0xb000;
181#endif
182 return 1;
183 } else {
184 return 0;
185 }
Jon Loeligerd93daf82007-03-20 11:19:10 -0500186}
187
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500188/*
189 * Called very early, device-tree isn't unflattened
190 */
191static int __init mpc8572_ds_probe(void)
192{
193 unsigned long root = of_get_flat_dt_root();
194
195 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
196#ifdef CONFIG_PCI
197 primary_phb_addr = 0x8000;
198#endif
199 return 1;
200 } else {
201 return 0;
202 }
203}
204
Jon Loeligerd93daf82007-03-20 11:19:10 -0500205define_machine(mpc8544_ds) {
206 .name = "MPC8544 DS",
207 .probe = mpc8544_ds_probe,
Kumar Gala7f503822007-08-17 09:26:40 -0500208 .setup_arch = mpc85xx_ds_setup_arch,
209 .init_IRQ = mpc85xx_ds_pic_init,
Kumar Gala2af85692007-09-10 14:30:33 -0500210#ifdef CONFIG_PCI
Roy Zangf16dab92007-07-13 18:05:08 +0800211 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Kumar Gala2af85692007-09-10 14:30:33 -0500212#endif
Jon Loeligerd93daf82007-03-20 11:19:10 -0500213 .get_irq = mpic_get_irq,
214 .restart = mpc85xx_restart,
215 .calibrate_decr = generic_calibrate_decr,
216 .progress = udbg_progress,
217};
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500218
219define_machine(mpc8572_ds) {
220 .name = "MPC8572 DS",
221 .probe = mpc8572_ds_probe,
222 .setup_arch = mpc85xx_ds_setup_arch,
223 .init_IRQ = mpc85xx_ds_pic_init,
224#ifdef CONFIG_PCI
225 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
226#endif
227 .get_irq = mpic_get_irq,
228 .restart = mpc85xx_restart,
229 .calibrate_decr = generic_calibrate_decr,
230 .progress = udbg_progress,
231};