diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 07175dc..36fc736 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -488,20 +488,18 @@ 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 @@ 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); diff --git a/include/usb/usb.h b/include/usb/usb.h index 2e1498c..95fb6f3 100644 --- a/include/usb/usb.h +++ b/include/usb/usb.h @@ -211,10 +211,13 @@ struct list_head list; int busnum; + int scanned; }; int usb_register_host(struct usb_host *); +int usb_host_detect(struct usb_host *host, int force); + /* Defines */ #define USB_UHCI_VEND_ID 0x8086 #define USB_UHCI_DEV_ID 0x7112