From 3ddd1b6e78ab565c6210663df6cd0c1a2a9afac6 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Tue, 14 Sep 2021 17:03:50 +0200
Subject: [PATCH] mt7621: add linksys ea6350 and ea7200 support

Signed-off-by: John Crispin <john@phrozen.org>
---
 package/boot/uboot-envtools/files/ramips      |  2 +
 .../ramips/dts/mt7621_linksys_ea6350-v4.dts   | 57 +++++++++++++++++++
 .../ramips/dts/mt7621_linksys_ea7200.dts      | 57 +++++++++++++++++++
 .../ramips/dts/mt7621_linksys_ea7xxx.dtsi     | 19 +------
 target/linux/ramips/image/mt7621.mk           | 17 ++++++
 .../mt7621/base-files/etc/board.d/02_network  |  8 ++-
 .../mt7621/base-files/lib/upgrade/platform.sh |  2 +
 7 files changed, 143 insertions(+), 19 deletions(-)
 create mode 100644 target/linux/ramips/dts/mt7621_linksys_ea6350-v4.dts
 create mode 100644 target/linux/ramips/dts/mt7621_linksys_ea7200.dts

diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips
index 0de062bd83..c711cc0a12 100644
--- a/package/boot/uboot-envtools/files/ramips
+++ b/package/boot/uboot-envtools/files/ramips
@@ -51,6 +51,8 @@ ravpower,rp-wd03)
 jcg,q20)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
 	;;
+linksys,ea6350-v4|\
+linksys,ea7200|\
 linksys,ea7300-v1|\
 linksys,ea7300-v2|\
 linksys,ea7500-v2|\
