2 * Helper functions for the PM3386s on the Radisys ENP2611
3 * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
4 * Dedicated to Marija Kulikova.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/delay.h>
15 #include <linux/netdevice.h>
20 * Read from register 'reg' of PM3386 device 'pm'.
22 static u16
pm3386_reg_read(int pm
, int reg
)
27 _reg
= (void *)ENP2611_PM3386_0_VIRT_BASE
;
29 _reg
= (void *)ENP2611_PM3386_1_VIRT_BASE
;
31 value
= *((volatile u16
*)(_reg
+ (reg
<< 1)));
33 // printk(KERN_INFO "pm3386_reg_read(%d, %.3x) = %.8x\n", pm, reg, value);
39 * Write to register 'reg' of PM3386 device 'pm', and perform
40 * a readback from the identification register.
42 static void pm3386_reg_write(int pm
, int reg
, u16 value
)
47 // printk(KERN_INFO "pm3386_reg_write(%d, %.3x, %.8x)\n", pm, reg, value);
49 _reg
= (void *)ENP2611_PM3386_0_VIRT_BASE
;
51 _reg
= (void *)ENP2611_PM3386_1_VIRT_BASE
;
53 *((volatile u16
*)(_reg
+ (reg
<< 1))) = value
;
55 dummy
= *((volatile u16
*)_reg
);
56 __asm__
__volatile__("mov %0, %0" : "+r" (dummy
));
60 * Read from port 'port' register 'reg', where the registers
61 * for the different ports are 'spacing' registers apart.
63 static u16
pm3386_port_reg_read(int port
, int _reg
, int spacing
)
71 return pm3386_reg_read(port
>> 1, reg
);
75 * Write to port 'port' register 'reg', where the registers
76 * for the different ports are 'spacing' registers apart.
78 static void pm3386_port_reg_write(int port
, int _reg
, int spacing
, u16 value
)
86 pm3386_reg_write(port
>> 1, reg
, value
);
90 void pm3386_reset(void)
94 /* Save programmed MAC addresses. */
95 pm3386_get_mac(0, mac
[0]);
96 pm3386_get_mac(1, mac
[1]);
97 pm3386_get_mac(2, mac
[2]);
99 /* Assert analog and digital reset. */
100 pm3386_reg_write(0, 0x002, 0x0060);
101 pm3386_reg_write(1, 0x002, 0x0060);
104 /* Deassert analog reset. */
105 pm3386_reg_write(0, 0x002, 0x0062);
106 pm3386_reg_write(1, 0x002, 0x0062);
109 /* Deassert digital reset. */
110 pm3386_reg_write(0, 0x002, 0x0063);
111 pm3386_reg_write(1, 0x002, 0x0063);
114 /* Restore programmed MAC addresses. */
115 pm3386_set_mac(0, mac
[0]);
116 pm3386_set_mac(1, mac
[1]);
117 pm3386_set_mac(2, mac
[2]);
119 /* Disable carrier on all ports. */
120 pm3386_set_carrier(0, 0);
121 pm3386_set_carrier(1, 0);
122 pm3386_set_carrier(2, 0);
125 static u16
swaph(u16 x
)
127 return ((x
<< 8) | (x
>> 8)) & 0xffff;
130 void pm3386_init_port(int port
)
135 * Work around ENP2611 bootloader programming MAC address
138 if (pm3386_port_reg_read(port
, 0x30a, 0x100) == 0x0000 &&
139 (pm3386_port_reg_read(port
, 0x309, 0x100) & 0xff00) == 0x5000) {
142 temp
[0] = pm3386_port_reg_read(port
, 0x308, 0x100);
143 temp
[1] = pm3386_port_reg_read(port
, 0x309, 0x100);
144 temp
[2] = pm3386_port_reg_read(port
, 0x30a, 0x100);
145 pm3386_port_reg_write(port
, 0x308, 0x100, swaph(temp
[2]));
146 pm3386_port_reg_write(port
, 0x309, 0x100, swaph(temp
[1]));
147 pm3386_port_reg_write(port
, 0x30a, 0x100, swaph(temp
[0]));
151 * Initialise narrowbanding mode. See application note 2010486
152 * for more information. (@@@ We also need to issue a reset
153 * when ROOL or DOOL are detected.)
155 pm3386_port_reg_write(port
, 0x708, 0x10, 0xd055);
157 pm3386_port_reg_write(port
, 0x708, 0x10, 0x5055);
160 * SPI-3 ingress block. Set 64 bytes SPI-3 burst size
161 * towards SPI-3 bridge.
163 pm3386_port_reg_write(port
, 0x122, 0x20, 0x0002);
166 * Enable ingress protocol checking, and soft reset the
167 * SPI-3 ingress block.
169 pm3386_reg_write(pm
, 0x103, 0x0003);
170 while (!(pm3386_reg_read(pm
, 0x103) & 0x80))
174 * SPI-3 egress block. Gather 12288 bytes of the current
175 * packet in the TX fifo before initiating transmit on the
176 * SERDES interface. (Prevents TX underflows.)
178 pm3386_port_reg_write(port
, 0x221, 0x20, 0x0007);
181 * Enforce odd parity from the SPI-3 bridge, and soft reset
182 * the SPI-3 egress block.
184 pm3386_reg_write(pm
, 0x203, 0x000d & ~(4 << (port
& 1)));
185 while ((pm3386_reg_read(pm
, 0x203) & 0x000c) != 0x000c)
189 * EGMAC block. Set this channels to reject long preambles,
190 * not send or transmit PAUSE frames, enable preamble checking,
191 * disable frame length checking, enable FCS appending, enable
194 pm3386_port_reg_write(port
, 0x302, 0x100, 0x0113);
197 * Soft reset the EGMAC block.
199 pm3386_port_reg_write(port
, 0x301, 0x100, 0x8000);
200 pm3386_port_reg_write(port
, 0x301, 0x100, 0x0000);
203 * Auto-sense autonegotiation status.
205 pm3386_port_reg_write(port
, 0x306, 0x100, 0x0100);
208 * Allow reception of jumbo frames.
210 pm3386_port_reg_write(port
, 0x310, 0x100, 9018);
213 * Allow transmission of jumbo frames.
215 pm3386_port_reg_write(port
, 0x336, 0x100, 9018);
217 /* @@@ Should set 0x337/0x437 (RX forwarding threshold.) */
220 * Set autonegotiation parameters to 'no PAUSE, full duplex.'
222 pm3386_port_reg_write(port
, 0x31c, 0x100, 0x0020);
225 * Enable and restart autonegotiation.
227 pm3386_port_reg_write(port
, 0x318, 0x100, 0x0003);
228 pm3386_port_reg_write(port
, 0x318, 0x100, 0x0002);
231 void pm3386_get_mac(int port
, u8
*mac
)
235 temp
= pm3386_port_reg_read(port
, 0x308, 0x100);
236 mac
[0] = temp
& 0xff;
237 mac
[1] = (temp
>> 8) & 0xff;
239 temp
= pm3386_port_reg_read(port
, 0x309, 0x100);
240 mac
[2] = temp
& 0xff;
241 mac
[3] = (temp
>> 8) & 0xff;
243 temp
= pm3386_port_reg_read(port
, 0x30a, 0x100);
244 mac
[4] = temp
& 0xff;
245 mac
[5] = (temp
>> 8) & 0xff;
248 void pm3386_set_mac(int port
, u8
*mac
)
250 pm3386_port_reg_write(port
, 0x308, 0x100, (mac
[1] << 8) | mac
[0]);
251 pm3386_port_reg_write(port
, 0x309, 0x100, (mac
[3] << 8) | mac
[2]);
252 pm3386_port_reg_write(port
, 0x30a, 0x100, (mac
[5] << 8) | mac
[4]);
255 static u32
pm3386_get_stat(int port
, u16 base
)
259 value
= pm3386_port_reg_read(port
, base
, 0x100);
260 value
|= pm3386_port_reg_read(port
, base
+ 1, 0x100) << 16;
265 void pm3386_get_stats(int port
, struct net_device_stats
*stats
)
268 * Snapshot statistics counters.
270 pm3386_port_reg_write(port
, 0x500, 0x100, 0x0001);
271 while (pm3386_port_reg_read(port
, 0x500, 0x100) & 0x0001)
274 memset(stats
, 0, sizeof(*stats
));
276 stats
->rx_packets
= pm3386_get_stat(port
, 0x510);
277 stats
->tx_packets
= pm3386_get_stat(port
, 0x590);
278 stats
->rx_bytes
= pm3386_get_stat(port
, 0x514);
279 stats
->tx_bytes
= pm3386_get_stat(port
, 0x594);
280 /* @@@ Add other stats. */
283 void pm3386_set_carrier(int port
, int state
)
285 pm3386_port_reg_write(port
, 0x703, 0x10, state
? 0x1001 : 0x0000);
288 int pm3386_is_link_up(int port
)
292 temp
= pm3386_port_reg_read(port
, 0x31a, 0x100);
293 temp
= pm3386_port_reg_read(port
, 0x31a, 0x100);
295 return !!(temp
& 0x0002);
298 void pm3386_enable_rx(int port
)
302 temp
= pm3386_port_reg_read(port
, 0x303, 0x100);
304 pm3386_port_reg_write(port
, 0x303, 0x100, temp
);
307 void pm3386_disable_rx(int port
)
311 temp
= pm3386_port_reg_read(port
, 0x303, 0x100);
313 pm3386_port_reg_write(port
, 0x303, 0x100, temp
);
316 void pm3386_enable_tx(int port
)
320 temp
= pm3386_port_reg_read(port
, 0x303, 0x100);
322 pm3386_port_reg_write(port
, 0x303, 0x100, temp
);
325 void pm3386_disable_tx(int port
)
329 temp
= pm3386_port_reg_read(port
, 0x303, 0x100);
331 pm3386_port_reg_write(port
, 0x303, 0x100, temp
);
334 MODULE_LICENSE("GPL");