1 /*
2  * MPC85xx RDB Board Setup
3  *
4  * Copyright 2009 Freescale Semiconductor Inc.
5  *
6  * This program is free software; you can redistribute  it and/or modify it
7  * under  the terms of  the GNU General  Public License as published by the
8  * Free Software Foundation;  either version 2 of the  License, or (at your
9  * option) any later version.
10  */
11 
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/pci.h>
15 #include <linux/kdev_t.h>
16 #include <linux/delay.h>
17 #include <linux/seq_file.h>
18 #include <linux/interrupt.h>
19 #include <linux/of_platform.h>
20 
21 #include <asm/system.h>
22 #include <asm/time.h>
23 #include <asm/machdep.h>
24 #include <asm/pci-bridge.h>
25 #include <mm/mmu_decl.h>
26 #include <asm/prom.h>
27 #include <asm/udbg.h>
28 #include <asm/mpic.h>
29 
30 #include <sysdev/fsl_soc.h>
31 #include <sysdev/fsl_pci.h>
32 
33 #undef DEBUG
34 
35 #ifdef DEBUG
36 #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
37 #else
38 #define DBG(fmt, args...)
39 #endif
40 
41 
42 void __init mpc85xx_rdb_pic_init(void)
43 {
44 	struct mpic *mpic;
45 	struct resource r;
46 	struct device_node *np;
47 	unsigned long root = of_get_flat_dt_root();
48 
49 	np = of_find_node_by_type(NULL, "open-pic");
50 	if (np == NULL) {
51 		printk(KERN_ERR "Could not find open-pic node\n");
52 		return;
53 	}
54 
55 	if (of_address_to_resource(np, 0, &r)) {
56 		printk(KERN_ERR "Failed to map mpic register space\n");
57 		of_node_put(np);
58 		return;
59 	}
60 
61 	if (of_flat_dt_is_compatible(root, "fsl,MPC85XXRDB-CAMP")) {
62 		mpic = mpic_alloc(np, r.start,
63 			MPIC_PRIMARY |
64 			MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
65 			MPIC_SINGLE_DEST_CPU,
66 			0, 256, " OpenPIC  ");
67 	} else {
68 		mpic = mpic_alloc(np, r.start,
69 		  MPIC_PRIMARY | MPIC_WANTS_RESET |
70 		  MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
71 		  MPIC_SINGLE_DEST_CPU,
72 		  0, 256, " OpenPIC  ");
73 	}
74 
75 	BUG_ON(mpic == NULL);
76 	of_node_put(np);
77 
78 	mpic_init(mpic);
79 
80 }
81 
82 /*
83  * Setup the architecture
84  */
85 #ifdef CONFIG_SMP
86 extern void __init mpc85xx_smp_init(void);
87 #endif
88 static void __init mpc85xx_rdb_setup_arch(void)
89 {
90 #ifdef CONFIG_PCI
91 	struct device_node *np;
92 #endif
93 
94 	if (ppc_md.progress)
95 		ppc_md.progress("mpc85xx_rdb_setup_arch()", 0);
96 
97 #ifdef CONFIG_PCI
98 	for_each_node_by_type(np, "pci") {
99 		if (of_device_is_compatible(np, "fsl,mpc8548-pcie"))
100 			fsl_add_bridge(np, 0);
101 	}
102 
103 #endif
104 
105 #ifdef CONFIG_SMP
106 	mpc85xx_smp_init();
107 #endif
108 
109 	printk(KERN_INFO "MPC85xx RDB board from Freescale Semiconductor\n");
110 }
111 
112 static struct of_device_id __initdata mpc85xxrdb_ids[] = {
113 	{ .type = "soc", },
114 	{ .compatible = "soc", },
115 	{ .compatible = "simple-bus", },
116 	{ .compatible = "gianfar", },
117 	{},
118 };
119 
120 static int __init mpc85xxrdb_publish_devices(void)
121 {
122 	return of_platform_bus_probe(NULL, mpc85xxrdb_ids, NULL);
123 }
124 machine_device_initcall(p2020_rdb, mpc85xxrdb_publish_devices);
125 machine_device_initcall(p1020_rdb, mpc85xxrdb_publish_devices);
126 
127 /*
128  * Called very early, device-tree isn't unflattened
129  */
130 static int __init p2020_rdb_probe(void)
131 {
132 	unsigned long root = of_get_flat_dt_root();
133 
134 	if (of_flat_dt_is_compatible(root, "fsl,P2020RDB"))
135 		return 1;
136 	return 0;
137 }
138 
139 static int __init p1020_rdb_probe(void)
140 {
141 	unsigned long root = of_get_flat_dt_root();
142 
143 	if (of_flat_dt_is_compatible(root, "fsl,P1020RDB"))
144 		return 1;
145 	return 0;
146 }
147 
148 define_machine(p2020_rdb) {
149 	.name			= "P2020 RDB",
150 	.probe			= p2020_rdb_probe,
151 	.setup_arch		= mpc85xx_rdb_setup_arch,
152 	.init_IRQ		= mpc85xx_rdb_pic_init,
153 #ifdef CONFIG_PCI
154 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
155 #endif
156 	.get_irq		= mpic_get_irq,
157 	.restart		= fsl_rstcr_restart,
158 	.calibrate_decr		= generic_calibrate_decr,
159 	.progress		= udbg_progress,
160 };
161 
162 define_machine(p1020_rdb) {
163 	.name			= "P1020 RDB",
164 	.probe			= p1020_rdb_probe,
165 	.setup_arch		= mpc85xx_rdb_setup_arch,
166 	.init_IRQ		= mpc85xx_rdb_pic_init,
167 #ifdef CONFIG_PCI
168 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
169 #endif
170 	.get_irq		= mpic_get_irq,
171 	.restart		= fsl_rstcr_restart,
172 	.calibrate_decr		= generic_calibrate_decr,
173 	.progress		= udbg_progress,
174 };
175