blob: 565f57d777fe7ee0efae2b9eb4023078987e03fc [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
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000323static int __init of_find_i2c_driver(struct device_node *node,
324 struct i2c_board_info *info)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000325{
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;
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000331 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
332 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
333 strlcpy(info->type, i2c_devices[i].i2c_type,
334 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
335 return -ENOMEM;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000336 return 0;
337 }
338 return -ENODEV;
339}
340
Guennadi Liakhovetskie78bb5d2007-08-16 05:15:03 +1000341static void __init of_register_i2c_devices(struct device_node *adap_node,
342 int bus_num)
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000343{
344 struct device_node *node = NULL;
345
346 while ((node = of_get_next_child(adap_node, node))) {
347 struct i2c_board_info info;
348 const u32 *addr;
349 int len;
350
351 addr = of_get_property(node, "reg", &len);
352 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
353 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
354 continue;
355 }
356
357 info.irq = irq_of_parse_and_map(node, 0);
358 if (info.irq == NO_IRQ)
359 info.irq = -1;
360
361 if (of_find_i2c_driver(node, &info) < 0)
362 continue;
363
364 info.platform_data = NULL;
365 info.addr = *addr;
366
367 i2c_register_board_info(bus_num, &info, 1);
368 }
369}
370
Kumar Galaeed32002006-01-13 11:19:13 -0600371static int __init fsl_i2c_of_init(void)
372{
373 struct device_node *np;
374 unsigned int i;
375 struct platform_device *i2c_dev;
376 int ret;
377
Kumar Gala2fb07d72006-01-23 16:58:04 -0600378 for (np = NULL, i = 0;
379 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
380 i++) {
Kumar Galaeed32002006-01-13 11:19:13 -0600381 struct resource r[2];
382 struct fsl_i2c_platform_data i2c_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000383 const unsigned char *flags = NULL;
Kumar Galaeed32002006-01-13 11:19:13 -0600384
385 memset(&r, 0, sizeof(r));
386 memset(&i2c_data, 0, sizeof(i2c_data));
387
388 ret = of_address_to_resource(np, 0, &r[0]);
389 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600390 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600391
Andy Fleminga9b14972006-10-19 19:52:26 -0500392 of_irq_to_resource(np, 0, &r[1]);
Kumar Galaeed32002006-01-13 11:19:13 -0600393
394 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
395 if (IS_ERR(i2c_dev)) {
396 ret = PTR_ERR(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600397 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600398 }
399
400 i2c_data.device_flags = 0;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000401 flags = of_get_property(np, "dfsrr", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600402 if (flags)
403 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
404
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000405 flags = of_get_property(np, "fsl5200-clocking", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600406 if (flags)
407 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
408
Kumar Gala2fb07d72006-01-23 16:58:04 -0600409 ret =
410 platform_device_add_data(i2c_dev, &i2c_data,
411 sizeof(struct
412 fsl_i2c_platform_data));
Kumar Galaeed32002006-01-13 11:19:13 -0600413 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600414 goto unreg;
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000415
416 of_register_i2c_devices(np, i);
Kumar Galaeed32002006-01-13 11:19:13 -0600417 }
418
419 return 0;
420
Kumar Gala2fb07d72006-01-23 16:58:04 -0600421unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600422 platform_device_unregister(i2c_dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600423err:
Kumar Galaeed32002006-01-13 11:19:13 -0600424 return ret;
425}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600426
Kumar Galaeed32002006-01-13 11:19:13 -0600427arch_initcall(fsl_i2c_of_init);
Guennadi Liakhovetskid13ae862007-07-21 06:26:15 +1000428#endif
Kumar Galaeed32002006-01-13 11:19:13 -0600429
430#ifdef CONFIG_PPC_83xx
431static int __init mpc83xx_wdt_init(void)
432{
433 struct resource r;
434 struct device_node *soc, *np;
435 struct platform_device *dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000436 const unsigned int *freq;
Kumar Galaeed32002006-01-13 11:19:13 -0600437 int ret;
438
439 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
440
441 if (!np) {
442 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600443 goto nodev;
Kumar Galaeed32002006-01-13 11:19:13 -0600444 }
445
446 soc = of_find_node_by_type(NULL, "soc");
447
448 if (!soc) {
449 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600450 goto nosoc;
Kumar Galaeed32002006-01-13 11:19:13 -0600451 }
452
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000453 freq = of_get_property(soc, "bus-frequency", NULL);
Kumar Galaeed32002006-01-13 11:19:13 -0600454 if (!freq) {
455 ret = -ENODEV;
Kumar Gala2fb07d72006-01-23 16:58:04 -0600456 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600457 }
458
459 memset(&r, 0, sizeof(r));
460
461 ret = of_address_to_resource(np, 0, &r);
462 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600463 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600464
465 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
466 if (IS_ERR(dev)) {
467 ret = PTR_ERR(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600468 goto err;
Kumar Galaeed32002006-01-13 11:19:13 -0600469 }
470
471 ret = platform_device_add_data(dev, freq, sizeof(int));
472 if (ret)
Kumar Gala2fb07d72006-01-23 16:58:04 -0600473 goto unreg;
Kumar Galaeed32002006-01-13 11:19:13 -0600474
475 of_node_put(soc);
476 of_node_put(np);
477
478 return 0;
479
Kumar Gala2fb07d72006-01-23 16:58:04 -0600480unreg:
Kumar Galaeed32002006-01-13 11:19:13 -0600481 platform_device_unregister(dev);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600482err:
Kumar Galaeed32002006-01-13 11:19:13 -0600483 of_node_put(soc);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600484nosoc:
Kumar Galaeed32002006-01-13 11:19:13 -0600485 of_node_put(np);
Kumar Gala2fb07d72006-01-23 16:58:04 -0600486nodev:
Kumar Galaeed32002006-01-13 11:19:13 -0600487 return ret;
488}
Kumar Gala2fb07d72006-01-23 16:58:04 -0600489
Kumar Galaeed32002006-01-13 11:19:13 -0600490arch_initcall(mpc83xx_wdt_init);
491#endif
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600492
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000493static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600494{
495 if (!phy_type)
496 return FSL_USB2_PHY_NONE;
497 if (!strcasecmp(phy_type, "ulpi"))
498 return FSL_USB2_PHY_ULPI;
499 if (!strcasecmp(phy_type, "utmi"))
500 return FSL_USB2_PHY_UTMI;
501 if (!strcasecmp(phy_type, "utmi_wide"))
502 return FSL_USB2_PHY_UTMI_WIDE;
503 if (!strcasecmp(phy_type, "serial"))
504 return FSL_USB2_PHY_SERIAL;
505
506 return FSL_USB2_PHY_NONE;
507}
508
509static int __init fsl_usb_of_init(void)
510{
511 struct device_node *np;
512 unsigned int i;
Li Yang97c5a202007-02-07 13:49:24 +0800513 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
514 *usb_dev_dr_client = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600515 int ret;
516
517 for (np = NULL, i = 0;
518 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
519 i++) {
520 struct resource r[2];
521 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000522 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600523
524 memset(&r, 0, sizeof(r));
525 memset(&usb_data, 0, sizeof(usb_data));
526
527 ret = of_address_to_resource(np, 0, &r[0]);
528 if (ret)
529 goto err;
530
Andy Fleminga9b14972006-10-19 19:52:26 -0500531 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600532
Kumar Gala01cced22006-04-11 10:07:16 -0500533 usb_dev_mph =
534 platform_device_register_simple("fsl-ehci", i, r, 2);
535 if (IS_ERR(usb_dev_mph)) {
536 ret = PTR_ERR(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600537 goto err;
538 }
539
Kumar Gala01cced22006-04-11 10:07:16 -0500540 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
541 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600542
543 usb_data.operating_mode = FSL_USB2_MPH_HOST;
544
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000545 prop = of_get_property(np, "port0", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600546 if (prop)
547 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
548
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000549 prop = of_get_property(np, "port1", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600550 if (prop)
551 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
552
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000553 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600554 usb_data.phy_mode = determine_usb_phy(prop);
555
556 ret =
Kumar Gala01cced22006-04-11 10:07:16 -0500557 platform_device_add_data(usb_dev_mph, &usb_data,
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600558 sizeof(struct
559 fsl_usb2_platform_data));
560 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500561 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600562 }
563
Kumar Gala01cced22006-04-11 10:07:16 -0500564 for (np = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600565 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
566 i++) {
567 struct resource r[2];
568 struct fsl_usb2_platform_data usb_data;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000569 const unsigned char *prop = NULL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600570
571 memset(&r, 0, sizeof(r));
572 memset(&usb_data, 0, sizeof(usb_data));
573
574 ret = of_address_to_resource(np, 0, &r[0]);
575 if (ret)
Kumar Gala01cced22006-04-11 10:07:16 -0500576 goto unreg_mph;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600577
Andy Fleminga9b14972006-10-19 19:52:26 -0500578 of_irq_to_resource(np, 0, &r[1]);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600579
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000580 prop = of_get_property(np, "dr_mode", NULL);
Li Yang97c5a202007-02-07 13:49:24 +0800581
582 if (!prop || !strcmp(prop, "host")) {
583 usb_data.operating_mode = FSL_USB2_DR_HOST;
584 usb_dev_dr_host = platform_device_register_simple(
585 "fsl-ehci", i, r, 2);
586 if (IS_ERR(usb_dev_dr_host)) {
587 ret = PTR_ERR(usb_dev_dr_host);
588 goto err;
589 }
590 } else if (prop && !strcmp(prop, "peripheral")) {
591 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
592 usb_dev_dr_client = platform_device_register_simple(
593 "fsl-usb2-udc", i, r, 2);
594 if (IS_ERR(usb_dev_dr_client)) {
595 ret = PTR_ERR(usb_dev_dr_client);
596 goto err;
597 }
598 } else if (prop && !strcmp(prop, "otg")) {
599 usb_data.operating_mode = FSL_USB2_DR_OTG;
600 usb_dev_dr_host = platform_device_register_simple(
601 "fsl-ehci", i, r, 2);
602 if (IS_ERR(usb_dev_dr_host)) {
603 ret = PTR_ERR(usb_dev_dr_host);
604 goto err;
605 }
606 usb_dev_dr_client = platform_device_register_simple(
607 "fsl-usb2-udc", i, r, 2);
608 if (IS_ERR(usb_dev_dr_client)) {
609 ret = PTR_ERR(usb_dev_dr_client);
610 goto err;
611 }
612 } else {
613 ret = -EINVAL;
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600614 goto err;
615 }
616
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000617 prop = of_get_property(np, "phy_type", NULL);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600618 usb_data.phy_mode = determine_usb_phy(prop);
619
Li Yang97c5a202007-02-07 13:49:24 +0800620 if (usb_dev_dr_host) {
621 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
622 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
623 dev.coherent_dma_mask;
624 if ((ret = platform_device_add_data(usb_dev_dr_host,
625 &usb_data, sizeof(struct
626 fsl_usb2_platform_data))))
627 goto unreg_dr;
628 }
629 if (usb_dev_dr_client) {
630 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
631 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
632 dev.coherent_dma_mask;
633 if ((ret = platform_device_add_data(usb_dev_dr_client,
634 &usb_data, sizeof(struct
635 fsl_usb2_platform_data))))
636 goto unreg_dr;
637 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600638 }
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600639 return 0;
640
Kumar Gala01cced22006-04-11 10:07:16 -0500641unreg_dr:
Li Yang97c5a202007-02-07 13:49:24 +0800642 if (usb_dev_dr_host)
643 platform_device_unregister(usb_dev_dr_host);
644 if (usb_dev_dr_client)
645 platform_device_unregister(usb_dev_dr_client);
Kumar Gala01cced22006-04-11 10:07:16 -0500646unreg_mph:
647 if (usb_dev_mph)
648 platform_device_unregister(usb_dev_mph);
Kumar Gala4b10cfd2006-02-02 12:31:00 -0600649err:
650 return ret;
651}
652
Kumar Gala01cced22006-04-11 10:07:16 -0500653arch_initcall(fsl_usb_of_init);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400654
655#ifdef CONFIG_CPM2
656
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300657extern void init_scc_ioports(struct fs_uart_platform_info*);
658
Vitaly Bordugfba43662006-09-21 17:26:34 +0400659static const char fcc_regs[] = "fcc_regs";
660static const char fcc_regs_c[] = "fcc_regs_c";
661static const char fcc_pram[] = "fcc_pram";
662static char bus_id[9][BUS_ID_SIZE];
663
664static int __init fs_enet_of_init(void)
665{
666 struct device_node *np;
667 unsigned int i;
668 struct platform_device *fs_enet_dev;
669 struct resource res;
670 int ret;
671
672 for (np = NULL, i = 0;
673 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
674 i++) {
675 struct resource r[4];
676 struct device_node *phy, *mdio;
677 struct fs_platform_info fs_enet_data;
Olof Johansson2b00b252006-10-05 21:16:48 -0500678 const unsigned int *id, *phy_addr, *phy_irq;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400679 const void *mac_addr;
680 const phandle *ph;
681 const char *model;
682
683 memset(r, 0, sizeof(r));
684 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
685
686 ret = of_address_to_resource(np, 0, &r[0]);
687 if (ret)
688 goto err;
689 r[0].name = fcc_regs;
690
691 ret = of_address_to_resource(np, 1, &r[1]);
692 if (ret)
693 goto err;
694 r[1].name = fcc_pram;
695
696 ret = of_address_to_resource(np, 2, &r[2]);
697 if (ret)
698 goto err;
699 r[2].name = fcc_regs_c;
Vitaly Borduged943c12006-10-02 22:41:50 +0400700 fs_enet_data.fcc_regs_c = r[2].start;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400701
Andy Fleminga9b14972006-10-19 19:52:26 -0500702 of_irq_to_resource(np, 0, &r[3]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400703
704 fs_enet_dev =
705 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
706
707 if (IS_ERR(fs_enet_dev)) {
708 ret = PTR_ERR(fs_enet_dev);
709 goto err;
710 }
711
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000712 model = of_get_property(np, "model", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400713 if (model == NULL) {
714 ret = -ENODEV;
715 goto unreg;
716 }
717
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600718 mac_addr = of_get_mac_address(np);
719 if (mac_addr)
720 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400721
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000722 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400723 phy = of_find_node_by_phandle(*ph);
724
725 if (phy == NULL) {
726 ret = -ENODEV;
727 goto unreg;
728 }
729
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000730 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400731 fs_enet_data.phy_addr = *phy_addr;
732
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000733 phy_irq = of_get_property(phy, "interrupts", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400734
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000735 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400736 fs_enet_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400737 strcpy(fs_enet_data.fs_type, model);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400738
739 mdio = of_get_parent(phy);
740 ret = of_address_to_resource(mdio, 0, &res);
741 if (ret) {
742 of_node_put(phy);
743 of_node_put(mdio);
744 goto unreg;
745 }
746
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000747 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
748 "rx-clock", NULL));
749 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
750 "tx-clock", NULL));
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400751
Vitaly Bordugfba43662006-09-21 17:26:34 +0400752 if (strstr(model, "FCC")) {
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400753 int fcc_index = *id - 1;
Olof Johansson2b00b252006-10-05 21:16:48 -0500754 const unsigned char *mdio_bb_prop;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400755
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400756 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400757 fs_enet_data.rx_ring = 32;
758 fs_enet_data.tx_ring = 32;
759 fs_enet_data.rx_copybreak = 240;
760 fs_enet_data.use_napi = 0;
761 fs_enet_data.napi_weight = 17;
762 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
763 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
764 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
765
766 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
767 (u32)res.start, fs_enet_data.phy_addr);
768 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
Vitaly Bordugd3465c92006-09-21 22:38:05 +0400769 fs_enet_data.init_ioports = init_fcc_ioports;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400770
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000771 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
Vitaly Borduged943c12006-10-02 22:41:50 +0400772 if (mdio_bb_prop) {
773 struct platform_device *fs_enet_mdio_bb_dev;
774 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400775
Vitaly Borduged943c12006-10-02 22:41:50 +0400776 fs_enet_mdio_bb_dev =
777 platform_device_register_simple("fsl-bb-mdio",
778 i, NULL, 0);
779 memset(&fs_enet_mdio_bb_data, 0,
780 sizeof(struct fs_mii_bb_platform_info));
781 fs_enet_mdio_bb_data.mdio_dat.bit =
782 mdio_bb_prop[0];
783 fs_enet_mdio_bb_data.mdio_dir.bit =
784 mdio_bb_prop[1];
785 fs_enet_mdio_bb_data.mdc_dat.bit =
786 mdio_bb_prop[2];
787 fs_enet_mdio_bb_data.mdio_port =
788 mdio_bb_prop[3];
789 fs_enet_mdio_bb_data.mdc_port =
790 mdio_bb_prop[4];
791 fs_enet_mdio_bb_data.delay =
792 mdio_bb_prop[5];
793
794 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
795 fs_enet_mdio_bb_data.irq[1] = -1;
796 fs_enet_mdio_bb_data.irq[2] = -1;
797 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
798 fs_enet_mdio_bb_data.irq[31] = -1;
799
800 fs_enet_mdio_bb_data.mdio_dat.offset =
801 (u32)&cpm2_immr->im_ioport.iop_pdatc;
802 fs_enet_mdio_bb_data.mdio_dir.offset =
803 (u32)&cpm2_immr->im_ioport.iop_pdirc;
804 fs_enet_mdio_bb_data.mdc_dat.offset =
805 (u32)&cpm2_immr->im_ioport.iop_pdatc;
806
807 ret = platform_device_add_data(
808 fs_enet_mdio_bb_dev,
809 &fs_enet_mdio_bb_data,
810 sizeof(struct fs_mii_bb_platform_info));
811 if (ret)
812 goto unreg;
813 }
Li Yang97c5a202007-02-07 13:49:24 +0800814
Vitaly Borduged943c12006-10-02 22:41:50 +0400815 of_node_put(phy);
816 of_node_put(mdio);
817
818 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
819 sizeof(struct
820 fs_platform_info));
Olof Johansson2b00b252006-10-05 21:16:48 -0500821 if (ret)
822 goto unreg;
823 }
Vitaly Bordugfba43662006-09-21 17:26:34 +0400824 }
825 return 0;
826
827unreg:
828 platform_device_unregister(fs_enet_dev);
829err:
830 return ret;
831}
832
833arch_initcall(fs_enet_of_init);
834
835static const char scc_regs[] = "regs";
836static const char scc_pram[] = "pram";
837
838static int __init cpm_uart_of_init(void)
839{
840 struct device_node *np;
841 unsigned int i;
842 struct platform_device *cpm_uart_dev;
843 int ret;
844
845 for (np = NULL, i = 0;
846 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
847 i++) {
848 struct resource r[3];
849 struct fs_uart_platform_info cpm_uart_data;
850 const int *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400851 const char *model;
Vitaly Bordugfba43662006-09-21 17:26:34 +0400852
853 memset(r, 0, sizeof(r));
854 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
855
856 ret = of_address_to_resource(np, 0, &r[0]);
857 if (ret)
858 goto err;
859
860 r[0].name = scc_regs;
861
862 ret = of_address_to_resource(np, 1, &r[1]);
863 if (ret)
864 goto err;
865 r[1].name = scc_pram;
866
Andy Fleminga9b14972006-10-19 19:52:26 -0500867 of_irq_to_resource(np, 0, &r[2]);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400868
869 cpm_uart_dev =
870 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
871
872 if (IS_ERR(cpm_uart_dev)) {
873 ret = PTR_ERR(cpm_uart_dev);
874 goto err;
875 }
876
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000877 id = of_get_property(np, "device-id", NULL);
Vitaly Bordugfba43662006-09-21 17:26:34 +0400878 cpm_uart_data.fs_no = *id;
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400879
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000880 model = of_get_property(np, "model", NULL);
Vitaly Bordug611a15a2006-09-21 22:38:05 +0400881 strcpy(cpm_uart_data.fs_type, model);
882
Vitaly Bordugfba43662006-09-21 17:26:34 +0400883 cpm_uart_data.uart_clk = ppc_proc_freq;
884
885 cpm_uart_data.tx_num_fifo = 4;
886 cpm_uart_data.tx_buf_size = 32;
887 cpm_uart_data.rx_num_fifo = 4;
888 cpm_uart_data.rx_buf_size = 32;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000889 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
890 "rx-clock", NULL));
891 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
892 "tx-clock", NULL));
Vitaly Bordugfba43662006-09-21 17:26:34 +0400893
894 ret =
895 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
896 sizeof(struct
897 fs_uart_platform_info));
898 if (ret)
899 goto unreg;
900 }
901
902 return 0;
903
904unreg:
905 platform_device_unregister(cpm_uart_dev);
906err:
907 return ret;
908}
909
910arch_initcall(cpm_uart_of_init);
911#endif /* CONFIG_CPM2 */
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300912
913#ifdef CONFIG_8xx
914
915extern void init_scc_ioports(struct fs_platform_info*);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000916extern int platform_device_skip(const char *model, int id);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300917
918static int __init fs_enet_mdio_of_init(void)
919{
920 struct device_node *np;
921 unsigned int i;
922 struct platform_device *mdio_dev;
923 struct resource res;
924 int ret;
925
926 for (np = NULL, i = 0;
927 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
928 i++) {
929 struct fs_mii_fec_platform_info mdio_data;
930
931 memset(&res, 0, sizeof(res));
932 memset(&mdio_data, 0, sizeof(mdio_data));
933
934 ret = of_address_to_resource(np, 0, &res);
935 if (ret)
936 goto err;
937
938 mdio_dev =
939 platform_device_register_simple("fsl-cpm-fec-mdio",
940 res.start, &res, 1);
941 if (IS_ERR(mdio_dev)) {
942 ret = PTR_ERR(mdio_dev);
943 goto err;
944 }
945
946 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
947
948 ret =
949 platform_device_add_data(mdio_dev, &mdio_data,
950 sizeof(struct fs_mii_fec_platform_info));
951 if (ret)
952 goto unreg;
953 }
954 return 0;
955
956unreg:
957 platform_device_unregister(mdio_dev);
958err:
959 return ret;
960}
961
962arch_initcall(fs_enet_mdio_of_init);
963
964static const char *enet_regs = "regs";
965static const char *enet_pram = "pram";
966static const char *enet_irq = "interrupt";
967static char bus_id[9][BUS_ID_SIZE];
968
969static int __init fs_enet_of_init(void)
970{
971 struct device_node *np;
972 unsigned int i;
973 struct platform_device *fs_enet_dev = NULL;
974 struct resource res;
975 int ret;
976
977 for (np = NULL, i = 0;
978 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
979 i++) {
980 struct resource r[4];
981 struct device_node *phy = NULL, *mdio = NULL;
982 struct fs_platform_info fs_enet_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000983 const unsigned int *id;
984 const unsigned int *phy_addr;
Scott Woodb7a69122007-05-09 03:15:34 +1000985 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000986 const phandle *ph;
987 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300988
989 memset(r, 0, sizeof(r));
990 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
991
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000992 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300993 if (model == NULL) {
994 ret = -ENODEV;
995 goto unreg;
996 }
997
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000998 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +0300999 fs_enet_data.fs_no = *id;
1000
1001 if (platform_device_skip(model, *id))
1002 continue;
1003
1004 ret = of_address_to_resource(np, 0, &r[0]);
1005 if (ret)
1006 goto err;
1007 r[0].name = enet_regs;
1008
Timur Tabi29cfe6f2007-02-16 12:01:29 -06001009 mac_addr = of_get_mac_address(np);
1010 if (mac_addr)
1011 memcpy(fs_enet_data.macaddr, mac_addr, 6);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001012
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001013 ph = of_get_property(np, "phy-handle", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001014 if (ph != NULL)
1015 phy = of_find_node_by_phandle(*ph);
1016
1017 if (phy != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001018 phy_addr = of_get_property(phy, "reg", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001019 fs_enet_data.phy_addr = *phy_addr;
1020 fs_enet_data.has_phy = 1;
1021
1022 mdio = of_get_parent(phy);
1023 ret = of_address_to_resource(mdio, 0, &res);
1024 if (ret) {
1025 of_node_put(phy);
1026 of_node_put(mdio);
1027 goto unreg;
1028 }
1029 }
1030
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001031 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001032 strcpy(fs_enet_data.fs_type, model);
1033
1034 if (strstr(model, "FEC")) {
1035 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1036 r[1].flags = IORESOURCE_IRQ;
1037 r[1].name = enet_irq;
1038
1039 fs_enet_dev =
1040 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1041
1042 if (IS_ERR(fs_enet_dev)) {
1043 ret = PTR_ERR(fs_enet_dev);
1044 goto err;
1045 }
1046
1047 fs_enet_data.rx_ring = 128;
1048 fs_enet_data.tx_ring = 16;
1049 fs_enet_data.rx_copybreak = 240;
1050 fs_enet_data.use_napi = 1;
1051 fs_enet_data.napi_weight = 17;
1052
1053 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1054 (u32)res.start, fs_enet_data.phy_addr);
1055 fs_enet_data.bus_id = (char*)&bus_id[i];
1056 fs_enet_data.init_ioports = init_fec_ioports;
1057 }
1058 if (strstr(model, "SCC")) {
1059 ret = of_address_to_resource(np, 1, &r[1]);
1060 if (ret)
1061 goto err;
1062 r[1].name = enet_pram;
1063
1064 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1065 r[2].flags = IORESOURCE_IRQ;
1066 r[2].name = enet_irq;
1067
1068 fs_enet_dev =
1069 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1070
1071 if (IS_ERR(fs_enet_dev)) {
1072 ret = PTR_ERR(fs_enet_dev);
1073 goto err;
1074 }
1075
1076 fs_enet_data.rx_ring = 64;
1077 fs_enet_data.tx_ring = 8;
1078 fs_enet_data.rx_copybreak = 240;
1079 fs_enet_data.use_napi = 1;
1080 fs_enet_data.napi_weight = 17;
1081
1082 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1083 fs_enet_data.bus_id = (char*)&bus_id[i];
1084 fs_enet_data.init_ioports = init_scc_ioports;
1085 }
1086
1087 of_node_put(phy);
1088 of_node_put(mdio);
1089
1090 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1091 sizeof(struct
1092 fs_platform_info));
1093 if (ret)
1094 goto unreg;
1095 }
1096 return 0;
1097
1098unreg:
1099 platform_device_unregister(fs_enet_dev);
1100err:
1101 return ret;
1102}
1103
1104arch_initcall(fs_enet_of_init);
1105
Vitaly Bordug80128ff2007-07-09 11:37:35 -07001106static int __init fsl_pcmcia_of_init(void)
1107{
1108 struct device_node *np = NULL;
1109 /*
1110 * Register all the devices which type is "pcmcia"
1111 */
1112 while ((np = of_find_compatible_node(np,
1113 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1114 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1115 return 0;
1116}
1117
1118arch_initcall(fsl_pcmcia_of_init);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001119
1120static const char *smc_regs = "regs";
1121static const char *smc_pram = "pram";
1122
1123static int __init cpm_smc_uart_of_init(void)
1124{
1125 struct device_node *np;
1126 unsigned int i;
1127 struct platform_device *cpm_uart_dev;
1128 int ret;
1129
1130 for (np = NULL, i = 0;
1131 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1132 i++) {
1133 struct resource r[3];
1134 struct fs_uart_platform_info cpm_uart_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001135 const int *id;
1136 const char *model;
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001137
1138 memset(r, 0, sizeof(r));
1139 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1140
1141 ret = of_address_to_resource(np, 0, &r[0]);
1142 if (ret)
1143 goto err;
1144
1145 r[0].name = smc_regs;
1146
1147 ret = of_address_to_resource(np, 1, &r[1]);
1148 if (ret)
1149 goto err;
1150 r[1].name = smc_pram;
1151
1152 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1153 r[2].flags = IORESOURCE_IRQ;
1154
1155 cpm_uart_dev =
1156 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1157
1158 if (IS_ERR(cpm_uart_dev)) {
1159 ret = PTR_ERR(cpm_uart_dev);
1160 goto err;
1161 }
1162
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001163 model = of_get_property(np, "model", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001164 strcpy(cpm_uart_data.fs_type, model);
1165
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001166 id = of_get_property(np, "device-id", NULL);
Vitaly Bordug88bdc6f2007-01-24 22:41:15 +03001167 cpm_uart_data.fs_no = *id;
1168 cpm_uart_data.uart_clk = ppc_proc_freq;
1169
1170 cpm_uart_data.tx_num_fifo = 4;
1171 cpm_uart_data.tx_buf_size = 32;
1172 cpm_uart_data.rx_num_fifo = 4;
1173 cpm_uart_data.rx_buf_size = 32;
1174
1175 ret =
1176 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1177 sizeof(struct
1178 fs_uart_platform_info));
1179 if (ret)
1180 goto unreg;
1181 }
1182
1183 return 0;
1184
1185unreg:
1186 platform_device_unregister(cpm_uart_dev);
1187err:
1188 return ret;
1189}
1190
1191arch_initcall(cpm_smc_uart_of_init);
1192
1193#endif /* CONFIG_8xx */