ar71xx: add support for Cisco Meraki Z1 Cloud Managed Teleworker Gateway
authorChris Blake <chrisrblake93@gmail.com>
Tue, 20 Sep 2016 12:14:29 +0000 (07:14 -0500)
committerJohn Crispin <john@phrozen.org>
Tue, 27 Sep 2016 15:50:22 +0000 (17:50 +0200)
This patch adds support for Cisco's Z1.
Detailed instructions for the flashing the device can
be found in the OpenWrt wiki:
<https://wiki.openwrt.org/toh/meraki/z1>

Signed-off-by: Chris Blake <chrisrblake93@gmail.com>
16 files changed:
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/diag.sh
target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
target/linux/ar71xx/base-files/etc/uci-defaults/03_network-switchX-migration
target/linux/ar71xx/base-files/lib/ar71xx.sh
target/linux/ar71xx/base-files/lib/preinit/05_set_iface_mac_ar71xx
target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
target/linux/ar71xx/base-files/lib/upgrade/platform.sh
target/linux/ar71xx/config-4.4
target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
target/linux/ar71xx/files/arch/mips/ath79/Makefile
target/linux/ar71xx/files/arch/mips/ath79/mach-z1.c [new file with mode: 0644]
target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
target/linux/ar71xx/image/nand.mk
target/linux/ar71xx/patches-4.4/818-MIPS-ath79-add-nu801-led-driver.patch

index cf0585981399f2c075f6b7c0ac4a6ae916ecc845..7551455a8a75be6ae96b5b07ec7f1b5b78104966 100755 (executable)
@@ -813,6 +813,10 @@ wzr-hp-g300nh)
        ucidef_set_led_usbdev "usb" "USB" "buffalo:blue:usb" "1-1"
        ;;
 
+z1)
+       ucidef_set_led_netdev "wlan1" "WLAN1" "z1:blue:tricolor0" "wlan1"
+       ;;
+
 zbt-we1526)
        ucidef_set_led_netdev "wan" "WAN" "zbt-we1526:green:wan" "eth1"
        ucidef_set_led_switch "lan1" "LAN1" "zbt-we1526:green:lan1" "switch0" "0x10"
index b637113eff11fa549803eed6e96b659b4018ca05..2a50c9dca5ac3a8d1bc319a97b25ca7cab708e5b 100755 (executable)
@@ -538,6 +538,12 @@ wndr3700)
        ucidef_add_switch_port_attr "switch0" 5 led 2
        ;;
 
+z1)
+       ucidef_set_interfaces_lan_wan "eth0" "eth1"
+       ucidef_add_switch "switch0" \
+               "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
+       ;;
+
 *)
        ucidef_set_interfaces_lan_wan "eth0" "eth1"
        ;;
index 69ef609332c488b70f6944b95e4dc65160a92d99..6ce49b0e9bbf7b574400106e2e9e7e87b47916ae 100644 (file)
@@ -426,6 +426,9 @@ get_status_led() {
        wrt160nl)
                status_led="wrt160nl:blue:wps"
                ;;
+       z1)
+               status_led="z1:green:tricolor0"
+               ;;
        zbt-we1526)
                status_led="zbt-we1526:green:status"
                ;;
index 3b0229d3d531008b11a089c1c3da72496fa70d3e..31416253076268a56330710a6b8075a15b253b70 100644 (file)
@@ -73,6 +73,16 @@ case "$FIRMWARE" in
                ath9k_eeprom_extract "caldata" 4096 2048
                ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
                ;;
+       z1)
+               . /lib/upgrade/nand.sh
+
+               if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
+                       ath9k_ubi_eeprom_extract "caldata" 4096 2048
+               else
+                       ath9k_eeprom_extract "origcaldata" 4096 2048
+               fi
+               ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
+               ;;
        *)
                ath9k_eeprom_die "board $board is not supported yet"
                ;;
@@ -100,6 +110,16 @@ case "$FIRMWARE" in
                ath9k_eeprom_extract "caldata" 20480 2048
                ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
                ;;
+       z1)
+               . /lib/upgrade/nand.sh
+
+               if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
+                       ath9k_ubi_eeprom_extract "caldata" 86016 4096
+               else
+                       ath9k_eeprom_extract "origcaldata" 86016 4096
+               fi
+               ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
+               ;;
        *)
                ath9k_eeprom_die "board $board is not supported yet"
                ;;
index aa0e1b4e2f2eab85adcdebcd3daf2fac6c781693..ee8f63b5d597463e57b309689076a2a88057303a 100644 (file)
@@ -78,6 +78,7 @@ whr-hp-g300n|\
 whr-hp-gn|\
 wzr-hp-ag300h|\
 wzr-hp-g450h|\
