[POWERPC] 52xx: Fix mpc52xx_uart_of_assign to use correct index
[deliverable/linux.git] / arch / powerpc / sysdev / fsl_soc.c
CommitLineData
eed32001
KG
1/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
fba43665
VB
6 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
8 *
eed32001
KG
9 * 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
eed32001
KG
15#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>
0af666fa 25#include <linux/of_platform.h>
a9b14973 26#include <linux/phy.h>
eed32001 27#include <linux/fsl_devices.h>
fba43665
VB
28#include <linux/fs_enet_pd.h>
29#include <linux/fs_uart_pd.h>
eed32001
KG
30
31#include <asm/system.h>
32#include <asm/atomic.h>
33#include <asm/io.h>
34#include <asm/irq.h>
fba43665 35#include <asm/time.h>
eed32001
KG
36#include <asm/prom.h>
37#include <sysdev/fsl_soc.h>
38#include <mm/mmu_decl.h>
fba43665 39#include <asm/cpm2.h>
eed32001 40
d3465c92 41extern void init_fcc_ioports(struct fs_platform_info*);
88bdc6f0
VB
42extern void init_fec_ioports(struct fs_platform_info*);
43extern void init_smc_ioports(struct fs_uart_platform_info*);
eed32001
KG
44static 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");
2fb07d77 54 if (soc) {
f9234736 55 int size;
e2eb6392 56 const void *prop = of_get_property(soc, "reg", &size);
fba43665
VB
57
58 if (prop)
59 immrbase = of_translate_address(soc, prop);
eed32001 60 of_node_put(soc);
f9234736 61 }
eed32001
KG
62
63 return immrbase;
64}
eed32001 65
2fb07d77 66EXPORT_SYMBOL(get_immrbase);
eed32001 67
88bdc6f0 68#if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
fba43665
VB
69
70static u32 brgfreq = -1;
71
72u32 get_brgfreq(void)
73{
74 struct device_node *node;
75
76 if (brgfreq != -1)
77 return brgfreq;
78
f9234736
SW
79 node = of_find_compatible_node(NULL, NULL, "fsl,cpm1");
80 if (!node)
81 node = of_find_compatible_node(NULL, NULL, "fsl,cpm2");
82 if (!node)
83 node = of_find_node_by_type(NULL, "cpm");
fba43665 84 if (node) {
f9234736
SW
85 int size;
86 const unsigned int *prop;
fba43665 87
f9234736
SW
88 prop = of_get_property(node, "fsl,brg-frequency", &size);
89 if (!prop)
90 prop = of_get_property(node, "brg-frequency", &size);
91 if (prop && size == 4)
fba43665 92 brgfreq = *prop;
f9234736 93
fba43665 94 of_node_put(node);
f9234736 95 }
fba43665
VB
96
97 return brgfreq;
98}
99
100EXPORT_SYMBOL(get_brgfreq);
101
102static u32 fs_baudrate = -1;
103
104u32 get_baudrate(void)
105{
106 struct device_node *node;
107
108 if (fs_baudrate != -1)
109 return fs_baudrate;
110
111 node = of_find_node_by_type(NULL, "serial");
112 if (node) {
f9234736 113 int size;
e2eb6392
SR
114 const unsigned int *prop = of_get_property(node,
115 "current-speed", &size);
fba43665
VB
116
117 if (prop)
118 fs_baudrate = *prop;
119 of_node_put(node);
f9234736 120 }
fba43665
VB
121
122 return fs_baudrate;
123}
124
125EXPORT_SYMBOL(get_baudrate);
126#endif /* CONFIG_CPM2 */
127
2fb07d77 128static int __init gfar_mdio_of_init(void)
eed32001
KG
129{
130 struct device_node *np;
131 unsigned int i;
2fb07d77 132 struct platform_device *mdio_dev;
eed32001
KG
133 struct resource res;
134 int ret;
135
2fb07d77
KG
136 for (np = NULL, i = 0;
137 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
138 i++) {
eed32001
KG
139 int k;
140 struct device_node *child = NULL;
141 struct gianfar_mdio_data mdio_data;
142
143 memset(&res, 0, sizeof(res));
144 memset(&mdio_data, 0, sizeof(mdio_data));
145
146 ret = of_address_to_resource(np, 0, &res);
147 if (ret)
2fb07d77 148 goto err;
eed32001 149
2fb07d77
KG
150 mdio_dev =
151 platform_device_register_simple("fsl-gianfar_mdio",
152 res.start, &res, 1);
eed32001
KG
153 if (IS_ERR(mdio_dev)) {
154 ret = PTR_ERR(mdio_dev);
2fb07d77 155 goto err;
eed32001
KG
156 }
157
158 for (k = 0; k < 32; k++)
a9b14973 159 mdio_data.irq[k] = PHY_POLL;
eed32001
KG
160
161 while ((child = of_get_next_child(np, child)) != NULL) {
fba43665
VB
162 int irq = irq_of_parse_and_map(child, 0);
163 if (irq != NO_IRQ) {
e2eb6392
SR
164 const u32 *id = of_get_property(child,
165 "reg", NULL);
fba43665
VB
166 mdio_data.irq[*id] = irq;
167 }
eed32001
KG
168 }
169
2fb07d77
KG
170 ret =
171 platform_device_add_data(mdio_dev, &mdio_data,
172 sizeof(struct gianfar_mdio_data));
eed32001 173 if (ret)
2fb07d77 174 goto unreg;
eed32001
KG
175 }
176
2fb07d77
KG
177 return 0;
178
179unreg:
180 platform_device_unregister(mdio_dev);
181err:
182 return ret;
183}
184
185arch_initcall(gfar_mdio_of_init);
186
187static const char *gfar_tx_intr = "tx";
188static const char *gfar_rx_intr = "rx";
189static const char *gfar_err_intr = "error";
190
a9b14973 191
2fb07d77
KG
192static int __init gfar_of_init(void)
193{
194 struct device_node *np;
195 unsigned int i;
196 struct platform_device *gfar_dev;
197 struct resource res;
198 int ret;
199
200 for (np = NULL, i = 0;
201 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
202 i++) {
eed32001
KG
203 struct resource r[4];
204 struct device_node *phy, *mdio;
205 struct gianfar_platform_data gfar_data;
a7f67bdf
JK
206 const unsigned int *id;
207 const char *model;
7132ab7f 208 const char *ctype;
a7f67bdf
JK
209 const void *mac_addr;
210 const phandle *ph;
fba43665 211 int n_res = 2;
eed32001
KG
212
213 memset(r, 0, sizeof(r));
214 memset(&gfar_data, 0, sizeof(gfar_data));
215
216 ret = of_address_to_resource(np, 0, &r[0]);
217 if (ret)
2fb07d77 218 goto err;
eed32001 219
a9b14973 220 of_irq_to_resource(np, 0, &r[1]);
eed32001 221
e2eb6392 222 model = of_get_property(np, "model", NULL);
eed32001
KG
223
224 /* If we aren't the FEC we have multiple interrupts */
225 if (model && strcasecmp(model, "FEC")) {
226 r[1].name = gfar_tx_intr;
227
228 r[2].name = gfar_rx_intr;
a9b14973 229 of_irq_to_resource(np, 1, &r[2]);
eed32001
KG
230
231 r[3].name = gfar_err_intr;
a9b14973 232 of_irq_to_resource(np, 2, &r[3]);
919fede6
JL
233
234 n_res += 2;
eed32001
KG
235 }
236
2fb07d77
KG
237 gfar_dev =
238 platform_device_register_simple("fsl-gianfar", i, &r[0],
fba43665 239 n_res);
eed32001
KG
240
241 if (IS_ERR(gfar_dev)) {
242 ret = PTR_ERR(gfar_dev);
2fb07d77 243 goto err;
eed32001
KG
244 }
245
29cfe6f4 246 mac_addr = of_get_mac_address(np);
f583165f
JL
247 if (mac_addr)
248 memcpy(gfar_data.mac_addr, mac_addr, 6);
eed32001
KG
249
250 if (model && !strcasecmp(model, "TSEC"))
251 gfar_data.device_flags =
2fb07d77
KG
252 FSL_GIANFAR_DEV_HAS_GIGABIT |
253 FSL_GIANFAR_DEV_HAS_COALESCE |
254 FSL_GIANFAR_DEV_HAS_RMON |
255 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
eed32001
KG
256 if (model && !strcasecmp(model, "eTSEC"))
257 gfar_data.device_flags =
2fb07d77
KG
258 FSL_GIANFAR_DEV_HAS_GIGABIT |
259 FSL_GIANFAR_DEV_HAS_COALESCE |
260 FSL_GIANFAR_DEV_HAS_RMON |
261 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
262 FSL_GIANFAR_DEV_HAS_CSUM |
263 FSL_GIANFAR_DEV_HAS_VLAN |
264 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
eed32001 265
7132ab7f
AF
266 ctype = of_get_property(np, "phy-connection-type", NULL);
267
268 /* We only care about rgmii-id. The rest are autodetected */
269 if (ctype && !strcmp(ctype, "rgmii-id"))
270 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
271 else
272 gfar_data.interface = PHY_INTERFACE_MODE_MII;
273
e2eb6392 274 ph = of_get_property(np, "phy-handle", NULL);
eed32001
KG
275 phy = of_find_node_by_phandle(*ph);
276
277 if (phy == NULL) {
278 ret = -ENODEV;
2fb07d77 279 goto unreg;
eed32001
KG
280 }
281
282 mdio = of_get_parent(phy);
283
e2eb6392 284 id = of_get_property(phy, "reg", NULL);
eed32001
KG
285 ret = of_address_to_resource(mdio, 0, &res);
286 if (ret) {
287 of_node_put(phy);
288 of_node_put(mdio);
2fb07d77 289 goto unreg;
eed32001
KG
290 }
291
292 gfar_data.phy_id = *id;
293 gfar_data.bus_id = res.start;
294
295 of_node_put(phy);
296 of_node_put(mdio);
297
2fb07d77
KG
298 ret =
299 platform_device_add_data(gfar_dev, &gfar_data,
300 sizeof(struct
301 gianfar_platform_data));
eed32001 302 if (ret)
2fb07d77 303 goto unreg;
eed32001
KG
304 }
305
306 return 0;
307
2fb07d77 308unreg:
eed32001 309 platform_device_unregister(gfar_dev);
2fb07d77 310err:
eed32001
KG
311 return ret;
312}
2fb07d77 313
eed32001
KG
314arch_initcall(gfar_of_init);
315
d13ae862
GL
316#ifdef CONFIG_I2C_BOARDINFO
317#include <linux/i2c.h>
318struct i2c_driver_device {
319 char *of_device;
320 char *i2c_driver;
321 char *i2c_type;
322};
323
324static struct i2c_driver_device i2c_devices[] __initdata = {
325 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
326 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
327 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
328 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
329};
330
e78bb5dc
GL
331static int __init of_find_i2c_driver(struct device_node *node,
332 struct i2c_board_info *info)
d13ae862
GL
333{
334 int i;
335
336 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
337 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
338 continue;
e78bb5dc
GL
339 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
340 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
341 strlcpy(info->type, i2c_devices[i].i2c_type,
342 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
343 return -ENOMEM;
d13ae862
GL
344 return 0;
345 }
346 return -ENODEV;
347}
348
e78bb5dc
GL
349static void __init of_register_i2c_devices(struct device_node *adap_node,
350 int bus_num)
d13ae862
GL
351{
352 struct device_node *node = NULL;
353
354 while ((node = of_get_next_child(adap_node, node))) {
355 struct i2c_board_info info;
356 const u32 *addr;
357 int len;
358
359 addr = of_get_property(node, "reg", &len);
360 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
361 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
362 continue;
363 }
364
365 info.irq = irq_of_parse_and_map(node, 0);
366 if (info.irq == NO_IRQ)
367 info.irq = -1;
368
369 if (of_find_i2c_driver(node, &info) < 0)
370 continue;
371
372 info.platform_data = NULL;
373 info.addr = *addr;
374
375 i2c_register_board_info(bus_num, &info, 1);
376 }
377}
378
eed32001
KG
379static int __init fsl_i2c_of_init(void)
380{
381 struct device_node *np;
382 unsigned int i;
383 struct platform_device *i2c_dev;
384 int ret;
385
2fb07d77
KG
386 for (np = NULL, i = 0;
387 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
388 i++) {
eed32001
KG
389 struct resource r[2];
390 struct fsl_i2c_platform_data i2c_data;
a7f67bdf 391 const unsigned char *flags = NULL;
eed32001
KG
392
393 memset(&r, 0, sizeof(r));
394 memset(&i2c_data, 0, sizeof(i2c_data));
395
396 ret = of_address_to_resource(np, 0, &r[0]);
397 if (ret)
2fb07d77 398 goto err;
eed32001 399
a9b14973 400 of_irq_to_resource(np, 0, &r[1]);
eed32001
KG
401
402 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
403 if (IS_ERR(i2c_dev)) {
404 ret = PTR_ERR(i2c_dev);
2fb07d77 405 goto err;
eed32001
KG
406 }
407
408 i2c_data.device_flags = 0;
e2eb6392 409 flags = of_get_property(np, "dfsrr", NULL);
eed32001
KG
410 if (flags)
411 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
412
e2eb6392 413 flags = of_get_property(np, "fsl5200-clocking", NULL);
eed32001
KG
414 if (flags)
415 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
416
2fb07d77
KG
417 ret =
418 platform_device_add_data(i2c_dev, &i2c_data,
419 sizeof(struct
420 fsl_i2c_platform_data));
eed32001 421 if (ret)
2fb07d77 422 goto unreg;
d13ae862
GL
423
424 of_register_i2c_devices(np, i);
eed32001
KG
425 }
426
427 return 0;
428
2fb07d77 429unreg:
eed32001 430 platform_device_unregister(i2c_dev);
2fb07d77 431err:
eed32001
KG
432 return ret;
433}
2fb07d77 434
eed32001 435arch_initcall(fsl_i2c_of_init);
d13ae862 436#endif
eed32001
KG
437
438#ifdef CONFIG_PPC_83xx
439static int __init mpc83xx_wdt_init(void)
440{
441 struct resource r;
442 struct device_node *soc, *np;
443 struct platform_device *dev;
a7f67bdf 444 const unsigned int *freq;
eed32001
KG
445 int ret;
446
447 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
448
449 if (!np) {
450 ret = -ENODEV;
2fb07d77 451 goto nodev;
eed32001
KG
452 }
453
454 soc = of_find_node_by_type(NULL, "soc");
455
456 if (!soc) {
457 ret = -ENODEV;
2fb07d77 458 goto nosoc;
eed32001
KG
459 }
460
e2eb6392 461 freq = of_get_property(soc, "bus-frequency", NULL);
eed32001
KG
462 if (!freq) {
463 ret = -ENODEV;
2fb07d77 464 goto err;
eed32001
KG
465 }
466
467 memset(&r, 0, sizeof(r));
468
469 ret = of_address_to_resource(np, 0, &r);
470 if (ret)
2fb07d77 471 goto err;
eed32001
KG
472
473 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
474 if (IS_ERR(dev)) {
475 ret = PTR_ERR(dev);
2fb07d77 476 goto err;
eed32001
KG
477 }
478
479 ret = platform_device_add_data(dev, freq, sizeof(int));
480 if (ret)
2fb07d77 481 goto unreg;
eed32001
KG
482
483 of_node_put(soc);
484 of_node_put(np);
485
486 return 0;
487
2fb07d77 488unreg:
eed32001 489 platform_device_unregister(dev);
2fb07d77 490err:
eed32001 491 of_node_put(soc);
2fb07d77 492nosoc:
eed32001 493 of_node_put(np);
2fb07d77 494nodev:
eed32001
KG
495 return ret;
496}
2fb07d77 497
eed32001
KG
498arch_initcall(mpc83xx_wdt_init);
499#endif
4b10cfd4 500
a7f67bdf 501static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
4b10cfd4
KG
502{
503 if (!phy_type)
504 return FSL_USB2_PHY_NONE;
505 if (!strcasecmp(phy_type, "ulpi"))
506 return FSL_USB2_PHY_ULPI;
507 if (!strcasecmp(phy_type, "utmi"))
508 return FSL_USB2_PHY_UTMI;
509 if (!strcasecmp(phy_type, "utmi_wide"))
510 return FSL_USB2_PHY_UTMI_WIDE;
511 if (!strcasecmp(phy_type, "serial"))
512 return FSL_USB2_PHY_SERIAL;
513
514 return FSL_USB2_PHY_NONE;
515}
516
517static int __init fsl_usb_of_init(void)
518{
519 struct device_node *np;
520 unsigned int i;
97c5a20a
LY
521 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
522 *usb_dev_dr_client = NULL;
4b10cfd4
KG
523 int ret;
524
525 for (np = NULL, i = 0;
526 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
527 i++) {
528 struct resource r[2];
529 struct fsl_usb2_platform_data usb_data;
a7f67bdf 530 const unsigned char *prop = NULL;
4b10cfd4
KG
531
532 memset(&r, 0, sizeof(r));
533 memset(&usb_data, 0, sizeof(usb_data));
534
535 ret = of_address_to_resource(np, 0, &r[0]);
536 if (ret)
537 goto err;
538
a9b14973 539 of_irq_to_resource(np, 0, &r[1]);
4b10cfd4 540
01cced25
KG
541 usb_dev_mph =
542 platform_device_register_simple("fsl-ehci", i, r, 2);
543 if (IS_ERR(usb_dev_mph)) {
544 ret = PTR_ERR(usb_dev_mph);
4b10cfd4
KG
545 goto err;
546 }
547
01cced25
KG
548 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
549 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
4b10cfd4
KG
550
551 usb_data.operating_mode = FSL_USB2_MPH_HOST;
552
e2eb6392 553 prop = of_get_property(np, "port0", NULL);
4b10cfd4
KG
554 if (prop)
555 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
556
e2eb6392 557 prop = of_get_property(np, "port1", NULL);
4b10cfd4
KG
558 if (prop)
559 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
560
e2eb6392 561 prop = of_get_property(np, "phy_type", NULL);
4b10cfd4
KG
562 usb_data.phy_mode = determine_usb_phy(prop);
563
564 ret =
01cced25 565 platform_device_add_data(usb_dev_mph, &usb_data,
4b10cfd4
KG
566 sizeof(struct
567 fsl_usb2_platform_data));
568 if (ret)
01cced25 569 goto unreg_mph;
4b10cfd4
KG
570 }
571
01cced25 572 for (np = NULL;
4b10cfd4
KG
573 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
574 i++) {
575 struct resource r[2];
576 struct fsl_usb2_platform_data usb_data;
a7f67bdf 577 const unsigned char *prop = NULL;
4b10cfd4
KG
578
579 memset(&r, 0, sizeof(r));
580 memset(&usb_data, 0, sizeof(usb_data));
581
582 ret = of_address_to_resource(np, 0, &r[0]);
583 if (ret)
01cced25 584 goto unreg_mph;
4b10cfd4 585
a9b14973 586 of_irq_to_resource(np, 0, &r[1]);
4b10cfd4 587
e2eb6392 588 prop = of_get_property(np, "dr_mode", NULL);
97c5a20a
LY
589
590 if (!prop || !strcmp(prop, "host")) {
591 usb_data.operating_mode = FSL_USB2_DR_HOST;
592 usb_dev_dr_host = platform_device_register_simple(
593 "fsl-ehci", i, r, 2);
594 if (IS_ERR(usb_dev_dr_host)) {
595 ret = PTR_ERR(usb_dev_dr_host);
596 goto err;
597 }
598 } else if (prop && !strcmp(prop, "peripheral")) {
599 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
600 usb_dev_dr_client = platform_device_register_simple(
601 "fsl-usb2-udc", i, r, 2);
602 if (IS_ERR(usb_dev_dr_client)) {
603 ret = PTR_ERR(usb_dev_dr_client);
604 goto err;
605 }
606 } else if (prop && !strcmp(prop, "otg")) {
607 usb_data.operating_mode = FSL_USB2_DR_OTG;
608 usb_dev_dr_host = platform_device_register_simple(
609 "fsl-ehci", i, r, 2);
610 if (IS_ERR(usb_dev_dr_host)) {
611 ret = PTR_ERR(usb_dev_dr_host);
612 goto err;
613 }
614 usb_dev_dr_client = platform_device_register_simple(
615 "fsl-usb2-udc", i, r, 2);
616 if (IS_ERR(usb_dev_dr_client)) {
617 ret = PTR_ERR(usb_dev_dr_client);
618 goto err;
619 }
620 } else {
621 ret = -EINVAL;
4b10cfd4
KG
622 goto err;
623 }
624
e2eb6392 625 prop = of_get_property(np, "phy_type", NULL);
4b10cfd4
KG
626 usb_data.phy_mode = determine_usb_phy(prop);
627
97c5a20a
LY
628 if (usb_dev_dr_host) {
629 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
630 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
631 dev.coherent_dma_mask;
632 if ((ret = platform_device_add_data(usb_dev_dr_host,
633 &usb_data, sizeof(struct
634 fsl_usb2_platform_data))))
635 goto unreg_dr;
636 }
637 if (usb_dev_dr_client) {
638 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
639 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
640 dev.coherent_dma_mask;
641 if ((ret = platform_device_add_data(usb_dev_dr_client,
642 &usb_data, sizeof(struct
643 fsl_usb2_platform_data))))
644 goto unreg_dr;
645 }
4b10cfd4 646 }
4b10cfd4
KG
647 return 0;
648
01cced25 649unreg_dr:
97c5a20a
LY
650 if (usb_dev_dr_host)
651 platform_device_unregister(usb_dev_dr_host);
652 if (usb_dev_dr_client)
653 platform_device_unregister(usb_dev_dr_client);
01cced25
KG
654unreg_mph:
655 if (usb_dev_mph)
656 platform_device_unregister(usb_dev_mph);
4b10cfd4
KG
657err:
658 return ret;
659}
660
01cced25 661arch_initcall(fsl_usb_of_init);
fba43665
VB
662
663#ifdef CONFIG_CPM2
664
88bdc6f0
VB
665extern void init_scc_ioports(struct fs_uart_platform_info*);
666
fba43665
VB
667static const char fcc_regs[] = "fcc_regs";
668static const char fcc_regs_c[] = "fcc_regs_c";
669static const char fcc_pram[] = "fcc_pram";
670static char bus_id[9][BUS_ID_SIZE];
671
672static int __init fs_enet_of_init(void)
673{
674 struct device_node *np;
675 unsigned int i;
676 struct platform_device *fs_enet_dev;
677 struct resource res;
678 int ret;
679
680 for (np = NULL, i = 0;
681 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
682 i++) {
683 struct resource r[4];
684 struct device_node *phy, *mdio;
685 struct fs_platform_info fs_enet_data;
2b00b254 686 const unsigned int *id, *phy_addr, *phy_irq;
fba43665
VB
687 const void *mac_addr;
688 const phandle *ph;
689 const char *model;
690
691 memset(r, 0, sizeof(r));
692 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
693
694 ret = of_address_to_resource(np, 0, &r[0]);
695 if (ret)
696 goto err;
697 r[0].name = fcc_regs;
698
699 ret = of_address_to_resource(np, 1, &r[1]);
700 if (ret)
701 goto err;
702 r[1].name = fcc_pram;
703
704 ret = of_address_to_resource(np, 2, &r[2]);
705 if (ret)
706 goto err;
707 r[2].name = fcc_regs_c;
ed943c1f 708 fs_enet_data.fcc_regs_c = r[2].start;
fba43665 709
a9b14973 710 of_irq_to_resource(np, 0, &r[3]);
fba43665
VB
711
712 fs_enet_dev =
713 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
714
715 if (IS_ERR(fs_enet_dev)) {
716 ret = PTR_ERR(fs_enet_dev);
717 goto err;
718 }
719
e2eb6392 720 model = of_get_property(np, "model", NULL);
fba43665
VB
721 if (model == NULL) {
722 ret = -ENODEV;
723 goto unreg;
724 }
725
29cfe6f4
TT
726 mac_addr = of_get_mac_address(np);
727 if (mac_addr)
728 memcpy(fs_enet_data.macaddr, mac_addr, 6);
fba43665 729
e2eb6392 730 ph = of_get_property(np, "phy-handle", NULL);
fba43665
VB
731 phy = of_find_node_by_phandle(*ph);
732
733 if (phy == NULL) {
734 ret = -ENODEV;
735 goto unreg;
736 }
737
e2eb6392 738 phy_addr = of_get_property(phy, "reg", NULL);
fba43665
VB
739 fs_enet_data.phy_addr = *phy_addr;
740
e2eb6392 741 phy_irq = of_get_property(phy, "interrupts", NULL);
ed943c1f 742
e2eb6392 743 id = of_get_property(np, "device-id", NULL);
fba43665 744 fs_enet_data.fs_no = *id;
611a15af 745 strcpy(fs_enet_data.fs_type, model);
fba43665
VB
746
747 mdio = of_get_parent(phy);
748 ret = of_address_to_resource(mdio, 0, &res);
749 if (ret) {
750 of_node_put(phy);
751 of_node_put(mdio);
752 goto unreg;
753 }
754
e2eb6392
SR
755 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
756 "rx-clock", NULL));
757 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
758 "tx-clock", NULL));
d3465c92 759
fba43665 760 if (strstr(model, "FCC")) {
611a15af 761 int fcc_index = *id - 1;
2b00b254 762 const unsigned char *mdio_bb_prop;
fba43665 763
fc8e50e3 764 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
fba43665
VB
765 fs_enet_data.rx_ring = 32;
766 fs_enet_data.tx_ring = 32;
767 fs_enet_data.rx_copybreak = 240;
768 fs_enet_data.use_napi = 0;
769 fs_enet_data.napi_weight = 17;
770 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
771 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
772 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
773
774 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
775 (u32)res.start, fs_enet_data.phy_addr);
776 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
d3465c92 777 fs_enet_data.init_ioports = init_fcc_ioports;
fba43665 778
e2eb6392 779 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
ed943c1f
VB
780 if (mdio_bb_prop) {
781 struct platform_device *fs_enet_mdio_bb_dev;
782 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
783
784 fs_enet_mdio_bb_dev =
785 platform_device_register_simple("fsl-bb-mdio",
786 i, NULL, 0);
787 memset(&fs_enet_mdio_bb_data, 0,
788 sizeof(struct fs_mii_bb_platform_info));
789 fs_enet_mdio_bb_data.mdio_dat.bit =
790 mdio_bb_prop[0];
791 fs_enet_mdio_bb_data.mdio_dir.bit =
792 mdio_bb_prop[1];
793 fs_enet_mdio_bb_data.mdc_dat.bit =
794 mdio_bb_prop[2];
795 fs_enet_mdio_bb_data.mdio_port =
796 mdio_bb_prop[3];
797 fs_enet_mdio_bb_data.mdc_port =
798 mdio_bb_prop[4];
799 fs_enet_mdio_bb_data.delay =
800 mdio_bb_prop[5];
801
802 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
803 fs_enet_mdio_bb_data.irq[1] = -1;
804 fs_enet_mdio_bb_data.irq[2] = -1;
805 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
806 fs_enet_mdio_bb_data.irq[31] = -1;
807
808 fs_enet_mdio_bb_data.mdio_dat.offset =
809 (u32)&cpm2_immr->im_ioport.iop_pdatc;
810 fs_enet_mdio_bb_data.mdio_dir.offset =
811 (u32)&cpm2_immr->im_ioport.iop_pdirc;
812 fs_enet_mdio_bb_data.mdc_dat.offset =
813 (u32)&cpm2_immr->im_ioport.iop_pdatc;
814
815 ret = platform_device_add_data(
816 fs_enet_mdio_bb_dev,
817 &fs_enet_mdio_bb_data,
818 sizeof(struct fs_mii_bb_platform_info));
819 if (ret)
820 goto unreg;
821 }
97c5a20a 822
ed943c1f
VB
823 of_node_put(phy);
824 of_node_put(mdio);
fba43665 825
ed943c1f
VB
826 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
827 sizeof(struct
828 fs_platform_info));
2b00b254
OJ
829 if (ret)
830 goto unreg;
831 }
fba43665
VB
832 }
833 return 0;
834
835unreg:
836 platform_device_unregister(fs_enet_dev);
837err:
838 return ret;
839}
840
841arch_initcall(fs_enet_of_init);
842
843static const char scc_regs[] = "regs";
844static const char scc_pram[] = "pram";
845
846static int __init cpm_uart_of_init(void)
847{
848 struct device_node *np;
849 unsigned int i;
850 struct platform_device *cpm_uart_dev;
851 int ret;
852
853 for (np = NULL, i = 0;
854 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
855 i++) {
856 struct resource r[3];
857 struct fs_uart_platform_info cpm_uart_data;
858 const int *id;
611a15af 859 const char *model;
fba43665
VB
860
861 memset(r, 0, sizeof(r));
862 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
863
864 ret = of_address_to_resource(np, 0, &r[0]);
865 if (ret)
866 goto err;
867
868 r[0].name = scc_regs;
869
870 ret = of_address_to_resource(np, 1, &r[1]);
871 if (ret)
872 goto err;
873 r[1].name = scc_pram;
874
a9b14973 875 of_irq_to_resource(np, 0, &r[2]);
fba43665
VB
876
877 cpm_uart_dev =
878 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
879
880 if (IS_ERR(cpm_uart_dev)) {
881 ret = PTR_ERR(cpm_uart_dev);
882 goto err;
883 }
884
e2eb6392 885 id = of_get_property(np, "device-id", NULL);
fba43665 886 cpm_uart_data.fs_no = *id;
611a15af 887
e2eb6392 888 model = of_get_property(np, "model", NULL);
611a15af
VB
889 strcpy(cpm_uart_data.fs_type, model);
890
fba43665
VB
891 cpm_uart_data.uart_clk = ppc_proc_freq;
892
893 cpm_uart_data.tx_num_fifo = 4;
894 cpm_uart_data.tx_buf_size = 32;
895 cpm_uart_data.rx_num_fifo = 4;
896 cpm_uart_data.rx_buf_size = 32;
e2eb6392
SR
897 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
898 "rx-clock", NULL));
899 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
900 "tx-clock", NULL));
fba43665
VB
901
902 ret =
903 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
904 sizeof(struct
905 fs_uart_platform_info));
906 if (ret)
907 goto unreg;
908 }
909
910 return 0;
911
912unreg:
913 platform_device_unregister(cpm_uart_dev);
914err:
915 return ret;
916}
917
918arch_initcall(cpm_uart_of_init);
919#endif /* CONFIG_CPM2 */
88bdc6f0
VB
920
921#ifdef CONFIG_8xx
922
923extern void init_scc_ioports(struct fs_platform_info*);
e2eb6392 924extern int platform_device_skip(const char *model, int id);
88bdc6f0
VB
925
926static int __init fs_enet_mdio_of_init(void)
927{
928 struct device_node *np;
929 unsigned int i;
930 struct platform_device *mdio_dev;
931 struct resource res;
932 int ret;
933
934 for (np = NULL, i = 0;
935 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
936 i++) {
937 struct fs_mii_fec_platform_info mdio_data;
938
939 memset(&res, 0, sizeof(res));
940 memset(&mdio_data, 0, sizeof(mdio_data));
941
942 ret = of_address_to_resource(np, 0, &res);
943 if (ret)
944 goto err;
945
946 mdio_dev =
947 platform_device_register_simple("fsl-cpm-fec-mdio",
948 res.start, &res, 1);
949 if (IS_ERR(mdio_dev)) {
950 ret = PTR_ERR(mdio_dev);
951 goto err;
952 }
953
954 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
955
956 ret =
957 platform_device_add_data(mdio_dev, &mdio_data,
958 sizeof(struct fs_mii_fec_platform_info));
959 if (ret)
960 goto unreg;
961 }
962 return 0;
963
964unreg:
965 platform_device_unregister(mdio_dev);
966err:
967 return ret;
968}
969
970arch_initcall(fs_enet_mdio_of_init);
971
972static const char *enet_regs = "regs";
973static const char *enet_pram = "pram";
974static const char *enet_irq = "interrupt";
975static char bus_id[9][BUS_ID_SIZE];
976
977static int __init fs_enet_of_init(void)
978{
979 struct device_node *np;
980 unsigned int i;
981 struct platform_device *fs_enet_dev = NULL;
982 struct resource res;
983 int ret;
984
985 for (np = NULL, i = 0;
986 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
987 i++) {
988 struct resource r[4];
989 struct device_node *phy = NULL, *mdio = NULL;
990 struct fs_platform_info fs_enet_data;
e2eb6392
SR
991 const unsigned int *id;
992 const unsigned int *phy_addr;
b7a69129 993 const void *mac_addr;
e2eb6392
SR
994 const phandle *ph;
995 const char *model;
88bdc6f0
VB
996
997 memset(r, 0, sizeof(r));
998 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
999
e2eb6392 1000 model = of_get_property(np, "model", NULL);
88bdc6f0
VB
1001 if (model == NULL) {
1002 ret = -ENODEV;
1003 goto unreg;
1004 }
1005
e2eb6392 1006 id = of_get_property(np, "device-id", NULL);
88bdc6f0
VB
1007 fs_enet_data.fs_no = *id;
1008
1009 if (platform_device_skip(model, *id))
1010 continue;
1011
1012 ret = of_address_to_resource(np, 0, &r[0]);
1013 if (ret)
1014 goto err;
1015 r[0].name = enet_regs;
1016
29cfe6f4
TT
1017 mac_addr = of_get_mac_address(np);
1018 if (mac_addr)
1019 memcpy(fs_enet_data.macaddr, mac_addr, 6);
88bdc6f0 1020
e2eb6392 1021 ph = of_get_property(np, "phy-handle", NULL);
88bdc6f0
VB
1022 if (ph != NULL)
1023 phy = of_find_node_by_phandle(*ph);
1024
1025 if (phy != NULL) {
e2eb6392 1026 phy_addr = of_get_property(phy, "reg", NULL);
88bdc6f0
VB
1027 fs_enet_data.phy_addr = *phy_addr;
1028 fs_enet_data.has_phy = 1;
1029
1030 mdio = of_get_parent(phy);
1031 ret = of_address_to_resource(mdio, 0, &res);
1032 if (ret) {
1033 of_node_put(phy);
1034 of_node_put(mdio);
1035 goto unreg;
1036 }
1037 }
1038
e2eb6392 1039 model = of_get_property(np, "model", NULL);
88bdc6f0
VB
1040 strcpy(fs_enet_data.fs_type, model);
1041
1042 if (strstr(model, "FEC")) {
1043 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1044 r[1].flags = IORESOURCE_IRQ;
1045 r[1].name = enet_irq;
1046
1047 fs_enet_dev =
1048 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1049
1050 if (IS_ERR(fs_enet_dev)) {
1051 ret = PTR_ERR(fs_enet_dev);
1052 goto err;
1053 }
1054
1055 fs_enet_data.rx_ring = 128;
1056 fs_enet_data.tx_ring = 16;
1057 fs_enet_data.rx_copybreak = 240;
1058 fs_enet_data.use_napi = 1;
1059 fs_enet_data.napi_weight = 17;
1060
1061 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1062 (u32)res.start, fs_enet_data.phy_addr);
1063 fs_enet_data.bus_id = (char*)&bus_id[i];
1064 fs_enet_data.init_ioports = init_fec_ioports;
1065 }
1066 if (strstr(model, "SCC")) {
1067 ret = of_address_to_resource(np, 1, &r[1]);
1068 if (ret)
1069 goto err;
1070 r[1].name = enet_pram;
1071
1072 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1073 r[2].flags = IORESOURCE_IRQ;
1074 r[2].name = enet_irq;
1075
1076 fs_enet_dev =
1077 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1078
1079 if (IS_ERR(fs_enet_dev)) {
1080 ret = PTR_ERR(fs_enet_dev);
1081 goto err;
1082 }
1083
1084 fs_enet_data.rx_ring = 64;
1085 fs_enet_data.tx_ring = 8;
1086 fs_enet_data.rx_copybreak = 240;
1087 fs_enet_data.use_napi = 1;
1088 fs_enet_data.napi_weight = 17;
1089
1090 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1091 fs_enet_data.bus_id = (char*)&bus_id[i];
1092 fs_enet_data.init_ioports = init_scc_ioports;
1093 }
1094
1095 of_node_put(phy);
1096 of_node_put(mdio);
1097
1098 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1099 sizeof(struct
1100 fs_platform_info));
1101 if (ret)
1102 goto unreg;
1103 }
1104 return 0;
1105
1106unreg:
1107 platform_device_unregister(fs_enet_dev);
1108err:
1109 return ret;
1110}
1111
1112arch_initcall(fs_enet_of_init);
1113
80128ff7
VB
1114static int __init fsl_pcmcia_of_init(void)
1115{
1116 struct device_node *np = NULL;
1117 /*
1118 * Register all the devices which type is "pcmcia"
1119 */
1120 while ((np = of_find_compatible_node(np,
1121 "pcmcia", "fsl,pq-pcmcia")) != NULL)
1122 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1123 return 0;
1124}
1125
1126arch_initcall(fsl_pcmcia_of_init);
88bdc6f0
VB
1127
1128static const char *smc_regs = "regs";
1129static const char *smc_pram = "pram";
1130
1131static int __init cpm_smc_uart_of_init(void)
1132{
1133 struct device_node *np;
1134 unsigned int i;
1135 struct platform_device *cpm_uart_dev;
1136 int ret;
1137
1138 for (np = NULL, i = 0;
1139 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1140 i++) {
1141 struct resource r[3];
1142 struct fs_uart_platform_info cpm_uart_data;
e2eb6392
SR
1143 const int *id;
1144 const char *model;
88bdc6f0
VB
1145
1146 memset(r, 0, sizeof(r));
1147 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1148
1149 ret = of_address_to_resource(np, 0, &r[0]);
1150 if (ret)
1151 goto err;
1152
1153 r[0].name = smc_regs;
1154
1155 ret = of_address_to_resource(np, 1, &r[1]);
1156 if (ret)
1157 goto err;
1158 r[1].name = smc_pram;
1159
1160 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1161 r[2].flags = IORESOURCE_IRQ;
1162
1163 cpm_uart_dev =
1164 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1165
1166 if (IS_ERR(cpm_uart_dev)) {
1167 ret = PTR_ERR(cpm_uart_dev);
1168 goto err;
1169 }
1170
e2eb6392 1171 model = of_get_property(np, "model", NULL);
88bdc6f0
VB
1172 strcpy(cpm_uart_data.fs_type, model);
1173
e2eb6392 1174 id = of_get_property(np, "device-id", NULL);
88bdc6f0
VB
1175 cpm_uart_data.fs_no = *id;
1176 cpm_uart_data.uart_clk = ppc_proc_freq;
1177
1178 cpm_uart_data.tx_num_fifo = 4;
1179 cpm_uart_data.tx_buf_size = 32;
1180 cpm_uart_data.rx_num_fifo = 4;
1181 cpm_uart_data.rx_buf_size = 32;
1182
1183 ret =
1184 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1185 sizeof(struct
1186 fs_uart_platform_info));
1187 if (ret)
1188 goto unreg;
1189 }
1190
1191 return 0;
1192
1193unreg:
1194 platform_device_unregister(cpm_uart_dev);
1195err:
1196 return ret;
1197}
1198
1199arch_initcall(cpm_smc_uart_of_init);
1200
1201#endif /* CONFIG_8xx */
This page took 0.321118 seconds and 5 git commands to generate.