ar71xx: Add support to TP-Link EAP120
authorHenryk Heisig <hyniu@o2.pl>
Thu, 6 Oct 2016 21:46:38 +0000 (23:46 +0200)
committerJohn Crispin <john@phrozen.org>
Tue, 18 Oct 2016 07:18:55 +0000 (09:18 +0200)
Signed-off-by: Henryk Heisig <hyniu@o2.pl>
target/linux/ar71xx/base-files/etc/board.d/02_network
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/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-eap120.c [new file with mode: 0644]
target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
target/linux/ar71xx/image/tp-link.mk
tools/firmware-utils/src/tplink-safeloader.c

index f720767fbb224307f7a38f9da4e0d4b26727e42d..b7b91d0ad80e22eabcde208970728b2280f481eb 100755 (executable)
@@ -66,6 +66,7 @@ ar71xx_setup_interfaces()
        bullet-m|\
        c-55|\
        cap4200ag|\
+       eap120|\
        eap300v2|\
        eap7660d|\
        el-mini|\
index 0d069ec88c10ec29aba1f20e9a1ab69b5c9f6c56..7a40f44e4a3f11031099d67c797ae9ca467d2d6d 100644 (file)
@@ -130,6 +130,9 @@ get_status_led() {
        oolite)
                status_led="$board:red:system"
                ;;
+       eap120)
+               status_led="$(ar71xx_board_name):green:system"
+               ;;
        eap300v2)
                status_led="engenius:blue:power"
                ;;
index 940c1c95de45456cf78d83c9f4baa4a9417eeeff..1492b5077449db7a7038d1467f674e02308a59b9 100755 (executable)
@@ -361,6 +361,9 @@ tplink_pharos_board_detect() {
        'CPE520(TP-LINK|UN|N300-5)')
                model='TP-Link CPE520'
                ;;
+       'EAP120(TP-LINK|UN|N300-2)')
+               model='TP-Link EAP120'
+               ;;
        esac
 
        [ -n "$model" ] && AR71XX_MODEL="$model v$2"
@@ -563,6 +566,10 @@ ar71xx_board_detect() {
        *"Domino Pi")
                name="gl-domino"
                ;;
+       *"EAP120")
+               name="eap120"
+               tplink_pharos_board_detect
+               ;;
        *"EAP300 v2")
                name="eap300v2"
                ;;
index 7c554e3f29260326b4b058bc4081b89db3b144bf..35e9bb4391e8a409eabfd2b56a59e02fa3c48252 100755 (executable)
@@ -433,7 +433,8 @@ platform_check_image() {
                return $?
                ;;
        cpe210|\
-       cpe510)
+       cpe510|\
+       eap120)
                tplink_pharos_check_image "$1" && return 0
                return 1
                ;;
index fb59b077ce78c9dc365f787d49936272592a3a39..77a594999d0b3916dbe3c94c91354cd402f4018d 100644 (file)
@@ -80,6 +80,7 @@ CONFIG_ATH79_MACH_DLAN_PRO_500_WP=y
 CONFIG_ATH79_MACH_DR344=y
 CONFIG_ATH79_MACH_DR531=y
 CONFIG_ATH79_MACH_DRAGINO2=y
+CONFIG_ATH79_MACH_EAP120=y
 CONFIG_ATH79_MACH_EAP300V2=y
 CONFIG_ATH79_MACH_EAP7660D=y
 CONFIG_ATH79_MACH_EL_M150=y
@@ -315,7 +316,9 @@ CONFIG_LEDS_NU801=y
 # CONFIG_LEDS_WNDR3700_USB is not set
 CONFIG_LIBFDT=y
 CONFIG_MARVELL_PHY=y
+CONFIG_MDIO_BITBANG=y
 CONFIG_MDIO_BOARDINFO=y
+CONFIG_MDIO_GPIO=y
 CONFIG_MICREL_PHY=y
 CONFIG_MIPS=y
 CONFIG_MIPS_CLOCK_VSYSCALL=y
index 3084155673714e83ec656c723c832921390f087b..7c171ee2acb80227d84fe3389edba3246987e454 100644 (file)
@@ -666,6 +666,15 @@ config ATH79_MACH_GL_INET
        select ATH79_DEV_USB
        select ATH79_DEV_WMAC
 
