[PATCH 6/6] usb: print number of skipped OTG controllers when scanning

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Feb 28 08:05:18 PST 2024


I often get confused by running usb and wondering why devices behind
unconfigured OTG controllers are not enumerated. Improve the user
experience by printing a message when doing a USB scan while some OTG
controllers are not yet configured (i.e. the otg.mode device parameter
hasn't been set to "peripheral" or "host").

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/usb/core/usb.c   | 14 ++++++++++++++
 drivers/usb/otg/otgdev.c | 12 ++++++++++++
 include/linux/usb/usb.h  |  2 ++
 3 files changed, 28 insertions(+)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 614527fecbf3..1f6f1d7c4184 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -616,6 +616,20 @@ int usb_rescan(void)
 
 	pr_info("%d USB Device(s) found\n", dev_count);
 
+	if (IS_ENABLED(CONFIG_USB_OTGDEV)) {
+		unsigned int skipped_otg = 0;
+		struct device *dev;
+
+		bus_for_each_device(&otg_bus_type, dev) {
+			if (otg_device_get_mode(dev) == USB_DR_MODE_OTG)
+				skipped_otg++;
+		}
+
+		if (skipped_otg)
+			pr_notice("%u unconfigured OTG controller(s) were not scanned\n",
+				  skipped_otg);
+	}
+
 	return dev_count;
 }
 
diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index b4315c2d3c28..5a8626343056 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -62,6 +62,18 @@ struct bus_type otg_bus_type = {
 	.name = "usbotg" /* "otg" is already taken for the alias */
 };
 
+int otg_device_get_mode(struct device *dev)
+{
+	struct otg_mode *otg;
+
+	if (dev->bus != &otg_bus_type)
+		return -ENODEV;
+
+	otg = dev->priv;
+
+	return otg->cur_mode;
+}
+
 int usb_register_otg_device(struct device *parent,
 			    int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
 {
diff --git a/include/linux/usb/usb.h b/include/linux/usb/usb.h
index a611d19b4a17..4ad2fd32d217 100644
--- a/include/linux/usb/usb.h
+++ b/include/linux/usb/usb.h
@@ -480,6 +480,8 @@ enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np,
 int usb_register_otg_device(struct device *parent,
 			    int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx);
 
+int otg_device_get_mode(struct device *dev);
+
 extern struct bus_type otg_bus_type;
 
 extern struct list_head usb_device_list;
-- 
2.39.2




More information about the barebox mailing list