4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
6 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
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.
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>
30 #include <asm/system.h>
31 #include <asm/atomic.h>
36 #include <sysdev/fsl_soc.h>
37 #include <mm/mmu_decl.h>
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;
45 phys_addr_t
get_immrbase(void)
47 struct device_node
*soc
;
52 soc
= of_find_node_by_type(NULL
, "soc");
55 const void *prop
= of_get_property(soc
, "reg", &size
);
58 immrbase
= of_translate_address(soc
, prop
);
65 EXPORT_SYMBOL(get_immrbase
);
67 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
69 static u32 brgfreq
= -1;
73 struct device_node
*node
;
78 node
= of_find_node_by_type(NULL
, "cpm");
81 const unsigned int *prop
= of_get_property(node
,
82 "brg-frequency", &size
);
92 EXPORT_SYMBOL(get_brgfreq
);
94 static u32 fs_baudrate
= -1;
96 u32
get_baudrate(void)
98 struct device_node
*node
;
100 if (fs_baudrate
!= -1)
103 node
= of_find_node_by_type(NULL
, "serial");
106 const unsigned int *prop
= of_get_property(node
,
107 "current-speed", &size
);
117 EXPORT_SYMBOL(get_baudrate
);
118 #endif /* CONFIG_CPM2 */
120 static int __init
gfar_mdio_of_init(void)
122 struct device_node
*np
;
124 struct platform_device
*mdio_dev
;
128 for (np
= NULL
, i
= 0;
129 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
132 struct device_node
*child
= NULL
;
133 struct gianfar_mdio_data mdio_data
;
135 memset(&res
, 0, sizeof(res
));
136 memset(&mdio_data
, 0, sizeof(mdio_data
));
138 ret
= of_address_to_resource(np
, 0, &res
);
143 platform_device_register_simple("fsl-gianfar_mdio",
145 if (IS_ERR(mdio_dev
)) {
146 ret
= PTR_ERR(mdio_dev
);
150 for (k
= 0; k
< 32; k
++)
151 mdio_data
.irq
[k
] = PHY_POLL
;
153 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
154 int irq
= irq_of_parse_and_map(child
, 0);
156 const u32
*id
= of_get_property(child
,
158 mdio_data
.irq
[*id
] = irq
;
163 platform_device_add_data(mdio_dev
, &mdio_data
,
164 sizeof(struct gianfar_mdio_data
));
172 platform_device_unregister(mdio_dev
);
177 arch_initcall(gfar_mdio_of_init
);
179 static const char *gfar_tx_intr
= "tx";
180 static const char *gfar_rx_intr
= "rx";
181 static const char *gfar_err_intr
= "error";
184 static int __init
gfar_of_init(void)
186 struct device_node
*np
;
188 struct platform_device
*gfar_dev
;
192 for (np
= NULL
, i
= 0;
193 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
195 struct resource r
[4];
196 struct device_node
*phy
, *mdio
;
197 struct gianfar_platform_data gfar_data
;
198 const unsigned int *id
;
201 const void *mac_addr
;
205 memset(r
, 0, sizeof(r
));
206 memset(&gfar_data
, 0, sizeof(gfar_data
));
208 ret
= of_address_to_resource(np
, 0, &r
[0]);
212 of_irq_to_resource(np
, 0, &r
[1]);
214 model
= of_get_property(np
, "model", NULL
);
216 /* If we aren't the FEC we have multiple interrupts */
217 if (model
&& strcasecmp(model
, "FEC")) {
218 r
[1].name
= gfar_tx_intr
;
220 r
[2].name
= gfar_rx_intr
;
221 of_irq_to_resource(np
, 1, &r
[2]);
223 r
[3].name
= gfar_err_intr
;
224 of_irq_to_resource(np
, 2, &r
[3]);
230 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
233 if (IS_ERR(gfar_dev
)) {
234 ret
= PTR_ERR(gfar_dev
);
238 mac_addr
= of_get_mac_address(np
);
240 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
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
;
258 ctype
= of_get_property(np
, "phy-connection-type", NULL
);
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
;
264 gfar_data
.interface
= PHY_INTERFACE_MODE_MII
;
266 ph
= of_get_property(np
, "phy-handle", NULL
);
267 phy
= of_find_node_by_phandle(*ph
);
274 mdio
= of_get_parent(phy
);
276 id
= of_get_property(phy
, "reg", NULL
);
277 ret
= of_address_to_resource(mdio
, 0, &res
);
284 gfar_data
.phy_id
= *id
;
285 gfar_data
.bus_id
= res
.start
;
291 platform_device_add_data(gfar_dev
, &gfar_data
,
293 gianfar_platform_data
));
301 platform_device_unregister(gfar_dev
);
306 arch_initcall(gfar_of_init
);
308 #ifdef CONFIG_I2C_BOARDINFO
309 #include <linux/i2c.h>
310 struct i2c_driver_device
{
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",},
323 static int __init
of_find_i2c_driver(struct device_node
*node
, struct i2c_board_info
*info
)
327 for (i
= 0; i
< ARRAY_SIZE(i2c_devices
); i
++) {
328 if (!of_device_is_compatible(node
, i2c_devices
[i
].of_device
))
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
);
337 static void __init
of_register_i2c_devices(struct device_node
*adap_node
, int bus_num
)
339 struct device_node
*node
= NULL
;
341 while ((node
= of_get_next_child(adap_node
, node
))) {
342 struct i2c_board_info info
;
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");
352 info
.irq
= irq_of_parse_and_map(node
, 0);
353 if (info
.irq
== NO_IRQ
)
356 if (of_find_i2c_driver(node
, &info
) < 0)
359 info
.platform_data
= NULL
;
362 i2c_register_board_info(bus_num
, &info
, 1);
366 static int __init
fsl_i2c_of_init(void)
368 struct device_node
*np
;
370 struct platform_device
*i2c_dev
;
373 for (np
= NULL
, i
= 0;
374 (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
;
376 struct resource r
[2];
377 struct fsl_i2c_platform_data i2c_data
;
378 const unsigned char *flags
= NULL
;
380 memset(&r
, 0, sizeof(r
));
381 memset(&i2c_data
, 0, sizeof(i2c_data
));
383 ret
= of_address_to_resource(np
, 0, &r
[0]);
387 of_irq_to_resource(np
, 0, &r
[1]);
389 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
390 if (IS_ERR(i2c_dev
)) {
391 ret
= PTR_ERR(i2c_dev
);
395 i2c_data
.device_flags
= 0;
396 flags
= of_get_property(np
, "dfsrr", NULL
);
398 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
400 flags
= of_get_property(np
, "fsl5200-clocking", NULL
);
402 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
405 platform_device_add_data(i2c_dev
, &i2c_data
,
407 fsl_i2c_platform_data
));
411 of_register_i2c_devices(np
, i
);
417 platform_device_unregister(i2c_dev
);
422 arch_initcall(fsl_i2c_of_init
);
425 #ifdef CONFIG_PPC_83xx
426 static int __init
mpc83xx_wdt_init(void)
429 struct device_node
*soc
, *np
;
430 struct platform_device
*dev
;
431 const unsigned int *freq
;
434 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
441 soc
= of_find_node_by_type(NULL
, "soc");
448 freq
= of_get_property(soc
, "bus-frequency", NULL
);
454 memset(&r
, 0, sizeof(r
));
456 ret
= of_address_to_resource(np
, 0, &r
);
460 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
466 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
476 platform_device_unregister(dev
);
485 arch_initcall(mpc83xx_wdt_init
);
488 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *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
;
501 return FSL_USB2_PHY_NONE
;
504 static int __init
fsl_usb_of_init(void)
506 struct device_node
*np
;
508 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr_host
= NULL
,
509 *usb_dev_dr_client
= NULL
;
512 for (np
= NULL
, i
= 0;
513 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
515 struct resource r
[2];
516 struct fsl_usb2_platform_data usb_data
;
517 const unsigned char *prop
= NULL
;
519 memset(&r
, 0, sizeof(r
));
520 memset(&usb_data
, 0, sizeof(usb_data
));
522 ret
= of_address_to_resource(np
, 0, &r
[0]);
526 of_irq_to_resource(np
, 0, &r
[1]);
529 platform_device_register_simple("fsl-ehci", i
, r
, 2);
530 if (IS_ERR(usb_dev_mph
)) {
531 ret
= PTR_ERR(usb_dev_mph
);
535 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
536 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
538 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
540 prop
= of_get_property(np
, "port0", NULL
);
542 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
544 prop
= of_get_property(np
, "port1", NULL
);
546 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
548 prop
= of_get_property(np
, "phy_type", NULL
);
549 usb_data
.phy_mode
= determine_usb_phy(prop
);
552 platform_device_add_data(usb_dev_mph
, &usb_data
,
554 fsl_usb2_platform_data
));
560 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
562 struct resource r
[2];
563 struct fsl_usb2_platform_data usb_data
;
564 const unsigned char *prop
= NULL
;
566 memset(&r
, 0, sizeof(r
));
567 memset(&usb_data
, 0, sizeof(usb_data
));
569 ret
= of_address_to_resource(np
, 0, &r
[0]);
573 of_irq_to_resource(np
, 0, &r
[1]);
575 prop
= of_get_property(np
, "dr_mode", NULL
);
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
);
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
);
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
);
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
);
612 prop
= of_get_property(np
, "phy_type", NULL
);
613 usb_data
.phy_mode
= determine_usb_phy(prop
);
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
))))
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
))))
638 platform_device_unregister(usb_dev_dr_host
);
639 if (usb_dev_dr_client
)
640 platform_device_unregister(usb_dev_dr_client
);
643 platform_device_unregister(usb_dev_mph
);
648 arch_initcall(fsl_usb_of_init
);
652 extern void init_scc_ioports(struct fs_uart_platform_info
*);
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
];
659 static int __init
fs_enet_of_init(void)
661 struct device_node
*np
;
663 struct platform_device
*fs_enet_dev
;
667 for (np
= NULL
, i
= 0;
668 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
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
;
678 memset(r
, 0, sizeof(r
));
679 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
681 ret
= of_address_to_resource(np
, 0, &r
[0]);
684 r
[0].name
= fcc_regs
;
686 ret
= of_address_to_resource(np
, 1, &r
[1]);
689 r
[1].name
= fcc_pram
;
691 ret
= of_address_to_resource(np
, 2, &r
[2]);
694 r
[2].name
= fcc_regs_c
;
695 fs_enet_data
.fcc_regs_c
= r
[2].start
;
697 of_irq_to_resource(np
, 0, &r
[3]);
700 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
702 if (IS_ERR(fs_enet_dev
)) {
703 ret
= PTR_ERR(fs_enet_dev
);
707 model
= of_get_property(np
, "model", NULL
);
713 mac_addr
= of_get_mac_address(np
);
715 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
717 ph
= of_get_property(np
, "phy-handle", NULL
);
718 phy
= of_find_node_by_phandle(*ph
);
725 phy_addr
= of_get_property(phy
, "reg", NULL
);
726 fs_enet_data
.phy_addr
= *phy_addr
;
728 phy_irq
= of_get_property(phy
, "interrupts", NULL
);
730 id
= of_get_property(np
, "device-id", NULL
);
731 fs_enet_data
.fs_no
= *id
;
732 strcpy(fs_enet_data
.fs_type
, model
);
734 mdio
= of_get_parent(phy
);
735 ret
= of_address_to_resource(mdio
, 0, &res
);
742 fs_enet_data
.clk_rx
= *((u32
*)of_get_property(np
,
744 fs_enet_data
.clk_tx
= *((u32
*)of_get_property(np
,
747 if (strstr(model
, "FCC")) {
748 int fcc_index
= *id
- 1;
749 const unsigned char *mdio_bb_prop
;
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
);
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
;
766 mdio_bb_prop
= of_get_property(phy
, "bitbang", NULL
);
768 struct platform_device
*fs_enet_mdio_bb_dev
;
769 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data
;
771 fs_enet_mdio_bb_dev
=
772 platform_device_register_simple("fsl-bb-mdio",
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
=
778 fs_enet_mdio_bb_data
.mdio_dir
.bit
=
780 fs_enet_mdio_bb_data
.mdc_dat
.bit
=
782 fs_enet_mdio_bb_data
.mdio_port
=
784 fs_enet_mdio_bb_data
.mdc_port
=
786 fs_enet_mdio_bb_data
.delay
=
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;
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
;
802 ret
= platform_device_add_data(
804 &fs_enet_mdio_bb_data
,
805 sizeof(struct fs_mii_bb_platform_info
));
813 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
823 platform_device_unregister(fs_enet_dev
);
828 arch_initcall(fs_enet_of_init
);
830 static const char scc_regs
[] = "regs";
831 static const char scc_pram
[] = "pram";
833 static int __init
cpm_uart_of_init(void)
835 struct device_node
*np
;
837 struct platform_device
*cpm_uart_dev
;
840 for (np
= NULL
, i
= 0;
841 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
843 struct resource r
[3];
844 struct fs_uart_platform_info cpm_uart_data
;
848 memset(r
, 0, sizeof(r
));
849 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
851 ret
= of_address_to_resource(np
, 0, &r
[0]);
855 r
[0].name
= scc_regs
;
857 ret
= of_address_to_resource(np
, 1, &r
[1]);
860 r
[1].name
= scc_pram
;
862 of_irq_to_resource(np
, 0, &r
[2]);
865 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
867 if (IS_ERR(cpm_uart_dev
)) {
868 ret
= PTR_ERR(cpm_uart_dev
);
872 id
= of_get_property(np
, "device-id", NULL
);
873 cpm_uart_data
.fs_no
= *id
;
875 model
= of_get_property(np
, "model", NULL
);
876 strcpy(cpm_uart_data
.fs_type
, model
);
878 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
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
,
886 cpm_uart_data
.clk_tx
= *((u32
*)of_get_property(np
,
890 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
892 fs_uart_platform_info
));
900 platform_device_unregister(cpm_uart_dev
);
905 arch_initcall(cpm_uart_of_init
);
906 #endif /* CONFIG_CPM2 */
910 extern void init_scc_ioports(struct fs_platform_info
*);
911 extern int platform_device_skip(const char *model
, int id
);
913 static int __init
fs_enet_mdio_of_init(void)
915 struct device_node
*np
;
917 struct platform_device
*mdio_dev
;
921 for (np
= NULL
, i
= 0;
922 (np
= of_find_compatible_node(np
, "mdio", "fs_enet")) != NULL
;
924 struct fs_mii_fec_platform_info mdio_data
;
926 memset(&res
, 0, sizeof(res
));
927 memset(&mdio_data
, 0, sizeof(mdio_data
));
929 ret
= of_address_to_resource(np
, 0, &res
);
934 platform_device_register_simple("fsl-cpm-fec-mdio",
936 if (IS_ERR(mdio_dev
)) {
937 ret
= PTR_ERR(mdio_dev
);
941 mdio_data
.mii_speed
= ((((ppc_proc_freq
+ 4999999) / 2500000) / 2) & 0x3F) << 1;
944 platform_device_add_data(mdio_dev
, &mdio_data
,
945 sizeof(struct fs_mii_fec_platform_info
));
952 platform_device_unregister(mdio_dev
);
957 arch_initcall(fs_enet_mdio_of_init
);
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
];
964 static int __init
fs_enet_of_init(void)
966 struct device_node
*np
;
968 struct platform_device
*fs_enet_dev
= NULL
;
972 for (np
= NULL
, i
= 0;
973 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
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
;
984 memset(r
, 0, sizeof(r
));
985 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
987 model
= of_get_property(np
, "model", NULL
);
993 id
= of_get_property(np
, "device-id", NULL
);
994 fs_enet_data
.fs_no
= *id
;
996 if (platform_device_skip(model
, *id
))
999 ret
= of_address_to_resource(np
, 0, &r
[0]);
1002 r
[0].name
= enet_regs
;
1004 mac_addr
= of_get_mac_address(np
);
1006 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
1008 ph
= of_get_property(np
, "phy-handle", NULL
);
1010 phy
= of_find_node_by_phandle(*ph
);
1013 phy_addr
= of_get_property(phy
, "reg", NULL
);
1014 fs_enet_data
.phy_addr
= *phy_addr
;
1015 fs_enet_data
.has_phy
= 1;
1017 mdio
= of_get_parent(phy
);
1018 ret
= of_address_to_resource(mdio
, 0, &res
);
1026 model
= of_get_property(np
, "model", NULL
);
1027 strcpy(fs_enet_data
.fs_type
, model
);
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
;
1035 platform_device_register_simple("fsl-cpm-fec", i
, &r
[0], 2);
1037 if (IS_ERR(fs_enet_dev
)) {
1038 ret
= PTR_ERR(fs_enet_dev
);
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;
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
;
1053 if (strstr(model
, "SCC")) {
1054 ret
= of_address_to_resource(np
, 1, &r
[1]);
1057 r
[1].name
= enet_pram
;
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
;
1064 platform_device_register_simple("fsl-cpm-scc", i
, &r
[0], 3);
1066 if (IS_ERR(fs_enet_dev
)) {
1067 ret
= PTR_ERR(fs_enet_dev
);
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;
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
;
1085 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
1094 platform_device_unregister(fs_enet_dev
);
1099 arch_initcall(fs_enet_of_init
);
1101 static int __init
fsl_pcmcia_of_init(void)
1103 struct device_node
*np
= NULL
;
1105 * Register all the devices which type is "pcmcia"
1107 while ((np
= of_find_compatible_node(np
,
1108 "pcmcia", "fsl,pq-pcmcia")) != NULL
)
1109 of_platform_device_create(np
, "m8xx-pcmcia", NULL
);
1113 arch_initcall(fsl_pcmcia_of_init
);
1115 static const char *smc_regs
= "regs";
1116 static const char *smc_pram
= "pram";
1118 static int __init
cpm_smc_uart_of_init(void)
1120 struct device_node
*np
;
1122 struct platform_device
*cpm_uart_dev
;
1125 for (np
= NULL
, i
= 0;
1126 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
1128 struct resource r
[3];
1129 struct fs_uart_platform_info cpm_uart_data
;
1133 memset(r
, 0, sizeof(r
));
1134 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
1136 ret
= of_address_to_resource(np
, 0, &r
[0]);
1140 r
[0].name
= smc_regs
;
1142 ret
= of_address_to_resource(np
, 1, &r
[1]);
1145 r
[1].name
= smc_pram
;
1147 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
1148 r
[2].flags
= IORESOURCE_IRQ
;
1151 platform_device_register_simple("fsl-cpm-smc:uart", i
, &r
[0], 3);
1153 if (IS_ERR(cpm_uart_dev
)) {
1154 ret
= PTR_ERR(cpm_uart_dev
);
1158 model
= of_get_property(np
, "model", NULL
);
1159 strcpy(cpm_uart_data
.fs_type
, model
);
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
;
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;
1171 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
1173 fs_uart_platform_info
));
1181 platform_device_unregister(cpm_uart_dev
);
1186 arch_initcall(cpm_smc_uart_of_init
);
1188 #endif /* CONFIG_8xx */