1 #include <linux/delay.h>
2 #include <linux/if_ether.h>
3 #include <linux/ioport.h>
4 #include <linux/mv643xx.h>
5 #include <linux/platform_device.h>
7 #include "ocelot_3_fpga.h"
9 #if defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE)
11 static struct resource mv643xx_eth_shared_resources
[] = {
13 .name
= "ethernet shared base",
14 .start
= 0xf1000000 + MV643XX_ETH_SHARED_REGS
,
15 .end
= 0xf1000000 + MV643XX_ETH_SHARED_REGS
+
16 MV643XX_ETH_SHARED_REGS_SIZE
- 1,
17 .flags
= IORESOURCE_MEM
,
21 static struct platform_device mv643xx_eth_shared_device
= {
22 .name
= MV643XX_ETH_SHARED_NAME
,
24 .num_resources
= ARRAY_SIZE(mv643xx_eth_shared_resources
),
25 .resource
= mv643xx_eth_shared_resources
,
28 #define MV_SRAM_BASE 0xfe000000UL
29 #define MV_SRAM_SIZE (256 * 1024)
31 #define MV_SRAM_RXRING_SIZE (MV_SRAM_SIZE / 4)
32 #define MV_SRAM_TXRING_SIZE (MV_SRAM_SIZE / 4)
34 #define MV_SRAM_BASE_ETH0 MV_SRAM_BASE
35 #define MV_SRAM_BASE_ETH1 (MV_SRAM_BASE + (MV_SRAM_SIZE / 2))
37 #define MV64x60_IRQ_ETH_0 48
38 #define MV64x60_IRQ_ETH_1 49
39 #define MV64x60_IRQ_ETH_2 50
41 #ifdef CONFIG_MV643XX_ETH_0
43 static struct resource mv64x60_eth0_resources
[] = {
46 .start
= MV64x60_IRQ_ETH_0
,
47 .end
= MV64x60_IRQ_ETH_0
,
48 .flags
= IORESOURCE_IRQ
,
52 static char eth0_mac_addr
[ETH_ALEN
];
54 static struct mv643xx_eth_platform_data eth0_pd
= {
55 .mac_addr
= eth0_mac_addr
,
57 .tx_sram_addr
= MV_SRAM_BASE_ETH0
,
58 .tx_sram_size
= MV_SRAM_TXRING_SIZE
,
59 .tx_queue_size
= MV_SRAM_TXRING_SIZE
/ 16,
61 .rx_sram_addr
= MV_SRAM_BASE_ETH0
+ MV_SRAM_TXRING_SIZE
,
62 .rx_sram_size
= MV_SRAM_RXRING_SIZE
,
63 .rx_queue_size
= MV_SRAM_RXRING_SIZE
/ 16,
66 static struct platform_device eth0_device
= {
67 .name
= MV643XX_ETH_NAME
,
69 .num_resources
= ARRAY_SIZE(mv64x60_eth0_resources
),
70 .resource
= mv64x60_eth0_resources
,
72 .platform_data
= ð0_pd
,
75 #endif /* CONFIG_MV643XX_ETH_0 */
77 #ifdef CONFIG_MV643XX_ETH_1
79 static struct resource mv64x60_eth1_resources
[] = {
82 .start
= MV64x60_IRQ_ETH_1
,
83 .end
= MV64x60_IRQ_ETH_1
,
84 .flags
= IORESOURCE_IRQ
,
88 static char eth1_mac_addr
[ETH_ALEN
];
90 static struct mv643xx_eth_platform_data eth1_pd
= {
91 .mac_addr
= eth1_mac_addr
,
93 .tx_sram_addr
= MV_SRAM_BASE_ETH1
,
94 .tx_sram_size
= MV_SRAM_TXRING_SIZE
,
95 .tx_queue_size
= MV_SRAM_TXRING_SIZE
/ 16,
97 .rx_sram_addr
= MV_SRAM_BASE_ETH1
+ MV_SRAM_TXRING_SIZE
,
98 .rx_sram_size
= MV_SRAM_RXRING_SIZE
,
99 .rx_queue_size
= MV_SRAM_RXRING_SIZE
/ 16,
102 static struct platform_device eth1_device
= {
103 .name
= MV643XX_ETH_NAME
,
105 .num_resources
= ARRAY_SIZE(mv64x60_eth1_resources
),
106 .resource
= mv64x60_eth1_resources
,
108 .platform_data
= ð1_pd
,
111 #endif /* CONFIG_MV643XX_ETH_1 */
113 #ifdef CONFIG_MV643XX_ETH_2
115 static struct resource mv64x60_eth2_resources
[] = {
118 .start
= MV64x60_IRQ_ETH_2
,
119 .end
= MV64x60_IRQ_ETH_2
,
120 .flags
= IORESOURCE_IRQ
,
124 static char eth2_mac_addr
[ETH_ALEN
];
126 static struct mv643xx_eth_platform_data eth2_pd
= {
127 .mac_addr
= eth2_mac_addr
,
130 static struct platform_device eth2_device
= {
131 .name
= MV643XX_ETH_NAME
,
133 .num_resources
= ARRAY_SIZE(mv64x60_eth2_resources
),
134 .resource
= mv64x60_eth2_resources
,
136 .platform_data
= ð2_pd
,
139 #endif /* CONFIG_MV643XX_ETH_2 */
141 static struct platform_device
*mv643xx_eth_pd_devs
[] __initdata
= {
142 &mv643xx_eth_shared_device
,
143 #ifdef CONFIG_MV643XX_ETH_0
146 #ifdef CONFIG_MV643XX_ETH_1
149 #ifdef CONFIG_MV643XX_ETH_2
154 static u8 __init
exchange_bit(u8 val
, u8 cs
)
157 OCELOT_FPGA_WRITE((val
<< 2) | cs
, EEPROM_MODE
);
160 /* turn the clock on */
161 OCELOT_FPGA_WRITE((val
<< 2) | cs
| 0x2, EEPROM_MODE
);
164 /* turn the clock off and read-strobe */
165 OCELOT_FPGA_WRITE((val
<< 2) | cs
| 0x10, EEPROM_MODE
);
167 /* return the data */
168 return (OCELOT_FPGA_READ(EEPROM_MODE
) >> 3) & 0x1;
171 static void __init
get_mac(char dest
[6])
173 u8 read_opcode
[12] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
176 for (i
= 0; i
< 12; i
++)
177 exchange_bit(read_opcode
[i
], 1);
179 for (j
= 0; j
< 6; j
++) {
181 for (i
= 0; i
< 8; i
++) {
183 dest
[j
] |= exchange_bit(0, 1);
192 * Copy and increment ethernet MAC address by a small value.
194 * This is useful for systems where the only one MAC address is stored in
195 * non-volatile memory for multiple ports.
197 static inline void eth_mac_add(unsigned char *dst
, unsigned char *src
,
204 for (i
= ETH_ALEN
; i
>= 0; i
--) {
205 dst
[i
] = src
[i
] + add
;
206 add
= dst
[i
] < src
[i
]; /* compute carry */
212 static int __init
mv643xx_eth_add_pds(void)
214 unsigned char mac
[ETH_ALEN
];
218 #ifdef CONFIG_MV643XX_ETH_0
219 eth_mac_add(eth1_mac_addr
, mac
, 0);
221 #ifdef CONFIG_MV643XX_ETH_1
222 eth_mac_add(eth1_mac_addr
, mac
, 1);
224 #ifdef CONFIG_MV643XX_ETH_2
225 eth_mac_add(eth2_mac_addr
, mac
, 2);
227 ret
= platform_add_devices(mv643xx_eth_pd_devs
,
228 ARRAY_SIZE(mv643xx_eth_pd_devs
));
233 device_initcall(mv643xx_eth_add_pds
);
235 #endif /* defined(CONFIG_MV643XX_ETH) || defined(CONFIG_MV643XX_ETH_MODULE) */