]> git.sur5r.net Git - u-boot/commitdiff
dm: usb: Do not scan companion buses if no devices where handed over
authorHans de Goede <hdegoede@redhat.com>
Sun, 10 May 2015 12:10:21 +0000 (14:10 +0200)
committerSimon Glass <sjg@chromium.org>
Fri, 15 May 2015 00:49:31 +0000 (18:49 -0600)
USB scanning is slow, and there is no need to scan the companion buses
if no usb devices where handed over to the companinon controllers by any
of the main controllers.

This saves e.g. 2 seconds when booting a A10 OLinuxIno Lime with no USB-1
devices plugged into the root usb ports.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Simon Glass <sjg@chromium.org>
drivers/usb/host/usb-uclass.c

index 749257cf6d8fd04aa0f195040772e8b9a73a29e5..963464cff94d0b7cc57daad0d86d0765f89c82fd 100644 (file)
@@ -21,6 +21,10 @@ DECLARE_GLOBAL_DATA_PTR;
 extern bool usb_started; /* flag for the started/stopped USB status */
 static bool asynch_allowed;
 
+struct usb_uclass_priv {
+       int companion_device_count;
+};
+
 int usb_disable_asynch(int disable)
 {
        int old_value = asynch_allowed;
@@ -46,11 +50,22 @@ int submit_control_msg(struct usb_device *udev, unsigned long pipe,
 {
        struct udevice *bus = udev->controller_dev;
        struct dm_usb_ops *ops = usb_get_ops(bus);
+       struct usb_uclass_priv *uc_priv = bus->uclass->priv;
+       int err;
 
        if (!ops->control)
                return -ENOSYS;
 
-       return ops->control(bus, udev, pipe, buffer, length, setup);
+       err = ops->control(bus, udev, pipe, buffer, length, setup);
+       if (setup->request == USB_REQ_SET_FEATURE &&
+           setup->requesttype == USB_RT_PORT &&
+           setup->value == cpu_to_le16(USB_PORT_FEAT_RESET) &&
+           err == -ENXIO) {
+               /* Device handed over to companion after port reset */
+               uc_priv->companion_device_count++;
+       }
+
+       return err;
 }
 
 int submit_bulk_msg(struct usb_device *udev, unsigned long pipe, void *buffer,
@@ -117,12 +132,16 @@ int usb_stop(void)
 {
        struct udevice *bus;
        struct uclass *uc;
+       struct usb_uclass_priv *uc_priv;
        int err = 0, ret;
 
        /* De-activate any devices that have been activated */
        ret = uclass_get(UCLASS_USB, &uc);
        if (ret)
                return ret;
+
+       uc_priv = uc->priv;
+
        uclass_foreach_dev(bus, uc) {
                ret = device_remove(bus);
                if (ret && !err)
@@ -142,6 +161,7 @@ int usb_stop(void)
 #endif
        usb_stor_reset();
        usb_hub_reset();
+       uc_priv->companion_device_count = 0;
        usb_started = 0;
 
        return err;
@@ -171,6 +191,7 @@ static void usb_scan_bus(struct udevice *bus, bool recurse)
 int usb_init(void)
 {
        int controllers_initialized = 0;
+       struct usb_uclass_priv *uc_priv;
        struct usb_bus_priv *priv;
        struct udevice *bus;
        struct uclass *uc;
@@ -184,6 +205,8 @@ int usb_init(void)
        if (ret)
                return ret;
 
+       uc_priv = uc->priv;
+
        uclass_foreach_dev(bus, uc) {
                /* init low_level USB */
                printf("USB%d:   ", count);
@@ -219,15 +242,17 @@ int usb_init(void)
        /*
         * Now that the primary controllers have been scanned and have handed
         * over any devices they do not understand to their companions, scan
-        * the companions.
+        * the companions if necessary.
         */
-       uclass_foreach_dev(bus, uc) {
-               if (!device_active(bus))
-                       continue;
+       if (uc_priv->companion_device_count) {
+               uclass_foreach_dev(bus, uc) {
+                       if (!device_active(bus))
+                               continue;
 
-               priv = dev_get_uclass_priv(bus);
-               if (priv->companion)
-                       usb_scan_bus(bus, true);
+                       priv = dev_get_uclass_priv(bus);
+                       if (priv->companion)
+                               usb_scan_bus(bus, true);
+               }
        }
 
        debug("scan end\n");
@@ -685,6 +710,7 @@ UCLASS_DRIVER(usb) = {
        .name           = "usb",
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
        .post_bind      = usb_post_bind,
+       .priv_auto_alloc_size = sizeof(struct usb_uclass_priv),
        .per_child_auto_alloc_size = sizeof(struct usb_device),
        .per_device_auto_alloc_size = sizeof(struct usb_bus_priv),
        .child_post_bind = usb_child_post_bind,