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 static phys_addr_t immrbase
= -1;
42 phys_addr_t
get_immrbase(void)
44 struct device_node
*soc
;
49 soc
= of_find_node_by_type(NULL
, "soc");
52 const void *prop
= get_property(soc
, "reg", &size
);
55 immrbase
= of_translate_address(soc
, prop
);
62 EXPORT_SYMBOL(get_immrbase
);
66 static u32 brgfreq
= -1;
70 struct device_node
*node
;
75 node
= of_find_node_by_type(NULL
, "cpm");
78 const unsigned int *prop
= get_property(node
, "brg-frequency",
89 EXPORT_SYMBOL(get_brgfreq
);
91 static u32 fs_baudrate
= -1;
93 u32
get_baudrate(void)
95 struct device_node
*node
;
97 if (fs_baudrate
!= -1)
100 node
= of_find_node_by_type(NULL
, "serial");
103 const unsigned int *prop
= get_property(node
, "current-speed",
114 EXPORT_SYMBOL(get_baudrate
);
115 #endif /* CONFIG_CPM2 */
117 static int __init
gfar_mdio_of_init(void)
119 struct device_node
*np
;
121 struct platform_device
*mdio_dev
;
125 for (np
= NULL
, i
= 0;
126 (np
= of_find_compatible_node(np
, "mdio", "gianfar")) != NULL
;
129 struct device_node
*child
= NULL
;
130 struct gianfar_mdio_data mdio_data
;
132 memset(&res
, 0, sizeof(res
));
133 memset(&mdio_data
, 0, sizeof(mdio_data
));
135 ret
= of_address_to_resource(np
, 0, &res
);
140 platform_device_register_simple("fsl-gianfar_mdio",
142 if (IS_ERR(mdio_dev
)) {
143 ret
= PTR_ERR(mdio_dev
);
147 for (k
= 0; k
< 32; k
++)
148 mdio_data
.irq
[k
] = -1;
150 while ((child
= of_get_next_child(np
, child
)) != NULL
) {
151 int irq
= irq_of_parse_and_map(child
, 0);
153 const u32
*id
= get_property(child
, "reg", NULL
);
154 mdio_data
.irq
[*id
] = irq
;
159 platform_device_add_data(mdio_dev
, &mdio_data
,
160 sizeof(struct gianfar_mdio_data
));
168 platform_device_unregister(mdio_dev
);
173 arch_initcall(gfar_mdio_of_init
);
175 static const char *gfar_tx_intr
= "tx";
176 static const char *gfar_rx_intr
= "rx";
177 static const char *gfar_err_intr
= "error";
179 static int __init
gfar_of_init(void)
181 struct device_node
*np
;
183 struct platform_device
*gfar_dev
;
187 for (np
= NULL
, i
= 0;
188 (np
= of_find_compatible_node(np
, "network", "gianfar")) != NULL
;
190 struct resource r
[4];
191 struct device_node
*phy
, *mdio
;
192 struct gianfar_platform_data gfar_data
;
193 const unsigned int *id
;
195 const void *mac_addr
;
199 memset(r
, 0, sizeof(r
));
200 memset(&gfar_data
, 0, sizeof(gfar_data
));
202 ret
= of_address_to_resource(np
, 0, &r
[0]);
206 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
207 r
[1].flags
= IORESOURCE_IRQ
;
209 model
= get_property(np
, "model", NULL
);
211 /* If we aren't the FEC we have multiple interrupts */
212 if (model
&& strcasecmp(model
, "FEC")) {
213 r
[1].name
= gfar_tx_intr
;
215 r
[2].name
= gfar_rx_intr
;
216 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 1);
217 r
[2].flags
= IORESOURCE_IRQ
;
219 r
[3].name
= gfar_err_intr
;
220 r
[3].start
= r
[3].end
= irq_of_parse_and_map(np
, 2);
221 r
[3].flags
= IORESOURCE_IRQ
;
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 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
326 r
[1].flags
= IORESOURCE_IRQ
;
328 i2c_dev
= platform_device_register_simple("fsl-i2c", i
, r
, 2);
329 if (IS_ERR(i2c_dev
)) {
330 ret
= PTR_ERR(i2c_dev
);
334 i2c_data
.device_flags
= 0;
335 flags
= get_property(np
, "dfsrr", NULL
);
337 i2c_data
.device_flags
|= FSL_I2C_DEV_SEPARATE_DFSRR
;
339 flags
= get_property(np
, "fsl5200-clocking", NULL
);
341 i2c_data
.device_flags
|= FSL_I2C_DEV_CLOCK_5200
;
344 platform_device_add_data(i2c_dev
, &i2c_data
,
346 fsl_i2c_platform_data
));
354 platform_device_unregister(i2c_dev
);
359 arch_initcall(fsl_i2c_of_init
);
361 #ifdef CONFIG_PPC_83xx
362 static int __init
mpc83xx_wdt_init(void)
365 struct device_node
*soc
, *np
;
366 struct platform_device
*dev
;
367 const unsigned int *freq
;
370 np
= of_find_compatible_node(NULL
, "watchdog", "mpc83xx_wdt");
377 soc
= of_find_node_by_type(NULL
, "soc");
384 freq
= get_property(soc
, "bus-frequency", NULL
);
390 memset(&r
, 0, sizeof(r
));
392 ret
= of_address_to_resource(np
, 0, &r
);
396 dev
= platform_device_register_simple("mpc83xx_wdt", 0, &r
, 1);
402 ret
= platform_device_add_data(dev
, freq
, sizeof(int));
412 platform_device_unregister(dev
);
421 arch_initcall(mpc83xx_wdt_init
);
424 static enum fsl_usb2_phy_modes
determine_usb_phy(const char *phy_type
)
427 return FSL_USB2_PHY_NONE
;
428 if (!strcasecmp(phy_type
, "ulpi"))
429 return FSL_USB2_PHY_ULPI
;
430 if (!strcasecmp(phy_type
, "utmi"))
431 return FSL_USB2_PHY_UTMI
;
432 if (!strcasecmp(phy_type
, "utmi_wide"))
433 return FSL_USB2_PHY_UTMI_WIDE
;
434 if (!strcasecmp(phy_type
, "serial"))
435 return FSL_USB2_PHY_SERIAL
;
437 return FSL_USB2_PHY_NONE
;
440 static int __init
fsl_usb_of_init(void)
442 struct device_node
*np
;
444 struct platform_device
*usb_dev_mph
= NULL
, *usb_dev_dr
= NULL
;
447 for (np
= NULL
, i
= 0;
448 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-mph")) != NULL
;
450 struct resource r
[2];
451 struct fsl_usb2_platform_data usb_data
;
452 const unsigned char *prop
= NULL
;
454 memset(&r
, 0, sizeof(r
));
455 memset(&usb_data
, 0, sizeof(usb_data
));
457 ret
= of_address_to_resource(np
, 0, &r
[0]);
461 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
462 r
[1].flags
= IORESOURCE_IRQ
;
465 platform_device_register_simple("fsl-ehci", i
, r
, 2);
466 if (IS_ERR(usb_dev_mph
)) {
467 ret
= PTR_ERR(usb_dev_mph
);
471 usb_dev_mph
->dev
.coherent_dma_mask
= 0xffffffffUL
;
472 usb_dev_mph
->dev
.dma_mask
= &usb_dev_mph
->dev
.coherent_dma_mask
;
474 usb_data
.operating_mode
= FSL_USB2_MPH_HOST
;
476 prop
= get_property(np
, "port0", NULL
);
478 usb_data
.port_enables
|= FSL_USB2_PORT0_ENABLED
;
480 prop
= get_property(np
, "port1", NULL
);
482 usb_data
.port_enables
|= FSL_USB2_PORT1_ENABLED
;
484 prop
= get_property(np
, "phy_type", NULL
);
485 usb_data
.phy_mode
= determine_usb_phy(prop
);
488 platform_device_add_data(usb_dev_mph
, &usb_data
,
490 fsl_usb2_platform_data
));
496 (np
= of_find_compatible_node(np
, "usb", "fsl-usb2-dr")) != NULL
;
498 struct resource r
[2];
499 struct fsl_usb2_platform_data usb_data
;
500 const unsigned char *prop
= NULL
;
502 memset(&r
, 0, sizeof(r
));
503 memset(&usb_data
, 0, sizeof(usb_data
));
505 ret
= of_address_to_resource(np
, 0, &r
[0]);
509 r
[1].start
= r
[1].end
= irq_of_parse_and_map(np
, 0);
510 r
[1].flags
= IORESOURCE_IRQ
;
513 platform_device_register_simple("fsl-ehci", i
, r
, 2);
514 if (IS_ERR(usb_dev_dr
)) {
515 ret
= PTR_ERR(usb_dev_dr
);
519 usb_dev_dr
->dev
.coherent_dma_mask
= 0xffffffffUL
;
520 usb_dev_dr
->dev
.dma_mask
= &usb_dev_dr
->dev
.coherent_dma_mask
;
522 usb_data
.operating_mode
= FSL_USB2_DR_HOST
;
524 prop
= get_property(np
, "phy_type", NULL
);
525 usb_data
.phy_mode
= determine_usb_phy(prop
);
528 platform_device_add_data(usb_dev_dr
, &usb_data
,
530 fsl_usb2_platform_data
));
538 platform_device_unregister(usb_dev_dr
);
541 platform_device_unregister(usb_dev_mph
);
546 arch_initcall(fsl_usb_of_init
);
550 static const char fcc_regs
[] = "fcc_regs";
551 static const char fcc_regs_c
[] = "fcc_regs_c";
552 static const char fcc_pram
[] = "fcc_pram";
553 static char bus_id
[9][BUS_ID_SIZE
];
555 static int __init
fs_enet_of_init(void)
557 struct device_node
*np
;
559 struct platform_device
*fs_enet_dev
;
563 for (np
= NULL
, i
= 0;
564 (np
= of_find_compatible_node(np
, "network", "fs_enet")) != NULL
;
566 struct resource r
[4];
567 struct device_node
*phy
, *mdio
;
568 struct fs_platform_info fs_enet_data
;
569 const unsigned int *id
, *phy_addr
;
570 const void *mac_addr
;
574 memset(r
, 0, sizeof(r
));
575 memset(&fs_enet_data
, 0, sizeof(fs_enet_data
));
577 ret
= of_address_to_resource(np
, 0, &r
[0]);
580 r
[0].name
= fcc_regs
;
582 ret
= of_address_to_resource(np
, 1, &r
[1]);
585 r
[1].name
= fcc_pram
;
587 ret
= of_address_to_resource(np
, 2, &r
[2]);
590 r
[2].name
= fcc_regs_c
;
592 r
[3].start
= r
[3].end
= irq_of_parse_and_map(np
, 0);
593 r
[3].flags
= IORESOURCE_IRQ
;
596 platform_device_register_simple("fsl-cpm-fcc", i
, &r
[0], 4);
598 if (IS_ERR(fs_enet_dev
)) {
599 ret
= PTR_ERR(fs_enet_dev
);
603 model
= get_property(np
, "model", NULL
);
609 mac_addr
= get_property(np
, "mac-address", NULL
);
610 memcpy(fs_enet_data
.macaddr
, mac_addr
, 6);
612 ph
= get_property(np
, "phy-handle", NULL
);
613 phy
= of_find_node_by_phandle(*ph
);
620 phy_addr
= get_property(phy
, "reg", NULL
);
621 fs_enet_data
.phy_addr
= *phy_addr
;
623 id
= get_property(np
, "device-id", NULL
);
624 fs_enet_data
.fs_no
= *id
;
625 strcpy(fs_enet_data
.fs_type
, model
);
627 mdio
= of_get_parent(phy
);
628 ret
= of_address_to_resource(mdio
, 0, &res
);
635 fs_enet_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
636 fs_enet_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
638 if (strstr(model
, "FCC")) {
639 int fcc_index
= *id
- 1;
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
;
660 ret
= platform_device_add_data(fs_enet_dev
, &fs_enet_data
,
669 platform_device_unregister(fs_enet_dev
);
674 arch_initcall(fs_enet_of_init
);
676 static const char scc_regs
[] = "regs";
677 static const char scc_pram
[] = "pram";
679 static int __init
cpm_uart_of_init(void)
681 struct device_node
*np
;
683 struct platform_device
*cpm_uart_dev
;
686 for (np
= NULL
, i
= 0;
687 (np
= of_find_compatible_node(np
, "serial", "cpm_uart")) != NULL
;
689 struct resource r
[3];
690 struct fs_uart_platform_info cpm_uart_data
;
694 memset(r
, 0, sizeof(r
));
695 memset(&cpm_uart_data
, 0, sizeof(cpm_uart_data
));
697 ret
= of_address_to_resource(np
, 0, &r
[0]);
701 r
[0].name
= scc_regs
;
703 ret
= of_address_to_resource(np
, 1, &r
[1]);
706 r
[1].name
= scc_pram
;
708 r
[2].start
= r
[2].end
= irq_of_parse_and_map(np
, 0);
709 r
[2].flags
= IORESOURCE_IRQ
;
712 platform_device_register_simple("fsl-cpm-scc:uart", i
, &r
[0], 3);
714 if (IS_ERR(cpm_uart_dev
)) {
715 ret
= PTR_ERR(cpm_uart_dev
);
719 id
= get_property(np
, "device-id", NULL
);
720 cpm_uart_data
.fs_no
= *id
;
722 model
= (char*)get_property(np
, "model", NULL
);
723 strcpy(cpm_uart_data
.fs_type
, model
);
725 cpm_uart_data
.uart_clk
= ppc_proc_freq
;
727 cpm_uart_data
.tx_num_fifo
= 4;
728 cpm_uart_data
.tx_buf_size
= 32;
729 cpm_uart_data
.rx_num_fifo
= 4;
730 cpm_uart_data
.rx_buf_size
= 32;
731 cpm_uart_data
.clk_rx
= *((u32
*) get_property(np
, "rx-clock", NULL
));
732 cpm_uart_data
.clk_tx
= *((u32
*) get_property(np
, "tx-clock", NULL
));
735 platform_device_add_data(cpm_uart_dev
, &cpm_uart_data
,
737 fs_uart_platform_info
));
745 platform_device_unregister(cpm_uart_dev
);
750 arch_initcall(cpm_uart_of_init
);
751 #endif /* CONFIG_CPM2 */