ar71xx: add support for RB LHG 5nD
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rbspi.c
index 8f8a4f5a11dad851ca5c757258f6edee61f1cd29..b26b1ae46eb7c3fcf94863249608b9f379c4189c 100644 (file)
@@ -4,6 +4,17 @@
  *  - MikroTik RouterBOARD mAP L-2nD
  *  - MikroTik RouterBOARD 941L-2nD
  *  - MikroTik RouterBOARD 951Ui-2nD
+ *  - MikroTik RouterBOARD 750UP r2
+ *  - MikroTik RouterBOARD 750 r2
+ *  - MikroTik RouterBOARD LHG 5nD
+ *
+ *  Preliminary support for the following hardware
+ *  - MikroTik RouterBOARD wAP2nD
+ *  - MikroTik RouterBOARD cAP2nD
+ *  - MikroTik RouterBOARD mAP2nD
+ *  Furthermore, the cAP lite (cAPL2nD) appears to feature the exact same
+ *  hardware as the mAP L-2nD. It is unknown if they share the same board
+ *  identifier.
  *
  *  Copyright (C) 2017 Thibaut VARENE <varenet@parisc-linux.org>
  *
 #define RBSPI_KEYS_DEBOUNCE_INTERVAL (3 * RBSPI_KEYS_POLL_INTERVAL)
 
 #define RBSPI_HAS_USB          BIT(0)
-#define RBSPI_HAS_WLAN         BIT(1)
-#define RBSPI_HAS_WAN4         BIT(2)  /* has WAN port on PHY4 */
-#define RBSPI_HAS_SSR          BIT(3)  /* has an SSR on SPI bus 0 */
+#define RBSPI_HAS_WLAN0                BIT(1)
+#define RBSPI_HAS_WLAN1                BIT(2)
+#define RBSPI_HAS_WAN4         BIT(3)  /* has WAN port on PHY4 */
+#define RBSPI_HAS_SSR          BIT(4)  /* has an SSR on SPI bus 0 */
+#define RBSPI_HAS_POE          BIT(5)
+#define RBSPI_HAS_MDIO1                BIT(6)
 
 #define RB_ROUTERBOOT_OFFSET    0x0000
 #define RB_BIOS_SIZE            0x1000
 #define RB_SOFT_CFG_SIZE        0x1000
