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/spi/spi.h>
28 #include <linux/fsl_devices.h>
29 #include <linux/fs_enet_pd.h>
30 #include <linux/fs_uart_pd.h>
32 #include <asm/system.h>
33 #include <asm/atomic.h>
38 #include <sysdev/fsl_soc.h>
39 #include <mm/mmu_decl.h>
42 extern void init_fcc_ioports(struct fs_platform_info
*);
43 extern void init_fec_ioports(struct fs_platform_info
*);
44 extern void init_smc_ioports(struct fs_uart_platform_info
*);
45 static phys_addr_t immrbase
= -1;
47 phys_addr_t
get_immrbase(void)
49 struct device_node
*soc
;
54 soc
= of_find_node_by_type(NULL
, "soc");
57 const void *prop
= of_get_property(soc
, "reg", &size
);
60 immrbase
= of_translate_address(soc
, prop
);
67 EXPORT_SYMBOL(get_immrbase
);
69 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
71 static u32 brgfreq
= -1;
75 struct device_node
*node
;
76 const unsigned int *prop
;
82 node
= of_find_compatible_node(NULL
, NULL
, "fsl,cpm-brg");
84 prop
= of_get_property(node
, "clock-frequency", &size
);
85 if (prop
&& size
== 4)
92 /* Legacy device binding -- will go away when no users are left. */
93 node
= of_find_node_by_type(NULL
, "cpm");
95 prop
= of_get_property(node
, "brg-frequency", &size
);
96 if (prop
&& size
== 4)
105 EXPORT_SYMBOL(get_brgfreq
);
107 static u32 fs_baudrate
= -1;
109 u32
get_baudrate(void)
111 struct device_node
*node
;
113 if (fs_baudrate
!= -1)
116 node
= of_find_node_by_type(NULL
, "serial");
119 const unsigned int *prop
= of_get_property(node
,
120 "current-speed", &size
);
130 EXPORT_SYMBOL(get_baudrate
);
131 #endif /* CONFIG_CPM2 */
133 static int __init
gfar_mdio_of_init(void)
135 struct device_node
*np
;
137 struct platform_device
*mdio_dev
;
141 for (np
= NULL
, i
= 0;
142 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
145 struct device_node
*child
= NULL
;
146 struct gianfar_mdio_data mdio_data
;
148 memset(&res
, 0, sizeof(res
));
149 memset(&mdio_data
, 0, sizeof(mdio_data
));
151 ret
= of_address_to_resource(np
, 0, &res
);
156 platform_device_register_simple("fsl-gianfar_mdio",
158 if (IS_ERR(mdio_dev
)) {
159 ret
= PTR_ERR(mdio_dev
);
163 for (k
= 0; k
< 32; k
++)
164 mdio_data
.irq
[k
] = PHY_POLL
;
166 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
167 int irq
= irq_of_parse_and_map(child
, 0);
169 const u32
*id
= of_get_property(child
,
171 mdio_data
.irq
[*id
] = irq
;
176 platform_device_add_data(mdio_dev
, &mdio_data
,
177 sizeof(struct gianfar_mdio_data
));
185 platform_device_unregister(mdio_dev
);
190 arch_initcall(gfar_mdio_of_init
);
192 static const char *gfar_tx_intr
= "tx";
193 static const char *gfar_rx_intr
= "rx";
194 static const char *gfar_err_intr
= "error";
197 static int __init
gfar_of_init(void)
199 struct device_node
*np
;
201 struct platform_device
*gfar_dev
;
205 for (np
= NULL
, i
= 0;
206 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
208 struct resource r
[4];
209 struct device_node
*phy
, *mdio
;
210 struct gianfar_platform_data gfar_data
;
211 const unsigned int *id
;
214 const void *mac_addr
;
218 memset(r
, 0, sizeof(r
));
219 memset(&gfar_data
, 0, sizeof(gfar_data
));
221 ret
= of_address_to_resource(np
, 0, &r
[0]);
225 of_irq_to_resource(np
, 0, &r
[1]);
227 model
= of_get_property(np
, "model", NULL
);
229 /* If we aren't the FEC we have multiple interrupts */
230 if (model
&& strcasecmp(model
, "FEC")) {
231 r
[1].name
= gfar_tx_intr
;
233 r
[2].name
= gfar_rx_intr
;
234 of_irq_to_resource(np
, 1, &r
[2]);
236 r
[3].name
= gfar_err_intr
;
237 of_irq_to_resource(np
, 2, &r
[3]);
243 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
246 if (IS_ERR(gfar_dev
)) {
247 ret
= PTR_ERR(gfar_dev
);
251 mac_addr
= of_get_mac_address(np
);
253 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
255 if (model
&& !strcasecmp(model
, "TSEC"))
256 gfar_data
.device_flags
=
257 FSL_GIANFAR_DEV_HAS_GIGABIT
|
258 FSL_GIANFAR_DEV_HAS_COALESCE
|
259 FSL_GIANFAR_DEV_HAS_RMON
|
260 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
261 if (model
&& !strcasecmp(model
, "eTSEC"))
262 gfar_data
.device_flags
=
263 FSL_GIANFAR_DEV_HAS_GIGABIT
|
264 FSL_GIANFAR_DEV_HAS_COALESCE
|
265 FSL_GIANFAR_DEV_HAS_RMON
|
266 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
267 FSL_GIANFAR_DEV_HAS_CSUM
|
268 FSL_GIANFAR_DEV_HAS_VLAN
|
269 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
271 ctype
= of_get_property(np
, "phy-connection-type", NULL
);
273 /* We only care about rgmii-id. The rest are autodetected */
274 if (ctype
&& !strcmp(ctype
, "rgmii-id"))
275 gfar_data
.interface
= PHY_INTERFACE_MODE_RGMII_ID
;
277 gfar_data
.interface
= PHY_INTERFACE_MODE_MII
;
279 ph
= of_get_property(np
, "phy-handle", NULL
);
280 phy
= of_find_node_by_phandle(*ph
);
287 mdio
= of_get_parent(phy
);
289 id
= of_get_property(phy
, "reg", NULL
);
290 ret
= of_address_to_resource(mdio
, 0, &res
);
297 gfar_data
.phy_id
= *id
;
298 gfar_data
.bus_id
= res
.start
;
304 platform_device_add_data(gfar_dev
, &gfar_data
,
306 gianfar_platform_data
));
314 platform_device_unregister(gfar_dev
);
319 arch_initcall(gfar_of_init
);
321 #ifdef CONFIG_I2C_BOARDINFO
322 #include <linux/i2c.h>
323 struct i2c_driver_device
{
329 static struct i2c_driver_device i2c_devices
[] __initdata
= {
330 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
331 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
332 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
333 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
334 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
335 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
336 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
337 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
338 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
339 {"stm,m41t00", "rtc-ds1307", "m41t00"},
340 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
343 static int __init
of_find_i2c_driver(struct device_node
*node
,
344 struct i2c_board_info
*info
)
348 for (i
= 0; i
< ARRAY_SIZE(i2c_devices
); i
++) {
349 if (!of_device_is_compatible(node
, i2c_devices
[i
].of_device
))
351 if (strlcpy(info
->driver_name
, i2c_devices
[i
].i2c_driver
,
352 KOBJ_NAME_LEN
) >= KOBJ_NAME_LEN
||
353 strlcpy(info
->type
, i2c_devices
[i
].i2c_type
,
354 I2C_NAME_SIZE
) >= I2C_NAME_SIZE
)
361 static void __init
of_register_i2c_devices(struct device_node
*adap_node
,
364 struct device_node
*node
= NULL
;
366 while ((node
= of_get_next_child(adap_node
, node
))) {
367 struct i2c_board_info info
= {};
371 addr
= of_get_property(node
, "reg", &len
);
372 if (!addr
|| len
< sizeof(int) || *addr
> (1 << 10) - 1) {
373 printk(KERN_WARNING
"fsl_soc.c: invalid i2c device entry\n");
377 info
.irq
= irq_of_parse_and_map(node
, 0);
378 if (info
.irq
== NO_IRQ
)
381 if (of_find_i2c_driver(node
, &info
) < 0)
386 i2c_register_board_info(bus_num
, &info
, 1);
390 static int __init
fsl_i2c_of_init(void)
392 struct device_node
*np
;
394 struct platform_device
*i2c_dev
;
397 for (np
= NULL
, i
= 0;
398 (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
;
400 struct resource r
[2];
401 struct fsl_i2c_platform_data i2c_data
;
402 const unsigned char *flags
= NULL
;
404 memset(&r
, 0, sizeof(r
));
405 memset(&i2c_data
, 0, sizeof(i2c_data
));
407 ret
= of_address_to_resource(np
, 0, &r
[0]);
411 of_irq_to_resource(np
, 0, &r
[1]);
413 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
414 if (IS_ERR(i2c_dev
)) {
415 ret
= PTR_ERR(i2c_dev
);
419 i2c_data
.device_flags
= 0;
420 flags
= of_get_property(np
, "dfsrr", NULL
);
422 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
424 flags
= of_get_property(np
, "fsl5200-clocking", NULL
);
426 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
429 platform_device_add_data(i2c_dev
, &i2c_data
,
431 fsl_i2c_platform_data
));
435 of_register_i2c_devices(np
, i
);
441 platform_device_unregister(i2c_dev
);
446 arch_initcall(fsl_i2c_of_init
);
449 #ifdef CONFIG_PPC_83xx
450 static int __init
mpc83xx_wdt_init(void)
453 struct device_node
*soc
, *np
;
454 struct platform_device
*dev
;
455 const unsigned int *freq
;
458 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
465 soc
= of_find_node_by_type(NULL
, "soc");
472 freq
= of_get_property(soc
, "bus-frequency", NULL
);
478 memset(&r
, 0, sizeof(r
));
480 ret
= of_address_to_resource(np
, 0, &r
);
484 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
490 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
500 platform_device_unregister(dev
);
509 arch_initcall(mpc83xx_wdt_init
);
512 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
515 return FSL_USB2_PHY_NONE
;
516 if (!strcasecmp(phy_type
, "ulpi"))
517 return FSL_USB2_PHY_ULPI
;
518 if (!strcasecmp(phy_type
, "utmi"))
519 return FSL_USB2_PHY_UTMI
;
520 if (!strcasecmp(phy_type
, "utmi_wide"))
521 return FSL_USB2_PHY_UTMI_WIDE
;
522 if (!strcasecmp(phy_type
, "serial"))
523 return FSL_USB2_PHY_SERIAL
;
525 return FSL_USB2_PHY_NONE
;
528 static int __init
fsl_usb_of_init(void)
530 struct device_node
*np
;
532 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr_host
= NULL
,
533 *usb_dev_dr_client
= NULL
;
536 for (np
= NULL
, i
= 0;
537 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
539 struct resource r
[2];
540 struct fsl_usb2_platform_data usb_data
;
541 const unsigned char *prop
= NULL
;
543 memset(&r
, 0, sizeof(r
));
544 memset(&usb_data
, 0, sizeof(usb_data
));
546 ret
= of_address_to_resource(np
, 0, &r
[0]);
550 of_irq_to_resource(np
, 0, &r
[1]);
553 platform_device_register_simple("fsl-ehci", i
, r
, 2);
554 if (IS_ERR(usb_dev_mph
)) {
555 ret
= PTR_ERR(usb_dev_mph
);
559 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
560 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
562 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
564 prop
= of_get_property(np
, "port0", NULL
);
566 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
568 prop
= of_get_property(np
, "port1", NULL
);
570 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
572 prop
= of_get_property(np
, "phy_type", NULL
);
573 usb_data
.phy_mode
= determine_usb_phy(prop
);
576 platform_device_add_data(usb_dev_mph
, &usb_data
,
578 fsl_usb2_platform_data
));
584 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
586 struct resource r
[2];
587 struct fsl_usb2_platform_data usb_data
;
588 const unsigned char *prop
= NULL
;
590 memset(&r
, 0, sizeof(r
));
591 memset(&usb_data
, 0, sizeof(usb_data
));
593 ret
= of_address_to_resource(np
, 0, &r
[0]);
597 of_irq_to_resource(np
, 0, &r
[1]);
599 prop
= of_get_property(np
, "dr_mode", NULL
);
601 if (!prop
|| !strcmp(prop
, "host")) {
602 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
603 usb_dev_dr_host
= platform_device_register_simple(
604 "fsl-ehci", i
, r
, 2);
605 if (IS_ERR(usb_dev_dr_host
)) {
606 ret
= PTR_ERR(usb_dev_dr_host
);
609 } else if (prop
&& !strcmp(prop
, "peripheral")) {
610 usb_data
.operating_mode
= FSL_USB2_DR_DEVICE
;
611 usb_dev_dr_client
= platform_device_register_simple(
612 "fsl-usb2-udc", i
, r
, 2);
613 if (IS_ERR(usb_dev_dr_client
)) {
614 ret
= PTR_ERR(usb_dev_dr_client
);
617 } else if (prop
&& !strcmp(prop
, "otg")) {
618 usb_data
.operating_mode
= FSL_USB2_DR_OTG
;
619 usb_dev_dr_host
= platform_device_register_simple(
620 "fsl-ehci", i
, r
, 2);
621 if (IS_ERR(usb_dev_dr_host
)) {
622 ret
= PTR_ERR(usb_dev_dr_host
);
625 usb_dev_dr_client
= platform_device_register_simple(
626 "fsl-usb2-udc", i
, r
, 2);
627 if (IS_ERR(usb_dev_dr_client
)) {
628 ret
= PTR_ERR(usb_dev_dr_client
);
636 prop
= of_get_property(np
, "phy_type", NULL
);
637 usb_data
.phy_mode
= determine_usb_phy(prop
);
639 if (usb_dev_dr_host
) {
640 usb_dev_dr_host
->dev
.coherent_dma_mask
= 0xffffffffUL
;
641 usb_dev_dr_host
->dev
.dma_mask
= &usb_dev_dr_host
->
642 dev
.coherent_dma_mask
;
643 if ((ret
= platform_device_add_data(usb_dev_dr_host
,
644 &usb_data
, sizeof(struct
645 fsl_usb2_platform_data
))))
648 if (usb_dev_dr_client
) {
649 usb_dev_dr_client
->dev
.coherent_dma_mask
= 0xffffffffUL
;
650 usb_dev_dr_client
->dev
.dma_mask
= &usb_dev_dr_client
->
651 dev
.coherent_dma_mask
;
652 if ((ret
= platform_device_add_data(usb_dev_dr_client
,
653 &usb_data
, sizeof(struct
654 fsl_usb2_platform_data
))))
662 platform_device_unregister(usb_dev_dr_host
);
663 if (usb_dev_dr_client
)
664 platform_device_unregister(usb_dev_dr_client
);
667 platform_device_unregister(usb_dev_mph
);
672 arch_initcall(fsl_usb_of_init
);
674 #ifndef CONFIG_PPC_CPM_NEW_BINDING
677 extern void init_scc_ioports(struct fs_uart_platform_info
*);
679 static const char fcc_regs
[] = "fcc_regs";
680 static const char fcc_regs_c
[] = "fcc_regs_c";
681 static const char fcc_pram
[] = "fcc_pram";
682 static char bus_id
[9][BUS_ID_SIZE
];
684 static int __init
fs_enet_of_init(void)
686 struct device_node
*np
;
688 struct platform_device
*fs_enet_dev
;
692 for (np
= NULL
, i
= 0;
693 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
695 struct resource r
[4];
696 struct device_node
*phy
, *mdio
;
697 struct fs_platform_info fs_enet_data
;
698 const unsigned int *id
, *phy_addr
, *phy_irq
;
699 const void *mac_addr
;
703 memset(r
, 0, sizeof(r
));
704 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
706 ret
= of_address_to_resource(np
, 0, &r
[0]);
709 r
[0].name
= fcc_regs
;
711 ret
= of_address_to_resource(np
, 1, &r
[1]);
714 r
[1].name
= fcc_pram
;
716 ret
= of_address_to_resource(np
, 2, &r
[2]);
719 r
[2].name
= fcc_regs_c
;
720 fs_enet_data
.fcc_regs_c
= r
[2].start
;
722 of_irq_to_resource(np
, 0, &r
[3]);
725 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
727 if (IS_ERR(fs_enet_dev
)) {
728 ret
= PTR_ERR(fs_enet_dev
);
732 model
= of_get_property(np
, "model", NULL
);
738 mac_addr
= of_get_mac_address(np
);
740 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
742 ph
= of_get_property(np
, "phy-handle", NULL
);
743 phy
= of_find_node_by_phandle(*ph
);
750 phy_addr
= of_get_property(phy
, "reg", NULL
);
751 fs_enet_data
.phy_addr
= *phy_addr
;
753 phy_irq
= of_get_property(phy
, "interrupts", NULL
);
755 id
= of_get_property(np
, "device-id", NULL
);
756 fs_enet_data
.fs_no
= *id
;
757 strcpy(fs_enet_data
.fs_type
, model
);
759 mdio
= of_get_parent(phy
);
760 ret
= of_address_to_resource(mdio
, 0, &res
);
767 fs_enet_data
.clk_rx
= *((u32
*)of_get_property(np
,
769 fs_enet_data
.clk_tx
= *((u32
*)of_get_property(np
,
772 if (strstr(model
, "FCC")) {
773 int fcc_index
= *id
- 1;
774 const unsigned char *mdio_bb_prop
;
776 fs_enet_data
.dpram_offset
= (u32
)cpm_dpram_addr(0);
777 fs_enet_data
.rx_ring
= 32;
778 fs_enet_data
.tx_ring
= 32;
779 fs_enet_data
.rx_copybreak
= 240;
780 fs_enet_data
.use_napi
= 0;
781 fs_enet_data
.napi_weight
= 17;
782 fs_enet_data
.mem_offset
= FCC_MEM_OFFSET(fcc_index
);
783 fs_enet_data
.cp_page
= CPM_CR_FCC_PAGE(fcc_index
);
784 fs_enet_data
.cp_block
= CPM_CR_FCC_SBLOCK(fcc_index
);
786 snprintf((char*)&bus_id
[(*id
)], BUS_ID_SIZE
, "%x:%02x",
787 (u32
)res
.start
, fs_enet_data
.phy_addr
);
788 fs_enet_data
.bus_id
= (char*)&bus_id
[(*id
)];
789 fs_enet_data
.init_ioports
= init_fcc_ioports
;
791 mdio_bb_prop
= of_get_property(phy
, "bitbang", NULL
);
793 struct platform_device
*fs_enet_mdio_bb_dev
;
794 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data
;
796 fs_enet_mdio_bb_dev
=
797 platform_device_register_simple("fsl-bb-mdio",
799 memset(&fs_enet_mdio_bb_data
, 0,
800 sizeof(struct fs_mii_bb_platform_info
));
801 fs_enet_mdio_bb_data
.mdio_dat
.bit
=
803 fs_enet_mdio_bb_data
.mdio_dir
.bit
=
805 fs_enet_mdio_bb_data
.mdc_dat
.bit
=
807 fs_enet_mdio_bb_data
.mdio_port
=
809 fs_enet_mdio_bb_data
.mdc_port
=
811 fs_enet_mdio_bb_data
.delay
=
814 fs_enet_mdio_bb_data
.irq
[0] = phy_irq
[0];
815 fs_enet_mdio_bb_data
.irq
[1] = -1;
816 fs_enet_mdio_bb_data
.irq
[2] = -1;
817 fs_enet_mdio_bb_data
.irq
[3] = phy_irq
[0];
818 fs_enet_mdio_bb_data
.irq
[31] = -1;
820 fs_enet_mdio_bb_data
.mdio_dat
.offset
=
821 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
822 fs_enet_mdio_bb_data
.mdio_dir
.offset
=
823 (u32
)&cpm2_immr
->im_ioport
.iop_pdirc
;
824 fs_enet_mdio_bb_data
.mdc_dat
.offset
=
825 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
827 ret
= platform_device_add_data(
829 &fs_enet_mdio_bb_data
,
830 sizeof(struct fs_mii_bb_platform_info
));
838 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
848 platform_device_unregister(fs_enet_dev
);
853 arch_initcall(fs_enet_of_init
);
855 static const char scc_regs
[] = "regs";
856 static const char scc_pram
[] = "pram";
858 static int __init
cpm_uart_of_init(void)
860 struct device_node
*np
;
862 struct platform_device
*cpm_uart_dev
;
865 for (np
= NULL
, i
= 0;
866 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
868 struct resource r
[3];
869 struct fs_uart_platform_info cpm_uart_data
;
873 memset(r
, 0, sizeof(r
));
874 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
876 ret
= of_address_to_resource(np
, 0, &r
[0]);
880 r
[0].name
= scc_regs
;
882 ret
= of_address_to_resource(np
, 1, &r
[1]);
885 r
[1].name
= scc_pram
;
887 of_irq_to_resource(np
, 0, &r
[2]);
890 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
892 if (IS_ERR(cpm_uart_dev
)) {
893 ret
= PTR_ERR(cpm_uart_dev
);
897 id
= of_get_property(np
, "device-id", NULL
);
898 cpm_uart_data
.fs_no
= *id
;
900 model
= of_get_property(np
, "model", NULL
);
901 strcpy(cpm_uart_data
.fs_type
, model
);
903 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
905 cpm_uart_data
.tx_num_fifo
= 4;
906 cpm_uart_data
.tx_buf_size
= 32;
907 cpm_uart_data
.rx_num_fifo
= 4;
908 cpm_uart_data
.rx_buf_size
= 32;
909 cpm_uart_data
.clk_rx
= *((u32
*)of_get_property(np
,
911 cpm_uart_data
.clk_tx
= *((u32
*)of_get_property(np
,
915 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
917 fs_uart_platform_info
));
925 platform_device_unregister(cpm_uart_dev
);
930 arch_initcall(cpm_uart_of_init
);
931 #endif /* CONFIG_CPM2 */
935 extern void init_scc_ioports(struct fs_platform_info
*);
936 extern int platform_device_skip(const char *model
, int id
);
938 static int __init
fs_enet_mdio_of_init(void)
940 struct device_node
*np
;
942 struct platform_device
*mdio_dev
;
946 for (np
= NULL
, i
= 0;
947 (np
= of_find_compatible_node(np
, "mdio", "fs_enet")) != NULL
;
949 struct fs_mii_fec_platform_info mdio_data
;
951 memset(&res
, 0, sizeof(res
));
952 memset(&mdio_data
, 0, sizeof(mdio_data
));
954 ret
= of_address_to_resource(np
, 0, &res
);
959 platform_device_register_simple("fsl-cpm-fec-mdio",
961 if (IS_ERR(mdio_dev
)) {
962 ret
= PTR_ERR(mdio_dev
);
966 mdio_data
.mii_speed
= ((((ppc_proc_freq
+ 4999999) / 2500000) / 2) & 0x3F) << 1;
969 platform_device_add_data(mdio_dev
, &mdio_data
,
970 sizeof(struct fs_mii_fec_platform_info
));
977 platform_device_unregister(mdio_dev
);
982 arch_initcall(fs_enet_mdio_of_init
);
984 static const char *enet_regs
= "regs";
985 static const char *enet_pram
= "pram";
986 static const char *enet_irq
= "interrupt";
987 static char bus_id
[9][BUS_ID_SIZE
];
989 static int __init
fs_enet_of_init(void)
991 struct device_node
*np
;
993 struct platform_device
*fs_enet_dev
= NULL
;
997 for (np
= NULL
, i
= 0;
998 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
1000 struct resource r
[4];
1001 struct device_node
*phy
= NULL
, *mdio
= NULL
;
1002 struct fs_platform_info fs_enet_data
;
1003 const unsigned int *id
;
1004 const unsigned int *phy_addr
;
1005 const void *mac_addr
;
1009 memset(r
, 0, sizeof(r
));
1010 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
1012 model
= of_get_property(np
, "model", NULL
);
1013 if (model
== NULL
) {
1018 id
= of_get_property(np
, "device-id", NULL
);
1019 fs_enet_data
.fs_no
= *id
;
1021 if (platform_device_skip(model
, *id
))
1024 ret
= of_address_to_resource(np
, 0, &r
[0]);
1027 r
[0].name
= enet_regs
;
1029 mac_addr
= of_get_mac_address(np
);
1031 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
1033 ph
= of_get_property(np
, "phy-handle", NULL
);
1035 phy
= of_find_node_by_phandle(*ph
);
1038 phy_addr
= of_get_property(phy
, "reg", NULL
);
1039 fs_enet_data
.phy_addr
= *phy_addr
;
1040 fs_enet_data
.has_phy
= 1;
1042 mdio
= of_get_parent(phy
);
1043 ret
= of_address_to_resource(mdio
, 0, &res
);
1051 model
= of_get_property(np
, "model", NULL
);
1052 strcpy(fs_enet_data
.fs_type
, model
);
1054 if (strstr(model
, "FEC")) {
1055 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
1056 r
[1].flags
= IORESOURCE_IRQ
;
1057 r
[1].name
= enet_irq
;
1060 platform_device_register_simple("fsl-cpm-fec", i
, &r
[0], 2);
1062 if (IS_ERR(fs_enet_dev
)) {
1063 ret
= PTR_ERR(fs_enet_dev
);
1067 fs_enet_data
.rx_ring
= 128;
1068 fs_enet_data
.tx_ring
= 16;
1069 fs_enet_data
.rx_copybreak
= 240;
1070 fs_enet_data
.use_napi
= 1;
1071 fs_enet_data
.napi_weight
= 17;
1073 snprintf((char*)&bus_id
[i
], BUS_ID_SIZE
, "%x:%02x",
1074 (u32
)res
.start
, fs_enet_data
.phy_addr
);
1075 fs_enet_data
.bus_id
= (char*)&bus_id
[i
];
1076 fs_enet_data
.init_ioports
= init_fec_ioports
;
1078 if (strstr(model
, "SCC")) {
1079 ret
= of_address_to_resource(np
, 1, &r
[1]);
1082 r
[1].name
= enet_pram
;
1084 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
1085 r
[2].flags
= IORESOURCE_IRQ
;
1086 r
[2].name
= enet_irq
;
1089 platform_device_register_simple("fsl-cpm-scc", i
, &r
[0], 3);
1091 if (IS_ERR(fs_enet_dev
)) {
1092 ret
= PTR_ERR(fs_enet_dev
);
1096 fs_enet_data
.rx_ring
= 64;
1097 fs_enet_data
.tx_ring
= 8;
1098 fs_enet_data
.rx_copybreak
= 240;
1099 fs_enet_data
.use_napi
= 1;
1100 fs_enet_data
.napi_weight
= 17;
1102 snprintf((char*)&bus_id
[i
], BUS_ID_SIZE
, "%s", "fixed@10:1");
1103 fs_enet_data
.bus_id
= (char*)&bus_id
[i
];
1104 fs_enet_data
.init_ioports
= init_scc_ioports
;
1110 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
1119 platform_device_unregister(fs_enet_dev
);
1124 arch_initcall(fs_enet_of_init
);
1126 static int __init
fsl_pcmcia_of_init(void)
1128 struct device_node
*np
= NULL
;
1130 * Register all the devices which type is "pcmcia"
1132 while ((np
= of_find_compatible_node(np
,
1133 "pcmcia", "fsl,pq-pcmcia")) != NULL
)
1134 of_platform_device_create(np
, "m8xx-pcmcia", NULL
);
1138 arch_initcall(fsl_pcmcia_of_init
);
1140 static const char *smc_regs
= "regs";
1141 static const char *smc_pram
= "pram";
1143 static int __init
cpm_smc_uart_of_init(void)
1145 struct device_node
*np
;
1147 struct platform_device
*cpm_uart_dev
;
1150 for (np
= NULL
, i
= 0;
1151 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
1153 struct resource r
[3];
1154 struct fs_uart_platform_info cpm_uart_data
;
1158 memset(r
, 0, sizeof(r
));
1159 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
1161 ret
= of_address_to_resource(np
, 0, &r
[0]);
1165 r
[0].name
= smc_regs
;
1167 ret
= of_address_to_resource(np
, 1, &r
[1]);
1170 r
[1].name
= smc_pram
;
1172 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
1173 r
[2].flags
= IORESOURCE_IRQ
;
1176 platform_device_register_simple("fsl-cpm-smc:uart", i
, &r
[0], 3);
1178 if (IS_ERR(cpm_uart_dev
)) {
1179 ret
= PTR_ERR(cpm_uart_dev
);
1183 model
= of_get_property(np
, "model", NULL
);
1184 strcpy(cpm_uart_data
.fs_type
, model
);
1186 id
= of_get_property(np
, "device-id", NULL
);
1187 cpm_uart_data
.fs_no
= *id
;
1188 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
1190 cpm_uart_data
.tx_num_fifo
= 4;
1191 cpm_uart_data
.tx_buf_size
= 32;
1192 cpm_uart_data
.rx_num_fifo
= 4;
1193 cpm_uart_data
.rx_buf_size
= 32;
1196 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
1198 fs_uart_platform_info
));
1206 platform_device_unregister(cpm_uart_dev
);
1211 arch_initcall(cpm_smc_uart_of_init
);
1213 #endif /* CONFIG_8xx */
1214 #endif /* CONFIG_PPC_CPM_NEW_BINDING */
1216 int __init
fsl_spi_init(struct spi_board_info
*board_infos
,
1217 unsigned int num_board_infos
,
1218 void (*activate_cs
)(u8 cs
, u8 polarity
),
1219 void (*deactivate_cs
)(u8 cs
, u8 polarity
))
1221 struct device_node
*np
;
1225 /* SPI controller is either clocked from QE or SoC clock */
1226 np
= of_find_node_by_type(NULL
, "qe");
1228 np
= of_find_node_by_type(NULL
, "soc");
1233 sysclk
= of_get_property(np
, "bus-frequency", NULL
);
1237 for (np
= NULL
, i
= 1;
1238 (np
= of_find_compatible_node(np
, "spi", "fsl_spi")) != NULL
;
1243 struct resource res
[2];
1244 struct platform_device
*pdev
;
1245 struct fsl_spi_platform_data pdata
= {
1246 .activate_cs
= activate_cs
,
1247 .deactivate_cs
= deactivate_cs
,
1250 memset(res
, 0, sizeof(res
));
1252 pdata
.sysclk
= *sysclk
;
1254 prop
= of_get_property(np
, "reg", NULL
);
1257 pdata
.bus_num
= *(u32
*)prop
;
1259 prop
= of_get_property(np
, "mode", NULL
);
1260 if (prop
&& !strcmp(prop
, "cpu-qe"))
1263 for (j
= 0; j
< num_board_infos
; j
++) {
1264 if (board_infos
[j
].bus_num
== pdata
.bus_num
)
1265 pdata
.max_chipselect
++;
1268 if (!pdata
.max_chipselect
)
1271 ret
= of_address_to_resource(np
, 0, &res
[0]);
1275 ret
= of_irq_to_resource(np
, 0, &res
[1]);
1279 pdev
= platform_device_alloc("mpc83xx_spi", i
);
1283 ret
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
1287 ret
= platform_device_add_resources(pdev
, res
,
1292 ret
= platform_device_register(pdev
);
1298 platform_device_del(pdev
);
1303 return spi_register_board_info(board_infos
, num_board_infos
);
1306 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1307 static __be32 __iomem
*rstcr
;
1309 static int __init
setup_rstcr(void)
1311 struct device_node
*np
;
1312 np
= of_find_node_by_name(NULL
, "global-utilities");
1313 if ((np
&& of_get_property(np
, "fsl,has-rstcr", NULL
))) {
1314 const u32
*prop
= of_get_property(np
, "reg", NULL
);
1316 /* map reset control register
1317 * 0xE00B0 is offset of reset control register
1319 rstcr
= ioremap(get_immrbase() + *prop
+ 0xB0, 0xff);
1321 printk (KERN_EMERG
"Error: reset control "
1322 "register not mapped!\n");
1325 printk (KERN_INFO
"rstcr compatible register does not exist!\n");
1331 arch_initcall(setup_rstcr
);
1333 void fsl_rstcr_restart(char *cmd
)
1335 local_irq_disable();
1337 /* set reset control register */
1338 out_be32(rstcr
, 0x2); /* HRESET_REQ */