Merge git://git.denx.de/u-boot-mpc85xx
[oweals/u-boot.git] / drivers / usb / host / usb-uclass.c
index 838d05af755b4fcc8868839eeb83cc753ac537e9..50538e0bd760461342812df0a162d262e541e0a4 100644 (file)
@@ -158,9 +158,6 @@ int usb_stop(void)
                ret = device_remove(bus);
                if (ret && !err)
                        err = ret;
-               ret = device_unbind_children(bus);
-               if (ret && !err)
-                       err = ret;
        }
 
 #ifdef CONFIG_SANDBOX
@@ -205,6 +202,20 @@ static void usb_scan_bus(struct udevice *bus, bool recurse)
                printf("%d USB Device(s) found\n", priv->next_addr);
 }
 
+static void remove_inactive_children(struct uclass *uc, struct udevice *bus)
+{
+       uclass_foreach_dev(bus, uc) {
+               struct udevice *dev, *next;
+
+               if (!device_active(bus))
+                       continue;
+               device_foreach_child_safe(dev, next, bus) {
+                       if (!device_active(dev))
+                               device_unbind(dev);
+               }
+       }
+}
+
 int usb_init(void)
 {
        int controllers_initialized = 0;
@@ -273,6 +284,15 @@ int usb_init(void)
        }
 
        debug("scan end\n");
+
+       /* Remove any devices that were not found on this scan */
+       remove_inactive_children(uc, bus);
+
+       ret = uclass_get(UCLASS_USB_HUB, &uc);
+       if (ret)
+               return ret;
+       remove_inactive_children(uc, bus);
+
        /* if we were not able to find at least one working bus, bail out */
        if (!count)
                printf("No controllers found\n");
@@ -282,6 +302,14 @@ int usb_init(void)
        return usb_started ? 0 : -1;
 }
 
+/*
+ * TODO(sjg@chromium.org): Remove this legacy function. At present it is needed
+ * to support boards which use driver model for USB but not Ethernet, and want
+ * to use USB Ethernet.
+ *
+ * The #if clause is here to ensure that remains the only case.
+ */
+#if !defined(CONFIG_DM_ETH) && defined(CONFIG_USB_HOST_ETHER)
 static struct usb_device *find_child_devnum(struct udevice *parent, int devnum)
 {
        struct usb_device *udev;
@@ -315,6 +343,7 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
        return find_child_devnum(dev, devnum);
 }
+#endif
 
 int usb_post_bind(struct udevice *dev)
 {