ar71xx: add support for RB951Ui-2nD
authorThibaut VARENE <hacks@slashdirt.org>
Tue, 7 Feb 2017 18:10:04 +0000 (19:10 +0100)
committerFelix Fietkau <nbd@nbd.name>
Wed, 15 Feb 2017 10:28:58 +0000 (11:28 +0100)
This patch adds support for the MikroTik RouterBOARD hAP
https://routerboard.com/RB951Ui-2nD

Specifications:
- SoC: Qualcomm QCA9531 (650MHz)
- RAM: 64MB
- Storage: 16MB NOR SPI flash
- Wireless: builtin QCA9531, 2x2:2
- Ethernet: 5x100M (1 PoE in, 1 PoE out)
- USB: Type A

Signed-off-by: Thibaut VARENE <hacks@slashdirt.org>
target/linux/ar71xx/base-files/etc/board.d/01_leds
target/linux/ar71xx/base-files/etc/board.d/02_network
target/linux/ar71xx/base-files/etc/board.d/03_gpio_switches
target/linux/ar71xx/base-files/etc/diag.sh
target/linux/ar71xx/base-files/lib/ar71xx.sh
target/linux/ar71xx/base-files/lib/upgrade/platform.sh
target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
target/linux/ar71xx/files/arch/mips/ath79/machtypes.h

index 1d692fff3a3ef719ad6479ad351ca5e2468c2d64..403715c002a7898551438b535f3a79cacd9883e9 100755 (executable)
@@ -225,6 +225,15 @@ rb-750)
 rb-941-2nd)
        ucidef_set_led_timer "user" "USR/ACT" "rb:green:user" "1000" "1000"
        ;;
+rb-951ui-2nd)
+       ucidef_set_led_timer "user" "USER" "rb:green:user" "1000" "1000"
+       ucidef_set_led_netdev "port1" "port1" "rb:green:port1" "eth0"
+       ucidef_set_led_switch "port2" "port2" "rb:green:port2" "switch0" "0x10"
+       ucidef_set_led_switch "port3" "port2" "rb:green:port3" "switch0" "0x08"
+       ucidef_set_led_switch "port4" "port3" "rb:green:port4" "switch0" "0x04"
+       ucidef_set_led_switch "port5" "port5" "rb:green:port5" "switch0" "0x02"
+       ucidef_set_led_wlan "wlan" "WLAN" "rb:blue:wlan" "phy0tpt"
+       ;;
 rb-2011l|\
 rb-2011uas|\
 rb-2011uias|\
index f3dcd907e3032584f73dcd009ae078314827f909..721c01c6a4b87af2e8eb8a43dc669b488727b2db 100755 (executable)
@@ -137,6 +137,7 @@ ar71xx_setup_interfaces()
        pb42|\
        pb44|\
        rb-951ui-2hnd|\
+       rb-951ui-2nd|\
        routerstation|\
        tl-wr710n|\
        tl-wr720n-v3|\
index 66be8e76d555314832f846041a293674b40c64e9..e76c9be68aefdc80f3fc53fda3126b375fc106b5 100755 (executable)
@@ -27,6 +27,10 @@ rb-912uag-2hpnd|\
 rb-912uag-5hpnd)
        ucidef_add_gpio_switch "usb_power_switch" "USB Power Switch" "52" "1"
        ;;
+rb-951ui-2nd)
+       ucidef_add_gpio_switch "usb_power_switch" "USB Power Switch" "45" "1"
+       ucidef_add_gpio_switch "poe_passthrough" "PoE Passthrough" "14"
+       ;;
 esac
 
 board_config_flush
index 527e8b749e1ef15d73ee638d2fbd213931be5a21..5f52389c8b66b5c06701e2f1600f049d368707e6 100644 (file)
@@ -299,6 +299,7 @@ get_status_led() {
        rb-912uag-2hpnd|\
        rb-912uag-5hpnd|\
        rb-941-2nd|\
+       rb-951ui-2nd|\
        rb-mapl-2nd)
                status_led="rb:green:user"
                ;;
index 066f8eb17f3eaf16e45adebb39e67b25ea88c678..a79839864cf5a2b9da638c3e5db4a69e4a01fb0a 100755 (executable)
@@ -868,6 +868,9 @@ ar71xx_board_detect() {
        *"RouterBOARD 951Ui-2HnD")
                name="rb-951ui-2hnd"
                ;;
+       *"951Ui-2nD")
+               name="rb-951ui-2nd"
+               ;;
        *"RouterBOARD 2011L")
                name="rb-2011l"
                ;;
