mpc85xx_ds.c 6.5 KB
Newer Older
1
/*
2
 * MPC85xx DS Board Setup
3 4
 *
 * Author Xianghua Xiao (x.xiao@freescale.com)
5 6
 * Roy Zang <tie-fei.zang@freescale.com>
 * 	- Add PCI/PCI Exprees support
7 8 9 10 11 12 13 14 15 16
 * Copyright 2007 Freescale Semiconductor Inc.
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/stddef.h>
#include <linux/kernel.h>
17
#include <linux/pci.h>
18 19 20
#include <linux/kdev_t.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
21
#include <linux/interrupt.h>
22
#include <linux/of_platform.h>
Y
Yinghai Lu 已提交
23
#include <linux/memblock.h>
24 25 26 27

#include <asm/system.h>
#include <asm/time.h>
#include <asm/machdep.h>
28
#include <asm/pci-bridge.h>
29 30 31 32 33
#include <mm/mmu_decl.h>
#include <asm/prom.h>
#include <asm/udbg.h>
#include <asm/mpic.h>
#include <asm/i8259.h>
34
#include <asm/swiotlb.h>
35 36

#include <sysdev/fsl_soc.h>
37
#include <sysdev/fsl_pci.h>
38
#include "smp.h"
39

40 41
#include "mpc85xx.h"

42 43 44
#undef DEBUG

#ifdef DEBUG
45
#define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
46 47 48 49
#else
#define DBG(fmt, args...)
#endif

50
#ifdef CONFIG_PPC_I8259
51
static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
52
{
53
	struct irq_chip *chip = irq_desc_get_chip(desc);
54 55 56 57 58
	unsigned int cascade_irq = i8259_irq();

	if (cascade_irq != NO_IRQ) {
		generic_handle_irq(cascade_irq);
	}
59
	chip->irq_eoi(&desc->irq_data);
60 61
}
#endif	/* CONFIG_PPC_I8259 */
62

63
void __init mpc85xx_ds_pic_init(void)
64 65 66
{
	struct mpic *mpic;
#ifdef CONFIG_PPC_I8259
67
	struct device_node *np;
68 69 70
	struct device_node *cascade_node = NULL;
	int cascade_irq;
#endif
71
	unsigned long root = of_get_flat_dt_root();
72

73
	if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
74
		mpic = mpic_alloc(NULL, 0,
75
			MPIC_NO_RESET |
76
			MPIC_BIG_ENDIAN |
77
			MPIC_SINGLE_DEST_CPU,
78 79
			0, 256, " OpenPIC  ");
	} else {
80
		mpic = mpic_alloc(NULL, 0,
81
			  MPIC_BIG_ENDIAN |
82
			  MPIC_SINGLE_DEST_CPU,
83
			0, 256, " OpenPIC  ");
84 85
	}

86 87 88 89 90 91
	BUG_ON(mpic == NULL);
	mpic_init(mpic);

#ifdef CONFIG_PPC_I8259
	/* Initialize the i8259 controller */
	for_each_node_by_type(np, "interrupt-controller")
92
	    if (of_device_is_compatible(np, "chrp,iic")) {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
		cascade_node = np;
		break;
	}

	if (cascade_node == NULL) {
		printk(KERN_DEBUG "Could not find i8259 PIC\n");
		return;
	}

	cascade_irq = irq_of_parse_and_map(cascade_node, 0);
	if (cascade_irq == NO_IRQ) {
		printk(KERN_ERR "Failed to map cascade interrupt\n");
		return;
	}

108
	DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
109 110 111 112

	i8259_init(cascade_node, 0);
	of_node_put(cascade_node);

113
	irq_set_chained_handler(cascade_irq, mpc85xx_8259_cascade);
114 115 116
#endif	/* CONFIG_PPC_I8259 */
}

117
#ifdef CONFIG_PCI
118
static int primary_phb_addr;
119 120
extern int uli_exclude_device(struct pci_controller *hose,
				u_char bus, u_char devfn);
121

122 123
static int mpc85xx_exclude_device(struct pci_controller *hose,
				   u_char bus, u_char devfn)
124
{
125
	struct device_node* node;
126
	struct resource rsrc;
127

128
	node = hose->dn;
129
	of_address_to_resource(node, 0, &rsrc);
130

131
	if ((rsrc.start & 0xfffff) == primary_phb_addr) {
132 133
		return uli_exclude_device(hose, bus, devfn);
	}
134

135
	return PCIBIOS_SUCCESSFUL;
136 137
}
#endif	/* CONFIG_PCI */
138 139 140 141

/*
 * Setup the architecture
 */
