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/of_platform.h>
26 #include <linux/phy.h>
27 #include <linux/phy_fixed.h>
28 #include <linux/spi/spi.h>
29 #include <linux/fsl_devices.h>
30 #include <linux/fs_enet_pd.h>
31 #include <linux/fs_uart_pd.h>
33 #include <asm/system.h>
34 #include <asm/atomic.h>
39 #include <sysdev/fsl_soc.h>
40 #include <mm/mmu_decl.h>
43 extern void init_fcc_ioports(struct fs_platform_info
*);
44 extern void init_fec_ioports(struct fs_platform_info
*);
45 extern void init_smc_ioports(struct fs_uart_platform_info
*);
46 static phys_addr_t immrbase
= -1;
48 phys_addr_t
get_immrbase(void)
50 struct device_node
*soc
;
55 soc
= of_find_node_by_type(NULL
, "soc");
59 const u32
*prop
= of_get_property(soc
, "#address-cells", &size
);
61 if (prop
&& size
== 4)
66 prop
= of_get_property(soc
, "ranges", &size
);
68 immrbase
= of_translate_address(soc
, prop
+ naddr
);
76 EXPORT_SYMBOL(get_immrbase
);
78 #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
80 static u32 brgfreq
= -1;
84 struct device_node
*node
;
85 const unsigned int *prop
;
91 node
= of_find_compatible_node(NULL
, NULL
, "fsl,cpm-brg");
93 prop
= of_get_property(node
, "clock-frequency", &size
);
94 if (prop
&& size
== 4)
101 /* Legacy device binding -- will go away when no users are left. */
102 node
= of_find_node_by_type(NULL
, "cpm");
104 node
= of_find_compatible_node(NULL
, NULL
, "fsl,qe");
106 node
= of_find_node_by_type(NULL
, "qe");
109 prop
= of_get_property(node
, "brg-frequency", &size
);
110 if (prop
&& size
== 4)
113 if (brgfreq
== -1 || brgfreq
== 0) {
114 prop
= of_get_property(node
, "bus-frequency", &size
);
115 if (prop
&& size
== 4)
124 EXPORT_SYMBOL(get_brgfreq
);
126 static u32 fs_baudrate
= -1;
128 u32
get_baudrate(void)
130 struct device_node
*node
;
132 if (fs_baudrate
!= -1)
135 node
= of_find_node_by_type(NULL
, "serial");
138 const unsigned int *prop
= of_get_property(node
,
139 "current-speed", &size
);
149 EXPORT_SYMBOL(get_baudrate
);
150 #endif /* CONFIG_CPM2 */
152 #ifdef CONFIG_FIXED_PHY
153 static int __init
of_add_fixed_phys(void)
156 struct device_node
*np
;
158 struct fixed_phy_status status
= {};
160 for_each_node_by_name(np
, "ethernet") {
161 fixed_link
= (u32
*)of_get_property(np
, "fixed-link", NULL
);
166 status
.duplex
= fixed_link
[1];
167 status
.speed
= fixed_link
[2];
168 status
.pause
= fixed_link
[3];
169 status
.asym_pause
= fixed_link
[4];
171 ret
= fixed_phy_add(PHY_POLL
, fixed_link
[0], &status
);
180 arch_initcall(of_add_fixed_phys
);
181 #endif /* CONFIG_FIXED_PHY */
183 static int __init
gfar_mdio_of_init(void)
185 struct device_node
*np
= NULL
;
186 struct platform_device
*mdio_dev
;
190 np
= of_find_compatible_node(np
, NULL
, "fsl,gianfar-mdio");
192 /* try the deprecated version */
194 np
= of_find_compatible_node(np
, "mdio", "gianfar");
198 struct device_node
*child
= NULL
;
199 struct gianfar_mdio_data mdio_data
;
201 memset(&res
, 0, sizeof(res
));
202 memset(&mdio_data
, 0, sizeof(mdio_data
));
204 ret
= of_address_to_resource(np
, 0, &res
);
209 platform_device_register_simple("fsl-gianfar_mdio",
211 if (IS_ERR(mdio_dev
)) {
212 ret
= PTR_ERR(mdio_dev
);
216 for (k
= 0; k
< 32; k
++)
217 mdio_data
.irq
[k
] = PHY_POLL
;
219 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
220 int irq
= irq_of_parse_and_map(child
, 0);
222 const u32
*id
= of_get_property(child
,
224 mdio_data
.irq
[*id
] = irq
;
229 platform_device_add_data(mdio_dev
, &mdio_data
,
230 sizeof(struct gianfar_mdio_data
));
239 platform_device_unregister(mdio_dev
);
245 arch_initcall(gfar_mdio_of_init
);
247 static const char *gfar_tx_intr
= "tx";
248 static const char *gfar_rx_intr
= "rx";
249 static const char *gfar_err_intr
= "error";
251 static int __init
gfar_of_init(void)
253 struct device_node
*np
;
255 struct platform_device
*gfar_dev
;
259 for (np
= NULL
, i
= 0;
260 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
262 struct resource r
[4];
263 struct device_node
*phy
, *mdio
;
264 struct gianfar_platform_data gfar_data
;
265 const unsigned int *id
;
268 const void *mac_addr
;
272 memset(r
, 0, sizeof(r
));
273 memset(&gfar_data
, 0, sizeof(gfar_data
));
275 ret
= of_address_to_resource(np
, 0, &r
[0]);
279 of_irq_to_resource(np
, 0, &r
[1]);
281 model
= of_get_property(np
, "model", NULL
);
283 /* If we aren't the FEC we have multiple interrupts */
284 if (model
&& strcasecmp(model
, "FEC")) {
285 r
[1].name
= gfar_tx_intr
;
287 r
[2].name
= gfar_rx_intr
;
288 of_irq_to_resource(np
, 1, &r
[2]);
290 r
[3].name
= gfar_err_intr
;
291 of_irq_to_resource(np
, 2, &r
[3]);
297 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
300 if (IS_ERR(gfar_dev
)) {
301 ret
= PTR_ERR(gfar_dev
);
305 mac_addr
= of_get_mac_address(np
);
307 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
309 if (model
&& !strcasecmp(model
, "TSEC"))
310 gfar_data
.device_flags
=
311 FSL_GIANFAR_DEV_HAS_GIGABIT
|
312 FSL_GIANFAR_DEV_HAS_COALESCE
|
313 FSL_GIANFAR_DEV_HAS_RMON
|
314 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
315 if (model
&& !strcasecmp(model
, "eTSEC"))
316 gfar_data
.device_flags
=
317 FSL_GIANFAR_DEV_HAS_GIGABIT
|
318 FSL_GIANFAR_DEV_HAS_COALESCE
|
319 FSL_GIANFAR_DEV_HAS_RMON
|
320 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
321 FSL_GIANFAR_DEV_HAS_CSUM
|
322 FSL_GIANFAR_DEV_HAS_VLAN
|
323 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
325 ctype
= of_get_property(np
, "phy-connection-type", NULL
);
327 /* We only care about rgmii-id. The rest are autodetected */
328 if (ctype
&& !strcmp(ctype
, "rgmii-id"))
329 gfar_data
.interface
= PHY_INTERFACE_MODE_RGMII_ID
;
331 gfar_data
.interface
= PHY_INTERFACE_MODE_MII
;
333 ph
= of_get_property(np
, "phy-handle", NULL
);
337 fixed_link
= (u32
*)of_get_property(np
, "fixed-link",
344 gfar_data
.bus_id
= 0;
345 gfar_data
.phy_id
= fixed_link
[0];
347 phy
= of_find_node_by_phandle(*ph
);
354 mdio
= of_get_parent(phy
);
356 id
= of_get_property(phy
, "reg", NULL
);
357 ret
= of_address_to_resource(mdio
, 0, &res
);
364 gfar_data
.phy_id
= *id
;
365 gfar_data
.bus_id
= res
.start
;
372 platform_device_add_data(gfar_dev
, &gfar_data
,
374 gianfar_platform_data
));
382 platform_device_unregister(gfar_dev
);
387 arch_initcall(gfar_of_init
);
389 #ifdef CONFIG_I2C_BOARDINFO
390 #include <linux/i2c.h>
391 struct i2c_driver_device
{
397 static struct i2c_driver_device i2c_devices
[] __initdata
= {
398 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
399 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
400 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
401 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
402 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
403 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
404 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
405 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
406 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
407 {"stm,m41t00", "rtc-ds1307", "m41t00"},
408 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
411 static int __init
of_find_i2c_driver(struct device_node
*node
,
412 struct i2c_board_info
*info
)
416 for (i
= 0; i
< ARRAY_SIZE(i2c_devices
); i
++) {
417 if (!of_device_is_compatible(node
, i2c_devices
[i
].of_device
))
419 if (strlcpy(info
->driver_name
, i2c_devices
[i
].i2c_driver
,
420 KOBJ_NAME_LEN
) >= KOBJ_NAME_LEN
||
421 strlcpy(info
->type
, i2c_devices
[i
].i2c_type
,
422 I2C_NAME_SIZE
) >= I2C_NAME_SIZE
)
429 static void __init
of_register_i2c_devices(struct device_node
*adap_node
,
432 struct device_node
*node
= NULL
;
434 while ((node
= of_get_next_child(adap_node
, node
))) {
435 struct i2c_board_info info
= {};
439 addr
= of_get_property(node
, "reg", &len
);
440 if (!addr
|| len
< sizeof(int) || *addr
> (1 << 10) - 1) {
441 printk(KERN_WARNING
"fsl_soc.c: invalid i2c device entry\n");
445 info
.irq
= irq_of_parse_and_map(node
, 0);
446 if (info
.irq
== NO_IRQ
)
449 if (of_find_i2c_driver(node
, &info
) < 0)
454 i2c_register_board_info(bus_num
, &info
, 1);
458 static int __init
fsl_i2c_of_init(void)
460 struct device_node
*np
;
462 struct platform_device
*i2c_dev
;
465 for_each_compatible_node(np
, NULL
, "fsl-i2c") {
466 struct resource r
[2];
467 struct fsl_i2c_platform_data i2c_data
;
468 const unsigned char *flags
= NULL
;
470 memset(&r
, 0, sizeof(r
));
471 memset(&i2c_data
, 0, sizeof(i2c_data
));
473 ret
= of_address_to_resource(np
, 0, &r
[0]);
477 of_irq_to_resource(np
, 0, &r
[1]);
479 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
480 if (IS_ERR(i2c_dev
)) {
481 ret
= PTR_ERR(i2c_dev
);
485 i2c_data
.device_flags
= 0;
486 flags
= of_get_property(np
, "dfsrr", NULL
);
488 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
490 flags
= of_get_property(np
, "fsl5200-clocking", NULL
);
492 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
495 platform_device_add_data(i2c_dev
, &i2c_data
,
497 fsl_i2c_platform_data
));
501 of_register_i2c_devices(np
, i
++);
507 platform_device_unregister(i2c_dev
);
512 arch_initcall(fsl_i2c_of_init
);
515 #ifdef CONFIG_PPC_83xx
516 static int __init
mpc83xx_wdt_init(void)
519 struct device_node
*soc
, *np
;
520 struct platform_device
*dev
;
521 const unsigned int *freq
;
524 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
531 soc
= of_find_node_by_type(NULL
, "soc");
538 freq
= of_get_property(soc
, "bus-frequency", NULL
);
544 memset(&r
, 0, sizeof(r
));
546 ret
= of_address_to_resource(np
, 0, &r
);
550 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
556 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
566 platform_device_unregister(dev
);
575 arch_initcall(mpc83xx_wdt_init
);
578 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
581 return FSL_USB2_PHY_NONE
;
582 if (!strcasecmp(phy_type
, "ulpi"))
583 return FSL_USB2_PHY_ULPI
;
584 if (!strcasecmp(phy_type
, "utmi"))
585 return FSL_USB2_PHY_UTMI
;
586 if (!strcasecmp(phy_type
, "utmi_wide"))
587 return FSL_USB2_PHY_UTMI_WIDE
;
588 if (!strcasecmp(phy_type
, "serial"))
589 return FSL_USB2_PHY_SERIAL
;
591 return FSL_USB2_PHY_NONE
;
594 static int __init
fsl_usb_of_init(void)
596 struct device_node
*np
;
598 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr_host
= NULL
,
599 *usb_dev_dr_client
= NULL
;
602 for_each_compatible_node(np
, NULL
, "fsl-usb2-mph") {
603 struct resource r
[2];
604 struct fsl_usb2_platform_data usb_data
;
605 const unsigned char *prop
= NULL
;
607 memset(&r
, 0, sizeof(r
));
608 memset(&usb_data
, 0, sizeof(usb_data
));
610 ret
= of_address_to_resource(np
, 0, &r
[0]);
614 of_irq_to_resource(np
, 0, &r
[1]);
617 platform_device_register_simple("fsl-ehci", i
, r
, 2);
618 if (IS_ERR(usb_dev_mph
)) {
619 ret
= PTR_ERR(usb_dev_mph
);
623 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
624 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
626 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
628 prop
= of_get_property(np
, "port0", NULL
);
630 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
632 prop
= of_get_property(np
, "port1", NULL
);
634 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
636 prop
= of_get_property(np
, "phy_type", NULL
);
637 usb_data
.phy_mode
= determine_usb_phy(prop
);
640 platform_device_add_data(usb_dev_mph
, &usb_data
,
642 fsl_usb2_platform_data
));
648 for_each_compatible_node(np
, NULL
, "fsl-usb2-dr") {
649 struct resource r
[2];
650 struct fsl_usb2_platform_data usb_data
;
651 const unsigned char *prop
= NULL
;
653 memset(&r
, 0, sizeof(r
));
654 memset(&usb_data
, 0, sizeof(usb_data
));
656 ret
= of_address_to_resource(np
, 0, &r
[0]);
660 of_irq_to_resource(np
, 0, &r
[1]);
662 prop
= of_get_property(np
, "dr_mode", NULL
);
664 if (!prop
|| !strcmp(prop
, "host")) {
665 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
666 usb_dev_dr_host
= platform_device_register_simple(
667 "fsl-ehci", i
, r
, 2);
668 if (IS_ERR(usb_dev_dr_host
)) {
669 ret
= PTR_ERR(usb_dev_dr_host
);
672 } else if (prop
&& !strcmp(prop
, "peripheral")) {
673 usb_data
.operating_mode
= FSL_USB2_DR_DEVICE
;
674 usb_dev_dr_client
= platform_device_register_simple(
675 "fsl-usb2-udc", i
, r
, 2);
676 if (IS_ERR(usb_dev_dr_client
)) {
677 ret
= PTR_ERR(usb_dev_dr_client
);
680 } else if (prop
&& !strcmp(prop
, "otg")) {
681 usb_data
.operating_mode
= FSL_USB2_DR_OTG
;
682 usb_dev_dr_host
= platform_device_register_simple(
683 "fsl-ehci", i
, r
, 2);
684 if (IS_ERR(usb_dev_dr_host
)) {
685 ret
= PTR_ERR(usb_dev_dr_host
);
688 usb_dev_dr_client
= platform_device_register_simple(
689 "fsl-usb2-udc", i
, r
, 2);
690 if (IS_ERR(usb_dev_dr_client
)) {
691 ret
= PTR_ERR(usb_dev_dr_client
);
699 prop
= of_get_property(np
, "phy_type", NULL
);
700 usb_data
.phy_mode
= determine_usb_phy(prop
);
702 if (usb_dev_dr_host
) {
703 usb_dev_dr_host
->dev
.coherent_dma_mask
= 0xffffffffUL
;
704 usb_dev_dr_host
->dev
.dma_mask
= &usb_dev_dr_host
->
705 dev
.coherent_dma_mask
;
706 if ((ret
= platform_device_add_data(usb_dev_dr_host
,
707 &usb_data
, sizeof(struct
708 fsl_usb2_platform_data
))))
711 if (usb_dev_dr_client
) {
712 usb_dev_dr_client
->dev
.coherent_dma_mask
= 0xffffffffUL
;
713 usb_dev_dr_client
->dev
.dma_mask
= &usb_dev_dr_client
->
714 dev
.coherent_dma_mask
;
715 if ((ret
= platform_device_add_data(usb_dev_dr_client
,
716 &usb_data
, sizeof(struct
717 fsl_usb2_platform_data
))))
726 platform_device_unregister(usb_dev_dr_host
);
727 if (usb_dev_dr_client
)
728 platform_device_unregister(usb_dev_dr_client
);
731 platform_device_unregister(usb_dev_mph
);
736 arch_initcall(fsl_usb_of_init
);
738 #ifndef CONFIG_PPC_CPM_NEW_BINDING
741 extern void init_scc_ioports(struct fs_uart_platform_info
*);
743 static const char fcc_regs
[] = "fcc_regs";
744 static const char fcc_regs_c
[] = "fcc_regs_c";
745 static const char fcc_pram
[] = "fcc_pram";
746 static char bus_id
[9][BUS_ID_SIZE
];
748 static int __init
fs_enet_of_init(void)
750 struct device_node
*np
;
752 struct platform_device
*fs_enet_dev
;
756 for (np
= NULL
, i
= 0;
757 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
759 struct resource r
[4];
760 struct device_node
*phy
, *mdio
;
761 struct fs_platform_info fs_enet_data
;
762 const unsigned int *id
, *phy_addr
, *phy_irq
;
763 const void *mac_addr
;
767 memset(r
, 0, sizeof(r
));
768 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
770 ret
= of_address_to_resource(np
, 0, &r
[0]);
773 r
[0].name
= fcc_regs
;
775 ret
= of_address_to_resource(np
, 1, &r
[1]);
778 r
[1].name
= fcc_pram
;
780 ret
= of_address_to_resource(np
, 2, &r
[2]);
783 r
[2].name
= fcc_regs_c
;
784 fs_enet_data
.fcc_regs_c
= r
[2].start
;
786 of_irq_to_resource(np
, 0, &r
[3]);
789 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
791 if (IS_ERR(fs_enet_dev
)) {
792 ret
= PTR_ERR(fs_enet_dev
);
796 model
= of_get_property(np
, "model", NULL
);
802 mac_addr
= of_get_mac_address(np
);
804 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
806 ph
= of_get_property(np
, "phy-handle", NULL
);
807 phy
= of_find_node_by_phandle(*ph
);
814 phy_addr
= of_get_property(phy
, "reg", NULL
);
815 fs_enet_data
.phy_addr
= *phy_addr
;
817 phy_irq
= of_get_property(phy
, "interrupts", NULL
);
819 id
= of_get_property(np
, "device-id", NULL
);
820 fs_enet_data
.fs_no
= *id
;
821 strcpy(fs_enet_data
.fs_type
, model
);
823 mdio
= of_get_parent(phy
);
824 ret
= of_address_to_resource(mdio
, 0, &res
);
831 fs_enet_data
.clk_rx
= *((u32
*)of_get_property(np
,
833 fs_enet_data
.clk_tx
= *((u32
*)of_get_property(np
,
836 if (strstr(model
, "FCC")) {
837 int fcc_index
= *id
- 1;
838 const unsigned char *mdio_bb_prop
;
840 fs_enet_data
.dpram_offset
= (u32
)cpm_dpram_addr(0);
841 fs_enet_data
.rx_ring
= 32;
842 fs_enet_data
.tx_ring
= 32;
843 fs_enet_data
.rx_copybreak
= 240;
844 fs_enet_data
.use_napi
= 0;
845 fs_enet_data
.napi_weight
= 17;
846 fs_enet_data
.mem_offset
= FCC_MEM_OFFSET(fcc_index
);
847 fs_enet_data
.cp_page
= CPM_CR_FCC_PAGE(fcc_index
);
848 fs_enet_data
.cp_block
= CPM_CR_FCC_SBLOCK(fcc_index
);
850 snprintf((char*)&bus_id
[(*id
)], BUS_ID_SIZE
, "%x:%02x",
851 (u32
)res
.start
, fs_enet_data
.phy_addr
);
852 fs_enet_data
.bus_id
= (char*)&bus_id
[(*id
)];
853 fs_enet_data
.init_ioports
= init_fcc_ioports
;
855 mdio_bb_prop
= of_get_property(phy
, "bitbang", NULL
);
857 struct platform_device
*fs_enet_mdio_bb_dev
;
858 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data
;
860 fs_enet_mdio_bb_dev
=
861 platform_device_register_simple("fsl-bb-mdio",
863 memset(&fs_enet_mdio_bb_data
, 0,
864 sizeof(struct fs_mii_bb_platform_info
));
865 fs_enet_mdio_bb_data
.mdio_dat
.bit
=
867 fs_enet_mdio_bb_data
.mdio_dir
.bit
=
869 fs_enet_mdio_bb_data
.mdc_dat
.bit
=
871 fs_enet_mdio_bb_data
.mdio_port
=
873 fs_enet_mdio_bb_data
.mdc_port
=
875 fs_enet_mdio_bb_data
.delay
=
878 fs_enet_mdio_bb_data
.irq
[0] = phy_irq
[0];
879 fs_enet_mdio_bb_data
.irq
[1] = -1;
880 fs_enet_mdio_bb_data
.irq
[2] = -1;
881 fs_enet_mdio_bb_data
.irq
[3] = phy_irq
[0];
882 fs_enet_mdio_bb_data
.irq
[31] = -1;
884 fs_enet_mdio_bb_data
.mdio_dat
.offset
=
885 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
886 fs_enet_mdio_bb_data
.mdio_dir
.offset
=
887 (u32
)&cpm2_immr
->im_ioport
.iop_pdirc
;
888 fs_enet_mdio_bb_data
.mdc_dat
.offset
=
889 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
891 ret
= platform_device_add_data(
893 &fs_enet_mdio_bb_data
,
894 sizeof(struct fs_mii_bb_platform_info
));
902 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
912 platform_device_unregister(fs_enet_dev
);
917 arch_initcall(fs_enet_of_init
);
919 static const char scc_regs
[] = "regs";
920 static const char scc_pram
[] = "pram";
922 static int __init
cpm_uart_of_init(void)
924 struct device_node
*np
;
926 struct platform_device
*cpm_uart_dev
;
929 for (np
= NULL
, i
= 0;
930 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
932 struct resource r
[3];
933 struct fs_uart_platform_info cpm_uart_data
;
937 memset(r
, 0, sizeof(r
));
938 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
940 ret
= of_address_to_resource(np
, 0, &r
[0]);
944 r
[0].name
= scc_regs
;
946 ret
= of_address_to_resource(np
, 1, &r
[1]);
949 r
[1].name
= scc_pram
;
951 of_irq_to_resource(np
, 0, &r
[2]);
954 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
956 if (IS_ERR(cpm_uart_dev
)) {
957 ret
= PTR_ERR(cpm_uart_dev
);
961 id
= of_get_property(np
, "device-id", NULL
);
962 cpm_uart_data
.fs_no
= *id
;
964 model
= of_get_property(np
, "model", NULL
);
965 strcpy(cpm_uart_data
.fs_type
, model
);
967 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
969 cpm_uart_data
.tx_num_fifo
= 4;
970 cpm_uart_data
.tx_buf_size
= 32;
971 cpm_uart_data
.rx_num_fifo
= 4;
972 cpm_uart_data
.rx_buf_size
= 32;
973 cpm_uart_data
.clk_rx
= *((u32
*)of_get_property(np
,
975 cpm_uart_data
.clk_tx
= *((u32
*)of_get_property(np
,
979 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
981 fs_uart_platform_info
));
989 platform_device_unregister(cpm_uart_dev
);
994 arch_initcall(cpm_uart_of_init
);
995 #endif /* CONFIG_CPM2 */
999 extern void init_scc_ioports(struct fs_platform_info
*);
1000 extern int platform_device_skip(const char *model
, int id
);
1002 static int __init
fs_enet_mdio_of_init(void)
1004 struct device_node
*np
;
1006 struct platform_device
*mdio_dev
;
1007 struct resource res
;
1010 for (np
= NULL
, i
= 0;
1011 (np
= of_find_compatible_node(np
, "mdio", "fs_enet")) != NULL
;
1013 struct fs_mii_fec_platform_info mdio_data
;
1015 memset(&res
, 0, sizeof(res
));
1016 memset(&mdio_data
, 0, sizeof(mdio_data
));
1018 ret
= of_address_to_resource(np
, 0, &res
);
1023 platform_device_register_simple("fsl-cpm-fec-mdio",
1024 res
.start
, &res
, 1);
1025 if (IS_ERR(mdio_dev
)) {
1026 ret
= PTR_ERR(mdio_dev
);
1030 mdio_data
.mii_speed
= ((((ppc_proc_freq
+ 4999999) / 2500000) / 2) & 0x3F) << 1;
1033 platform_device_add_data(mdio_dev
, &mdio_data
,
1034 sizeof(struct fs_mii_fec_platform_info
));
1041 platform_device_unregister(mdio_dev
);
1046 arch_initcall(fs_enet_mdio_of_init
);
1048 static const char *enet_regs
= "regs";
1049 static const char *enet_pram
= "pram";
1050 static const char *enet_irq
= "interrupt";
1051 static char bus_id
[9][BUS_ID_SIZE
];
1053 static int __init
fs_enet_of_init(void)
1055 struct device_node
*np
;
1057 struct platform_device
*fs_enet_dev
= NULL
;
1058 struct resource res
;
1061 for (np
= NULL
, i
= 0;
1062 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
1064 struct resource r
[4];
1065 struct device_node
*phy
= NULL
, *mdio
= NULL
;
1066 struct fs_platform_info fs_enet_data
;
1067 const unsigned int *id
;
1068 const unsigned int *phy_addr
;
1069 const void *mac_addr
;
1073 memset(r
, 0, sizeof(r
));
1074 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
1076 model
= of_get_property(np
, "model", NULL
);
1077 if (model
== NULL
) {
1082 id
= of_get_property(np
, "device-id", NULL
);
1083 fs_enet_data
.fs_no
= *id
;
1085 if (platform_device_skip(model
, *id
))
1088 ret
= of_address_to_resource(np
, 0, &r
[0]);
1091 r
[0].name
= enet_regs
;
1093 mac_addr
= of_get_mac_address(np
);
1095 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
1097 ph
= of_get_property(np
, "phy-handle", NULL
);
1099 phy
= of_find_node_by_phandle(*ph
);
1102 phy_addr
= of_get_property(phy
, "reg", NULL
);
1103 fs_enet_data
.phy_addr
= *phy_addr
;
1104 fs_enet_data
.has_phy
= 1;
1106 mdio
= of_get_parent(phy
);
1107 ret
= of_address_to_resource(mdio
, 0, &res
);
1115 model
= of_get_property(np
, "model", NULL
);
1116 strcpy(fs_enet_data
.fs_type
, model
);
1118 if (strstr(model
, "FEC")) {
1119 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
1120 r
[1].flags
= IORESOURCE_IRQ
;
1121 r
[1].name
= enet_irq
;
1124 platform_device_register_simple("fsl-cpm-fec", i
, &r
[0], 2);
1126 if (IS_ERR(fs_enet_dev
)) {
1127 ret
= PTR_ERR(fs_enet_dev
);
1131 fs_enet_data
.rx_ring
= 128;
1132 fs_enet_data
.tx_ring
= 16;
1133 fs_enet_data
.rx_copybreak
= 240;
1134 fs_enet_data
.use_napi
= 1;
1135 fs_enet_data
.napi_weight
= 17;
1137 snprintf((char*)&bus_id
[i
], BUS_ID_SIZE
, "%x:%02x",
1138 (u32
)res
.start
, fs_enet_data
.phy_addr
);
1139 fs_enet_data
.bus_id
= (char*)&bus_id
[i
];
1140 fs_enet_data
.init_ioports
= init_fec_ioports
;
1142 if (strstr(model
, "SCC")) {
1143 ret
= of_address_to_resource(np
, 1, &r
[1]);
1146 r
[1].name
= enet_pram
;
1148 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
1149 r
[2].flags
= IORESOURCE_IRQ
;
1150 r
[2].name
= enet_irq
;
1153 platform_device_register_simple("fsl-cpm-scc", i
, &r
[0], 3);
1155 if (IS_ERR(fs_enet_dev
)) {
1156 ret
= PTR_ERR(fs_enet_dev
);
1160 fs_enet_data
.rx_ring
= 64;
1161 fs_enet_data
.tx_ring
= 8;
1162 fs_enet_data
.rx_copybreak
= 240;
1163 fs_enet_data
.use_napi
= 1;
1164 fs_enet_data
.napi_weight
= 17;
1166 snprintf((char*)&bus_id
[i
], BUS_ID_SIZE
, "%s", "fixed@10:1");
1167 fs_enet_data
.bus_id
= (char*)&bus_id
[i
];
1168 fs_enet_data
.init_ioports
= init_scc_ioports
;
1174 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
1183 platform_device_unregister(fs_enet_dev
);
1188 arch_initcall(fs_enet_of_init
);
1190 static int __init
fsl_pcmcia_of_init(void)
1192 struct device_node
*np
;
1194 * Register all the devices which type is "pcmcia"
1196 for_each_compatible_node(np
, "pcmcia", "fsl,pq-pcmcia")
1197 of_platform_device_create(np
, "m8xx-pcmcia", NULL
);
1201 arch_initcall(fsl_pcmcia_of_init
);
1203 static const char *smc_regs
= "regs";
1204 static const char *smc_pram
= "pram";
1206 static int __init
cpm_smc_uart_of_init(void)
1208 struct device_node
*np
;
1210 struct platform_device
*cpm_uart_dev
;
1213 for (np
= NULL
, i
= 0;
1214 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
1216 struct resource r
[3];
1217 struct fs_uart_platform_info cpm_uart_data
;
1221 memset(r
, 0, sizeof(r
));
1222 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
1224 ret
= of_address_to_resource(np
, 0, &r
[0]);
1228 r
[0].name
= smc_regs
;
1230 ret
= of_address_to_resource(np
, 1, &r
[1]);
1233 r
[1].name
= smc_pram
;
1235 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
1236 r
[2].flags
= IORESOURCE_IRQ
;
1239 platform_device_register_simple("fsl-cpm-smc:uart", i
, &r
[0], 3);
1241 if (IS_ERR(cpm_uart_dev
)) {
1242 ret
= PTR_ERR(cpm_uart_dev
);
1246 model
= of_get_property(np
, "model", NULL
);
1247 strcpy(cpm_uart_data
.fs_type
, model
);
1249 id
= of_get_property(np
, "device-id", NULL
);
1250 cpm_uart_data
.fs_no
= *id
;
1251 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
1253 cpm_uart_data
.tx_num_fifo
= 4;
1254 cpm_uart_data
.tx_buf_size
= 32;
1255 cpm_uart_data
.rx_num_fifo
= 4;
1256 cpm_uart_data
.rx_buf_size
= 32;
1259 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
1261 fs_uart_platform_info
));
1269 platform_device_unregister(cpm_uart_dev
);
1274 arch_initcall(cpm_smc_uart_of_init
);
1276 #endif /* CONFIG_8xx */
1277 #endif /* CONFIG_PPC_CPM_NEW_BINDING */
1279 static int __init
of_fsl_spi_probe(char *type
, char *compatible
, u32 sysclk
,
1280 struct spi_board_info
*board_infos
,
1281 unsigned int num_board_infos
,
1282 void (*activate_cs
)(u8 cs
, u8 polarity
),
1283 void (*deactivate_cs
)(u8 cs
, u8 polarity
))
1285 struct device_node
*np
;
1288 for_each_compatible_node(np
, type
, compatible
) {
1292 struct resource res
[2];
1293 struct platform_device
*pdev
;
1294 struct fsl_spi_platform_data pdata
= {
1295 .activate_cs
= activate_cs
,
1296 .deactivate_cs
= deactivate_cs
,
1299 memset(res
, 0, sizeof(res
));
1301 pdata
.sysclk
= sysclk
;
1303 prop
= of_get_property(np
, "reg", NULL
);
1306 pdata
.bus_num
= *(u32
*)prop
;
1308 prop
= of_get_property(np
, "cell-index", NULL
);
1312 prop
= of_get_property(np
, "mode", NULL
);
1313 if (prop
&& !strcmp(prop
, "cpu-qe"))
1316 for (j
= 0; j
< num_board_infos
; j
++) {
1317 if (board_infos
[j
].bus_num
== pdata
.bus_num
)
1318 pdata
.max_chipselect
++;
1321 if (!pdata
.max_chipselect
)
1324 ret
= of_address_to_resource(np
, 0, &res
[0]);
1328 ret
= of_irq_to_resource(np
, 0, &res
[1]);
1332 pdev
= platform_device_alloc("mpc83xx_spi", i
);
1336 ret
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
1340 ret
= platform_device_add_resources(pdev
, res
,
1345 ret
= platform_device_add(pdev
);
1351 platform_device_del(pdev
);
1353 pr_err("%s: registration failed\n", np
->full_name
);
1361 int __init
fsl_spi_init(struct spi_board_info
*board_infos
,
1362 unsigned int num_board_infos
,
1363 void (*activate_cs
)(u8 cs
, u8 polarity
),
1364 void (*deactivate_cs
)(u8 cs
, u8 polarity
))
1369 #ifdef CONFIG_QUICC_ENGINE
1370 /* SPI controller is either clocked from QE or SoC clock */
1371 sysclk
= get_brgfreq();
1374 struct device_node
*np
;
1378 np
= of_find_node_by_type(NULL
, "soc");
1382 freq
= of_get_property(np
, "clock-frequency", &size
);
1383 if (!freq
|| size
!= sizeof(*freq
) || *freq
== 0) {
1384 freq
= of_get_property(np
, "bus-frequency", &size
);
1385 if (!freq
|| size
!= sizeof(*freq
) || *freq
== 0) {
1395 ret
= of_fsl_spi_probe(NULL
, "fsl,spi", sysclk
, board_infos
,
1396 num_board_infos
, activate_cs
, deactivate_cs
);
1398 of_fsl_spi_probe("spi", "fsl_spi", sysclk
, board_infos
,
1399 num_board_infos
, activate_cs
, deactivate_cs
);
1401 return spi_register_board_info(board_infos
, num_board_infos
);
1404 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1405 static __be32 __iomem
*rstcr
;
1407 static int __init
setup_rstcr(void)
1409 struct device_node
*np
;
1410 np
= of_find_node_by_name(NULL
, "global-utilities");
1411 if ((np
&& of_get_property(np
, "fsl,has-rstcr", NULL
))) {
1412 const u32
*prop
= of_get_property(np
, "reg", NULL
);
1414 /* map reset control register
1415 * 0xE00B0 is offset of reset control register
1417 rstcr
= ioremap(get_immrbase() + *prop
+ 0xB0, 0xff);
1419 printk (KERN_EMERG
"Error: reset control "
1420 "register not mapped!\n");
1423 printk (KERN_INFO
"rstcr compatible register does not exist!\n");
1429 arch_initcall(setup_rstcr
);
1431 void fsl_rstcr_restart(char *cmd
)
1433 local_irq_disable();
1435 /* set reset control register */
1436 out_be32(rstcr
, 0x2); /* HRESET_REQ */