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