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