fix wr850g detection (#1936)
[openwrt/openwrt.git] / package / broadcom-diag / src / diag.c
index c53ff2f97ca4d528f9f45119160a59dba24378b2..35737b002f92f8c26c184c40fdf2480264075c09 100644 (file)
@@ -96,6 +96,7 @@ enum {
        WE800G,
        WR850GV1,
        WR850GV2V3,
+       WR850GP,
 
        /* Belkin */
        BELKIN_UNKNOWN,
@@ -112,6 +113,7 @@ enum {
        /* D-Link */
        DIR130,
        DIR330,
+       DWL3150,
 };
 
 static void __init bcm4780_init(void) {
@@ -487,6 +489,18 @@ static struct platform_t __initdata platforms[] = {
                .buttons        = {
                        { .name = "reset",      .gpio = 1 << 5 },
                },
+               .leds           = {
+                       { .name = "power",      .gpio = 1 << 1, .polarity = NORMAL },
+                       { .name = "wlan",       .gpio = 1 << 0, .polarity = REVERSE },
+                       { .name = "wan",        .gpio = 1 << 6, .polarity = INPUT },
+                       { .name = "diag",       .gpio = 1 << 7, .polarity = REVERSE },
+               },
+       },
+       [WR850GP] = {
+               .name           = "Motorola WR850GP",
+               .buttons        = {
+                       { .name = "reset",      .gpio = 1 << 5 },
+               },
                .leds           = {
                        { .name = "power",      .gpio = 1 << 1, .polarity = NORMAL },
                        { .name = "wlan",       .gpio = 1 << 0, .polarity = REVERSE },
@@ -494,6 +508,7 @@ static struct platform_t __initdata platforms[] = {
                        { .name = "diag",       .gpio = 1 << 7, .polarity = REVERSE },
                },
        },
+
        /* Belkin */
        [BELKIN_UNKNOWN] = {
                .name           = "Belkin (unknown)",
@@ -565,20 +580,75 @@ static struct platform_t __initdata platforms[] = {
                        { .name = "blue",       .gpio = 1 << 6},
                },
        },
+       [DWL3150] = {
+               .name   = "D-Link DWL-3150",
+               .buttons        = {
+                       { .name = "reset",      .gpio = 1 << 7},
+               },
+               .leds     = {
+                       { .name = "diag",       .gpio = 1 << 2},
+                       { .name = "status",     .gpio = 1 << 1},
+               },
+       },
 };
 
 static struct platform_t __init *platform_detect(void)
 {
        char *boardnum, *boardtype, *buf;
 
-       boardnum = getvar("boardnum");
-       boardtype = getvar("boardtype");
-
        if (strcmp(getvar("nvram_type"), "cfe") == 0)
                return &platforms[WGT634U];
-       
-       if (strncmp(getvar("model_no"), "WL700",5) == 0)
-               return &platforms[WL700GE];
+
+       /* Look for a model identifier */
+
+       /* Based on "model_name" */
+       if (buf = nvram_get("model_name")) {
+               if (!strcmp(buf, "DIR-130"))
+                       return &platforms[DIR130];
+               if (!strcmp(buf, "DIR-330"))
+                       return &platforms[DIR330];
+       }
+
+       /* Based on "model_no" */
+       if (buf = nvram_get("model_no")) {
+               if (!strncmp(buf,"WL700", 5)) /* WL700* */
+                       return &platforms[WL700GE];
+       }
+
+       /* Based on "ModelId" */
+       if (buf = nvram_get("ModelId")) {
+               if (!strcmp(buf, "WR850GP"))
+                       return &platforms[WR850GP];
+               if (!strcmp(buf,"WX-5565"))
+                       return &platforms[TM2300];
+               if (!strncmp(buf,"WE800G", 6)) /* WE800G* */
+                       return &platforms[WE800G];
+       }
+
+       /* Buffalo */
+       if ((buf = (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
+               /* Buffalo hardware, check id for specific hardware matches */
+               if (!strcmp(buf, "29bb0332"))
+                       return &platforms[WBR2_G54];
+               if (!strcmp(buf, "29129"))
+                       return &platforms[WLA2_G54L];
+               if (!strcmp(buf, "30189"))
+                       return &platforms[WHR_HP_G54];
+               if (!strcmp(buf, "30182"))
+                       return &platforms[WHR_G54S];
+               if (!strcmp(buf, "290441dd"))
+                       return &platforms[WHR2_A54G54];
+               if (!strcmp(buf, "31120"))
+                       return &platforms[WZR_G300N];
+               if (!strcmp(buf, "30083"))
+                       return &platforms[WZR_RS_G54];
+               if (!strcmp(buf, "30103"))
+                       return &platforms[WZR_RS_G54HP];
+       }
+
+       /* no easy model number, attempt to guess */
+       boardnum = getvar("boardnum");
+       boardtype = getvar("boardtype");
 
        if (strncmp(getvar("pmon_ver"), "CFE", 3) == 0) {
                /* CFE based - newer hardware */
@@ -608,24 +678,10 @@ static struct platform_t __init *platform_detect(void)
                if (!strcmp(boardnum, "10496"))
                        return &platforms[USR5461];
 
-               /* D-Link */
-               if (!strcmp(getvar("model_name"), "DIR-130"))
-                       return &platforms[DIR130];
-               if (!strcmp(getvar("model_name"), "DIR-330"))
-                       return &platforms[DIR330];
-
        } else { /* PMON based - old stuff */
-
-               /* Dell TrueMobile 2300 */
-               if (!strcmp(getvar("ModelId"),"WX-5565"))
-                       return &platforms[TM2300];
-       
                if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
                        (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
-                       if (!strncmp(getvar("ModelId"),"WE800G", 6))
-                               return &platforms[WE800G];
-                       else
-                               return &platforms[WR850GV1];
+                       return &platforms[WR850GV1];
                }
                if (!strncmp(boardtype, "bcm94710dev", 11)) {
                        if (!strcmp(boardnum, "42"))
@@ -650,26 +706,6 @@ static struct platform_t __init *platform_detect(void)
                        return &platforms[ASUS_4702];
        }
 
-       if ((buf = (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
-               /* Buffalo hardware, check id for specific hardware matches */
-               if (!strcmp(buf, "29bb0332"))
-                       return &platforms[WBR2_G54];
-               if (!strcmp(buf, "29129"))
-                       return &platforms[WLA2_G54L];
-               if (!strcmp(buf, "30189"))
-                       return &platforms[WHR_HP_G54];
-               if (!strcmp(buf, "30182"))
-                       return &platforms[WHR_G54S];
-               if (!strcmp(buf, "290441dd"))
-                       return &platforms[WHR2_A54G54];
-               if (!strcmp(buf, "31120"))
-                       return &platforms[WZR_G300N];
-               if (!strcmp(buf, "30083"))
-                       return &platforms[WZR_RS_G54];
-               if (!strcmp(buf, "30103"))
-                       return &platforms[WZR_RS_G54HP];
-       }
-
        if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
                if (!strncmp(boardtype, "bcm94710ap", 10))
                        return &platforms[BUFFALO_UNKNOWN_4710];
@@ -677,7 +713,8 @@ static struct platform_t __init *platform_detect(void)
                        return &platforms[BUFFALO_UNKNOWN];
        }
 
-       if (!strcmp(getvar("CFEver"), "MotoWRv203") ||
+       if (!strncmp(getvar("CFEver"), "MotoWRv2", 8) ||
+               !strncmp(getvar("CFEver"), "MotoWRv3", 8) ||
                !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
 
                return &platforms[WR850GV2V3];
@@ -690,6 +727,9 @@ static struct platform_t __init *platform_detect(void)
        if (!strncmp(boardnum, "04FN52", 6)) /* SimpleTech SimpleShare */
                return &platforms[STI_NAS];
 
+       if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
+               return &platforms[DWL3150];
+
        /* not found */
        return NULL;
 }
@@ -854,6 +894,7 @@ static void register_leds(struct led_t *l)
 {
        struct proc_dir_entry *p;
        u32 mask = 0;
+       u32 oe_mask = 0;
        u32 val = 0;
 
        leds = proc_mkdir("led", diag);
@@ -868,10 +909,13 @@ static void register_leds(struct led_t *l)
                        l->state = 0;
                        set_led_extif(l);
                } else {
+                       if (l->polarity != INPUT) oe_mask != l->gpio;
                        mask |= l->gpio;
                        val |= (l->polarity == NORMAL)?0:l->gpio;
                }
 
+               if (l->polarity == INPUT) continue;
+
                if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
                        l->proc.type = PROC_LED;
                        l->proc.ptr = l;
@@ -880,7 +924,7 @@ static void register_leds(struct led_t *l)
                }
        }
 
-       gpio_outen(mask, mask);
+       gpio_outen(mask, oe_mask);
        gpio_control(mask, 0);
        gpio_out(mask, val);
 }