Linux 2.6.17.3
[linux/fpc-iii.git] / drivers / net / ixp2000 / pm3386.c
blob5224651c9aac30e3ab308286c7d01f93c987ee79
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.
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>
16 #include <asm/io.h>
17 #include "pm3386.h"
20 * Read from register 'reg' of PM3386 device 'pm'.
22 static u16 pm3386_reg_read(int pm, int reg)
24 void *_reg;
25 u16 value;
27 _reg = (void *)ENP2611_PM3386_0_VIRT_BASE;
28 if (pm == 1)
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);
35 return 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)
44 void *_reg;
45 u16 dummy;
47 // printk(KERN_INFO "pm3386_reg_write(%d, %.3x, %.8x)\n", pm, reg, value);
49 _reg = (void *)ENP2611_PM3386_0_VIRT_BASE;
50 if (pm == 1)
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)
65 int reg;
67 reg = _reg;
68 if (port & 1)
69 reg += 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)
80 int reg;
82 reg = _reg;
83 if (port & 1)
84 reg += spacing;
86 pm3386_reg_write(port >> 1, reg, value);
89 int pm3386_secondary_present(void)
91 return pm3386_reg_read(1, 0) == 0x3386;
94 void pm3386_reset(void)
96 u8 mac[3][6];
97 int secondary;
99 secondary = pm3386_secondary_present();
101 /* Save programmed MAC addresses. */
102 pm3386_get_mac(0, mac[0]);
103 pm3386_get_mac(1, mac[1]);
104 if (secondary)
105 pm3386_get_mac(2, mac[2]);
107 /* Assert analog and digital reset. */
108 pm3386_reg_write(0, 0x002, 0x0060);
109 if (secondary)
110 pm3386_reg_write(1, 0x002, 0x0060);
111 mdelay(1);
113 /* Deassert analog reset. */
114 pm3386_reg_write(0, 0x002, 0x0062);
115 if (secondary)
116 pm3386_reg_write(1, 0x002, 0x0062);
117 mdelay(10);
119 /* Deassert digital reset. */
120 pm3386_reg_write(0, 0x002, 0x0063);
121 if (secondary)
122 pm3386_reg_write(1, 0x002, 0x0063);
123 mdelay(10);
125 /* Restore programmed MAC addresses. */
126 pm3386_set_mac(0, mac[0]);
127 pm3386_set_mac(1, mac[1]);
128 if (secondary)
129 pm3386_set_mac(2, mac[2]);
131 /* Disable carrier on all ports. */
132 pm3386_set_carrier(0, 0);
133 pm3386_set_carrier(1, 0);
134 if (secondary)
135 pm3386_set_carrier(2, 0);
138 static u16 swaph(u16 x)
140 return ((x << 8) | (x >> 8)) & 0xffff;
143 int pm3386_port_count(void)
145 return 2 + pm3386_secondary_present();
148 void pm3386_init_port(int port)
150 int pm = port >> 1;
153 * Work around ENP2611 bootloader programming MAC address
154 * in reverse.
156 if (pm3386_port_reg_read(port, 0x30a, 0x100) == 0x0000 &&
157 (pm3386_port_reg_read(port, 0x309, 0x100) & 0xff00) == 0x5000) {
158 u16 temp[3];
160 temp[0] = pm3386_port_reg_read(port, 0x308, 0x100);
161 temp[1] = pm3386_port_reg_read(port, 0x309, 0x100);
162 temp[2] = pm3386_port_reg_read(port, 0x30a, 0x100);
163 pm3386_port_reg_write(port, 0x308, 0x100, swaph(temp[2]));
164 pm3386_port_reg_write(port, 0x309, 0x100, swaph(temp[1]));
165 pm3386_port_reg_write(port, 0x30a, 0x100, swaph(temp[0]));
169 * Initialise narrowbanding mode. See application note 2010486
170 * for more information. (@@@ We also need to issue a reset
171 * when ROOL or DOOL are detected.)
173 pm3386_port_reg_write(port, 0x708, 0x10, 0xd055);
174 udelay(500);
175 pm3386_port_reg_write(port, 0x708, 0x10, 0x5055);
178 * SPI-3 ingress block. Set 64 bytes SPI-3 burst size
179 * towards SPI-3 bridge.
181 pm3386_port_reg_write(port, 0x122, 0x20, 0x0002);
184 * Enable ingress protocol checking, and soft reset the
185 * SPI-3 ingress block.
187 pm3386_reg_write(pm, 0x103, 0x0003);
188 while (!(pm3386_reg_read(pm, 0x103) & 0x80))
192 * SPI-3 egress block. Gather 12288 bytes of the current
193 * packet in the TX fifo before initiating transmit on the
194 * SERDES interface. (Prevents TX underflows.)
196 pm3386_port_reg_write(port, 0x221, 0x20, 0x0007);
199 * Enforce odd parity from the SPI-3 bridge, and soft reset
200 * the SPI-3 egress block.
202 pm3386_reg_write(pm, 0x203, 0x000d & ~(4 << (port & 1)));
203 while ((pm3386_reg_read(pm, 0x203) & 0x000c) != 0x000c)
207 * EGMAC block. Set this channels to reject long preambles,
208 * not send or transmit PAUSE frames, enable preamble checking,
209 * disable frame length checking, enable FCS appending, enable
210 * TX frame padding.
212 pm3386_port_reg_write(port, 0x302, 0x100, 0x0113);
215 * Soft reset the EGMAC block.
217 pm3386_port_reg_write(port, 0x301, 0x100, 0x8000);
218 pm3386_port_reg_write(port, 0x301, 0x100, 0x0000);
221 * Auto-sense autonegotiation status.
223 pm3386_port_reg_write(port, 0x306, 0x100, 0x0100);
226 * Allow reception of jumbo frames.
228 pm3386_port_reg_write(port, 0x310, 0x100, 9018);
231 * Allow transmission of jumbo frames.
233 pm3386_port_reg_write(port, 0x336, 0x100, 9018);
235 /* @@@ Should set 0x337/0x437 (RX forwarding threshold.) */
238 * Set autonegotiation parameters to 'no PAUSE, full duplex.'
240 pm3386_port_reg_write(port, 0x31c, 0x100, 0x0020);
243 * Enable and restart autonegotiation.
245 pm3386_port_reg_write(port, 0x318, 0x100, 0x0003);
246 pm3386_port_reg_write(port, 0x318, 0x100, 0x0002);
249 void pm3386_get_mac(int port, u8 *mac)
251 u16 temp;
253 temp = pm3386_port_reg_read(port, 0x308, 0x100);
254 mac[0] = temp & 0xff;
255 mac[1] = (temp >> 8) & 0xff;
257 temp = pm3386_port_reg_read(port, 0x309, 0x100);
258 mac[2] = temp & 0xff;
259 mac[3] = (temp >> 8) & 0xff;
261 temp = pm3386_port_reg_read(port, 0x30a, 0x100);
262 mac[4] = temp & 0xff;
263 mac[5] = (temp >> 8) & 0xff;
266 void pm3386_set_mac(int port, u8 *mac)
268 pm3386_port_reg_write(port, 0x308, 0x100, (mac[1] << 8) | mac[0]);
269 pm3386_port_reg_write(port, 0x309, 0x100, (mac[3] << 8) | mac[2]);
270 pm3386_port_reg_write(port, 0x30a, 0x100, (mac[5] << 8) | mac[4]);
273 static u32 pm3386_get_stat(int port, u16 base)
275 u32 value;
277 value = pm3386_port_reg_read(port, base, 0x100);
278 value |= pm3386_port_reg_read(port, base + 1, 0x100) << 16;
280 return value;
283 void pm3386_get_stats(int port, struct net_device_stats *stats)
286 * Snapshot statistics counters.
288 pm3386_port_reg_write(port, 0x500, 0x100, 0x0001);
289 while (pm3386_port_reg_read(port, 0x500, 0x100) & 0x0001)
292 memset(stats, 0, sizeof(*stats));
294 stats->rx_packets = pm3386_get_stat(port, 0x510);
295 stats->tx_packets = pm3386_get_stat(port, 0x590);
296 stats->rx_bytes = pm3386_get_stat(port, 0x514);
297 stats->tx_bytes = pm3386_get_stat(port, 0x594);
298 /* @@@ Add other stats. */
301 void pm3386_set_carrier(int port, int state)
303 pm3386_port_reg_write(port, 0x703, 0x10, state ? 0x1001 : 0x0000);
306 int pm3386_is_link_up(int port)
308 u16 temp;
310 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
311 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
313 return !!(temp & 0x0002);
316 void pm3386_enable_rx(int port)
318 u16 temp;
320 temp = pm3386_port_reg_read(port, 0x303, 0x100);
321 temp |= 0x1000;
322 pm3386_port_reg_write(port, 0x303, 0x100, temp);
325 void pm3386_disable_rx(int port)
327 u16 temp;
329 temp = pm3386_port_reg_read(port, 0x303, 0x100);
330 temp &= 0xefff;
331 pm3386_port_reg_write(port, 0x303, 0x100, temp);
334 void pm3386_enable_tx(int port)
336 u16 temp;
338 temp = pm3386_port_reg_read(port, 0x303, 0x100);
339 temp |= 0x4000;
340 pm3386_port_reg_write(port, 0x303, 0x100, temp);
343 void pm3386_disable_tx(int port)
345 u16 temp;
347 temp = pm3386_port_reg_read(port, 0x303, 0x100);
348 temp &= 0xbfff;
349 pm3386_port_reg_write(port, 0x303, 0x100, temp);
352 MODULE_LICENSE("GPL");