From b35683b3cc708c1edd0c729fad781200d92bc54b Mon Sep 17 00:00:00 2001
From: Stijn Segers <foss@volatilesystems.org>
Date: Thu, 29 Sep 2022 23:56:19 +0200
Subject: [PATCH] ramips: mt76x8: add support for TP-Link RE220 v1

---
 .../ramips/dts/mt7628an_tplink_re220-v1.dts   | 65 +++++++++++++++++++
 target/linux/ramips/image/mt76x8.mk           | 10 +++
 .../mt76x8/base-files/etc/board.d/01_leds     |  1 +
 .../mt76x8/base-files/etc/board.d/02_network  |  1 +
 4 files changed, 77 insertions(+)
 create mode 100644 target/linux/ramips/dts/mt7628an_tplink_re220-v1.dts

diff --git a/target/linux/ramips/dts/mt7628an_tplink_re220-v1.dts b/target/linux/ramips/dts/mt7628an_tplink_re220-v1.dts
new file mode 100644
index 0000000000..ad252fd39b
--- /dev/null
+++ b/target/linux/ramips/dts/mt7628an_tplink_re220-v1.dts
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/dts-v1/;
+
+#include "mt7628an_tplink_re200.dtsi"
+
+/ {
+    compatible = "tplink,re220-v1", "mediatek,mt7628an-soc";
+    model = "TP-Link RE220 v1";
+
+    aliases {
+        led-boot = &led_power;
+        led-failsafe = &led_power;
+        led-running = &led_power;
+        led-upgrade = &led_power;
+    };
+
+    leds {
+        compatible = "gpio-leds";
+
+        wps {
+            label = "green:wps";
+            gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
+        };
+
+        wifi {
+            label = "green:wifi";
+            gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+        };
+
+        lan {
+            label = "green:lan";
+            gpios = <&gpio 39 GPIO_ACTIVE_LOW>;
+        };
+
+        led_power: power {
+            label = "green:power";
+            gpios = <&gpio 43 GPIO_ACTIVE_LOW>;
+        };
+
+	wifi2g_green {
+            label = "green:wifi2g";
+            gpios = <&gpio 41 GPIO_ACTIVE_LOW>;
+            linux,default-trigger = "phy0tpt";
+        };
+
+        wifi5g_green {
+            label = "green:wifi5g";
+            gpios = <&gpio 42 GPIO_ACTIVE_LOW>;
+            linux,default-trigger = "phy1tpt";
+        };
+
+        wifi_red {
+            label = "red:wifi";
+            gpios = <&gpio 40 GPIO_ACTIVE_LOW>;
+        };
+    };
+};
+
+&state_default {
+    gpio {
+        groups = "p4led_an", "p3led_an", "p2led_an", "p1led_an",
+                "p0led_an", "wled_an", "i2c", "wdt", "refclk";
+        function = "gpio";
+    };
+};
diff --git a/target/linux/ramips/image/mt76x8.mk b/target/linux/ramips/image/mt76x8.mk
index 5e8d05b042..3e9456d1fa 100644
--- a/target/linux/ramips/image/mt76x8.mk
+++ b/target/linux/ramips/image/mt76x8.mk
@@ -579,6 +579,16 @@ define Device/tplink_re200-v4
 endef
 TARGET_DEVICES += tplink_re200-v4
 
+define Device/tplink_re220-v1
+  $(Device/tplink-safeloader)
+  IMAGE_SIZE := 7808k
+  DEVICE_MODEL := RE220
+  DEVICE_VARIANT := v1
+  DEVICE_PACKAGES := kmod-mt76x0e
+  TPLINK_BOARD_ID := RE220-V1
+endef
+TARGET_DEVICES += tplink_re220-v1
+
 define Device/tplink_re220-v2
   $(Device/tplink-safeloader)
   IMAGE_SIZE := 7808k
diff --git a/target/linux/ramips/mt76x8/base-files/etc/board.d/01_leds b/target/linux/ramips/mt76x8/base-files/etc/board.d/01_leds
index 8a21756225..679664ec35 100644
--- a/target/linux/ramips/mt76x8/base-files/etc/board.d/01_leds
+++ b/target/linux/ramips/mt76x8/base-files/etc/board.d/01_leds
@@ -76,6 +76,7 @@ tplink,archer-c50-v4)
 tplink,re200-v2|\
 tplink,re200-v3|\
 tplink,re200-v4|\
+tplink,re220-v1|\
 tplink,re220-v2|\
 tplink,tl-mr3020-v3|\
 tplink,tl-wa801nd-v5)
diff --git a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
index 38ff38bac5..49f4a3bd41 100644
--- a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
@@ -23,6 +23,7 @@ ramips_setup_interfaces()
 	tplink,re200-v2|\
 	tplink,re200-v3|\
 	tplink,re200-v4|\
+	tplink,re220-v1|\
 	tplink,re220-v2|\
 	tplink,re305-v1|\
 	tplink,re305-v3|\
-- 
2.35.1

