2005-12-25 16:18:55 +02:00
|
|
|
/*
|
2005-12-25 16:24:36 +02:00
|
|
|
* ADMTEK Adm6996 switch configuration module
|
2005-12-25 16:18:55 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Felix Fietkau <nbd@nbd.name>
|
2010-07-21 01:25:04 +03:00
|
|
|
*
|
2006-03-18 20:09:48 +02:00
|
|
|
* Partially based on Broadcom Home Networking Division 10/100 Mbit/s
|
|
|
|
* Ethernet Device Driver (from Montavista 2.4.20_mvl31 Kernel).
|
|
|
|
* Copyright (C) 2004 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* adm_rreg function from adm6996
|
|
|
|
* Copyright (C) 2004 Nikki Chumakov <nikki@gattaca.ru>
|
2005-12-25 16:18:55 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-21 01:25:04 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
2005-12-25 16:18:55 +02:00
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include "switch-core.h"
|
2005-12-26 00:13:00 +02:00
|
|
|
#include "gpio.h"
|
2005-12-25 16:18:55 +02:00
|
|
|
|
|
|
|
#define DRIVER_NAME "adm6996"
|
2006-01-12 00:57:52 +02:00
|
|
|
#define DRIVER_VERSION "0.01"
|
2005-12-25 16:18:55 +02:00
|
|
|
|
2006-01-14 19:49:21 +02:00
|
|
|
static int eecs = 0;
|
|
|
|
static int eesk = 0;
|
|
|
|
static int eedi = 0;
|
|
|
|
static int eerc = 0;
|
2005-12-25 16:18:55 +02:00
|
|
|
static int force = 0;
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Felix Fietkau <openwrt@nbd.name>");
|
|
|
|
MODULE_LICENSE("GPL");
|
2006-06-20 11:28:06 +03:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,52)
|
2006-06-19 05:05:27 +03:00
|
|
|
module_param(eecs, int, 0);
|
|
|
|
module_param(eesk, int, 0);
|
|
|
|
module_param(eedi, int, 0);
|
|
|
|
module_param(eerc, int, 0);
|
|
|
|
module_param(force, int, 0);
|
|
|
|
#else
|
2005-12-25 16:18:55 +02:00
|
|
|
MODULE_PARM(eecs, "i");
|
|
|
|
MODULE_PARM(eesk, "i");
|
|
|
|
MODULE_PARM(eedi, "i");
|
|
|
|
MODULE_PARM(eerc, "i");
|
|
|
|
MODULE_PARM(force, "i");
|
2006-06-19 05:05:27 +03:00
|
|
|
#endif
|
2005-12-25 16:18:55 +02:00
|
|
|
|
|
|
|
/* Minimum timing constants */
|
|
|
|
#define EECK_EDGE_TIME 3 /* 3us - max(adm 2.5us, 93c 1us) */
|
|
|
|
#define EEDI_SETUP_TIME 1 /* 1us - max(adm 10ns, 93c 400ns) */
|
|
|
|
#define EECS_SETUP_TIME 1 /* 1us - max(adm no, 93c 200ns) */
|
|
|
|
|
|
|
|
/* Handy macros for writing fixed length values */
|
|
|
|
#define adm_write8(cs, b) { __u8 val = (__u8) (b); adm_write(cs, &val, sizeof(val)*8); }
|
|
|
|
#define adm_write16(cs, w) { __u16 val = hton16(w); adm_write(cs, (__u8 *)&val, sizeof(val)*8); }
|
|
|
|
#define adm_write32(cs, i) { uint32 val = hton32(i); adm_write(cs, (__u8 *)&val, sizeof(val)*8); }
|
|
|
|
|
2006-01-12 00:57:52 +02:00
|
|
|
#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
|
2005-12-25 16:18:55 +02:00
|
|
|
|
2007-03-14 15:42:21 +02:00
|
|
|
#ifdef BROADCOM
|
2006-01-12 00:57:52 +02:00
|
|
|
extern char *nvram_get(char *name);
|
2005-12-25 16:18:55 +02:00
|
|
|
|
2006-01-14 19:49:21 +02:00
|
|
|
/* Return gpio pin number assigned to the named pin */
|
|
|
|
/*
|
|
|
|
* Variable should be in format:
|
|
|
|
*
|
|
|
|
* gpio<N>=pin_name
|
|
|
|
*
|
|
|
|
* 'def_pin' is returned if there is no such variable found.
|
|
|
|
*/
|
2007-03-14 15:42:21 +02:00
|
|
|
static unsigned int get_gpiopin(char *pin_name, unsigned int def_pin)
|
2006-01-14 19:49:21 +02:00
|
|
|
{
|
|
|
|
char name[] = "gpioXXXX";
|
|
|
|
char *val;
|
|
|
|
unsigned int pin;
|
|
|
|
|
|
|
|
/* Go thru all possibilities till a match in pin name */
|
|
|
|
for (pin = 0; pin < 16; pin ++) {
|
|
|
|
sprintf(name, "gpio%d", pin);
|
|
|
|
val = nvram_get(name);
|
|
|
|
if (val && !strcmp(val, pin_name))
|
|
|
|
return pin;
|
|
|
|
}
|
|
|
|
return def_pin;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
|
|
|
|
static void adm_write(int cs, char *buf, unsigned int bits)
|
|
|
|
{
|
|
|
|
int i, len = (bits + 7) / 8;
|
|
|
|
__u8 mask;
|
|
|
|
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eecs, (cs ? eecs : 0));
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
/* Byte assemble from MSB to LSB */
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
/* Bit bang from MSB to LSB */
|
|
|
|
for (mask = 0x80; mask && bits > 0; mask >>= 1, bits --) {
|
|
|
|
/* Clock low */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
/* Output on rising edge */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eedi, ((mask & buf[i]) ? eedi : 0));
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EEDI_SETUP_TIME);
|
|
|
|
|
|
|
|
/* Clock high */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, eesk);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clock low */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
if (cs)
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eecs, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void adm_read(int cs, char *buf, unsigned int bits)
|
|
|
|
{
|
|
|
|
int i, len = (bits + 7) / 8;
|
|
|
|
__u8 mask;
|
|
|
|
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eecs, (cs ? eecs : 0));
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
/* Byte assemble from MSB to LSB */
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
__u8 byte;
|
|
|
|
|
|
|
|
/* Bit bang from MSB to LSB */
|
|
|
|
for (mask = 0x80, byte = 0; mask && bits > 0; mask >>= 1, bits --) {
|
|
|
|
__u8 gp;
|
|
|
|
|
|
|
|
/* Clock low */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
/* Input on rising edge */
|
2007-03-14 03:19:24 +02:00
|
|
|
gp = gpio_in();
|
2005-12-25 16:18:55 +02:00
|
|
|
if (gp & eedi)
|
|
|
|
byte |= mask;
|
|
|
|
|
|
|
|
/* Clock high */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, eesk);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
*buf++ = byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clock low */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
if (cs)
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eecs, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Enable outputs with specified value to the chip */
|
|
|
|
static void adm_enout(__u8 pins, __u8 val)
|
2010-07-21 01:25:04 +03:00
|
|
|
{
|
2005-12-25 16:18:55 +02:00
|
|
|
/* Prepare GPIO output value */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(pins, val);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
/* Enable GPIO outputs */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_outen(pins, pins);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Disable outputs to the chip */
|
|
|
|
static void adm_disout(__u8 pins)
|
2010-07-21 01:25:04 +03:00
|
|
|
{
|
2005-12-25 16:18:55 +02:00
|
|
|
/* Disable GPIO outputs */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_outen(pins, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Advance clock(s) */
|
|
|
|
static void adm_adclk(int clocks)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < clocks; i++) {
|
|
|
|
/* Clock high */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, eesk);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
|
|
|
|
/* Clock low */
|
2007-03-14 03:19:24 +02:00
|
|
|
gpio_out(eesk, 0);
|
2005-12-25 16:18:55 +02:00
|
|
|
udelay(EECK_EDGE_TIME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __u32 adm_rreg(__u8 table, __u8 addr)
|
|
|
|
{
|
|
|
|
/* cmd: 01 10 T DD R RRRRRR */
|
|
|
|
__u8 bits[6] = {
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
(0x06 << 4) | ((table & 0x01) << 3 | (addr&64)>>6),
|
2006-12-27 21:35:13 +02:00
|
|
|
((addr&63)<<2)
|
2005-12-25 16:18:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
__u8 rbits[4];
|
|
|
|
|
|
|
|
/* Enable GPIO outputs with all pins to 0 */
|
|
|
|
adm_enout((__u8)(eecs | eesk | eedi), 0);
|
|
|
|
|
|
|
|
adm_write(0, bits, 46);
|
|
|
|
adm_disout((__u8)(eedi));
|
|
|
|
adm_adclk(2);
|
|
|
|
adm_read (0, rbits, 32);
|
|
|
|
|
|
|
|
/* Extra clock(s) required per datasheet */
|
|
|
|
adm_adclk(2);
|
|
|
|
|
|
|
|
/* Disable GPIO outputs */
|
|
|
|
adm_disout((__u8)(eecs | eesk));
|
|
|
|
|
|
|
|
if (!table) /* EEPROM has 16-bit registers, but pumps out two registers in one request */
|
|
|
|
return (addr & 0x01 ? (rbits[0]<<8) | rbits[1] : (rbits[2]<<8) | (rbits[3]));
|
|
|
|
else
|
|
|
|
return (rbits[0]<<24) | (rbits[1]<<16) | (rbits[2]<<8) | rbits[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Write chip configuration register */
|
|
|
|
/* Follow 93c66 timing and chip's min EEPROM timing requirement */
|
|
|
|
void
|
|
|
|
adm_wreg(__u8 addr, __u16 val)
|
|
|
|
{
|
|
|
|
/* cmd(27bits): sb(1) + opc(01) + addr(bbbbbbbb) + data(bbbbbbbbbbbbbbbb) */
|
|
|
|
__u8 bits[4] = {
|
|
|
|
(0x05 << 5) | (addr >> 3),
|
|
|
|
(addr << 5) | (__u8)(val >> 11),
|
|
|
|
(__u8)(val >> 3),
|
|
|
|
(__u8)(val << 5)
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Enable GPIO outputs with all pins to 0 */
|
|
|
|
adm_enout((__u8)(eecs | eesk | eedi), 0);
|
|
|
|
|
|
|
|
/* Write cmd. Total 27 bits */
|
|
|
|
adm_write(1, bits, 27);
|
|
|
|
|
|
|
|
/* Extra clock(s) required per datasheet */
|
|
|
|
adm_adclk(2);
|
|
|
|
|
|
|
|
/* Disable GPIO outputs */
|
|
|
|
adm_disout((__u8)(eecs | eesk | eedi));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Port configuration registers */
|
|
|
|
static int port_conf[] = { 0x01, 0x03, 0x05, 0x07, 0x08, 0x09 };
|
|
|
|
|
|
|
|
/* Bits in VLAN port mapping */
|
|
|
|
static int vlan_ports[] = { 1 << 0, 1 << 2, 1 << 4, 1 << 6, 1 << 7, 1 << 8 };
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_vlan_port_read(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int ports, i, c, len = 0;
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
if ((nr < 0) || (nr > 15))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Get VLAN port map */
|
|
|
|
ports = adm_rreg(0, 0x13 + nr);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
for (i = 0; i <= 5; i++) {
|
|
|
|
if (ports & vlan_ports[i]) {
|
|
|
|
c = adm_rreg(0, port_conf[i]);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2006-01-14 19:49:21 +02:00
|
|
|
len += sprintf(buf + len, "%d", i);
|
|
|
|
if (c & (1 << 4)) {
|
|
|
|
buf[len++] = 't';
|
|
|
|
if (((c & (0xf << 10)) >> 10) == nr)
|
|
|
|
buf[len++] = '*';
|
|
|
|
} else if (i == 5)
|
|
|
|
buf[len++] = 'u';
|
|
|
|
|
|
|
|
buf[len++] = '\t';
|
2005-12-25 16:18:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
len += sprintf(buf + len, "\n");
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_vlan_port_write(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
2006-01-04 21:10:06 +02:00
|
|
|
int i, cfg, ports;
|
|
|
|
switch_driver *d = (switch_driver *) driver;
|
|
|
|
switch_vlan_config *c = switch_parse_vlan(d, buf);
|
2005-12-25 16:18:55 +02:00
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
if (c == NULL)
|
2005-12-25 16:18:55 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
ports = adm_rreg(0, 0x13 + nr);
|
2006-01-04 21:10:06 +02:00
|
|
|
for (i = 0; i < d->ports; i++) {
|
|
|
|
if (c->port & (1 << i)) {
|
2005-12-25 16:18:55 +02:00
|
|
|
ports |= vlan_ports[i];
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
cfg = adm_rreg(0, port_conf[i]);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
/* Tagging */
|
2006-01-04 21:10:06 +02:00
|
|
|
if (c->untag & (1 << i))
|
|
|
|
cfg &= ~(1 << 4);
|
2005-12-25 16:18:55 +02:00
|
|
|
else
|
2006-01-04 21:10:06 +02:00
|
|
|
cfg |= (1 << 4);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
if ((c->untag | c->pvid) & (1 << i)) {
|
|
|
|
cfg = (cfg & ~(0xf << 10)) | (nr << 10);
|
|
|
|
}
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
adm_wreg(port_conf[i], (__u16) cfg);
|
2005-12-25 16:18:55 +02:00
|
|
|
} else {
|
|
|
|
ports &= ~(vlan_ports[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
adm_wreg(0x13 + nr, (__u16) ports);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_port_enable_read(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", ((adm_rreg(0, port_conf[nr]) & (1 << 5)) ? 0 : 1));
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_port_enable_write(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int reg = adm_rreg(0, port_conf[nr]);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
if (buf[0] == '0')
|
|
|
|
reg |= (1 << 5);
|
|
|
|
else if (buf[0] == '1')
|
|
|
|
reg &= ~(1 << 5);
|
|
|
|
else return -1;
|
|
|
|
|
|
|
|
adm_wreg(port_conf[nr], (__u16) reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_port_media_read(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int media = 0;
|
|
|
|
int reg = adm_rreg(0, port_conf[nr]);
|
|
|
|
|
|
|
|
if (reg & (1 << 1))
|
|
|
|
media |= SWITCH_MEDIA_AUTO;
|
|
|
|
if (reg & (1 << 2))
|
|
|
|
media |= SWITCH_MEDIA_100;
|
|
|
|
if (reg & (1 << 3))
|
|
|
|
media |= SWITCH_MEDIA_FD;
|
|
|
|
|
|
|
|
len = switch_print_media(buf, media);
|
|
|
|
return len + sprintf(buf + len, "\n");
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_port_media_write(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int media = switch_parse_media(buf);
|
|
|
|
int reg = adm_rreg(0, port_conf[nr]);
|
|
|
|
|
|
|
|
if (media < 0)
|
|
|
|
return -1;
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
reg &= ~((1 << 1) | (1 << 2) | (1 << 3));
|
|
|
|
if (media & SWITCH_MEDIA_AUTO)
|
|
|
|
reg |= 1 << 1;
|
|
|
|
if (media & SWITCH_MEDIA_100)
|
|
|
|
reg |= 1 << 2;
|
|
|
|
if (media & SWITCH_MEDIA_FD)
|
|
|
|
reg |= 1 << 3;
|
|
|
|
|
|
|
|
adm_wreg(port_conf[nr], reg);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_vlan_enable_read(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", ((adm_rreg(0, 0x11) & (1 << 5)) ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_vlan_enable_write(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int reg = adm_rreg(0, 0x11);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
if (buf[0] == '1')
|
|
|
|
reg |= (1 << 5);
|
|
|
|
else if (buf[0] == '0')
|
|
|
|
reg &= ~(1 << 5);
|
|
|
|
else return -1;
|
|
|
|
|
|
|
|
adm_wreg(0x11, (__u16) reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_reset(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int i;
|
2006-01-15 18:18:50 +02:00
|
|
|
u32 cfg;
|
2005-12-25 16:18:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset sequence: RC high->low(100ms)->high(30ms)
|
|
|
|
*
|
|
|
|
* WAR: Certain boards don't have the correct power on
|
|
|
|
* reset logic therefore we must explicitly perform the
|
|
|
|
* sequence in software.
|
|
|
|
*/
|
2006-01-14 19:49:21 +02:00
|
|
|
if (eerc) {
|
|
|
|
/* Keep RC high for at least 20ms */
|
|
|
|
adm_enout(eerc, eerc);
|
|
|
|
for (i = 0; i < 20; i ++)
|
|
|
|
udelay(1000);
|
|
|
|
/* Keep RC low for at least 100ms */
|
|
|
|
adm_enout(eerc, 0);
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
udelay(1000);
|
|
|
|
/* Set default configuration */
|
|
|
|
adm_enout((__u8)(eesk | eedi), eesk);
|
|
|
|
/* Keep RC high for at least 30ms */
|
|
|
|
adm_enout(eerc, eerc);
|
|
|
|
for (i = 0; i < 30; i++)
|
|
|
|
udelay(1000);
|
|
|
|
/* Leave RC high and disable GPIO outputs */
|
|
|
|
adm_disout((__u8)(eecs | eesk | eedi));
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2006-01-14 19:49:21 +02:00
|
|
|
}
|
2006-01-15 18:18:50 +02:00
|
|
|
|
|
|
|
/* set up initial configuration for cpu port */
|
|
|
|
cfg = (0x8000 | /* Auto MDIX */
|
|
|
|
(0xf << 10) | /* PVID */
|
|
|
|
(1 << 4) | /* Tagging */
|
|
|
|
0xf); /* full duplex, 100Mbps, auto neg, flow ctrl */
|
|
|
|
adm_wreg(port_conf[5], cfg);
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
/* vlan mode select register (0x11): vlan on, mac clone */
|
|
|
|
adm_wreg(0x11, 0xff30);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_registers(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int i, len = 0;
|
2010-07-21 01:25:04 +03:00
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
for (i = 0; i <= 0x33; i++) {
|
|
|
|
len += sprintf(buf + len, "0x%02x: 0x%04x\n", i, adm_rreg(0, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-01-04 21:10:06 +02:00
|
|
|
static int handle_counters(void *driver, char *buf, int nr)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int i, len = 0;
|
|
|
|
|
|
|
|
for (i = 0; i <= 0x3c; i++) {
|
|
|
|
len += sprintf(buf + len, "0x%02x: 0x%08x\n", i, adm_rreg(1, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-06-19 05:05:27 +03:00
|
|
|
static int detect_adm(void)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2007-03-14 15:42:21 +02:00
|
|
|
#ifdef BROADCOM
|
2006-01-12 00:57:52 +02:00
|
|
|
int boardflags = atoi(nvram_get("boardflags"));
|
2006-12-11 23:46:31 +02:00
|
|
|
int boardnum = atoi(nvram_get("boardnum"));
|
2006-01-12 00:57:52 +02:00
|
|
|
|
2007-11-16 05:11:09 +02:00
|
|
|
if ((boardnum == 44) && (boardflags == 0x0388)) { /* Trendware TEW-411BRP+ */
|
|
|
|
ret = 1;
|
2006-12-11 23:46:31 +02:00
|
|
|
|
2007-11-16 05:11:09 +02:00
|
|
|
eecs = get_gpiopin("adm_eecs", 2);
|
|
|
|
eesk = get_gpiopin("adm_eesk", 3);
|
|
|
|
eedi = get_gpiopin("adm_eedi", 4);
|
|
|
|
eerc = get_gpiopin("adm_rc", 5);
|
2006-12-11 23:46:31 +02:00
|
|
|
|
|
|
|
} else if ((boardflags & 0x80) || force) {
|
2006-01-14 19:49:21 +02:00
|
|
|
ret = 1;
|
|
|
|
|
2007-03-14 15:42:21 +02:00
|
|
|
eecs = get_gpiopin("adm_eecs", 2);
|
|
|
|
eesk = get_gpiopin("adm_eesk", 3);
|
|
|
|
eedi = get_gpiopin("adm_eedi", 4);
|
|
|
|
eerc = get_gpiopin("adm_rc", 0);
|
2006-01-14 19:49:21 +02:00
|
|
|
|
2006-01-15 18:18:50 +02:00
|
|
|
} else if ((strcmp(nvram_get("boardtype") ?: "", "bcm94710dev") == 0) &&
|
|
|
|
(strncmp(nvram_get("boardnum") ?: "", "42", 2) == 0)) {
|
2006-01-14 19:49:21 +02:00
|
|
|
/* WRT54G v1.1 hack */
|
|
|
|
eecs = 2;
|
|
|
|
eesk = 3;
|
|
|
|
eedi = 5;
|
|
|
|
|
2005-12-25 16:18:55 +02:00
|
|
|
ret = 1;
|
2008-11-03 01:14:16 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 19:49:21 +02:00
|
|
|
if (eecs)
|
|
|
|
eecs = (1 << eecs);
|
|
|
|
if (eesk)
|
|
|
|
eesk = (1 << eesk);
|
|
|
|
if (eedi)
|
|
|
|
eedi = (1 << eedi);
|
|
|
|
if (eerc)
|
|
|
|
eerc = (1 << eerc);
|
2005-12-25 16:18:55 +02:00
|
|
|
#else
|
|
|
|
ret = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-19 05:05:27 +03:00
|
|
|
static int __init adm_init(void)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
switch_config cfg[] = {
|
|
|
|
{"registers", handle_registers, NULL},
|
|
|
|
{"counters", handle_counters, NULL},
|
|
|
|
{"reset", NULL, handle_reset},
|
|
|
|
{"enable_vlan", handle_vlan_enable_read, handle_vlan_enable_write},
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
switch_config port[] = {
|
2006-01-12 00:57:52 +02:00
|
|
|
{"enable", handle_port_enable_read, handle_port_enable_write},
|
2005-12-25 16:18:55 +02:00
|
|
|
{"media", handle_port_media_read, handle_port_media_write},
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
switch_config vlan[] = {
|
|
|
|
{"ports", handle_vlan_port_read, handle_vlan_port_write},
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
switch_driver driver = {
|
|
|
|
name: DRIVER_NAME,
|
2006-01-12 00:57:52 +02:00
|
|
|
version: DRIVER_VERSION,
|
2006-01-04 21:10:06 +02:00
|
|
|
interface: "eth0",
|
2005-12-25 16:18:55 +02:00
|
|
|
ports: 6,
|
2006-01-04 21:10:06 +02:00
|
|
|
cpuport: 5,
|
2005-12-25 16:18:55 +02:00
|
|
|
vlans: 16,
|
|
|
|
driver_handlers: cfg,
|
|
|
|
port_handlers: port,
|
|
|
|
vlan_handlers: vlan,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!detect_adm())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return switch_register_driver(&driver);
|
|
|
|
}
|
|
|
|
|
2006-06-19 05:05:27 +03:00
|
|
|
static void __exit adm_exit(void)
|
2005-12-25 16:18:55 +02:00
|
|
|
{
|
|
|
|
switch_unregister_driver(DRIVER_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(adm_init);
|
|
|
|
module_exit(adm_exit);
|