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);
53 EXPORT_SYMBOL(get_immrbase);
55 static int __init gfar_mdio_of_init(void)
57 struct device_node *np;
59 struct platform_device *mdio_dev;
63 for (np = NULL, i = 0;
64 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
67 struct device_node *child = NULL;
68 struct gianfar_mdio_data mdio_data;
70 memset(&res, 0, sizeof(res));
71 memset(&mdio_data, 0, sizeof(mdio_data));
73 ret = of_address_to_resource(np, 0, &res);
78 platform_device_register_simple("fsl-gianfar_mdio",
80 if (IS_ERR(mdio_dev)) {
81 ret = PTR_ERR(mdio_dev);
85 for (k = 0; k < 32; k++)
86 mdio_data.irq[k] = -1;
88 while ((child = of_get_next_child(np, child)) != NULL) {
91 (u32 *) get_property(child, "reg", NULL);
92 mdio_data.irq[*id] = child->intrs[0].line;
97 platform_device_add_data(mdio_dev, &mdio_data,
98 sizeof(struct gianfar_mdio_data));
106 platform_device_unregister(mdio_dev);
111 arch_initcall(gfar_mdio_of_init);
113 static const char *gfar_tx_intr = "tx";
114 static const char *gfar_rx_intr = "rx";
115 static const char *gfar_err_intr = "error";
117 static int __init gfar_of_init(void)
119 struct device_node *np;
121 struct platform_device *gfar_dev;
125 for (np = NULL, i = 0;
126 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
128 struct resource r[4];
129 struct device_node *phy, *mdio;
130 struct gianfar_platform_data gfar_data;
136 memset(r, 0, sizeof(r));
137 memset(&gfar_data, 0, sizeof(gfar_data));
139 ret = of_address_to_resource(np, 0, &r[0]);
143 r[1].start = np->intrs[0].line;
144 r[1].end = np->intrs[0].line;
145 r[1].flags = IORESOURCE_IRQ;
147 model = get_property(np, "model", NULL);
149 /* If we aren't the FEC we have multiple interrupts */
150 if (model && strcasecmp(model, "FEC")) {
151 r[1].name = gfar_tx_intr;
153 r[2].name = gfar_rx_intr;
154 r[2].start = np->intrs[1].line;
155 r[2].end = np->intrs[1].line;
156 r[2].flags = IORESOURCE_IRQ;
158 r[3].name = gfar_err_intr;
159 r[3].start = np->intrs[2].line;
160 r[3].end = np->intrs[2].line;
161 r[3].flags = IORESOURCE_IRQ;
165 platform_device_register_simple("fsl-gianfar", i, &r[0],
168 if (IS_ERR(gfar_dev)) {
169 ret = PTR_ERR(gfar_dev);
173 mac_addr = get_property(np, "address", NULL);
174 memcpy(gfar_data.mac_addr, mac_addr, 6);
176 if (model && !strcasecmp(model, "TSEC"))
177 gfar_data.device_flags =
178 FSL_GIANFAR_DEV_HAS_GIGABIT |
179 FSL_GIANFAR_DEV_HAS_COALESCE |
180 FSL_GIANFAR_DEV_HAS_RMON |
181 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
182 if (model && !strcasecmp(model, "eTSEC"))
183 gfar_data.device_flags =
184 FSL_GIANFAR_DEV_HAS_GIGABIT |
185 FSL_GIANFAR_DEV_HAS_COALESCE |
186 FSL_GIANFAR_DEV_HAS_RMON |
187 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
188 FSL_GIANFAR_DEV_HAS_CSUM |
189 FSL_GIANFAR_DEV_HAS_VLAN |
190 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
192 ph = (phandle *) get_property(np, "phy-handle", NULL);
193 phy = of_find_node_by_phandle(*ph);
200 mdio = of_get_parent(phy);
202 id = (u32 *) get_property(phy, "reg", NULL);
203 ret = of_address_to_resource(mdio, 0, &res);
210 gfar_data.phy_id = *id;
211 gfar_data.bus_id = res.start;
217 platform_device_add_data(gfar_dev, &gfar_data,
219 gianfar_platform_data));
227 platform_device_unregister(gfar_dev);
232 arch_initcall(gfar_of_init);
234 static int __init fsl_i2c_of_init(void)
236 struct device_node *np;
238 struct platform_device *i2c_dev;
241 for (np = NULL, i = 0;
242 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
244 struct resource r[2];
245 struct fsl_i2c_platform_data i2c_data;
246 unsigned char *flags = NULL;
248 memset(&r, 0, sizeof(r));
249 memset(&i2c_data, 0, sizeof(i2c_data));
251 ret = of_address_to_resource(np, 0, &r[0]);
255 r[1].start = np->intrs[0].line;
256 r[1].end = np->intrs[0].line;
257 r[1].flags = IORESOURCE_IRQ;
259 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
260 if (IS_ERR(i2c_dev)) {
261 ret = PTR_ERR(i2c_dev);
265 i2c_data.device_flags = 0;
266 flags = get_property(np, "dfsrr", NULL);
268 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
270 flags = get_property(np, "fsl5200-clocking", NULL);
272 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
275 platform_device_add_data(i2c_dev, &i2c_data,
277 fsl_i2c_platform_data));
285 platform_device_unregister(i2c_dev);
290 arch_initcall(fsl_i2c_of_init);
292 #ifdef CONFIG_PPC_83xx
293 static int __init mpc83xx_wdt_init(void)
296 struct device_node *soc, *np;
297 struct platform_device *dev;
301 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
308 soc = of_find_node_by_type(NULL, "soc");
315 freq = (unsigned int *)get_property(soc, "bus-frequency", NULL);
321 memset(&r, 0, sizeof(r));
323 ret = of_address_to_resource(np, 0, &r);
327 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
333 ret = platform_device_add_data(dev, freq, sizeof(int));
343 platform_device_unregister(dev);
352 arch_initcall(mpc83xx_wdt_init);
355 static enum fsl_usb2_phy_modes determine_usb_phy(char * phy_type)
358 return FSL_USB2_PHY_NONE;
359 if (!strcasecmp(phy_type, "ulpi"))
360 return FSL_USB2_PHY_ULPI;
361 if (!strcasecmp(phy_type, "utmi"))
362 return FSL_USB2_PHY_UTMI;
363 if (!strcasecmp(phy_type, "utmi_wide"))
364 return FSL_USB2_PHY_UTMI_WIDE;
365 if (!strcasecmp(phy_type, "serial"))
366 return FSL_USB2_PHY_SERIAL;
368 return FSL_USB2_PHY_NONE;
371 static int __init fsl_usb_of_init(void)
373 struct device_node *np;
375 struct platform_device *usb_dev;
378 for (np = NULL, i = 0;
379 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
381 struct resource r[2];
382 struct fsl_usb2_platform_data usb_data;
383 unsigned char *prop = NULL;
385 memset(&r, 0, sizeof(r));
386 memset(&usb_data, 0, sizeof(usb_data));
388 ret = of_address_to_resource(np, 0, &r[0]);
392 r[1].start = np->intrs[0].line;
393 r[1].end = np->intrs[0].line;
394 r[1].flags = IORESOURCE_IRQ;
397 platform_device_register_simple("fsl-usb2-mph", i, r, 2);
398 if (IS_ERR(usb_dev)) {
399 ret = PTR_ERR(usb_dev);
403 usb_dev->dev.coherent_dma_mask = 0xffffffffUL;
404 usb_dev->dev.dma_mask = &usb_dev->dev.coherent_dma_mask;
406 usb_data.operating_mode = FSL_USB2_MPH_HOST;
408 prop = get_property(np, "port0", NULL);
410 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
412 prop = get_property(np, "port1", NULL);
414 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
416 prop = get_property(np, "phy_type", NULL);
417 usb_data.phy_mode = determine_usb_phy(prop);
420 platform_device_add_data(usb_dev, &usb_data,
422 fsl_usb2_platform_data));
430 platform_device_unregister(usb_dev);
435 arch_initcall(fsl_usb_of_init);
437 static int __init fsl_usb_dr_of_init(void)
439 struct device_node *np;
441 struct platform_device *usb_dev;
444 for (np = NULL, i = 0;
445 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
447 struct resource r[2];
448 struct fsl_usb2_platform_data usb_data;
449 unsigned char *prop = NULL;
451 memset(&r, 0, sizeof(r));
452 memset(&usb_data, 0, sizeof(usb_data));
454 ret = of_address_to_resource(np, 0, &r[0]);
458 r[1].start = np->intrs[0].line;
459 r[1].end = np->intrs[0].line;
460 r[1].flags = IORESOURCE_IRQ;
463 platform_device_register_simple("fsl-usb2-dr", i, r, 2);
464 if (IS_ERR(usb_dev)) {
465 ret = PTR_ERR(usb_dev);
469 usb_dev->dev.coherent_dma_mask = 0xffffffffUL;
470 usb_dev->dev.dma_mask = &usb_dev->dev.coherent_dma_mask;
472 usb_data.operating_mode = FSL_USB2_DR_HOST;
474 prop = get_property(np, "phy_type", NULL);
475 usb_data.phy_mode = determine_usb_phy(prop);
478 platform_device_add_data(usb_dev, &usb_data,
480 fsl_usb2_platform_data));
488 platform_device_unregister(usb_dev);
493 arch_initcall(fsl_usb_dr_of_init);