From abd6918dc1af8d411aacc333bbddbfdcce25d439 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Wed, 20 Apr 2022 09:13:33 +0200
Subject: [PATCH 01/35] ramips: add mt7621_indio_um-305ax

Signed-off-by: John Crispin <john@phrozen.org>
---
 .../ramips/dts/mt7621_indio_um-305ax.dts      | 146 ++++++++++++++++++
 target/linux/ramips/image/mt7621.mk           |  12 ++
 .../mt7621/base-files/etc/board.d/02_network  |   6 +
 .../etc/hotplug.d/ieee80211/10_fix_wifi_mac   |   6 +
 target/linux/ramips/mt7621/config-5.4         |  11 +-
 5 files changed, 176 insertions(+), 5 deletions(-)
 create mode 100644 target/linux/ramips/dts/mt7621_indio_um-305ax.dts

diff --git a/target/linux/ramips/dts/mt7621_indio_um-305ax.dts b/target/linux/ramips/dts/mt7621_indio_um-305ax.dts
new file mode 100644
index 0000000000..79cffbdec2
--- /dev/null
+++ b/target/linux/ramips/dts/mt7621_indio_um-305ax.dts
@@ -0,0 +1,146 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "mt7621.dtsi"
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+
+/ {
+	compatible = "indio,um-305ax", "mediatek,mt7621-soc";
+	model = "INDIO UM-305AX";
+
+	aliases {
+		led-boot = &led_green;
+		led-failsafe = &led_red;
+		led-running = &led_blue;
+		led-upgrade = &led_red;
+		label-mac-device = &wan_port;
+	};
+
+	chosen {
+		bootargs = "console=ttyS0,115200";
+		bootargs-override = "console=ttyS0,115200";
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led_blue: blue {
+			label = "blue";
+			gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
+			default-state = "off";
+		};
+
+		led_red: red {
+			label = "red";
+			gpios = <&gpio 23 GPIO_ACTIVE_LOW>;
+			default-state = "off";
+		};
+
+		led_green: green {
+			label = "green";
+			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
+		};
+	};
+
+	keys {
+		compatible = "gpio-keys-polled";
+		poll-interval = <50>;
+		pinctrl-names = "default";
+
+		reset {
+			label = "reset";
+			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+			linux,code = <KEY_RESTART>;
+		};
+	};
+};
+
+&state_default {
+	gpio {
+		groups = "rgmii2";
+		function = "gpio";
+	};
+};
+
+&pcie {
+	status = "okay";
+};
+
+&pcie1 {
+	wifi@0,0 {
+		reg = <0x0 0 0 0 0>;
+		mediatek,mtd-eeprom = <&factory 0x0>;
+	};
+};
+
+&gmac0 {
+	mtd-mac-address = <&factory 0x4>;
+};
+
+&switch0 {
+	ports {
+		wan_port: port@0 {
+			status = "okay";
+			label = "wan";
+			mtd-mac-address = <&factory 0x28>;
+		};
+
+		port@1 {
+			status = "okay";
+			label = "lan";
+		};
+	};
+};
+
+&spi0 {
+	status = "okay";
+
+	flash@0 {
+		compatible = "jedec,spi-nor";
+		reg = <0>;
+		spi-max-frequency = <50000000>;
+
+		partitions {
+			compatible = "fixed-partitions";
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			partition@0 {
+				label = "u-boot";
+				reg = <0x0 0x30000>;
+				read-only;
+			};
+
+			partition@30000 {
+				label = "u-boot-env";
+				reg = <0x30000 0x10000>;
+				read-only;
+			};
+
+			partition@40000 {
+				label = "product";
+				reg = <0x40000 0x10000>;
+				read-only;
+			};
+
+			factory: partition@50000 {
+				label = "factory";
+				reg = <0x50000 0x40000>;
+				read-only;
+			};
+			partition@90000 {
+				compatible = "denx,fit";
+				label = "firmware";
+				reg = <0x90000 0xf60000>;
+			};
+
+		        partition@ff0000 {
+                                 label = "certificates";
+                                 reg = <0xff0000 0x10000>;
+                       };
+
+		};
+	};
+};
+
diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index 81ef6bbd14..9e1eed024b 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -1736,3 +1736,15 @@ define Device/zyxel_wap6805
   IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
 endef
 TARGET_DEVICES += zyxel_wap6805
