blob: 849c0ac0025fd6d849fcb2eb9a295e542fb41155 [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>
Kumar Gala152d0182009-05-15 00:37:35 -050023#include <linux/lmb.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050024
25#include <asm/system.h>
26#include <asm/time.h>
27#include <asm/machdep.h>
Roy Zangf16dab92007-07-13 18:05:08 +080028#include <asm/pci-bridge.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050029#include <mm/mmu_decl.h>
30#include <asm/prom.h>
31#include <asm/udbg.h>
32#include <asm/mpic.h>
33#include <asm/i8259.h>
Kumar Gala152d0182009-05-15 00:37:35 -050034#include <asm/swiotlb.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050035
36#include <sysdev/fsl_soc.h>
Roy Zangf16dab92007-07-13 18:05:08 +080037#include <sysdev/fsl_pci.h>
Jon Loeligerd93daf82007-03-20 11:19:10 -050038
39#undef DEBUG
40
41#ifdef DEBUG
Harvey Harrisone48b1b42008-03-29 08:21:07 +110042#define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
Jon Loeligerd93daf82007-03-20 11:19:10 -050043#else
44#define DBG(fmt, args...)
45#endif
46
Roy Zangf16dab92007-07-13 18:05:08 +080047#ifdef CONFIG_PPC_I8259
Kumar Gala7f503822007-08-17 09:26:40 -050048static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
Roy Zangf16dab92007-07-13 18:05:08 +080049{
50 unsigned int cascade_irq = i8259_irq();
51
52 if (cascade_irq != NO_IRQ) {
53 generic_handle_irq(cascade_irq);
54 }
55 desc->chip->eoi(irq);
56}
57#endif /* CONFIG_PPC_I8259 */
Jon Loeligerd93daf82007-03-20 11:19:10 -050058
Kumar Gala7f503822007-08-17 09:26:40 -050059void __init mpc85xx_ds_pic_init(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -050060{
61 struct mpic *mpic;
62 struct resource r;
Kumar Galaa712b652008-07-02 10:00:56 -050063 struct device_node *np;
Jon Loeligerd93daf82007-03-20 11:19:10 -050064#ifdef CONFIG_PPC_I8259
65 struct device_node *cascade_node = NULL;
66 int cascade_irq;
67#endif
Haiying Wang06be64a2008-11-13 07:46:12 -060068 unsigned long root = of_get_flat_dt_root();
Jon Loeligerd93daf82007-03-20 11:19:10 -050069
Jason Jinb93eeba2008-07-08 09:21:08 +080070 np = of_find_node_by_type(NULL, "open-pic");
Jon Loeligerd93daf82007-03-20 11:19:10 -050071 if (np == NULL) {
72 printk(KERN_ERR "Could not find open-pic node\n");
73 return;
74 }
75
76 if (of_address_to_resource(np, 0, &r)) {
77 printk(KERN_ERR "Failed to map mpic register space\n");
78 of_node_put(np);
79 return;
80 }
81
Haiying Wang06be64a2008-11-13 07:46:12 -060082 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
83 mpic = mpic_alloc(np, r.start,
84 MPIC_PRIMARY |
85 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
86 0, 256, " OpenPIC ");
87 } else {
88 mpic = mpic_alloc(np, r.start,
Jason Jin741edc42008-05-23 16:32:48 +080089 MPIC_PRIMARY | MPIC_WANTS_RESET |
Kumar Gala3c10c9c2008-10-28 18:01:39 +000090 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
91 MPIC_SINGLE_DEST_CPU,
Kumar Galab533f8a2007-07-03 02:35:35 -050092 0, 256, " OpenPIC ");
Haiying Wang06be64a2008-11-13 07:46:12 -060093 }
94
Jon Loeligerd93daf82007-03-20 11:19:10 -050095 BUG_ON(mpic == NULL);
Kumar Galaa712b652008-07-02 10:00:56 -050096 of_node_put(np);
Jon Loeligerd93daf82007-03-20 11:19:10 -050097
Jon Loeligerd93daf82007-03-20 11:19:10 -050098 mpic_init(mpic);
99
100#ifdef CONFIG_PPC_I8259
101 /* Initialize the i8259 controller */
102 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000103 if (of_device_is_compatible(np, "chrp,iic")) {
Jon Loeligerd93daf82007-03-20 11:19:10 -0500104 cascade_node = np;
105 break;
106 }
107
108 if (cascade_node == NULL) {
109 printk(KERN_DEBUG "Could not find i8259 PIC\n");
110 return;
111 }
112
113 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
114 if (cascade_irq == NO_IRQ) {
115 printk(KERN_ERR "Failed to map cascade interrupt\n");
116 return;
117 }
118
Kumar Gala7f503822007-08-17 09:26:40 -0500119 DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500120
121 i8259_init(cascade_node, 0);
122 of_node_put(cascade_node);
123
Kumar Gala7f503822007-08-17 09:26:40 -0500124 set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500125#endif /* CONFIG_PPC_I8259 */
126}
127
Roy Zangf16dab92007-07-13 18:05:08 +0800128#ifdef CONFIG_PCI
Kumar Gala7f503822007-08-17 09:26:40 -0500129static int primary_phb_addr;
Kumar Galab66510c2007-08-16 23:55:55 -0500130extern int uli_exclude_device(struct pci_controller *hose,
131 u_char bus, u_char devfn);
Roy Zangf16dab92007-07-13 18:05:08 +0800132
Kumar Galab66510c2007-08-16 23:55:55 -0500133static int mpc85xx_exclude_device(struct pci_controller *hose,
134 u_char bus, u_char devfn)
Roy Zangf16dab92007-07-13 18:05:08 +0800135{
Kumar Gala7f503822007-08-17 09:26:40 -0500136 struct device_node* node;
Kumar Galab66510c2007-08-16 23:55:55 -0500137 struct resource rsrc;
Roy Zangf16dab92007-07-13 18:05:08 +0800138
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100139 node = hose->dn;
Kumar Galab66510c2007-08-16 23:55:55 -0500140 of_address_to_resource(node, 0, &rsrc);
Roy Zangf16dab92007-07-13 18:05:08 +0800141
Kumar Gala7f503822007-08-17 09:26:40 -0500142 if ((rsrc.start & 0xfffff) == primary_phb_addr) {
Kumar Galab66510c2007-08-16 23:55:55 -0500143 return uli_exclude_device(hose, bus, devfn);
144 }
145
146 return PCIBIOS_SUCCESSFUL;
Roy Zangf16dab92007-07-13 18:05:08 +0800147}
Roy Zangf16dab92007-07-13 18:05:08 +0800148#endif /* CONFIG_PCI */
Jon Loeligerd93daf82007-03-20 11:19:10 -0500149
150/*
151 * Setup the architecture
152 */
Kumar Gala8bd39472008-11-19 09:25:29 -0600153#ifdef CONFIG_SMP
154extern void __init mpc85xx_smp_init(void);
155#endif
Kumar Gala7f503822007-08-17 09:26:40 -0500156static void __init mpc85xx_ds_setup_arch(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -0500157{
Roy Zangf16dab92007-07-13 18:05:08 +0800158#ifdef CONFIG_PCI
159 struct device_node *np;
Kumar Gala152d0182009-05-15 00:37:35 -0500160 struct pci_controller *hose;
Roy Zangf16dab92007-07-13 18:05:08 +0800161#endif
Kumar Gala152d0182009-05-15 00:37:35 -0500162 dma_addr_t max = 0xffffffff;
Roy Zangf16dab92007-07-13 18:05:08 +0800163
Jon Loeligerd93daf82007-03-20 11:19:10 -0500164 if (ppc_md.progress)
Kumar Gala7f503822007-08-17 09:26:40 -0500165 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500166
Roy Zangf16dab92007-07-13 18:05:08 +0800167#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500168 for_each_node_by_type(np, "pci") {
169 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
Kumar Gala01af9502009-04-15 14:38:40 -0500170 of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
171 of_device_is_compatible(np, "fsl,p2020-pcie")) {
Kumar Galac9438af2007-10-04 00:28:43 -0500172 struct resource rsrc;
173 of_address_to_resource(np, 0, &rsrc);
174 if ((rsrc.start & 0xfffff) == primary_phb_addr)
175 fsl_add_bridge(np, 1);
176 else
177 fsl_add_bridge(np, 0);
Kumar Gala152d0182009-05-15 00:37:35 -0500178
179 hose = pci_find_hose_for_OF_device(np);
180 max = min(max, hose->dma_window_base_cur +
181 hose->dma_window_size);
Kumar Galac9438af2007-10-04 00:28:43 -0500182 }
Roy Zangf16dab92007-07-13 18:05:08 +0800183 }
Kumar Galac9438af2007-10-04 00:28:43 -0500184
Kumar Galab66510c2007-08-16 23:55:55 -0500185 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
Roy Zangf16dab92007-07-13 18:05:08 +0800186#endif
187
Kumar Gala8bd39472008-11-19 09:25:29 -0600188#ifdef CONFIG_SMP
189 mpc85xx_smp_init();
190#endif
191
Kumar Gala152d0182009-05-15 00:37:35 -0500192#ifdef CONFIG_SWIOTLB
193 if (lmb_end_of_DRAM() > max) {
194 ppc_swiotlb_enable = 1;
195 set_pci_dma_ops(&swiotlb_pci_dma_ops);
196 }
197#endif
198
Kumar Gala7f503822007-08-17 09:26:40 -0500199 printk("MPC85xx DS board from Freescale Semiconductor\n");
Jon Loeligerd93daf82007-03-20 11:19:10 -0500200}
201
Jon Loeligerd93daf82007-03-20 11:19:10 -0500202/*
203 * Called very early, device-tree isn't unflattened
204 */
205static int __init mpc8544_ds_probe(void)
206{
207 unsigned long root = of_get_flat_dt_root();
208
Kumar Gala7f503822007-08-17 09:26:40 -0500209 if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
210#ifdef CONFIG_PCI
211 primary_phb_addr = 0xb000;
212#endif
213 return 1;
Kumar Gala7f503822007-08-17 09:26:40 -0500214 }
Kumar Gala01af9502009-04-15 14:38:40 -0500215
216 return 0;
Jon Loeligerd93daf82007-03-20 11:19:10 -0500217}
218
Kumar Galaa712b652008-07-02 10:00:56 -0500219static struct of_device_id __initdata mpc85xxds_ids[] = {
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100220 { .type = "soc", },
221 { .compatible = "soc", },
Kim Phillipscf0d19f2008-07-29 15:29:24 -0500222 { .compatible = "simple-bus", },
Anton Vorontsov84ba4a52009-03-19 21:01:48 +0300223 { .compatible = "gianfar", },
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100224 {},
225};
226
227static int __init mpc85xxds_publish_devices(void)
228{
229 return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
230}
231machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
Jason Jin741edc42008-05-23 16:32:48 +0800232machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices);
Kumar Gala01af9502009-04-15 14:38:40 -0500233machine_device_initcall(p2020_ds, mpc85xxds_publish_devices);
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100234
Kumar Gala152d0182009-05-15 00:37:35 -0500235machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier);
236machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier);
237machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier);
238
Kumar Gala5d54ddc2007-09-11 01:25:43 -0500239/*
240 * Called very early, device-tree isn't unflattened
241 */
242static int __init mpc8572_ds_probe(void)
243{
244 unsigned long root = of_get_flat_dt_root();
245
246 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
247#ifdef CONFIG_PCI
248 primary_phb_addr = 0x8000;
249#endif
250 return 1;
Kumar Gala5d54ddc2007-09-11 01:25:43 -0500251 }
Kumar Gala01af9502009-04-15 14:38:40 -0500252
253 return 0;
254}
255
256/*
257 * Called very early, device-tree isn't unflattened
258 */
259static int __init p2020_ds_probe(void)
260{
261 unsigned long root = of_get_flat_dt_root();
262
263 if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
264#ifdef CONFIG_PCI
265 primary_phb_addr = 0x9000;
266#endif
267 return 1;
268 }
269
270 return 0;
Kumar Gala5d54ddc2007-09-11 01:25:43 -0500271}
272
Jon Loeligerd93daf82007-03-20 11:19:10 -0500273define_machine(mpc8544_ds) {
274 .name = "MPC8544 DS",
275 .probe = mpc8544_ds_probe,
Kumar Gala7f503822007-08-17 09:26:40 -0500276 .setup_arch = mpc85xx_ds_setup_arch,
277 .init_IRQ = mpc85xx_ds_pic_init,
Kumar Gala2af85692007-09-10 14:30:33 -0500278#ifdef CONFIG_PCI
Roy Zangf16dab92007-07-13 18:05:08 +0800279 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Kumar Gala2af85692007-09-10 14:30:33 -0500280#endif
Jon Loeligerd93daf82007-03-20 11:19:10 -0500281 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500282 .restart = fsl_rstcr_restart,
Jon Loeligerd93daf82007-03-20 11:19:10 -0500283 .calibrate_decr = generic_calibrate_decr,
284 .progress = udbg_progress,
285};
Kumar Gala5d54ddc2007-09-11 01:25:43 -0500286
287define_machine(mpc8572_ds) {
288 .name = "MPC8572 DS",
289 .probe = mpc8572_ds_probe,
290 .setup_arch = mpc85xx_ds_setup_arch,
291 .init_IRQ = mpc85xx_ds_pic_init,
292#ifdef CONFIG_PCI
293 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
294#endif
295 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500296 .restart = fsl_rstcr_restart,
Kumar Gala5d54ddc2007-09-11 01:25:43 -0500297 .calibrate_decr = generic_calibrate_decr,
298 .progress = udbg_progress,
299};
Kumar Gala01af9502009-04-15 14:38:40 -0500300
301define_machine(p2020_ds) {
302 .name = "P2020 DS",
303 .probe = p2020_ds_probe,
304 .setup_arch = mpc85xx_ds_setup_arch,
305 .init_IRQ = mpc85xx_ds_pic_init,
306#ifdef CONFIG_PCI
307 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
308#endif
309 .get_irq = mpic_get_irq,
310 .restart = fsl_rstcr_restart,
311 .calibrate_decr = generic_calibrate_decr,
312 .progress = udbg_progress,
313};