aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ixp2000/pm3386.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ixp2000/pm3386.c')
-rw-r--r--drivers/net/ixp2000/pm3386.c334
1 files changed, 334 insertions, 0 deletions
diff --git a/drivers/net/ixp2000/pm3386.c b/drivers/net/ixp2000/pm3386.c
new file mode 100644
index 000000000000..5c7ab7564053
--- /dev/null
+++ b/drivers/net/ixp2000/pm3386.c
@@ -0,0 +1,334 @@
1/*
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.
5 *
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.
10 */
11
12#include <linux/config.h>
13#include <linux/module.h>
14#include <linux/delay.h>
15#include <linux/netdevice.h>
16#include <asm/io.h>
17#include "pm3386.h"
18
19/*
20 * Read from register 'reg' of PM3386 device 'pm'.
21 */
22static u16 pm3386_reg_read(int pm, int reg)
23{
24 void *_reg;
25 u16 value;
26
27 _reg = (void *)ENP2611_PM3386_0_VIRT_BASE;
28 if (pm == 1)
29 _reg = (void *)ENP2611_PM3386_1_VIRT_BASE;
30
31 value = *((volatile u16 *)(_reg + (reg << 1)));
32
33// printk(KERN_INFO "pm3386_reg_read(%d, %.3x) = %.8x\n", pm, reg, value);
34
35 return value;
36}
37
38/*
39 * Write to register 'reg' of PM3386 device 'pm', and perform
40 * a readback from the identification register.
41 */
42static void pm3386_reg_write(int pm, int reg, u16 value)
43{
44 void *_reg;
45 u16 dummy;
46
47// printk(KERN_INFO "pm3386_reg_write(%d, %.3x, %.8x)\n", pm, reg, value);
48
49 _reg = (void *)ENP2611_PM3386_0_VIRT_BASE;
50 if (pm == 1)
51 _reg = (void *)ENP2611_PM3386_1_VIRT_BASE;
52
53 *((volatile u16 *)(_reg + (reg << 1))) = value;
54
55 dummy = *((volatile u16 *)_reg);
56 __asm__ __volatile__("mov %0, %0" : "+r" (dummy));
57}
58
59/*
60 * Read from port 'port' register 'reg', where the registers
61 * for the different ports are 'spacing' registers apart.
62 */
63static u16 pm3386_port_reg_read(int port, int _reg, int spacing)
64{
65 int reg;
66
67 reg = _reg;
68 if (port & 1)
69 reg += spacing;
70
71 return pm3386_reg_read(port >> 1, reg);
72}
73
74/*
75 * Write to port 'port' register 'reg', where the registers
76 * for the different ports are 'spacing' registers apart.
77 */
78static void pm3386_port_reg_write(int port, int _reg, int spacing, u16 value)
79{
80 int reg;
81
82 reg = _reg;
83 if (port & 1)
84 reg += spacing;
85
86 pm3386_reg_write(port >> 1, reg, value);
87}
88
89
90void pm3386_reset(void)
91{
92 u8 mac[3][6];
93
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]);
98
99 /* Assert analog and digital reset. */
100 pm3386_reg_write(0, 0x002, 0x0060);
101 pm3386_reg_write(1, 0x002, 0x0060);
102 mdelay(1);
103
104 /* Deassert analog reset. */
105 pm3386_reg_write(0, 0x002, 0x0062);
106 pm3386_reg_write(1, 0x002, 0x0062);
107 mdelay(10);
108
109 /* Deassert digital reset. */
110 pm3386_reg_write(0, 0x002, 0x0063);
111 pm3386_reg_write(1, 0x002, 0x0063);
112 mdelay(10);
113
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]);
118
119 /* Disable carrier on all ports. */
120 pm3386_set_carrier(0, 0);
121 pm3386_set_carrier(1, 0);
122 pm3386_set_carrier(2, 0);
123}
124
125static u16 swaph(u16 x)
126{
127 return ((x << 8) | (x >> 8)) & 0xffff;
128}
129
130void pm3386_init_port(int port)
131{
132 int pm = port >> 1;
133
134 /*
135 * Work around ENP2611 bootloader programming MAC address
136 * in reverse.
137 */
138 if (pm3386_port_reg_read(port, 0x30a, 0x100) == 0x0000 &&
139 (pm3386_port_reg_read(port, 0x309, 0x100) & 0xff00) == 0x5000) {
140 u16 temp[3];
141
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]));
148 }
149
150 /*
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.)
154 */
155 pm3386_port_reg_write(port, 0x708, 0x10, 0xd055);
156 udelay(500);
157 pm3386_port_reg_write(port, 0x708, 0x10, 0x5055);
158
159 /*
160 * SPI-3 ingress block. Set 64 bytes SPI-3 burst size
161 * towards SPI-3 bridge.
162 */
163 pm3386_port_reg_write(port, 0x122, 0x20, 0x0002);
164
165 /*
166 * Enable ingress protocol checking, and soft reset the
167 * SPI-3 ingress block.
168 */
169 pm3386_reg_write(pm, 0x103, 0x0003);
170 while (!(pm3386_reg_read(pm, 0x103) & 0x80))
171 ;
172
173 /*
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.)
177 */
178 pm3386_port_reg_write(port, 0x221, 0x20, 0x0007);
179
180 /*
181 * Enforce odd parity from the SPI-3 bridge, and soft reset
182 * the SPI-3 egress block.
183 */
184 pm3386_reg_write(pm, 0x203, 0x000d & ~(4 << (port & 1)));
185 while ((pm3386_reg_read(pm, 0x203) & 0x000c) != 0x000c)
186 ;
187
188 /*
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
192 * TX frame padding.
193 */
194 pm3386_port_reg_write(port, 0x302, 0x100, 0x0113);
195
196 /*
197 * Soft reset the EGMAC block.
198 */
199 pm3386_port_reg_write(port, 0x301, 0x100, 0x8000);
200 pm3386_port_reg_write(port, 0x301, 0x100, 0x0000);
201
202 /*
203 * Auto-sense autonegotiation status.
204 */
205 pm3386_port_reg_write(port, 0x306, 0x100, 0x0100);
206
207 /*
208 * Allow reception of jumbo frames.
209 */
210 pm3386_port_reg_write(port, 0x310, 0x100, 9018);
211
212 /*
213 * Allow transmission of jumbo frames.
214 */
215 pm3386_port_reg_write(port, 0x336, 0x100, 9018);
216
217 /* @@@ Should set 0x337/0x437 (RX forwarding threshold.) */
218
219 /*
220 * Set autonegotiation parameters to 'no PAUSE, full duplex.'
221 */
222 pm3386_port_reg_write(port, 0x31c, 0x100, 0x0020);
223
224 /*
225 * Enable and restart autonegotiation.
226 */
227 pm3386_port_reg_write(port, 0x318, 0x100, 0x0003);
228 pm3386_port_reg_write(port, 0x318, 0x100, 0x0002);
229}
230
231void pm3386_get_mac(int port, u8 *mac)
232{
233 u16 temp;
234
235 temp = pm3386_port_reg_read(port, 0x308, 0x100);
236 mac[0] = temp & 0xff;
237 mac[1] = (temp >> 8) & 0xff;
238
239 temp = pm3386_port_reg_read(port, 0x309, 0x100);
240 mac[2] = temp & 0xff;
241 mac[3] = (temp >> 8) & 0xff;
242
243 temp = pm3386_port_reg_read(port, 0x30a, 0x100);
244 mac[4] = temp & 0xff;
245 mac[5] = (temp >> 8) & 0xff;
246}
247
248void pm3386_set_mac(int port, u8 *mac)
249{
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]);
253}
254
255static u32 pm3386_get_stat(int port, u16 base)
256{
257 u32 value;
258
259 value = pm3386_port_reg_read(port, base, 0x100);
260 value |= pm3386_port_reg_read(port, base + 1, 0x100) << 16;
261
262 return value;
263}
264
265void pm3386_get_stats(int port, struct net_device_stats *stats)
266{
267 /*
268 * Snapshot statistics counters.
269 */
270 pm3386_port_reg_write(port, 0x500, 0x100, 0x0001);
271 while (pm3386_port_reg_read(port, 0x500, 0x100) & 0x0001)
272 ;
273
274 memset(stats, 0, sizeof(*stats));
275
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. */
281}
282
283void pm3386_set_carrier(int port, int state)
284{
285 pm3386_port_reg_write(port, 0x703, 0x10, state ? 0x1001 : 0x0000);
286}
287
288int pm3386_is_link_up(int port)
289{
290 u16 temp;
291
292 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
293 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
294
295 return !!(temp & 0x0002);
296}
297
298void pm3386_enable_rx(int port)
299{
300 u16 temp;
301
302 temp = pm3386_port_reg_read(port, 0x303, 0x100);
303 temp |= 0x1000;
304 pm3386_port_reg_write(port, 0x303, 0x100, temp);
305}
306
307void pm3386_disable_rx(int port)
308{
309 u16 temp;
310
311 temp = pm3386_port_reg_read(port, 0x303, 0x100);
312 temp &= 0xefff;
313 pm3386_port_reg_write(port, 0x303, 0x100, temp);
314}
315
316void pm3386_enable_tx(int port)
317{
318 u16 temp;
319
320 temp = pm3386_port_reg_read(port, 0x303, 0x100);
321 temp |= 0x4000;
322 pm3386_port_reg_write(port, 0x303, 0x100, temp);
323}
324
325void pm3386_disable_tx(int port)
326{
327 u16 temp;
328
329 temp = pm3386_port_reg_read(port, 0x303, 0x100);
330 temp &= 0xbfff;
331 pm3386_port_reg_write(port, 0x303, 0x100, temp);
332}
333
334MODULE_LICENSE("GPL");