From d0740692a0524e3c806558030efa4e1d65f2cc9e Mon Sep 17 00:00:00 2001
From: viktorxda <35473052+viktorxda@users.noreply.github.com>
Date: Thu, 20 Jul 2023 12:57:12 +0200
Subject: [PATCH] Hisilicon: add external mt7601u driver to hi3516ev300
 ultimate (#918)

---
 .../configs/hi3516ev300_ultimate_defconfig    |  3 ++-
 general/overlay/etc/wireless                  | 10 ++++-----
 general/package/Config.in                     |  2 +-
 general/package/mt7601u-ap-openipc/Config.in  |  8 -------
 .../mt7601u-ap-openipc/mt7601u-ap-openipc.mk  | 22 -------------------
 general/package/mt7601u-openipc/Config.in     |  5 +++++
 .../mt7601u-openipc/mt7601u-openipc.mk        | 17 ++++++++++++++
 7 files changed, 30 insertions(+), 37 deletions(-)
 delete mode 100644 general/package/mt7601u-ap-openipc/Config.in
 delete mode 100644 general/package/mt7601u-ap-openipc/mt7601u-ap-openipc.mk
 create mode 100644 general/package/mt7601u-openipc/Config.in
 create mode 100644 general/package/mt7601u-openipc/mt7601u-openipc.mk

diff --git a/br-ext-chip-hisilicon/configs/hi3516ev300_ultimate_defconfig b/br-ext-chip-hisilicon/configs/hi3516ev300_ultimate_defconfig
index bb8c3d7d..43033303 100644
--- a/br-ext-chip-hisilicon/configs/hi3516ev300_ultimate_defconfig
+++ b/br-ext-chip-hisilicon/configs/hi3516ev300_ultimate_defconfig
@@ -109,7 +109,8 @@ BR2_PACKAGE_LINUX_FIRMWARE_OPENIPC=y
 BR2_PACKAGE_LINUX_FIRMWARE_OPENIPC_MEDIATEK_MT7601U=y
 BR2_PACKAGE_LINUX_FIRMWARE_OPENIPC_RTL_8188EU=y
 # BR2_PACKAGE_RTL8188EU is not set
-BR2_PACKAGE_RTL8188FU_OPENIPC=y
+BR2_PACKAGE_RTL8188FU=y
+BR2_PACKAGE_MT7601U_OPENIPC=y
 
 # WIREGUARD
 BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y
diff --git a/general/overlay/etc/wireless b/general/overlay/etc/wireless
index 9a6b200d..9d1f7a42 100755
--- a/general/overlay/etc/wireless
+++ b/general/overlay/etc/wireless
@@ -35,7 +35,7 @@ fi
 if [ "$1" = "mt7601u-hi3516ev300-camhi" ]; then
 	devmem 0x100C0080 32 0x530
 	set_gpio 7 0
-	modprobe mt7601u
+	modprobe mt7601sta
 	exit 0
 fi
 
@@ -104,7 +104,7 @@ if [ "$1" = "l716-t31-camhi" ]; then
 	exit 0
 fi
 
-# T31 ATBM603X on SDIO bus mmc0
+# T31 ATBM603X mmc0
 if [ "$1" = "atbm603x-t31-mmc0" ]; then
 	# PB10 in wifi mmc1 is in the pull-down state by default, it needs to be set to a high-impedance state
 	devmem 0x10011128 32 0x400
@@ -119,12 +119,12 @@ if [ "$1" = "atbm603x-t31-mmc0" ]; then
 
 	cp /usr/share/atbm603x_conf/atbm_txpwer_dcxo_cfg.txt /tmp
 	cp /usr/share/atbm603x_conf/set_rate_power.txt /tmp
-	# note, let this run on the background because if the firmware fails to load, it'll stall the OS startup
+
 	modprobe atbm603x_wifi_sdi0
 	exit 0
 fi
 
-# T31 ATBM603X on SDIO bus mmc1
+# T31 ATBM603X mmc1
 if [ "$1" = "atbm603x-t31-mmc1" ]; then
 	# not sure what this does, but it's copied from the stock fw
 	devmem 0x10011110 32 0x6e094800
@@ -137,7 +137,7 @@ if [ "$1" = "atbm603x-t31-mmc1" ]; then
 
 	cp /usr/share/atbm603x_conf/atbm_txpwer_dcxo_cfg.txt /tmp
 	cp /usr/share/atbm603x_conf/set_rate_power.txt /tmp
-	# note, let this run on the background because if the firmware fails to load, it'll stall the OS startup
+
 	modprobe atbm603x_wifi_sdi1
 	exit 0
 fi
diff --git a/general/package/Config.in b/general/package/Config.in
index f88839e7..bbd05615 100644
--- a/general/package/Config.in
+++ b/general/package/Config.in
@@ -64,7 +64,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/microsnander/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/mini/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/mini-snmpd-openipc/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/motors/Config.in"
-source "$BR2_EXTERNAL_GENERAL_PATH/package/mt7601u-ap-openipc/Config.in"
+source "$BR2_EXTERNAL_GENERAL_PATH/package/mt7601u-openipc/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/nabto/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/node-exporter/Config.in"
 source "$BR2_EXTERNAL_GENERAL_PATH/package/novatek-osdrv-nt9856x/Config.in"
diff --git a/general/package/mt7601u-ap-openipc/Config.in b/general/package/mt7601u-ap-openipc/Config.in
deleted file mode 100644
index acfb26fd..00000000
--- a/general/package/mt7601u-ap-openipc/Config.in
+++ /dev/null
@@ -1,8 +0,0 @@
-config BR2_PACKAGE_MT7601U_AP_OPENIPC
-	bool "mt7601u-ap-openipc"
-	depends on BR2_LINUX_KERNEL
-	help
-	  Wireless driver mt7601u with AP mode.
-
-comment "MT7601U_AP_OPENIPC needs a Linux kernel to be built"
-	depends on !BR2_LINUX_KERNEL
diff --git a/general/package/mt7601u-ap-openipc/mt7601u-ap-openipc.mk b/general/package/mt7601u-ap-openipc/mt7601u-ap-openipc.mk
deleted file mode 100644
index 5fa51f5b..00000000
--- a/general/package/mt7601u-ap-openipc/mt7601u-ap-openipc.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-################################################################################
-#
-# mt7601u-ap-openipc
-#
-################################################################################
-
-ifeq ($(LOCAL_DOWNLOAD),y)
-MT7601U_AP_OPENIPC_SITE_METHOD = git
-MT7601U_AP_OPENIPC_SITE = https://github.com/openipc/mt7601u
-MT7601U_AP_OPENIPC_VERSION = $(shell git ls-remote $(MT7601U_AP_OPENIPC_SITE) HEAD | head -1 | cut -f1)
-else
-MT7601U_AP_OPENIPC_SITE = https://github.com/openipc/mt7601u/archive
-MT7601U_AP_OPENIPC_SOURCE = master.tar.gz
-endif
-
-MT7601U_AP_OPENIPC_LICENSE = GPL-2.0
-
-MT7601U_AP_OPENIPC_MODULE_MAKE_OPTS = \
-	KSRC=$(LINUX_DIR)
-
-$(eval $(kernel-module))
-$(eval $(generic-package))
diff --git a/general/package/mt7601u-openipc/Config.in b/general/package/mt7601u-openipc/Config.in
new file mode 100644
index 00000000..b1dc01a1
--- /dev/null
+++ b/general/package/mt7601u-openipc/Config.in
@@ -0,0 +1,5 @@
+config BR2_PACKAGE_MT7601U_OPENIPC
+	bool "mt7601u-openipc"
+	depends on BR2_LINUX_KERNEL
+	help
+	  Wireless driver MT7601U
diff --git a/general/package/mt7601u-openipc/mt7601u-openipc.mk b/general/package/mt7601u-openipc/mt7601u-openipc.mk
new file mode 100644
index 00000000..6e090e88
--- /dev/null
+++ b/general/package/mt7601u-openipc/mt7601u-openipc.mk
@@ -0,0 +1,17 @@
+################################################################################
+#
+# mt7601u-openipc
+#
+################################################################################
+
+MT7601U_OPENIPC_SITE_METHOD = git
+MT7601U_OPENIPC_SITE = https://github.com/openipc/mt7601u
+MT7601U_OPENIPC_VERSION = $(shell git ls-remote $(MT7601U_OPENIPC_SITE) HEAD | head -1 | cut -f1)
+
+MT7601U_OPENIPC_LICENSE = GPL-2.0
+
+MT7601U_OPENIPC_MODULE_MAKE_OPTS = \
+	KSRC=$(LINUX_DIR)
+
+$(eval $(kernel-module))
+$(eval $(generic-package))