4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
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.
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
17 #include <linux/major.h>
18 #include <linux/delay.h>
19 #include <linux/irq.h>
20 #include <linux/module.h>
21 #include <linux/device.h>
22 #include <linux/platform_device.h>
23 #include <linux/fsl_devices.h>
25 #include <asm/system.h>
26 #include <asm/atomic.h>
30 #include <sysdev/fsl_soc.h>
31 #include <mm/mmu_decl.h>
33 static phys_addr_t immrbase
= -1;
35 phys_addr_t
get_immrbase(void)
37 struct device_node
*soc
;
42 soc
= of_find_node_by_type(NULL
, "soc");
45 void *prop
= get_property(soc
, "reg", &size
);
46 immrbase
= of_translate_address(soc
, prop
);
52 EXPORT_SYMBOL(get_immrbase
);
54 static const char * gfar_tx_intr
= "tx";
55 static const char * gfar_rx_intr
= "rx";
56 static const char * gfar_err_intr
= "error";
58 static int __init
gfar_of_init(void)
60 struct device_node
*np
;
62 struct platform_device
*mdio_dev
, *gfar_dev
;
66 for (np
= NULL
, i
= 0; (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
; i
++) {
68 struct device_node
*child
= NULL
;
69 struct gianfar_mdio_data mdio_data
;
71 memset(&res
, 0, sizeof(res
));
72 memset(&mdio_data
, 0, sizeof(mdio_data
));
74 ret
= of_address_to_resource(np
, 0, &res
);
78 mdio_dev
= platform_device_register_simple("fsl-gianfar_mdio", res
.start
, &res
, 1);
79 if (IS_ERR(mdio_dev
)) {
80 ret
= PTR_ERR(mdio_dev
);
84 for (k
= 0; k
< 32; k
++)
85 mdio_data
.irq
[k
] = -1;
87 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
89 u32
*id
= (u32
*) get_property(child
, "reg", NULL
);
90 mdio_data
.irq
[*id
] = child
->intrs
[0].line
;
94 ret
= platform_device_add_data(mdio_dev
, &mdio_data
, sizeof(struct gianfar_mdio_data
));
99 for (np
= NULL
, i
= 0; (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
; i
++) {
100 struct resource r
[4];
101 struct device_node
*phy
, *mdio
;
102 struct gianfar_platform_data gfar_data
;
108 memset(r
, 0, sizeof(r
));
109 memset(&gfar_data
, 0, sizeof(gfar_data
));
111 ret
= of_address_to_resource(np
, 0, &r
[0]);
115 r
[1].start
= np
->intrs
[0].line
;
116 r
[1].end
= np
->intrs
[0].line
;
117 r
[1].flags
= IORESOURCE_IRQ
;
119 model
= get_property(np
, "model", NULL
);
121 /* If we aren't the FEC we have multiple interrupts */
122 if (model
&& strcasecmp(model
, "FEC")) {
123 r
[1].name
= gfar_tx_intr
;
125 r
[2].name
= gfar_rx_intr
;
126 r
[2].start
= np
->intrs
[1].line
;
127 r
[2].end
= np
->intrs
[1].line
;
128 r
[2].flags
= IORESOURCE_IRQ
;
130 r
[3].name
= gfar_err_intr
;
131 r
[3].start
= np
->intrs
[2].line
;
132 r
[3].end
= np
->intrs
[2].line
;
133 r
[3].flags
= IORESOURCE_IRQ
;
136 gfar_dev
= platform_device_register_simple("fsl-gianfar", i
, &r
[0], np
->n_intrs
+ 1);
138 if (IS_ERR(gfar_dev
)) {
139 ret
= PTR_ERR(gfar_dev
);
143 mac_addr
= get_property(np
, "address", NULL
);
144 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
146 if (model
&& !strcasecmp(model
, "TSEC"))
147 gfar_data
.device_flags
=
148 FSL_GIANFAR_DEV_HAS_GIGABIT
|
149 FSL_GIANFAR_DEV_HAS_COALESCE
|
150 FSL_GIANFAR_DEV_HAS_RMON
|
151 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
152 if (model
&& !strcasecmp(model
, "eTSEC"))
153 gfar_data
.device_flags
=
154 FSL_GIANFAR_DEV_HAS_GIGABIT
|
155 FSL_GIANFAR_DEV_HAS_COALESCE
|
156 FSL_GIANFAR_DEV_HAS_RMON
|
157 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
158 FSL_GIANFAR_DEV_HAS_CSUM
|
159 FSL_GIANFAR_DEV_HAS_VLAN
|
160 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
162 ph
= (phandle
*) get_property(np
, "phy-handle", NULL
);
163 phy
= of_find_node_by_phandle(*ph
);
170 mdio
= of_get_parent(phy
);
172 id
= (u32
*) get_property(phy
, "reg", NULL
);
173 ret
= of_address_to_resource(mdio
, 0, &res
);
180 gfar_data
.phy_id
= *id
;
181 gfar_data
.bus_id
= res
.start
;
186 ret
= platform_device_add_data(gfar_dev
, &gfar_data
, sizeof(struct gianfar_platform_data
));
194 platform_device_unregister(mdio_dev
);
199 platform_device_unregister(gfar_dev
);
203 arch_initcall(gfar_of_init
);
205 static int __init
fsl_i2c_of_init(void)
207 struct device_node
*np
;
209 struct platform_device
*i2c_dev
;
212 for (np
= NULL
, i
= 0; (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
; i
++) {
213 struct resource r
[2];
214 struct fsl_i2c_platform_data i2c_data
;
215 unsigned char * flags
= NULL
;
217 memset(&r
, 0, sizeof(r
));
218 memset(&i2c_data
, 0, sizeof(i2c_data
));
220 ret
= of_address_to_resource(np
, 0, &r
[0]);
224 r
[1].start
= np
->intrs
[0].line
;
225 r
[1].end
= np
->intrs
[0].line
;
226 r
[1].flags
= IORESOURCE_IRQ
;
228 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
229 if (IS_ERR(i2c_dev
)) {
230 ret
= PTR_ERR(i2c_dev
);
234 i2c_data
.device_flags
= 0;
235 flags
= get_property(np
, "dfsrr", NULL
);
237 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
239 flags
= get_property(np
, "fsl5200-clocking", NULL
);
241 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
243 ret
= platform_device_add_data(i2c_dev
, &i2c_data
, sizeof(struct fsl_i2c_platform_data
));
251 platform_device_unregister(i2c_dev
);
255 arch_initcall(fsl_i2c_of_init
);
257 #ifdef CONFIG_PPC_83xx
258 static int __init
mpc83xx_wdt_init(void)
261 struct device_node
*soc
, *np
;
262 struct platform_device
*dev
;
266 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
270 goto mpc83xx_wdt_nodev
;
273 soc
= of_find_node_by_type(NULL
, "soc");
277 goto mpc83xx_wdt_nosoc
;
280 freq
= (unsigned int *)get_property(soc
, "bus-frequency", NULL
);
283 goto mpc83xx_wdt_err
;
286 memset(&r
, 0, sizeof(r
));
288 ret
= of_address_to_resource(np
, 0, &r
);
290 goto mpc83xx_wdt_err
;
292 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
295 goto mpc83xx_wdt_err
;
298 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
300 goto mpc83xx_wdt_unreg
;
308 platform_device_unregister(dev
);
316 arch_initcall(mpc83xx_wdt_init
);