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