+
+define Device/indio_um-305ax
+  $(Device/dsa-migration)
+  DEVICE_VENDOR := INDIO
+  DEVICE_MODEL := UM-305AX
+  DEVICE_DTS_CONFIG := config@1
+  DEVICE_PACKAGES += kmod-mt7915e
+  KERNEL := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb
+  IMAGE_SIZE := 15774k
+endef
+TARGET_DEVICES += indio_um-305ax
+
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 b88fac6f59..c0a6bc884a 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
@@ -33,6 +33,7 @@ ramips_setup_interfaces()
 		;;
 	actiontec,web7200|\
 	asiarf,ap7621-001|\
+	indio,um-305ax|\
 	winstars,ws-wn583a6)
 		ucidef_set_interfaces_lan_wan "lan" "wan"
 		;;
@@ -173,6 +174,11 @@ ramips_setup_macs()
 		wan_mac=$label_mac
 		lan_mac=$(macaddr_add $label_mac 1)
 		;;
+	indio,um-305ax)
+		label_mac=$(mtd_get_mac_binary factory 0x4)
+		wan_mac=$(macaddr_add $label_mac 1)
+		lan_mac=$label_mac
+		;;
 	esac
 
 	[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
diff --git a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
index 7109a4647e..157e706534 100644
--- a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
+++ b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
@@ -15,6 +15,12 @@ case "$board" in
 		[ "$PHYNBR" = "0" ] && macaddr_add $wan_mac 2 > /sys${DEVPATH}/macaddress
 		[ "$PHYNBR" = "1" ] && macaddr_add $wan_mac 3 > /sys${DEVPATH}/macaddress
 		;;
+	indio,um-305ax)
+		[ "$PHYNBR" = "0" ] && \
+			macaddr_add "$(mtd_get_mac_binary factory 0x4)" 2 > /sys${DEVPATH}/macaddress
+		[ "$PHYNBR" = "1" ] && \
+			macaddr_add "$(mtd_get_mac_binary factory 0x4)" 3 > /sys${DEVPATH}/macaddress
+		;;
 	glinet,gl-mt1300)
 		[ "$PHYNBR" = "1" ] && \
 			macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1 > /sys${DEVPATH}/macaddress
diff --git a/target/linux/ramips/mt7621/config-5.4 b/target/linux/ramips/mt7621/config-5.4
index eada0ff602..809baf5441 100644
--- a/target/linux/ramips/mt7621/config-5.4
+++ b/target/linux/ramips/mt7621/config-5.4
@@ -43,6 +43,7 @@ CONFIG_CRYPTO_AEAD2=y
 CONFIG_CRYPTO_DEFLATE=y
 CONFIG_CRYPTO_HASH2=y
 CONFIG_CRYPTO_HASH_INFO=y
+CONFIG_CRYPTO_LIB_POLY1305_RSIZE=2
 CONFIG_CRYPTO_LZO=y
 CONFIG_CRYPTO_MANAGER=y
 CONFIG_CRYPTO_MANAGER2=y
@@ -53,17 +54,12 @@ CONFIG_DEBUG_PINCTRL=y
 CONFIG_DIMLIB=y
 CONFIG_DMA_NONCOHERENT=y
 CONFIG_DMA_NONCOHERENT_CACHE_SYNC=y
-# CONFIG_DMA_RALINK is not set
 # CONFIG_DTB_GNUBEE1 is not set
 # CONFIG_DTB_GNUBEE2 is not set
 CONFIG_DTB_RT_NONE=y
 CONFIG_DTC=y
 CONFIG_EARLY_PRINTK=y
-CONFIG_EFI_EARLYCON=y
 CONFIG_FIXED_PHY=y
-CONFIG_FONT_8x16=y
-CONFIG_FONT_AUTOSELECT=y
-CONFIG_FONT_SUPPORT=y
 CONFIG_FW_LOADER_PAGED_BUF=y
 CONFIG_GENERIC_ATOMIC64=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -209,6 +205,7 @@ CONFIG_PHYLIB=y
 CONFIG_PHYLINK=y
 # CONFIG_PHY_RALINK_USB is not set
 CONFIG_PINCTRL=y
+CONFIG_PINCTRL_AW9523=y
 CONFIG_PINCTRL_RT2880=y
 # CONFIG_PINCTRL_SINGLE is not set
 CONFIG_PINCTRL_SX150X=y
@@ -222,7 +219,11 @@ CONFIG_RALINK=y
 CONFIG_RATIONAL=y
 CONFIG_RCU_NEED_SEGCBLIST=y
 CONFIG_RCU_STALL_COMMON=y
+CONFIG_REED_SOLOMON=y
+CONFIG_REED_SOLOMON_DEC8=y
+CONFIG_REED_SOLOMON_ENC8=y
 CONFIG_REGMAP=y
+CONFIG_REGMAP_I2C=y
 CONFIG_REGMAP_MMIO=y
 CONFIG_REGULATOR=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
-- 
2.25.1