-#define RB_KERNEL_SIZE          (2 * 1024 * 1024)      /* 2MB kernel */
 
 /* Flash partitions indexes */
 enum {
@@ -58,8 +71,7 @@ enum {
        RBSPI_PART_BIOS,
        RBSPI_PART_RBOOT2,
        RBSPI_PART_SCONF,
-       RBSPI_PART_KERN,
-       RBSPI_PART_ROOT,
+       RBSPI_PART_FIRMW,
        RBSPI_PARTS
 };
 
@@ -68,8 +80,6 @@ static struct mtd_partition rbspi_spi_partitions[RBSPI_PARTS];
 /*
  * Setup the SPI flash partition table based on initial parsing.
  * The kernel can be at any aligned position and have any size.
- * The size of the kernel partition is the desired RB_KERNEL_SIZE
- * minus the size of the preceding partitions (128KB).
  */
 static void __init rbspi_init_partitions(const struct rb_info *info)
 {
@@ -103,16 +113,10 @@ static void __init rbspi_init_partitions(const struct rb_info *info)
        parts[RBSPI_PART_SCONF].offset = info->soft_cfg_offs;
        parts[RBSPI_PART_SCONF].size = RB_SOFT_CFG_SIZE;
 
-       parts[RBSPI_PART_KERN].name = "kernel";
-       parts[RBSPI_PART_KERN].offset = parts[RBSPI_PART_SCONF].offset
+       parts[RBSPI_PART_FIRMW].name = "firmware";
+       parts[RBSPI_PART_FIRMW].offset = parts[RBSPI_PART_SCONF].offset
                                        + parts[RBSPI_PART_SCONF].size;
-       parts[RBSPI_PART_KERN].size = RB_KERNEL_SIZE
-                                       - parts[RBSPI_PART_KERN].offset;
-
-       parts[RBSPI_PART_ROOT].name = "rootfs";
-       parts[RBSPI_PART_ROOT].offset = parts[RBSPI_PART_KERN].offset
-                                       + parts[RBSPI_PART_KERN].size;
-       parts[RBSPI_PART_ROOT].size = MTDPART_SIZ_FULL;
+       parts[RBSPI_PART_FIRMW].size = MTDPART_SIZ_FULL;
 }
 
 static struct flash_platform_data rbspi_spi_flash_data = {
@@ -186,6 +190,7 @@ static struct gpio_led rbhapl_leds[] __initdata = {
 #define RB952_GPIO_SSR_CS      11
 #define RB952_GPIO_LED_USER    4
 #define RB952_GPIO_POE_POWER   14
+#define RB952_GPIO_POE_STATUS  12
 #define RB952_GPIO_USB_POWER   RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER)
 #define RB952_GPIO_LED_LAN1    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN1)
 #define RB952_GPIO_LED_LAN2    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN2)
@@ -226,6 +231,162 @@ static struct gpio_led rb952_leds[] __initdata = {
        },
 };
 
+/* RB wAP-2nD gpios */
+#define RBWAP_GPIO_LED_USER    14
+#define RBWAP_GPIO_LED_WLAN    11
+
+static struct gpio_led rbwap_leds[] __initdata = {
+       {
+               .name = "rb:green:user",
+               .gpio = RBWAP_GPIO_LED_USER,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:wlan",
+               .gpio = RBWAP_GPIO_LED_WLAN,
+               .active_low = 1,
+       },
+};
+
+/* RB cAP-2nD gpios */
+#define RBCAP_GPIO_LED_1       14
+#define RBCAP_GPIO_LED_2       12
+#define RBCAP_GPIO_LED_3       11
+#define RBCAP_GPIO_LED_4       4
+#define RBCAP_GPIO_LED_ALL     13
+
+static struct gpio_led rbcap_leds[] __initdata = {
+       {
+               .name = "rb:green:rssi1",
+               .gpio = RBCAP_GPIO_LED_1,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi2",
+               .gpio = RBCAP_GPIO_LED_2,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi3",
+               .gpio = RBCAP_GPIO_LED_3,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi4",
+               .gpio = RBCAP_GPIO_LED_4,
+               .active_low = 1,
+       },
+};
+
+/* RB mAP-2nD gpios */
+#define RBMAP_SSR_BIT_LED_LAN1 0
+#define RBMAP_SSR_BIT_LED_LAN2 1
+#define RBMAP_SSR_BIT_LED_POEO 2
+#define RBMAP_SSR_BIT_LED_USER 3
+#define RBMAP_SSR_BIT_LED_WLAN 4
+#define RBMAP_SSR_BIT_USB_POWER        5
+#define RBMAP_SSR_BIT_LED_APCAP        6
+#define RBMAP_GPIO_SSR_CS      11
+#define RBMAP_GPIO_LED_POWER   4
+#define RBMAP_GPIO_POE_POWER   14
+#define RBMAP_GPIO_POE_STATUS  12
+#define RBMAP_GPIO_USB_POWER   RBSPI_SSR_GPIO(RBMAP_SSR_BIT_USB_POWER)
+#define RBMAP_GPIO_LED_LAN1    RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN1)
+#define RBMAP_GPIO_LED_LAN2    RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN2)
+#define RBMAP_GPIO_LED_POEO    RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_POEO)
+#define RBMAP_GPIO_LED_USER    RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_USER)
+#define RBMAP_GPIO_LED_WLAN    RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_WLAN)
+#define RBMAP_GPIO_LED_APCAP   RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_APCAP)
+
+static struct gpio_led rbmap_leds[] __initdata = {
+       {
+               .name = "rb:green:power",
+               .gpio = RBMAP_GPIO_LED_POWER,
+               .active_low = 1,
+               .default_state = LEDS_GPIO_DEFSTATE_ON,
+       }, {
+               .name = "rb:green:eth1",
+               .gpio = RBMAP_GPIO_LED_LAN1,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:eth2",
+               .gpio = RBMAP_GPIO_LED_WLAN,
+               .active_low = 1,
+       }, {
+               .name = "rb:red:poe_out",
+               .gpio = RBMAP_GPIO_LED_POEO,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:user",
+               .gpio = RBMAP_GPIO_LED_USER,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:wlan",
+               .gpio = RBMAP_GPIO_LED_WLAN,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:ap_cap",
+               .gpio = RBMAP_GPIO_LED_APCAP,
+               .active_low = 1,
+       },
+};
+
+/* RB LHG 5nD gpios */
+#define RBLHG_GPIO_LED_0       13
+#define RBLHG_GPIO_LED_1       12
+#define RBLHG_GPIO_LED_2       4
+#define RBLHG_GPIO_LED_3       21
+#define RBLHG_GPIO_LED_4       18
+#define RBLHG_GPIO_LED_ETH     14
+#define RBLHG_GPIO_LED_POWER   11
+#define RBLHG_GPIO_LED_USER    20
+#define RBLHG_GPIO_BTN_RESET   15
+
+static struct gpio_led rblhg_leds[] __initdata = {
+       {
+               .name = "rb:green:rssi0",
+               .gpio = RBLHG_GPIO_LED_0,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi1",
+               .gpio = RBLHG_GPIO_LED_1,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi2",
+               .gpio = RBLHG_GPIO_LED_2,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi3",
+               .gpio = RBLHG_GPIO_LED_3,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:rssi4",
+               .gpio = RBLHG_GPIO_LED_4,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:eth",
+               .gpio = RBLHG_GPIO_LED_ETH,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:user",
+               .gpio = RBLHG_GPIO_LED_USER,
+               .active_low = 1,
+       }, {
+               .name = "rb:blue:power",
+               .gpio = RBLHG_GPIO_LED_POWER,
+               .active_low = 0,
+               .default_state = LEDS_GPIO_DEFSTATE_ON,
+       },
+};
+
+static struct gpio_keys_button rblhg_gpio_keys[] __initdata = {
+       {
+               .desc = "Reset button",
+               .type = EV_KEY,
+               .code = KEY_RESTART,
+               .debounce_interval = RBSPI_KEYS_DEBOUNCE_INTERVAL,
+               .gpio = RBLHG_GPIO_BTN_RESET,
+               .active_low = 1,
+       },
+};
+
+
 static struct gen_74x164_chip_platform_data rbspi_ssr_data = {
        .base = RBSPI_SSR_GPIO_BASE,
 };
@@ -261,12 +422,12 @@ static struct spi_board_info rbspi_spi_info[] = {
        }
 };
 
-void __init rbspi_wlan_init(int wmac_offset)
+void __init rbspi_wlan_init(u16 id, int wmac_offset)
 {
        char *art_buf;
        u8 wlan_mac[ETH_ALEN];
 
-       art_buf = rb_get_wlan_data();
+       art_buf = rb_get_ext_wlan_data(id);
        if (!art_buf)
                return;
 
@@ -324,10 +485,12 @@ static void __init rbspi_peripherals_setup(u32 flags)
  * Sets LAN/WAN/WLAN.
  */
 static void __init rbspi_network_setup(u32 flags, int gmac1_offset,
-                                       int wmac_offset)
+                                       int wmac0_offset, int wmac1_offset)
 {
        /* for QCA953x that will init mdio1_device/data */
        ath79_register_mdio(0, 0x0);
+       if (flags & RBSPI_HAS_MDIO1)
+               ath79_register_mdio(1, 0x0);
 
        if (flags & RBSPI_HAS_WAN4) {
                ath79_setup_ar934x_eth_cfg(0);
@@ -356,12 +519,15 @@ static void __init rbspi_network_setup(u32 flags, int gmac1_offset,
        ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
        ath79_register_eth(1);
 
-       if (flags & RBSPI_HAS_WLAN)
-               rbspi_wlan_init(wmac_offset);
+       if (flags & RBSPI_HAS_WLAN0)
+               rbspi_wlan_init(0, wmac0_offset);
+
+       if (flags & RBSPI_HAS_WLAN1)
+               rbspi_wlan_init(1, wmac1_offset);
 }
 
 /* 
- * Init the mAP lite hardware.
+ * Init the mAP lite hardware (QCA953x).
  * The mAP L-2nD (mAP lite) has a single ethernet port, connected to PHY0.
  * Trying to use GMAC0 in direct mode was unsucessful, so we're
  * using SW_ONLY_MODE, which connects PHY0 to MAC1 on the internal
@@ -369,15 +535,15 @@ static void __init rbspi_network_setup(u32 flags, int gmac1_offset,
  */
 static void __init rbmapl_setup(void)
 {
-       u32 flags = RBSPI_HAS_WLAN;
+       u32 flags = RBSPI_HAS_WLAN0;
 
        if (rbspi_platform_setup())
                return;
 
        rbspi_peripherals_setup(flags);
 
-       /* GMAC1 is HW MAC, WLAN MAC is HW MAC + 1 */
-       rbspi_network_setup(flags, 0, 1);
+       /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
+       rbspi_network_setup(flags, 0, 1, 0);
 
        ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmapl_leds), rbmapl_leds);
 
@@ -392,7 +558,7 @@ static void __init rbmapl_setup(void)
 }
 
 /*
- * Init the hAP lite hardware.
+ * Init the hAP lite hardware (QCA953x).
  * The 941-2nD (hAP lite) has 4 ethernet ports, with port 2-4
  * being assigned to LAN on the casing, and port 1 being assigned
  * to "internet" (WAN) on the casing. Port 1 is connected to PHY3.
@@ -400,15 +566,15 @@ static void __init rbmapl_setup(void)
  */
 static void __init rbhapl_setup(void)
 {
-       u32 flags = RBSPI_HAS_WLAN;
+       u32 flags = RBSPI_HAS_WLAN0;
 
        if (rbspi_platform_setup())
                return;
 
        rbspi_peripherals_setup(flags);
 
-       /* GMAC1 is HW MAC, WLAN MAC is HW MAC + 4 */
-       rbspi_network_setup(flags, 0, 4);
+       /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 4 */
+       rbspi_network_setup(flags, 0, 4, 0);
 
        ath79_register_leds_gpio(-1, ARRAY_SIZE(rbhapl_leds), rbhapl_leds);
 
@@ -419,7 +585,38 @@ static void __init rbhapl_setup(void)
 }
 
 /*
- * Init the hAP hardware.
+ * The hAP, hEX lite and hEX PoE lite share the same platform
+ */
+static void __init rbspi_952_750r2_setup(u32 flags)
+{
+       if (flags & RBSPI_HAS_SSR)
+               rbspi_spi_cs_gpios[1] = RB952_GPIO_SSR_CS;
+
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC + 1, WLAN0 MAC IS HW MAC + 5 */
+       rbspi_network_setup(flags, 1, 5, 0);
+
+       if (flags & RBSPI_HAS_USB)
+               gpio_request_one(RB952_GPIO_USB_POWER,
+                               GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
+                               "USB power");
+
+       if (flags & RBSPI_HAS_POE)
+               gpio_request_one(RB952_GPIO_POE_POWER,
+                               GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
+                               "POE power");
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(rb952_leds), rb952_leds);
+
+       /* These devices have a single reset button as gpio 16 */
+       ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
+                                       ARRAY_SIZE(rbspi_gpio_keys_reset16),
+                                       rbspi_gpio_keys_reset16);
+}
+
+/*
+ * Init the hAP hardware (QCA953x).
  * The 951Ui-2nD (hAP) has 5 ethernet ports, with ports 2-5 being assigned
  * to LAN on the casing, and port 1 being assigned to "internet" (WAN).
  * Port 1 is connected to PHY4 (the ports are labelled in reverse physical
@@ -429,35 +626,133 @@ static void __init rbhapl_setup(void)
  */
 static void __init rb952_setup(void)
 {
-       u32 flags = RBSPI_HAS_WLAN | RBSPI_HAS_WAN4 | RBSPI_HAS_USB |
-                       RBSPI_HAS_SSR;
+       u32 flags = RBSPI_HAS_WLAN0 | RBSPI_HAS_WAN4 | RBSPI_HAS_USB |
+                       RBSPI_HAS_SSR | RBSPI_HAS_POE;
 
        if (rbspi_platform_setup())
                return;
 
-       rbspi_spi_cs_gpios[1] = RB952_GPIO_SSR_CS;
+       rbspi_952_750r2_setup(flags);
+}
 
