mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/6] usb: print number of skipped OTG controllers when scanning
Date: Wed, 28 Feb 2024 17:05:18 +0100	[thread overview]
Message-ID: <20240228160518.1589193-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240228160518.1589193-1-a.fatoum@pengutronix.de>

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@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




  parent reply	other threads:[~2024-02-28 16:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 16:05 [PATCH 1/6] driver: make struct bus_type::match optional Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 2/6] driver: make struct bus_type::probe optional Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 3/6] treewide: remove bus probe functions that just call driver probe Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 4/6] usb: otg: maintain list of USB OTG controllers Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 5/6] usb: otg: turn global otg device into device alias Ahmad Fatoum
2024-02-28 16:05 ` Ahmad Fatoum [this message]
2024-02-29  8:10 ` [PATCH 1/6] driver: make struct bus_type::match optional Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240228160518.1589193-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox