[ar71xx] Add support for Ubiquiti UniFi AP
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ubnt.c
index 5ad59943d8011fc143b645b773eb4c14d3a47ec1..e99542f2b8a3929330ce0b307abfd79b6099e593 100644 (file)
  *  by the Free Software Foundation.
  */
 
-#include <linux/pci.h>
-#include <linux/platform_device.h>
-
-#include <asm/mips_machine.h>
 #include <asm/mach-ar71xx/ar71xx.h>
 
+#include "machtype.h"
 #include "devices.h"
 #include "dev-m25p80.h"
 #include "dev-ap91-pci.h"
 #include "dev-gpio-buttons.h"
 #include "dev-pb42-pci.h"
 #include "dev-leds-gpio.h"
+#include "dev-usb.h"
 
 #define UBNT_RS_GPIO_LED_RF    2
 #define UBNT_RS_GPIO_SW4       8
@@ -106,8 +104,8 @@ static struct gpio_button ubnt_gpio_buttons[] __initdata = {
        {
                .desc           = "sw4",
                .type           = EV_KEY,
-               .code           = BTN_0,
-               .threshold      = 5,
+               .code           = KEY_RESTART,
+               .threshold      = 3,
                .gpio           = UBNT_RS_GPIO_SW4,
                .active_low     = 1,
        }
@@ -117,8 +115,8 @@ static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
        {
                .desc           = "reset",
                .type           = EV_KEY,
-               .code           = BTN_0,
-               .threshold      = 5,
+               .code           = KEY_RESTART,
+               .threshold      = 3,
                .gpio           = UBNT_M_GPIO_BTN_RESET,
                .active_low     = 1,
        }
@@ -138,21 +136,18 @@ static void __init ubnt_generic_setup(void)
 #define UBNT_RS_WAN_PHYMASK    (1 << 20)
 #define UBNT_RS_LAN_PHYMASK    ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
 
-#define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
-#define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
-
 static void __init ubnt_rs_setup(void)
 {
        ubnt_generic_setup();
 
        ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
 
+       ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
        ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
 
+       ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
        ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
-       ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
-
        ar71xx_eth1_data.speed = SPEED_100;
        ar71xx_eth1_data.duplex = DUPLEX_FULL;
 
@@ -165,7 +160,11 @@ static void __init ubnt_rs_setup(void)
                                        ubnt_rs_leds_gpio);
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
+            ubnt_rs_setup);
+
+#define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
+#define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
 
 static void __init ubnt_rspro_setup(void)
 {
@@ -173,12 +172,13 @@ static void __init ubnt_rspro_setup(void)
 
        ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
 
+       ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
        ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
 
+       ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
        ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
        ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
-
        ar71xx_eth1_data.speed = SPEED_1000;
        ar71xx_eth1_data.duplex = DUPLEX_FULL;
 
@@ -191,7 +191,7 @@ static void __init ubnt_rspro_setup(void)
                                        ubnt_rs_leds_gpio);
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "Ubiquiti RouterStation Pro",
+MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
             ubnt_rspro_setup);
 
 static void __init ubnt_lsx_setup(void)
@@ -199,7 +199,7 @@ static void __init ubnt_lsx_setup(void)
        ubnt_generic_setup();
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
 
 #define UBNT_LSSR71_PHY_MASK   (1 << 1)
 
@@ -209,6 +209,7 @@ static void __init ubnt_lssr71_setup(void)
 
        ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
 
+       ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
        ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
 
@@ -218,21 +219,21 @@ static void __init ubnt_lssr71_setup(void)
                                        ubnt_ls_sr71_leds_gpio);
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
+            ubnt_lssr71_setup);
 
 static void __init ubnt_m_setup(void)
 {
        u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
        u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
 
-       ar71xx_set_mac_base(mac);
-
        ar71xx_add_device_m25p80(NULL);
 
        ar71xx_add_device_mdio(~0);
 
+       ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
+       ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
        ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
-       ar71xx_eth0_data.phy_mask = 0;
        ar71xx_eth0_data.speed = SPEED_100;
        ar71xx_eth0_data.duplex = DUPLEX_FULL;
        ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
@@ -257,8 +258,10 @@ static void __init ubnt_rocket_m_setup(void)
        ar71xx_add_device_usb();
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "Ubiquiti Bullet M", ubnt_m_setup);
-MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "Ubiquiti Rocket M", ubnt_rocket_m_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
+            ubnt_m_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
+            ubnt_rocket_m_setup);
 
 /* TODO detect the second ethernet port and use one
    init function for all Ubiquiti MIMO series products */
@@ -267,7 +270,6 @@ static void __init ubnt_nano_m_setup(void)
        ubnt_m_setup();
 
        ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
-       ar71xx_eth1_data.phy_mask = 0;
        ar71xx_eth1_data.speed = SPEED_1000;
        ar71xx_eth1_data.duplex = DUPLEX_FULL;
        ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
@@ -277,4 +279,42 @@ static void __init ubnt_nano_m_setup(void)
        ar71xx_add_device_eth(1);
 }
 
-MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "Ubiquiti Nanostation M", ubnt_nano_m_setup);
+MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
+            ubnt_nano_m_setup);
+
+static struct gpio_led ubnt_unifi_leds_gpio[] __initdata = {
+       {
+               .name           = "ubnt:orange:dome",
+               .gpio           = 1,
+               .active_low     = 0,
+       }, {
+               .name           = "ubnt:green:dome",
+               .gpio           = 0,
+               .active_low     = 0,
+       }
+};
+
+static void __init ubnt_unifi_setup(void)
+{
+       u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
+       u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
+
+       ar71xx_add_device_m25p80(NULL);
+
+       ar71xx_add_device_mdio(~0);
+
+       ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
+       ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
+       ar71xx_eth0_data.speed = SPEED_100;
+       ar71xx_eth0_data.duplex = DUPLEX_FULL;
+
+       ar71xx_add_device_eth(0);
+
+       ap91_pci_init(ee, NULL);
+
+       ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_leds_gpio),
+                                       ubnt_unifi_leds_gpio);
+}
+
+MIPS_MACHINE(AR71XX_MACH_UBNT_UNIFI, "UBNT-XM", "Ubiquiti UniFi",
+            ubnt_unifi_setup);