summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-07-01 10:14:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-07-01 10:14:40 +0200
commit12657cb99e1ca670da6a7cace3b238a42003e629 (patch)
treeb3f9c2ffb80e29ef78d79c71b52efe055371c66a
parent55e87e07c1c788726423ac617545590cf36c0402 (diff)
parent706a47fa9c54056d53a42436b9762833756b971b (diff)
downloadbarebox-12657cb99e1ca670da6a7cace3b238a42003e629.tar.gz
barebox-12657cb99e1ca670da6a7cace3b238a42003e629.tar.xz
Merge branch 'for-next/usb'
-rw-r--r--commands/usb.c10
-rw-r--r--drivers/usb/core/usb.c47
-rw-r--r--drivers/usb/host/ehci-hcd.c9
-rw-r--r--include/usb/usb.h5
4 files changed, 53 insertions, 18 deletions
diff --git a/commands/usb.c b/commands/usb.c
index e5030659b4..9aee4308da 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -22,24 +22,20 @@
#include <usb/usb.h>
#include <getopt.h>
-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 9a0723a2ed..36fc736fd0 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -431,14 +431,22 @@ static int usb_new_device(struct usb_device *dev)
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 @@ static struct usb_device *usb_alloc_new_device(void)
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 @@ void usb_rescan(void)
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 7297e4861e..f44f836357 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -850,6 +850,13 @@ submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
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 @@ int ehci_register(struct device_d *dev, struct ehci_data *data)
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 da0090e039..95fb6f3a3b 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -211,10 +211,13 @@ struct usb_host {
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_clear_halt(struct usb_device *dev, int pipe);
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 */