From ad21a419dfa5eeb030b3b5d4136bd939ca158d42 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Sun, 10 Jun 2018 14:45:46 +0800 Subject: [PATCH] fix Phicomm K2T A3 board support --- .../ar71xx/base-files/etc/board.d/02_network | 4 + .../etc/hotplug.d/firmware/10-ath9k-eeprom | 4 + .../etc/hotplug.d/firmware/11-ath10k-caldata | 12 +-- .../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 3 + target/linux/ar71xx/base-files/lib/ar71xx.sh | 8 +- .../lib/preinit/05_set_iface_mac_ar71xx | 8 +- .../base-files/lib/preinit/82_patch_ath9k | 26 ----- .../ar71xx/base-files/lib/upgrade/platform.sh | 16 ++-- .../files/arch/mips/ath79/Kconfig.openwrt | 21 ++--- .../ar71xx/files/arch/mips/ath79/Makefile | 2 +- .../ar71xx/files/arch/mips/ath79/mach-k2t.c | 94 +++++++++---------- .../ar71xx/files/arch/mips/ath79/machtypes.h | 2 +- target/linux/ar71xx/image/generic.mk | 29 +++--- 13 files changed, 107 insertions(+), 122 deletions(-) delete mode 100644 target/linux/ar71xx/base-files/lib/preinit/82_patch_ath9k 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 ae3298aeb..f9f481213 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -298,6 +298,10 @@ ar71xx_setup_interfaces() ucidef_add_switch "switch0" \ "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2" ;; + k2t) + lan_mac=$(head -c400 $(find_mtd_chardev config) | grep -o wan_mac.* | cut -d\" -f3) + wan_mac=$(macaddr_add "$lan_mac" 1) + ;; cr5000|\ dgl-5500-a1|\ dhp-1565-a1|\ 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 41ab43f7c..2a7ac12fe 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 @@ -75,6 +75,10 @@ case "$FIRMWARE" in ath9k_eeprom_extract "art" 4096 2048 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1) ;; + k2t) + ath9k_eeprom_extract "art" 4096 2048 + ath9k_patch_firmware_mac $(macaddr_add $(head -c400 $(find_mtd_chardev config) | grep -o wan_mac.* | cut -d\" -f3) +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 8179e0783..82fc2a7e4 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 @@ -160,12 +160,6 @@ case "$FIRMWARE" in ;; "ath10k/pre-cal-pci-0000:00:00.0.bin") case $board in - k2t) - ath10kcal_extract "art" 20480 12064 - ath10kcal_patch_mac $(macaddr_add $(cat /dev/mtd1 | grep -o wan_mac.* | cut -d\" -f3) +2) - ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ - /lib/firmware/ath10k/QCA9888/hw2.0/board.bin - ;; archer-c58-v1|\ archer-c59-v1|\ archer-c60-v1|\ @@ -179,6 +173,12 @@ case "$FIRMWARE" in cf-e385ac) ath10kcal_extract "art" 20480 12064 ;; + k2t) + ath10kcal_extract "art" 20480 12064 + ath10kcal_patch_mac $(macaddr_add $(head -c400 $(find_mtd_chardev config) | grep -o wan_mac.* | cut -d\" -f3) +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/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ar71xx/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac index a763938ec..3e77a3524 100644 --- a/target/linux/ar71xx/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac +++ b/target/linux/ar71xx/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac @@ -18,6 +18,9 @@ case "$board" in archer-c60-v2) echo $(macaddr_add $(mtd_get_mac_binary mac 8) $(($PHYNBR - 1)) ) > /sys${DEVPATH}/macaddress ;; + k2t) + echo $(macaddr_add $(head -c400 $(find_mtd_chardev config) | grep -o wan_mac.* | cut -d\" -f3) +$((2+$PHYNBR))) > /sys${DEVPATH}/macaddress + ;; *) ;; esac diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh index 9ce4a528b..e8e4202b7 100755 --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh @@ -461,9 +461,6 @@ ar71xx_board_detect() { *"AP152 reference board") name="ap152" ;; - *"Phicomm K2T") - name="k2t" - ;; *"AP531B0") name="ap531b0" ;; @@ -768,6 +765,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 /dev/mtd1 | grep -o hw_ver.* | cut -d\" -f3),") + name="k2t" + ;; *"LAN Turtle") name="lan-turtle" ;; 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 1293ccf6d..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 @@ -22,10 +22,6 @@ preinit_set_mac_address() { . /lib/functions.sh case $(board_name) in - k2t) - mac_wan=$(cat /dev/mtd1 | grep -o wan_mac.* | cut -d\" -f3) - [ -n "$mac_wan" ] && ifconfig eth0 hw ether "$mac_wan" - ;; c-55|\ c-60) mac_lan=$(mtd_get_mac_binary art 0) @@ -38,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/preinit/82_patch_ath9k b/target/linux/ar71xx/base-files/lib/preinit/82_patch_ath9k deleted file mode 100644 index 52c2c4073..000000000 --- a/target/linux/ar71xx/base-files/lib/preinit/82_patch_ath9k +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh -. /lib/functions/system.sh - -do_patch_ath9k_firmware_k2t() { - local current_mac="$(hexdump -v -n 6 -s $((0x1000+2)) -e '5/1 "%02x:" 1/1 "%02x"' /dev/mtd6 2>/dev/null)" - [ "00:02:03:04:05:06" = "$current_mac" ] || return - - local mac=$(macaddr_add $(cat /dev/mtd1 | grep -o wan_mac.* | cut -d\" -f3) +3) - - dd if=/dev/mtd6 of=/tmp/mtd6 && \ - macaddr_2bin $mac | dd of=/tmp/mtd6 conv=notrunc bs=1 seek=$((0x1000+2)) count=6 && \ - mtd write /tmp/mtd6 art - rm -f /tmp/mtd6 -} - -check_patch_ath9k_firmware() { - case $(board_name) in - k2t) - do_patch_ath9k_firmware_k2t - ;; - esac -} - -boot_hook_add preinit_main check_patch_ath9k_firmware diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh index 955322038..b0389cccd 100755 --- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh @@ -323,14 +323,6 @@ platform_check_image() { return 1 } - return 0 - ;; - k2t) - [ "$magic_long" != "27051956" ] && { - echo "Invalid image type." - return 1 - } - return 0 ;; alfa-ap96|\ @@ -638,6 +630,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/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt index 21e660e69..8a256f9dd 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt +++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt @@ -949,6 +949,16 @@ 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_USB + select ATH79_DEV_WMAC + select ATH79_DEV_AP9X_PCI if PCI + config ATH79_MACH_WAM250 bool "Samsung WAM250 support" select SOC_AR934X @@ -2357,14 +2367,3 @@ config ATH79_MACH_FRITZ300E select ATH79_DEV_GPIO_BUTTONS select ATH79_DEV_LEDS_GPIO select ATH79_DEV_M25P80 - -config ATH79_MACH_K2T - bool "Phicomm K2T support" - select SOC_QCA956X - select ATH79_DEV_AP9X_PCI if PCI - select ATH79_DEV_ETH - select ATH79_DEV_GPIO_BUTTONS - select ATH79_DEV_LEDS_GPIO - select ATH79_DEV_M25P80 - select ATH79_DEV_WMAC - select ATH79_DEV_USB diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile index 48ae402ed..09e9d6775 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile +++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile @@ -141,7 +141,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_K2T) += mach-k2t.o obj-$(CONFIG_ATH79_MACH_LAN_TURTLE) += mach-lan-turtle.o obj-$(CONFIG_ATH79_MACH_LIMA) += mach-lima.o obj-$(CONFIG_ATH79_MACH_MC_MAC1200R) += mach-mc-mac1200r.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 index 6c712292e..de57144a6 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c @@ -1,68 +1,68 @@ /* - * Phicomm k2t support + * Phicomm K2T A1/A2/A3 reference board support * - * Copyright (C) 2018 Lean + * 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. * - * 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 -#include -#include #include #include #include -#include - #include #include "common.h" -#include "dev-ap9x-pci.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-m25p80.h" +#include "dev-usb.h" #include "dev-wmac.h" -#include "machtypes.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_GPIO_BTN_RESET 2 +#define K2T_KEYS_POLL_INTERVAL 20 /* msecs */ +#define K2T_KEYS_DEBOUNCE_INTERVAL (3 * K2T_KEYS_POLL_INTERVAL) -#define K2T_KEYS_POLL_INTERVAL 20 /* msecs */ -#define K2T_KEYS_DEBOUNCE_INTERVAL (3 * K2T_KEYS_POLL_INTERVAL) - -#define K2T_LAN_MAC_OFFSET 0 -#define K2T_WAN_MAC_OFFSET 6 -#define K2T_WLAN_MAC_OFFSET 12 -#define K2T_WMAC_CALDATA_OFFSET 0x1000 -#define K2T_PCIE_CALDATA_OFFSET 0x5000 +#define K2T_MAC0_OFFSET 0 static struct gpio_led k2t_leds_gpio[] __initdata = { { - .name = "k2t:blue", + .name = "k2t:blue:lan", .gpio = K2T_GPIO_LED_BLUE, .active_low = 1, }, { - .name = "k2t:red", + .name = "k2t:red:lan", .gpio = K2T_GPIO_LED_RED, - .active_low = 1, + .active_low = 0, }, { - .name = "k2t:yellow", + .name = "k2t:yellow:lan", .gpio = K2T_GPIO_LED_YELLOW, .active_low = 1, - }, + }, }; -static struct gpio_keys_button K2T_GPIO_keys[] __initdata = { +static struct gpio_keys_button k2t_gpio_keys[] __initdata = { { .desc = "Reset button", .type = EV_KEY, @@ -70,16 +70,16 @@ static struct gpio_keys_button K2T_GPIO_keys[] __initdata = { .debounce_interval = K2T_KEYS_DEBOUNCE_INTERVAL, .gpio = K2T_GPIO_BTN_RESET, .active_low = 1, - } + }, }; -static struct ar8327_pad_cfg k2t_qca8337_pad0_cfg = { +static struct ar8327_pad_cfg k2t_ar8337_pad0_cfg = { .mode = AR8327_PAD_MAC_SGMII, .sgmii_delay_en = true, }; -static struct ar8327_platform_data k2t_qca8337_data = { - .pad0_cfg = &k2t_qca8337_pad0_cfg, +static struct ar8327_platform_data k2t_ar8337_data = { + .pad0_cfg = &k2t_ar8337_pad0_cfg, .port0_cfg = { .force_link = 1, .speed = AR8327_PORT_SPEED_1000, @@ -93,45 +93,43 @@ static struct mdio_board_info k2t_mdio0_info[] = { { .bus_id = "ag71xx-mdio.0", .phy_addr = 0, - .platform_data = &k2t_qca8337_data, + .platform_data = &k2t_ar8337_data, }, }; static void __init k2t_setup(void) { u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); - u8 tmpmac[ETH_ALEN]; 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); + ARRAY_SIZE(k2t_gpio_keys), + k2t_gpio_keys); - ath79_init_mac(tmpmac, art + K2T_WLAN_MAC_OFFSET, 0); - ath79_register_wmac(art + K2T_WMAC_CALDATA_OFFSET, tmpmac); + ath79_register_usb(); - ath79_init_mac(tmpmac, art + K2T_WLAN_MAC_OFFSET, 1); - ap91_pci_init(art + K2T_PCIE_CALDATA_OFFSET, tmpmac); + platform_device_register(&ath79_mdio0_device); mdiobus_register_board_info(k2t_mdio0_info, ARRAY_SIZE(k2t_mdio0_info)); - ath79_register_mdio(0, 0x0); - - ath79_init_mac(ath79_eth0_data.mac_addr, art + K2T_LAN_MAC_OFFSET, 0); - /* GMAC0 is connected to a QCA8337 switch SMGII interface*/ + 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", k2t_setup); +MIPS_MACHINE(ATH79_MACH_K2T, "K2T", "Phicomm K2T A1/A2/A3 board", + k2t_setup); \ No newline at end of file diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h index 59f9c4959..1afefb5cf 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h @@ -139,7 +139,7 @@ enum ath79_mach_type { ATH79_MACH_JA76PF2, /* jjPlus JA76PF2 */ ATH79_MACH_JWAP003, /* jjPlus JWAP003 */ ATH79_MACH_JWAP230, /* jjPlus JWAP230 */ - ATH79_MACH_K2T, /* Phicomm K2T */ + 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/image/generic.mk b/target/linux/ar71xx/image/generic.mk index 36c080240..6b95bd2eb 100644 --- a/target/linux/ar71xx/image/generic.mk +++ b/target/linux/ar71xx/image/generic.mk @@ -788,6 +788,21 @@ define Device/jwap230 endef TARGET_DEVICES += jwap230 +define Device/k2t + DEVICE_TITLE := Phicomm K2T A1/A2/A3 board (16MB flash) + DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-storage 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 + KERNEL_INITRAMFS := kernel-bin | patch-cmdline | lzma | uImage lzma + KERNEL_INITRAMFS_SUFFIX := -factory.bin + 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 @@ -1295,17 +1310,3 @@ define Device/fritz300e append-rootfs | pad-rootfs | append-metadata | check-size $$$$(IMAGE_SIZE) endef TARGET_DEVICES += fritz300e - -define Device/k2t - DEVICE_TITLE := Phicomm K2T - DEVICE_PACKAGES := kmod-ath9k kmod-ath10k ath10k-firmware-qca9888 - BOARDNAME := K2T - SUPPORTED_DEVICES := k2t - DEVICE_PROFILE := K2T - IMAGE_SIZE := 15744k - IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) |\ - append-rootfs | pad-rootfs | append-metadata | check-size $$$$(IMAGE_SIZE) - CONSOLE := ttyATH0,115200 - MTDPARTS := spi0.0:192k(u-boot)ro,64k(config)ro,320k(permanent),15744k(firmware),64k(art)ro -endef -TARGET_DEVICES += k2t \ No newline at end of file