index 43515fe93aba6da80c141d5e3142b9a7f046c5e2..b18e87eec7088b8545a97da5b48ec69f4e43d652 100755 (executable)
@@ -344,6 +344,7 @@ platform_check_image() {
        pb42|\
        pb44|\
        rb-941-2nd|\
+       rb-951ui-2nd|\
        rb-mapl-2nd|\
        routerstation-pro|\
        routerstation|\
@@ -617,6 +618,7 @@ platform_pre_upgrade() {
 
        case "$board" in
        rb-941-2nd|\
+       rb-951ui-2nd|\
        rb-mapl-2nd)
                ;;
        rb*|\
@@ -654,6 +656,7 @@ platform_do_upgrade() {
 
        case "$board" in
        rb-941-2nd|\
+       rb-951ui-2nd|\
        rb-mapl-2nd)
                PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=1
                platform_do_upgrade_combined "$ARGV"
index 9bca451002ba3115ac6a6aba8b8ab971ddc45dd0..ef22aea3485ac85e6e8ed3397eb386f32543cdcc 100644 (file)
@@ -921,12 +921,14 @@ config ATH79_MACH_RBSPI
        select ATH79_DEV_GPIO_BUTTONS
        select ATH79_DEV_LEDS_GPIO
        select ATH79_DEV_M25P80
+       select ATH79_DEV_USB
        select ATH79_DEV_WMAC
        select ATH79_ROUTERBOOT
        help
          Say 'Y' here if you want your kernel to support the
          MikroTik RouterBOARD mAP lite
          MikroTik RouterBOARD hAP lite
+         MikroTik RouterBOARD hAP
 
 config ATH79_MACH_RBSXTLITE
        bool "MikroTik RouterBOARD SXT Lite"
index 541865220c79dd92d54c79cd2255c3eb4aa61cf1..8f8a4f5a11dad851ca5c757258f6edee61f1cd29 100644 (file)
@@ -3,6 +3,7 @@
  *
  *  - MikroTik RouterBOARD mAP L-2nD
  *  - MikroTik RouterBOARD 941L-2nD
+ *  - MikroTik RouterBOARD 951Ui-2nD
  *
  *  Copyright (C) 2017 Thibaut VARENE <varenet@parisc-linux.org>
  *
@@ -16,6 +17,9 @@
 #include <linux/routerboot.h>
 #include <linux/gpio.h>
 
+#include <linux/spi/spi.h>
+#include <linux/spi/74x164.h>
+
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
@@ -40,6 +44,7 @@
 #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 RB_ROUTERBOOT_OFFSET    0x0000
 #define RB_BIOS_SIZE            0x1000
@@ -166,6 +171,96 @@ static struct gpio_led rbhapl_leds[] __initdata = {
        },
 };
 
