[POWERPC] Fix OF node refcnt underflow in 836x and 832x platform code
[linux-2.6/verdex.git] / arch / powerpc / platforms / 83xx / mpc832x_mds.c
blob4d471190be8dc8ea877ca35fbc893b29b42fc635
1 /*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
4 * Description:
5 * MPC832xE MDS board specific routines.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
17 #include <linux/reboot.h>
18 #include <linux/pci.h>
19 #include <linux/kdev_t.h>
20 #include <linux/major.h>
21 #include <linux/console.h>
22 #include <linux/delay.h>
23 #include <linux/seq_file.h>
24 #include <linux/root_dev.h>
25 #include <linux/initrd.h>
27 #include <asm/of_device.h>
28 #include <asm/system.h>
29 #include <asm/atomic.h>
30 #include <asm/time.h>
31 #include <asm/io.h>
32 #include <asm/machdep.h>
33 #include <asm/ipic.h>
34 #include <asm/bootinfo.h>
35 #include <asm/irq.h>
36 #include <asm/prom.h>
37 #include <asm/udbg.h>
38 #include <sysdev/fsl_soc.h>
39 #include <asm/qe.h>
40 #include <asm/qe_ic.h>
42 #include "mpc83xx.h"
43 #include "mpc832x_mds.h"
45 #undef DEBUG
46 #ifdef DEBUG
47 #define DBG(fmt...) udbg_printf(fmt)
48 #else
49 #define DBG(fmt...)
50 #endif
52 #ifndef CONFIG_PCI
53 unsigned long isa_io_base = 0;
54 unsigned long isa_mem_base = 0;
55 #endif
57 static u8 *bcsr_regs = NULL;
59 u8 *get_bcsr(void)
61 return bcsr_regs;
64 /* ************************************************************************
66 * Setup the architecture
69 static void __init mpc832x_sys_setup_arch(void)
71 struct device_node *np;
73 if (ppc_md.progress)
74 ppc_md.progress("mpc832x_sys_setup_arch()", 0);
76 np = of_find_node_by_type(NULL, "cpu");
77 if (np != 0) {
78 unsigned int *fp =
79 (int *)get_property(np, "clock-frequency", NULL);
80 if (fp != 0)
81 loops_per_jiffy = *fp / HZ;
82 else
83 loops_per_jiffy = 50000000 / HZ;
84 of_node_put(np);
87 /* Map BCSR area */
88 np = of_find_node_by_name(NULL, "bcsr");
89 if (np != 0) {
90 struct resource res;
92 of_address_to_resource(np, 0, &res);
93 bcsr_regs = ioremap(res.start, res.end - res.start +1);
94 of_node_put(np);
97 #ifdef CONFIG_PCI
98 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
99 add_bridge(np);
100 ppc_md.pci_exclude_device = mpc83xx_exclude_device;
101 #endif
103 #ifdef CONFIG_QUICC_ENGINE
104 qe_reset();
106 if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
107 par_io_init(np);
108 of_node_put(np);
110 for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
111 par_io_of_config(np);
114 if ((np = of_find_compatible_node(NULL, "network", "ucc_geth"))
115 != NULL){
116 /* Reset the Ethernet PHY */
117 bcsr_regs[9] &= ~0x20;
118 udelay(1000);
119 bcsr_regs[9] |= 0x20;
120 iounmap(bcsr_regs);
121 of_node_put(np);
124 #endif /* CONFIG_QUICC_ENGINE */
126 #ifdef CONFIG_BLK_DEV_INITRD
127 if (initrd_start)
128 ROOT_DEV = Root_RAM0;
129 else
130 #endif
131 #ifdef CONFIG_ROOT_NFS
132 ROOT_DEV = Root_NFS;
133 #else
134 ROOT_DEV = Root_HDA1;
135 #endif
138 static int __init mpc832x_declare_of_platform_devices(void)
140 struct device_node *np;
142 for (np = NULL; (np = of_find_compatible_node(np, "network",
143 "ucc_geth")) != NULL;) {
144 int ucc_num;
145 char bus_id[BUS_ID_SIZE];
147 ucc_num = *((uint *) get_property(np, "device-id", NULL)) - 1;
148 snprintf(bus_id, BUS_ID_SIZE, "ucc_geth.%u", ucc_num);
149 of_platform_device_create(np, bus_id, NULL);
152 return 0;
154 device_initcall(mpc832x_declare_of_platform_devices);
156 void __init mpc832x_sys_init_IRQ(void)
159 struct device_node *np;
161 np = of_find_node_by_type(NULL, "ipic");
162 if (!np)
163 return;
165 ipic_init(np, 0);
167 /* Initialize the default interrupt mapping priorities,
168 * in case the boot rom changed something on us.
170 ipic_set_default_priority();
171 of_node_put(np);
173 #ifdef CONFIG_QUICC_ENGINE
174 np = of_find_node_by_type(NULL, "qeic");
175 if (!np)
176 return;
178 qe_ic_init(np, 0);
179 of_node_put(np);
180 #endif /* CONFIG_QUICC_ENGINE */
183 #if defined(CONFIG_I2C_MPC) && defined(CONFIG_SENSORS_DS1374)
184 extern ulong ds1374_get_rtc_time(void);
185 extern int ds1374_set_rtc_time(ulong);
187 static int __init mpc832x_rtc_hookup(void)
189 struct timespec tv;
191 ppc_md.get_rtc_time = ds1374_get_rtc_time;
192 ppc_md.set_rtc_time = ds1374_set_rtc_time;
194 tv.tv_nsec = 0;
195 tv.tv_sec = (ppc_md.get_rtc_time) ();
196 do_settimeofday(&tv);
198 return 0;
201 late_initcall(mpc832x_rtc_hookup);
202 #endif
205 * Called very early, MMU is off, device-tree isn't unflattened
207 static int __init mpc832x_sys_probe(void)
209 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
210 "model", NULL);
212 if (model == NULL)
213 return 0;
214 if (strcmp(model, "MPC8323EMDS"))
215 return 0;
217 DBG("%s found\n", model);
219 return 1;
222 define_machine(mpc832x_mds) {
223 .name = "MPC832x MDS",
224 .probe = mpc832x_sys_probe,
225 .setup_arch = mpc832x_sys_setup_arch,
226 .init_IRQ = mpc832x_sys_init_IRQ,
227 .get_irq = ipic_get_irq,
228 .restart = mpc83xx_restart,
229 .time_init = mpc83xx_time_init,
230 .calibrate_decr = generic_calibrate_decr,
231 .progress = udbg_progress,