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_scc_ioports(struct fs_uart_platform_info
*);
42 static phys_addr_t immrbase
= -1;
44 phys_addr_t
get_immrbase(void)
46 struct device_node
*soc
;
51 soc
= of_find_node_by_type(NULL
, "soc");
54 const void *prop
= get_property(soc
, "reg", &size
);
57 immrbase
= of_translate_address(soc
, prop
);
64 EXPORT_SYMBOL(get_immrbase
);
68 static u32 brgfreq
= -1;
72 struct device_node
*node
;
77 node
= of_find_node_by_type(NULL
, "cpm");
80 const unsigned int *prop
= get_property(node
, "brg-frequency",
91 EXPORT_SYMBOL(get_brgfreq
);
93 static u32 fs_baudrate
= -1;
95 u32
get_baudrate(void)
97 struct device_node
*node
;
99 if (fs_baudrate
!= -1)
102 node
= of_find_node_by_type(NULL
, "serial");
105 const unsigned int *prop
= get_property(node
, "current-speed",
116 EXPORT_SYMBOL(get_baudrate
);
117 #endif /* CONFIG_CPM2 */
119 static int __init
gfar_mdio_of_init(void)
121 struct device_node
*np
;
123 struct platform_device
*mdio_dev
;
127 for (np
= NULL
, i
= 0;
128 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
131 struct device_node
*child
= NULL
;
132 struct gianfar_mdio_data mdio_data
;
134 memset(&res
, 0, sizeof(res
));
135 memset(&mdio_data
, 0, sizeof(mdio_data
));
137 ret
= of_address_to_resource(np
, 0, &res
);
142 platform_device_register_simple("fsl-gianfar_mdio",
144 if (IS_ERR(mdio_dev
)) {
145 ret
= PTR_ERR(mdio_dev
);
149 for (k
= 0; k
< 32; k
++)
150 mdio_data
.irq
[k
] = PHY_POLL
;
152 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
153 int irq
= irq_of_parse_and_map(child
, 0);
155 const u32
*id
= get_property(child
, "reg", NULL
);
156 mdio_data
.irq
[*id
] = irq
;
161 platform_device_add_data(mdio_dev
, &mdio_data
,
162 sizeof(struct gianfar_mdio_data
));
170 platform_device_unregister(mdio_dev
);
175 arch_initcall(gfar_mdio_of_init
);
177 static const char *gfar_tx_intr
= "tx";
178 static const char *gfar_rx_intr
= "rx";
179 static const char *gfar_err_intr
= "error";
182 static int __init
gfar_of_init(void)
184 struct device_node
*np
;
186 struct platform_device
*gfar_dev
;
190 for (np
= NULL
, i
= 0;
191 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
193 struct resource r
[4];
194 struct device_node
*phy
, *mdio
;
195 struct gianfar_platform_data gfar_data
;
196 const unsigned int *id
;
198 const void *mac_addr
;
202 memset(r
, 0, sizeof(r
));
203 memset(&gfar_data
, 0, sizeof(gfar_data
));
205 ret
= of_address_to_resource(np
, 0, &r
[0]);
209 of_irq_to_resource(np
, 0, &r
[1]);
211 model
= get_property(np
, "model", NULL
);
213 /* If we aren't the FEC we have multiple interrupts */
214 if (model
&& strcasecmp(model
, "FEC")) {
215 r
[1].name
= gfar_tx_intr
;
217 r
[2].name
= gfar_rx_intr
;
218 of_irq_to_resource(np
, 1, &r
[2]);
220 r
[3].name
= gfar_err_intr
;
221 of_irq_to_resource(np
, 2, &r
[3]);
227 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
230 if (IS_ERR(gfar_dev
)) {
231 ret
= PTR_ERR(gfar_dev
);
235 mac_addr
= get_property(np
, "local-mac-address", NULL
);
236 if (mac_addr
== NULL
)
237 mac_addr
= get_property(np
, "mac-address", NULL
);
238 if (mac_addr
== NULL
) {
240 mac_addr
= get_property(np
, "address", NULL
);
244 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
246 if (model
&& !strcasecmp(model
, "TSEC"))
247 gfar_data
.device_flags
=
248 FSL_GIANFAR_DEV_HAS_GIGABIT
|
249 FSL_GIANFAR_DEV_HAS_COALESCE
|
250 FSL_GIANFAR_DEV_HAS_RMON
|
251 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
252 if (model
&& !strcasecmp(model
, "eTSEC"))
253 gfar_data
.device_flags
=
254 FSL_GIANFAR_DEV_HAS_GIGABIT
|
255 FSL_GIANFAR_DEV_HAS_COALESCE
|
256 FSL_GIANFAR_DEV_HAS_RMON
|
257 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
258 FSL_GIANFAR_DEV_HAS_CSUM
|
259 FSL_GIANFAR_DEV_HAS_VLAN
|
260 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
262 ph
= get_property(np
, "phy-handle", NULL
);
263 phy
= of_find_node_by_phandle(*ph
);
270 mdio
= of_get_parent(phy
);
272 id
= get_property(phy
, "reg", NULL
);
273 ret
= of_address_to_resource(mdio
, 0, &res
);
280 gfar_data
.phy_id
= *id
;
281 gfar_data
.bus_id
= res
.start
;
287 platform_device_add_data(gfar_dev
, &gfar_data
,
289 gianfar_platform_data
));
297 platform_device_unregister(gfar_dev
);
302 arch_initcall(gfar_of_init
);
304 static int __init
fsl_i2c_of_init(void)
306 struct device_node
*np
;
308 struct platform_device
*i2c_dev
;
311 for (np
= NULL
, i
= 0;
312 (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
;
314 struct resource r
[2];
315 struct fsl_i2c_platform_data i2c_data
;
316 const unsigned char *flags
= NULL
;
318 memset(&r
, 0, sizeof(r
));
319 memset(&i2c_data
, 0, sizeof(i2c_data
));
321 ret
= of_address_to_resource(np
, 0, &r
[0]);
325 of_irq_to_resource(np
, 0, &r
[1]);
327 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
328 if (IS_ERR(i2c_dev
)) {
329 ret
= PTR_ERR(i2c_dev
);
333 i2c_data
.device_flags
= 0;
334 flags
= get_property(np
, "dfsrr", NULL
);
336 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
338 flags
= get_property(np
, "fsl5200-clocking", NULL
);
340 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
343 platform_device_add_data(i2c_dev
, &i2c_data
,
345 fsl_i2c_platform_data
));
353 platform_device_unregister(i2c_dev
);
358 arch_initcall(fsl_i2c_of_init
);
360 #ifdef CONFIG_PPC_83xx
361 static int __init
mpc83xx_wdt_init(void)
364 struct device_node
*soc
, *np
;
365 struct platform_device
*dev
;
366 const unsigned int *freq
;
369 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
376 soc
= of_find_node_by_type(NULL
, "soc");
383 freq
= get_property(soc
, "bus-frequency", NULL
);
389 memset(&r
, 0, sizeof(r
));
391 ret
= of_address_to_resource(np
, 0, &r
);
395 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
401 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
411 platform_device_unregister(dev
);
420 arch_initcall(mpc83xx_wdt_init
);
423 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
426 return FSL_USB2_PHY_NONE
;
427 if (!strcasecmp(phy_type
, "ulpi"))
428 return FSL_USB2_PHY_ULPI
;
429 if (!strcasecmp(phy_type
, "utmi"))
430 return FSL_USB2_PHY_UTMI
;
431 if (!strcasecmp(phy_type
, "utmi_wide"))
432 return FSL_USB2_PHY_UTMI_WIDE
;
433 if (!strcasecmp(phy_type
, "serial"))
434 return FSL_USB2_PHY_SERIAL
;
436 return FSL_USB2_PHY_NONE
;
439 static int __init
fsl_usb_of_init(void)
441 struct device_node
*np
;
443 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr
= NULL
;
446 for (np
= NULL
, i
= 0;
447 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
449 struct resource r
[2];
450 struct fsl_usb2_platform_data usb_data
;
451 const unsigned char *prop
= NULL
;
453 memset(&r
, 0, sizeof(r
));
454 memset(&usb_data
, 0, sizeof(usb_data
));
456 ret
= of_address_to_resource(np
, 0, &r
[0]);
460 of_irq_to_resource(np
, 0, &r
[1]);
463 platform_device_register_simple("fsl-ehci", i
, r
, 2);
464 if (IS_ERR(usb_dev_mph
)) {
465 ret
= PTR_ERR(usb_dev_mph
);
469 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
470 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
472 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
474 prop
= get_property(np
, "port0", NULL
);
476 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
478 prop
= get_property(np
, "port1", NULL
);
480 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
482 prop
= get_property(np
, "phy_type", NULL
);
483 usb_data
.phy_mode
= determine_usb_phy(prop
);
486 platform_device_add_data(usb_dev_mph
, &usb_data
,
488 fsl_usb2_platform_data
));
494 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
496 struct resource r
[2];
497 struct fsl_usb2_platform_data usb_data
;
498 const unsigned char *prop
= NULL
;
500 memset(&r
, 0, sizeof(r
));
501 memset(&usb_data
, 0, sizeof(usb_data
));
503 ret
= of_address_to_resource(np
, 0, &r
[0]);
507 of_irq_to_resource(np
, 0, &r
[1]);
510 platform_device_register_simple("fsl-ehci", i
, r
, 2);
511 if (IS_ERR(usb_dev_dr
)) {
512 ret
= PTR_ERR(usb_dev_dr
);
516 usb_dev_dr
->dev
.coherent_dma_mask
= 0xffffffffUL
;
517 usb_dev_dr
->dev
.dma_mask
= &usb_dev_dr
->dev
.coherent_dma_mask
;
519 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
521 prop
= get_property(np
, "phy_type", NULL
);
522 usb_data
.phy_mode
= determine_usb_phy(prop
);
525 platform_device_add_data(usb_dev_dr
, &usb_data
,
527 fsl_usb2_platform_data
));
535 platform_device_unregister(usb_dev_dr
);
538 platform_device_unregister(usb_dev_mph
);
543 arch_initcall(fsl_usb_of_init
);
547 static const char fcc_regs
[] = "fcc_regs";
548 static const char fcc_regs_c
[] = "fcc_regs_c";
549 static const char fcc_pram
[] = "fcc_pram";
550 static char bus_id
[9][BUS_ID_SIZE
];
552 static int __init
fs_enet_of_init(void)
554 struct device_node
*np
;
556 struct platform_device
*fs_enet_dev
;
560 for (np
= NULL
, i
= 0;
561 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
563 struct resource r
[4];
564 struct device_node
*phy
, *mdio
;
565 struct fs_platform_info fs_enet_data
;
566 const unsigned int *id
, *phy_addr
, *phy_irq
;
567 const void *mac_addr
;
571 memset(r
, 0, sizeof(r
));
572 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
574 ret
= of_address_to_resource(np
, 0, &r
[0]);
577 r
[0].name
= fcc_regs
;
579 ret
= of_address_to_resource(np
, 1, &r
[1]);
582 r
[1].name
= fcc_pram
;
584 ret
= of_address_to_resource(np
, 2, &r
[2]);
587 r
[2].name
= fcc_regs_c
;
588 fs_enet_data
.fcc_regs_c
= r
[2].start
;
590 of_irq_to_resource(np
, 0, &r
[3]);
593 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
595 if (IS_ERR(fs_enet_dev
)) {
596 ret
= PTR_ERR(fs_enet_dev
);
600 model
= get_property(np
, "model", NULL
);
606 mac_addr
= get_property(np
, "mac-address", NULL
);
607 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
609 ph
= get_property(np
, "phy-handle", NULL
);
610 phy
= of_find_node_by_phandle(*ph
);
617 phy_addr
= get_property(phy
, "reg", NULL
);
618 fs_enet_data
.phy_addr
= *phy_addr
;
620 phy_irq
= get_property(phy
, "interrupts", NULL
);
622 id
= get_property(np
, "device-id", NULL
);
623 fs_enet_data
.fs_no
= *id
;
624 strcpy(fs_enet_data
.fs_type
, model
);
626 mdio
= of_get_parent(phy
);
627 ret
= of_address_to_resource(mdio
, 0, &res
);
634 fs_enet_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
635 fs_enet_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
637 if (strstr(model
, "FCC")) {
638 int fcc_index
= *id
- 1;
639 const unsigned char *mdio_bb_prop
;
641 fs_enet_data
.dpram_offset
= (u32
)cpm_dpram_addr(0);
642 fs_enet_data
.rx_ring
= 32;
643 fs_enet_data
.tx_ring
= 32;
644 fs_enet_data
.rx_copybreak
= 240;
645 fs_enet_data
.use_napi
= 0;
646 fs_enet_data
.napi_weight
= 17;
647 fs_enet_data
.mem_offset
= FCC_MEM_OFFSET(fcc_index
);
648 fs_enet_data
.cp_page
= CPM_CR_FCC_PAGE(fcc_index
);
649 fs_enet_data
.cp_block
= CPM_CR_FCC_SBLOCK(fcc_index
);
651 snprintf((char*)&bus_id
[(*id
)], BUS_ID_SIZE
, "%x:%02x",
652 (u32
)res
.start
, fs_enet_data
.phy_addr
);
653 fs_enet_data
.bus_id
= (char*)&bus_id
[(*id
)];
654 fs_enet_data
.init_ioports
= init_fcc_ioports
;
656 mdio_bb_prop
= get_property(phy
, "bitbang", NULL
);
658 struct platform_device
*fs_enet_mdio_bb_dev
;
659 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data
;
661 fs_enet_mdio_bb_dev
=
662 platform_device_register_simple("fsl-bb-mdio",
664 memset(&fs_enet_mdio_bb_data
, 0,
665 sizeof(struct fs_mii_bb_platform_info
));
666 fs_enet_mdio_bb_data
.mdio_dat
.bit
=
668 fs_enet_mdio_bb_data
.mdio_dir
.bit
=
670 fs_enet_mdio_bb_data
.mdc_dat
.bit
=
672 fs_enet_mdio_bb_data
.mdio_port
=
674 fs_enet_mdio_bb_data
.mdc_port
=
676 fs_enet_mdio_bb_data
.delay
=
679 fs_enet_mdio_bb_data
.irq
[0] = phy_irq
[0];
680 fs_enet_mdio_bb_data
.irq
[1] = -1;
681 fs_enet_mdio_bb_data
.irq
[2] = -1;
682 fs_enet_mdio_bb_data
.irq
[3] = phy_irq
[0];
683 fs_enet_mdio_bb_data
.irq
[31] = -1;
685 fs_enet_mdio_bb_data
.mdio_dat
.offset
=
686 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
687 fs_enet_mdio_bb_data
.mdio_dir
.offset
=
688 (u32
)&cpm2_immr
->im_ioport
.iop_pdirc
;
689 fs_enet_mdio_bb_data
.mdc_dat
.offset
=
690 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
692 ret
= platform_device_add_data(
694 &fs_enet_mdio_bb_data
,
695 sizeof(struct fs_mii_bb_platform_info
));
703 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
713 platform_device_unregister(fs_enet_dev
);
718 arch_initcall(fs_enet_of_init
);
720 static const char scc_regs
[] = "regs";
721 static const char scc_pram
[] = "pram";
723 static int __init
cpm_uart_of_init(void)
725 struct device_node
*np
;
727 struct platform_device
*cpm_uart_dev
;
730 for (np
= NULL
, i
= 0;
731 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
733 struct resource r
[3];
734 struct fs_uart_platform_info cpm_uart_data
;
738 memset(r
, 0, sizeof(r
));
739 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
741 ret
= of_address_to_resource(np
, 0, &r
[0]);
745 r
[0].name
= scc_regs
;
747 ret
= of_address_to_resource(np
, 1, &r
[1]);
750 r
[1].name
= scc_pram
;
752 of_irq_to_resource(np
, 0, &r
[2]);
755 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
757 if (IS_ERR(cpm_uart_dev
)) {
758 ret
= PTR_ERR(cpm_uart_dev
);
762 id
= get_property(np
, "device-id", NULL
);
763 cpm_uart_data
.fs_no
= *id
;
765 model
= (char*)get_property(np
, "model", NULL
);
766 strcpy(cpm_uart_data
.fs_type
, model
);
768 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
770 cpm_uart_data
.tx_num_fifo
= 4;
771 cpm_uart_data
.tx_buf_size
= 32;
772 cpm_uart_data
.rx_num_fifo
= 4;
773 cpm_uart_data
.rx_buf_size
= 32;
774 cpm_uart_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
775 cpm_uart_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
778 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
780 fs_uart_platform_info
));
788 platform_device_unregister(cpm_uart_dev
);
793 arch_initcall(cpm_uart_of_init
);
794 #endif /* CONFIG_CPM2 */