diff --git a/commands/usb.c b/commands/usb.c index e503065..9aee430 100644 --- a/commands/usb.c +++ b/commands/usb.c @@ -22,24 +22,20 @@ #include #include -static int scanned; - static int do_usb(int argc, char *argv[]) { int opt; + int force = 0; while ((opt = getopt(argc, argv, "f")) > 0) { switch (opt) { case 'f': - scanned = 0; + force = 1; break; } } - if (!scanned) { - usb_rescan(); - scanned = 1; - } + usb_rescan(force); return 0; } diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 9a0723a..36fc736 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -431,14 +431,22 @@ if (dev->descriptor->iSerialNumber) usb_string(dev, dev->descriptor->iSerialNumber, dev->serial, sizeof(dev->serial)); + + if (parent) { + sprintf(dev->dev.name, "%s-%d", parent->dev.name, port); + } else { + sprintf(dev->dev.name, "usb%d", dev->host->busnum); + } + + dev->dev.id = DEVICE_ID_SINGLE; + + register_device(&dev->dev); + /* now prode if the device is a hub */ usb_hub_probe(dev, 0); - sprintf(dev->dev.name, "usb%d-%d", dev->host->busnum, dev->devnum); - print_usb_device(dev); - register_device(&dev->dev); dev_add_param_int_ro(&dev->dev, "iManufacturer", dev->descriptor->iManufacturer, "%d"); dev_add_param_int_ro(&dev->dev, "iProduct", @@ -480,13 +488,18 @@ return usbdev; } -void usb_rescan(void) +int usb_host_detect(struct usb_host *host, int force) { struct usb_device *dev, *tmp; - struct usb_host *host; int ret; + 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) @@ -496,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/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 7297e48..f44f836 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -850,6 +850,13 @@ return -1; } +static int ehci_detect(struct device_d *dev) +{ + struct ehci_priv *ehci = dev->priv; + + return usb_host_detect(&ehci->host, 0); +} + int ehci_register(struct device_d *dev, struct ehci_data *data) { struct usb_host *host; @@ -885,6 +892,8 @@ ehci_reset(ehci); } + dev->detect = ehci_detect; + usb_register_host(host); reg = HC_VERSION(ehci_readl(&ehci->hccr->cr_capbase)); diff --git a/include/usb/usb.h b/include/usb/usb.h index da0090e..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 @@ -248,7 +251,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size); int usb_set_interface(struct usb_device *dev, int interface, int alternate); -void usb_rescan(void); +void usb_rescan(int force); /* big endian -> little endian conversion */ /* some CPUs are already little endian e.g. the ARM920T */