Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6] / arch / powerpc / sysdev / fsl_soc.c
1 /*
2  * FSL SoC setup code
3  *
4  * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5  *
6  * 2006 (c) MontaVista Software, Inc.
7  * Vitaly Bordug <vbordug@ru.mvista.com>
8  *
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
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>
25 #include <linux/of_platform.h>
26 #include <linux/phy.h>
27 #include <linux/phy_fixed.h>
28 #include <linux/spi/spi.h>
29 #include <linux/fsl_devices.h>
30 #include <linux/fs_enet_pd.h>
31 #include <linux/fs_uart_pd.h>
32
33 #include <asm/system.h>
34 #include <asm/atomic.h>
35 #include <asm/io.h>
36 #include <asm/irq.h>
37 #include <asm/time.h>
38 #include <asm/prom.h>
39 #include <sysdev/fsl_soc.h>
40 #include <mm/mmu_decl.h>
41 #include <asm/cpm2.h>
42
43 extern void init_fcc_ioports(struct fs_platform_info*);
44 extern void init_fec_ioports(struct fs_platform_info*);
45 extern void init_smc_ioports(struct fs_uart_platform_info*);
46 static phys_addr_t immrbase = -1;
47
48 phys_addr_t get_immrbase(void)
49 {
50         struct device_node *soc;
51
52         if (immrbase != -1)
53                 return immrbase;
54
55         soc = of_find_node_by_type(NULL, "soc");
56         if (soc) {
57                 int size;
58                 u32 naddr;
59                 const u32 *prop = of_get_property(soc, "#address-cells", &size);
60
61                 if (prop && size == 4)
62                         naddr = *prop;
63                 else
64                         naddr = 2;
65
66                 prop = of_get_property(soc, "ranges", &size);
67                 if (prop)
68                         immrbase = of_translate_address(soc, prop + naddr);
69
70                 of_node_put(soc);
71         }
72
73         return immrbase;
74 }
75
76 EXPORT_SYMBOL(get_immrbase);
77
78 static u32 sysfreq = -1;
79
80 u32 fsl_get_sys_freq(void)
81 {
82         struct device_node *soc;
83         const u32 *prop;
84         int size;
85
86         if (sysfreq != -1)
87                 return sysfreq;
88
89         soc = of_find_node_by_type(NULL, "soc");
90         if (!soc)
91                 return -1;
92
93         prop = of_get_property(soc, "clock-frequency", &size);
94         if (!prop || size != sizeof(*prop) || *prop == 0)
95                 prop = of_get_property(soc, "bus-frequency", &size);
96
97         if (prop && size == sizeof(*prop))
98                 sysfreq = *prop;
99
100         of_node_put(soc);
101         return sysfreq;
102 }
103 EXPORT_SYMBOL(fsl_get_sys_freq);
104
105 #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
106
107 static u32 brgfreq = -1;
108
109 u32 get_brgfreq(void)
110 {
111         struct device_node *node;
112         const unsigned int *prop;
113         int size;
114
115         if (brgfreq != -1)
116                 return brgfreq;
117
118         node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
119         if (node) {
120                 prop = of_get_property(node, "clock-frequency", &size);
121                 if (prop && size == 4)
122                         brgfreq = *prop;
123
124                 of_node_put(node);
125                 return brgfreq;
126         }
127
128         /* Legacy device binding -- will go away when no users are left. */
129         node = of_find_node_by_type(NULL, "cpm");
130         if (!node)
131                 node = of_find_compatible_node(NULL, NULL, "fsl,qe");
132         if (!node)
133                 node = of_find_node_by_type(NULL, "qe");
134
135         if (node) {
136                 prop = of_get_property(node, "brg-frequency", &size);
137                 if (prop && size == 4)
138                         brgfreq = *prop;
139
140                 if (brgfreq == -1 || brgfreq == 0) {
141                         prop = of_get_property(node, "bus-frequency", &size);
142                         if (prop && size == 4)
143                                 brgfreq = *prop / 2;
144                 }
145                 of_node_put(node);
146         }
147
148         return brgfreq;
149 }
150
151 EXPORT_SYMBOL(get_brgfreq);
152
153 static u32 fs_baudrate = -1;
154
155 u32 get_baudrate(void)
156 {
157         struct device_node *node;
158
159         if (fs_baudrate != -1)
160                 return fs_baudrate;
161
162         node = of_find_node_by_type(NULL, "serial");
163         if (node) {
164                 int size;
165                 const unsigned int *prop = of_get_property(node,
166                                 "current-speed", &size);
167
168                 if (prop)
169                         fs_baudrate = *prop;
170                 of_node_put(node);
171         }
172
173         return fs_baudrate;
174 }
175
176 EXPORT_SYMBOL(get_baudrate);
177 #endif /* CONFIG_CPM2 */
178
179 #ifdef CONFIG_FIXED_PHY
180 static int __init of_add_fixed_phys(void)
181 {
182         int ret;
183         struct device_node *np;
184         u32 *fixed_link;
185         struct fixed_phy_status status = {};
186
187         for_each_node_by_name(np, "ethernet") {
188                 fixed_link  = (u32 *)of_get_property(np, "fixed-link", NULL);
189                 if (!fixed_link)
190                         continue;
191
192                 status.link = 1;
193                 status.duplex = fixed_link[1];
194                 status.speed = fixed_link[2];
195                 status.pause = fixed_link[3];
196                 status.asym_pause = fixed_link[4];
197
198                 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
199                 if (ret) {
200                         of_node_put(np);
201                         return ret;
202                 }
203         }
204
205         return 0;
206 }
207 arch_initcall(of_add_fixed_phys);
208 #endif /* CONFIG_FIXED_PHY */
209
210 static int __init gfar_mdio_of_init(void)
211 {
212         struct device_node *np = NULL;
213         struct platform_device *mdio_dev;
214         struct resource res;
215         int ret;
216
217         np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
218
219         /* try the deprecated version */
220         if (!np)
221                 np = of_find_compatible_node(np, "mdio", "gianfar");
222
223         if (np) {
224                 int k;
225                 struct device_node *child = NULL;
226                 struct gianfar_mdio_data mdio_data;
227
228                 memset(&res, 0, sizeof(res));
229                 memset(&mdio_data, 0, sizeof(mdio_data));
230
231                 ret = of_address_to_resource(np, 0, &res);
232                 if (ret)
233                         goto err;
234
235                 mdio_dev =
236                     platform_device_register_simple("fsl-gianfar_mdio",
237                                                     res.start, &res, 1);
238                 if (IS_ERR(mdio_dev)) {
239                         ret = PTR_ERR(mdio_dev);
240                         goto err;
241                 }
242
243                 for (k = 0; k < 32; k++)
244                         mdio_data.irq[k] = PHY_POLL;
245
246                 while ((child = of_get_next_child(np, child)) != NULL) {
247                         int irq = irq_of_parse_and_map(child, 0);
248                         if (irq != NO_IRQ) {
249                                 const u32 *id = of_get_property(child,
250                                                         "reg", NULL);
251                                 mdio_data.irq[*id] = irq;
252                         }
253                 }
254
255                 ret =
256                     platform_device_add_data(mdio_dev, &mdio_data,
257                                              sizeof(struct gianfar_mdio_data));
258                 if (ret)
259                         goto unreg;
260         }
261
262         of_node_put(np);
263         return 0;
264
265 unreg:
266         platform_device_unregister(mdio_dev);
267 err:
268         of_node_put(np);
269         return ret;
270 }
271
272 arch_initcall(gfar_mdio_of_init);
273
274 static const char *gfar_tx_intr = "tx";
275 static const char *gfar_rx_intr = "rx";
276 static const char *gfar_err_intr = "error";
277
278 static int __init gfar_of_init(void)
279 {
280         struct device_node *np;
281         unsigned int i;
282         struct platform_device *gfar_dev;
283         struct resource res;
284         int ret;
285
286         for (np = NULL, i = 0;
287              (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
288              i++) {
289                 struct resource r[4];
290                 struct device_node *phy, *mdio;
291                 struct gianfar_platform_data gfar_data;
292                 const unsigned int *id;
293                 const char *model;
294                 const char *ctype;
295                 const void *mac_addr;
296                 const phandle *ph;
297                 int n_res = 2;
298
299                 memset(r, 0, sizeof(r));
300                 memset(&gfar_data, 0, sizeof(gfar_data));
301
302                 ret = of_address_to_resource(np, 0, &r[0]);
303                 if (ret)
304                         goto err;
305
306                 of_irq_to_resource(np, 0, &r[1]);
307
308                 model = of_get_property(np, "model", NULL);
309
310                 /* If we aren't the FEC we have multiple interrupts */
311                 if (model && strcasecmp(model, "FEC")) {
312                         r[1].name = gfar_tx_intr;
313
314                         r[2].name = gfar_rx_intr;
315                         of_irq_to_resource(np, 1, &r[2]);
316
317                         r[3].name = gfar_err_intr;
318                         of_irq_to_resource(np, 2, &r[3]);
319
320                         n_res += 2;
321                 }
322
323                 gfar_dev =
324                     platform_device_register_simple("fsl-gianfar", i, &r[0],
325                                                     n_res);
326
327                 if (IS_ERR(gfar_dev)) {
328                         ret = PTR_ERR(gfar_dev);
329                         goto err;
330                 }
331
332                 mac_addr = of_get_mac_address(np);
333                 if (mac_addr)
334                         memcpy(gfar_data.mac_addr, mac_addr, 6);
335
336                 if (model && !strcasecmp(model, "TSEC"))
337                         gfar_data.device_flags =
338                             FSL_GIANFAR_DEV_HAS_GIGABIT |
339                             FSL_GIANFAR_DEV_HAS_COALESCE |
340                             FSL_GIANFAR_DEV_HAS_RMON |
341                             FSL_GIANFAR_DEV_HAS_MULTI_INTR;
342                 if (model && !strcasecmp(model, "eTSEC"))
343                         gfar_data.device_flags =
344                             FSL_GIANFAR_DEV_HAS_GIGABIT |
345                             FSL_GIANFAR_DEV_HAS_COALESCE |
346                             FSL_GIANFAR_DEV_HAS_RMON |
347                             FSL_GIANFAR_DEV_HAS_MULTI_INTR |
348                             FSL_GIANFAR_DEV_HAS_CSUM |
349                             FSL_GIANFAR_DEV_HAS_VLAN |
350                             FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
351
352                 ctype = of_get_property(np, "phy-connection-type", NULL);
353
354                 /* We only care about rgmii-id.  The rest are autodetected */
355                 if (ctype && !strcmp(ctype, "rgmii-id"))
356                         gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
357                 else
358                         gfar_data.interface = PHY_INTERFACE_MODE_MII;
359
360                 ph = of_get_property(np, "phy-handle", NULL);
361                 if (ph == NULL) {
362                         u32 *fixed_link;
363
364                         fixed_link = (u32 *)of_get_property(np, "fixed-link",
365                                                            NULL);
366                         if (!fixed_link) {
367                                 ret = -ENODEV;
368                                 goto unreg;
369                         }
370
371                         snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
372                         gfar_data.phy_id = fixed_link[0];
373                 } else {
374                         phy = of_find_node_by_phandle(*ph);
375
376                         if (phy == NULL) {
377                                 ret = -ENODEV;
378                                 goto unreg;
379                         }
380
381                         mdio = of_get_parent(phy);
382
383                         id = of_get_property(phy, "reg", NULL);
384                         ret = of_address_to_resource(mdio, 0, &res);
385                         if (ret) {
386                                 of_node_put(phy);
387                                 of_node_put(mdio);
388                                 goto unreg;
389                         }
390
391                         gfar_data.phy_id = *id;
392                         snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%x",
393                                         res.start);
394
395                         of_node_put(phy);
396                         of_node_put(mdio);
397                 }
398
399                 ret =
400                     platform_device_add_data(gfar_dev, &gfar_data,
401                                              sizeof(struct
402                                                     gianfar_platform_data));
403                 if (ret)
404                         goto unreg;
405         }
406
407         return 0;
408
409 unreg:
410         platform_device_unregister(gfar_dev);
411 err:
412         return ret;
413 }
414
415 arch_initcall(gfar_of_init);
416
417 #ifdef CONFIG_I2C_BOARDINFO
418 #include <linux/i2c.h>
419 struct i2c_driver_device {
420         char    *of_device;
421         char    *i2c_driver;
422         char    *i2c_type;
423 };
424
425 static struct i2c_driver_device i2c_devices[] __initdata = {
426         {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
427         {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
428         {"ricoh,rv5c386",  "rtc-rs5c372", "rv5c386",},
429         {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
430         {"dallas,ds1307",  "rtc-ds1307",  "ds1307",},
431         {"dallas,ds1337",  "rtc-ds1307",  "ds1337",},
432         {"dallas,ds1338",  "rtc-ds1307",  "ds1338",},
433         {"dallas,ds1339",  "rtc-ds1307",  "ds1339",},
434         {"dallas,ds1340",  "rtc-ds1307",  "ds1340",},
435         {"stm,m41t00",     "rtc-ds1307",  "m41t00"},
436         {"dallas,ds1374",  "rtc-ds1374",  "rtc-ds1374",},
437 };
438
439 static int __init of_find_i2c_driver(struct device_node *node,
440                                      struct i2c_board_info *info)
441 {
442         int i;
443
444         for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
445                 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
446                         continue;
447                 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
448                             KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
449                     strlcpy(info->type, i2c_devices[i].i2c_type,
450                             I2C_NAME_SIZE) >= I2C_NAME_SIZE)
451                         return -ENOMEM;
452                 return 0;
453         }
454         return -ENODEV;
455 }
456
457 static void __init of_register_i2c_devices(struct device_node *adap_node,
458                                            int bus_num)
459 {
460         struct device_node *node = NULL;
461
462         while ((node = of_get_next_child(adap_node, node))) {
463                 struct i2c_board_info info = {};
464                 const u32 *addr;
465                 int len;
466
467                 addr = of_get_property(node, "reg", &len);
468                 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
469                         printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
470                         continue;
471                 }
472
473                 info.irq = irq_of_parse_and_map(node, 0);
474                 if (info.irq == NO_IRQ)
475                         info.irq = -1;
476
477                 if (of_find_i2c_driver(node, &info) < 0)
478                         continue;
479
480                 info.addr = *addr;
481
482                 i2c_register_board_info(bus_num, &info, 1);
483         }
484 }
485
486 static int __init fsl_i2c_of_init(void)
487 {
488         struct device_node *np;
489         unsigned int i = 0;
490         struct platform_device *i2c_dev;
491         int ret;
492
493         for_each_compatible_node(np, NULL, "fsl-i2c") {
494                 struct resource r[2];
495                 struct fsl_i2c_platform_data i2c_data;
496                 const unsigned char *flags = NULL;
497
498                 memset(&r, 0, sizeof(r));
499                 memset(&i2c_data, 0, sizeof(i2c_data));
500
501                 ret = of_address_to_resource(np, 0, &r[0]);
502                 if (ret)
503                         goto err;
504
505                 of_irq_to_resource(np, 0, &r[1]);
506
507                 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
508                 if (IS_ERR(i2c_dev)) {
509                         ret = PTR_ERR(i2c_dev);
510                         goto err;
511                 }
512
513                 i2c_data.device_flags = 0;
514                 flags = of_get_property(np, "dfsrr", NULL);
515                 if (flags)
516                         i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
517
518                 flags = of_get_property(np, "fsl5200-clocking", NULL);
519                 if (flags)
520                         i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
521
522                 ret =
523                     platform_device_add_data(i2c_dev, &i2c_data,
524                                              sizeof(struct
525                                                     fsl_i2c_platform_data));
526                 if (ret)
527                         goto unreg;
528
529                 of_register_i2c_devices(np, i++);
530         }
531
532         return 0;
533
534 unreg:
535         platform_device_unregister(i2c_dev);
536 err:
537         return ret;
538 }
539
540 arch_initcall(fsl_i2c_of_init);
541 #endif
542
543 #ifdef CONFIG_PPC_83xx
544 static int __init mpc83xx_wdt_init(void)
545 {
546         struct resource r;
547         struct device_node *np;
548         struct platform_device *dev;
549         u32 freq = fsl_get_sys_freq();
550         int ret;
551
552         np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
553
554         if (!np) {
555                 ret = -ENODEV;
556                 goto nodev;
557         }
558
559         memset(&r, 0, sizeof(r));
560
561         ret = of_address_to_resource(np, 0, &r);
562         if (ret)
563                 goto err;
564
565         dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
566         if (IS_ERR(dev)) {
567                 ret = PTR_ERR(dev);
568                 goto err;
569         }
570
571         ret = platform_device_add_data(dev, &freq, sizeof(freq));
572         if (ret)
573                 goto unreg;
574
575         of_node_put(np);
576         return 0;
577
578 unreg:
579         platform_device_unregister(dev);
580 err:
581         of_node_put(np);
582 nodev:
583         return ret;
584 }
585
586 arch_initcall(mpc83xx_wdt_init);
587 #endif
588
589 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
590 {
591         if (!phy_type)
592                 return FSL_USB2_PHY_NONE;
593         if (!strcasecmp(phy_type, "ulpi"))
594                 return FSL_USB2_PHY_ULPI;
595         if (!strcasecmp(phy_type, "utmi"))
596                 return FSL_USB2_PHY_UTMI;
597         if (!strcasecmp(phy_type, "utmi_wide"))
598                 return FSL_USB2_PHY_UTMI_WIDE;
599         if (!strcasecmp(phy_type, "serial"))
600                 return FSL_USB2_PHY_SERIAL;
601
602         return FSL_USB2_PHY_NONE;
603 }
604
605 static int __init fsl_usb_of_init(void)
606 {
607         struct device_node *np;
608         unsigned int i = 0;
609         struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
610                 *usb_dev_dr_client = NULL;
611         int ret;
612
613         for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
614                 struct resource r[2];
615                 struct fsl_usb2_platform_data usb_data;
616                 const unsigned char *prop = NULL;
617
618                 memset(&r, 0, sizeof(r));
619                 memset(&usb_data, 0, sizeof(usb_data));
620
621                 ret = of_address_to_resource(np, 0, &r[0]);
622                 if (ret)
623                         goto err;
624
625                 of_irq_to_resource(np, 0, &r[1]);
626
627                 usb_dev_mph =
628                     platform_device_register_simple("fsl-ehci", i, r, 2);
629                 if (IS_ERR(usb_dev_mph)) {
630                         ret = PTR_ERR(usb_dev_mph);
631                         goto err;
632                 }
633
634                 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
635                 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
636
637                 usb_data.operating_mode = FSL_USB2_MPH_HOST;
638
639                 prop = of_get_property(np, "port0", NULL);
640                 if (prop)
641                         usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
642
643                 prop = of_get_property(np, "port1", NULL);
644                 if (prop)
645                         usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
646
647                 prop = of_get_property(np, "phy_type", NULL);
648                 usb_data.phy_mode = determine_usb_phy(prop);
649
650                 ret =
651                     platform_device_add_data(usb_dev_mph, &usb_data,
652                                              sizeof(struct
653                                                     fsl_usb2_platform_data));
654                 if (ret)
655                         goto unreg_mph;
656                 i++;
657         }
658
659         for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
660                 struct resource r[2];
661                 struct fsl_usb2_platform_data usb_data;
662                 const unsigned char *prop = NULL;
663
664                 memset(&r, 0, sizeof(r));
665                 memset(&usb_data, 0, sizeof(usb_data));
666
667                 ret = of_address_to_resource(np, 0, &r[0]);
668                 if (ret)
669                         goto unreg_mph;
670
671                 of_irq_to_resource(np, 0, &r[1]);
672
673                 prop = of_get_property(np, "dr_mode", NULL);
674
675                 if (!prop || !strcmp(prop, "host")) {
676                         usb_data.operating_mode = FSL_USB2_DR_HOST;
677                         usb_dev_dr_host = platform_device_register_simple(
678                                         "fsl-ehci", i, r, 2);
679                         if (IS_ERR(usb_dev_dr_host)) {
680                                 ret = PTR_ERR(usb_dev_dr_host);
681                                 goto err;
682                         }
683                 } else if (prop && !strcmp(prop, "peripheral")) {
684                         usb_data.operating_mode = FSL_USB2_DR_DEVICE;
685                         usb_dev_dr_client = platform_device_register_simple(
686                                         "fsl-usb2-udc", i, r, 2);
687                         if (IS_ERR(usb_dev_dr_client)) {
688                                 ret = PTR_ERR(usb_dev_dr_client);
689                                 goto err;
690                         }
691                 } else if (prop && !strcmp(prop, "otg")) {
692                         usb_data.operating_mode = FSL_USB2_DR_OTG;
693                         usb_dev_dr_host = platform_device_register_simple(
694                                         "fsl-ehci", i, r, 2);
695                         if (IS_ERR(usb_dev_dr_host)) {
696                                 ret = PTR_ERR(usb_dev_dr_host);
697                                 goto err;
698                         }
699                         usb_dev_dr_client = platform_device_register_simple(
700                                         "fsl-usb2-udc", i, r, 2);
701                         if (IS_ERR(usb_dev_dr_client)) {
702                                 ret = PTR_ERR(usb_dev_dr_client);
703                                 goto err;
704                         }
705                 } else {
706                         ret = -EINVAL;
707                         goto err;
708                 }
709
710                 prop = of_get_property(np, "phy_type", NULL);
711                 usb_data.phy_mode = determine_usb_phy(prop);
712
713                 if (usb_dev_dr_host) {
714                         usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
715                         usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
716                                 dev.coherent_dma_mask;
717                         if ((ret = platform_device_add_data(usb_dev_dr_host,
718                                                 &usb_data, sizeof(struct
719                                                 fsl_usb2_platform_data))))
720                                 goto unreg_dr;
721                 }
722                 if (usb_dev_dr_client) {
723                         usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
724                         usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
725                                 dev.coherent_dma_mask;
726                         if ((ret = platform_device_add_data(usb_dev_dr_client,
727                                                 &usb_data, sizeof(struct
728                                                 fsl_usb2_platform_data))))
729                                 goto unreg_dr;
730                 }
731                 i++;
732         }
733         return 0;
734
735 unreg_dr:
736         if (usb_dev_dr_host)
737                 platform_device_unregister(usb_dev_dr_host);
738         if (usb_dev_dr_client)
739                 platform_device_unregister(usb_dev_dr_client);
740 unreg_mph:
741         if (usb_dev_mph)
742                 platform_device_unregister(usb_dev_mph);
743 err:
744         return ret;
745 }
746
747 arch_initcall(fsl_usb_of_init);
748
749 static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
750                                    struct spi_board_info *board_infos,
751                                    unsigned int num_board_infos,
752                                    void (*activate_cs)(u8 cs, u8 polarity),
753                                    void (*deactivate_cs)(u8 cs, u8 polarity))
754 {
755         struct device_node *np;
756         unsigned int i = 0;
757
758         for_each_compatible_node(np, type, compatible) {
759                 int ret;
760                 unsigned int j;
761                 const void *prop;
762                 struct resource res[2];
763                 struct platform_device *pdev;
764                 struct fsl_spi_platform_data pdata = {
765                         .activate_cs = activate_cs,
766                         .deactivate_cs = deactivate_cs,
767                 };
768
769                 memset(res, 0, sizeof(res));
770
771                 pdata.sysclk = sysclk;
772
773                 prop = of_get_property(np, "reg", NULL);
774                 if (!prop)
775                         goto err;
776                 pdata.bus_num = *(u32 *)prop;
777
778                 prop = of_get_property(np, "cell-index", NULL);
779                 if (prop)
780                         i = *(u32 *)prop;
781
782                 prop = of_get_property(np, "mode", NULL);
783                 if (prop && !strcmp(prop, "cpu-qe"))
784                         pdata.qe_mode = 1;
785
786                 for (j = 0; j < num_board_infos; j++) {
787                         if (board_infos[j].bus_num == pdata.bus_num)
788                                 pdata.max_chipselect++;
789                 }
790
791                 if (!pdata.max_chipselect)
792                         continue;
793
794                 ret = of_address_to_resource(np, 0, &res[0]);
795                 if (ret)
796                         goto err;
797
798                 ret = of_irq_to_resource(np, 0, &res[1]);
799                 if (ret == NO_IRQ)
800                         goto err;
801
802                 pdev = platform_device_alloc("mpc83xx_spi", i);
803                 if (!pdev)
804                         goto err;
805
806                 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
807                 if (ret)
808                         goto unreg;
809
810                 ret = platform_device_add_resources(pdev, res,
811                                                     ARRAY_SIZE(res));
812                 if (ret)
813                         goto unreg;
814
815                 ret = platform_device_add(pdev);
816                 if (ret)
817                         goto unreg;
818
819                 goto next;
820 unreg:
821                 platform_device_del(pdev);
822 err:
823                 pr_err("%s: registration failed\n", np->full_name);
824 next:
825                 i++;
826         }
827
828         return i;
829 }
830
831 int __init fsl_spi_init(struct spi_board_info *board_infos,
832                         unsigned int num_board_infos,
833                         void (*activate_cs)(u8 cs, u8 polarity),
834                         void (*deactivate_cs)(u8 cs, u8 polarity))
835 {
836         u32 sysclk = -1;
837         int ret;
838
839 #ifdef CONFIG_QUICC_ENGINE
840         /* SPI controller is either clocked from QE or SoC clock */
841         sysclk = get_brgfreq();
842 #endif
843         if (sysclk == -1) {
844                 sysclk = fsl_get_sys_freq();
845                 if (sysclk == -1)
846                         return -ENODEV;
847         }
848
849         ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
850                                num_board_infos, activate_cs, deactivate_cs);
851         if (!ret)
852                 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
853                                  num_board_infos, activate_cs, deactivate_cs);
854
855         return spi_register_board_info(board_infos, num_board_infos);
856 }
857
858 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
859 static __be32 __iomem *rstcr;
860
861 static int __init setup_rstcr(void)
862 {
863         struct device_node *np;
864         np = of_find_node_by_name(NULL, "global-utilities");
865         if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
866                 const u32 *prop = of_get_property(np, "reg", NULL);
867                 if (prop) {
868                         /* map reset control register
869                          * 0xE00B0 is offset of reset control register
870                          */
871                         rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
872                         if (!rstcr)
873                                 printk (KERN_EMERG "Error: reset control "
874                                                 "register not mapped!\n");
875                 }
876         } else
877                 printk (KERN_INFO "rstcr compatible register does not exist!\n");
878         if (np)
879                 of_node_put(np);
880         return 0;
881 }
882
883 arch_initcall(setup_rstcr);
884
885 void fsl_rstcr_restart(char *cmd)
886 {
887         local_irq_disable();
888         if (rstcr)
889                 /* set reset control register */
890                 out_be32(rstcr, 0x2);   /* HRESET_REQ */
891
892         while (1) ;
893 }
894 #endif