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