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