diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-06-20 00:00:17 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-06-21 07:41:38 +0200 |
commit | 8f5889eb0a8a6171be96da58b02ad731eefd2768 (patch) | |
tree | cf70947cadc82134010bb664e19a412f8fbdc55c /drivers/usb/core/usb.c | |
parent | 31879ed96f75e1e75b150e9665e261a44e3fa904 (diff) | |
download | barebox-8f5889eb0a8a6171be96da58b02ad731eefd2768.tar.gz barebox-8f5889eb0a8a6171be96da58b02ad731eefd2768.tar.xz |
usb: implement a usb_host_detect to scan individual USB hosts
Currently we can only (re)scan all USB hosts. Add a function to
scan individual hosts. This is useful for implementing the detect
callback in the next patch.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/usb/core/usb.c')
-rw-r--r-- | drivers/usb/core/usb.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 07175dc3f1..36fc736fd0 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -488,20 +488,18 @@ static struct usb_device *usb_alloc_new_device(void) return usbdev; } -static int scanned; - -void usb_rescan(int force) +int usb_host_detect(struct usb_host *host, int force) { struct usb_device *dev, *tmp; - struct usb_host *host; int ret; - if (scanned && !force) - return; - - scanned = 1; + if (host->scanned && !force) + return -EBUSY; list_for_each_entry_safe(dev, tmp, &usb_device_list, list) { + if (dev->host != host) + continue; + list_del(&dev->list); unregister_device(&dev->dev); if (dev->hub) @@ -511,17 +509,31 @@ void usb_rescan(int force) free(dev); } + ret = host->init(host); + if (ret) + return ret; + + dev = usb_alloc_new_device(); + dev->host = host; + usb_new_device(dev); + + host->scanned = 1; + + return 0; +} + +void usb_rescan(int force) +{ + struct usb_host *host; + int ret; + printf("USB: scanning bus for devices...\n"); dev_index = 0; list_for_each_entry(host, &host_list, list) { - ret = host->init(host); + ret = usb_host_detect(host, force); if (ret) continue; - - dev = usb_alloc_new_device(); - dev->host = host; - usb_new_device(dev); } printf("%d USB Device(s) found\n", dev_index); |