fritzbox leds detection (thanks Axel Gembe)
[openwrt.git] / target / linux / ar7 / files / arch / mips / ar7 / platform.c
index f3a9372..c1cd5f9 100644 (file)
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/version.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
+#include <linux/vlynq.h>
 #include <linux/leds.h>
-#endif
+#include <linux/string.h>
 
 #include <asm/addrspace.h>
 #include <asm/ar7/ar7.h>
 #include <asm/ar7/gpio.h>
 #include <asm/ar7/prom.h>
-#include <asm/ar7/vlynq.h>
 
 struct plat_vlynq_data {
        struct plat_vlynq_ops ops;
@@ -320,12 +319,11 @@ static struct platform_device uart = {
 };
 #endif
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
 static struct gpio_led default_leds[] = {
        { .name = "status", .gpio = 8, .active_low = 1, },
 };
 
-static struct gpio_led fb_leds[] = {
+static struct gpio_led fb_sl_leds[] = {
        { .name = "1", .gpio = 7, },
        { .name = "2", .gpio = 13, .active_low = 1, },
        { .name = "3", .gpio = 10, .active_low = 1, },
@@ -350,7 +348,6 @@ static struct platform_device ar7_gpio_leds = {
                .platform_data = &ar7_led_data,
        }
 };
-#endif
 
 static struct platform_device ar7_udc = {
        .id = -1,
@@ -393,6 +390,30 @@ static void cpmac_get_mac(int instance, unsigned char *dev_addr)
                        char2hex(mac[i * 3 + 1]);
 }
 
+static void __init detect_leds(void)
+{
+       char *prId;
+
+       /* Default LEDs */
+       ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
+       ar7_led_data.leds = default_leds;
+
+       /* FIXME: the whole thing is unreliable */
+       prId = prom_getenv("ProductID");
+       
+       /* If we can't get the product id from PROM, use the default LEDs */
+       if (!prId)
+               return;
+
+       if (strstr(prId, "Fritz_Box_FON")) {
+               ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
+               ar7_led_data.leds = fb_fon_leds;
+       } else if (strstr(prId, "Fritz_Box_")) {
+               ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
+               ar7_led_data.leds = fb_sl_leds;
+       }
+}
+
 static int __init ar7_register_devices(void)
 {
        int res;
@@ -476,12 +497,8 @@ static int __init ar7_register_devices(void)
        if (res)
                return res;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-#warning FIXME: add model detection
-       ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
-       ar7_led_data.leds = default_leds;
+       detect_leds();
        res = platform_device_register(&ar7_gpio_leds);
-#endif
        if (res)
                return res;
 
This page took 0.030789 seconds and 4 git commands to generate.