+z1|\
 ew-dorin|\
 ew-dorin-router)
        migrate_switch_name "eth0" "switch0"
index 7a3759e7d5e5ef145abf5436c331856cbdc07818..dae6fb2a2d7a119d7243dbb559e184db16778279 100755 (executable)
@@ -1134,6 +1134,9 @@ ar71xx_board_detect() {
        *WHR-HP-G300N)
                name="whr-hp-g300n"
                ;;
+       *Z1)
+               name="z1"
+               ;;
        *ZBT-WE1526)
                name="zbt-we1526"
                ;;
index 39da3090f81d1bd3c827338e410eac79b77f11dc..60e278782fcc937e817b269a048425991a190332 100644 (file)
@@ -49,6 +49,10 @@ preinit_set_mac_address() {
                wrt160nl)
                        fetch_mac_from_mtd nvram lan_hwaddr wan_hwaddr
                        ;;
+               z1)
+                       mac_lan=$(mtd_get_mac_binary_ubi board-config 102)
+                       [ -n "$mac_lan" ] && ifconfig eth0 hw ether "$mac_lan"
+                       ;;
        esac
 }
 
index cc7a86c93d74181d8218fe3fbe0de8cef675b4c5..78cde20a130707382968a8d6e65db4e020054857 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2015 Chris Blake <chrisrblake93@gmail.com>
+# Copyright (C) 2015-2016 Chris Blake <chrisrblake93@gmail.com>
 #
 # Custom upgrade script for Meraki NAND devices (ex. MR18)
 # Based on dir825.sh and stock nand functions
@@ -14,34 +14,52 @@ get_magic_at() {
        dd bs=1 count=2 skip=$pos if=$mtddev 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
 }
 
-mr18_is_caldata_valid() {
-       local mtddev=$1
+meraki_is_caldata_valid() {
+       local board=$1
+       local mtddev=$2
        local magic
 
-       magic=$(get_magic_at $mtddev 4096)
-       [ "$magic" != "0202" ] && return 0
+       case "$board" in
+       "mr18")
+               magic=$(get_magic_at $mtddev 4096)
+               [ "$magic" != "0202" ] && return 0
+
+               magic=$(get_magic_at $mtddev 20480)
+               [ "$magic" != "0202" ] && return 0
 
-       magic=$(get_magic_at $mtddev 20480)
-       [ "$magic" != "0202" ] && return 0
+               magic=$(get_magic_at $mtddev 36864)
+               [ "$magic" != "0202" ] && return 0
+
+               return 1
+               ;;
+       "z1")
+               magic=$(get_magic_at $mtddev 4096)
+               [ "$magic" != "0202" ] && return 0
 
-       magic=$(get_magic_at $mtddev 36864)
-       [ "$magic" != "0202" ] && return 0
+               magic=$(get_magic_at $mtddev 86016)
+               [ "$magic" != "a55a" ] && return 0
 
-       return 1
+               return 1
+               ;;
+       *)
+               return 1
+               ;;
+       esac
 }
 
 merakinand_copy_caldata() {
        local cal_src=$1
        local cal_dst=$2
-       local ubidev=$( nand_find_ubi $CI_UBIPART )
+       local ubidev="$(nand_find_ubi $CI_UBIPART)"
        local board_name="$(cat /tmp/sysinfo/board_name)"
        local rootfs_size="$(ubinfo /dev/ubi0 -N rootfs_data | grep "Size" | awk '{ print $6 }')"
 
        # Setup partitions using board name, in case of future platforms
        case "$board_name" in
-       "mr18")
+       "mr18"|\
+       "z1")
                # Src is MTD
