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)
92 /* @@@ Implement me. */
95 static u16 swaph(u16 x)
97 return ((x << 8) | (x >> 8)) & 0xffff;
100 void pm3386_init_port(int port)
105 * Work around ENP2611 bootloader programming MAC address
108 if (pm3386_port_reg_read(port, 0x30a, 0x100) == 0x0000 &&
109 (pm3386_port_reg_read(port, 0x309, 0x100) & 0xff00) == 0x5000) {
112 temp[0] = pm3386_port_reg_read(port, 0x308, 0x100);
113 temp[1] = pm3386_port_reg_read(port, 0x309, 0x100);
114 temp[2] = pm3386_port_reg_read(port, 0x30a, 0x100);
115 pm3386_port_reg_write(port, 0x308, 0x100, swaph(temp[2]));
116 pm3386_port_reg_write(port, 0x309, 0x100, swaph(temp[1]));
117 pm3386_port_reg_write(port, 0x30a, 0x100, swaph(temp[0]));
121 * Initialise narrowbanding mode. See application note 2010486
122 * for more information. (@@@ We also need to issue a reset
123 * when ROOL or DOOL are detected.)
125 pm3386_port_reg_write(port, 0x708, 0x10, 0xd055);
127 pm3386_port_reg_write(port, 0x708, 0x10, 0x5055);
130 * SPI-3 ingress block. Set 64 bytes SPI-3 burst size
131 * towards SPI-3 bridge.
133 pm3386_port_reg_write(port, 0x122, 0x20, 0x0002);
136 * Enable ingress protocol checking, and soft reset the
137 * SPI-3 ingress block.
139 pm3386_reg_write(pm, 0x103, 0x0003);
140 while (!(pm3386_reg_read(pm, 0x103) & 0x80))
144 * SPI-3 egress block. Gather 12288 bytes of the current
145 * packet in the TX fifo before initiating transmit on the
146 * SERDES interface. (Prevents TX underflows.)
148 pm3386_port_reg_write(port, 0x221, 0x20, 0x0007);
151 * Enforce odd parity from the SPI-3 bridge, and soft reset
152 * the SPI-3 egress block.
154 pm3386_reg_write(pm, 0x203, 0x000d & ~(4 << (port & 1)));
155 while ((pm3386_reg_read(pm, 0x203) & 0x000c) != 0x000c)
159 * EGMAC block. Set this channels to reject long preambles,
160 * not send or transmit PAUSE frames, enable preamble checking,
161 * disable frame length checking, enable FCS appending, enable
164 pm3386_port_reg_write(port, 0x302, 0x100, 0x0113);
167 * Soft reset the EGMAC block.
169 pm3386_port_reg_write(port, 0x301, 0x100, 0x8000);
170 pm3386_port_reg_write(port, 0x301, 0x100, 0x0000);
173 * Auto-sense autonegotiation status.
175 pm3386_port_reg_write(port, 0x306, 0x100, 0x0100);
178 * Allow reception of jumbo frames.
180 pm3386_port_reg_write(port, 0x310, 0x100, 9018);
183 * Allow transmission of jumbo frames.
185 pm3386_port_reg_write(port, 0x336, 0x100, 9018);
187 /* @@@ Should set 0x337/0x437 (RX forwarding threshold.) */
190 * Set autonegotiation parameters to 'no PAUSE, full duplex.'
192 pm3386_port_reg_write(port, 0x31c, 0x100, 0x0020);
195 * Enable and restart autonegotiation.
197 pm3386_port_reg_write(port, 0x318, 0x100, 0x0003);
198 pm3386_port_reg_write(port, 0x318, 0x100, 0x0002);
201 void pm3386_get_mac(int port, u8 *mac)
205 temp = pm3386_port_reg_read(port, 0x308, 0x100);
206 mac[0] = temp & 0xff;
207 mac[1] = (temp >> 8) & 0xff;
209 temp = pm3386_port_reg_read(port, 0x309, 0x100);
210 mac[2] = temp & 0xff;
211 mac[3] = (temp >> 8) & 0xff;
213 temp = pm3386_port_reg_read(port, 0x30a, 0x100);
214 mac[4] = temp & 0xff;
215 mac[5] = (temp >> 8) & 0xff;
218 void pm3386_set_mac(int port, u8 *mac)
220 pm3386_port_reg_write(port, 0x308, 0x100, (mac[1] << 8) | mac[0]);
221 pm3386_port_reg_write(port, 0x309, 0x100, (mac[3] << 8) | mac[2]);
222 pm3386_port_reg_write(port, 0x30a, 0x100, (mac[5] << 8) | mac[4]);
225 static u32 pm3386_get_stat(int port, u16 base)
229 value = pm3386_port_reg_read(port, base, 0x100);
230 value |= pm3386_port_reg_read(port, base + 1, 0x100) << 16;
235 void pm3386_get_stats(int port, struct net_device_stats *stats)
238 * Snapshot statistics counters.
240 pm3386_port_reg_write(port, 0x500, 0x100, 0x0001);
241 while (pm3386_port_reg_read(port, 0x500, 0x100) & 0x0001)
244 memset(stats, 0, sizeof(*stats));
246 stats->rx_packets = pm3386_get_stat(port, 0x510);
247 stats->tx_packets = pm3386_get_stat(port, 0x590);
248 stats->rx_bytes = pm3386_get_stat(port, 0x514);
249 stats->tx_bytes = pm3386_get_stat(port, 0x594);
250 /* @@@ Add other stats. */
253 int pm3386_is_link_up(int port)
257 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
258 temp = pm3386_port_reg_read(port, 0x31a, 0x100);
260 return !!(temp & 0x0002);
263 void pm3386_enable_rx(int port)
267 temp = pm3386_port_reg_read(port, 0x303, 0x100);
269 pm3386_port_reg_write(port, 0x303, 0x100, temp);
272 void pm3386_disable_rx(int port)
276 temp = pm3386_port_reg_read(port, 0x303, 0x100);
278 pm3386_port_reg_write(port, 0x303, 0x100, temp);
281 void pm3386_enable_tx(int port)
285 temp = pm3386_port_reg_read(port, 0x303, 0x100);
287 pm3386_port_reg_write(port, 0x303, 0x100, temp);
290 void pm3386_disable_tx(int port)
294 temp = pm3386_port_reg_read(port, 0x303, 0x100);
296 pm3386_port_reg_write(port, 0x303, 0x100, temp);
299 MODULE_LICENSE("GPL");