diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds index 0aad77a98..79e6ff40f 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/01_leds +++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds @@ -442,6 +442,11 @@ hornet-ub-x2) ucidef_set_led_wlan "wlan" "WLAN" "alfa:blue:wlan" "phy0tpt" ucidef_set_led_usbdev "usb" "USB" "alfa:blue:usb" "1-1" ;; +k2t) + ucidef_set_led_switch "blue" "WAN(blue)" "$board:blue:lan" "switch0" "0x10" + ucidef_set_led_default "yellow" "STATUS(yellow)" "$board:yellow:lan" "1" + ucidef_set_led_default "red" "RUNNING(red)" "$board:red:lan" "0" + ;; koala) ucidef_set_led_default "power" "POWER" "$board:green:power" "1" ucidef_set_led_wlan "wlan2g" "WLAN 2.4GHz" "$board:yellow:wlan2" "phy1tpt" diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network index 48e3f4428..5d7921c63 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -461,6 +461,10 @@ ar71xx_setup_interfaces() ucidef_add_switch "switch0" \ "0@eth0" "1:lan" "5:wan" "6@eth1" ;; + k2t) + ucidef_add_switch "switch0" \ + "0@eth0" "3:lan:1" "5:lan:2" "4:wan" + ;; nanostation-m-xw) ucidef_add_switch "switch0" \ "0@eth0" "5:lan" "1:wan" @@ -620,6 +624,10 @@ ar71xx_setup_macs() mynet-n750) wan_mac=$(mtd_get_mac_ascii devdata "wanmac") ;; + k2t) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(macaddr_add "$lan_mac" 1) + ;; wlr8100) lan_mac=$(mtd_get_mac_ascii u-boot-env "ethaddr") wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr") diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh index aa3e9d627..5895c10cc 100644 --- a/target/linux/ar71xx/base-files/etc/diag.sh +++ b/target/linux/ar71xx/base-files/etc/diag.sh @@ -267,6 +267,9 @@ get_status_led() { jwap230) status_led="$board:green:led1" ;; + k2t) + status_led="$board:red:lan" + ;; koala) status_led="$board:blue:sys" ;; diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index 94bce7d33..4be6c0cb3 100644 --- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom +++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -79,6 +79,10 @@ case "$FIRMWARE" in fritz450e) ath9k_eeprom_extract_reverse "urlader" 5441 1088 ;; + k2t) + ath9k_eeprom_extract "art" 4096 2048 + ath9k_patch_firmware_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +3) + ;; mr18) . /lib/upgrade/nand.sh diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index e08df23df..bee3eeaff 100644 --- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,5 +1,21 @@ #!/bin/sh +# xor multiple hex values of the same length +xor() { + local val + local ret="0x$1" + local retlen=${#1} + + shift + while [ -n "$1" ]; do + val="0x$1" + ret=$((ret ^ val)) + shift + done + + printf "%0${retlen}x" "$ret" +} + ath10kcal_die() { echo "ath10cal: " "$*" exit 1 @@ -42,6 +58,29 @@ ath10kcal_patch_mac() { macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6 } +ath10kcal_patch_mac_crc() { + local mac=$1 + local mac_offset=6 + local chksum_offset=2 + local xor_mac + local xor_fw_mac + local xor_fw_chksum + + xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) + xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" + + ath10kcal_patch_mac "$mac" && { + xor_mac=${mac//:/} + xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" + + xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) + xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) + + printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ + dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 + } +} + [ -e /lib/firmware/$FIRMWARE ] && exit 0 . /lib/functions.sh @@ -180,6 +219,12 @@ case "$FIRMWARE" in cf-e385ac) ath10kcal_extract "art" 20480 12064 ;; + k2t) + ath10kcal_extract "art" 20480 12064 + ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) +2) + ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ + /lib/firmware/ath10k/QCA9888/hw2.0/board.bin + ;; esac ;; *) diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh index 1fea4dce5..254fe423c 100755 --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh @@ -805,6 +805,11 @@ ar71xx_board_detect() { *"JWAP230") name="jwap230" ;; + *"K2T A1/A2/A3 board") + #fixup: update the machine name + machine=$(echo -n "$machine" | sed "s,A1/A2/A3,$(head -c400 $(find_mtd_chardev config) | grep -o hw_ver.* | cut -d\" -f3),") + name="k2t" + ;; *"Koala") name="koala" ;; diff --git a/target/linux/ar71xx/base-files/lib/preinit/05_set_iface_mac_ar71xx b/target/linux/ar71xx/base-files/lib/preinit/05_set_iface_mac_ar71xx index 7d3e82813..dc69970c8 100644 --- a/target/linux/ar71xx/base-files/lib/preinit/05_set_iface_mac_ar71xx +++ b/target/linux/ar71xx/base-files/lib/preinit/05_set_iface_mac_ar71xx @@ -34,6 +34,10 @@ preinit_set_mac_address() { dir-615-i1) fetch_mac_from_mtd nvram sys_lan_mac sys_wan_mac ;; + k2t) + mac_wan=$(head -c400 $(find_mtd_chardev config) | grep -o wan_mac.* | cut -d\" -f3) + [ -n "$mac_wan" ] && ifconfig eth0 hw ether "$mac_wan" + ;; mr18|\ z1) mac_lan=$(mtd_get_mac_binary_ubi board-config 102) diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh index 1f0d8da6f..cfac33c7c 100755 --- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh @@ -662,6 +662,14 @@ platform_check_image() { cybertan_check_image "$1" && return 0 return 1 ;; + k2t) + [ "$magic_long" != "27051956" ] && { + echo "Invalid image type." + return 1 + } + + return 0 + ;; nbg6616|\ uap-pro|\ unifi-outdoor-plus) diff --git a/target/linux/ar71xx/config-4.14 b/target/linux/ar71xx/config-4.14 index 62dea32a7..001e7b334 100644 --- a/target/linux/ar71xx/config-4.14 +++ b/target/linux/ar71xx/config-4.14 @@ -138,6 +138,7 @@ CONFIG_ATH79=y # CONFIG_ATH79_MACH_JA76PF is not set # CONFIG_ATH79_MACH_JWAP003 is not set # CONFIG_ATH79_MACH_JWAP230 is not set +# CONFIG_ATH79_MACH_K2T is not set # CONFIG_ATH79_MACH_KOALA is not set # CONFIG_ATH79_MACH_LAN_TURTLE is not set # CONFIG_ATH79_MACH_LIMA is not set diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt index 9a8a1deec..3398d4a84 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt +++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt @@ -993,6 +993,15 @@ config ATH79_MACH_JWAP230 select ATH79_DEV_USB select ATH79_DEV_WMAC +config ATH79_MACH_K2T + bool "Phicomm K2T A1/A2/A3 board" + select SOC_QCA956X + select ATH79_DEV_GPIO_BUTTONS + select ATH79_DEV_LEDS_GPIO + select ATH79_DEV_M25P80 + select ATH79_DEV_WMAC + select ATH79_DEV_AP9X_PCI if PCI + config ATH79_MACH_KOALA bool "OCEDO Koala board support" select SOC_QCA955X diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile index a62859275..29a97b780 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile +++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile @@ -148,6 +148,7 @@ obj-$(CONFIG_ATH79_MACH_HORNET_UB) += mach-hornet-ub.o obj-$(CONFIG_ATH79_MACH_JA76PF) += mach-ja76pf.o obj-$(CONFIG_ATH79_MACH_JWAP003) += mach-jwap003.o obj-$(CONFIG_ATH79_MACH_JWAP230) += mach-jwap230.o +obj-$(CONFIG_ATH79_MACH_K2T) += mach-k2t.o obj-$(CONFIG_ATH79_MACH_KOALA) += mach-koala.o obj-$(CONFIG_ATH79_MACH_LAN_TURTLE) += mach-lan-turtle.o obj-$(CONFIG_ATH79_MACH_LIMA) += mach-lima.o diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c new file mode 100644 index 000000000..c8c89e2eb --- /dev/null +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c @@ -0,0 +1,133 @@ + +/* + * Phicomm K2T A1/A2/A3 reference board support + * + * Copyright (c) 2018 Chen Minqiang + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include +#include +#include + +#include "common.h" +#include "dev-m25p80.h" +#include "machtypes.h" +#include "pci.h" +#include "dev-eth.h" +#include "dev-ap9x-pci.h" +#include "dev-gpio-buttons.h" +#include "dev-leds-gpio.h" +#include "dev-spi.h" +#include "dev-wmac.h" + +#define K2T_GPIO_LED_BLUE 6 +#define K2T_GPIO_LED_RED 7 +#define K2T_GPIO_LED_YELLOW 8 + +#define K2T_GPIO_BTN_RESET 2 +#define K2T_KEYS_POLL_INTERVAL 20 /* msecs */ +#define K2T_KEYS_DEBOUNCE_INTERVAL (3 * K2T_KEYS_POLL_INTERVAL) + +#define K2T_MAC0_OFFSET 0 + +static struct gpio_led k2t_leds_gpio[] __initdata = { + { + .name = "k2t:blue:lan", + .gpio = K2T_GPIO_LED_BLUE, + .active_low = 1, + }, + { + .name = "k2t:red:lan", + .gpio = K2T_GPIO_LED_RED, + .active_low = 0, + }, + { + .name = "k2t:yellow:lan", + .gpio = K2T_GPIO_LED_YELLOW, + .active_low = 1, + }, +}; + +static struct gpio_keys_button k2t_gpio_keys[] __initdata = { + { + .desc = "Reset button", + .type = EV_KEY, + .code = KEY_RESTART, + .debounce_interval = K2T_KEYS_DEBOUNCE_INTERVAL, + .gpio = K2T_GPIO_BTN_RESET, + .active_low = 1, + }, +}; + +static struct ar8327_pad_cfg k2t_ar8337_pad0_cfg = { + .mode = AR8327_PAD_MAC_SGMII, + .sgmii_delay_en = true, +}; + +static struct ar8327_platform_data k2t_ar8337_data = { + .pad0_cfg = &k2t_ar8337_pad0_cfg, + .port0_cfg = { + .force_link = 1, + .speed = AR8327_PORT_SPEED_1000, + .duplex = 1, + .txpause = 1, + .rxpause = 1, + }, +}; + +static struct mdio_board_info k2t_mdio0_info[] = { + { + .bus_id = "ag71xx-mdio.0", + .mdio_addr = 0, + .platform_data = &k2t_ar8337_data, + }, +}; + +static void __init k2t_setup(void) +{ + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); + + ath79_register_m25p80(NULL); + + ath79_register_leds_gpio(-1, ARRAY_SIZE(k2t_leds_gpio), + k2t_leds_gpio); + ath79_register_gpio_keys_polled(-1, K2T_KEYS_POLL_INTERVAL, + ARRAY_SIZE(k2t_gpio_keys), + k2t_gpio_keys); + + platform_device_register(&ath79_mdio0_device); + + mdiobus_register_board_info(k2t_mdio0_info, + ARRAY_SIZE(k2t_mdio0_info)); + + ath79_init_mac(ath79_eth0_data.mac_addr, art + K2T_MAC0_OFFSET, 0); + + /* GMAC0 is connected to an AR8337 switch */ + ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII; + ath79_eth0_data.speed = SPEED_1000; + ath79_eth0_data.duplex = DUPLEX_FULL; + ath79_eth0_data.phy_mask = BIT(0); + ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev; + + ath79_register_eth(0); + + ath79_register_wmac_simple(); + ath79_register_pci(); +} + +MIPS_MACHINE(ATH79_MACH_K2T, "K2T", "Phicomm K2T A1/A2/A3 board", + k2t_setup); diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h index 19df432f2..d268e5814 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h @@ -149,6 +149,7 @@ enum ath79_mach_type { ATH79_MACH_JWAP003, /* jjPlus JWAP003 */ ATH79_MACH_JWAP230, /* jjPlus JWAP230 */ ATH79_MACH_KOALA, /* OCEDO Koala */ + ATH79_MACH_K2T, /* Phicomm K2T A1/A2/A3 board */ ATH79_MACH_LAN_TURTLE, /* Hak5 LAN Turtle */ ATH79_MACH_LIMA, /* 8devices Lima */ ATH79_MACH_MC_MAC1200R, /* MERCURY MAC1200R */ diff --git a/target/linux/ar71xx/generic/config-default b/target/linux/ar71xx/generic/config-default index 35f83a271..1b9e36300 100644 --- a/target/linux/ar71xx/generic/config-default +++ b/target/linux/ar71xx/generic/config-default @@ -107,6 +107,7 @@ CONFIG_ATH79_MACH_HORNET_UB=y CONFIG_ATH79_MACH_JA76PF=y CONFIG_ATH79_MACH_JWAP003=y CONFIG_ATH79_MACH_JWAP230=y +CONFIG_ATH79_MACH_K2T=y CONFIG_ATH79_MACH_KOALA=y CONFIG_ATH79_MACH_LAN_TURTLE=y CONFIG_ATH79_MACH_LIMA=y diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk index 8167ad091..bc59dedee 100644 --- a/target/linux/ar71xx/image/generic.mk +++ b/target/linux/ar71xx/image/generic.mk @@ -823,6 +823,18 @@ define Device/jwap230 endef TARGET_DEVICES += jwap230 +define Device/k2t + DEVICE_TITLE := Phicomm K2T + DEVICE_PACKAGES := kmod-ath10k ath10k-firmware-qca9888 + BOARDNAME := K2T + IMAGE_SIZE := 15744k + MTDPARTS := spi0.0:192k(u-boot)ro,64k(config)ro,320k(permanent),15744k(firmware),64k(art)ro + SUPPORTED_DEVICES := k2t + IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | \ + append-rootfs | pad-rootfs | append-metadata | check-size $$$$(IMAGE_SIZE) +endef +TARGET_DEVICES += k2t + define Device/r36a DEVICE_TITLE := ALFA Network R36A DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-ledtrig-usbport -swconfig