-               mtd_src=$(find_mtd_chardev $cal_src)
+               mtd_src="$(find_mtd_chardev $cal_src)"
                [ -n "$mtd_src" ] || {
                        echo "no mtd device found for partition $cal_src"
                        exit 1
@@ -56,12 +74,12 @@ merakinand_copy_caldata() {
                        exit 1
                }
 
-               mr18_is_caldata_valid "$mtd_src" && {
+               meraki_is_caldata_valid "$board_name" "$mtd_src" && {
                        echo "no valid calibration data found in $cal_src"
                        exit 1
                }
 
-               mr18_is_caldata_valid "/dev/$mtd_dst" && {
+               meraki_is_caldata_valid "$board_name" "/dev/$mtd_dst" && {
                        echo "Copying calibration data from $cal_src to $cal_dst..."
                        dd if="$mtd_src" of=/tmp/caldata.tmp 2>/dev/null
                        ubiupdatevol "/dev/$mtd_dst" /tmp/caldata.tmp
@@ -89,6 +107,11 @@ merakinand_do_kernel_check() {
                        echo "pass" && return 0
                }
                ;;
+       "z1")
+               [ "$image_magic_word" == "4d495053" ] && {
+                       echo "pass" && return 0
+               }
+               ;;
        esac
 
        exit 1
@@ -102,7 +125,8 @@ merakinand_do_platform_check() {
        local kernel_magic="$(merakinand_do_kernel_check $1 $2)"
 
        case "$board_name" in
-       "mr18")
+       "mr18"|\
+       "z1")
                [ "$control_length" = 0 -o "$file_type" != "squashfs" -o "$kernel_magic" != "pass" ] && {
                        echo "Invalid sysupgrade file for $board_name"
                        return 1
@@ -128,6 +152,11 @@ merakinand_do_upgrade() {
                merakinand_copy_caldata "odm-caldata" "caldata"
                nand_do_upgrade $1
                ;;
+       "z1")
+               # Check and create UBI caldata if it's invalid
+               merakinand_copy_caldata "origcaldata" "caldata"
+               nand_do_upgrade $1
+               ;;
        *)
                echo "Unsupported device $board_name";
                exit 1
index 716fa525a97021e3c78ea8495acd181ebdcf18cd..c78d1fb34f701de7bd64f4f94f9a3714fa0abe87 100755 (executable)
@@ -472,7 +472,8 @@ platform_check_image() {
                }
                return 0
                ;;
-       mr18)
+       mr18 | \
+       z1 )
                merakinand_do_platform_check $board $1
                return $?;
                ;;
@@ -543,7 +544,8 @@ platform_pre_upgrade() {
        wndr4300 )
                nand_do_upgrade "$1"
                ;;
-       mr18)
+       mr18 | \
+       z1 )
                merakinand_do_upgrade "$1"
                ;;
        esac
index 0b5e3942f02230410d9f47f4d165a5398c187002..f81a74c0c4ee33598e993cef3cb6586ef22f50c8 100644 (file)
@@ -201,6 +201,7 @@ CONFIG_ATH79_MACH_WZR_HP_AG300H=y
 CONFIG_ATH79_MACH_WZR_HP_G300NH=y
 CONFIG_ATH79_MACH_WZR_HP_G300NH2=y
 CONFIG_ATH79_MACH_WZR_HP_G450H=y
+CONFIG_ATH79_MACH_Z1=y
 CONFIG_ATH79_MACH_ZBT_WE1526=y
 CONFIG_ATH79_MACH_ZCN_1523H=y
 CONFIG_ATH79_NVRAM=y
index a6f19daa0d2c8de0d1829eb352224b40a7d04af3..4cefde1ac235a546f1ab2fdfa290b9dc46113904 100644 (file)
@@ -1552,6 +1552,18 @@ config ATH79_MACH_MYNET_REXT
        select ATH79_DEV_WMAC
        select ATH79_NVRAM
 
+config ATH79_MACH_Z1
+       bool "Meraki Z1 board support"
+       select SOC_AR934X
+       select ATH79_DEV_AP9X_PCI if PCI
+       select ATH79_DEV_ETH
+       select ATH79_DEV_GPIO_BUTTONS
+       select ATH79_DEV_LEDS_GPIO
+       select ATH79_DEV_NFC
+       select ATH79_DEV_USB
+       select ATH79_DEV_WMAC
+       select LEDS_NU801
+
 config ATH79_MACH_ZBT_WE1526
        bool "Zbtlink ZBT-WE1526 board support"
        select SOC_QCA953X
index 3222a76660806cc0e83ee820f6f6ec8facf9eb25..a0f8d998e259cde372b417952a4f2d7c4017e66e 100644 (file)
@@ -205,6 +205,7 @@ obj-$(CONFIG_ATH79_MACH_WZR_HP_G300NH2)     += mach-wzr-hp-g300nh2.o
 obj-$(CONFIG_ATH79_MACH_WZR_HP_AG300H) += mach-wzr-hp-ag300h.o
 obj-$(CONFIG_ATH79_MACH_WZR_HP_G450H)  += mach-wzr-hp-g450h.o
 obj-$(CONFIG_ATH79_MACH_WZR_450HP2)    += mach-wzr-450hp2.o
