[ar71xx] enable TL-WR941ND in kernel config
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / platform.c
index e41fcd646b0830ba02009998ead622a714d44f81..6a29fc46a00429ed776b5e90bc17ba01ac8d0122 100644 (file)
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
 #include <linux/platform_device.h>
 #include <linux/serial_8250.h>
+#include <linux/ath9k_platform.h>
 
-#include <asm/mips_machine.h>
 #include <asm/mach-ar71xx/ar71xx.h>
 #include <asm/mach-ar71xx/platform.h>
 
@@ -27,7 +28,7 @@ static u8 ar71xx_mac_base[ETH_ALEN] __initdata;
 /*
  * OHCI (USB full speed host controller)
  */
-static struct resource ar71xx_usb_ohci_resources[] = {
+static struct resource ar71xx_ohci_resources[] = {
        [0] = {
                .start  = AR71XX_OHCI_BASE,
                .end    = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1,
@@ -41,11 +42,11 @@ static struct resource ar71xx_usb_ohci_resources[] = {
 };
 
 static u64 ar71xx_ohci_dmamask = DMA_BIT_MASK(32);
-static struct platform_device ar71xx_usb_ohci_device = {
+static struct platform_device ar71xx_ohci_device = {
        .name           = "ar71xx-ohci",
        .id             = -1,
-       .resource       = ar71xx_usb_ohci_resources,
-       .num_resources  = ARRAY_SIZE(ar71xx_usb_ohci_resources),
+       .resource       = ar71xx_ohci_resources,
+       .num_resources  = ARRAY_SIZE(ar71xx_ohci_resources),
        .dev = {
                .dma_mask               = &ar71xx_ohci_dmamask,
                .coherent_dma_mask      = DMA_BIT_MASK(32),
@@ -55,7 +56,7 @@ static struct platform_device ar71xx_usb_ohci_device = {
 /*
  * EHCI (USB full speed host controller)
  */
-static struct resource ar71xx_usb_ehci_resources[] = {
+static struct resource ar71xx_ehci_resources[] = {
        [0] = {
                .start  = AR71XX_EHCI_BASE,
                .end    = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1,
@@ -68,15 +69,19 @@ static struct resource ar71xx_usb_ehci_resources[] = {
        },
 };
 
+
 static u64 ar71xx_ehci_dmamask = DMA_BIT_MASK(32);
-static struct platform_device ar71xx_usb_ehci_device = {
+static struct ar71xx_ehci_platform_data ar71xx_ehci_data;
+
+static struct platform_device ar71xx_ehci_device = {
        .name           = "ar71xx-ehci",
        .id             = -1,
-       .resource       = ar71xx_usb_ehci_resources,
-       .num_resources  = ARRAY_SIZE(ar71xx_usb_ehci_resources),
+       .resource       = ar71xx_ehci_resources,
+       .num_resources  = ARRAY_SIZE(ar71xx_ehci_resources),
        .dev = {
                .dma_mask               = &ar71xx_ehci_dmamask,
                .coherent_dma_mask      = DMA_BIT_MASK(32),
+               .platform_data          = &ar71xx_ehci_data,
        },
 };
 
@@ -84,7 +89,7 @@ static struct platform_device ar71xx_usb_ehci_device = {
        (RESET_MODULE_USB_HOST | RESET_MODULE_USB_PHY \
        | RESET_MODULE_USB_OHCI_DLL)
 
-void __init ar71xx_add_device_usb(void)
+static void ar71xx_usb_setup(void)
 {
        ar71xx_device_stop(AR71XX_USB_RESET_MASK);
        mdelay(1000);
@@ -97,14 +102,44 @@ void __init ar71xx_add_device_usb(void)
        ar71xx_usb_ctrl_wr(USB_CTRL_REG_FLADJ, 0x20c00);
 
        mdelay(900);
+}
+
+static void ar91xx_usb_setup(void)
+{
+       ar71xx_device_stop(RESET_MODULE_USBSUS_OVERRIDE);
+       mdelay(10);
+
+       ar71xx_device_start(RESET_MODULE_USB_HOST);
+       mdelay(10);
+
+       ar71xx_device_start(RESET_MODULE_USB_PHY);
+       mdelay(10);
+}
+
+void __init ar71xx_add_device_usb(void)
+{
+       switch (ar71xx_soc) {
+       case AR71XX_SOC_AR7130:
+       case AR71XX_SOC_AR7141:
+       case AR71XX_SOC_AR7161:
+               ar71xx_usb_setup();
+               platform_device_register(&ar71xx_ohci_device);
+               platform_device_register(&ar71xx_ehci_device);
+               break;
 
-       platform_device_register(&ar71xx_usb_ohci_device);
-       platform_device_register(&ar71xx_usb_ehci_device);
+       case AR71XX_SOC_AR9130:
+       case AR71XX_SOC_AR9132:
+               ar91xx_usb_setup();
+               ar71xx_ehci_data.is_ar91xx = 1;
+               platform_device_register(&ar71xx_ehci_device);
+               break;
+
+       default:
+               BUG();
+       }
 }
 
-#ifdef CONFIG_AR71XX_EARLY_SERIAL
-static void __init ar71xx_add_device_uart(void) {};
-#else
+#ifndef CONFIG_AR71XX_EARLY_SERIAL
 static struct resource ar71xx_uart_resources[] = {
        {
                .start  = AR71XX_UART_BASE,
@@ -136,7 +171,7 @@ static struct platform_device ar71xx_uart_device = {
        },
 };
 
-static void __init ar71xx_add_device_uart(void)
+void __init ar71xx_add_device_uart(void)
 {
        ar71xx_uart_data[0].uartclk = ar71xx_ahb_freq;
        platform_device_register(&ar71xx_uart_device);
@@ -422,8 +457,15 @@ void __init ar71xx_add_device_eth(unsigned int id)
                break;
        }
 
-       memcpy(pdata->mac_addr, ar71xx_mac_base, ETH_ALEN);
-       pdata->mac_addr[5] += ar71xx_eth_instance;
+       if (is_valid_ether_addr(ar71xx_mac_base)) {
+               memcpy(pdata->mac_addr, ar71xx_mac_base, ETH_ALEN);
+               pdata->mac_addr[5] += ar71xx_eth_instance;
+       } else {
+               random_ether_addr(pdata->mac_addr);
+               printk(KERN_DEBUG
+                       "ar71xx: using random MAC address for eth%d\n",
+                       ar71xx_eth_instance);
+       }
 
        platform_device_register(pdev);
        ar71xx_eth_instance++;
@@ -448,8 +490,6 @@ void __init ar71xx_add_device_spi(struct ar71xx_spi_platform_data *pdata,
                                struct spi_board_info const *info,
                                unsigned n)
 {
-       ar71xx_gpio_function_enable(GPIO_FUNC_SPI_EN);
-
        spi_register_board_info(info, n);
        ar71xx_spi_device.dev.platform_data = pdata;
        platform_device_register(&ar71xx_spi_device);
@@ -475,7 +515,7 @@ void __init ar71xx_add_device_leds_gpio(int id, unsigned num_leds,
 
        memset(&pdata, 0, sizeof(pdata));
        pdata.num_leds = num_leds;
-       pdata.leds = leds;
+       pdata.leds = p;
 
        err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
        if (err)
@@ -555,6 +595,10 @@ void __init ar71xx_parse_mac_addr(char *mac_str)
        t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
                        &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
 
+       if (t != ETH_ALEN)
+               t = sscanf(mac_str, "%02hhx.%02hhx.%02hhx.%02hhx.%02hhx.%02hhx",
+                       &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
+
        if (t == ETH_ALEN)
                ar71xx_set_mac_base(tmp);
        else
@@ -562,15 +606,42 @@ void __init ar71xx_parse_mac_addr(char *mac_str)
                                "\"%s\"\n", mac_str);
 }
 
-static int __init ar71xx_machine_setup(void)
+static struct resource ar91xx_wmac_resources[] = {
+       {
+               .start  = AR91XX_WMAC_BASE,
+               .end    = AR91XX_WMAC_BASE + AR91XX_WMAC_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = AR71XX_CPU_IRQ_WMAC,
+               .end    = AR71XX_CPU_IRQ_WMAC,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct ath9k_platform_data ar91xx_wmac_data;
+
+static struct platform_device ar91xx_wmac_device = {
+       .name           = "ath9k",
+       .id             = -1,
+       .resource       = ar91xx_wmac_resources,
+       .num_resources  = ARRAY_SIZE(ar91xx_wmac_resources),
+       .dev = {
+               .platform_data = &ar91xx_wmac_data,
+       },
+};
+
+void __init ar91xx_add_device_wmac(void)
 {
-       ar71xx_gpio_init();
+       u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
 
-       ar71xx_add_device_uart();
-       ar71xx_add_device_wdt();
+       memcpy(ar91xx_wmac_data.eeprom_data, ee,
+              sizeof(ar91xx_wmac_data.eeprom_data));
 
-       mips_machine_setup(ar71xx_mach_type);
-       return 0;
-}
+       ar71xx_device_stop(RESET_MODULE_AMBA2WMAC);
+       mdelay(10);
 
-arch_initcall(ar71xx_machine_setup);
+       ar71xx_device_start(RESET_MODULE_AMBA2WMAC);
+       mdelay(10);
+
+       platform_device_register(&ar91xx_wmac_device);
+}