From 7e21ce8e2b0b73f145af96958511f761544942d7 Mon Sep 17 00:00:00 2001
From: Sven Hauer <sven.hauer+github@uniku.de>
Date: Mon, 27 Jun 2022 22:25:12 +0200
Subject: [PATCH] ath79: support for TP-Link EAP225 v4
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This model is almost identical to the EAP225 v3.
Major difference is the RTL8211FS PHY Chipset.

Device specifications:
* SoC: QCA9563 @ 775MHz
* RAM: 128MiB DDR2
* Flash: 16MiB SPI-NOR
* Wireless 2.4GHz (SoC): b/g/n, 3x3
* Wireless 5Ghz (QCA9886): a/n/ac, 2x2 MU-MIMO
* Ethernet (RTL8211FS): 1× 1GbE, 802.3at PoE

Flashing instructions:
* ssh into target device and run `cliclientd stopcs`
* Upgrade with factory image via web interface

Debricking:
* Serial port can be soldered on PCB J4 (1: TXD, 2: RXD, 3: GND, 4: VCC)
    * Bridge unpopulated resistors R225 (TXD) and R237 (RXD).
      Do NOT bridge R230.
    * Use 3.3V, 115200 baud, 8n1
* Interrupt bootloader by holding CTRL+B during boot
* tftp initramfs to flash via LuCI web interface
    setenv ipaddr 192.168.1.1 # default, change as required
    setenv serverip 192.168.1.10 # default, change as required
    tftp 0x80800000 initramfs.bin
    bootelf $fileaddr

MAC addresses:
MAC address (as on device label) is stored in device info partition at
an offset of 8 bytes. ath9k device has same address as ethernet, ath10k
uses address incremented by 1.

Signed-off-by: Sven Hauer <sven.hauer+github@uniku.de>
---
 .../ath79/dts/qca9563_tplink_eap225-v4.dts    | 59 +++++++++++++++++++
 .../generic/base-files/etc/board.d/02_network |  1 +
 target/linux/ath79/image/generic-tp-link.mk   | 11 ++++
 3 files changed, 71 insertions(+)
 create mode 100644 target/linux/ath79/dts/qca9563_tplink_eap225-v4.dts

diff --git a/target/linux/ath79/dts/qca9563_tplink_eap225-v4.dts b/target/linux/ath79/dts/qca9563_tplink_eap225-v4.dts
new file mode 100644
index 00000000000..ae27ff70684
--- /dev/null
+++ b/target/linux/ath79/dts/qca9563_tplink_eap225-v4.dts
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "qca9563_tplink_eap2x5-1port.dtsi"
+
+/ {
+	compatible = "tplink,eap225-v4", "qca,qca9563";
+	model = "TP-Link EAP225 v4";
+
+	aliases {
+		led-boot = &led_status_green;
+		led-failsafe = &led_status_amber;
+		led-running = &led_status_green;
+		led-upgrade = &led_status_amber;
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led_status_green: status_green {
+			label = "green:status";
+			gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
+			default-state = "on";
+		};
+
+		led_status_amber: status_amber {
+			label = "amber:status";
+			gpios = <&gpio 9 GPIO_ACTIVE_HIGH>;
+		};
+	};
+};
+
+&art {
+	precalibration_ath10k: pre-calibration@5000 {
+		reg = <0x5000 0x2f20>;
+	};
+};
+
+&eth0 {
+	phy-handle = <&phy6>;
+	phy-mode = "sgmii";
+};
+
+&mdio0 {
+	phy6: ethernet-phy@6 {
+		reg = <6>;
+	};
+};
+
+&pcie {
+	wifi@0,0 {
+		compatible = "qcom,ath10k";
+		reg = <0 0 0 0 0>;
+
+		mac-address-increment = <1>;
+
+		nvmem-cells = <&macaddr_info_8>, <&precalibration_ath10k>;
+		nvmem-cell-names = "mac-address", "pre-calibration";
+	};
+};
diff --git a/target/linux/ath79/generic/base-files/etc/board.d/02_network b/target/linux/ath79/generic/base-files/etc/board.d/02_network
index 42ab19b47a6..7ba39c4c496 100644
--- a/target/linux/ath79/generic/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network
@@ -79,6 +79,7 @@ ath79_setup_interfaces()
 	tplink,eap225-outdoor-v3|\
 	tplink,eap225-v1|\
 	tplink,eap225-v3|\
+	tplink,eap225-v4|\
 	tplink,eap245-v1|\
 	tplink,re350k-v1|\
 	tplink,re355-v1|\
diff --git a/target/linux/ath79/image/generic-tp-link.mk b/target/linux/ath79/image/generic-tp-link.mk
index ffe999660ac..6d9ba2cd403 100644
--- a/target/linux/ath79/image/generic-tp-link.mk
+++ b/target/linux/ath79/image/generic-tp-link.mk
@@ -434,6 +434,17 @@ define Device/tplink_eap225-v3
 endef
 TARGET_DEVICES += tplink_eap225-v3
 
+define Device/tplink_eap225-v4
+  $(Device/tplink-eap2x5)
+  SOC := qca9563
+  IMAGE_SIZE := 13824k
+  DEVICE_MODEL := EAP225
+  DEVICE_VARIANT := v4
+  DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca9888-ct
+  TPLINK_BOARD_ID := EAP225-V3
+endef
+TARGET_DEVICES += tplink_eap225-v4
+
 define Device/tplink_eap225-wall-v2
   $(Device/tplink-eap2x5)
   SOC := qca9561