+obj-$(CONFIG_ATH79_MACH_Z1)            += mach-z1.o
 obj-$(CONFIG_ATH79_MACH_ZBT_WE1526)    += mach-zbt-we1526.o
 obj-$(CONFIG_ATH79_MACH_ZCN_1523H)     += mach-zcn-1523h.o
 obj-$(CONFIG_ATH79_MACH_CARAMBOLA2)    += mach-carambola2.o
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-z1.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-z1.c
new file mode 100644 (file)
index 0000000..552d646
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ *  Cisco Meraki Z1 board support
+ *
+ *  Copyright (C) 2016 Chris Blake <chrisrblake93@gmail.com>
+ *  Copyright (C) 2016 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ *  Based on Cisco Meraki GPL Release r23-20150601 Z1 Device Config
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+#include <linux/platform_device.h>
+#include <linux/ath9k_platform.h>
+#include <linux/ar8216_platform.h>
+#include <linux/platform/ar934x_nfc.h>
+
+#include <asm/mach-ath79/ath79.h>
+#include <asm/mach-ath79/ar71xx_regs.h>
+
+#include <linux/leds-nu801.h>
+#include <linux/firmware.h>
+#include <linux/pci.h>
+
+#include "common.h"
+#include "dev-eth.h"
+#include "dev-gpio-buttons.h"
+#include "dev-leds-gpio.h"
+#include "dev-nfc.h"
+#include "dev-usb.h"
+#include "dev-wmac.h"
+#include "dev-ap9x-pci.h"
+#include "machtypes.h"
+
+#define Z1_GPIO_LED_POWER_ORANGE       17
+
+#define Z1_GPIO_NU801_CKI              14
+#define Z1_GPIO_NU801_SDI              15
+
+#define Z1_GPIO_XLNA0                  18
+#define Z1_GPIO_XLNA1                  19
+
+#define Z1_GPIO_BTN_RESET              12
+#define Z1_KEYS_POLL_INTERVAL          20  /* msecs */
+#define Z1_KEYS_DEBOUNCE_INTERVAL      (3 * Z1_KEYS_POLL_INTERVAL)
+
+#define Z1_ETH_SWITCH_PHY              0
+
+static struct gpio_led Z1_leds_gpio[] __initdata = {
+       {
+               .name = "z1:orange:power",
+               .gpio = Z1_GPIO_LED_POWER_ORANGE,
+               .active_low  = 1,
+       },
+};
+
+static struct gpio_keys_button Z1_gpio_keys[] __initdata = {
+       {
+               .desc = "reset",
+               .type = EV_KEY,
+               .code = KEY_RESTART,
+               .debounce_interval = Z1_KEYS_DEBOUNCE_INTERVAL,
+               .gpio    = Z1_GPIO_BTN_RESET,
+               .active_low  = 1,
+       },
+};
+
+static struct led_nu801_template tricolor_led_template = {
+       .device_name = "z1",
+       .name = "tricolor",
+       .num_leds = 1,
+       .cki = Z1_GPIO_NU801_CKI,
+       .sdi = Z1_GPIO_NU801_SDI,
+       .lei = -1,
+       .ndelay = 500,
+       .init_brightness = {
+               LED_OFF,
+               LED_OFF,
+               LED_OFF,
+       },
+       .default_trigger = "none",
+};
+
+static struct led_nu801_platform_data tricolor_led_data = {
+       .num_controllers = 1,
+       .template = &tricolor_led_template,
+};
+
+static struct platform_device tricolor_leds = {
+       .name = "leds-nu801",
+       .id = -1,
+       .dev.platform_data = &tricolor_led_data,
+};
+
+static struct ar8327_pad_cfg z1_ar8327_pad0_cfg = {
+       .mode = AR8327_PAD_MAC_RGMII,
+       .txclk_delay_en = true,
+       .rxclk_delay_en = true,
+       .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
+       .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
+};
+
+static struct ar8327_platform_data z1_ar8327_data = {
+       .pad0_cfg = &z1_ar8327_pad0_cfg,
+       .port0_cfg = {
+               .force_link = 1,
+               .speed = AR8327_PORT_SPEED_1000,
+               .duplex = 1,
+               .txpause = 1,
+               .rxpause = 1,
+       },
+};
+
+static struct mdio_board_info z1_mdio0_info[] = {
+       {
+               .bus_id = "ag71xx-mdio.0",
+               .phy_addr = Z1_ETH_SWITCH_PHY,
+               .platform_data = &z1_ar8327_data,
+       },
+};
+
+static void __init z1_setup(void)
+{
+       /* NAND */
+       ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_SOFT_BCH);
+       ath79_register_nfc();
+
+       /* Eth Config */
+       ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
+                                  AR934X_ETH_CFG_SW_ONLY_MODE);
+
+       /* MDIO Interface */
+       ath79_register_mdio(1, 0x0);
+       ath79_register_mdio(0, 0x0);
+       mdiobus_register_board_info(z1_mdio0_info,
+                                   ARRAY_SIZE(z1_mdio0_info));
+
+       /* GMAC0 is connected to an AR8327 switch */
+       ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
+       ath79_eth0_data.phy_mask = BIT(Z1_ETH_SWITCH_PHY);
+       ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
+       ath79_eth0_pll_data.pll_1000 = 0x06000000;
+       ath79_register_eth(0);
+
+       /* XLNA */
+       ath79_wmac_set_ext_lna_gpio(0, Z1_GPIO_XLNA0);
+       ath79_wmac_set_ext_lna_gpio(1, Z1_GPIO_XLNA1);
+
+       /* LEDs and Buttons */
+       platform_device_register(&tricolor_leds);
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(Z1_leds_gpio),
+                                Z1_leds_gpio);
+       ath79_register_gpio_keys_polled(-1, Z1_KEYS_POLL_INTERVAL,
+                                       ARRAY_SIZE(Z1_gpio_keys),
+                                       Z1_gpio_keys);
+
+       /* USB */
+       ath79_register_usb();
+
+       /* Wireless */
+       ath79_register_wmac_simple();
+       ap91_pci_init_simple();
+}
+MIPS_MACHINE(ATH79_MACH_Z1, "Z1", "Meraki Z1", z1_setup);
index a3b8c8749d3bcab07ef805ae051157130e78c4d7..87acc4a982bfcf61eb79452d4554520023908981 100644 (file)
@@ -266,6 +266,7 @@ enum ath79_mach_type {
        ATH79_MACH_WZR_HP_G300NH2,      /* Buffalo WZR-HP-G300NH2 */
        ATH79_MACH_WZR_HP_G450H,        /* Buffalo WZR-HP-G450H */
        ATH79_MACH_WZR_450HP2,          /* Buffalo WZR-450HP2 */
+       ATH79_MACH_Z1,                  /* Cisco Meraki Z1 */
        ATH79_MACH_ZBT_WE1526,          /* Zbtlink ZBT-WE1526 */
        ATH79_MACH_ZCN_1523H_2,         /* Zcomax ZCN-1523H-2-xx */
        ATH79_MACH_ZCN_1523H_5,         /* Zcomax ZCN-1523H-5-xx */
index c6a8d7e41010822455fdbfd625049221e02be927..aa431ac18c3be568bc5e7b8089d6a583e05b7b54 100644 (file)
@@ -20,6 +20,29 @@ define Device/mr18
 endef
 TARGET_DEVICES += mr18
 
+define Build/MerakiNAND-old
+       -$(STAGING_DIR_HOST)/bin/mkmerakifw-old \
+               -B $(BOARDNAME) -s \
+               -i $@ \
+               -o $@.new
+       @mv $@.new $@
+endef
+
+define Device/z1
+  DEVICE_TITLE := Meraki Z1
+  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-ledtrig-usbdev kmod-spi-gpio kmod-ath9k kmod-owl-loader
+  BOARDNAME = Z1
+  BLOCKSIZE := 64k
+  CONSOLE = ttyS0,115200
+  MTDPARTS = ar934x-nfc:128K(loader1)ro,8064K(kernel),128K(loader2)ro,8064K(recovery),114560K(ubi),128K(origcaldata)ro
+  IMAGES := sysupgrade.tar
+  KERNEL := kernel-bin | patch-cmdline | MerakiNAND-old
+  KERNEL_INITRAMFS := kernel-bin | patch-cmdline | MerakiNAND-old
+  IMAGE/sysupgrade.tar := sysupgrade-tar
+endef
+
+TARGET_DEVICES += z1
+
 define LegacyDevice/R6100
   DEVICE_TITLE := NETGEAR R6100
   DEVICE_PACKAGES := kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-ledtrig-usbdev
index ec9f59e3fe519cdd671e052f23770c97edc72ea6..420bbff185b1175f45c1df5ba2b699abec54e920 100644 (file)
@@ -6,7 +6,7 @@
  
 +config LEDS_NU801
 +      tristate "LED driver for NU801 RGB LED"
-+      depends on LEDS_CLASS && ATH79_MACH_MR18
++      depends on LEDS_CLASS && (ATH79_MACH_MR18 || ATH79_MACH_Z1)
 +      help
 +        This option enables support for NU801 RGB LED driver chips
 +        accessed via GPIO.