-       rbspi_peripherals_setup(flags);
+/*
+ * Init the hEX (PoE) lite hardware (QCA953x).
+ * The 750UP r2 (hEX PoE lite) is nearly identical to the hAP, only without
+ * WLAN. The 750 r2 (hEX lite) is nearly identical to the 750UP r2, only
+ * without USB and POE. It shares the same bootloader board identifier.
+ */
+static void __init rb750upr2_setup(void)
+{
+       u32 flags = RBSPI_HAS_WAN4 | RBSPI_HAS_SSR;
 
-       /* GMAC1 is HW MAC + 1, WLAN MAC IS HW MAC + 5 */
-       rbspi_network_setup(flags, 1, 5);
+       if (rbspi_platform_setup())
+               return;
 
-       gpio_request_one(RB952_GPIO_USB_POWER,
-                       GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
-                       "USB power");
+       /* differentiate the hEX lite from the hEX PoE lite */
+       if (strstr(mips_get_machine_name(), "750UP r2"))
+               flags |= RBSPI_HAS_USB | RBSPI_HAS_POE;
 
-       gpio_request_one(RB952_GPIO_POE_POWER,
-                       GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
-                       "POE power");
+       rbspi_952_750r2_setup(flags);
+}
 
-       ath79_register_leds_gpio(-1, ARRAY_SIZE(rb952_leds), rb952_leds);
+/*
+ * Init the LHG hardware (AR9344).
+ * The LHG 5nD has a single ethernet port connected to PHY0.
+ * Wireless is provided via 5GHz WLAN1.
+ */
+static void __init rblhg_setup(void)
+{
+       u32 flags = RBSPI_HAS_WLAN1 | RBSPI_HAS_MDIO1;
+
+       if (rbspi_platform_setup())
+               return;
+
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC, WLAN1 MAC is HW MAC + 1 */
+       rbspi_network_setup(flags, 0, 0, 1);
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(rblhg_leds), rblhg_leds);
 
