fritzbox leds detection (thanks Axel Gembe)
[openwrt/openwrt.git] / target / linux / ar7 / files / arch / mips / ar7 / platform.c
index cae35bc2290655b9ef97944baef7698bcd53e104..c1cd5f97b90c5e5e929368448c05e9fd57494ef8 100644 (file)
@@ -1,18 +1,16 @@
 /*
- * $Id$
- * 
  * Copyright (C) 2006, 2007 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
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/delay.h>
+#include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/mtd/physmap.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
 #include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/version.h>
+#include <linux/vlynq.h>
+#include <linux/leds.h>
+#include <linux/string.h>
+
 #include <asm/addrspace.h>
-#include <asm/io.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;
@@ -58,10 +61,9 @@ static int vlynq_on(struct vlynq_device *dev)
        if ((result = ar7_gpio_enable(pdata->gpio_bit)))
                goto out_enabled;
 
-       if ((result = gpio_direction_output(pdata->gpio_bit)))
+       if ((result = gpio_direction_output(pdata->gpio_bit, 0)))
                goto out_gpio_enabled;
 
-       gpio_set_value(pdata->gpio_bit, 0);
        mdelay(50);
 
        gpio_set_value(pdata->gpio_bit, 1);
@@ -91,21 +93,21 @@ static struct resource physmap_flash_resource = {
        .flags = IORESOURCE_MEM,
        .start = 0x10000000,
        .end = 0x107fffff,
-};     
+};
 
 static struct resource cpmac_low_res[] = {
        {
                .name = "regs",
                .flags = IORESOURCE_MEM,
                .start = AR7_REGS_MAC0,
-               .end = AR7_REGS_MAC0 + 0x7FF,
+               .end = AR7_REGS_MAC0 + 0x7ff,
        },
        {
                .name = "irq",
                .flags = IORESOURCE_IRQ,
                .start = 27,
                .end = 27,
-        },
+       },
 };
 
 static struct resource cpmac_high_res[] = {
@@ -113,14 +115,14 @@ static struct resource cpmac_high_res[] = {
                .name = "regs",
                .flags = IORESOURCE_MEM,
                .start = AR7_REGS_MAC1,
-               .end = AR7_REGS_MAC1 + 0x7FF,
+               .end = AR7_REGS_MAC1 + 0x7ff,
        },
        {
                .name = "irq",
                .flags = IORESOURCE_IRQ,
                .start = 41,
                .end = 41,
-        },
+       },
 };
 
 static struct resource vlynq_low_res[] = {
@@ -135,7 +137,7 @@ static struct resource vlynq_low_res[] = {
                .flags = IORESOURCE_IRQ,
                .start = 29,
                .end = 29,
-        },
+       },
        {
                .name = "mem",
                .flags = IORESOURCE_MEM,
@@ -155,14 +157,14 @@ static struct resource vlynq_high_res[] = {
                .name = "regs",
                .flags = IORESOURCE_MEM,
                .start = AR7_REGS_VLYNQ1,
-               .end = AR7_REGS_VLYNQ1 + 0xFF,
+               .end = AR7_REGS_VLYNQ1 + 0xff,
        },
        {
                .name = "irq",
                .flags = IORESOURCE_IRQ,
                .start = 33,
                .end = 33,
-        },
+       },
        {
                .name = "mem",
                .flags = IORESOURCE_MEM,
@@ -177,6 +179,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,
 };
@@ -215,10 +238,15 @@ static struct platform_device physmap_flash = {
        .num_resources = 1,
 };
 
+static u64 cpmac_dma_mask = DMA_32BIT_MASK;
 static struct platform_device cpmac_low = {
        .id = 0,
        .name = "cpmac",
-       .dev.platform_data = &cpmac_low_data,
+       .dev = {
+               .dma_mask = &cpmac_dma_mask,
+               .coherent_dma_mask = DMA_32BIT_MASK,
+               .platform_data = &cpmac_low_data,
+       },
        .resource = cpmac_low_res,
        .num_resources = ARRAY_SIZE(cpmac_low_res),
 };
@@ -226,7 +254,11 @@ static struct platform_device cpmac_low = {
 static struct platform_device cpmac_high = {
        .id = 1,
        .name = "cpmac",
-       .dev.platform_data = &cpmac_high_data,
+       .dev = {
+               .dma_mask = &cpmac_dma_mask,
+               .coherent_dma_mask = DMA_32BIT_MASK,
+               .platform_data = &cpmac_high_data,
+       },
        .resource = cpmac_high_res,
        .num_resources = ARRAY_SIZE(cpmac_high_res),
 };
@@ -253,8 +285,7 @@ static struct platform_device vlynq_high = {
  */
 #if !defined(CONFIG_SERIAL_8250)
 
