/*
- * Broadcom BCM5325E/536x switch configuration module
+ * ADMTEK Adm6996 switch configuration module
*
* Copyright (C) 2005 Felix Fietkau <nbd@nbd.name>
*
#include <linux/delay.h>
#include <asm/uaccess.h>
-#include "gpio.h"
#include "switch-core.h"
+#include "gpio.h"
#define DRIVER_NAME "adm6996"
+#define DRIVER_VERSION "0.01"
static int eecs = 2;
static int eesk = 3;
#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); }
+#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
-extern int getintvar(char **vars, char *name);
+extern char *nvram_get(char *name);
static void adm_write(int cs, char *buf, unsigned int bits)
/* Bits in VLAN port mapping */
static int vlan_ports[] = { 1 << 0, 1 << 2, 1 << 4, 1 << 6, 1 << 7, 1 << 8 };
-static int handle_vlan_port_read(char *buf, int nr)
+static int handle_vlan_port_read(void *driver, char *buf, int nr)
{
int ports, i, c, len = 0;
return len;
}
-static int handle_vlan_port_write(char *buf, int nr)
+static int handle_vlan_port_write(void *driver, char *buf, int nr)
{
- int i, c, ports;
- int map = switch_parse_vlan(buf);
+ int i, cfg, ports;
+ switch_driver *d = (switch_driver *) driver;
+ switch_vlan_config *c = switch_parse_vlan(d, buf);
- if (map == -1)
+ if (c == NULL)
return -1;
ports = adm_rreg(0, 0x13 + nr);
- for (i = 0; i <= 5; i++) {
- if (map & (1 << i)) {
+ for (i = 0; i < d->ports; i++) {
+ if (c->port & (1 << i)) {
ports |= vlan_ports[i];
- c = adm_rreg(0, port_conf[i]);
+ cfg = adm_rreg(0, port_conf[i]);
/* Tagging */
- if (map & (1 << (8 + i)))
- c |= (1 << 4);
+ if (c->untag & (1 << i))
+ cfg &= ~(1 << 4);
else
- c &= ~(1 << 4);
-
- c = (c & ~(0xf << 10)) | (nr << 10);
+ cfg |= (1 << 4);
- adm_wreg(port_conf[i], (__u16) c);
+ if ((c->untag | c->pvid) & (1 << i)) {
+ cfg = (cfg & ~(0xf << 10)) | (nr << 10);
+ }
+
+ adm_wreg(port_conf[i], (__u16) cfg);
} else {
ports &= ~(vlan_ports[i]);
}
return 0;
}
-static int handle_port_enable_read(char *buf, int nr)
+static int handle_port_enable_read(void *driver, char *buf, int nr)
{
return sprintf(buf, "%d\n", ((adm_rreg(0, port_conf[nr]) & (1 << 5)) ? 0 : 1));
}
-static int handle_port_enable_write(char *buf, int nr)
+static int handle_port_enable_write(void *driver, char *buf, int nr)
{
int reg = adm_rreg(0, port_conf[nr]);
return 0;
}
-static int handle_port_media_read(char *buf, int nr)
+static int handle_port_media_read(void *driver, char *buf, int nr)
{
int len;
int media = 0;
return len + sprintf(buf + len, "\n");
}
-static int handle_port_media_write(char *buf, int nr)
+static int handle_port_media_write(void *driver, char *buf, int nr)
{
int media = switch_parse_media(buf);
int reg = adm_rreg(0, port_conf[nr]);
return 0;
}
-static int handle_vlan_enable_read(char *buf, int nr)
+static int handle_vlan_enable_read(void *driver, char *buf, int nr)
{
return sprintf(buf, "%d\n", ((adm_rreg(0, 0x11) & (1 << 5)) ? 1 : 0));
}
-static int handle_vlan_enable_write(char *buf, int nr)
+static int handle_vlan_enable_write(void *driver, char *buf, int nr)
{
int reg = adm_rreg(0, 0x11);
return 0;
}
-static int handle_reset(char *buf, int nr)
+static int handle_reset(void *driver, char *buf, int nr)
{
int i;
return 0;
}
-static int handle_registers(char *buf, int nr)
+static int handle_registers(void *driver, char *buf, int nr)
{
int i, len = 0;
return len;
}
-static int handle_counters(char *buf, int nr)
+static int handle_counters(void *driver, char *buf, int nr)
{
int i, len = 0;
int ret = 0;
#if defined(BCMGPIO2) || defined(BCMGPIO)
-#ifdef LINUX_2_4
- int boardflags = getintvar(NULL, "boardflags");
-#else
- extern int boardflags;
-#endif
+ int boardflags = atoi(nvram_get("boardflags"));
+
if ((boardflags & 0x80) || force)
ret = 1;
else
{NULL, NULL, NULL}
};
switch_config port[] = {
- {"enabled", handle_port_enable_read, handle_port_enable_write},
+ {"enable", handle_port_enable_read, handle_port_enable_write},
{"media", handle_port_media_read, handle_port_media_write},
{NULL, NULL, NULL}
};
};
switch_driver driver = {
name: DRIVER_NAME,
+ version: DRIVER_VERSION,
+ interface: "eth0",
ports: 6,
+ cpuport: 5,
vlans: 16,
driver_handlers: cfg,
port_handlers: port,