diff --git a/target/linux/ramips/dts/mt7621_linksys_ea6350-v4.dts b/target/linux/ramips/dts/mt7621_linksys_ea6350-v4.dts
new file mode 100644
index 0000000000..12378e61bc
--- /dev/null
+++ b/target/linux/ramips/dts/mt7621_linksys_ea6350-v4.dts
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "mt7621_linksys_ea7xxx.dtsi"
+
+/ {
+	compatible = "linksys,ea6350-v4", "mediatek,mt7621-soc";
+	model = "Linksys EA6350 v4";
+
+	keys {
+		/delete-node/ wps;
+
+		wps {
+			label = "wps";
+			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+			linux,code = <KEY_WPS_BUTTON>;
+		};
+	};
+
+	leds {
+		/delete-node/ wan_green;
+		/delete-node/ lan1_green;
+		/delete-node/ lan2_green;
+		/delete-node/ lan3_green;
+		/delete-node/ lan4_green;
+		/delete-node/ wps;
+	};
+};
+
+&pcie1 {
+	mt76@0,0 {
+		ieee80211-freq-limit = <5000000 6000000>;
+	};
+};
+
+&switch0 {
+	ports {
+		port@0 {
+			label = "lan1";
+		};
+
+		port@1 {
+			label = "lan2";
+		};
+
+		port@2 {
+			label = "lan3";
+		};
+
+		port@3 {
+			label = "lan4";
+		};
+
+		port@4 {
+			label = "wan";
+		};
+	};
+};
diff --git a/target/linux/ramips/dts/mt7621_linksys_ea7200.dts b/target/linux/ramips/dts/mt7621_linksys_ea7200.dts
new file mode 100644
index 0000000000..c9eb7a7bba
--- /dev/null
+++ b/target/linux/ramips/dts/mt7621_linksys_ea7200.dts
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "mt7621_linksys_ea7xxx.dtsi"
+
+/ {
+	compatible = "linksys,ea7200", "mediatek,mt7621-soc";
+	model = "Linksys EA6350 v4";
+
+	keys {
+		/delete-node/ wps;
+
+		wps {
+			label = "wps";
+			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+			linux,code = <KEY_WPS_BUTTON>;
+		};
+	};
+
+	leds {
+		/delete-node/ wan_green;
+		/delete-node/ lan1_green;
+		/delete-node/ lan2_green;
+		/delete-node/ lan3_green;
+		/delete-node/ lan4_green;
+		/delete-node/ wps;
+	};
+};
+
+&pcie1 {
+	mt76@0,0 {
+		ieee80211-freq-limit = <5000000 6000000>;
+	};
+};
+
+&switch0 {
+	ports {
+		port@0 {
+			label = "lan1";
+		};
+
+		port@1 {
+			label = "lan2";
+		};
+
+		port@2 {
+			label = "lan3";
+		};
+
+		port@3 {
+			label = "lan4";
+		};
+
+		port@4 {
+			label = "wan";
+		};
+	};
+};
diff --git a/target/linux/ramips/dts/mt7621_linksys_ea7xxx.dtsi b/target/linux/ramips/dts/mt7621_linksys_ea7xxx.dtsi
index ecff6406d5..86878e6e1b 100644
--- a/target/linux/ramips/dts/mt7621_linksys_ea7xxx.dtsi
+++ b/target/linux/ramips/dts/mt7621_linksys_ea7xxx.dtsi
@@ -82,15 +82,14 @@
 		#size-cells = <1>;
 
 		partition@0 {
-			label = "boot";
+			label = "u-boot";
 			reg = <0x0 0x80000>;
 			read-only;
 		};
 
 		partition@80000 {
-			label = "u_env";
+			label = "u-boot-env";
 			reg = <0x80000 0x40000>;
-			read-only;
 		};
 
 		factory: partition@c0000 {
@@ -117,19 +116,7 @@
 
 		partition@580000 {
 			label = "ubi";
-			reg = <0x580000 0x2400000>;
-		};
-
-		partition@2980000 {
-			label = "alt_kernel";
-			reg = <0x2980000 0x400000>;
-			read-only;
-		};
-
-		partition@2d80000 {
-			label = "alt_rootfs";
-			reg = <0x2d80000 0x2400000>;
-			read-only;
+			reg = <0x580000 0x4c00000>;
 		};
 
 		partition@5180000 {
diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index 6e0b9b5f76..eebd49d86c 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -829,6 +829,23 @@ define Device/linksys_ea7xxx
 	append-ubi | check-size | linksys-image type=$$$$(LINKSYS_HWNAME)
 endef
 
+define Device/linksys_ea6350-v4
+  $(Device/linksys_ea7xxx)
+  DEVICE_MODEL := EA6350
+  DEVICE_VARIANT := v4
+  LINKSYS_HWNAME := EA6350v4
+  DEVICE_PACKAGES += kmod-mt7603 kmod-mt7663-firmware-ap
+endef
+TARGET_DEVICES += linksys_ea6350-v4
+
+define Device/linksys_ea7200
+  $(Device/linksys_ea7xxx)
+  DEVICE_MODEL := EA7200
+  LINKSYS_HWNAME := EA7200
+  DEVICE_PACKAGES += kmod-mt7603 kmod-mt7663-firmware-ap
+endef
+TARGET_DEVICES += linksys_ea7200
+
 define Device/linksys_ea7300-v1
   $(Device/linksys_ea7xxx)
   DEVICE_MODEL := EA7300
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
index 1c4e29dd97..53910135cc 100755
--- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
@@ -142,13 +142,15 @@ ramips_setup_macs()
 		label_mac=$(mtd_get_mac_binary factory 0x4)
 		;;
 	linksys,e5600|\
+	linksys,ea6350-v4|\
+	linksys,ea7200|\
 	linksys,ea7300-v1|\
 	linksys,ea7300-v2|\
 	linksys,ea7500-v2|\
 	linksys,ea8100-v1)
-		lan_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
-		wan_mac=$lan_mac
-		label_mac=$lan_mac
+		label_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
+		lan_mac=$(macaddr_add $label_mac 1)
+		wan_mac=$label_mac
 		;;
 	mikrotik,routerboard-750gr3|\
 	mikrotik,routerboard-760igs|\
diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
index acaa62d171..1f1ecb33d9 100755
--- a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
@@ -59,6 +59,8 @@ platform_do_upgrade() {
 	hiwifi,hc5962|\
 	jcg,q20|\
 	linksys,e5600|\
+	linksys,ea6350-v4|\
+	linksys,ea7200|\
 	linksys,ea7300-v1|\
 	linksys,ea7300-v2|\
 	linksys,ea7500-v2|\
-- 
2.25.1

