[projects/geninitrd] usbkbd: find usb controllers attached to any bus

atler atler at pld-linux.org
Tue Sep 20 02:20:47 CEST 2022


commit 4ad811f1d486af4393e6257e5f1197b3e48e4a7e
Author: Jan Palus <atler at pld-linux.org>
Date:   Tue Sep 20 02:18:28 2022 +0200

    usbkbd: find usb controllers attached to any bus
    
    fallback to pci-exclusive method if none were found

 functions     |  6 +++++-
 mod-usbkbd.sh | 19 ++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/functions b/functions
index 186b967..5f38115 100644
--- a/functions
+++ b/functions
@@ -186,11 +186,15 @@ dm_node() {
 	printf "/dev/mapper/%s" $(dm_name "$node")
 }
 
+is_kmod() {
+	modprobe --version | grep -q "^kmod"
+}
+
 # find modules by class
 # find_modules_by_class 0106 - finds modules for SATA devices in the system
 # find_modules_by_class 0c03 - finds modules for USB controllers
 find_modules_by_class() {
-	if modprobe --version | grep -q "^kmod"; then
+	if is_kmod; then
 		find_modules_by_class_kmod $@
 	else
 		find_modules_by_class_mit $@
diff --git a/mod-usbkbd.sh b/mod-usbkbd.sh
index dd2ab95..4857bd4 100644
--- a/mod-usbkbd.sh
+++ b/mod-usbkbd.sh
@@ -57,9 +57,22 @@ find_modules_usbkbd() {
 
 	if [ -n "$modules" ]; then
 		# usb controllers
-		for m in $(find_modules_by_class "0c03"); do
-			find_module "$m"
-		done
+		if is_kmod; then
+			# find parent devices of usb hubs
+			for hub_dc in `grep -l 09 /sys/bus/usb/devices/*/bDeviceClass`; do
+				ctrl=$(dirname $(dirname $(readlink -f $hub_dc)))
+				if [ -f "$ctrl/modalias" ]; then
+					find_module $(cat "$ctrl/modalias")
+					usb_ctrl_found=1
+				fi
+			done
+		fi
+		if [ -z "$usb_ctrl_found" ]; then
+			# fallback to old pci only method
+			for m in $(find_modules_by_class "0c03"); do
+				find_module "$m"
+			done
+		fi
 
 		# always add hid-generic
 		find_module "-hid-generic"
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/geninitrd.git/commitdiff/4ad811f1d486af4393e6257e5f1197b3e48e4a7e



More information about the pld-cvs-commit mailing list