add proper email addresses to the comment headers
[openwrt.git] / target / linux / ar7 / files / arch / mips / ar7 / platform.c
index 1671be1..81d4290 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2006, 2007 OpenWrt.org
+ * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #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;
@@ -180,6 +180,27 @@ static struct resource vlynq_high_res[] = {
        },
 };
 
+static struct resource usb_res[] = {
+       {
+               .name = "regs",
+               .flags = IORESOURCE_MEM,
+               .start = AR7_REGS_USB,
+               .end = AR7_REGS_USB + 0xff,
+       },
+       {
+               .name = "irq",
+               .flags = IORESOURCE_IRQ,
+               .start = 32,
+               .end = 32,
+       },
+       {
+               .name = "mem",
+               .flags = IORESOURCE_MEM,
+               .start = 0x03400000,
+               .end = 0x034001fff,
+       },
+};
+
 static struct physmap_flash_data physmap_flash_data = {
        .width = 2,
 };
@@ -299,12 +320,25 @@ 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 dsl502t_leds[] = {
+       { .name = "status", .gpio = 9, .active_low = 1, },
+       { .name = "ethernet", .gpio = 7, .active_low = 1, },
+       { .name = "usb", .gpio = 12, .active_low = 1, },
+};
+
+static struct gpio_led dg834g_leds[] = {
+       { .name = "ppp", .gpio = 6, .active_low = 1, },
+       { .name = "status", .gpio = 7, .active_low = 1, },
+       { .name = "adsl", .gpio = 8, .active_low = 1, },
+       { .name = "wifi", .gpio = 12, .active_low = 1, },
+       { .name = "power", .gpio = 14, .active_low = 1, .default_trigger = "default-on", },
+};
+
+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, },
@@ -329,7 +363,13 @@ static struct platform_device ar7_gpio_leds = {
                .platform_data = &ar7_led_data,
        }
 };
-#endif
+
+static struct platform_device ar7_udc = {
+       .id = -1,
+       .name = "ar7_udc",
+       .resource = usb_res,
+       .num_resources = ARRAY_SIZE(usb_res),
+};
 
 static inline unsigned char char2hex(char h)
 {
@@ -365,6 +405,37 @@ static void cpmac_get_mac(int instance, unsigned char *dev_addr)
                        char2hex(mac[i * 3 + 1]);
 }
 
+static void __init detect_leds(void)
+{
+       char *prId, *usb_prod;
+
+       /* 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");
+       usb_prod = prom_getenv("usb_prod");
+       
+       /* 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;
+       } else if ((!strcmp(prId, "AR7RD") || !strcmp(prId, "AR7DB")) && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
+               ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
+               ar7_led_data.leds = dsl502t_leds;
+       } else if (strstr(prId, "DG834")) {
+               ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
+               ar7_led_data.leds = dg834g_leds;
+       }
+}
+
 static int __init ar7_register_devices(void)
 {
        int res;
@@ -448,12 +519,13 @@ 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;
+
+       res = platform_device_register(&ar7_udc);
+
        return res;
 }
 
This page took 0.03241 seconds and 4 git commands to generate.