-static struct plat_serial8250_port uart0_data =
-{
+static struct plat_serial8250_port uart0_data = {
        .mapbase = AR7_REGS_UART0,
        .irq = AR7_IRQ_UART0,
        .regshift = 2,
@@ -262,8 +293,7 @@ static struct plat_serial8250_port uart0_data =
        .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
 };
 
-static struct plat_serial8250_port uart1_data =
-{
+static struct plat_serial8250_port uart1_data = {
        .mapbase = UR8_REGS_UART1,
        .irq = AR7_IRQ_UART1,
        .regshift = 2,
@@ -272,13 +302,13 @@ static struct plat_serial8250_port uart1_data =
 };
 
 static struct plat_serial8250_port uart_data[] = {
-    uart0_data,
-    uart1_data,
+       uart0_data,
+       uart1_data,
        { .flags = 0 }
 };
 
 static struct plat_serial8250_port uart_data_single[] = {
-    uart0_data,
+       uart0_data,
        { .flags = 0 }
 };
 
@@ -289,6 +319,43 @@ static struct platform_device uart = {
 };
 #endif
 
+static struct gpio_led default_leds[] = {
+       { .name = "status", .gpio = 8, .active_low = 1, },
+};
+
+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, },
+       { .name = "4", .gpio = 12, .active_low = 1, },
+       { .name = "5", .gpio = 9, .active_low = 1, },
+};
+
+static struct gpio_led fb_fon_leds[] = {
+       { .name = "1", .gpio = 8, },
+       { .name = "2", .gpio = 3, .active_low = 1, },
+       { .name = "3", .gpio = 5, },
+       { .name = "4", .gpio = 4, .active_low = 1, },
+       { .name = "5", .gpio = 11, .active_low = 1, },
+};
+
+static struct gpio_led_platform_data ar7_led_data;
+
+static struct platform_device ar7_gpio_leds = {
+       .name = "leds-gpio",
+       .id = -1,
+       .dev = {
+               .platform_data = &ar7_led_data,
+       }
+};
+
+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)
 {
        switch (h) {
@@ -323,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;
@@ -346,36 +437,35 @@ static int __init ar7_register_devices(void)
                return res;
 
 
-    // Only TNETD73xx have a second serial port
-    if (ar7_has_second_uart()) {
-       uart_port[1].type = PORT_AR7;
-       uart_port[1].line = 1;
-       uart_port[1].irq = AR7_IRQ_UART1;
-       uart_port[1].uartclk = ar7_bus_freq() / 2;
-       uart_port[1].iotype = UPIO_MEM;
-       uart_port[1].mapbase = UR8_REGS_UART1;
-       uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
-       uart_port[1].regshift = 2;
-       res = early_serial_setup(&uart_port[1]);
-       if (res)
-               return res;
-    }
-    
-#else // !CONFIG_SERIAL_8250
+       /* Only TNETD73xx have a second serial port */
+       if (ar7_has_second_uart()) {
+               uart_port[1].type = PORT_AR7;
+               uart_port[1].line = 1;
+               uart_port[1].irq = AR7_IRQ_UART1;
+               uart_port[1].uartclk = ar7_bus_freq() / 2;
+               uart_port[1].iotype = UPIO_MEM;
+               uart_port[1].mapbase = UR8_REGS_UART1;
+               uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
+               uart_port[1].regshift = 2;
+               res = early_serial_setup(&uart_port[1]);
+               if (res)
+                       return res;
+       }
+
+#else /* !CONFIG_SERIAL_8250 */
 
        uart_data[0].uartclk = ar7_bus_freq() / 2;
        uart_data[1].uartclk = uart_data[0].uartclk;
 
-    // Only TNETD73xx have a second serial port
-    if (ar7_has_second_uart()) {
-        uart.dev.platform_data = uart_data;
-    }
+       /* Only TNETD73xx have a second serial port */
+       if (ar7_has_second_uart())
+               uart.dev.platform_data = uart_data;
 
        res = platform_device_register(&uart);
        if (res)
                return res;
-        
-#endif // CONFIG_SERIAL_8250
+
+#endif /* CONFIG_SERIAL_8250 */
 
        res = platform_device_register(&physmap_flash);
        if (res)
@@ -404,6 +494,15 @@ static int __init ar7_register_devices(void)
 
        cpmac_get_mac(0, cpmac_low_data.dev_addr);
        res = platform_device_register(&cpmac_low);
+       if (res)
+               return res;
+
+       detect_leds();
+       res = platform_device_register(&ar7_gpio_leds);
+       if (res)
+               return res;
+
+       res = platform_device_register(&ar7_udc);
 
        return res;
 }