2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <bcm63xx_dev_enet.h>
13 #include <bcm63xx_io.h>
14 #include <bcm63xx_regs.h>
16 static struct resource shared_res
[] = {
18 .start
= -1, /* filled at runtime */
19 .end
= -1, /* filled at runtime */
20 .flags
= IORESOURCE_MEM
,
24 static struct platform_device bcm63xx_enet_shared_device
= {
25 .name
= "bcm63xx_enet_shared",
27 .num_resources
= ARRAY_SIZE(shared_res
),
28 .resource
= shared_res
,
31 static int shared_device_registered
;
33 static struct resource enet0_res
[] = {
35 .start
= -1, /* filled at runtime */
36 .end
= -1, /* filled at runtime */
37 .flags
= IORESOURCE_MEM
,
40 .start
= -1, /* filled at runtime */
41 .flags
= IORESOURCE_IRQ
,
44 .start
= -1, /* filled at runtime */
45 .flags
= IORESOURCE_IRQ
,
48 .start
= -1, /* filled at runtime */
49 .flags
= IORESOURCE_IRQ
,
53 static struct bcm63xx_enet_platform_data enet0_pd
;
55 static struct platform_device bcm63xx_enet0_device
= {
56 .name
= "bcm63xx_enet",
58 .num_resources
= ARRAY_SIZE(enet0_res
),
59 .resource
= enet0_res
,
61 .platform_data
= &enet0_pd
,
65 static struct resource enet1_res
[] = {
67 .start
= -1, /* filled at runtime */
68 .end
= -1, /* filled at runtime */
69 .flags
= IORESOURCE_MEM
,
72 .start
= -1, /* filled at runtime */
73 .flags
= IORESOURCE_IRQ
,
76 .start
= -1, /* filled at runtime */
77 .flags
= IORESOURCE_IRQ
,
80 .start
= -1, /* filled at runtime */
81 .flags
= IORESOURCE_IRQ
,
85 static struct bcm63xx_enet_platform_data enet1_pd
;
87 static struct platform_device bcm63xx_enet1_device
= {
88 .name
= "bcm63xx_enet",
90 .num_resources
= ARRAY_SIZE(enet1_res
),
91 .resource
= enet1_res
,
93 .platform_data
= &enet1_pd
,
97 int __init
bcm63xx_enet_register(int unit
,
98 const struct bcm63xx_enet_platform_data
*pd
)
100 struct platform_device
*pdev
;
101 struct bcm63xx_enet_platform_data
*dpd
;
107 if (!shared_device_registered
) {
108 shared_res
[0].start
= bcm63xx_regset_address(RSET_ENETDMA
);
109 shared_res
[0].end
= shared_res
[0].start
;
110 if (BCMCPU_IS_6338())
111 shared_res
[0].end
+= (RSET_ENETDMA_SIZE
/ 2) - 1;
113 shared_res
[0].end
+= (RSET_ENETDMA_SIZE
) - 1;
115 ret
= platform_device_register(&bcm63xx_enet_shared_device
);
118 shared_device_registered
= 1;
122 enet0_res
[0].start
= bcm63xx_regset_address(RSET_ENET0
);
123 enet0_res
[0].end
= enet0_res
[0].start
;
124 enet0_res
[0].end
+= RSET_ENET_SIZE
- 1;
125 enet0_res
[1].start
= bcm63xx_get_irq_number(IRQ_ENET0
);
126 enet0_res
[2].start
= bcm63xx_get_irq_number(IRQ_ENET0_RXDMA
);
127 enet0_res
[3].start
= bcm63xx_get_irq_number(IRQ_ENET0_TXDMA
);
128 pdev
= &bcm63xx_enet0_device
;
130 enet1_res
[0].start
= bcm63xx_regset_address(RSET_ENET1
);
131 enet1_res
[0].end
= enet1_res
[0].start
;
132 enet1_res
[0].end
+= RSET_ENET_SIZE
- 1;
133 enet1_res
[1].start
= bcm63xx_get_irq_number(IRQ_ENET1
);
134 enet1_res
[2].start
= bcm63xx_get_irq_number(IRQ_ENET1_RXDMA
);
135 enet1_res
[3].start
= bcm63xx_get_irq_number(IRQ_ENET1_TXDMA
);
136 pdev
= &bcm63xx_enet1_device
;
139 /* copy given platform data */
140 dpd
= pdev
->dev
.platform_data
;
141 memcpy(dpd
, pd
, sizeof(*pd
));
143 /* adjust them in case internal phy is used */
144 if (dpd
->use_internal_phy
) {
146 /* internal phy only exists for enet0 */
151 dpd
->has_phy_interrupt
= 1;
152 dpd
->phy_interrupt
= bcm63xx_get_irq_number(IRQ_ENET_PHY
);
155 ret
= platform_device_register(pdev
);