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/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/errno.h>
16 #include <linux/major.h>
17 #include <linux/delay.h>
18 #include <linux/irq.h>
19 #include <linux/module.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
22 #include <linux/fsl_devices.h>
24 #include <asm/system.h>
25 #include <asm/atomic.h>
29 #include <sysdev/fsl_soc.h>
30 #include <mm/mmu_decl.h>
32 static phys_addr_t immrbase
= -1;
34 phys_addr_t
get_immrbase(void)
36 struct device_node
*soc
;
41 soc
= of_find_node_by_type(NULL
, "soc");
44 const void *prop
= get_property(soc
, "reg", &size
);
45 immrbase
= of_translate_address(soc
, prop
);
52 EXPORT_SYMBOL(get_immrbase
);
54 static int __init
gfar_mdio_of_init(void)
56 struct device_node
*np
;
58 struct platform_device
*mdio_dev
;
62 for (np
= NULL
, i
= 0;
63 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
66 struct device_node
*child
= NULL
;
67 struct gianfar_mdio_data mdio_data
;
69 memset(&res
, 0, sizeof(res
));
70 memset(&mdio_data
, 0, sizeof(mdio_data
));
72 ret
= of_address_to_resource(np
, 0, &res
);
77 platform_device_register_simple("fsl-gianfar_mdio",
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
) {
88 const u32
*id
= get_property(child
, "reg", NULL
);
89 mdio_data
.irq
[*id
] = irq_of_parse_and_map(child
, 0);
93 platform_device_add_data(mdio_dev
, &mdio_data
,
94 sizeof(struct gianfar_mdio_data
));
102 platform_device_unregister(mdio_dev
);
107 arch_initcall(gfar_mdio_of_init
);
109 static const char *gfar_tx_intr
= "tx";
110 static const char *gfar_rx_intr
= "rx";
111 static const char *gfar_err_intr
= "error";
113 static int __init
gfar_of_init(void)
115 struct device_node
*np
;
117 struct platform_device
*gfar_dev
;
121 for (np
= NULL
, i
= 0;
122 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
124 struct resource r
[4];
125 struct device_node
*phy
, *mdio
;
126 struct gianfar_platform_data gfar_data
;
127 const unsigned int *id
;
129 const void *mac_addr
;
133 memset(r
, 0, sizeof(r
));
134 memset(&gfar_data
, 0, sizeof(gfar_data
));
136 ret
= of_address_to_resource(np
, 0, &r
[0]);
140 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
141 r
[1].flags
= IORESOURCE_IRQ
;
143 model
= get_property(np
, "model", NULL
);
145 /* If we aren't the FEC we have multiple interrupts */
146 if (model
&& strcasecmp(model
, "FEC")) {
147 r
[1].name
= gfar_tx_intr
;
149 r
[2].name
= gfar_rx_intr
;
150 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 1);
151 r
[2].flags
= IORESOURCE_IRQ
;
153 r
[3].name
= gfar_err_intr
;
154 r
[3].start
= r
[3].end
= irq_of_parse_and_map(np
, 2);
155 r
[3].flags
= IORESOURCE_IRQ
;
161 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
164 if (IS_ERR(gfar_dev
)) {
165 ret
= PTR_ERR(gfar_dev
);
169 mac_addr
= get_property(np
, "local-mac-address", NULL
);
170 if (mac_addr
== NULL
)
171 mac_addr
= get_property(np
, "mac-address", NULL
);
172 if (mac_addr
== NULL
) {
174 mac_addr
= get_property(np
, "address", NULL
);
178 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
180 if (model
&& !strcasecmp(model
, "TSEC"))
181 gfar_data
.device_flags
=
182 FSL_GIANFAR_DEV_HAS_GIGABIT
|
183 FSL_GIANFAR_DEV_HAS_COALESCE
|
184 FSL_GIANFAR_DEV_HAS_RMON
|
185 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
186 if (model
&& !strcasecmp(model
, "eTSEC"))
187 gfar_data
.device_flags
=
188 FSL_GIANFAR_DEV_HAS_GIGABIT
|
189 FSL_GIANFAR_DEV_HAS_COALESCE
|
190 FSL_GIANFAR_DEV_HAS_RMON
|
191 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
192 FSL_GIANFAR_DEV_HAS_CSUM
|
193 FSL_GIANFAR_DEV_HAS_VLAN
|
194 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
196 ph
= get_property(np
, "phy-handle", NULL
);
197 phy
= of_find_node_by_phandle(*ph
);
204 mdio
= of_get_parent(phy
);
206 id
= get_property(phy
, "reg", NULL
);
207 ret
= of_address_to_resource(mdio
, 0, &res
);
214 gfar_data
.phy_id
= *id
;
215 gfar_data
.bus_id
= res
.start
;
221 platform_device_add_data(gfar_dev
, &gfar_data
,
223 gianfar_platform_data
));
231 platform_device_unregister(gfar_dev
);
236 arch_initcall(gfar_of_init
);
238 static int __init
fsl_i2c_of_init(void)
240 struct device_node
*np
;
242 struct platform_device
*i2c_dev
;
245 for (np
= NULL
, i
= 0;
246 (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
;
248 struct resource r
[2];
249 struct fsl_i2c_platform_data i2c_data
;
250 const unsigned char *flags
= NULL
;
252 memset(&r
, 0, sizeof(r
));
253 memset(&i2c_data
, 0, sizeof(i2c_data
));
255 ret
= of_address_to_resource(np
, 0, &r
[0]);
259 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
260 r
[1].flags
= IORESOURCE_IRQ
;
262 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
263 if (IS_ERR(i2c_dev
)) {
264 ret
= PTR_ERR(i2c_dev
);
268 i2c_data
.device_flags
= 0;
269 flags
= get_property(np
, "dfsrr", NULL
);
271 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
273 flags
= get_property(np
, "fsl5200-clocking", NULL
);
275 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
278 platform_device_add_data(i2c_dev
, &i2c_data
,
280 fsl_i2c_platform_data
));
288 platform_device_unregister(i2c_dev
);
293 arch_initcall(fsl_i2c_of_init
);
295 #ifdef CONFIG_PPC_83xx
296 static int __init
mpc83xx_wdt_init(void)
299 struct device_node
*soc
, *np
;
300 struct platform_device
*dev
;
301 const unsigned int *freq
;
304 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
311 soc
= of_find_node_by_type(NULL
, "soc");
318 freq
= get_property(soc
, "bus-frequency", NULL
);
324 memset(&r
, 0, sizeof(r
));
326 ret
= of_address_to_resource(np
, 0, &r
);
330 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
336 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
346 platform_device_unregister(dev
);
355 arch_initcall(mpc83xx_wdt_init
);
358 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
361 return FSL_USB2_PHY_NONE
;
362 if (!strcasecmp(phy_type
, "ulpi"))
363 return FSL_USB2_PHY_ULPI
;
364 if (!strcasecmp(phy_type
, "utmi"))
365 return FSL_USB2_PHY_UTMI
;
366 if (!strcasecmp(phy_type
, "utmi_wide"))
367 return FSL_USB2_PHY_UTMI_WIDE
;
368 if (!strcasecmp(phy_type
, "serial"))
369 return FSL_USB2_PHY_SERIAL
;
371 return FSL_USB2_PHY_NONE
;
374 static int __init
fsl_usb_of_init(void)
376 struct device_node
*np
;
378 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr
= NULL
;
381 for (np
= NULL
, i
= 0;
382 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
384 struct resource r
[2];
385 struct fsl_usb2_platform_data usb_data
;
386 const unsigned char *prop
= NULL
;
388 memset(&r
, 0, sizeof(r
));
389 memset(&usb_data
, 0, sizeof(usb_data
));
391 ret
= of_address_to_resource(np
, 0, &r
[0]);
395 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
396 r
[1].flags
= IORESOURCE_IRQ
;
399 platform_device_register_simple("fsl-ehci", i
, r
, 2);
400 if (IS_ERR(usb_dev_mph
)) {
401 ret
= PTR_ERR(usb_dev_mph
);
405 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
406 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
408 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
410 prop
= get_property(np
, "port0", NULL
);
412 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
414 prop
= get_property(np
, "port1", NULL
);
416 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
418 prop
= get_property(np
, "phy_type", NULL
);
419 usb_data
.phy_mode
= determine_usb_phy(prop
);
422 platform_device_add_data(usb_dev_mph
, &usb_data
,
424 fsl_usb2_platform_data
));
430 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
432 struct resource r
[2];
433 struct fsl_usb2_platform_data usb_data
;
434 const unsigned char *prop
= NULL
;
436 memset(&r
, 0, sizeof(r
));
437 memset(&usb_data
, 0, sizeof(usb_data
));
439 ret
= of_address_to_resource(np
, 0, &r
[0]);
443 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
444 r
[1].flags
= IORESOURCE_IRQ
;
447 platform_device_register_simple("fsl-ehci", i
, r
, 2);
448 if (IS_ERR(usb_dev_dr
)) {
449 ret
= PTR_ERR(usb_dev_dr
);
453 usb_dev_dr
->dev
.coherent_dma_mask
= 0xffffffffUL
;
454 usb_dev_dr
->dev
.dma_mask
= &usb_dev_dr
->dev
.coherent_dma_mask
;
456 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
458 prop
= get_property(np
, "phy_type", NULL
);
459 usb_data
.phy_mode
= determine_usb_phy(prop
);
462 platform_device_add_data(usb_dev_dr
, &usb_data
,
464 fsl_usb2_platform_data
));
472 platform_device_unregister(usb_dev_dr
);
475 platform_device_unregister(usb_dev_mph
);
480 arch_initcall(fsl_usb_of_init
);