2 * Broadcom BCM5325E/536x switch configuration module
4 * Copyright (C) 2005 Felix Fietkau <nbd@nbd.name>
5 * Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
6 * Based on 'robocfg' by Oleg I. Vdovikin
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/init.h>
27 #include <linux/if_arp.h>
28 #include <linux/sockios.h>
29 #include <linux/ethtool.h>
30 #include <linux/mii.h>
31 #include <linux/delay.h>
32 #include <linux/gpio.h>
33 #include <asm/uaccess.h>
35 #include "switch-core.h"
39 #include <bcm47xx_nvram.h>
42 #define DRIVER_NAME "bcm53xx"
43 #define DRIVER_VERSION "0.02"
44 #define PFX "roboswitch: "
46 #define ROBO_PHY_ADDR 0x1E /* robo switch phy address */
47 #define ROBO_PHY_ADDR_TG3 0x01 /* Tigon3 PHY address */
48 #define ROBO_PHY_ADDR_BCM63XX 0x00 /* BCM63XX PHY address */
51 #define REG_MII_PAGE 0x10 /* MII Page register */
52 #define REG_MII_ADDR 0x11 /* MII Address register */
53 #define REG_MII_DATA0 0x18 /* MII Data register 0 */
55 #define REG_MII_PAGE_ENABLE 1
56 #define REG_MII_ADDR_WRITE 1
57 #define REG_MII_ADDR_READ 2
59 /* Robo device ID register (in ROBO_MGMT_PAGE) */
60 #define ROBO_DEVICE_ID 0x30
61 #define ROBO_DEVICE_ID_5325 0x25 /* Faked */
62 #define ROBO_DEVICE_ID_5395 0x95
63 #define ROBO_DEVICE_ID_5397 0x97
64 #define ROBO_DEVICE_ID_5398 0x98
65 #define ROBO_DEVICE_ID_53115 0x3115
66 #define ROBO_DEVICE_ID_53125 0x3125
68 /* Private et.o ioctls */
69 #define SIOCGETCPHYRD (SIOCDEVPRIVATE + 9)
70 #define SIOCSETCPHYWR (SIOCDEVPRIVATE + 10)
72 /* Data structure for a Roboswitch device. */
74 char *device; /* The device name string (ethX) */
75 u16 devid; /* ROBO_DEVICE_ID_53xx */
77 bool gmii; /* gigabit mii */
80 int gpio_lanports_enable;
82 struct net_device *dev;
83 unsigned char port[9];
86 /* Currently we can only have one device in the system. */
87 static struct robo_switch robo;
90 static int do_ioctl(int cmd)
92 mm_segment_t old_fs = get_fs();
96 ret = robo.dev->netdev_ops->ndo_do_ioctl(robo.dev, &robo.ifr, cmd);
102 static u16 mdio_read(__u16 phy_id, __u8 reg)
104 struct mii_ioctl_data *mii = if_mii(&robo.ifr);
107 mii->phy_id = phy_id;
110 err = do_ioctl(SIOCGMIIREG);
112 printk(KERN_ERR PFX "failed to read mdio reg %i with err %i.\n", reg, err);
120 static void mdio_write(__u16 phy_id, __u8 reg, __u16 val)
122 struct mii_ioctl_data *mii = if_mii(&robo.ifr);
125 mii->phy_id = phy_id;
129 err = do_ioctl(SIOCSMIIREG);
131 printk(KERN_ERR PFX "failed to write mdio reg: %i with err %i.\n", reg, err);
136 static int robo_reg(__u8 page, __u8 reg, __u8 op)
140 /* set page number */
141 mdio_write(ROBO_PHY_ADDR, REG_MII_PAGE,
142 (page << 8) | REG_MII_PAGE_ENABLE);
144 /* set register address */
145 mdio_write(ROBO_PHY_ADDR, REG_MII_ADDR,
148 /* check if operation completed */
150 if ((mdio_read(ROBO_PHY_ADDR, REG_MII_ADDR) & 3) == 0)
154 printk(KERN_ERR PFX "timeout in robo_reg on page %i and reg %i with op %i.\n", page, reg, op);
160 static void robo_read(__u8 page, __u8 reg, __u16 *val, int count)
164 robo_reg(page, reg, REG_MII_ADDR_READ);
166 for (i = 0; i < count; i++)
167 val[i] = mdio_read(ROBO_PHY_ADDR, REG_MII_DATA0 + i);
171 static __u16 robo_read16(__u8 page, __u8 reg)
173 robo_reg(page, reg, REG_MII_ADDR_READ);
175 return mdio_read(ROBO_PHY_ADDR, REG_MII_DATA0);
178 static __u32 robo_read32(__u8 page, __u8 reg)
180 robo_reg(page, reg, REG_MII_ADDR_READ);
182 return mdio_read(ROBO_PHY_ADDR, REG_MII_DATA0) |
183 (mdio_read(ROBO_PHY_ADDR, REG_MII_DATA0 + 1) << 16);
186 static void robo_write16(__u8 page, __u8 reg, __u16 val16)
189 mdio_write(ROBO_PHY_ADDR, REG_MII_DATA0, val16);
191 robo_reg(page, reg, REG_MII_ADDR_WRITE);
194 static void robo_write32(__u8 page, __u8 reg, __u32 val32)
197 mdio_write(ROBO_PHY_ADDR, REG_MII_DATA0, val32 & 0xFFFF);
198 mdio_write(ROBO_PHY_ADDR, REG_MII_DATA0 + 1, val32 >> 16);
200 robo_reg(page, reg, REG_MII_ADDR_WRITE);
203 /* checks that attached switch is 5365 */
204 static bool robo_bcm5365(void)
206 /* set vlan access id to 15 and read it back */
208 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
210 /* 5365 will refuse this as it does not have this reg */
211 return robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS) != val16;
214 static bool robo_gmii(void)
216 if (mdio_read(0, ROBO_MII_STAT) & 0x0100)
217 return ((mdio_read(0, 0x0f) & 0xf000) != 0);
221 static int robo_switch_enable(void)
223 unsigned int i, last_port;
225 #ifdef CONFIG_BCM47XX
229 val = robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE);
230 if (!(val & (1 << 1))) {
233 /* With forwarding */
235 robo_write16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE, val);
236 val = robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE);
237 if (!(val & (1 << 1))) {
238 printk(KERN_ERR PFX "Failed to enable switch\n");
242 /* No spanning tree for unmanaged mode */
243 last_port = (robo.devid == ROBO_DEVICE_ID_5398) ?
244 ROBO_PORT7_CTRL : ROBO_PORT4_CTRL;
245 for (i = ROBO_PORT0_CTRL; i <= last_port; i++)
246 robo_write16(ROBO_CTRL_PAGE, i, 0);
248 /* No spanning tree on IMP port too */
249 robo_write16(ROBO_CTRL_PAGE, ROBO_IM_PORT_CTRL, 0);
252 if (robo.devid == ROBO_DEVICE_ID_53125) {
253 /* Make IM port status link by default */
254 val = robo_read16(ROBO_CTRL_PAGE, ROBO_PORT_OVERRIDE_CTRL) | 0xb1;
255 robo_write16(ROBO_CTRL_PAGE, ROBO_PORT_OVERRIDE_CTRL, val);
256 // TODO: init EEE feature
259 #ifdef CONFIG_BCM47XX
260 /* WAN port LED, except for Netgear WGT634U */
261 if (bcm47xx_nvram_getenv("nvram_type", buf, sizeof(buf)) >= 0) {
262 if (strcmp(buf, "cfe") != 0)
263 robo_write16(ROBO_CTRL_PAGE, 0x16, 0x1F);
269 static void robo_switch_reset(void)
271 if ((robo.devid == ROBO_DEVICE_ID_5395) ||
272 (robo.devid == ROBO_DEVICE_ID_5397) ||
273 (robo.devid == ROBO_DEVICE_ID_5398)) {
274 /* Trigger a software reset. */
275 robo_write16(ROBO_CTRL_PAGE, 0x79, 0x83);
277 robo_write16(ROBO_CTRL_PAGE, 0x79, 0);
281 #ifdef CONFIG_BCM47XX
282 static int get_gpio_pin(const char *name)
288 for (i = 0; i < 16; i++) {
289 err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i);
292 err = bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf));
295 if (!strcmp(name, buf))
302 static int robo_probe(char *devname)
307 struct mii_ioctl_data *mii;
309 printk(KERN_INFO PFX "Probing device '%s'\n", devname);
310 strcpy(robo.ifr.ifr_name, devname);
312 if ((robo.dev = dev_get_by_name(&init_net, devname)) == NULL) {
313 printk(KERN_ERR PFX "No such device\n");
317 if (!robo.dev->netdev_ops || !robo.dev->netdev_ops->ndo_do_ioctl) {
318 printk(KERN_ERR PFX "ndo_do_ioctl not implemented in ethernet driver\n");
323 robo.device = devname;
325 /* try access using MII ioctls - get phy address */
326 err = do_ioctl(SIOCGMIIPHY);
328 printk(KERN_ERR PFX "error (%i) while accessing MII phy registers with ioctls\n", err);
332 /* got phy address check for robo address */
333 mii = if_mii(&robo.ifr);
334 if ((mii->phy_id != ROBO_PHY_ADDR) &&
335 (mii->phy_id != ROBO_PHY_ADDR_BCM63XX) &&
336 (mii->phy_id != ROBO_PHY_ADDR_TG3)) {
337 printk(KERN_ERR PFX "Invalid phy address (%d)\n", mii->phy_id);
342 #ifdef CONFIG_BCM47XX
343 robo.gpio_lanports_enable = get_gpio_pin("lanports_enable");
344 if (robo.gpio_lanports_enable >= 0) {
345 err = gpio_request(robo.gpio_lanports_enable, "lanports_enable");
347 printk(KERN_ERR PFX "error (%i) requesting lanports_enable gpio (%i)\n",
348 err, robo.gpio_lanports_enable);
351 gpio_direction_output(robo.gpio_lanports_enable, 1);
355 robo.gpio_robo_reset = get_gpio_pin("robo_reset");
356 if (robo.gpio_robo_reset >= 0) {
357 err = gpio_request(robo.gpio_robo_reset, "robo_reset");
359 printk(KERN_ERR PFX "error (%i) requesting robo_reset gpio (%i)\n",
360 err, robo.gpio_robo_reset);
363 gpio_set_value(robo.gpio_robo_reset, 0);
364 gpio_direction_output(robo.gpio_robo_reset, 1);
365 gpio_set_value(robo.gpio_robo_reset, 0);
368 gpio_set_value(robo.gpio_robo_reset, 1);
371 // TODO: reset the internal robo switch
375 phyid = mdio_read(ROBO_PHY_ADDR, 0x2) |
376 (mdio_read(ROBO_PHY_ADDR, 0x3) << 16);
378 if (phyid == 0xffffffff || phyid == 0x55210022) {
379 printk(KERN_ERR PFX "No Robo switch in managed mode found, phy_id = 0x%08x\n", phyid);
381 goto err_gpio_lanports;
384 /* Get the device ID */
385 for (i = 0; i < 10; i++) {
386 robo.devid = robo_read16(ROBO_MGMT_PAGE, ROBO_DEVICE_ID);
392 robo.devid = ROBO_DEVICE_ID_5325; /* Fake it */
393 if (robo.devid == ROBO_DEVICE_ID_5325)
394 robo.is_5365 = robo_bcm5365();
396 robo.is_5365 = false;
398 robo.gmii = robo_gmii();
399 if (robo.devid == ROBO_DEVICE_ID_5325) {
400 for (i = 0; i < 5; i++)
403 for (i = 0; i < 8; i++)
406 robo.port[i] = ROBO_IM_PORT_CTRL;
409 err = robo_switch_enable();
411 goto err_gpio_lanports;
413 printk(KERN_INFO PFX "found a 5%s%x!%s at %s\n", robo.devid & 0xff00 ? "" : "3", robo.devid,
414 robo.is_5365 ? " It's a BCM5365." : "", devname);
419 if (robo.gpio_lanports_enable >= 0)
420 gpio_free(robo.gpio_lanports_enable);
422 if (robo.gpio_robo_reset >= 0)
423 gpio_free(robo.gpio_robo_reset);
431 static int handle_vlan_port_read_old(switch_driver *d, char *buf, int nr)
437 val16 = (nr) /* vlan */ | (0 << 12) /* read */ | (1 << 13) /* enable */;
440 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5365, val16);
442 val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_READ);
443 if ((val16 & (1 << 14)) /* valid */) {
444 for (j = 0; j < d->ports; j++) {
445 if (val16 & (1 << j)) {
446 len += sprintf(buf + len, "%d", j);
447 if (val16 & (1 << (j + 7))) {
452 if (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_PORT0_DEF_TAG + (j << 1)) == nr)
458 len += sprintf(buf + len, "\n");
462 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
464 val32 = robo_read32(ROBO_VLAN_PAGE, ROBO_VLAN_READ);
465 if ((val32 & (1 << 20)) /* valid */) {
466 for (j = 0; j < d->ports; j++) {
467 if (val32 & (1 << j)) {
468 len += sprintf(buf + len, "%d", j);
469 if (val32 & (1 << (j + d->ports))) {
474 if (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_PORT0_DEF_TAG + (j << 1)) == nr)
480 len += sprintf(buf + len, "\n");
489 static int handle_vlan_port_read_new(switch_driver *d, char *buf, int nr)
491 __u8 vtbl_entry, vtbl_index, vtbl_access;
496 if ((robo.devid == ROBO_DEVICE_ID_5395) ||
497 (robo.devid == ROBO_DEVICE_ID_53115) ||
498 (robo.devid == ROBO_DEVICE_ID_53125)) {
499 vtbl_access = ROBO_VTBL_ACCESS_5395;
500 vtbl_index = ROBO_VTBL_INDX_5395;
501 vtbl_entry = ROBO_VTBL_ENTRY_5395;
503 vtbl_access = ROBO_VTBL_ACCESS;
504 vtbl_index = ROBO_VTBL_INDX;
505 vtbl_entry = ROBO_VTBL_ENTRY;
508 robo_write16(ROBO_ARLIO_PAGE, vtbl_index, nr);
509 robo_write16(ROBO_ARLIO_PAGE, vtbl_access, (1 << 7) | (1 << 0));
510 val32 = robo_read32(ROBO_ARLIO_PAGE, vtbl_entry);
511 for (j = 0; j < d->ports; j++) {
512 if (val32 & (1 << j)) {
513 len += sprintf(buf + len, "%d", j);
514 if (val32 & (1 << (j + d->ports))) {
519 if (robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_PORT0_DEF_TAG + (j << 1)) == nr)
525 len += sprintf(buf + len, "\n");
530 static int handle_vlan_port_read(void *driver, char *buf, int nr)
532 switch_driver *d = (switch_driver *) driver;
534 if (robo.devid != ROBO_DEVICE_ID_5325)
535 return handle_vlan_port_read_new(d, buf, nr);
537 return handle_vlan_port_read_old(d, buf, nr);
540 static void handle_vlan_port_write_old(switch_driver *d, switch_vlan_config *c, int nr)
544 __u32 untag = ((c->untag & ~(1 << d->cpuport)) << d->ports);
546 /* write config now */
547 val16 = (nr) /* vlan */ | (1 << 12) /* write */ | (1 << 13) /* enable */;
549 robo_write32(ROBO_VLAN_PAGE, ROBO_VLAN_WRITE_5365,
550 (1 << 14) /* valid */ | (untag << 1 ) | c->port);
551 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS_5365, val16);
553 if (robo.corerev < 3)
554 val32 = (1 << 20) | ((nr >> 4) << 12) | untag | c->port;
556 val32 = (1 << 24) | (nr << 12) | untag | c->port;
557 robo_write32(ROBO_VLAN_PAGE, ROBO_VLAN_WRITE, val32);
558 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
562 static void handle_vlan_port_write_new(switch_driver *d, switch_vlan_config *c, int nr)
564 __u8 vtbl_entry, vtbl_index, vtbl_access;
565 __u32 untag = ((c->untag & ~(1 << d->cpuport)) << d->ports);
567 /* write config now */
568 if ((robo.devid == ROBO_DEVICE_ID_5395) ||
569 (robo.devid == ROBO_DEVICE_ID_53115) ||
570 (robo.devid == ROBO_DEVICE_ID_53125)) {
571 vtbl_access = ROBO_VTBL_ACCESS_5395;
572 vtbl_index = ROBO_VTBL_INDX_5395;
573 vtbl_entry = ROBO_VTBL_ENTRY_5395;
575 vtbl_access = ROBO_VTBL_ACCESS;
576 vtbl_index = ROBO_VTBL_INDX;
577 vtbl_entry = ROBO_VTBL_ENTRY;
580 robo_write32(ROBO_ARLIO_PAGE, vtbl_entry, untag | c->port);
581 robo_write16(ROBO_ARLIO_PAGE, vtbl_index, nr);
582 robo_write16(ROBO_ARLIO_PAGE, vtbl_access, 1 << 7);
585 static int handle_vlan_port_write(void *driver, char *buf, int nr)
587 switch_driver *d = (switch_driver *)driver;
588 switch_vlan_config *c = switch_parse_vlan(d, buf);
594 for (j = 0; j < d->ports; j++) {
595 if ((c->untag | c->pvid) & (1 << j)) {
596 /* change default vlan tag */
597 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_PORT0_DEF_TAG + (j << 1), nr);
601 if (robo.devid != ROBO_DEVICE_ID_5325)
602 handle_vlan_port_write_new(d, c, nr);
604 handle_vlan_port_write_old(d, c, nr);
610 #define set_switch(state) \
611 robo_write16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE, (robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE) & ~2) | (state ? 2 : 0));
613 static int handle_enable_read(void *driver, char *buf, int nr)
615 return sprintf(buf, "%d\n", (((robo_read16(ROBO_CTRL_PAGE, ROBO_SWITCH_MODE) & 2) == 2) ? 1 : 0));
618 static int handle_enable_write(void *driver, char *buf, int nr)
620 set_switch(buf[0] == '1');
625 static int handle_port_enable_read(void *driver, char *buf, int nr)
627 return sprintf(buf, "%d\n", ((robo_read16(ROBO_CTRL_PAGE, robo.port[nr]) & 3) == 3 ? 0 : 1));
630 static int handle_port_enable_write(void *driver, char *buf, int nr)
635 val16 = 3; /* disabled */
636 else if (buf[0] == '1')
637 val16 = 0; /* enabled */
641 robo_write16(ROBO_CTRL_PAGE, robo.port[nr],
642 (robo_read16(ROBO_CTRL_PAGE, robo.port[nr]) & ~3) | val16);
647 static int handle_port_media_read(void *driver, char *buf, int nr)
649 u16 bmcr = mdio_read(robo.port[nr], MII_BMCR);
652 if (bmcr & BMCR_ANENABLE)
653 media = SWITCH_MEDIA_AUTO;
655 if (bmcr & BMCR_SPEED1000)
656 media = SWITCH_MEDIA_1000;
657 else if (bmcr & BMCR_SPEED100)
658 media = SWITCH_MEDIA_100;
662 if (bmcr & BMCR_FULLDPLX)
663 media |= SWITCH_MEDIA_FD;
666 len = switch_print_media(buf, media);
667 return len + sprintf(buf + len, "\n");
670 static int handle_port_media_write(void *driver, char *buf, int nr)
672 int media = switch_parse_media(buf);
675 if (media & SWITCH_MEDIA_AUTO)
676 bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
678 if (media & SWITCH_MEDIA_1000) {
681 bmcr = BMCR_SPEED1000;
683 else if (media & SWITCH_MEDIA_100)
684 bmcr = BMCR_SPEED100;
688 if (media & SWITCH_MEDIA_FD)
689 bmcr |= BMCR_FULLDPLX;
692 bmcr_mask = ~(BMCR_SPEED1000 | BMCR_SPEED100 | BMCR_FULLDPLX | BMCR_ANENABLE | BMCR_ANRESTART);
693 mdio_write(robo.port[nr], MII_BMCR,
694 (mdio_read(robo.port[nr], MII_BMCR) & bmcr_mask) | bmcr);
699 static int handle_enable_vlan_read(void *driver, char *buf, int nr)
701 return sprintf(buf, "%d\n", (((robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0) & (1 << 7)) == (1 << 7)) ? 1 : 0));
704 static int handle_enable_vlan_write(void *driver, char *buf, int nr)
707 int disable = ((buf[0] != '1') ? 1 : 0);
709 val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0);
710 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL0, disable ? 0 :
711 val16 | (1 << 7) /* 802.1Q VLAN */ | (3 << 5) /* mac check and hash */);
713 val16 = robo_read16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1);
714 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL1, disable ? 0 :
715 val16 | (robo.devid == ROBO_DEVICE_ID_5325 ? (1 << 1) :
716 0) | (1 << 2) | (1 << 3)); /* RSV multicast */
718 if (robo.devid != ROBO_DEVICE_ID_5325)
721 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL4, disable ? 0 :
722 (1 << 6) /* drop invalid VID frames */);
723 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_CTRL5, disable ? 0 :
724 (1 << 3) /* drop miss V table frames */);
729 static void handle_reset_old(switch_driver *d, char *buf, int nr)
735 for (j = 0; j <= ((robo.is_5365) ? VLAN_ID_MAX_5365 : VLAN_ID_MAX); j++) {
736 /* write config now */
737 val16 = (j) /* vlan */ | (1 << 12) /* write */ | (1 << 13) /* enable */;
739 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_WRITE_5365, 0);
741 robo_write32(ROBO_VLAN_PAGE, ROBO_VLAN_WRITE, 0);
742 robo_write16(ROBO_VLAN_PAGE, robo.is_5365 ? ROBO_VLAN_TABLE_ACCESS_5365 :
743 ROBO_VLAN_TABLE_ACCESS,
748 static void handle_reset_new(switch_driver *d, char *buf, int nr)
751 __u8 vtbl_entry, vtbl_index, vtbl_access;
753 if ((robo.devid == ROBO_DEVICE_ID_5395) ||
754 (robo.devid == ROBO_DEVICE_ID_53115) ||
755 (robo.devid == ROBO_DEVICE_ID_53125)) {
756 vtbl_access = ROBO_VTBL_ACCESS_5395;
757 vtbl_index = ROBO_VTBL_INDX_5395;
758 vtbl_entry = ROBO_VTBL_ENTRY_5395;
760 vtbl_access = ROBO_VTBL_ACCESS;
761 vtbl_index = ROBO_VTBL_INDX;
762 vtbl_entry = ROBO_VTBL_ENTRY;
765 for (j = 0; j <= VLAN_ID_MAX; j++) {
766 /* write config now */
767 robo_write32(ROBO_ARLIO_PAGE, vtbl_entry, 0);
768 robo_write16(ROBO_ARLIO_PAGE, vtbl_index, j);
769 robo_write16(ROBO_ARLIO_PAGE, vtbl_access, 1 << 7);
773 static int handle_reset(void *driver, char *buf, int nr)
776 switch_driver *d = (switch_driver *) driver;
778 /* disable switching */
781 if (robo.devid != ROBO_DEVICE_ID_5325)
782 handle_reset_new(d, buf, nr);
784 handle_reset_old(d, buf, nr);
786 /* reset ports to a known good state */
787 for (j = 0; j < d->ports; j++) {
788 robo_write16(ROBO_CTRL_PAGE, robo.port[j], 0x0000);
789 robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_PORT0_DEF_TAG + (j << 1), 0);
792 /* enable switching */
796 handle_enable_vlan_write(driver, "1", 0);
801 static int __init robo_init(void)
806 device = strdup("ethX");
807 for (device[3] = '0'; (device[3] <= '3') && notfound; device[3]++) {
808 if (! switch_device_registered (device))
809 notfound = robo_probe(device);
817 static const switch_config cfg[] = {
820 .read = handle_enable_read,
821 .write = handle_enable_write
823 .name = "enable_vlan",
824 .read = handle_enable_vlan_read,
825 .write = handle_enable_vlan_write
829 .write = handle_reset
832 static const switch_config port[] = {
835 .read = handle_port_enable_read,
836 .write = handle_port_enable_write
839 .read = handle_port_media_read,
840 .write = handle_port_media_write
843 static const switch_config vlan[] = {
846 .read = handle_vlan_port_read,
847 .write = handle_vlan_port_write
850 switch_driver driver = {
852 .version = DRIVER_VERSION,
857 .driver_handlers = cfg,
858 .port_handlers = port,
859 .vlan_handlers = vlan,
861 if (robo.devid != ROBO_DEVICE_ID_5325) {
866 return switch_register_driver(&driver);
870 static void __exit robo_exit(void)
872 switch_unregister_driver(DRIVER_NAME);
875 if (robo.gpio_robo_reset >= 0)
876 gpio_free(robo.gpio_robo_reset);
877 if (robo.gpio_lanports_enable >= 0)
878 gpio_free(robo.gpio_lanports_enable);
883 MODULE_AUTHOR("Felix Fietkau <openwrt@nbd.name>");
884 MODULE_LICENSE("GPL");
886 module_init(robo_init);
887 module_exit(robo_exit);