Skip to content

Commit

Permalink
move k2t support in ar71xx
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsnowwolf committed Jan 2, 2019
1 parent 05f9b24 commit d24aebd
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 0 deletions.
5 changes: 5 additions & 0 deletions target/linux/ar71xx/base-files/etc/board.d/01_leds
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions target/linux/ar71xx/base-files/etc/board.d/02_network
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions target/linux/ar71xx/base-files/etc/diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
;;
*)
Expand Down
5 changes: 5 additions & 0 deletions target/linux/ar71xx/base-files/lib/ar71xx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions target/linux/ar71xx/base-files/lib/upgrade/platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions target/linux/ar71xx/config-4.14
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions target/linux/ar71xx/files/arch/mips/ath79/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
133 changes: 133 additions & 0 deletions target/linux/ar71xx/files/arch/mips/ath79/mach-k2t.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

/*
* Phicomm K2T A1/A2/A3 reference board support
*
* Copyright (c) 2018 Chen Minqiang <[email protected]>
*
* 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 <linux/platform_device.h>
#include <linux/ath9k_platform.h>
#include <linux/ar8216_platform.h>
#include <asm/mach-ath79/ar71xx_regs.h>

#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);
1 change: 1 addition & 0 deletions target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions target/linux/ar71xx/generic/config-default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions target/linux/ar71xx/image/generic.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d24aebd

Please sign in to comment.