[PATCH 6/7] usb: add fallback ->detect method for USB host drivers
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Feb 2 14:40:58 EST 2021
We already maintain a list of USB host controllers, so we can use that
to implement a generic detect callback. Currently, all drivers define
their own, which uses driver-specific means to arrive at the struct
usb_host and then call usb_host_detect().
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
- no change
---
drivers/usb/core/usb.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index ea244d4bcf6c..938a28e030bf 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -88,11 +88,25 @@ static inline void usb_host_release(struct usb_host *host)
slice_release(&host->slice);
}
+static int usb_hw_detect(struct device_d *dev)
+{
+ struct usb_host *host;
+
+ list_for_each_entry(host, &host_list, list) {
+ if (dev == host->hw_dev)
+ return usb_host_detect(host);
+ }
+
+ return -ENODEV;
+}
+
int usb_register_host(struct usb_host *host)
{
list_add_tail(&host->list, &host_list);
host->busnum = host_busnum++;
slice_init(&host->slice, dev_name(host->hw_dev));
+ if (!host->hw_dev->detect)
+ host->hw_dev->detect = usb_hw_detect;
return 0;
}
--
2.30.0
More information about the barebox
mailing list