+/* common RB SSRs */
+#define RBSPI_SSR_GPIO_BASE    40
+#define RBSPI_SSR_GPIO(bit)    (RBSPI_SSR_GPIO_BASE + (bit))
+
+/* RB 951Ui-2nD gpios */
+#define RB952_SSR_BIT_LED_LAN1 0
+#define RB952_SSR_BIT_LED_LAN2 1
+#define RB952_SSR_BIT_LED_LAN3 2
+#define RB952_SSR_BIT_LED_LAN4 3
+#define RB952_SSR_BIT_LED_LAN5 4
+#define RB952_SSR_BIT_USB_POWER        5
+#define RB952_SSR_BIT_LED_WLAN 6
+#define RB952_GPIO_SSR_CS      11
+#define RB952_GPIO_LED_USER    4
+#define RB952_GPIO_POE_POWER   14
+#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)
+#define RB952_GPIO_LED_LAN3    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN3)
+#define RB952_GPIO_LED_LAN4    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN4)
+#define RB952_GPIO_LED_LAN5    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN5)
+#define RB952_GPIO_LED_WLAN    RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_WLAN)
+
+static struct gpio_led rb952_leds[] __initdata = {
+       {
+               .name = "rb:green:user",
+               .gpio = RB952_GPIO_LED_USER,
+               .active_low = 0,
+       }, {
+               .name = "rb:blue:wlan",
+               .gpio = RB952_GPIO_LED_WLAN,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:port1",
+               .gpio = RB952_GPIO_LED_LAN1,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:port2",
+               .gpio = RB952_GPIO_LED_LAN2,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:port3",
+               .gpio = RB952_GPIO_LED_LAN3,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:port4",
+               .gpio = RB952_GPIO_LED_LAN4,
+               .active_low = 1,
+       }, {
+               .name = "rb:green:port5",
+               .gpio = RB952_GPIO_LED_LAN5,
+               .active_low = 1,
+       },
+};
+
+static struct gen_74x164_chip_platform_data rbspi_ssr_data = {
+       .base = RBSPI_SSR_GPIO_BASE,
+};
+
+/* the spi-ath79 driver can only natively handle CS0. Other CS are bit-banged */
+static int rbspi_spi_cs_gpios[] = {
+       -ENOENT,        /* CS0 is always -ENOENT: natively handled */
+       -ENOENT,        /* CS1 can be updated by the code as necessary */
+};
+
+static struct ath79_spi_platform_data rbspi_ath79_spi_data = {
+       .bus_num = 0,
+       .cs_gpios = rbspi_spi_cs_gpios,
+};
+
+/*
+ * Global spi_board_info: devices that don't have an SSR only have the SPI NOR
+ * flash on bus0 CS0, while devices that have an SSR add it on the same bus CS1
+ */
+static struct spi_board_info rbspi_spi_info[] = {
+       {
+               .bus_num        = 0,
+               .chip_select    = 0,
+               .max_speed_hz   = 25000000,
+               .modalias       = "m25p80",
+               .platform_data  = &rbspi_spi_flash_data,
+       }, {
+               .bus_num        = 0,
+               .chip_select    = 1,
+               .max_speed_hz   = 25000000,
+               .modalias       = "74x164",
+               .platform_data  = &rbspi_ssr_data,
+       }
+};
+
 void __init rbspi_wlan_init(int wmac_offset)
 {
        char *art_buf;
@@ -209,7 +304,16 @@ static int __init rbspi_platform_setup(void)
  */
 static void __init rbspi_peripherals_setup(u32 flags)
 {
-       ath79_register_m25p80(&rbspi_spi_flash_data);
+       unsigned spi_n;
+
+       if (flags & RBSPI_HAS_SSR)
+               spi_n = ARRAY_SIZE(rbspi_spi_info);
+       else
+               spi_n = 1;     /* only one device on bus0 */
+
+       rbspi_ath79_spi_data.num_chipselect = spi_n;
+       rbspi_ath79_spi_data.cs_gpios = rbspi_spi_cs_gpios;
+       ath79_register_spi(&rbspi_ath79_spi_data, rbspi_spi_info, spi_n);
 
        if (flags & RBSPI_HAS_USB)
                ath79_register_usb();
@@ -314,5 +418,46 @@ static void __init rbhapl_setup(void)
                                        rbspi_gpio_keys_reset16);
 }
 
+/*
+ * Init the hAP hardware.
+ * 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
+ * number), so the SoC can be set to connect GMAC0 to PHY4 and GMAC1 to the
+ * internal switch for the LAN ports.
+ * The device also has USB, PoE output and an SSR used for LED multiplexing.
+ */
+static void __init rb952_setup(void)
+{
+       u32 flags = RBSPI_HAS_WLAN | RBSPI_HAS_WAN4 | RBSPI_HAS_USB |
+                       RBSPI_HAS_SSR;
+
+       if (rbspi_platform_setup())
+               return;
+
+       rbspi_spi_cs_gpios[1] = RB952_GPIO_SSR_CS;
+
+       rbspi_peripherals_setup(flags);
+
+       /* GMAC1 is HW MAC + 1, WLAN MAC IS HW MAC + 5 */
+       rbspi_network_setup(flags, 1, 5);
+
+       gpio_request_one(RB952_GPIO_USB_POWER,
+                       GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
+                       "USB power");
+
+       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);
+
+       /* 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);
+}
+
 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);
index 706663ca11a92b0840b16fbb8a6d213dc939345c..2df4eda5cacd84d8e2759b5a321950318c9686f7 100644 (file)
@@ -173,6 +173,7 @@ enum ath79_mach_type {
        ATH79_MACH_RB_941,                      /* MikroTik RouterBOARD 941-2nD */
        ATH79_MACH_RB_951G,                     /* Mikrotik RouterBOARD 951G */
        ATH79_MACH_RB_951U,                     /* Mikrotik RouterBOARD 951Ui-2HnD */
+       ATH79_MACH_RB_952,                      /* MikroTik RouterBOARD 951Ui-2nD */
        ATH79_MACH_RB_MAPL,                     /* Mikrotik RouterBOARD mAP L-2nD */
        ATH79_MACH_RB_SXTLITE2ND,               /* Mikrotik RouterBOARD SXT Lite 2nD */
        ATH79_MACH_RB_SXTLITE5ND,               /* Mikrotik RouterBOARD SXT Lite 5nD */