-       /* hAP has a single reset button as gpio 16 */
        ath79_register_gpio_keys_polled(-1, RBSPI_KEYS_POLL_INTERVAL,
-                                       ARRAY_SIZE(rbspi_gpio_keys_reset16),
-                                       rbspi_gpio_keys_reset16);
+                                       ARRAY_SIZE(rblhg_gpio_keys),
+                                       rblhg_gpio_keys);
 }
 
+/*
+ * Init the wAP hardware (EXPERIMENTAL).
+ * The wAP 2nD has a single ethernet port.
+ */
+static void __init rbwap_setup(void)
+{
+       u32 flags = RBSPI_HAS_WLAN0;
+
+       if (rbspi_platform_setup())
+               return;
+
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
+       rbspi_network_setup(flags, 0, 1, 0);
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwap_leds), rbwap_leds);
+}
+
+/*
+ * Init the cAP hardware (EXPERIMENTAL).
+ * The cAP 2nD has a single ethernet port, and a global LED switch.
+ */
+static void __init rbcap_setup(void)
+{
+       u32 flags = RBSPI_HAS_WLAN0;
+
+       if (rbspi_platform_setup())
+               return;
+
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
+       rbspi_network_setup(flags, 0, 1, 0);
+
+       gpio_request_one(RBCAP_GPIO_LED_ALL,
+                        GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
+                        "LEDs enable");
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(rbcap_leds), rbcap_leds);
+}
+
+/*
+ * Init the mAP hardware (EXPERIMENTAL).
+ * The mAP 2nD has two ethernet ports, PoE output and an SSR for LED
+ * multiplexing.
+ */
+static void __init rbmap_setup(void)
+{
+       u32 flags = RBSPI_HAS_WLAN0 | RBSPI_HAS_SSR | RBSPI_HAS_POE;
+
+       if (rbspi_platform_setup())
+               return;
+
+       rbspi_spi_cs_gpios[1] = RBMAP_GPIO_SSR_CS;
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 2 */
+       rbspi_network_setup(flags, 0, 2, 0);
+
+       if (flags & RBSPI_HAS_POE)
+               gpio_request_one(RBMAP_GPIO_POE_POWER,
+                               GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
+                               "POE power");
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmap_leds), rbmap_leds);
+}
+
+
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAPL, "map-hb", rbmapl_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_941, "H951L", rbhapl_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_952, "952-hb", rb952_setup);
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_750UPR2, "750-hb", rb750upr2_setup);
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_LHG5, "lhg", rblhg_setup);
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_WAP, "wap-hb", rbwap_setup);
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_CAP, "cap-hb", rbcap_setup);
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAP, "map2-hb", rbmap_setup);