diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-01-29 17:11:15 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-02-01 10:05:53 +0100 |
commit | cec9117d1394c509b34532d0eb1a923a131f6df0 (patch) | |
tree | 30332628c93d6beef26df2c7ea1321674fad89d6 | |
parent | 9ac5043add311e1f804c45dcd67b8f7e98d7f91c (diff) | |
download | barebox-cec9117d1394c509b34532d0eb1a923a131f6df0.tar.gz barebox-cec9117d1394c509b34532d0eb1a923a131f6df0.tar.xz |
usb: add fallback ->detect method for USB host drivers
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@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/usb/core/usb.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index ea244d4bcf..938a28e030 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; } |