From 6f836af9356041769c18190e08aa6eb38803bae4 Mon Sep 17 00:00:00 2001
From: Igor Zalatov <flyrouter@gmail.com>
Date: Sun, 9 Jul 2023 23:18:29 +0300
Subject: [PATCH] Add RNDIS USB modem support (#907)

---
 .../board/t31/kernel/t31.generic.config       | 35 +++++++++++++++++--
 general/overlay/etc/network/interfaces.d/usb0 |  2 ++
 general/overlay/etc/wireless                  | 28 +++++++++++++++
 3 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 general/overlay/etc/network/interfaces.d/usb0

diff --git a/br-ext-chip-ingenic/board/t31/kernel/t31.generic.config b/br-ext-chip-ingenic/board/t31/kernel/t31.generic.config
index bc8e3e98..b5382a76 100644
--- a/br-ext-chip-ingenic/board/t31/kernel/t31.generic.config
+++ b/br-ext-chip-ingenic/board/t31/kernel/t31.generic.config
@@ -838,8 +838,36 @@ CONFIG_PHYLIB=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_RTL8152 is not set
-# CONFIG_USB_USBNET is not set
+CONFIG_USB_USBNET=m
+# CONFIG_USB_NET_AX8817X is not set
+# CONFIG_USB_NET_AX88179_178A is not set
+CONFIG_USB_NET_CDCETHER=m
+# CONFIG_USB_NET_CDC_EEM is not set
+# CONFIG_USB_NET_CDC_NCM is not set
+# CONFIG_USB_NET_CDC_MBIM is not set
+# CONFIG_USB_NET_DM9601 is not set
+# CONFIG_USB_NET_SMSC75XX is not set
+# CONFIG_USB_NET_SMSC95XX is not set
+# CONFIG_USB_NET_GL620A is not set
+# CONFIG_USB_NET_NET1080 is not set
+# CONFIG_USB_NET_PLUSB is not set
+# CONFIG_USB_NET_MCS7830 is not set
+CONFIG_USB_NET_RNDIS_HOST=m
+# CONFIG_USB_NET_CDC_SUBSET is not set
+# CONFIG_USB_ALI_M5632 is not set
+# CONFIG_USB_AN2720 is not set
+# CONFIG_USB_BELKIN is not set
+# CONFIG_USB_ARMLINUX is not set
+# CONFIG_USB_EPSON2888 is not set
+# CONFIG_USB_KC2190 is not set
+# CONFIG_USB_NET_ZAURUS is not set
+# CONFIG_USB_NET_CX82310_ETH is not set
+# CONFIG_USB_NET_KALMIA is not set
+# CONFIG_USB_NET_QMI_WWAN is not set
+# CONFIG_USB_NET_INT51X1 is not set
 # CONFIG_USB_IPHETH is not set
+# CONFIG_USB_SIERRA_NET is not set
+# CONFIG_USB_VL600 is not set
 CONFIG_WLAN=y
 # CONFIG_LIBERTAS_THINFIRM is not set
 # CONFIG_AT76C50X_USB is not set
@@ -1336,7 +1364,7 @@ CONFIG_USB_DWC2_VERBOSE_VERBOSE=y
 # USB port drivers
 #
 CONFIG_USB_SERIAL=m
-# CONFIG_USB_SERIAL_GENERIC is not set
+CONFIG_USB_SERIAL_GENERIC=y
 # CONFIG_USB_SERIAL_AIRCABLE is not set
 # CONFIG_USB_SERIAL_ARK3116 is not set
 # CONFIG_USB_SERIAL_BELKIN is not set
@@ -1380,7 +1408,8 @@ CONFIG_USB_SERIAL=m
 # CONFIG_USB_SERIAL_TI is not set
 # CONFIG_USB_SERIAL_CYBERJACK is not set
 # CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OPTION is not set
+CONFIG_USB_SERIAL_WWAN=m
+CONFIG_USB_SERIAL_OPTION=m
 # CONFIG_USB_SERIAL_OMNINET is not set
 # CONFIG_USB_SERIAL_OPTICON is not set
 # CONFIG_USB_SERIAL_VIVOPAY_SERIAL is not set
diff --git a/general/overlay/etc/network/interfaces.d/usb0 b/general/overlay/etc/network/interfaces.d/usb0
new file mode 100644
index 00000000..a0a955c3
--- /dev/null
+++ b/general/overlay/etc/network/interfaces.d/usb0
@@ -0,0 +1,2 @@
+#auto usb0
+iface usb0 inet dhcp
diff --git a/general/overlay/etc/wireless b/general/overlay/etc/wireless
index 8d4c9cf1..3fa1eea0 100755
--- a/general/overlay/etc/wireless
+++ b/general/overlay/etc/wireless
@@ -55,4 +55,32 @@ if [ "$1" = "mt7601u-t31-camhi" ]; then
 	exit 0
 fi
 
+# T31 CamHi with Quectel EC200S-CN, EC200T-EU and usb0
+if [ "$1" = "ec200-t31-camhi" ]; then
+	set_gpio 61 0
+	modprobe usbserial vendor=0x2c7c product=0x6026
+	modprobe rndis_host
+	sleep 10
+	exit 0
+fi
+
+# T31 CamHi with Fibocom L610-CN and usb0
+if [ "$1" = "l610-t31-camhi" ]; then
+	set_gpio 61 0
+	modprobe usbserial vendor=0x1782 product=0x4d11
+	modprobe rndis_host
+	sleep 10
+	exit 0
+fi
+
+# T31 CamHi with Fibocom L716-CN and usb0
+if [ "$1" = "l716-t31-camhi" ]; then
+	set_gpio 61 0
+	modprobe usbserial vendor=0x2cb7 product=0x0001
+	modprobe rndis_host
+	sleep 10
+	exit 0
+fi
+
+
 exit 1