Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[sfrench/cifs-2.6.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/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, struct i2c_board_info *info)
324 {
325         int i;
326
327         for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
328                 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
329                         continue;
330                 strncpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN);
331                 strncpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE);
332                 return 0;
333         }
334         return -ENODEV;
335 }
336
337 static void __init of_register_i2c_devices(struct device_node *adap_node, int bus_num)
338 {
339         struct device_node *node = NULL;
340
341         while ((node = of_get_next_child(adap_node, node))) {
342                 struct i2c_board_info info;
343                 const u32 *addr;
344                 int len;
345
346                 addr = of_get_property(node, "reg", &len);
347                 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
348                         printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n");
349                         continue;
350                 }
351
352                 info.irq = irq_of_parse_and_map(node, 0);
353                 if (info.irq == NO_IRQ)
354                         info.irq = -1;
355
356                 if (of_find_i2c_driver(node, &info) < 0)
357                         continue;
358
359                 info.platform_data = NULL;
360                 info.addr = *addr;
361
362                 i2c_register_board_info(bus_num, &info, 1);
363         }
364 }
365
366 static int __init fsl_i2c_of_init(void)
367 {
368         struct device_node *np;
369         unsigned int i;
370         struct platform_device *i2c_dev;
371         int ret;
372
373         for (np = NULL, i = 0;
374              (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
375              i++) {
376                 struct resource r[2];
377                 struct fsl_i2c_platform_data i2c_data;
378                 const unsigned char *flags = NULL;
379
380                 memset(&r, 0, sizeof(r));
381                 memset(&i2c_data, 0, sizeof(i2c_data));
382
383                 ret = of_address_to_resource(np, 0, &r[0]);
384                 if (ret)
385                         goto err;
386
387                 of_irq_to_resource(np, 0, &r[1]);
388
389                 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
390                 if (IS_ERR(i2c_dev)) {
391                         ret = PTR_ERR(i2c_dev);
392                         goto err;
393                 }
394
395                 i2c_data.device_flags = 0;
396                 flags = of_get_property(np, "dfsrr", NULL);
397                 if (flags)
398                         i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
399
400                 flags = of_get_property(np, "fsl5200-clocking", NULL);
401                 if (flags)
402                         i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
403
404                 ret =
405                     platform_device_add_data(i2c_dev, &i2c_data,
406                                              sizeof(struct
407                                                     fsl_i2c_platform_data));
408                 if (ret)
409                         goto unreg;
410
411                 of_register_i2c_devices(np, i);
412         }
413
414         return 0;
415
416 unreg:
417         platform_device_unregister(i2c_dev);
418 err:
419         return ret;
420 }
421
422 arch_initcall(fsl_i2c_of_init);
423 #endif
424
425 #ifdef CONFIG_PPC_83xx
426 static int __init mpc83xx_wdt_init(void)
427 {
428         struct resource r;
429         struct device_node *soc, *np;
430         struct platform_device *dev;
431         const unsigned int *freq;
432         int ret;
433
434         np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
435
436         if (!np) {
437                 ret = -ENODEV;
438                 goto nodev;
439         }
440
441         soc = of_find_node_by_type(NULL, "soc");
442
443         if (!soc) {
444                 ret = -ENODEV;
445                 goto nosoc;
446         }
447
448         freq = of_get_property(soc, "bus-frequency", NULL);
449         if (!freq) {
450                 ret = -ENODEV;
451                 goto err;
452         }
453
454         memset(&r, 0, sizeof(r));
455
456         ret = of_address_to_resource(np, 0, &r);
457         if (ret)
458                 goto err;
459
460         dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
461         if (IS_ERR(dev)) {
462                 ret = PTR_ERR(dev);
463                 goto err;
464         }
465
466         ret = platform_device_add_data(dev, freq, sizeof(int));
467         if (ret)
468                 goto unreg;
469
470         of_node_put(soc);
471         of_node_put(np);
472
473         return 0;
474
475 unreg:
476         platform_device_unregister(dev);
477 err:
478         of_node_put(soc);
479 nosoc:
480         of_node_put(np);
481 nodev:
482         return ret;
483 }
484
485 arch_initcall(mpc83xx_wdt_init);
486 #endif
487
488 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
489 {
490         if (!phy_type)
491                 return FSL_USB2_PHY_NONE;
492         if (!strcasecmp(phy_type, "ulpi"))
493                 return FSL_USB2_PHY_ULPI;
494         if (!strcasecmp(phy_type, "utmi"))
495                 return FSL_USB2_PHY_UTMI;
496         if (!strcasecmp(phy_type, "utmi_wide"))
497                 return FSL_USB2_PHY_UTMI_WIDE;
498         if (!strcasecmp(phy_type, "serial"))
499                 return FSL_USB2_PHY_SERIAL;
500
501         return FSL_USB2_PHY_NONE;
502 }
503
504 static int __init fsl_usb_of_init(void)
505 {
506         struct device_node *np;
507         unsigned int i;
508         struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
509                 *usb_dev_dr_client = NULL;
510         int ret;
511
512         for (np = NULL, i = 0;
513              (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
514              i++) {
515                 struct resource r[2];
516                 struct fsl_usb2_platform_data usb_data;
517                 const unsigned char *prop = NULL;
518
519                 memset(&r, 0, sizeof(r));
520                 memset(&usb_data, 0, sizeof(usb_data));
521
522                 ret = of_address_to_resource(np, 0, &r[0]);
523                 if (ret)
524                         goto err;
525
526                 of_irq_to_resource(np, 0, &r[1]);
527
528                 usb_dev_mph =
529                     platform_device_register_simple("fsl-ehci", i, r, 2);
530                 if (IS_ERR(usb_dev_mph)) {
531                         ret = PTR_ERR(usb_dev_mph);
532                         goto err;
533                 }
534
535                 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
536                 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
537
538                 usb_data.operating_mode = FSL_USB2_MPH_HOST;
539
540                 prop = of_get_property(np, "port0", NULL);
541                 if (prop)
542                         usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
543
544                 prop = of_get_property(np, "port1", NULL);
545                 if (prop)
546                         usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
547
548                 prop = of_get_property(np, "phy_type", NULL);
549                 usb_data.phy_mode = determine_usb_phy(prop);
550
551                 ret =
552                     platform_device_add_data(usb_dev_mph, &usb_data,
553                                              sizeof(struct
554                                                     fsl_usb2_platform_data));
555                 if (ret)
556                         goto unreg_mph;
557         }
558
559         for (np = NULL;
560              (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
561              i++) {
562                 struct resource r[2];
563                 struct fsl_usb2_platform_data usb_data;
564                 const unsigned char *prop = NULL;
565
566                 memset(&r, 0, sizeof(r));
567                 memset(&usb_data, 0, sizeof(usb_data));
568
569                 ret = of_address_to_resource(np, 0, &r[0]);
570                 if (ret)
571                         goto unreg_mph;
572
573                 of_irq_to_resource(np, 0, &r[1]);
574
575                 prop = of_get_property(np, "dr_mode", NULL);
576
577                 if (!prop || !strcmp(prop, "host")) {
578                         usb_data.operating_mode = FSL_USB2_DR_HOST;
579                         usb_dev_dr_host = platform_device_register_simple(
580                                         "fsl-ehci", i, r, 2);
581                         if (IS_ERR(usb_dev_dr_host)) {
582                                 ret = PTR_ERR(usb_dev_dr_host);
583                                 goto err;
584                         }
585                 } else if (prop && !strcmp(prop, "peripheral")) {
586                         usb_data.operating_mode = FSL_USB2_DR_DEVICE;
587                         usb_dev_dr_client = platform_device_register_simple(
588                                         "fsl-usb2-udc", i, r, 2);
589                         if (IS_ERR(usb_dev_dr_client)) {
590                                 ret = PTR_ERR(usb_dev_dr_client);
591                                 goto err;
592                         }
593                 } else if (prop && !strcmp(prop, "otg")) {
594                         usb_data.operating_mode = FSL_USB2_DR_OTG;
595                         usb_dev_dr_host = platform_device_register_simple(
596                                         "fsl-ehci", i, r, 2);
597                         if (IS_ERR(usb_dev_dr_host)) {
598                                 ret = PTR_ERR(usb_dev_dr_host);
599                                 goto err;
600                         }
601                         usb_dev_dr_client = platform_device_register_simple(
602                                         "fsl-usb2-udc", i, r, 2);
603                         if (IS_ERR(usb_dev_dr_client)) {
604                                 ret = PTR_ERR(usb_dev_dr_client);
605                                 goto err;
606                         }
607                 } else {
608                         ret = -EINVAL;
609                         goto err;
610                 }
611
612                 prop = of_get_property(np, "phy_type", NULL);
613                 usb_data.phy_mode = determine_usb_phy(prop);
614
615                 if (usb_dev_dr_host) {
616                         usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
617                         usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
618                                 dev.coherent_dma_mask;
619                         if ((ret = platform_device_add_data(usb_dev_dr_host,
620                                                 &usb_data, sizeof(struct
621                                                 fsl_usb2_platform_data))))
622                                 goto unreg_dr;
623                 }
624                 if (usb_dev_dr_client) {
625                         usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
626                         usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
627                                 dev.coherent_dma_mask;
628                         if ((ret = platform_device_add_data(usb_dev_dr_client,
629                                                 &usb_data, sizeof(struct
630                                                 fsl_usb2_platform_data))))
631                                 goto unreg_dr;
632                 }
633         }
634         return 0;
635
636 unreg_dr:
637         if (usb_dev_dr_host)
638                 platform_device_unregister(usb_dev_dr_host);
639         if (usb_dev_dr_client)
640                 platform_device_unregister(usb_dev_dr_client);
641 unreg_mph:
642         if (usb_dev_mph)
643                 platform_device_unregister(usb_dev_mph);
644 err:
645         return ret;
646 }
647
648 arch_initcall(fsl_usb_of_init);
649
650 #ifdef CONFIG_CPM2
651
652 extern void init_scc_ioports(struct fs_uart_platform_info*);
653
654 static const char fcc_regs[] = "fcc_regs";
655 static const char fcc_regs_c[] = "fcc_regs_c";
656 static const char fcc_pram[] = "fcc_pram";
657 static char bus_id[9][BUS_ID_SIZE];
658
659 static int __init fs_enet_of_init(void)
660 {
661         struct device_node *np;
662         unsigned int i;
663         struct platform_device *fs_enet_dev;
664         struct resource res;
665         int ret;
666
667         for (np = NULL, i = 0;
668              (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
669              i++) {
670                 struct resource r[4];
671                 struct device_node *phy, *mdio;
672                 struct fs_platform_info fs_enet_data;
673                 const unsigned int *id, *phy_addr, *phy_irq;
674                 const void *mac_addr;
675                 const phandle *ph;
676                 const char *model;
677
678                 memset(r, 0, sizeof(r));
679                 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
680
681                 ret = of_address_to_resource(np, 0, &r[0]);
682                 if (ret)
683                         goto err;
684                 r[0].name = fcc_regs;
685
686                 ret = of_address_to_resource(np, 1, &r[1]);
687                 if (ret)
688                         goto err;
689                 r[1].name = fcc_pram;
690
691                 ret = of_address_to_resource(np, 2, &r[2]);
692                 if (ret)
693                         goto err;
694                 r[2].name = fcc_regs_c;
695                 fs_enet_data.fcc_regs_c = r[2].start;
696
697                 of_irq_to_resource(np, 0, &r[3]);
698
699                 fs_enet_dev =
700                     platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
701
702                 if (IS_ERR(fs_enet_dev)) {
703                         ret = PTR_ERR(fs_enet_dev);
704                         goto err;
705                 }
706
707                 model = of_get_property(np, "model", NULL);
708                 if (model == NULL) {
709                         ret = -ENODEV;
710                         goto unreg;
711                 }
712
713                 mac_addr = of_get_mac_address(np);
714                 if (mac_addr)
715                         memcpy(fs_enet_data.macaddr, mac_addr, 6);
716
717                 ph = of_get_property(np, "phy-handle", NULL);
718                 phy = of_find_node_by_phandle(*ph);
719
720                 if (phy == NULL) {
721                         ret = -ENODEV;
722                         goto unreg;
723                 }
724
725                 phy_addr = of_get_property(phy, "reg", NULL);
726                 fs_enet_data.phy_addr = *phy_addr;
727
728                 phy_irq = of_get_property(phy, "interrupts", NULL);
729
730                 id = of_get_property(np, "device-id", NULL);
731                 fs_enet_data.fs_no = *id;
732                 strcpy(fs_enet_data.fs_type, model);
733
734                 mdio = of_get_parent(phy);
735                 ret = of_address_to_resource(mdio, 0, &res);
736                 if (ret) {
737                         of_node_put(phy);
738                         of_node_put(mdio);
739                         goto unreg;
740                 }
741
742                 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
743                                                 "rx-clock", NULL));
744                 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
745                                                 "tx-clock", NULL));
746
747                 if (strstr(model, "FCC")) {
748                         int fcc_index = *id - 1;
749                         const unsigned char *mdio_bb_prop;
750
751                         fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
752                         fs_enet_data.rx_ring = 32;
753                         fs_enet_data.tx_ring = 32;
754                         fs_enet_data.rx_copybreak = 240;
755                         fs_enet_data.use_napi = 0;
756                         fs_enet_data.napi_weight = 17;
757                         fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
758                         fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
759                         fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
760
761                         snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
762                                                         (u32)res.start, fs_enet_data.phy_addr);
763                         fs_enet_data.bus_id = (char*)&bus_id[(*id)];
764                         fs_enet_data.init_ioports = init_fcc_ioports;
765
766                         mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
767                         if (mdio_bb_prop) {
768                                 struct platform_device *fs_enet_mdio_bb_dev;
769                                 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
770
771                                 fs_enet_mdio_bb_dev =
772                                         platform_device_register_simple("fsl-bb-mdio",
773                                                         i, NULL, 0);
774                                 memset(&fs_enet_mdio_bb_data, 0,
775                                                 sizeof(struct fs_mii_bb_platform_info));
776                                 fs_enet_mdio_bb_data.mdio_dat.bit =
777                                         mdio_bb_prop[0];
778                                 fs_enet_mdio_bb_data.mdio_dir.bit =
779                                         mdio_bb_prop[1];
780                                 fs_enet_mdio_bb_data.mdc_dat.bit =
781                                         mdio_bb_prop[2];
782                                 fs_enet_mdio_bb_data.mdio_port =
783                                         mdio_bb_prop[3];
784                                 fs_enet_mdio_bb_data.mdc_port =
785                                         mdio_bb_prop[4];
786                                 fs_enet_mdio_bb_data.delay =
787                                         mdio_bb_prop[5];
788
789                                 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
790                                 fs_enet_mdio_bb_data.irq[1] = -1;
791                                 fs_enet_mdio_bb_data.irq[2] = -1;
792                                 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
793                                 fs_enet_mdio_bb_data.irq[31] = -1;
794
795                                 fs_enet_mdio_bb_data.mdio_dat.offset =
796                                         (u32)&cpm2_immr->im_ioport.iop_pdatc;
797                                 fs_enet_mdio_bb_data.mdio_dir.offset =
798                                         (u32)&cpm2_immr->im_ioport.iop_pdirc;
799                                 fs_enet_mdio_bb_data.mdc_dat.offset =
800                                         (u32)&cpm2_immr->im_ioport.iop_pdatc;
801
802                                 ret = platform_device_add_data(
803                                                 fs_enet_mdio_bb_dev,
804                                                 &fs_enet_mdio_bb_data,
805                                                 sizeof(struct fs_mii_bb_platform_info));
806                                 if (ret)
807                                         goto unreg;
808                         }
809
810                         of_node_put(phy);
811                         of_node_put(mdio);
812
813                         ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
814                                                      sizeof(struct
815                                                             fs_platform_info));
816                         if (ret)
817                                 goto unreg;
818                 }
819         }
820         return 0;
821
822 unreg:
823         platform_device_unregister(fs_enet_dev);
824 err:
825         return ret;
826 }
827
828 arch_initcall(fs_enet_of_init);
829
830 static const char scc_regs[] = "regs";
831 static const char scc_pram[] = "pram";
832
833 static int __init cpm_uart_of_init(void)
834 {
835         struct device_node *np;
836         unsigned int i;
837         struct platform_device *cpm_uart_dev;
838         int ret;
839
840         for (np = NULL, i = 0;
841              (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
842              i++) {
843                 struct resource r[3];
844                 struct fs_uart_platform_info cpm_uart_data;
845                 const int *id;
846                 const char *model;
847
848                 memset(r, 0, sizeof(r));
849                 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
850
851                 ret = of_address_to_resource(np, 0, &r[0]);
852                 if (ret)
853                         goto err;
854
855                 r[0].name = scc_regs;
856
857                 ret = of_address_to_resource(np, 1, &r[1]);
858                 if (ret)
859                         goto err;
860                 r[1].name = scc_pram;
861
862                 of_irq_to_resource(np, 0, &r[2]);
863
864                 cpm_uart_dev =
865                     platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
866
867                 if (IS_ERR(cpm_uart_dev)) {
868                         ret = PTR_ERR(cpm_uart_dev);
869                         goto err;
870                 }
871
872                 id = of_get_property(np, "device-id", NULL);
873                 cpm_uart_data.fs_no = *id;
874
875                 model = of_get_property(np, "model", NULL);
876                 strcpy(cpm_uart_data.fs_type, model);
877
878                 cpm_uart_data.uart_clk = ppc_proc_freq;
879
880                 cpm_uart_data.tx_num_fifo = 4;
881                 cpm_uart_data.tx_buf_size = 32;
882                 cpm_uart_data.rx_num_fifo = 4;
883                 cpm_uart_data.rx_buf_size = 32;
884                 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
885                                                 "rx-clock", NULL));
886                 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
887                                                 "tx-clock", NULL));
888
889                 ret =
890                     platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
891                                              sizeof(struct
892                                                     fs_uart_platform_info));
893                 if (ret)
894                         goto unreg;
895         }
896
897         return 0;
898
899 unreg:
900         platform_device_unregister(cpm_uart_dev);
901 err:
902         return ret;
903 }
904
905 arch_initcall(cpm_uart_of_init);
906 #endif /* CONFIG_CPM2 */
907
908 #ifdef CONFIG_8xx
909
910 extern void init_scc_ioports(struct fs_platform_info*);
911 extern int platform_device_skip(const char *model, int id);
912
913 static int __init fs_enet_mdio_of_init(void)
914 {
915         struct device_node *np;
916         unsigned int i;
917         struct platform_device *mdio_dev;
918         struct resource res;
919         int ret;
920
921         for (np = NULL, i = 0;
922              (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
923              i++) {
924                 struct fs_mii_fec_platform_info mdio_data;
925
926                 memset(&res, 0, sizeof(res));
927                 memset(&mdio_data, 0, sizeof(mdio_data));
928
929                 ret = of_address_to_resource(np, 0, &res);
930                 if (ret)
931                         goto err;
932
933                 mdio_dev =
934                     platform_device_register_simple("fsl-cpm-fec-mdio",
935                                                     res.start, &res, 1);
936                 if (IS_ERR(mdio_dev)) {
937                         ret = PTR_ERR(mdio_dev);
938                         goto err;
939                 }
940
941                 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
942
943                 ret =
944                     platform_device_add_data(mdio_dev, &mdio_data,
945                                              sizeof(struct fs_mii_fec_platform_info));
946                 if (ret)
947                         goto unreg;
948         }
949         return 0;
950
951 unreg:
952         platform_device_unregister(mdio_dev);
953 err:
954         return ret;
955 }
956
957 arch_initcall(fs_enet_mdio_of_init);
958
959 static const char *enet_regs = "regs";
960 static const char *enet_pram = "pram";
961 static const char *enet_irq = "interrupt";
962 static char bus_id[9][BUS_ID_SIZE];
963
964 static int __init fs_enet_of_init(void)
965 {
966         struct device_node *np;
967         unsigned int i;
968         struct platform_device *fs_enet_dev = NULL;
969         struct resource res;
970         int ret;
971
972         for (np = NULL, i = 0;
973              (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
974              i++) {
975                 struct resource r[4];
976                 struct device_node *phy = NULL, *mdio = NULL;
977                 struct fs_platform_info fs_enet_data;
978                 const unsigned int *id;
979                 const unsigned int *phy_addr;
980                 const void *mac_addr;
981                 const phandle *ph;
982                 const char *model;
983
984                 memset(r, 0, sizeof(r));
985                 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
986
987                 model = of_get_property(np, "model", NULL);
988                 if (model == NULL) {
989                         ret = -ENODEV;
990                         goto unreg;
991                 }
992
993                 id = of_get_property(np, "device-id", NULL);
994                 fs_enet_data.fs_no = *id;
995
996                 if (platform_device_skip(model, *id))
997                         continue;
998
999                 ret = of_address_to_resource(np, 0, &r[0]);
1000                 if (ret)
1001                         goto err;
1002                 r[0].name = enet_regs;
1003
1004                 mac_addr = of_get_mac_address(np);
1005                 if (mac_addr)
1006                         memcpy(fs_enet_data.macaddr, mac_addr, 6);
1007
1008                 ph = of_get_property(np, "phy-handle", NULL);
1009                 if (ph != NULL)
1010                         phy = of_find_node_by_phandle(*ph);
1011
1012                 if (phy != NULL) {
1013                         phy_addr = of_get_property(phy, "reg", NULL);
1014                         fs_enet_data.phy_addr = *phy_addr;
1015                         fs_enet_data.has_phy = 1;
1016
1017                         mdio = of_get_parent(phy);
1018                         ret = of_address_to_resource(mdio, 0, &res);
1019                         if (ret) {
1020                                 of_node_put(phy);
1021                                 of_node_put(mdio);
1022                                 goto unreg;
1023                         }
1024                 }
1025
1026                 model = of_get_property(np, "model", NULL);
1027                 strcpy(fs_enet_data.fs_type, model);
1028
1029                 if (strstr(model, "FEC")) {
1030                         r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1031                         r[1].flags = IORESOURCE_IRQ;
1032                         r[1].name = enet_irq;
1033
1034                         fs_enet_dev =
1035                                     platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1036
1037                         if (IS_ERR(fs_enet_dev)) {
1038                                 ret = PTR_ERR(fs_enet_dev);
1039                                 goto err;
1040                         }
1041
1042                         fs_enet_data.rx_ring = 128;
1043                         fs_enet_data.tx_ring = 16;
1044                         fs_enet_data.rx_copybreak = 240;
1045                         fs_enet_data.use_napi = 1;
1046                         fs_enet_data.napi_weight = 17;
1047
1048                         snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1049                                                         (u32)res.start, fs_enet_data.phy_addr);
1050                         fs_enet_data.bus_id = (char*)&bus_id[i];
1051                         fs_enet_data.init_ioports = init_fec_ioports;
1052                 }
1053                 if (strstr(model, "SCC")) {
1054                         ret = of_address_to_resource(np, 1, &r[1]);
1055                         if (ret)
1056                                 goto err;
1057                         r[1].name = enet_pram;
1058
1059                         r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1060                         r[2].flags = IORESOURCE_IRQ;
1061                         r[2].name = enet_irq;
1062
1063                         fs_enet_dev =
1064                                     platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1065
1066                         if (IS_ERR(fs_enet_dev)) {
1067                                 ret = PTR_ERR(fs_enet_dev);
1068                                 goto err;
1069                         }
1070
1071                         fs_enet_data.rx_ring = 64;
1072                         fs_enet_data.tx_ring = 8;
1073                         fs_enet_data.rx_copybreak = 240;
1074                         fs_enet_data.use_napi = 1;
1075                         fs_enet_data.napi_weight = 17;
1076
1077                         snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1078                         fs_enet_data.bus_id = (char*)&bus_id[i];
1079                         fs_enet_data.init_ioports = init_scc_ioports;
1080                 }
1081
1082                 of_node_put(phy);
1083                 of_node_put(mdio);
1084
1085                 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1086                                              sizeof(struct
1087                                                     fs_platform_info));
1088                 if (ret)
1089                         goto unreg;
1090         }
1091         return 0;
1092
1093 unreg:
1094         platform_device_unregister(fs_enet_dev);
1095 err:
1096         return ret;
1097 }
1098
1099 arch_initcall(fs_enet_of_init);
1100
1101 static int __init fsl_pcmcia_of_init(void)
1102 {
1103         struct device_node *np = NULL;
1104         /*
1105          * Register all the devices which type is "pcmcia"
1106          */
1107         while ((np = of_find_compatible_node(np,
1108                         "pcmcia", "fsl,pq-pcmcia")) != NULL)
1109                             of_platform_device_create(np, "m8xx-pcmcia", NULL);
1110         return 0;
1111 }
1112
1113 arch_initcall(fsl_pcmcia_of_init);
1114
1115 static const char *smc_regs = "regs";
1116 static const char *smc_pram = "pram";
1117
1118 static int __init cpm_smc_uart_of_init(void)
1119 {
1120         struct device_node *np;
1121         unsigned int i;
1122         struct platform_device *cpm_uart_dev;
1123         int ret;
1124
1125         for (np = NULL, i = 0;
1126              (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1127              i++) {
1128                 struct resource r[3];
1129                 struct fs_uart_platform_info cpm_uart_data;
1130                 const int *id;
1131                 const char *model;
1132
1133                 memset(r, 0, sizeof(r));
1134                 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1135
1136                 ret = of_address_to_resource(np, 0, &r[0]);
1137                 if (ret)
1138                         goto err;
1139
1140                 r[0].name = smc_regs;
1141
1142                 ret = of_address_to_resource(np, 1, &r[1]);
1143                 if (ret)
1144                         goto err;
1145                 r[1].name = smc_pram;
1146
1147                 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1148                 r[2].flags = IORESOURCE_IRQ;
1149
1150                 cpm_uart_dev =
1151                     platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1152
1153                 if (IS_ERR(cpm_uart_dev)) {
1154                         ret = PTR_ERR(cpm_uart_dev);
1155                         goto err;
1156                 }
1157
1158                 model = of_get_property(np, "model", NULL);
1159                 strcpy(cpm_uart_data.fs_type, model);
1160
1161                 id = of_get_property(np, "device-id", NULL);
1162                 cpm_uart_data.fs_no = *id;
1163                 cpm_uart_data.uart_clk = ppc_proc_freq;
1164
1165                 cpm_uart_data.tx_num_fifo = 4;
1166                 cpm_uart_data.tx_buf_size = 32;
1167                 cpm_uart_data.rx_num_fifo = 4;
1168                 cpm_uart_data.rx_buf_size = 32;
1169
1170                 ret =
1171                     platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1172                                              sizeof(struct
1173                                                     fs_uart_platform_info));
1174                 if (ret)
1175                         goto unreg;
1176         }
1177
1178         return 0;
1179
1180 unreg:
1181         platform_device_unregister(cpm_uart_dev);
1182 err:
1183         return ret;
1184 }
1185
1186 arch_initcall(cpm_smc_uart_of_init);
1187
1188 #endif /* CONFIG_8xx */