blob: 1cf29c9d4408dbb4cfa863b16abb441a15b6cc07 [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
324static int __init of_find_i2c_driver(struct device_node *node, struct i2c_board_info *info)
325{
326 int i;
327
328 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
329 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
330 continue;
331 strncpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN);
332 strncpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE);
333 return 0;
334 }
335 return -ENODEV;
336}
337
338static void __init of_register_i2c_devices(struct device_node *adap_node, int bus_num)
339{
340 struct device_node *node = NULL;
341
342 while ((node = of_get_next_child(adap_node, node))) {
343 struct i2c_board_info info;
344 const u32 *addr;
345 int len;
346
347 addr = of_get_property(node, "reg", &len);
348 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
349 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
350 continue;
351 }
352
353 info.irq = irq_of_parse_and_map(node, 0);
354 if (info.irq == NO_IRQ)
355 info.irq = -1;
356
357 if (of_find_i2c_driver(node, &info) < 0)
358 continue;
359
360 info.platform_data = NULL;
361 info.addr = *addr;
362
363 i2c_register_board_info(bus_num, &info, 1);
364 }
365}
366
Kumar Galaeed32002006-01-13 11:19:13 -0600367static int __init fsl_i2c_of_init(void)
368{
369 struct device_node *np;
370 unsigned int i;
371 struct platform_device *i2c_dev;
372 int ret;
373
Kumar Gala2fb07d72006-01-23 16:58:04 -0600374 for (np = NULL, i = 0;
375 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
376 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600377 struct resource r[2];
378 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000379 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600380
381 memset(&r, 0, sizeof(r));
382 memset(&i2c_data, 0, sizeof(i2c_data));
383
384 ret = of_address_to_resource(np, 0, &r[0]);
385 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600386 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600387
Andy Fleminga9b14972006-10-19 19:52:26 -0500388 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600389
390 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
391 if (IS_ERR(i2c_dev)) {
392 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600393 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600394 }
395
396 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000397 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600398 if (flags)
399 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
400
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000401 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600402 if (flags)
403 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
404
Kumar Gala2fb07d72006-01-23 16:58:04 -0600405 ret =
406 platform_device_add_data(i2c_dev, &i2c_data,
407 sizeof(struct
408 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600409 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600410 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000411
412 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600413 }
414
415 return 0;
416
Kumar Gala2fb07d72006-01-23 16:58:04 -0600417unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600418 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600419err:
Kumar Galaeed32002006-01-13 11:19:13 -0600420 return ret;
421}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600422
Kumar Galaeed32002006-01-13 11:19:13 -0600423arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000424#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600425
426#ifdef CONFIG_PPC_83xx
427static int __init mpc83xx_wdt_init(void)
428{
429 struct resource r;
430 struct device_node *soc, *np;
431 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000432 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600433 int ret;
434
435 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
436
437 if (!np) {
438 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600439 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600440 }
441
442 soc = of_find_node_by_type(NULL, "soc");
443
444 if (!soc) {
445 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600446 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600447 }
448
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000449 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600450 if (!freq) {
451 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600452 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600453 }
454
455 memset(&r, 0, sizeof(r));
456
457 ret = of_address_to_resource(np, 0, &r);
458 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600459 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600460
461 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
462 if (IS_ERR(dev)) {
463 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600464 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600465 }
466
467 ret = platform_device_add_data(dev, freq, sizeof(int));
468 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600469 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600470
471 of_node_put(soc);
472 of_node_put(np);
473
474 return 0;
475
Kumar Gala2fb07d72006-01-23 16:58:04 -0600476unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600477 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600478err:
Kumar Galaeed32002006-01-13 11:19:13 -0600479 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600480nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600481 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600482nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600483 return ret;
484}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600485
Kumar Galaeed32002006-01-13 11:19:13 -0600486arch_initcall(mpc83xx_wdt_init);
487#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600488
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000489static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600490{
491 if (!phy_type)
492 return FSL_USB2_PHY_NONE;
493 if (!strcasecmp(phy_type, "ulpi"))
494 return FSL_USB2_PHY_ULPI;
495 if (!strcasecmp(phy_type, "utmi"))
496 return FSL_USB2_PHY_UTMI;
497 if (!strcasecmp(phy_type, "utmi_wide"))
498 return FSL_USB2_PHY_UTMI_WIDE;
499 if (!strcasecmp(phy_type, "serial"))
500 return FSL_USB2_PHY_SERIAL;
501
502 return FSL_USB2_PHY_NONE;
503}
504
505static int __init fsl_usb_of_init(void)
506{
507 struct device_node *np;
508 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800509 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
510 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600511 int ret;
512
513 for (np = NULL, i = 0;
514 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
515 i++) {
516 struct resource r[2];
517 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000518 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600519
520 memset(&r, 0, sizeof(r));
521 memset(&usb_data, 0, sizeof(usb_data));
522
523 ret = of_address_to_resource(np, 0, &r[0]);
524 if (ret)
525 goto err;
526
Andy Fleminga9b14972006-10-19 19:52:26 -0500527 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600528
Kumar Gala01cced22006-04-11 10:07:16 -0500529 usb_dev_mph =
530 platform_device_register_simple("fsl-ehci", i, r, 2);
531 if (IS_ERR(usb_dev_mph)) {
532 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600533 goto err;
534 }
535
Kumar Gala01cced22006-04-11 10:07:16 -0500536 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
537 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600538
539 usb_data.operating_mode = FSL_USB2_MPH_HOST;
540
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000541 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600542 if (prop)
543 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
544
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000545 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600546 if (prop)
547 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
548
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000549 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600550 usb_data.phy_mode = determine_usb_phy(prop);
551
552 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500553 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600554 sizeof(struct
555 fsl_usb2_platform_data));
556 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500557 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600558 }
559
Kumar Gala01cced22006-04-11 10:07:16 -0500560 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600561 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
562 i++) {
563 struct resource r[2];
564 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000565 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600566
567 memset(&r, 0, sizeof(r));
568 memset(&usb_data, 0, sizeof(usb_data));
569
570 ret = of_address_to_resource(np, 0, &r[0]);
571 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500572 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600573
Andy Fleminga9b14972006-10-19 19:52:26 -0500574 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600575
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000576 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800577
578 if (!prop || !strcmp(prop, "host")) {
579 usb_data.operating_mode = FSL_USB2_DR_HOST;
580 usb_dev_dr_host = platform_device_register_simple(
581 "fsl-ehci", i, r, 2);
582 if (IS_ERR(usb_dev_dr_host)) {
583 ret = PTR_ERR(usb_dev_dr_host);
584 goto err;
585 }
586 } else if (prop && !strcmp(prop, "peripheral")) {
587 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
588 usb_dev_dr_client = platform_device_register_simple(
589 "fsl-usb2-udc", i, r, 2);
590 if (IS_ERR(usb_dev_dr_client)) {
591 ret = PTR_ERR(usb_dev_dr_client);
592 goto err;
593 }
594 } else if (prop && !strcmp(prop, "otg")) {
595 usb_data.operating_mode = FSL_USB2_DR_OTG;
596 usb_dev_dr_host = platform_device_register_simple(
597 "fsl-ehci", i, r, 2);
598 if (IS_ERR(usb_dev_dr_host)) {
599 ret = PTR_ERR(usb_dev_dr_host);
600 goto err;
601 }
602 usb_dev_dr_client = platform_device_register_simple(
603 "fsl-usb2-udc", i, r, 2);
604 if (IS_ERR(usb_dev_dr_client)) {
605 ret = PTR_ERR(usb_dev_dr_client);
606 goto err;
607 }
608 } else {
609 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600610 goto err;
611 }
612
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000613 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600614 usb_data.phy_mode = determine_usb_phy(prop);
615
Li Yang97c5a202007-02-07 13:49:24 +0800616 if (usb_dev_dr_host) {
617 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
618 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
619 dev.coherent_dma_mask;
620 if ((ret = platform_device_add_data(usb_dev_dr_host,
621 &usb_data, sizeof(struct
622 fsl_usb2_platform_data))))
623 goto unreg_dr;
624 }
625 if (usb_dev_dr_client) {
626 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
627 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
628 dev.coherent_dma_mask;
629 if ((ret = platform_device_add_data(usb_dev_dr_client,
630 &usb_data, sizeof(struct
631 fsl_usb2_platform_data))))
632 goto unreg_dr;
633 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600634 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600635 return 0;
636
Kumar Gala01cced22006-04-11 10:07:16 -0500637unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800638 if (usb_dev_dr_host)
639 platform_device_unregister(usb_dev_dr_host);
640 if (usb_dev_dr_client)
641 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500642unreg_mph:
643 if (usb_dev_mph)
644 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600645err:
646 return ret;
647}
648
Kumar Gala01cced22006-04-11 10:07:16 -0500649arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400650
651#ifdef CONFIG_CPM2
652
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300653extern void init_scc_ioports(struct fs_uart_platform_info*);
654
Vitaly Bordugfba43662006-09-21 17:26:34 +0400655static const char fcc_regs[] = "fcc_regs";
656static const char fcc_regs_c[] = "fcc_regs_c";
657static const char fcc_pram[] = "fcc_pram";
658static char bus_id[9][BUS_ID_SIZE];
659
660static int __init fs_enet_of_init(void)
661{
662 struct device_node *np;
663 unsigned int i;
664 struct platform_device *fs_enet_dev;
665 struct resource res;
666 int ret;
667
668 for (np = NULL, i = 0;
669 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
670 i++) {
671 struct resource r[4];
672 struct device_node *phy, *mdio;
673 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500674 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400675 const void *mac_addr;
676 const phandle *ph;
677 const char *model;
678
679 memset(r, 0, sizeof(r));
680 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
681
682 ret = of_address_to_resource(np, 0, &r[0]);
683 if (ret)
684 goto err;
685 r[0].name = fcc_regs;
686
687 ret = of_address_to_resource(np, 1, &r[1]);
688 if (ret)
689 goto err;
690 r[1].name = fcc_pram;
691
692 ret = of_address_to_resource(np, 2, &r[2]);
693 if (ret)
694 goto err;
695 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400696 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400697
Andy Fleminga9b14972006-10-19 19:52:26 -0500698 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400699
700 fs_enet_dev =
701 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
702
703 if (IS_ERR(fs_enet_dev)) {
704 ret = PTR_ERR(fs_enet_dev);
705 goto err;
706 }
707
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000708 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400709 if (model == NULL) {
710 ret = -ENODEV;
711 goto unreg;
712 }
713
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600714 mac_addr = of_get_mac_address(np);
715 if (mac_addr)
716 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400717
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000718 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400719 phy = of_find_node_by_phandle(*ph);
720
721 if (phy == NULL) {
722 ret = -ENODEV;
723 goto unreg;
724 }
725
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000726 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400727 fs_enet_data.phy_addr = *phy_addr;
728
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000729 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400730
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000731 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400732 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400733 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400734
735 mdio = of_get_parent(phy);
736 ret = of_address_to_resource(mdio, 0, &res);
737 if (ret) {
738 of_node_put(phy);
739 of_node_put(mdio);
740 goto unreg;
741 }
742
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000743 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
744 "rx-clock", NULL));
745 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
746 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400747
Vitaly Bordugfba43662006-09-21 17:26:34 +0400748 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400749 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500750 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400751
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400752 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400753 fs_enet_data.rx_ring = 32;
754 fs_enet_data.tx_ring = 32;
755 fs_enet_data.rx_copybreak = 240;
756 fs_enet_data.use_napi = 0;
757 fs_enet_data.napi_weight = 17;
758 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
759 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
760 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
761
762 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
763 (u32)res.start, fs_enet_data.phy_addr);
764 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400765 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400766
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000767 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400768 if (mdio_bb_prop) {
769 struct platform_device *fs_enet_mdio_bb_dev;
770 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400771
Vitaly Borduged943c12006-10-02 22:41:50 +0400772 fs_enet_mdio_bb_dev =
773 platform_device_register_simple("fsl-bb-mdio",
774 i, NULL, 0);
775 memset(&fs_enet_mdio_bb_data, 0,
776 sizeof(struct fs_mii_bb_platform_info));
777 fs_enet_mdio_bb_data.mdio_dat.bit =
778 mdio_bb_prop[0];
779 fs_enet_mdio_bb_data.mdio_dir.bit =
780 mdio_bb_prop[1];
781 fs_enet_mdio_bb_data.mdc_dat.bit =
782 mdio_bb_prop[2];
783 fs_enet_mdio_bb_data.mdio_port =
784 mdio_bb_prop[3];
785 fs_enet_mdio_bb_data.mdc_port =
786 mdio_bb_prop[4];
787 fs_enet_mdio_bb_data.delay =
788 mdio_bb_prop[5];
789
790 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
791 fs_enet_mdio_bb_data.irq[1] = -1;
792 fs_enet_mdio_bb_data.irq[2] = -1;
793 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
794 fs_enet_mdio_bb_data.irq[31] = -1;
795
796 fs_enet_mdio_bb_data.mdio_dat.offset =
797 (u32)&cpm2_immr->im_ioport.iop_pdatc;
798 fs_enet_mdio_bb_data.mdio_dir.offset =
799 (u32)&cpm2_immr->im_ioport.iop_pdirc;
800 fs_enet_mdio_bb_data.mdc_dat.offset =
801 (u32)&cpm2_immr->im_ioport.iop_pdatc;
802
803 ret = platform_device_add_data(
804 fs_enet_mdio_bb_dev,
805 &fs_enet_mdio_bb_data,
806 sizeof(struct fs_mii_bb_platform_info));
807 if (ret)
808 goto unreg;
809 }
Li Yang97c5a202007-02-07 13:49:24 +0800810
Vitaly Borduged943c12006-10-02 22:41:50 +0400811 of_node_put(phy);
812 of_node_put(mdio);
813
814 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
815 sizeof(struct
816 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500817 if (ret)
818 goto unreg;
819 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400820 }
821 return 0;
822
823unreg:
824 platform_device_unregister(fs_enet_dev);
825err:
826 return ret;
827}
828
829arch_initcall(fs_enet_of_init);
830
831static const char scc_regs[] = "regs";
832static const char scc_pram[] = "pram";
833
834static int __init cpm_uart_of_init(void)
835{
836 struct device_node *np;
837 unsigned int i;
838 struct platform_device *cpm_uart_dev;
839 int ret;
840
841 for (np = NULL, i = 0;
842 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
843 i++) {
844 struct resource r[3];
845 struct fs_uart_platform_info cpm_uart_data;
846 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400847 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400848
849 memset(r, 0, sizeof(r));
850 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
851
852 ret = of_address_to_resource(np, 0, &r[0]);
853 if (ret)
854 goto err;
855
856 r[0].name = scc_regs;
857
858 ret = of_address_to_resource(np, 1, &r[1]);
859 if (ret)
860 goto err;
861 r[1].name = scc_pram;
862
Andy Fleminga9b14972006-10-19 19:52:26 -0500863 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400864
865 cpm_uart_dev =
866 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
867
868 if (IS_ERR(cpm_uart_dev)) {
869 ret = PTR_ERR(cpm_uart_dev);
870 goto err;
871 }
872
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000873 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400874 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400875
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000876 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400877 strcpy(cpm_uart_data.fs_type, model);
878
Vitaly Bordugfba43662006-09-21 17:26:34 +0400879 cpm_uart_data.uart_clk = ppc_proc_freq;
880
881 cpm_uart_data.tx_num_fifo = 4;
882 cpm_uart_data.tx_buf_size = 32;
883 cpm_uart_data.rx_num_fifo = 4;
884 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000885 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
886 "rx-clock", NULL));
887 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
888 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400889
890 ret =
891 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
892 sizeof(struct
893 fs_uart_platform_info));
894 if (ret)
895 goto unreg;
896 }
897
898 return 0;
899
900unreg:
901 platform_device_unregister(cpm_uart_dev);
902err:
903 return ret;
904}
905
906arch_initcall(cpm_uart_of_init);
907#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300908
909#ifdef CONFIG_8xx
910
911extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000912extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300913
914static int __init fs_enet_mdio_of_init(void)
915{
916 struct device_node *np;
917 unsigned int i;
918 struct platform_device *mdio_dev;
919 struct resource res;
920 int ret;
921
922 for (np = NULL, i = 0;
923 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
924 i++) {
925 struct fs_mii_fec_platform_info mdio_data;
926
927 memset(&res, 0, sizeof(res));
928 memset(&mdio_data, 0, sizeof(mdio_data));
929
930 ret = of_address_to_resource(np, 0, &res);
931 if (ret)
932 goto err;
933
934 mdio_dev =
935 platform_device_register_simple("fsl-cpm-fec-mdio",
936 res.start, &res, 1);
937 if (IS_ERR(mdio_dev)) {
938 ret = PTR_ERR(mdio_dev);
939 goto err;
940 }
941
942 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
943
944 ret =
945 platform_device_add_data(mdio_dev, &mdio_data,
946 sizeof(struct fs_mii_fec_platform_info));
947 if (ret)
948 goto unreg;
949 }
950 return 0;
951
952unreg:
953 platform_device_unregister(mdio_dev);
954err:
955 return ret;
956}
957
958arch_initcall(fs_enet_mdio_of_init);
959
960static const char *enet_regs = "regs";
961static const char *enet_pram = "pram";
962static const char *enet_irq = "interrupt";
963static char bus_id[9][BUS_ID_SIZE];
964
965static int __init fs_enet_of_init(void)
966{
967 struct device_node *np;
968 unsigned int i;
969 struct platform_device *fs_enet_dev = NULL;
970 struct resource res;
971 int ret;
972
973 for (np = NULL, i = 0;
974 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
975 i++) {
976 struct resource r[4];
977 struct device_node *phy = NULL, *mdio = NULL;
978 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000979 const unsigned int *id;
980 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000981 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000982 const phandle *ph;
983 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300984
985 memset(r, 0, sizeof(r));
986 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
987
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000988 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300989 if (model == NULL) {
990 ret = -ENODEV;
991 goto unreg;
992 }
993
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000994 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300995 fs_enet_data.fs_no = *id;
996
997 if (platform_device_skip(model, *id))
998 continue;
999
1000 ret = of_address_to_resource(np, 0, &r[0]);
1001 if (ret)
1002 goto err;
1003 r[0].name = enet_regs;
1004
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001005 mac_addr = of_get_mac_address(np);
1006 if (mac_addr)
1007 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001008
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001009 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001010 if (ph != NULL)
1011 phy = of_find_node_by_phandle(*ph);
1012
1013 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001014 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001015 fs_enet_data.phy_addr = *phy_addr;
1016 fs_enet_data.has_phy = 1;
1017
1018 mdio = of_get_parent(phy);
1019 ret = of_address_to_resource(mdio, 0, &res);
1020 if (ret) {
1021 of_node_put(phy);
1022 of_node_put(mdio);
1023 goto unreg;
1024 }
1025 }
1026
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001027 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001028 strcpy(fs_enet_data.fs_type, model);
1029
1030 if (strstr(model, "FEC")) {
1031 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1032 r[1].flags = IORESOURCE_IRQ;
1033 r[1].name = enet_irq;
1034
1035 fs_enet_dev =
1036 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1037
1038 if (IS_ERR(fs_enet_dev)) {
1039 ret = PTR_ERR(fs_enet_dev);
1040 goto err;
1041 }
1042
1043 fs_enet_data.rx_ring = 128;
1044 fs_enet_data.tx_ring = 16;
1045 fs_enet_data.rx_copybreak = 240;
1046 fs_enet_data.use_napi = 1;
1047 fs_enet_data.napi_weight = 17;
1048
1049 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1050 (u32)res.start, fs_enet_data.phy_addr);
1051 fs_enet_data.bus_id = (char*)&bus_id[i];
1052 fs_enet_data.init_ioports = init_fec_ioports;
1053 }
1054 if (strstr(model, "SCC")) {
1055 ret = of_address_to_resource(np, 1, &r[1]);
1056 if (ret)
1057 goto err;
1058 r[1].name = enet_pram;
1059
1060 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1061 r[2].flags = IORESOURCE_IRQ;
1062 r[2].name = enet_irq;
1063
1064 fs_enet_dev =
1065 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1066
1067 if (IS_ERR(fs_enet_dev)) {
1068 ret = PTR_ERR(fs_enet_dev);
1069 goto err;
1070 }
1071
1072 fs_enet_data.rx_ring = 64;
1073 fs_enet_data.tx_ring = 8;
1074 fs_enet_data.rx_copybreak = 240;
1075 fs_enet_data.use_napi = 1;
1076 fs_enet_data.napi_weight = 17;
1077
1078 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1079 fs_enet_data.bus_id = (char*)&bus_id[i];
1080 fs_enet_data.init_ioports = init_scc_ioports;
1081 }
1082
1083 of_node_put(phy);
1084 of_node_put(mdio);
1085
1086 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1087 sizeof(struct
1088 fs_platform_info));
1089 if (ret)
1090 goto unreg;
1091 }
1092 return 0;
1093
1094unreg:
1095 platform_device_unregister(fs_enet_dev);
1096err:
1097 return ret;
1098}
1099
1100arch_initcall(fs_enet_of_init);
1101
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001102static int __init fsl_pcmcia_of_init(void)
1103{
1104 struct device_node *np = NULL;
1105 /*
1106 * Register all the devices which type is "pcmcia"
1107 */
1108 while ((np = of_find_compatible_node(np,
1109 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1110 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1111 return 0;
1112}
1113
1114arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001115
1116static const char *smc_regs = "regs";
1117static const char *smc_pram = "pram";
1118
1119static int __init cpm_smc_uart_of_init(void)
1120{
1121 struct device_node *np;
1122 unsigned int i;
1123 struct platform_device *cpm_uart_dev;
1124 int ret;
1125
1126 for (np = NULL, i = 0;
1127 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1128 i++) {
1129 struct resource r[3];
1130 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001131 const int *id;
1132 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001133
1134 memset(r, 0, sizeof(r));
1135 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1136
1137 ret = of_address_to_resource(np, 0, &r[0]);
1138 if (ret)
1139 goto err;
1140
1141 r[0].name = smc_regs;
1142
1143 ret = of_address_to_resource(np, 1, &r[1]);
1144 if (ret)
1145 goto err;
1146 r[1].name = smc_pram;
1147
1148 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1149 r[2].flags = IORESOURCE_IRQ;
1150
1151 cpm_uart_dev =
1152 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1153
1154 if (IS_ERR(cpm_uart_dev)) {
1155 ret = PTR_ERR(cpm_uart_dev);
1156 goto err;
1157 }
1158
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001159 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001160 strcpy(cpm_uart_data.fs_type, model);
1161
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001162 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001163 cpm_uart_data.fs_no = *id;
1164 cpm_uart_data.uart_clk = ppc_proc_freq;
1165
1166 cpm_uart_data.tx_num_fifo = 4;
1167 cpm_uart_data.tx_buf_size = 32;
1168 cpm_uart_data.rx_num_fifo = 4;
1169 cpm_uart_data.rx_buf_size = 32;
1170
1171 ret =
1172 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1173 sizeof(struct
1174 fs_uart_platform_info));
1175 if (ret)
1176 goto unreg;
1177 }
1178
1179 return 0;
1180
1181unreg:
1182 platform_device_unregister(cpm_uart_dev);
1183err:
1184 return ret;
1185}
1186
1187arch_initcall(cpm_smc_uart_of_init);
1188
1189#endif /* CONFIG_8xx */