From 81f7af48811656dc12c720efda3f88e088d39b2b Mon Sep 17 00:00:00 2001
From: Rasim Kalimullin <neutrino.vm@gmail.com>
Date: Tue, 15 Oct 2019 19:05:17 +0500
Subject: [PATCH] ath79: add support for TP-Link TL-WR1045ND v2

Specifications:
 - QCA9558 Soc
 - 720/800 (CPU/DDR)
 - 1x 10/100/1000 Mbps WAN Ethernet
 - 4x 10/100/1000 Mbps LAN Ethernet
 - 64 MB RAM (DDR2)
 - 8 MB FLASH
 - QCA9558 2.4 GHz 802.11bgn
 - 1x USB 2.0

Flash instruction
WebUI:
Download *-factory.bin image, rename to tp_firmware.bin and upload
it via the firmwary upgrade function of the stock firmware WebUI.

Tftp:
Rename OpenWRT or original firmware to wr1045v2_tp_recovery.bin and
Change your computer ip in 192.168.0.66 and subnet mask in 255.255.255.0.
Router will obtain IP 192.168.0.86 for a few seconds while loading,
when reset button pressed at power On.

Signed-off-by: Rasim Kalimullin <neutrino.vm@gmail.com>
[rebased onto base-files split]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 .../linux/ath79/dts/qca9558_tplink_tl-wr1045nd-v2.dts  |  9 +++++++++
 .../ath79/generic/base-files/etc/board.d/02_network    |  3 ++-
 target/linux/ath79/image/generic-tp-link.mk            | 10 ++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 target/linux/ath79/dts/qca9558_tplink_tl-wr1045nd-v2.dts

diff --git a/target/linux/ath79/dts/qca9558_tplink_tl-wr1045nd-v2.dts b/target/linux/ath79/dts/qca9558_tplink_tl-wr1045nd-v2.dts
new file mode 100644
index 0000000000..879b55549f
--- /dev/null
+++ b/target/linux/ath79/dts/qca9558_tplink_tl-wr1045nd-v2.dts
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/dts-v1/;
+
+#include "qca9558_tplink_tl-wr1043nd.dtsi"
+
+/ {
+	compatible = "tplink,tl-wr1045nd-v2", "qca,qca9557";
+	model = "TP-Link TL-WR1045ND v2";
+};
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 0cf411041d..e4179b4d38 100755
--- a/target/linux/ath79/generic/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network
@@ -239,7 +239,8 @@ ath79_setup_interfaces()
 			"1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
 		;;
 	tplink,tl-wr1043nd-v2|\
-	tplink,tl-wr1043nd-v3)
+	tplink,tl-wr1043nd-v3|\
+	tplink,tl-wr1045nd-v2)
 		ucidef_add_switch "switch0" \
 			"0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
 		;;
diff --git a/target/linux/ath79/image/generic-tp-link.mk b/target/linux/ath79/image/generic-tp-link.mk
index a74172e16d..b272276b9f 100644
--- a/target/linux/ath79/image/generic-tp-link.mk
+++ b/target/linux/ath79/image/generic-tp-link.mk
@@ -440,6 +440,16 @@ define Device/tplink_tl-wr1043n-v5
 endef
 TARGET_DEVICES += tplink_tl-wr1043n-v5
 
+define Device/tplink_tl-wr1045nd-v2
+  $(Device/tplink-8mlzma)
+  ATH_SOC := qca9558
+  DEVICE_MODEL := TL-WR1045ND
+  DEVICE_VARIANT := v2
+  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
+  TPLINK_HWID := 0x10450002
+endef
+TARGET_DEVICES += tplink_tl-wr1045nd-v2
+
 define Device/tplink_tl-wr2543-v1
   $(Device/tplink-8mlzma)
   ATH_SOC := ar7242
-- 
2.30.2