blob: 104a09b9f6d35623b93b289b53aa8604dfdfe5e2 [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>
Yinghai Lu95f72d12010-07-12 14:36:09 +100023#include <linux/memblock.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>
Kyle Moffett582d3e02011-12-02 06:27:58 +000038#include "smp.h"
Jon Loeligerd93daf82007-03-20 11:19:10 -050039
Dmitry Eremin-Solenikov543a07b2011-11-17 21:56:16 +040040#include "mpc85xx.h"
41
Jon Loeligerd93daf82007-03-20 11:19:10 -050042#undef DEBUG
43
44#ifdef DEBUG
Harvey Harrisone48b1b42008-03-29 08:21:07 +110045#define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
Jon Loeligerd93daf82007-03-20 11:19:10 -050046#else
47#define DBG(fmt, args...)
48#endif
49
Roy Zangf16dab92007-07-13 18:05:08 +080050#ifdef CONFIG_PPC_I8259
Kumar Gala7f503822007-08-17 09:26:40 -050051static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
Roy Zangf16dab92007-07-13 18:05:08 +080052{
Thomas Gleixnerec775d02011-03-25 16:45:20 +010053 struct irq_chip *chip = irq_desc_get_chip(desc);
Roy Zangf16dab92007-07-13 18:05:08 +080054 unsigned int cascade_irq = i8259_irq();
55
56 if (cascade_irq != NO_IRQ) {
57 generic_handle_irq(cascade_irq);
58 }
Lennert Buytenhek712d5d72011-03-07 13:59:19 +000059 chip->irq_eoi(&desc->irq_data);
Roy Zangf16dab92007-07-13 18:05:08 +080060}
61#endif /* CONFIG_PPC_I8259 */
Jon Loeligerd93daf82007-03-20 11:19:10 -050062
Kumar Gala7f503822007-08-17 09:26:40 -050063void __init mpc85xx_ds_pic_init(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -050064{
65 struct mpic *mpic;
Jon Loeligerd93daf82007-03-20 11:19:10 -050066#ifdef CONFIG_PPC_I8259
Kyle Moffett996983b2011-12-02 06:28:02 +000067 struct device_node *np;
Jon Loeligerd93daf82007-03-20 11:19:10 -050068 struct device_node *cascade_node = NULL;
69 int cascade_irq;
70#endif
Haiying Wang06be64a2008-11-13 07:46:12 -060071 unsigned long root = of_get_flat_dt_root();
Jon Loeligerd93daf82007-03-20 11:19:10 -050072
Haiying Wang06be64a2008-11-13 07:46:12 -060073 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
Kyle Moffett996983b2011-12-02 06:28:02 +000074 mpic = mpic_alloc(NULL, 0,
Haiying Wang06be64a2008-11-13 07:46:12 -060075 MPIC_PRIMARY |
Fabio Baltieria63e23b2011-07-12 09:49:43 +020076 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
77 MPIC_SINGLE_DEST_CPU,
Haiying Wang06be64a2008-11-13 07:46:12 -060078 0, 256, " OpenPIC ");
79 } else {
Kyle Moffett996983b2011-12-02 06:28:02 +000080 mpic = mpic_alloc(NULL, 0,
Jason Jin741edc42008-05-23 16:32:48 +080081 MPIC_PRIMARY | MPIC_WANTS_RESET |
Kumar Gala3c10c9c2008-10-28 18:01:39 +000082 MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
83 MPIC_SINGLE_DEST_CPU,
Kumar Galab533f8a2007-07-03 02:35:35 -050084 0, 256, " OpenPIC ");
Haiying Wang06be64a2008-11-13 07:46:12 -060085 }
86
Jon Loeligerd93daf82007-03-20 11:19:10 -050087 BUG_ON(mpic == NULL);
Jon Loeligerd93daf82007-03-20 11:19:10 -050088 mpic_init(mpic);
89
90#ifdef CONFIG_PPC_I8259
91 /* Initialize the i8259 controller */
92 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +100093 if (of_device_is_compatible(np, "chrp,iic")) {
Jon Loeligerd93daf82007-03-20 11:19:10 -050094 cascade_node = np;
95 break;
96 }
97
98 if (cascade_node == NULL) {
99 printk(KERN_DEBUG "Could not find i8259 PIC\n");
100 return;
101 }
102
103 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
104 if (cascade_irq == NO_IRQ) {
105 printk(KERN_ERR "Failed to map cascade interrupt\n");
106 return;
107 }
108
Kumar Gala7f503822007-08-17 09:26:40 -0500109 DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500110
111 i8259_init(cascade_node, 0);
112 of_node_put(cascade_node);
113
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100114 irq_set_chained_handler(cascade_irq, mpc85xx_8259_cascade);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500115#endif /* CONFIG_PPC_I8259 */
116}
117
Roy Zangf16dab92007-07-13 18:05:08 +0800118#ifdef CONFIG_PCI
Kumar Gala7f503822007-08-17 09:26:40 -0500119static int primary_phb_addr;
Kumar Galab66510c2007-08-16 23:55:55 -0500120extern int uli_exclude_device(struct pci_controller *hose,
121 u_char bus, u_char devfn);
Roy Zangf16dab92007-07-13 18:05:08 +0800122
Kumar Galab66510c2007-08-16 23:55:55 -0500123static int mpc85xx_exclude_device(struct pci_controller *hose,
124 u_char bus, u_char devfn)
Roy Zangf16dab92007-07-13 18:05:08 +0800125{
Kumar Gala7f503822007-08-17 09:26:40 -0500126 struct device_node* node;
Kumar Galab66510c2007-08-16 23:55:55 -0500127 struct resource rsrc;
Roy Zangf16dab92007-07-13 18:05:08 +0800128
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100129 node = hose->dn;
Kumar Galab66510c2007-08-16 23:55:55 -0500130 of_address_to_resource(node, 0, &rsrc);
Roy Zangf16dab92007-07-13 18:05:08 +0800131
Kumar Gala7f503822007-08-17 09:26:40 -0500132 if ((rsrc.start & 0xfffff) == primary_phb_addr) {
Kumar Galab66510c2007-08-16 23:55:55 -0500133 return uli_exclude_device(hose, bus, devfn);
134 }
135
136 return PCIBIOS_SUCCESSFUL;
Roy Zangf16dab92007-07-13 18:05:08 +0800137}
Roy Zangf16dab92007-07-13 18:05:08 +0800138#endif /* CONFIG_PCI */
Jon Loeligerd93daf82007-03-20 11:19:10 -0500139
140/*
141 * Setup the architecture
142 */
Kumar Gala7f503822007-08-17 09:26:40 -0500143static void __init mpc85xx_ds_setup_arch(void)
Jon Loeligerd93daf82007-03-20 11:19:10 -0500144{
Roy Zangf16dab92007-07-13 18:05:08 +0800145#ifdef CONFIG_PCI
146 struct device_node *np;
Kumar Gala152d0182009-05-15 00:37:35 -0500147 struct pci_controller *hose;
Roy Zangf16dab92007-07-13 18:05:08 +0800148#endif
Kumar Gala152d0182009-05-15 00:37:35 -0500149 dma_addr_t max = 0xffffffff;
Roy Zangf16dab92007-07-13 18:05:08 +0800150
Jon Loeligerd93daf82007-03-20 11:19:10 -0500151 if (ppc_md.progress)
Kumar Gala7f503822007-08-17 09:26:40 -0500152 ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
Jon Loeligerd93daf82007-03-20 11:19:10 -0500153
Roy Zangf16dab92007-07-13 18:05:08 +0800154#ifdef CONFIG_PCI
Kumar Galac9438af2007-10-04 00:28:43 -0500155 for_each_node_by_type(np, "pci") {
156 if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
Kumar Gala01af9502009-04-15 14:38:40 -0500157 of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
158 of_device_is_compatible(np, "fsl,p2020-pcie")) {
Kumar Galac9438af2007-10-04 00:28:43 -0500159 struct resource rsrc;
160 of_address_to_resource(np, 0, &rsrc);
161 if ((rsrc.start & 0xfffff) == primary_phb_addr)
162 fsl_add_bridge(np, 1);
163 else
164 fsl_add_bridge(np, 0);
Kumar Gala152d0182009-05-15 00:37:35 -0500165
166 hose = pci_find_hose_for_OF_device(np);
167 max = min(max, hose->dma_window_base_cur +
168 hose->dma_window_size);
Kumar Galac9438af2007-10-04 00:28:43 -0500169 }
Roy Zangf16dab92007-07-13 18:05:08 +0800170 }
Kumar Galac9438af2007-10-04 00:28:43 -0500171
Kumar Galab66510c2007-08-16 23:55:55 -0500172 ppc_md.pci_exclude_device = mpc85xx_exclude_device;
Roy Zangf16dab92007-07-13 18:05:08 +0800173#endif
174
Kumar Gala8bd39472008-11-19 09:25:29 -0600175 mpc85xx_smp_init();
Kumar Gala8bd39472008-11-19 09:25:29 -0600176
Kumar Gala152d0182009-05-15 00:37:35 -0500177#ifdef CONFIG_SWIOTLB
Yinghai Lu95f72d12010-07-12 14:36:09 +1000178 if (memblock_end_of_DRAM() > max) {
Kumar Gala152d0182009-05-15 00:37:35 -0500179 ppc_swiotlb_enable = 1;
FUJITA Tomonori37029772009-08-04 19:08:23 +0000180 set_pci_dma_ops(&swiotlb_dma_ops);
FUJITA Tomonori762afb72009-08-04 19:08:22 +0000181 ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
Kumar Gala152d0182009-05-15 00:37:35 -0500182 }
183#endif
184
Kumar Gala7f503822007-08-17 09:26:40 -0500185 printk("MPC85xx DS board from Freescale Semiconductor\n");
Jon Loeligerd93daf82007-03-20 11:19:10 -0500186}
187
Jon Loeligerd93daf82007-03-20 11:19:10 -0500188/*
189 * Called very early, device-tree isn't unflattened
190 */
191static int __init mpc8544_ds_probe(void)
192{
193 unsigned long root = of_get_flat_dt_root();
194
Kumar Gala7f503822007-08-17 09:26:40 -0500195 if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
196#ifdef CONFIG_PCI
197 primary_phb_addr = 0xb000;
198#endif
199 return 1;
Kumar Gala7f503822007-08-17 09:26:40 -0500200 }
Kumar Gala01af9502009-04-15 14:38:40 -0500201
202 return 0;
Jon Loeligerd93daf82007-03-20 11:19:10 -0500203}
204
Dmitry Eremin-Solenikov46d026a2011-11-17 21:56:17 +0400205machine_device_initcall(mpc8544_ds, mpc85xx_common_publish_devices);
206machine_device_initcall(mpc8572_ds, mpc85xx_common_publish_devices);
207machine_device_initcall(p2020_ds, mpc85xx_common_publish_devices);
Sebastian Siewior1028d4f2008-03-15 00:01:30 +0100208
Kumar Gala152d0182009-05-15 00:37:35 -0500209machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier);
210machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier);
211machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier);
212
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500213/*
214 * Called very early, device-tree isn't unflattened
215 */
216static int __init mpc8572_ds_probe(void)
217{
218 unsigned long root = of_get_flat_dt_root();
219
220 if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
221#ifdef CONFIG_PCI
222 primary_phb_addr = 0x8000;
223#endif
224 return 1;
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500225 }
Kumar Gala01af9502009-04-15 14:38:40 -0500226
227 return 0;
228}
229
230/*
231 * Called very early, device-tree isn't unflattened
232 */
233static int __init p2020_ds_probe(void)
234{
235 unsigned long root = of_get_flat_dt_root();
236
237 if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
238#ifdef CONFIG_PCI
239 primary_phb_addr = 0x9000;
240#endif
241 return 1;
242 }
243
244 return 0;
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500245}
246
Jon Loeligerd93daf82007-03-20 11:19:10 -0500247define_machine(mpc8544_ds) {
248 .name = "MPC8544 DS",
249 .probe = mpc8544_ds_probe,
Kumar Gala7f503822007-08-17 09:26:40 -0500250 .setup_arch = mpc85xx_ds_setup_arch,
251 .init_IRQ = mpc85xx_ds_pic_init,
Kumar Gala2af85692007-09-10 14:30:33 -0500252#ifdef CONFIG_PCI
Roy Zangf16dab92007-07-13 18:05:08 +0800253 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
Kumar Gala2af85692007-09-10 14:30:33 -0500254#endif
Jon Loeligerd93daf82007-03-20 11:19:10 -0500255 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500256 .restart = fsl_rstcr_restart,
Jon Loeligerd93daf82007-03-20 11:19:10 -0500257 .calibrate_decr = generic_calibrate_decr,
258 .progress = udbg_progress,
259};
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500260
261define_machine(mpc8572_ds) {
262 .name = "MPC8572 DS",
263 .probe = mpc8572_ds_probe,
264 .setup_arch = mpc85xx_ds_setup_arch,
265 .init_IRQ = mpc85xx_ds_pic_init,
266#ifdef CONFIG_PCI
267 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
268#endif
269 .get_irq = mpic_get_irq,
Kumar Galae1c15752007-10-04 01:04:57 -0500270 .restart = fsl_rstcr_restart,
Kumar Gala5d54ddcb2007-09-11 01:25:43 -0500271 .calibrate_decr = generic_calibrate_decr,
272 .progress = udbg_progress,
273};
Kumar Gala01af9502009-04-15 14:38:40 -0500274
275define_machine(p2020_ds) {
276 .name = "P2020 DS",
277 .probe = p2020_ds_probe,
278 .setup_arch = mpc85xx_ds_setup_arch,
279 .init_IRQ = mpc85xx_ds_pic_init,
280#ifdef CONFIG_PCI
281 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
282#endif
283 .get_irq = mpic_get_irq,
284 .restart = fsl_rstcr_restart,
285 .calibrate_decr = generic_calibrate_decr,
286 .progress = udbg_progress,
287};