dm: usb: Do not assume that first child is always a hub
authorHans de Goede <hdegoede@redhat.com>
Wed, 17 Jun 2015 19:33:53 +0000 (21:33 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 21 Jul 2015 23:39:36 +0000 (17:39 -0600)
On some single port (otg) controllers there is no emulated root hub, so
the first child (if any) may be one of: UCLASS_MASS_STORAGE,
UCLASS_USB_DEV_GENERIC or UCLASS_USB_HUB.

All three of these (and in the future others) are suitable for our
purposes, remove the check for the device being a hub, and add a check to
deal with the fact that there may be no child-dev.

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

index ca06826901feb9d1a5d2e044fcb55115bf66044b..2ed4cb474f8a7d00c16cc64d6081530e6007a9f0 100644 (file)
@@ -630,12 +630,11 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                     bus;
                     uclass_next_device(&bus)) {
                        struct usb_device *udev;
-                       struct udevice *hub;
+                       struct udevice *dev;
 
-                       device_find_first_child(bus, &hub);
-                       if (device_get_uclass_id(hub) == UCLASS_USB_HUB &&
-                           device_active(hub)) {
-                               udev = dev_get_parentdata(hub);
+                       device_find_first_child(bus, &dev);
+                       if (dev && device_active(dev)) {
+                               udev = dev_get_parentdata(dev);
                                usb_show_tree(udev);
                        }
                }
index b0e6e71a8fb0f6017d41177d6d5703fe8b3c1e7e..c5d1e7feb9d0e5da7e31ae2d3abe4c00a6b86350 100644 (file)
@@ -303,14 +303,14 @@ static struct usb_device *find_child_devnum(struct udevice *parent, int devnum)
 
 struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 {
-       struct udevice *hub;
+       struct udevice *dev;
        int devnum = index + 1; /* Addresses are allocated from 1 on USB */
 
-       device_find_first_child(bus, &hub);
-       if (device_get_uclass_id(hub) == UCLASS_USB_HUB)
-               return find_child_devnum(hub, devnum);
+       device_find_first_child(bus, &dev);
+       if (!dev)
+               return NULL;
 
-       return NULL;
+       return find_child_devnum(dev, devnum);
 }
 
 int usb_post_bind(struct udevice *dev)