broadcom-diag: support for the WNDR3700v3
[openwrt/openwrt.git] / package / broadcom-diag / src / diag.c
index 823b9b7d08cde1ce88275269b97d781ea44a7328..ccbaee2d264c501f8b7844fb6743a126156ecdf4 100644 (file)
@@ -66,6 +66,7 @@ enum {
        WRT610NV2,
        E1000V1,
        E3000V1,
+       E3200V1,
 
        /* ASUS */
        WLHDD,
@@ -121,6 +122,8 @@ enum {
        WGT634U,
        WNR834BV1,
        WNR834BV2,
+       WNDR3400V1,
+       WNDR3700V3,
 
        /* Trendware */
        TEW411BRPP,
@@ -456,6 +459,18 @@ static struct platform_t __initdata platforms[] = {
                        { .name = "wlan",       .gpio = 1 << 1, .polarity = NORMAL },   // Wireless LED
                },
        },
+       [E3200V1] = {
+               .name           = "Linksys E3200 V1",
+               .buttons        = {
+                       /* { .name = "switch",  .gpio = 1 << 4 },*/     /* nvram get gpio4=robo_reset */
+                       { .name = "reset",      .gpio = 1 << 5 },       /* nvram get reset_gpio=5 */
+                       { .name = "wps",        .gpio = 1 << 8 },       /* nvram get gpio8=wps_button */
+                       /* { .name = "wombo",   .gpio = 1 << 23 },*/    /* nvram get gpio23=wombo_reset - wireless on motherboard */
+               },
+               .leds   = {
+                       { .name = "power",      .gpio = 1 << 3, .polarity = REVERSE },  /* Power LED */
+               },
+       },
        /* Asus */
        [WLHDD] = {
                .name           = "ASUS WL-HDD",
@@ -897,6 +912,44 @@ static struct platform_t __initdata platforms[] = {
                        { .name = "connected",  .gpio = 1 << 7, .polarity = NORMAL },
                },
        },
+       [WNDR3400V1] = {
+               .name           = "Netgear WNDR3400 V1",
+               .buttons        = {
+                       /* nvram get gpio5=robo_reset */
+                       { .name = "reset",      .gpio = 1 << 4 },
+                       { .name = "wps",        .gpio = 1 << 6 },
+                       { .name = "wlan",       .gpio = 1 << 8 },
+               },
+               .leds           = {
+                       { .name = "wlan",       .gpio = 0 << 0, .polarity = NORMAL },
+                       { .name = "connected",  .gpio = 1 << 0, .polarity = NORMAL },
+                       { .name = "power",      .gpio = 1 << 3, .polarity = NORMAL },
+                       { .name = "diag",       .gpio = 1 << 7, .polarity = NORMAL },
+                       { .name = "usb",        .gpio = 1 << 2, .polarity = REVERSE },
+               },
+       },
+       [WNDR3700V3] = {
+               .name           = "Netgear WNDR3700 V3",
+               .buttons        = {
+                       /* { .name = "usb",     .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
+                       { .name = "wlan",       .gpio = 1 << 2 },
+                       { .name = "reset",      .gpio = 1 << 3 },
+                       { .name = "wps",        .gpio = 1 << 4 },
+                       /* { .name = "switch",  .gpio = 1 << 5 },*/     /* nvram get gpio5=robo_reset */
+               },
+               .leds           = {
+                       { .name = "power",      .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       { .name = "diag",       .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
+                        * { .name = "wan",     .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                        */
+                       { .name = "wlan2g",     .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       { .name = "wlan5g",     .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       { .name = "usb",        .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       { .name = "wps",        .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+                       { .name = "wlan",       .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
+               },
+       },
        /* Trendware */
        [TEW411BRPP] = {
                .name           = "Trendware TEW411BRP+",
@@ -1252,6 +1305,8 @@ static struct platform_t __init *platform_detect(void)
                return &platforms[E1000V1];
        case BCM47XX_BOARD_LINKSYS_E3000V1:
                return &platforms[E3000V1];
+       case BCM47XX_BOARD_LINKSYS_E3200V1:
+               return &platforms[E3200V1];
        case BCM47XX_BOARD_LINKSYS_WRT150NV1:
                return &platforms[WRT150NV1];
        case BCM47XX_BOARD_LINKSYS_WRT150NV11:
@@ -1274,6 +1329,10 @@ static struct platform_t __init *platform_detect(void)
                return &platforms[WR850GP];
        case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
                return &platforms[WR850GV2V3];
+       case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
+               return &platforms[WNDR3400V1];
+       case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
+               return &platforms[WNDR3700V3];
        case BCM47XX_BOARD_UNKNOWN:
        case BCM47XX_BOARD_NON:
                printk(MODULE_NAME ": unknown board found, try legacy detect\n");
@@ -1442,13 +1501,23 @@ static void register_leds(struct led_t *l)
                if (l->gpio & gpiomask)
                        continue;
 
-               if (l->gpio & GPIO_TYPE_EXTIF) {
+               switch (l->gpio & GPIO_TYPE_MASK) {
+               case GPIO_TYPE_EXTIF:
                        l->state = 0;
                        set_led_extif(l);
-               } else {
+                       break;
+               case GPIO_TYPE_SHIFT:
+                       mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
+                       oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
+                       l->state = (l->polarity != NORMAL);
+                       set_led_shift(l);
+                       break;
+               case GPIO_TYPE_NORMAL:
+               default:
                        if (l->polarity != INPUT) oe_mask |= l->gpio;
                        mask |= l->gpio;
                        val |= (l->polarity == NORMAL)?0:l->gpio;
+                       break;
                }
 
                if (l->polarity == INPUT) continue;
@@ -1484,20 +1553,68 @@ static void set_led_extif(struct led_t *led)
                *addr;
 }
 
+/*
+ * This should be extended to allow the platform to specify the pins and width
+ * of the shift register. They're hardcoded for now because only the WNDR3700v3
+ * uses it.
+ */
+static void shiftreg_output(unsigned int val)
+{
+       unsigned int mask;
+
+       bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
+       bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
+
+       /* shift 8 times */
+       for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
+       {
+               bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
+               bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
+               bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
+       }
+}
+
+static void set_led_shift(struct led_t *led)
+{
+       static u32      shiftreg = 0;
+       u32                     old = shiftreg;
+       u32                     pin = (led->gpio & ~GPIO_TYPE_MASK);
+
+       if (led->state) {
+               shiftreg |= pin;
+       } else {
+               shiftreg &= ~pin;
+       }
+
+       /* Clock the bits out. */
+       if (shiftreg != old) {
+               shiftreg_output(shiftreg);
+       }
+}
+
+
 static void led_flash(unsigned long dummy) {
        struct led_t *l;
        u32 mask = 0;
        u8 extif_blink = 0;
 
        for (l = platform.leds; l->name; l++) {
-               if (l->flash) {
-                       if (l->gpio & GPIO_TYPE_EXTIF) {
-                               extif_blink = 1;
-                               l->state = !l->state;
-                               set_led_extif(l);
-                       } else {
-                               mask |= l->gpio;
-                       }
+               if (!l->flash) continue;
+               switch (l->gpio & GPIO_TYPE_MASK) {
+               case GPIO_TYPE_EXTIF:
+                       extif_blink = 1;
+                       l->state = !l->state;
+                       set_led_extif(l);
+                       break;
+               case GPIO_TYPE_SHIFT:
+                       extif_blink = 1;
+                       l->state = !l->state;
+                       set_led_shift(l);
+                       break;
+               case GPIO_TYPE_NORMAL:
+               default:
+                       mask |= l->gpio;
+                       break;
                }
        }
 
@@ -1528,16 +1645,14 @@ static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t
                switch (handler->type) {
                        case PROC_LED: {
                                struct led_t * led = (struct led_t *) handler->ptr;
+                               u8 p = (led->polarity == NORMAL ? 0 : 1);
                                if (led->flash) {
                                        len = sprintf(page, "f\n");
+                               } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
+                                       len = sprintf(page, "%d\n", ((led->state ^ p) ? 1 : 0));
                                } else {
-                                       if (led->gpio & GPIO_TYPE_EXTIF) {
-                                               len = sprintf(page, "%d\n", led->state);
-                                       } else {
-                                               u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
-                                               u8 p = (led->polarity == NORMAL ? 0 : 1);
-                                               len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
-                                       }
+                                       u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
+                                       len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
                                }
                                break;
                        }
@@ -1594,9 +1709,12 @@ static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count,
                                        led_flash(0);
                                } else {
                                        led->flash = 0;
-                                       if (led->gpio & GPIO_TYPE_EXTIF) {
+                                       if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
                                                led->state = p ^ ((page[0] == '1') ? 1 : 0);
                                                set_led_extif(led);
+                                       } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
+                                               led->state = p ^ ((page[0] == '1') ? 1 : 0);
+                                               set_led_shift(led);
                                        } else {
                                                bcm47xx_gpio_outen(led->gpio, led->gpio);
                                                bcm47xx_gpio_control(led->gpio, 0);