blob: 727453d3e8b919cac9d5d435a5980842abc46cbd [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>
Andy Fleminga9b14972006-10-19 19:52:26 -050025#include <linux/phy.h>
Kumar Galaeed32002006-01-13 11:19:13 -060026#include <linux/fsl_devices.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040027#include <linux/fs_enet_pd.h>
28#include <linux/fs_uart_pd.h>
Kumar Galaeed32002006-01-13 11:19:13 -060029
30#include <asm/system.h>
31#include <asm/atomic.h>
32#include <asm/io.h>
33#include <asm/irq.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040034#include <asm/time.h>
Kumar Galaeed32002006-01-13 11:19:13 -060035#include <asm/prom.h>
36#include <sysdev/fsl_soc.h>
37#include <mm/mmu_decl.h>
Vitaly Bordugfba43662006-09-21 17:26:34 +040038#include <asm/cpm2.h>
Kumar Galaeed32002006-01-13 11:19:13 -060039
Vitaly Bordugd3465c92006-09-21 22:38:05 +040040extern void init_fcc_ioports(struct fs_platform_info*);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030041extern void init_fec_ioports(struct fs_platform_info*);
42extern void init_smc_ioports(struct fs_uart_platform_info*);
Kumar Galaeed32002006-01-13 11:19:13 -060043static phys_addr_t immrbase = -1;
44
45phys_addr_t get_immrbase(void)
46{
47 struct device_node *soc;
48
49 if (immrbase != -1)
50 return immrbase;
51
52 soc = of_find_node_by_type(NULL, "soc");
Kumar Gala2fb07d72006-01-23 16:58:04 -060053 if (soc) {
Kumar Galaeed32002006-01-13 11:19:13 -060054 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100055 const void *prop = of_get_property(soc, "reg", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040056
57 if (prop)
58 immrbase = of_translate_address(soc, prop);
Kumar Galaeed32002006-01-13 11:19:13 -060059 of_node_put(soc);
60 };
61
62 return immrbase;
63}
Kumar Gala2fb07d72006-01-23 16:58:04 -060064
Kumar Galaeed32002006-01-13 11:19:13 -060065EXPORT_SYMBOL(get_immrbase);
66
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +030067#if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
Vitaly Bordugfba43662006-09-21 17:26:34 +040068
69static u32 brgfreq = -1;
70
71u32 get_brgfreq(void)
72{
73 struct device_node *node;
74
75 if (brgfreq != -1)
76 return brgfreq;
77
78 node = of_find_node_by_type(NULL, "cpm");
79 if (node) {
80 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100081 const unsigned int *prop = of_get_property(node,
82 "brg-frequency", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +040083
84 if (prop)
85 brgfreq = *prop;
86 of_node_put(node);
87 };
88
89 return brgfreq;
90}
91
92EXPORT_SYMBOL(get_brgfreq);
93
94static u32 fs_baudrate = -1;
95
96u32 get_baudrate(void)
97{
98 struct device_node *node;
99
100 if (fs_baudrate != -1)
101 return fs_baudrate;
102
103 node = of_find_node_by_type(NULL, "serial");
104 if (node) {
105 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000106 const unsigned int *prop = of_get_property(node,
107 "current-speed", &size);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400108
109 if (prop)
110 fs_baudrate = *prop;
111 of_node_put(node);
112 };
113
114 return fs_baudrate;
115}
116
117EXPORT_SYMBOL(get_baudrate);
118#endif /* CONFIG_CPM2 */
119
Kumar Gala2fb07d72006-01-23 16:58:04 -0600120static int __init gfar_mdio_of_init(void)
Kumar Galaeed32002006-01-13 11:19:13 -0600121{
122 struct device_node *np;
123 unsigned int i;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600124 struct platform_device *mdio_dev;
Kumar Galaeed32002006-01-13 11:19:13 -0600125 struct resource res;
126 int ret;
127
Kumar Gala2fb07d72006-01-23 16:58:04 -0600128 for (np = NULL, i = 0;
129 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
130 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600131 int k;
132 struct device_node *child = NULL;
133 struct gianfar_mdio_data mdio_data;
134
135 memset(&res, 0, sizeof(res));
136 memset(&mdio_data, 0, sizeof(mdio_data));
137
138 ret = of_address_to_resource(np, 0, &res);
139 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600140 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600141
Kumar Gala2fb07d72006-01-23 16:58:04 -0600142 mdio_dev =
143 platform_device_register_simple("fsl-gianfar_mdio",
144 res.start, &res, 1);
Kumar Galaeed32002006-01-13 11:19:13 -0600145 if (IS_ERR(mdio_dev)) {
146 ret = PTR_ERR(mdio_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600147 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600148 }
149
150 for (k = 0; k < 32; k++)
Andy Fleminga9b14972006-10-19 19:52:26 -0500151 mdio_data.irq[k] = PHY_POLL;
Kumar Galaeed32002006-01-13 11:19:13 -0600152
153 while ((child = of_get_next_child(np, child)) != NULL) {
Vitaly Bordugfba43662006-09-21 17:26:34 +0400154 int irq = irq_of_parse_and_map(child, 0);
155 if (irq != NO_IRQ) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000156 const u32 *id = of_get_property(child,
157 "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400158 mdio_data.irq[*id] = irq;
159 }
Kumar Galaeed32002006-01-13 11:19:13 -0600160 }
161
Kumar Gala2fb07d72006-01-23 16:58:04 -0600162 ret =
163 platform_device_add_data(mdio_dev, &mdio_data,
164 sizeof(struct gianfar_mdio_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600165 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600166 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600167 }
168
Kumar Gala2fb07d72006-01-23 16:58:04 -0600169 return 0;
170
171unreg:
172 platform_device_unregister(mdio_dev);
173err:
174 return ret;
175}
176
177arch_initcall(gfar_mdio_of_init);
178
179static const char *gfar_tx_intr = "tx";
180static const char *gfar_rx_intr = "rx";
181static const char *gfar_err_intr = "error";
182
Andy Fleminga9b14972006-10-19 19:52:26 -0500183
Kumar Gala2fb07d72006-01-23 16:58:04 -0600184static int __init gfar_of_init(void)
185{
186 struct device_node *np;
187 unsigned int i;
188 struct platform_device *gfar_dev;
189 struct resource res;
190 int ret;
191
192 for (np = NULL, i = 0;
193 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
194 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600195 struct resource r[4];
196 struct device_node *phy, *mdio;
197 struct gianfar_platform_data gfar_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000198 const unsigned int *id;
199 const char *model;
Andy Fleming7132ab72007-07-11 11:43:07 -0500200 const char *ctype;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000201 const void *mac_addr;
202 const phandle *ph;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400203 int n_res = 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600204
205 memset(r, 0, sizeof(r));
206 memset(&gfar_data, 0, sizeof(gfar_data));
207
208 ret = of_address_to_resource(np, 0, &r[0]);
209 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600210 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600211
Andy Fleminga9b14972006-10-19 19:52:26 -0500212 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600213
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000214 model = of_get_property(np, "model", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600215
216 /* If we aren't the FEC we have multiple interrupts */
217 if (model && strcasecmp(model, "FEC")) {
218 r[1].name = gfar_tx_intr;
219
220 r[2].name = gfar_rx_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500221 of_irq_to_resource(np, 1, &r[2]);
Kumar Galaeed32002006-01-13 11:19:13 -0600222
223 r[3].name = gfar_err_intr;
Andy Fleminga9b14972006-10-19 19:52:26 -0500224 of_irq_to_resource(np, 2, &r[3]);
Jon Loeliger919fede2006-07-31 15:35:41 -0500225
226 n_res += 2;
Kumar Galaeed32002006-01-13 11:19:13 -0600227 }
228
Kumar Gala2fb07d72006-01-23 16:58:04 -0600229 gfar_dev =
230 platform_device_register_simple("fsl-gianfar", i, &r[0],
Vitaly Bordugfba43662006-09-21 17:26:34 +0400231 n_res);
Kumar Galaeed32002006-01-13 11:19:13 -0600232
233 if (IS_ERR(gfar_dev)) {
234 ret = PTR_ERR(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600235 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600236 }
237
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600238 mac_addr = of_get_mac_address(np);
Jon Loeligerf5831652006-08-17 08:42:35 -0500239 if (mac_addr)
240 memcpy(gfar_data.mac_addr, mac_addr, 6);
Kumar Galaeed32002006-01-13 11:19:13 -0600241
242 if (model && !strcasecmp(model, "TSEC"))
243 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600244 FSL_GIANFAR_DEV_HAS_GIGABIT |
245 FSL_GIANFAR_DEV_HAS_COALESCE |
246 FSL_GIANFAR_DEV_HAS_RMON |
247 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
Kumar Galaeed32002006-01-13 11:19:13 -0600248 if (model && !strcasecmp(model, "eTSEC"))
249 gfar_data.device_flags =
Kumar Gala2fb07d72006-01-23 16:58:04 -0600250 FSL_GIANFAR_DEV_HAS_GIGABIT |
251 FSL_GIANFAR_DEV_HAS_COALESCE |
252 FSL_GIANFAR_DEV_HAS_RMON |
253 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
254 FSL_GIANFAR_DEV_HAS_CSUM |
255 FSL_GIANFAR_DEV_HAS_VLAN |
256 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
Kumar Galaeed32002006-01-13 11:19:13 -0600257
Andy Fleming7132ab72007-07-11 11:43:07 -0500258 ctype = of_get_property(np, "phy-connection-type", NULL);
259
260 /* We only care about rgmii-id. The rest are autodetected */
261 if (ctype && !strcmp(ctype, "rgmii-id"))
262 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
263 else
264 gfar_data.interface = PHY_INTERFACE_MODE_MII;
265
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000266 ph = of_get_property(np, "phy-handle", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600267 phy = of_find_node_by_phandle(*ph);
268
269 if (phy == NULL) {
270 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600271 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600272 }
273
274 mdio = of_get_parent(phy);
275
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000276 id = of_get_property(phy, "reg", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600277 ret = of_address_to_resource(mdio, 0, &res);
278 if (ret) {
279 of_node_put(phy);
280 of_node_put(mdio);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600281 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600282 }
283
284 gfar_data.phy_id = *id;
285 gfar_data.bus_id = res.start;
286
287 of_node_put(phy);
288 of_node_put(mdio);
289
Kumar Gala2fb07d72006-01-23 16:58:04 -0600290 ret =
291 platform_device_add_data(gfar_dev, &gfar_data,
292 sizeof(struct
293 gianfar_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600294 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600295 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600296 }
297
298 return 0;
299
Kumar Gala2fb07d72006-01-23 16:58:04 -0600300unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600301 platform_device_unregister(gfar_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600302err:
Kumar Galaeed32002006-01-13 11:19:13 -0600303 return ret;
304}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600305
Kumar Galaeed32002006-01-13 11:19:13 -0600306arch_initcall(gfar_of_init);
307
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000308#ifdef CONFIG_I2C_BOARDINFO
309#include <linux/i2c.h>
310struct i2c_driver_device {
311 char *of_device;
312 char *i2c_driver;
313 char *i2c_type;
314};
315
316static struct i2c_driver_device i2c_devices[] __initdata = {
317 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
318 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
319 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
320 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
321};
322
323static int __init of_find_i2c_driver(struct device_node *node, struct i2c_board_info *info)
324{
325 int i;
326
327 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
328 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
329 continue;
330 strncpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN);
331 strncpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE);
332 return 0;
333 }
334 return -ENODEV;
335}
336
337static void __init of_register_i2c_devices(struct device_node *adap_node, int bus_num)
338{
339 struct device_node *node = NULL;
340
341 while ((node = of_get_next_child(adap_node, node))) {
342 struct i2c_board_info info;
343 const u32 *addr;
344 int len;
345
346 addr = of_get_property(node, "reg", &len);
347 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
348 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
349 continue;
350 }
351
352 info.irq = irq_of_parse_and_map(node, 0);
353 if (info.irq == NO_IRQ)
354 info.irq = -1;
355
356 if (of_find_i2c_driver(node, &info) < 0)
357 continue;
358
359 info.platform_data = NULL;
360 info.addr = *addr;
361
362 i2c_register_board_info(bus_num, &info, 1);
363 }
364}
365
Kumar Galaeed32002006-01-13 11:19:13 -0600366static int __init fsl_i2c_of_init(void)
367{
368 struct device_node *np;
369 unsigned int i;
370 struct platform_device *i2c_dev;
371 int ret;
372
Kumar Gala2fb07d72006-01-23 16:58:04 -0600373 for (np = NULL, i = 0;
374 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
375 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600376 struct resource r[2];
377 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000378 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600379
380 memset(&r, 0, sizeof(r));
381 memset(&i2c_data, 0, sizeof(i2c_data));
382
383 ret = of_address_to_resource(np, 0, &r[0]);
384 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600385 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600386
Andy Fleminga9b14972006-10-19 19:52:26 -0500387 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600388
389 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
390 if (IS_ERR(i2c_dev)) {
391 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600392 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600393 }
394
395 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000396 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600397 if (flags)
398 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
399
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000400 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600401 if (flags)
402 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
403
Kumar Gala2fb07d72006-01-23 16:58:04 -0600404 ret =
405 platform_device_add_data(i2c_dev, &i2c_data,
406 sizeof(struct
407 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600408 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600409 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000410
411 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600412 }
413
414 return 0;
415
Kumar Gala2fb07d72006-01-23 16:58:04 -0600416unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600417 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600418err:
Kumar Galaeed32002006-01-13 11:19:13 -0600419 return ret;
420}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600421
Kumar Galaeed32002006-01-13 11:19:13 -0600422arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000423#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600424
425#ifdef CONFIG_PPC_83xx
426static int __init mpc83xx_wdt_init(void)
427{
428 struct resource r;
429 struct device_node *soc, *np;
430 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000431 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600432 int ret;
433
434 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
435
436 if (!np) {
437 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600438 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600439 }
440
441 soc = of_find_node_by_type(NULL, "soc");
442
443 if (!soc) {
444 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600445 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600446 }
447
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000448 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600449 if (!freq) {
450 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600451 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600452 }
453
454 memset(&r, 0, sizeof(r));
455
456 ret = of_address_to_resource(np, 0, &r);
457 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600458 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600459
460 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
461 if (IS_ERR(dev)) {
462 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600463 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600464 }
465
466 ret = platform_device_add_data(dev, freq, sizeof(int));
467 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600468 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600469
470 of_node_put(soc);
471 of_node_put(np);
472
473 return 0;
474
Kumar Gala2fb07d72006-01-23 16:58:04 -0600475unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600476 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600477err:
Kumar Galaeed32002006-01-13 11:19:13 -0600478 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600479nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600480 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600481nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600482 return ret;
483}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600484
Kumar Galaeed32002006-01-13 11:19:13 -0600485arch_initcall(mpc83xx_wdt_init);
486#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600487
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000488static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600489{
490 if (!phy_type)
491 return FSL_USB2_PHY_NONE;
492 if (!strcasecmp(phy_type, "ulpi"))
493 return FSL_USB2_PHY_ULPI;
494 if (!strcasecmp(phy_type, "utmi"))
495 return FSL_USB2_PHY_UTMI;
496 if (!strcasecmp(phy_type, "utmi_wide"))
497 return FSL_USB2_PHY_UTMI_WIDE;
498 if (!strcasecmp(phy_type, "serial"))
499 return FSL_USB2_PHY_SERIAL;
500
501 return FSL_USB2_PHY_NONE;
502}
503
504static int __init fsl_usb_of_init(void)
505{
506 struct device_node *np;
507 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800508 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
509 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600510 int ret;
511
512 for (np = NULL, i = 0;
513 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
514 i++) {
515 struct resource r[2];
516 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000517 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600518
519 memset(&r, 0, sizeof(r));
520 memset(&usb_data, 0, sizeof(usb_data));
521
522 ret = of_address_to_resource(np, 0, &r[0]);
523 if (ret)
524 goto err;
525
Andy Fleminga9b14972006-10-19 19:52:26 -0500526 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600527
Kumar Gala01cced22006-04-11 10:07:16 -0500528 usb_dev_mph =
529 platform_device_register_simple("fsl-ehci", i, r, 2);
530 if (IS_ERR(usb_dev_mph)) {
531 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600532 goto err;
533 }
534
Kumar Gala01cced22006-04-11 10:07:16 -0500535 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
536 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600537
538 usb_data.operating_mode = FSL_USB2_MPH_HOST;
539
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000540 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600541 if (prop)
542 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
543
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000544 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600545 if (prop)
546 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
547
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000548 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600549 usb_data.phy_mode = determine_usb_phy(prop);
550
551 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500552 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600553 sizeof(struct
554 fsl_usb2_platform_data));
555 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500556 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600557 }
558
Kumar Gala01cced22006-04-11 10:07:16 -0500559 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600560 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
561 i++) {
562 struct resource r[2];
563 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000564 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600565
566 memset(&r, 0, sizeof(r));
567 memset(&usb_data, 0, sizeof(usb_data));
568
569 ret = of_address_to_resource(np, 0, &r[0]);
570 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500571 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600572
Andy Fleminga9b14972006-10-19 19:52:26 -0500573 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600574
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000575 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800576
577 if (!prop || !strcmp(prop, "host")) {
578 usb_data.operating_mode = FSL_USB2_DR_HOST;
579 usb_dev_dr_host = platform_device_register_simple(
580 "fsl-ehci", i, r, 2);
581 if (IS_ERR(usb_dev_dr_host)) {
582 ret = PTR_ERR(usb_dev_dr_host);
583 goto err;
584 }
585 } else if (prop && !strcmp(prop, "peripheral")) {
586 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
587 usb_dev_dr_client = platform_device_register_simple(
588 "fsl-usb2-udc", i, r, 2);
589 if (IS_ERR(usb_dev_dr_client)) {
590 ret = PTR_ERR(usb_dev_dr_client);
591 goto err;
592 }
593 } else if (prop && !strcmp(prop, "otg")) {
594 usb_data.operating_mode = FSL_USB2_DR_OTG;
595 usb_dev_dr_host = platform_device_register_simple(
596 "fsl-ehci", i, r, 2);
597 if (IS_ERR(usb_dev_dr_host)) {
598 ret = PTR_ERR(usb_dev_dr_host);
599 goto err;
600 }
601 usb_dev_dr_client = platform_device_register_simple(
602 "fsl-usb2-udc", i, r, 2);
603 if (IS_ERR(usb_dev_dr_client)) {
604 ret = PTR_ERR(usb_dev_dr_client);
605 goto err;
606 }
607 } else {
608 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600609 goto err;
610 }
611
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000612 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600613 usb_data.phy_mode = determine_usb_phy(prop);
614
Li Yang97c5a202007-02-07 13:49:24 +0800615 if (usb_dev_dr_host) {
616 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
617 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
618 dev.coherent_dma_mask;
619 if ((ret = platform_device_add_data(usb_dev_dr_host,
620 &usb_data, sizeof(struct
621 fsl_usb2_platform_data))))
622 goto unreg_dr;
623 }
624 if (usb_dev_dr_client) {
625 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
626 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
627 dev.coherent_dma_mask;
628 if ((ret = platform_device_add_data(usb_dev_dr_client,
629 &usb_data, sizeof(struct
630 fsl_usb2_platform_data))))
631 goto unreg_dr;
632 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600633 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600634 return 0;
635
Kumar Gala01cced22006-04-11 10:07:16 -0500636unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800637 if (usb_dev_dr_host)
638 platform_device_unregister(usb_dev_dr_host);
639 if (usb_dev_dr_client)
640 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500641unreg_mph:
642 if (usb_dev_mph)
643 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600644err:
645 return ret;
646}
647
Kumar Gala01cced22006-04-11 10:07:16 -0500648arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400649
650#ifdef CONFIG_CPM2
651
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300652extern void init_scc_ioports(struct fs_uart_platform_info*);
653
Vitaly Bordugfba43662006-09-21 17:26:34 +0400654static const char fcc_regs[] = "fcc_regs";
655static const char fcc_regs_c[] = "fcc_regs_c";
656static const char fcc_pram[] = "fcc_pram";
657static char bus_id[9][BUS_ID_SIZE];
658
659static int __init fs_enet_of_init(void)
660{
661 struct device_node *np;
662 unsigned int i;
663 struct platform_device *fs_enet_dev;
664 struct resource res;
665 int ret;
666
667 for (np = NULL, i = 0;
668 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
669 i++) {
670 struct resource r[4];
671 struct device_node *phy, *mdio;
672 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500673 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400674 const void *mac_addr;
675 const phandle *ph;
676 const char *model;
677
678 memset(r, 0, sizeof(r));
679 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
680
681 ret = of_address_to_resource(np, 0, &r[0]);
682 if (ret)
683 goto err;
684 r[0].name = fcc_regs;
685
686 ret = of_address_to_resource(np, 1, &r[1]);
687 if (ret)
688 goto err;
689 r[1].name = fcc_pram;
690
691 ret = of_address_to_resource(np, 2, &r[2]);
692 if (ret)
693 goto err;
694 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400695 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400696
Andy Fleminga9b14972006-10-19 19:52:26 -0500697 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400698
699 fs_enet_dev =
700 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
701
702 if (IS_ERR(fs_enet_dev)) {
703 ret = PTR_ERR(fs_enet_dev);
704 goto err;
705 }
706
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000707 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400708 if (model == NULL) {
709 ret = -ENODEV;
710 goto unreg;
711 }
712
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600713 mac_addr = of_get_mac_address(np);
714 if (mac_addr)
715 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400716
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000717 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400718 phy = of_find_node_by_phandle(*ph);
719
720 if (phy == NULL) {
721 ret = -ENODEV;
722 goto unreg;
723 }
724
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000725 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400726 fs_enet_data.phy_addr = *phy_addr;
727
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000728 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400729
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000730 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400731 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400732 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400733
734 mdio = of_get_parent(phy);
735 ret = of_address_to_resource(mdio, 0, &res);
736 if (ret) {
737 of_node_put(phy);
738 of_node_put(mdio);
739 goto unreg;
740 }
741
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000742 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
743 "rx-clock", NULL));
744 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
745 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400746
Vitaly Bordugfba43662006-09-21 17:26:34 +0400747 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400748 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500749 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400750
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400751 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400752 fs_enet_data.rx_ring = 32;
753 fs_enet_data.tx_ring = 32;
754 fs_enet_data.rx_copybreak = 240;
755 fs_enet_data.use_napi = 0;
756 fs_enet_data.napi_weight = 17;
757 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
758 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
759 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
760
761 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
762 (u32)res.start, fs_enet_data.phy_addr);
763 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400764 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400765
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000766 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400767 if (mdio_bb_prop) {
768 struct platform_device *fs_enet_mdio_bb_dev;
769 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400770
Vitaly Borduged943c12006-10-02 22:41:50 +0400771 fs_enet_mdio_bb_dev =
772 platform_device_register_simple("fsl-bb-mdio",
773 i, NULL, 0);
774 memset(&fs_enet_mdio_bb_data, 0,
775 sizeof(struct fs_mii_bb_platform_info));
776 fs_enet_mdio_bb_data.mdio_dat.bit =
777 mdio_bb_prop[0];
778 fs_enet_mdio_bb_data.mdio_dir.bit =
779 mdio_bb_prop[1];
780 fs_enet_mdio_bb_data.mdc_dat.bit =
781 mdio_bb_prop[2];
782 fs_enet_mdio_bb_data.mdio_port =
783 mdio_bb_prop[3];
784 fs_enet_mdio_bb_data.mdc_port =
785 mdio_bb_prop[4];
786 fs_enet_mdio_bb_data.delay =
787 mdio_bb_prop[5];
788
789 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
790 fs_enet_mdio_bb_data.irq[1] = -1;
791 fs_enet_mdio_bb_data.irq[2] = -1;
792 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
793 fs_enet_mdio_bb_data.irq[31] = -1;
794
795 fs_enet_mdio_bb_data.mdio_dat.offset =
796 (u32)&cpm2_immr->im_ioport.iop_pdatc;
797 fs_enet_mdio_bb_data.mdio_dir.offset =
798 (u32)&cpm2_immr->im_ioport.iop_pdirc;
799 fs_enet_mdio_bb_data.mdc_dat.offset =
800 (u32)&cpm2_immr->im_ioport.iop_pdatc;
801
802 ret = platform_device_add_data(
803 fs_enet_mdio_bb_dev,
804 &fs_enet_mdio_bb_data,
805 sizeof(struct fs_mii_bb_platform_info));
806 if (ret)
807 goto unreg;
808 }
Li Yang97c5a202007-02-07 13:49:24 +0800809
Vitaly Borduged943c12006-10-02 22:41:50 +0400810 of_node_put(phy);
811 of_node_put(mdio);
812
813 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
814 sizeof(struct
815 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500816 if (ret)
817 goto unreg;
818 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400819 }
820 return 0;
821
822unreg:
823 platform_device_unregister(fs_enet_dev);
824err:
825 return ret;
826}
827
828arch_initcall(fs_enet_of_init);
829
830static const char scc_regs[] = "regs";
831static const char scc_pram[] = "pram";
832
833static int __init cpm_uart_of_init(void)
834{
835 struct device_node *np;
836 unsigned int i;
837 struct platform_device *cpm_uart_dev;
838 int ret;
839
840 for (np = NULL, i = 0;
841 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
842 i++) {
843 struct resource r[3];
844 struct fs_uart_platform_info cpm_uart_data;
845 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400846 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400847
848 memset(r, 0, sizeof(r));
849 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
850
851 ret = of_address_to_resource(np, 0, &r[0]);
852 if (ret)
853 goto err;
854
855 r[0].name = scc_regs;
856
857 ret = of_address_to_resource(np, 1, &r[1]);
858 if (ret)
859 goto err;
860 r[1].name = scc_pram;
861
Andy Fleminga9b14972006-10-19 19:52:26 -0500862 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400863
864 cpm_uart_dev =
865 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
866
867 if (IS_ERR(cpm_uart_dev)) {
868 ret = PTR_ERR(cpm_uart_dev);
869 goto err;
870 }
871
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000872 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400873 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400874
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000875 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400876 strcpy(cpm_uart_data.fs_type, model);
877
Vitaly Bordugfba43662006-09-21 17:26:34 +0400878 cpm_uart_data.uart_clk = ppc_proc_freq;
879
880 cpm_uart_data.tx_num_fifo = 4;
881 cpm_uart_data.tx_buf_size = 32;
882 cpm_uart_data.rx_num_fifo = 4;
883 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000884 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
885 "rx-clock", NULL));
886 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
887 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400888
889 ret =
890 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
891 sizeof(struct
892 fs_uart_platform_info));
893 if (ret)
894 goto unreg;
895 }
896
897 return 0;
898
899unreg:
900 platform_device_unregister(cpm_uart_dev);
901err:
902 return ret;
903}
904
905arch_initcall(cpm_uart_of_init);
906#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300907
908#ifdef CONFIG_8xx
909
910extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000911extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300912
913static int __init fs_enet_mdio_of_init(void)
914{
915 struct device_node *np;
916 unsigned int i;
917 struct platform_device *mdio_dev;
918 struct resource res;
919 int ret;
920
921 for (np = NULL, i = 0;
922 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
923 i++) {
924 struct fs_mii_fec_platform_info mdio_data;
925
926 memset(&res, 0, sizeof(res));
927 memset(&mdio_data, 0, sizeof(mdio_data));
928
929 ret = of_address_to_resource(np, 0, &res);
930 if (ret)
931 goto err;
932
933 mdio_dev =
934 platform_device_register_simple("fsl-cpm-fec-mdio",
935 res.start, &res, 1);
936 if (IS_ERR(mdio_dev)) {
937 ret = PTR_ERR(mdio_dev);
938 goto err;
939 }
940
941 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
942
943 ret =
944 platform_device_add_data(mdio_dev, &mdio_data,
945 sizeof(struct fs_mii_fec_platform_info));
946 if (ret)
947 goto unreg;
948 }
949 return 0;
950
951unreg:
952 platform_device_unregister(mdio_dev);
953err:
954 return ret;
955}
956
957arch_initcall(fs_enet_mdio_of_init);
958
959static const char *enet_regs = "regs";
960static const char *enet_pram = "pram";
961static const char *enet_irq = "interrupt";
962static char bus_id[9][BUS_ID_SIZE];
963
964static int __init fs_enet_of_init(void)
965{
966 struct device_node *np;
967 unsigned int i;
968 struct platform_device *fs_enet_dev = NULL;
969 struct resource res;
970 int ret;
971
972 for (np = NULL, i = 0;
973 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
974 i++) {
975 struct resource r[4];
976 struct device_node *phy = NULL, *mdio = NULL;
977 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000978 const unsigned int *id;
979 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000980 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000981 const phandle *ph;
982 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300983
984 memset(r, 0, sizeof(r));
985 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
986
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000987 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300988 if (model == NULL) {
989 ret = -ENODEV;
990 goto unreg;
991 }
992
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000993 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300994 fs_enet_data.fs_no = *id;
995
996 if (platform_device_skip(model, *id))
997 continue;
998
999 ret = of_address_to_resource(np, 0, &r[0]);
1000 if (ret)
1001 goto err;
1002 r[0].name = enet_regs;
1003
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001004 mac_addr = of_get_mac_address(np);
1005 if (mac_addr)
1006 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001007
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001008 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001009 if (ph != NULL)
1010 phy = of_find_node_by_phandle(*ph);
1011
1012 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001013 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001014 fs_enet_data.phy_addr = *phy_addr;
1015 fs_enet_data.has_phy = 1;
1016
1017 mdio = of_get_parent(phy);
1018 ret = of_address_to_resource(mdio, 0, &res);
1019 if (ret) {
1020 of_node_put(phy);
1021 of_node_put(mdio);
1022 goto unreg;
1023 }
1024 }
1025
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001026 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001027 strcpy(fs_enet_data.fs_type, model);
1028
1029 if (strstr(model, "FEC")) {
1030 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1031 r[1].flags = IORESOURCE_IRQ;
1032 r[1].name = enet_irq;
1033
1034 fs_enet_dev =
1035 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1036
1037 if (IS_ERR(fs_enet_dev)) {
1038 ret = PTR_ERR(fs_enet_dev);
1039 goto err;
1040 }
1041
1042 fs_enet_data.rx_ring = 128;
1043 fs_enet_data.tx_ring = 16;
1044 fs_enet_data.rx_copybreak = 240;
1045 fs_enet_data.use_napi = 1;
1046 fs_enet_data.napi_weight = 17;
1047
1048 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1049 (u32)res.start, fs_enet_data.phy_addr);
1050 fs_enet_data.bus_id = (char*)&bus_id[i];
1051 fs_enet_data.init_ioports = init_fec_ioports;
1052 }
1053 if (strstr(model, "SCC")) {
1054 ret = of_address_to_resource(np, 1, &r[1]);
1055 if (ret)
1056 goto err;
1057 r[1].name = enet_pram;
1058
1059 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1060 r[2].flags = IORESOURCE_IRQ;
1061 r[2].name = enet_irq;
1062
1063 fs_enet_dev =
1064 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1065
1066 if (IS_ERR(fs_enet_dev)) {
1067 ret = PTR_ERR(fs_enet_dev);
1068 goto err;
1069 }
1070
1071 fs_enet_data.rx_ring = 64;
1072 fs_enet_data.tx_ring = 8;
1073 fs_enet_data.rx_copybreak = 240;
1074 fs_enet_data.use_napi = 1;
1075 fs_enet_data.napi_weight = 17;
1076
1077 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1078 fs_enet_data.bus_id = (char*)&bus_id[i];
1079 fs_enet_data.init_ioports = init_scc_ioports;
1080 }
1081
1082 of_node_put(phy);
1083 of_node_put(mdio);
1084
1085 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1086 sizeof(struct
1087 fs_platform_info));
1088 if (ret)
1089 goto unreg;
1090 }
1091 return 0;
1092
1093unreg:
1094 platform_device_unregister(fs_enet_dev);
1095err:
1096 return ret;
1097}
1098
1099arch_initcall(fs_enet_of_init);
1100
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001101static int __init fsl_pcmcia_of_init(void)
1102{
1103 struct device_node *np = NULL;
1104 /*
1105 * Register all the devices which type is "pcmcia"
1106 */
1107 while ((np = of_find_compatible_node(np,
1108 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1109 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1110 return 0;
1111}
1112
1113arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001114
1115static const char *smc_regs = "regs";
1116static const char *smc_pram = "pram";
1117
1118static int __init cpm_smc_uart_of_init(void)
1119{
1120 struct device_node *np;
1121 unsigned int i;
1122 struct platform_device *cpm_uart_dev;
1123 int ret;
1124
1125 for (np = NULL, i = 0;
1126 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1127 i++) {
1128 struct resource r[3];
1129 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001130 const int *id;
1131 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001132
1133 memset(r, 0, sizeof(r));
1134 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1135
1136 ret = of_address_to_resource(np, 0, &r[0]);
1137 if (ret)
1138 goto err;
1139
1140 r[0].name = smc_regs;
1141
1142 ret = of_address_to_resource(np, 1, &r[1]);
1143 if (ret)
1144 goto err;
1145 r[1].name = smc_pram;
1146
1147 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1148 r[2].flags = IORESOURCE_IRQ;
1149
1150 cpm_uart_dev =
1151 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1152
1153 if (IS_ERR(cpm_uart_dev)) {
1154 ret = PTR_ERR(cpm_uart_dev);
1155 goto err;
1156 }
1157
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001158 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001159 strcpy(cpm_uart_data.fs_type, model);
1160
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001161 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001162 cpm_uart_data.fs_no = *id;
1163 cpm_uart_data.uart_clk = ppc_proc_freq;
1164
1165 cpm_uart_data.tx_num_fifo = 4;
1166 cpm_uart_data.tx_buf_size = 32;
1167 cpm_uart_data.rx_num_fifo = 4;
1168 cpm_uart_data.rx_buf_size = 32;
1169
1170 ret =
1171 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1172 sizeof(struct
1173 fs_uart_platform_info));
1174 if (ret)
1175 goto unreg;
1176 }
1177
1178 return 0;
1179
1180unreg:
1181 platform_device_unregister(cpm_uart_dev);
1182err:
1183 return ret;
1184}
1185
1186arch_initcall(cpm_smc_uart_of_init);
1187
1188#endif /* CONFIG_8xx */