blob: f3abce11bead3b8e345a69a13c2afc65c486072a [file] [log] [blame]
Kumar Galaeed32002006-01-13 11:19:13 -06001/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
Vitaly Bordugfba43662006-09-21 17:26:34 +04006 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
8 *
Kumar Galaeed32002006-01-13 11:19:13 -06009 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
Kumar Galaeed32002006-01-13 11:19:13 -060015#include <linux/stddef.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/errno.h>
19#include <linux/major.h>
20#include <linux/delay.h>
21#include <linux/irq.h>
22#include <linux/module.h>
23#include <linux/device.h>
24#include <linux/platform_device.h>
Kumar Gala0af666f2007-08-17 08:23:06 -050025#include <linux/of_platform.h>
Andy Fleminga9b14972006-10-19 19:52:26 -050026#include <linux/phy.h>
Kumar Galaeed32002006-01-13 11:19:13 -060027#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040028#include <linux/fs_enet_pd.h>
29#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060030
31#include <asm/system.h>
32#include <asm/atomic.h>
33#include <asm/io.h>
34#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040035#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060036#include <asm/prom.h>
37#include <sysdev/fsl_soc.h>
38#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040039#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060040
Vitaly Bordugd3465c92006-09-21 22:38:05 +040041extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030042extern void init_fec_ioports(struct fs_platform_info*);
43extern void init_smc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060044static phys_addr_t immrbase = -1;
45
46phys_addr_t get_immrbase(void)
47{
48 struct device_node *soc;
49
50 if (immrbase != -1)
51 return immrbase;
52
53 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060054 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060055 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100056 const void *prop = of_get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040057
58 if (prop)
59 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060060 of_node_put(soc);
61 };
62
63 return immrbase;
64}
Kumar Gala2fb07d72006-01-23 16:58:04 -060065
Kumar Galaeed32002006-01-13 11:19:13 -060066EXPORT_SYMBOL(get_immrbase);
67
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030068#if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +040069
70static u32 brgfreq = -1;
71
72u32 get_brgfreq(void)
73{
74 struct device_node *node;
75
76 if (brgfreq != -1)
77 return brgfreq;
78
79 node = of_find_node_by_type(NULL, "cpm");
80 if (node) {
81 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100082 const unsigned int *prop = of_get_property(node,
83 "brg-frequency", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040084
85 if (prop)
86 brgfreq = *prop;
87 of_node_put(node);
88 };
89
90 return brgfreq;
91}
92
93EXPORT_SYMBOL(get_brgfreq);
94
95static u32 fs_baudrate = -1;
96
97u32 get_baudrate(void)
98{
99 struct device_node *node;
100
101 if (fs_baudrate != -1)
102 return fs_baudrate;
103
104 node = of_find_node_by_type(NULL, "serial");
105 if (node) {
106 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000107 const unsigned int *prop = of_get_property(node,
108 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400109
110 if (prop)
111 fs_baudrate = *prop;
112 of_node_put(node);
113 };
114
115 return fs_baudrate;
116}
117
118EXPORT_SYMBOL(get_baudrate);
119#endif /* CONFIG_CPM2 */
120
Kumar Gala2fb07d72006-01-23 16:58:04 -0600121static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600122{
123 struct device_node *np;
124 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600125 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600126 struct resource res;
127 int ret;
128
Kumar Gala2fb07d72006-01-23 16:58:04 -0600129 for (np = NULL, i = 0;
130 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
131 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600132 int k;
133 struct device_node *child = NULL;
134 struct gianfar_mdio_data mdio_data;
135
136 memset(&res, 0, sizeof(res));
137 memset(&mdio_data, 0, sizeof(mdio_data));
138
139 ret = of_address_to_resource(np, 0, &res);
140 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600141 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600142
Kumar Gala2fb07d72006-01-23 16:58:04 -0600143 mdio_dev =
144 platform_device_register_simple("fsl-gianfar_mdio",
145 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600146 if (IS_ERR(mdio_dev)) {
147 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600148 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600149 }
150
151 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500152 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600153
154 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400155 int irq = irq_of_parse_and_map(child, 0);
156 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000157 const u32 *id = of_get_property(child,
158 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400159 mdio_data.irq[*id] = irq;
160 }
Kumar Galaeed32002006-01-13 11:19:13 -0600161 }
162
Kumar Gala2fb07d72006-01-23 16:58:04 -0600163 ret =
164 platform_device_add_data(mdio_dev, &mdio_data,
165 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600166 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600167 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600168 }
169
Kumar Gala2fb07d72006-01-23 16:58:04 -0600170 return 0;
171
172unreg:
173 platform_device_unregister(mdio_dev);
174err:
175 return ret;
176}
177
178arch_initcall(gfar_mdio_of_init);
179
180static const char *gfar_tx_intr = "tx";
181static const char *gfar_rx_intr = "rx";
182static const char *gfar_err_intr = "error";
183
Andy Fleminga9b14972006-10-19 19:52:26 -0500184
Kumar Gala2fb07d72006-01-23 16:58:04 -0600185static int __init gfar_of_init(void)
186{
187 struct device_node *np;
188 unsigned int i;
189 struct platform_device *gfar_dev;
190 struct resource res;
191 int ret;
192
193 for (np = NULL, i = 0;
194 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
195 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600196 struct resource r[4];
197 struct device_node *phy, *mdio;
198 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000199 const unsigned int *id;
200 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500201 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000202 const void *mac_addr;
203 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400204 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600205
206 memset(r, 0, sizeof(r));
207 memset(&gfar_data, 0, sizeof(gfar_data));
208
209 ret = of_address_to_resource(np, 0, &r[0]);
210 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600211 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600212
Andy Fleminga9b14972006-10-19 19:52:26 -0500213 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600214
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000215 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600216
217 /* If we aren't the FEC we have multiple interrupts */
218 if (model && strcasecmp(model, "FEC")) {
219 r[1].name = gfar_tx_intr;
220
221 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500222 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600223
224 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500225 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500226
227 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600228 }
229
Kumar Gala2fb07d72006-01-23 16:58:04 -0600230 gfar_dev =
231 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400232 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600233
234 if (IS_ERR(gfar_dev)) {
235 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600236 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600237 }
238
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600239 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500240 if (mac_addr)
241 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600242
243 if (model && !strcasecmp(model, "TSEC"))
244 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600245 FSL_GIANFAR_DEV_HAS_GIGABIT |
246 FSL_GIANFAR_DEV_HAS_COALESCE |
247 FSL_GIANFAR_DEV_HAS_RMON |
248 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600249 if (model && !strcasecmp(model, "eTSEC"))
250 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600251 FSL_GIANFAR_DEV_HAS_GIGABIT |
252 FSL_GIANFAR_DEV_HAS_COALESCE |
253 FSL_GIANFAR_DEV_HAS_RMON |
254 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
255 FSL_GIANFAR_DEV_HAS_CSUM |
256 FSL_GIANFAR_DEV_HAS_VLAN |
257 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600258
Andy Fleming7132ab72007-07-11 11:43:07 -0500259 ctype = of_get_property(np, "phy-connection-type", NULL);
260
261 /* We only care about rgmii-id. The rest are autodetected */
262 if (ctype && !strcmp(ctype, "rgmii-id"))
263 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
264 else
265 gfar_data.interface = PHY_INTERFACE_MODE_MII;
266
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000267 ph = of_get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600268 phy = of_find_node_by_phandle(*ph);
269
270 if (phy == NULL) {
271 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600272 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600273 }
274
275 mdio = of_get_parent(phy);
276
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000277 id = of_get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600278 ret = of_address_to_resource(mdio, 0, &res);
279 if (ret) {
280 of_node_put(phy);
281 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600282 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600283 }
284
285 gfar_data.phy_id = *id;
286 gfar_data.bus_id = res.start;
287
288 of_node_put(phy);
289 of_node_put(mdio);
290
Kumar Gala2fb07d72006-01-23 16:58:04 -0600291 ret =
292 platform_device_add_data(gfar_dev, &gfar_data,
293 sizeof(struct
294 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600295 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600296 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600297 }
298
299 return 0;
300
Kumar Gala2fb07d72006-01-23 16:58:04 -0600301unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600302 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600303err:
Kumar Galaeed32002006-01-13 11:19:13 -0600304 return ret;
305}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600306
Kumar Galaeed32002006-01-13 11:19:13 -0600307arch_initcall(gfar_of_init);
308
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000309#ifdef CONFIG_I2C_BOARDINFO
310#include <linux/i2c.h>
311struct i2c_driver_device {
312 char *of_device;
313 char *i2c_driver;
314 char *i2c_type;
315};
316
317static struct i2c_driver_device i2c_devices[] __initdata = {
318 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
319 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
320 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
321 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
322};
323
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000324static int __init of_find_i2c_driver(struct device_node *node,
325 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000326{
327 int i;
328
329 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
330 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
331 continue;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000332 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
333 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
334 strlcpy(info->type, i2c_devices[i].i2c_type,
335 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
336 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000337 return 0;
338 }
339 return -ENODEV;
340}
341
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000342static void __init of_register_i2c_devices(struct device_node *adap_node,
343 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000344{
345 struct device_node *node = NULL;
346
347 while ((node = of_get_next_child(adap_node, node))) {
348 struct i2c_board_info info;
349 const u32 *addr;
350 int len;
351
352 addr = of_get_property(node, "reg", &len);
353 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
354 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
355 continue;
356 }
357
358 info.irq = irq_of_parse_and_map(node, 0);
359 if (info.irq == NO_IRQ)
360 info.irq = -1;
361
362 if (of_find_i2c_driver(node, &info) < 0)
363 continue;
364
365 info.platform_data = NULL;
366 info.addr = *addr;
367
368 i2c_register_board_info(bus_num, &info, 1);
369 }
370}
371
Kumar Galaeed32002006-01-13 11:19:13 -0600372static int __init fsl_i2c_of_init(void)
373{
374 struct device_node *np;
375 unsigned int i;
376 struct platform_device *i2c_dev;
377 int ret;
378
Kumar Gala2fb07d72006-01-23 16:58:04 -0600379 for (np = NULL, i = 0;
380 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
381 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600382 struct resource r[2];
383 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000384 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600385
386 memset(&r, 0, sizeof(r));
387 memset(&i2c_data, 0, sizeof(i2c_data));
388
389 ret = of_address_to_resource(np, 0, &r[0]);
390 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600391 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600392
Andy Fleminga9b14972006-10-19 19:52:26 -0500393 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600394
395 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
396 if (IS_ERR(i2c_dev)) {
397 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600398 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600399 }
400
401 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000402 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600403 if (flags)
404 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
405
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000406 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600407 if (flags)
408 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
409
Kumar Gala2fb07d72006-01-23 16:58:04 -0600410 ret =
411 platform_device_add_data(i2c_dev, &i2c_data,
412 sizeof(struct
413 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600414 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600415 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000416
417 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600418 }
419
420 return 0;
421
Kumar Gala2fb07d72006-01-23 16:58:04 -0600422unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600423 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600424err:
Kumar Galaeed32002006-01-13 11:19:13 -0600425 return ret;
426}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600427
Kumar Galaeed32002006-01-13 11:19:13 -0600428arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000429#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600430
431#ifdef CONFIG_PPC_83xx
432static int __init mpc83xx_wdt_init(void)
433{
434 struct resource r;
435 struct device_node *soc, *np;
436 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000437 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600438 int ret;
439
440 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
441
442 if (!np) {
443 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600444 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600445 }
446
447 soc = of_find_node_by_type(NULL, "soc");
448
449 if (!soc) {
450 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600451 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600452 }
453
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000454 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600455 if (!freq) {
456 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600457 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600458 }
459
460 memset(&r, 0, sizeof(r));
461
462 ret = of_address_to_resource(np, 0, &r);
463 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600464 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600465
466 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
467 if (IS_ERR(dev)) {
468 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600469 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600470 }
471
472 ret = platform_device_add_data(dev, freq, sizeof(int));
473 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600474 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600475
476 of_node_put(soc);
477 of_node_put(np);
478
479 return 0;
480
Kumar Gala2fb07d72006-01-23 16:58:04 -0600481unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600482 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600483err:
Kumar Galaeed32002006-01-13 11:19:13 -0600484 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600485nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600486 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600487nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600488 return ret;
489}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600490
Kumar Galaeed32002006-01-13 11:19:13 -0600491arch_initcall(mpc83xx_wdt_init);
492#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600493
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000494static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600495{
496 if (!phy_type)
497 return FSL_USB2_PHY_NONE;
498 if (!strcasecmp(phy_type, "ulpi"))
499 return FSL_USB2_PHY_ULPI;
500 if (!strcasecmp(phy_type, "utmi"))
501 return FSL_USB2_PHY_UTMI;
502 if (!strcasecmp(phy_type, "utmi_wide"))
503 return FSL_USB2_PHY_UTMI_WIDE;
504 if (!strcasecmp(phy_type, "serial"))
505 return FSL_USB2_PHY_SERIAL;
506
507 return FSL_USB2_PHY_NONE;
508}
509
510static int __init fsl_usb_of_init(void)
511{
512 struct device_node *np;
513 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800514 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
515 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600516 int ret;
517
518 for (np = NULL, i = 0;
519 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
520 i++) {
521 struct resource r[2];
522 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000523 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600524
525 memset(&r, 0, sizeof(r));
526 memset(&usb_data, 0, sizeof(usb_data));
527
528 ret = of_address_to_resource(np, 0, &r[0]);
529 if (ret)
530 goto err;
531
Andy Fleminga9b14972006-10-19 19:52:26 -0500532 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533
Kumar Gala01cced22006-04-11 10:07:16 -0500534 usb_dev_mph =
535 platform_device_register_simple("fsl-ehci", i, r, 2);
536 if (IS_ERR(usb_dev_mph)) {
537 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600538 goto err;
539 }
540
Kumar Gala01cced22006-04-11 10:07:16 -0500541 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
542 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600543
544 usb_data.operating_mode = FSL_USB2_MPH_HOST;
545
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000546 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600547 if (prop)
548 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
549
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000550 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600551 if (prop)
552 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
553
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000554 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600555 usb_data.phy_mode = determine_usb_phy(prop);
556
557 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500558 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600559 sizeof(struct
560 fsl_usb2_platform_data));
561 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500562 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600563 }
564
Kumar Gala01cced22006-04-11 10:07:16 -0500565 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600566 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
567 i++) {
568 struct resource r[2];
569 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000570 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600571
572 memset(&r, 0, sizeof(r));
573 memset(&usb_data, 0, sizeof(usb_data));
574
575 ret = of_address_to_resource(np, 0, &r[0]);
576 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500577 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600578
Andy Fleminga9b14972006-10-19 19:52:26 -0500579 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600580
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000581 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800582
583 if (!prop || !strcmp(prop, "host")) {
584 usb_data.operating_mode = FSL_USB2_DR_HOST;
585 usb_dev_dr_host = platform_device_register_simple(
586 "fsl-ehci", i, r, 2);
587 if (IS_ERR(usb_dev_dr_host)) {
588 ret = PTR_ERR(usb_dev_dr_host);
589 goto err;
590 }
591 } else if (prop && !strcmp(prop, "peripheral")) {
592 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
593 usb_dev_dr_client = platform_device_register_simple(
594 "fsl-usb2-udc", i, r, 2);
595 if (IS_ERR(usb_dev_dr_client)) {
596 ret = PTR_ERR(usb_dev_dr_client);
597 goto err;
598 }
599 } else if (prop && !strcmp(prop, "otg")) {
600 usb_data.operating_mode = FSL_USB2_DR_OTG;
601 usb_dev_dr_host = platform_device_register_simple(
602 "fsl-ehci", i, r, 2);
603 if (IS_ERR(usb_dev_dr_host)) {
604 ret = PTR_ERR(usb_dev_dr_host);
605 goto err;
606 }
607 usb_dev_dr_client = platform_device_register_simple(
608 "fsl-usb2-udc", i, r, 2);
609 if (IS_ERR(usb_dev_dr_client)) {
610 ret = PTR_ERR(usb_dev_dr_client);
611 goto err;
612 }
613 } else {
614 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600615 goto err;
616 }
617
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000618 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600619 usb_data.phy_mode = determine_usb_phy(prop);
620
Li Yang97c5a202007-02-07 13:49:24 +0800621 if (usb_dev_dr_host) {
622 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
623 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
624 dev.coherent_dma_mask;
625 if ((ret = platform_device_add_data(usb_dev_dr_host,
626 &usb_data, sizeof(struct
627 fsl_usb2_platform_data))))
628 goto unreg_dr;
629 }
630 if (usb_dev_dr_client) {
631 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
632 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
633 dev.coherent_dma_mask;
634 if ((ret = platform_device_add_data(usb_dev_dr_client,
635 &usb_data, sizeof(struct
636 fsl_usb2_platform_data))))
637 goto unreg_dr;
638 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600639 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600640 return 0;
641
Kumar Gala01cced22006-04-11 10:07:16 -0500642unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800643 if (usb_dev_dr_host)
644 platform_device_unregister(usb_dev_dr_host);
645 if (usb_dev_dr_client)
646 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500647unreg_mph:
648 if (usb_dev_mph)
649 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600650err:
651 return ret;
652}
653
Kumar Gala01cced22006-04-11 10:07:16 -0500654arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400655
656#ifdef CONFIG_CPM2
657
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300658extern void init_scc_ioports(struct fs_uart_platform_info*);
659
Vitaly Bordugfba43662006-09-21 17:26:34 +0400660static const char fcc_regs[] = "fcc_regs";
661static const char fcc_regs_c[] = "fcc_regs_c";
662static const char fcc_pram[] = "fcc_pram";
663static char bus_id[9][BUS_ID_SIZE];
664
665static int __init fs_enet_of_init(void)
666{
667 struct device_node *np;
668 unsigned int i;
669 struct platform_device *fs_enet_dev;
670 struct resource res;
671 int ret;
672
673 for (np = NULL, i = 0;
674 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
675 i++) {
676 struct resource r[4];
677 struct device_node *phy, *mdio;
678 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500679 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400680 const void *mac_addr;
681 const phandle *ph;
682 const char *model;
683
684 memset(r, 0, sizeof(r));
685 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
686
687 ret = of_address_to_resource(np, 0, &r[0]);
688 if (ret)
689 goto err;
690 r[0].name = fcc_regs;
691
692 ret = of_address_to_resource(np, 1, &r[1]);
693 if (ret)
694 goto err;
695 r[1].name = fcc_pram;
696
697 ret = of_address_to_resource(np, 2, &r[2]);
698 if (ret)
699 goto err;
700 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400701 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400702
Andy Fleminga9b14972006-10-19 19:52:26 -0500703 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400704
705 fs_enet_dev =
706 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
707
708 if (IS_ERR(fs_enet_dev)) {
709 ret = PTR_ERR(fs_enet_dev);
710 goto err;
711 }
712
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000713 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400714 if (model == NULL) {
715 ret = -ENODEV;
716 goto unreg;
717 }
718
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600719 mac_addr = of_get_mac_address(np);
720 if (mac_addr)
721 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400722
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000723 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400724 phy = of_find_node_by_phandle(*ph);
725
726 if (phy == NULL) {
727 ret = -ENODEV;
728 goto unreg;
729 }
730
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000731 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400732 fs_enet_data.phy_addr = *phy_addr;
733
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000734 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400735
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000736 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400737 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400738 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400739
740 mdio = of_get_parent(phy);
741 ret = of_address_to_resource(mdio, 0, &res);
742 if (ret) {
743 of_node_put(phy);
744 of_node_put(mdio);
745 goto unreg;
746 }
747
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000748 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
749 "rx-clock", NULL));
750 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
751 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400752
Vitaly Bordugfba43662006-09-21 17:26:34 +0400753 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400754 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500755 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400756
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400757 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400758 fs_enet_data.rx_ring = 32;
759 fs_enet_data.tx_ring = 32;
760 fs_enet_data.rx_copybreak = 240;
761 fs_enet_data.use_napi = 0;
762 fs_enet_data.napi_weight = 17;
763 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
764 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
765 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
766
767 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
768 (u32)res.start, fs_enet_data.phy_addr);
769 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400770 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400771
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000772 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400773 if (mdio_bb_prop) {
774 struct platform_device *fs_enet_mdio_bb_dev;
775 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400776
Vitaly Borduged943c12006-10-02 22:41:50 +0400777 fs_enet_mdio_bb_dev =
778 platform_device_register_simple("fsl-bb-mdio",
779 i, NULL, 0);
780 memset(&fs_enet_mdio_bb_data, 0,
781 sizeof(struct fs_mii_bb_platform_info));
782 fs_enet_mdio_bb_data.mdio_dat.bit =
783 mdio_bb_prop[0];
784 fs_enet_mdio_bb_data.mdio_dir.bit =
785 mdio_bb_prop[1];
786 fs_enet_mdio_bb_data.mdc_dat.bit =
787 mdio_bb_prop[2];
788 fs_enet_mdio_bb_data.mdio_port =
789 mdio_bb_prop[3];
790 fs_enet_mdio_bb_data.mdc_port =
791 mdio_bb_prop[4];
792 fs_enet_mdio_bb_data.delay =
793 mdio_bb_prop[5];
794
795 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
796 fs_enet_mdio_bb_data.irq[1] = -1;
797 fs_enet_mdio_bb_data.irq[2] = -1;
798 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
799 fs_enet_mdio_bb_data.irq[31] = -1;
800
801 fs_enet_mdio_bb_data.mdio_dat.offset =
802 (u32)&cpm2_immr->im_ioport.iop_pdatc;
803 fs_enet_mdio_bb_data.mdio_dir.offset =
804 (u32)&cpm2_immr->im_ioport.iop_pdirc;
805 fs_enet_mdio_bb_data.mdc_dat.offset =
806 (u32)&cpm2_immr->im_ioport.iop_pdatc;
807
808 ret = platform_device_add_data(
809 fs_enet_mdio_bb_dev,
810 &fs_enet_mdio_bb_data,
811 sizeof(struct fs_mii_bb_platform_info));
812 if (ret)
813 goto unreg;
814 }
Li Yang97c5a202007-02-07 13:49:24 +0800815
Vitaly Borduged943c12006-10-02 22:41:50 +0400816 of_node_put(phy);
817 of_node_put(mdio);
818
819 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
820 sizeof(struct
821 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500822 if (ret)
823 goto unreg;
824 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400825 }
826 return 0;
827
828unreg:
829 platform_device_unregister(fs_enet_dev);
830err:
831 return ret;
832}
833
834arch_initcall(fs_enet_of_init);
835
836static const char scc_regs[] = "regs";
837static const char scc_pram[] = "pram";
838
839static int __init cpm_uart_of_init(void)
840{
841 struct device_node *np;
842 unsigned int i;
843 struct platform_device *cpm_uart_dev;
844 int ret;
845
846 for (np = NULL, i = 0;
847 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
848 i++) {
849 struct resource r[3];
850 struct fs_uart_platform_info cpm_uart_data;
851 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400852 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400853
854 memset(r, 0, sizeof(r));
855 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
856
857 ret = of_address_to_resource(np, 0, &r[0]);
858 if (ret)
859 goto err;
860
861 r[0].name = scc_regs;
862
863 ret = of_address_to_resource(np, 1, &r[1]);
864 if (ret)
865 goto err;
866 r[1].name = scc_pram;
867
Andy Fleminga9b14972006-10-19 19:52:26 -0500868 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400869
870 cpm_uart_dev =
871 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
872
873 if (IS_ERR(cpm_uart_dev)) {
874 ret = PTR_ERR(cpm_uart_dev);
875 goto err;
876 }
877
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000878 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400879 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400880
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000881 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400882 strcpy(cpm_uart_data.fs_type, model);
883
Vitaly Bordugfba43662006-09-21 17:26:34 +0400884 cpm_uart_data.uart_clk = ppc_proc_freq;
885
886 cpm_uart_data.tx_num_fifo = 4;
887 cpm_uart_data.tx_buf_size = 32;
888 cpm_uart_data.rx_num_fifo = 4;
889 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000890 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
891 "rx-clock", NULL));
892 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
893 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400894
895 ret =
896 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
897 sizeof(struct
898 fs_uart_platform_info));
899 if (ret)
900 goto unreg;
901 }
902
903 return 0;
904
905unreg:
906 platform_device_unregister(cpm_uart_dev);
907err:
908 return ret;
909}
910
911arch_initcall(cpm_uart_of_init);
912#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300913
914#ifdef CONFIG_8xx
915
916extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000917extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300918
919static int __init fs_enet_mdio_of_init(void)
920{
921 struct device_node *np;
922 unsigned int i;
923 struct platform_device *mdio_dev;
924 struct resource res;
925 int ret;
926
927 for (np = NULL, i = 0;
928 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
929 i++) {
930 struct fs_mii_fec_platform_info mdio_data;
931
932 memset(&res, 0, sizeof(res));
933 memset(&mdio_data, 0, sizeof(mdio_data));
934
935 ret = of_address_to_resource(np, 0, &res);
936 if (ret)
937 goto err;
938
939 mdio_dev =
940 platform_device_register_simple("fsl-cpm-fec-mdio",
941 res.start, &res, 1);
942 if (IS_ERR(mdio_dev)) {
943 ret = PTR_ERR(mdio_dev);
944 goto err;
945 }
946
947 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
948
949 ret =
950 platform_device_add_data(mdio_dev, &mdio_data,
951 sizeof(struct fs_mii_fec_platform_info));
952 if (ret)
953 goto unreg;
954 }
955 return 0;
956
957unreg:
958 platform_device_unregister(mdio_dev);
959err:
960 return ret;
961}
962
963arch_initcall(fs_enet_mdio_of_init);
964
965static const char *enet_regs = "regs";
966static const char *enet_pram = "pram";
967static const char *enet_irq = "interrupt";
968static char bus_id[9][BUS_ID_SIZE];
969
970static int __init fs_enet_of_init(void)
971{
972 struct device_node *np;
973 unsigned int i;
974 struct platform_device *fs_enet_dev = NULL;
975 struct resource res;
976 int ret;
977
978 for (np = NULL, i = 0;
979 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
980 i++) {
981 struct resource r[4];
982 struct device_node *phy = NULL, *mdio = NULL;
983 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000984 const unsigned int *id;
985 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000986 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000987 const phandle *ph;
988 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300989
990 memset(r, 0, sizeof(r));
991 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
992
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000993 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300994 if (model == NULL) {
995 ret = -ENODEV;
996 goto unreg;
997 }
998
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000999 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001000 fs_enet_data.fs_no = *id;
1001
1002 if (platform_device_skip(model, *id))
1003 continue;
1004
1005 ret = of_address_to_resource(np, 0, &r[0]);
1006 if (ret)
1007 goto err;
1008 r[0].name = enet_regs;
1009
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001010 mac_addr = of_get_mac_address(np);
1011 if (mac_addr)
1012 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001013
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001014 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001015 if (ph != NULL)
1016 phy = of_find_node_by_phandle(*ph);
1017
1018 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001019 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001020 fs_enet_data.phy_addr = *phy_addr;
1021 fs_enet_data.has_phy = 1;
1022
1023 mdio = of_get_parent(phy);
1024 ret = of_address_to_resource(mdio, 0, &res);
1025 if (ret) {
1026 of_node_put(phy);
1027 of_node_put(mdio);
1028 goto unreg;
1029 }
1030 }
1031
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001032 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001033 strcpy(fs_enet_data.fs_type, model);
1034
1035 if (strstr(model, "FEC")) {
1036 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1037 r[1].flags = IORESOURCE_IRQ;
1038 r[1].name = enet_irq;
1039
1040 fs_enet_dev =
1041 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1042
1043 if (IS_ERR(fs_enet_dev)) {
1044 ret = PTR_ERR(fs_enet_dev);
1045 goto err;
1046 }
1047
1048 fs_enet_data.rx_ring = 128;
1049 fs_enet_data.tx_ring = 16;
1050 fs_enet_data.rx_copybreak = 240;
1051 fs_enet_data.use_napi = 1;
1052 fs_enet_data.napi_weight = 17;
1053
1054 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1055 (u32)res.start, fs_enet_data.phy_addr);
1056 fs_enet_data.bus_id = (char*)&bus_id[i];
1057 fs_enet_data.init_ioports = init_fec_ioports;
1058 }
1059 if (strstr(model, "SCC")) {
1060 ret = of_address_to_resource(np, 1, &r[1]);
1061 if (ret)
1062 goto err;
1063 r[1].name = enet_pram;
1064
1065 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1066 r[2].flags = IORESOURCE_IRQ;
1067 r[2].name = enet_irq;
1068
1069 fs_enet_dev =
1070 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1071
1072 if (IS_ERR(fs_enet_dev)) {
1073 ret = PTR_ERR(fs_enet_dev);
1074 goto err;
1075 }
1076
1077 fs_enet_data.rx_ring = 64;
1078 fs_enet_data.tx_ring = 8;
1079 fs_enet_data.rx_copybreak = 240;
1080 fs_enet_data.use_napi = 1;
1081 fs_enet_data.napi_weight = 17;
1082
1083 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1084 fs_enet_data.bus_id = (char*)&bus_id[i];
1085 fs_enet_data.init_ioports = init_scc_ioports;
1086 }
1087
1088 of_node_put(phy);
1089 of_node_put(mdio);
1090
1091 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1092 sizeof(struct
1093 fs_platform_info));
1094 if (ret)
1095 goto unreg;
1096 }
1097 return 0;
1098
1099unreg:
1100 platform_device_unregister(fs_enet_dev);
1101err:
1102 return ret;
1103}
1104
1105arch_initcall(fs_enet_of_init);
1106
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001107static int __init fsl_pcmcia_of_init(void)
1108{
1109 struct device_node *np = NULL;
1110 /*
1111 * Register all the devices which type is "pcmcia"
1112 */
1113 while ((np = of_find_compatible_node(np,
1114 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1115 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1116 return 0;
1117}
1118
1119arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001120
1121static const char *smc_regs = "regs";
1122static const char *smc_pram = "pram";
1123
1124static int __init cpm_smc_uart_of_init(void)
1125{
1126 struct device_node *np;
1127 unsigned int i;
1128 struct platform_device *cpm_uart_dev;
1129 int ret;
1130
1131 for (np = NULL, i = 0;
1132 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1133 i++) {
1134 struct resource r[3];
1135 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001136 const int *id;
1137 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001138
1139 memset(r, 0, sizeof(r));
1140 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1141
1142 ret = of_address_to_resource(np, 0, &r[0]);
1143 if (ret)
1144 goto err;
1145
1146 r[0].name = smc_regs;
1147
1148 ret = of_address_to_resource(np, 1, &r[1]);
1149 if (ret)
1150 goto err;
1151 r[1].name = smc_pram;
1152
1153 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1154 r[2].flags = IORESOURCE_IRQ;
1155
1156 cpm_uart_dev =
1157 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1158
1159 if (IS_ERR(cpm_uart_dev)) {
1160 ret = PTR_ERR(cpm_uart_dev);
1161 goto err;
1162 }
1163
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001164 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001165 strcpy(cpm_uart_data.fs_type, model);
1166
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001167 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001168 cpm_uart_data.fs_no = *id;
1169 cpm_uart_data.uart_clk = ppc_proc_freq;
1170
1171 cpm_uart_data.tx_num_fifo = 4;
1172 cpm_uart_data.tx_buf_size = 32;
1173 cpm_uart_data.rx_num_fifo = 4;
1174 cpm_uart_data.rx_buf_size = 32;
1175
1176 ret =
1177 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1178 sizeof(struct
1179 fs_uart_platform_info));
1180 if (ret)
1181 goto unreg;
1182 }
1183
1184 return 0;
1185
1186unreg:
1187 platform_device_unregister(cpm_uart_dev);
1188err:
1189 return ret;
1190}
1191
1192arch_initcall(cpm_smc_uart_of_init);
1193
1194#endif /* CONFIG_8xx */