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/fsl_devices.h>
26 #include <linux/fs_enet_pd.h>
27 #include <linux/fs_uart_pd.h>
29 #include <asm/system.h>
30 #include <asm/atomic.h>
35 #include <sysdev/fsl_soc.h>
36 #include <mm/mmu_decl.h>
39 extern void init_fcc_ioports(struct fs_platform_info
*);
40 extern void init_scc_ioports(struct fs_uart_platform_info
*);
41 static phys_addr_t immrbase
= -1;
43 phys_addr_t
get_immrbase(void)
45 struct device_node
*soc
;
50 soc
= of_find_node_by_type(NULL
, "soc");
53 const void *prop
= get_property(soc
, "reg", &size
);
56 immrbase
= of_translate_address(soc
, prop
);
63 EXPORT_SYMBOL(get_immrbase
);
67 static u32 brgfreq
= -1;
71 struct device_node
*node
;
76 node
= of_find_node_by_type(NULL
, "cpm");
79 const unsigned int *prop
= get_property(node
, "brg-frequency",
90 EXPORT_SYMBOL(get_brgfreq
);
92 static u32 fs_baudrate
= -1;
94 u32
get_baudrate(void)
96 struct device_node
*node
;
98 if (fs_baudrate
!= -1)
101 node
= of_find_node_by_type(NULL
, "serial");
104 const unsigned int *prop
= get_property(node
, "current-speed",
115 EXPORT_SYMBOL(get_baudrate
);
116 #endif /* CONFIG_CPM2 */
118 static int __init
gfar_mdio_of_init(void)
120 struct device_node
*np
;
122 struct platform_device
*mdio_dev
;
126 for (np
= NULL
, i
= 0;
127 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
130 struct device_node
*child
= NULL
;
131 struct gianfar_mdio_data mdio_data
;
133 memset(&res
, 0, sizeof(res
));
134 memset(&mdio_data
, 0, sizeof(mdio_data
));
136 ret
= of_address_to_resource(np
, 0, &res
);
141 platform_device_register_simple("fsl-gianfar_mdio",
143 if (IS_ERR(mdio_dev
)) {
144 ret
= PTR_ERR(mdio_dev
);
148 for (k
= 0; k
< 32; k
++)
149 mdio_data
.irq
[k
] = -1;
151 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
152 int irq
= irq_of_parse_and_map(child
, 0);
154 const u32
*id
= get_property(child
, "reg", NULL
);
155 mdio_data
.irq
[*id
] = irq
;
160 platform_device_add_data(mdio_dev
, &mdio_data
,
161 sizeof(struct gianfar_mdio_data
));
169 platform_device_unregister(mdio_dev
);
174 arch_initcall(gfar_mdio_of_init
);
176 static const char *gfar_tx_intr
= "tx";
177 static const char *gfar_rx_intr
= "rx";
178 static const char *gfar_err_intr
= "error";
180 static int __init
gfar_of_init(void)
182 struct device_node
*np
;
184 struct platform_device
*gfar_dev
;
188 for (np
= NULL
, i
= 0;
189 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
191 struct resource r
[4];
192 struct device_node
*phy
, *mdio
;
193 struct gianfar_platform_data gfar_data
;
194 const unsigned int *id
;
196 const void *mac_addr
;
200 memset(r
, 0, sizeof(r
));
201 memset(&gfar_data
, 0, sizeof(gfar_data
));
203 ret
= of_address_to_resource(np
, 0, &r
[0]);
207 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
208 r
[1].flags
= IORESOURCE_IRQ
;
210 model
= get_property(np
, "model", NULL
);
212 /* If we aren't the FEC we have multiple interrupts */
213 if (model
&& strcasecmp(model
, "FEC")) {
214 r
[1].name
= gfar_tx_intr
;
216 r
[2].name
= gfar_rx_intr
;
217 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 1);
218 r
[2].flags
= IORESOURCE_IRQ
;
220 r
[3].name
= gfar_err_intr
;
221 r
[3].start
= r
[3].end
= irq_of_parse_and_map(np
, 2);
222 r
[3].flags
= IORESOURCE_IRQ
;
228 platform_device_register_simple("fsl-gianfar", i
, &r
[0],
231 if (IS_ERR(gfar_dev
)) {
232 ret
= PTR_ERR(gfar_dev
);
236 mac_addr
= get_property(np
, "local-mac-address", NULL
);
237 if (mac_addr
== NULL
)
238 mac_addr
= get_property(np
, "mac-address", NULL
);
239 if (mac_addr
== NULL
) {
241 mac_addr
= get_property(np
, "address", NULL
);
245 memcpy(gfar_data
.mac_addr
, mac_addr
, 6);
247 if (model
&& !strcasecmp(model
, "TSEC"))
248 gfar_data
.device_flags
=
249 FSL_GIANFAR_DEV_HAS_GIGABIT
|
250 FSL_GIANFAR_DEV_HAS_COALESCE
|
251 FSL_GIANFAR_DEV_HAS_RMON
|
252 FSL_GIANFAR_DEV_HAS_MULTI_INTR
;
253 if (model
&& !strcasecmp(model
, "eTSEC"))
254 gfar_data
.device_flags
=
255 FSL_GIANFAR_DEV_HAS_GIGABIT
|
256 FSL_GIANFAR_DEV_HAS_COALESCE
|
257 FSL_GIANFAR_DEV_HAS_RMON
|
258 FSL_GIANFAR_DEV_HAS_MULTI_INTR
|
259 FSL_GIANFAR_DEV_HAS_CSUM
|
260 FSL_GIANFAR_DEV_HAS_VLAN
|
261 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH
;
263 ph
= get_property(np
, "phy-handle", NULL
);
264 phy
= of_find_node_by_phandle(*ph
);
271 mdio
= of_get_parent(phy
);
273 id
= get_property(phy
, "reg", NULL
);
274 ret
= of_address_to_resource(mdio
, 0, &res
);
281 gfar_data
.phy_id
= *id
;
282 gfar_data
.bus_id
= res
.start
;
288 platform_device_add_data(gfar_dev
, &gfar_data
,
290 gianfar_platform_data
));
298 platform_device_unregister(gfar_dev
);
303 arch_initcall(gfar_of_init
);
305 static int __init
fsl_i2c_of_init(void)
307 struct device_node
*np
;
309 struct platform_device
*i2c_dev
;
312 for (np
= NULL
, i
= 0;
313 (np
= of_find_compatible_node(np
, "i2c", "fsl-i2c")) != NULL
;
315 struct resource r
[2];
316 struct fsl_i2c_platform_data i2c_data
;
317 const unsigned char *flags
= NULL
;
319 memset(&r
, 0, sizeof(r
));
320 memset(&i2c_data
, 0, sizeof(i2c_data
));
322 ret
= of_address_to_resource(np
, 0, &r
[0]);
326 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
327 r
[1].flags
= IORESOURCE_IRQ
;
329 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
330 if (IS_ERR(i2c_dev
)) {
331 ret
= PTR_ERR(i2c_dev
);
335 i2c_data
.device_flags
= 0;
336 flags
= get_property(np
, "dfsrr", NULL
);
338 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
340 flags
= get_property(np
, "fsl5200-clocking", NULL
);
342 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
345 platform_device_add_data(i2c_dev
, &i2c_data
,
347 fsl_i2c_platform_data
));
355 platform_device_unregister(i2c_dev
);
360 arch_initcall(fsl_i2c_of_init
);
362 #ifdef CONFIG_PPC_83xx
363 static int __init
mpc83xx_wdt_init(void)
366 struct device_node
*soc
, *np
;
367 struct platform_device
*dev
;
368 const unsigned int *freq
;
371 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
378 soc
= of_find_node_by_type(NULL
, "soc");
385 freq
= get_property(soc
, "bus-frequency", NULL
);
391 memset(&r
, 0, sizeof(r
));
393 ret
= of_address_to_resource(np
, 0, &r
);
397 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
403 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
413 platform_device_unregister(dev
);
422 arch_initcall(mpc83xx_wdt_init
);
425 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
428 return FSL_USB2_PHY_NONE
;
429 if (!strcasecmp(phy_type
, "ulpi"))
430 return FSL_USB2_PHY_ULPI
;
431 if (!strcasecmp(phy_type
, "utmi"))
432 return FSL_USB2_PHY_UTMI
;
433 if (!strcasecmp(phy_type
, "utmi_wide"))
434 return FSL_USB2_PHY_UTMI_WIDE
;
435 if (!strcasecmp(phy_type
, "serial"))
436 return FSL_USB2_PHY_SERIAL
;
438 return FSL_USB2_PHY_NONE
;
441 static int __init
fsl_usb_of_init(void)
443 struct device_node
*np
;
445 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr
= NULL
;
448 for (np
= NULL
, i
= 0;
449 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
451 struct resource r
[2];
452 struct fsl_usb2_platform_data usb_data
;
453 const unsigned char *prop
= NULL
;
455 memset(&r
, 0, sizeof(r
));
456 memset(&usb_data
, 0, sizeof(usb_data
));
458 ret
= of_address_to_resource(np
, 0, &r
[0]);
462 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
463 r
[1].flags
= IORESOURCE_IRQ
;
466 platform_device_register_simple("fsl-ehci", i
, r
, 2);
467 if (IS_ERR(usb_dev_mph
)) {
468 ret
= PTR_ERR(usb_dev_mph
);
472 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
473 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
475 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
477 prop
= get_property(np
, "port0", NULL
);
479 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
481 prop
= get_property(np
, "port1", NULL
);
483 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
485 prop
= get_property(np
, "phy_type", NULL
);
486 usb_data
.phy_mode
= determine_usb_phy(prop
);
489 platform_device_add_data(usb_dev_mph
, &usb_data
,
491 fsl_usb2_platform_data
));
497 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
499 struct resource r
[2];
500 struct fsl_usb2_platform_data usb_data
;
501 const unsigned char *prop
= NULL
;
503 memset(&r
, 0, sizeof(r
));
504 memset(&usb_data
, 0, sizeof(usb_data
));
506 ret
= of_address_to_resource(np
, 0, &r
[0]);
510 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
511 r
[1].flags
= IORESOURCE_IRQ
;
514 platform_device_register_simple("fsl-ehci", i
, r
, 2);
515 if (IS_ERR(usb_dev_dr
)) {
516 ret
= PTR_ERR(usb_dev_dr
);
520 usb_dev_dr
->dev
.coherent_dma_mask
= 0xffffffffUL
;
521 usb_dev_dr
->dev
.dma_mask
= &usb_dev_dr
->dev
.coherent_dma_mask
;
523 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
525 prop
= get_property(np
, "phy_type", NULL
);
526 usb_data
.phy_mode
= determine_usb_phy(prop
);
529 platform_device_add_data(usb_dev_dr
, &usb_data
,
531 fsl_usb2_platform_data
));
539 platform_device_unregister(usb_dev_dr
);
542 platform_device_unregister(usb_dev_mph
);
547 arch_initcall(fsl_usb_of_init
);
551 static const char fcc_regs
[] = "fcc_regs";
552 static const char fcc_regs_c
[] = "fcc_regs_c";
553 static const char fcc_pram
[] = "fcc_pram";
554 static char bus_id
[9][BUS_ID_SIZE
];
556 static int __init
fs_enet_of_init(void)
558 struct device_node
*np
;
560 struct platform_device
*fs_enet_dev
;
564 for (np
= NULL
, i
= 0;
565 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
567 struct resource r
[4];
568 struct device_node
*phy
, *mdio
;
569 struct fs_platform_info fs_enet_data
;
570 const unsigned int *id
, *phy_addr
, *phy_irq
;
571 const void *mac_addr
;
575 memset(r
, 0, sizeof(r
));
576 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
578 ret
= of_address_to_resource(np
, 0, &r
[0]);
581 r
[0].name
= fcc_regs
;
583 ret
= of_address_to_resource(np
, 1, &r
[1]);
586 r
[1].name
= fcc_pram
;
588 ret
= of_address_to_resource(np
, 2, &r
[2]);
591 r
[2].name
= fcc_regs_c
;
592 fs_enet_data
.fcc_regs_c
= r
[2].start
;
594 r
[3].start
= r
[3].end
= irq_of_parse_and_map(np
, 0);
595 r
[3].flags
= IORESOURCE_IRQ
;
598 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
600 if (IS_ERR(fs_enet_dev
)) {
601 ret
= PTR_ERR(fs_enet_dev
);
605 model
= get_property(np
, "model", NULL
);
611 mac_addr
= get_property(np
, "mac-address", NULL
);
612 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
614 ph
= get_property(np
, "phy-handle", NULL
);
615 phy
= of_find_node_by_phandle(*ph
);
622 phy_addr
= get_property(phy
, "reg", NULL
);
623 fs_enet_data
.phy_addr
= *phy_addr
;
625 phy_irq
= get_property(phy
, "interrupts", NULL
);
627 id
= get_property(np
, "device-id", NULL
);
628 fs_enet_data
.fs_no
= *id
;
629 strcpy(fs_enet_data
.fs_type
, model
);
631 mdio
= of_get_parent(phy
);
632 ret
= of_address_to_resource(mdio
, 0, &res
);
639 fs_enet_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
640 fs_enet_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
642 if (strstr(model
, "FCC")) {
643 int fcc_index
= *id
- 1;
644 const unsigned char *mdio_bb_prop
;
646 fs_enet_data
.dpram_offset
= (u32
)cpm_dpram_addr(0);
647 fs_enet_data
.rx_ring
= 32;
648 fs_enet_data
.tx_ring
= 32;
649 fs_enet_data
.rx_copybreak
= 240;
650 fs_enet_data
.use_napi
= 0;
651 fs_enet_data
.napi_weight
= 17;
652 fs_enet_data
.mem_offset
= FCC_MEM_OFFSET(fcc_index
);
653 fs_enet_data
.cp_page
= CPM_CR_FCC_PAGE(fcc_index
);
654 fs_enet_data
.cp_block
= CPM_CR_FCC_SBLOCK(fcc_index
);
656 snprintf((char*)&bus_id
[(*id
)], BUS_ID_SIZE
, "%x:%02x",
657 (u32
)res
.start
, fs_enet_data
.phy_addr
);
658 fs_enet_data
.bus_id
= (char*)&bus_id
[(*id
)];
659 fs_enet_data
.init_ioports
= init_fcc_ioports
;
661 mdio_bb_prop
= get_property(phy
, "bitbang", NULL
);
663 struct platform_device
*fs_enet_mdio_bb_dev
;
664 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data
;
666 fs_enet_mdio_bb_dev
=
667 platform_device_register_simple("fsl-bb-mdio",
669 memset(&fs_enet_mdio_bb_data
, 0,
670 sizeof(struct fs_mii_bb_platform_info
));
671 fs_enet_mdio_bb_data
.mdio_dat
.bit
=
673 fs_enet_mdio_bb_data
.mdio_dir
.bit
=
675 fs_enet_mdio_bb_data
.mdc_dat
.bit
=
677 fs_enet_mdio_bb_data
.mdio_port
=
679 fs_enet_mdio_bb_data
.mdc_port
=
681 fs_enet_mdio_bb_data
.delay
=
684 fs_enet_mdio_bb_data
.irq
[0] = phy_irq
[0];
685 fs_enet_mdio_bb_data
.irq
[1] = -1;
686 fs_enet_mdio_bb_data
.irq
[2] = -1;
687 fs_enet_mdio_bb_data
.irq
[3] = phy_irq
[0];
688 fs_enet_mdio_bb_data
.irq
[31] = -1;
690 fs_enet_mdio_bb_data
.mdio_dat
.offset
=
691 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
692 fs_enet_mdio_bb_data
.mdio_dir
.offset
=
693 (u32
)&cpm2_immr
->im_ioport
.iop_pdirc
;
694 fs_enet_mdio_bb_data
.mdc_dat
.offset
=
695 (u32
)&cpm2_immr
->im_ioport
.iop_pdatc
;
697 ret
= platform_device_add_data(
699 &fs_enet_mdio_bb_data
,
700 sizeof(struct fs_mii_bb_platform_info
));
708 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
718 platform_device_unregister(fs_enet_dev
);
723 arch_initcall(fs_enet_of_init
);
725 static const char scc_regs
[] = "regs";
726 static const char scc_pram
[] = "pram";
728 static int __init
cpm_uart_of_init(void)
730 struct device_node
*np
;
732 struct platform_device
*cpm_uart_dev
;
735 for (np
= NULL
, i
= 0;
736 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
738 struct resource r
[3];
739 struct fs_uart_platform_info cpm_uart_data
;
743 memset(r
, 0, sizeof(r
));
744 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
746 ret
= of_address_to_resource(np
, 0, &r
[0]);
750 r
[0].name
= scc_regs
;
752 ret
= of_address_to_resource(np
, 1, &r
[1]);
755 r
[1].name
= scc_pram
;
757 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
758 r
[2].flags
= IORESOURCE_IRQ
;
761 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
763 if (IS_ERR(cpm_uart_dev
)) {
764 ret
= PTR_ERR(cpm_uart_dev
);
768 id
= get_property(np
, "device-id", NULL
);
769 cpm_uart_data
.fs_no
= *id
;
771 model
= (char*)get_property(np
, "model", NULL
);
772 strcpy(cpm_uart_data
.fs_type
, model
);
774 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
776 cpm_uart_data
.tx_num_fifo
= 4;
777 cpm_uart_data
.tx_buf_size
= 32;
778 cpm_uart_data
.rx_num_fifo
= 4;
779 cpm_uart_data
.rx_buf_size
= 32;
780 cpm_uart_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
781 cpm_uart_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
784 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
786 fs_uart_platform_info
));
794 platform_device_unregister(cpm_uart_dev
);
799 arch_initcall(cpm_uart_of_init
);
800 #endif /* CONFIG_CPM2 */