142
static void __init mpc85xx_ds_setup_arch(void)
143
{
144 145
#ifdef CONFIG_PCI
	struct device_node *np;
146
	struct pci_controller *hose;
147
#endif
148
	dma_addr_t max = 0xffffffff;
149

150
	if (ppc_md.progress)
151
		ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
152

153
#ifdef CONFIG_PCI
154 155
	for_each_node_by_type(np, "pci") {
		if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
156 157
		    of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
		    of_device_is_compatible(np, "fsl,p2020-pcie")) {
158 159 160 161 162 163
			struct resource rsrc;
			of_address_to_resource(np, 0, &rsrc);
			if ((rsrc.start & 0xfffff) == primary_phb_addr)
				fsl_add_bridge(np, 1);
			else
				fsl_add_bridge(np, 0);
164 165 166 167

			hose = pci_find_hose_for_OF_device(np);
			max = min(max, hose->dma_window_base_cur +
					hose->dma_window_size);
168
		}
169
	}
170

171
	ppc_md.pci_exclude_device = mpc85xx_exclude_device;
172 173
#endif

174 175
	mpc85xx_smp_init();

176
#ifdef CONFIG_SWIOTLB
Y
Yinghai Lu 已提交
177
	if (memblock_end_of_DRAM() > max) {
178
		ppc_swiotlb_enable = 1;
179
		set_pci_dma_ops(&swiotlb_dma_ops);
180
		ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
181 182 183
	}
#endif

184
	printk("MPC85xx DS board from Freescale Semiconductor\n");
185 186 187 188 189 190 191 192 193
}

/*
 * Called very early, device-tree isn't unflattened
 */
static int __init mpc8544_ds_probe(void)
{
	unsigned long root = of_get_flat_dt_root();

194 195 196 197 198 199
	if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
#ifdef CONFIG_PCI
		primary_phb_addr = 0xb000;
#endif
		return 1;
	}
200 201

	return 0;
202 203
}

204 205 206
machine_device_initcall(mpc8544_ds, mpc85xx_common_publish_devices);
machine_device_initcall(mpc8572_ds, mpc85xx_common_publish_devices);
machine_device_initcall(p2020_ds, mpc85xx_common_publish_devices);
207

208 209 210 211
machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier);
machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier);
machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier);

212 213 214 215 216 217 218 219 220 221 222 223 224
/*
 * Called very early, device-tree isn't unflattened
 */
static int __init mpc8572_ds_probe(void)
{
	unsigned long root = of_get_flat_dt_root();

	if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
#ifdef CONFIG_PCI
		primary_phb_addr = 0x8000;
#endif
		return 1;
	}
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

	return 0;
}

/*
 * Called very early, device-tree isn't unflattened
 */
static int __init p2020_ds_probe(void)
{
	unsigned long root = of_get_flat_dt_root();

	if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
#ifdef CONFIG_PCI
		primary_phb_addr = 0x9000;
#endif
		return 1;
	}

	return 0;
244 245
}

246 247 248
define_machine(mpc8544_ds) {
	.name			= "MPC8544 DS",
	.probe			= mpc8544_ds_probe,
249 250
	.setup_arch		= mpc85xx_ds_setup_arch,
	.init_IRQ		= mpc85xx_ds_pic_init,
251
#ifdef CONFIG_PCI
252
	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
253
#endif
254
	.get_irq		= mpic_get_irq,
255
	.restart		= fsl_rstcr_restart,
256 257 258
	.calibrate_decr		= generic_calibrate_decr,
	.progress		= udbg_progress,
};
259 260 261 262 263 264 265 266 267 268

define_machine(mpc8572_ds) {
	.name			= "MPC8572 DS",
	.probe			= mpc8572_ds_probe,
	.setup_arch		= mpc85xx_ds_setup_arch,
	.init_IRQ		= mpc85xx_ds_pic_init,
#ifdef CONFIG_PCI
	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
#endif
	.get_irq		= mpic_get_irq,
269
	.restart		= fsl_rstcr_restart,
270 271 272
	.calibrate_decr		= generic_calibrate_decr,
	.progress		= udbg_progress,
};
273 274 275 276 277 278 279 280 281 282 283 284 285 286

define_machine(p2020_ds) {
	.name			= "P2020 DS",
	.probe			= p2020_ds_probe,
	.setup_arch		= mpc85xx_ds_setup_arch,
	.init_IRQ		= mpc85xx_ds_pic_init,
#ifdef CONFIG_PCI
	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
#endif
	.get_irq		= mpic_get_irq,
	.restart		= fsl_rstcr_restart,
	.calibrate_decr		= generic_calibrate_decr,
	.progress		= udbg_progress,
};