+config ATH79_MACH_EAP120
+       bool "TP-LINK EAP120 support"
+       select SOC_AR934X
+       select ATH79_DEV_ETH
+       select ATH79_DEV_GPIO_BUTTONS
+       select ATH79_DEV_LEDS_GPIO
+       select ATH79_DEV_M25P80
+       select ATH79_DEV_WMAC
+
 config ATH79_MACH_EAP300V2
        bool "EnGenius EAP300 v2 support"
        select SOC_AR934X
index ed5c4d8faffb8363a84e5c82d299a8c894942c8b..c528c03e357f043c6322846fd73131d5665190b9 100644 (file)
@@ -86,6 +86,7 @@ obj-$(CONFIG_ATH79_MACH_DLAN_PRO_500_WP)      += mach-dlan-pro-500-wp.o
 obj-$(CONFIG_ATH79_MACH_DR344)                 += mach-dr344.o
 obj-$(CONFIG_ATH79_MACH_DR531)                 += mach-dr531.o
 obj-$(CONFIG_ATH79_MACH_DRAGINO2)              += mach-dragino2.o
+obj-$(CONFIG_ATH79_MACH_EAP120)                        += mach-eap120.o
 obj-$(CONFIG_ATH79_MACH_EAP300V2)              += mach-eap300v2.o
 obj-$(CONFIG_ATH79_MACH_EAP7660D)              += mach-eap7660d.o
 obj-$(CONFIG_ATH79_MACH_EL_M150)               += mach-el-m150.o
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-eap120.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-eap120.c
new file mode 100644 (file)
index 0000000..130c770
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ *  TP-LINK EAP120 board support
+ *
+ * Copyright (C) 2016 Henryk Heisig <hyniu@o2.pl>
+ *
+ * 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/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/platform_data/mdio-gpio.h>
+#include <asm/mach-ath79/ath79.h>
+#include <asm/mach-ath79/ar71xx_regs.h>
+#include <linux/platform_data/phy-at803x.h>
+
+#include "common.h"
+#include "dev-eth.h"
+#include "dev-gpio-buttons.h"
+#include "dev-leds-gpio.h"
+#include "dev-m25p80.h"
+#include "dev-wmac.h"
+#include "machtypes.h"
+
+
+#define EAP120_GPIO_LED_RED    12
+#define EAP120_GPIO_LED_YEL    13
+#define EAP120_GPIO_LED_GRN    15
+#define EAP120_GPIO_BTN_RESET  4
+
+#define EAP120_KEYS_POLL_INTERVAL      20 /* msecs */
+#define EAP120_KEYS_DEBOUNCE_INTERVAL  (3 * EAP120_KEYS_POLL_INTERVAL)
+
+#define EAP120_GPIO_SMI_MDIO           16
+#define EAP120_GPIO_SMI_MDC            17
+
+#define EAP120_LAN_PHYADDR             4
+
+static struct gpio_led eap120_leds_gpio[] __initdata = {
+       {
+               .name           = "eap120:red:system",
+               .gpio           = EAP120_GPIO_LED_RED,
+               .active_low     = 1,
+       }, {
+               .name           = "eap120:yellow:system",
+               .gpio           = EAP120_GPIO_LED_YEL,
+               .active_low     = 1,
+       }, {
+               .name           = "eap120:green:system",
+               .gpio           = EAP120_GPIO_LED_GRN,
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_button eap120_gpio_keys[] __initdata = {
+       {
+               .desc           = "Reset button",
+               .type           = EV_KEY,
+               .code           = KEY_RESTART,
+               .debounce_interval = EAP120_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = EAP120_GPIO_BTN_RESET,
+               .active_low     = 1,
+       }
+};
+
+static struct mdio_gpio_platform_data eap120_mdio = {
+       .mdc            = EAP120_GPIO_SMI_MDC,
+       .mdio           = EAP120_GPIO_SMI_MDIO,
+       .phy_mask       = ~BIT(EAP120_LAN_PHYADDR),
+};
+
+static struct at803x_platform_data eap120_ar8035_data = {
+       .disable_smarteee = 0,
+       .enable_rgmii_rx_delay = 1,
+       .enable_rgmii_tx_delay = 0,
+       .fixup_rgmii_tx_delay = 1,
+};
+
+static struct platform_device eap120_phy_device = {
+       .name   = "mdio-gpio",
+       .id     = 0,
+       .dev    = {
+               .platform_data = &eap120_mdio, &eap120_ar8035_data
+       },
+};
+
+static void __init eap_setup(u8 *mac)
+{
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(eap120_leds_gpio),
+                                eap120_leds_gpio);
+
+       ath79_register_gpio_keys_polled(1, EAP120_KEYS_POLL_INTERVAL,
+                                       ARRAY_SIZE(eap120_gpio_keys),
+                                       eap120_gpio_keys);
+
+       ath79_register_m25p80(NULL);
+
+       /* MDIO Interface */
+       platform_device_register(&eap120_phy_device);
+       ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
+
+       /* GMAC0 is connected to the RGMII interface to an Atheros AR8035-A */
+       ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
+       ath79_eth0_data.mii_bus_dev = &eap120_phy_device.dev;
+       ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
+       ath79_eth0_data.phy_mask = BIT(EAP120_LAN_PHYADDR);
+       ath79_eth0_pll_data.pll_1000 = 0x0e000000;
+       ath79_eth0_pll_data.pll_100 = 0x00000101;
+       ath79_eth0_pll_data.pll_10 = 0x00001313;
+       ath79_register_eth(0);
+}
+
+static void __init eap120_setup(void)
+{
+       u8 *mac = (u8 *) KSEG1ADDR(0x1f030008);
+       u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
+
+       eap_setup(mac);
+
+       ath79_register_wmac(ee, mac);
+}
+
+MIPS_MACHINE(ATH79_MACH_EAP120, "EAP120", "TP-LINK EAP120",
+               eap120_setup);
+
index 8835b97bd07a5f199e2332493489890efd7418d6..aa8215bbeb7c0b9c533eaccda8697cbc46fc0344 100644 (file)
@@ -75,6 +75,7 @@ enum ath79_mach_type {
        ATH79_MACH_DR344,                       /* Wallys DR344 */
        ATH79_MACH_DR531,                       /* Wallys DR531 */
        ATH79_MACH_DRAGINO2,                    /* Dragino Version 2 */
+       ATH79_MACH_EAP120,                      /* TP-LINK EAP120 */
        ATH79_MACH_EAP300V2,                    /* EnGenius EAP300 v2 */
        ATH79_MACH_EAP7660D,                    /* Senao EAP7660D */
        ATH79_MACH_EL_M150,                     /* EasyLink EL-M150 */
index c4cd25ffb843825d01b5e1dd031887d4d0473a0b..355955598570f5a80cd9797743eb4868fa4fb115 100644 (file)
@@ -109,6 +109,21 @@ $(Device/cpe510-520)
 endef
 TARGET_DEVICES += cpe210-220 cpe510-520
 
+define Device/eap120
+  DEVICE_TITLE := TP-LINK EAP120
+  MTDPARTS := spi0.0:128k(u-boot)ro,64k(pation-table)ro,64k(product-info)ro,1536k(kernel),14336k(rootfs),192k(config)ro,64k(ART)ro,15872k@0x40000(firmware)
+  IMAGE_SIZE := 15872k
+  BOARDNAME := EAP120
+  TPLINK_BOARD_NAME := EAP120
+  DEVICE_PROFILE := EAP120
+  LOADER_TYPE := elf
+  KERNEL := kernel-bin | patch-cmdline | lzma | loader-kernel
+  IMAGES := sysupgrade.bin factory.bin
+  IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade
+  IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
+endef
+TARGET_DEVICES += eap120
+
 define Device/tl-wdr4300-v1
 $(Device/tplink-8mlzma)
   DEVICE_TITLE := TP-LINK TL-WDR4300 v1
index 4938f74eecd122265072390e1c6b8cadb09844d0..fdf93d75d5052bbaa3eb9016b0e0f6a2ad4b7921 100644 (file)
@@ -108,6 +108,9 @@ static const char cpe510_vendor[] = "CPE510(TP-LINK|UN|N300-5):1.0\r\n";
 /** Vendor information for C2600 */
 static const char c2600_vendor[] = "";
 
+/** Vendor information for EAP120 */
+static const char eap120_vendor[] = "EAP120(TP-LINK|UN|N300-2):1.0\r\n";
+
 /**
     The flash partition table for CPE210/220/510/520;
     it is the same as the one used by the stock images.
@@ -162,6 +165,25 @@ static const struct flash_partition_entry c2600_partitions[] = {
        {NULL, 0, 0}
 };
 
+/**    The flash partition table for EAP120;
+    it is the same as the one used by the stock images.
+*/
+static const struct flash_partition_entry eap120_partitions[] = {
+       {"fs-uboot", 0x00000, 0x20000},
+       {"partition-table", 0x20000, 0x02000},
+       {"default-mac", 0x30000, 0x00020},
+       {"support-list", 0x31000, 0x00100},
+       {"product-info", 0x31100, 0x00100},
+       {"soft-version", 0x32000, 0x00100},
+       {"os-image", 0x40000, 0x180000},
+       {"file-system", 0x1c0000, 0x600000},
+       {"user-config", 0x7c0000, 0x10000},
+       {"backup-config", 0x7d0000, 0x10000},
+       {"log", 0x7e0000, 0x10000},
+       {"radio", 0x7f0000, 0x10000},
+       {NULL, 0, 0}
+};
+
 /**
    The support list for CPE210/220
 */
@@ -188,6 +210,13 @@ static const char c2600_support_list[] =
        "SupportList:\r\n"
        "{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n";
 
+/**
+   The support list for EAP120
+*/
+static const char eap120_support_list[] =
+       "SupportList:\r\n"
+       "EAP120(TP-LINK|UN|N300-2):1.0\r\n";
+
 #define error(_ret, _errno, _str, ...)                         \
        do {                                                    \
                fprintf(stderr, _str ": %s\n", ## __VA_ARGS__,  \
@@ -514,6 +543,37 @@ static void * generate_sysupgrade_image_c2600(const struct flash_partition_entry
 
        return image;
 }
+static void *generate_sysupgrade_image_eap120(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len)
+{
+       const struct flash_partition_entry *flash_os_image = &flash_parts[6];
+       const struct flash_partition_entry *flash_file_system = &flash_parts[7];
+
+       const struct image_partition_entry *image_os_image = &image_parts[3];
+       const struct image_partition_entry *image_file_system = &image_parts[4];
+
+       assert(strcmp(flash_os_image->name, "os-image") == 0);
+       assert(strcmp(flash_file_system->name, "file-system") == 0);
+
+       assert(strcmp(image_os_image->name, "os-image") == 0);
+       assert(strcmp(image_file_system->name, "file-system") == 0);
+
+       if (image_os_image->size > flash_os_image->size)
+               error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
+       if (image_file_system->size > flash_file_system->size)
+               error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
+
+       *len = flash_file_system->base - flash_os_image->base + image_file_system->size;
+
+       uint8_t *image = malloc(*len);
+       if (!image)
+               error(1, errno, "malloc");
+
+       memset(image, 0xff, *len);
+       memcpy(image, image_os_image->data, image_os_image->size);
+       memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
+
+       return image;
+}
 
 /** Generates an image for CPE210/220/510/520 and writes it to a file */
 static void do_cpe(const char *output,
@@ -588,6 +648,45 @@ static void do_c2600(const char *output, const char *kernel_image, const char *r
 }
 
 
+/** Generates an image for EAP120 and writes it to a file */
+static void do_eap(const char *output,
+               const char *kernel_image,
+               const char *rootfs_image,
+               uint32_t rev,
+               bool add_jffs2_eof,
+               bool sysupgrade,
+               const char *support_list) {
+       struct image_partition_entry parts[6] = {};
+
+       parts[0] = make_partition_table(eap120_partitions);
+       parts[1] = make_soft_version(rev);
+       parts[2] = make_support_list(support_list, false);
+       parts[3] = read_file("os-image", kernel_image, false);
+       parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
+
+       size_t len;
+       void *image;
+       if (sysupgrade)
+               image = generate_sysupgrade_image_eap120(eap120_partitions, parts, &len);
+       else
+               image = generate_factory_image(eap120_vendor, parts, &len);
+
+       FILE *file = fopen(output, "wb");
+       if (!file)
+               error(1, errno, "unable to open output file");
+
+       if (fwrite(image, len, 1, file) != 1)
+               error(1, 0, "unable to write output file");
+
+       fclose(file);
+
+       free(image);
+
+       size_t i;
+       for (i = 0; parts[i].name; i++)
+               free_image_partition(parts[i]);
+}
+
 /** Usage output */
 static void usage(const char *argv0) {
        fprintf(stderr,
@@ -673,6 +772,8 @@ int main(int argc, char *argv[]) {
                do_cpe(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, cpe510_support_list);
        else if (strcmp(board, "C2600") == 0)
                do_c2600(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
+       else if (strcmp(board, "EAP120") == 0)
+               do_eap(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade, eap120_support_list);
        else
                error(1, 0, "unsupported board %s", board);