]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
usb: hub: Add a new API to test if a hub device is root hub
authorBin Meng <bmeng.cn@gmail.com>
Wed, 19 Jul 2017 13:51:11 +0000 (21:51 +0800)
committerMarek Vasut <marex@denx.de>
Fri, 28 Jul 2017 21:34:30 +0000 (23:34 +0200)
Sometimes we need know if a given hub device is root hub or not.
Add a new API to test this. This removes the xHCI driver's own
version is_root_hub() and change to use the new API.

While we are here, remove the unused/commented out get_usb_device()
in the xHCI driver too.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
common/usb_hub.c
drivers/usb/host/xhci.c
include/usb.h

index 086b155cb7477de8132480da305d8a482cfedc6a..a8c2f560068427b7707462910b0f9a824474dd8e 100644 (file)
@@ -67,6 +67,16 @@ static inline bool usb_hub_is_superspeed(struct usb_device *hdev)
        return hdev->descriptor.bDeviceProtocol == 3;
 }
 
+#ifdef CONFIG_DM_USB
+bool usb_hub_is_root_hub(struct udevice *hub)
+{
+       if (device_get_uclass_id(hub->parent) != UCLASS_USB_HUB)
+               return true;
+
+       return false;
+}
+#endif
+
 static int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
 {
        unsigned short dtype = USB_DT_HUB;
index 62ab62b31b9195ca84aa5175c3e94e32f4a42497..0c88980522ac433021e0035cf751cb11bd698c1a 100644 (file)
@@ -1116,26 +1116,6 @@ int usb_lowlevel_stop(int index)
 #endif /* CONFIG_DM_USB */
 
 #ifdef CONFIG_DM_USB
-/*
-static struct usb_device *get_usb_device(struct udevice *dev)
-{
-       struct usb_device *udev;
-
-       if (device_get_uclass_id(dev) == UCLASS_USB)
-               udev = dev_get_uclass_priv(dev);
-       else
-               udev = dev_get_parent_priv(dev);
-
-       return udev;
-}
-*/
-static bool is_root_hub(struct udevice *dev)
-{
-       if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB)
-               return true;
-
-       return false;
-}
 
 static int xhci_submit_control_msg(struct udevice *dev, struct usb_device *udev,
                                   unsigned long pipe, void *buffer, int length,
@@ -1150,10 +1130,10 @@ static int xhci_submit_control_msg(struct udevice *dev, struct usb_device *udev,
        hub = udev->dev;
        if (device_get_uclass_id(hub) == UCLASS_USB_HUB) {
                /* Figure out our port number on the root hub */
-               if (is_root_hub(hub)) {
+               if (usb_hub_is_root_hub(hub)) {
                        root_portnr = udev->portnr;
                } else {
-                       while (!is_root_hub(hub->parent))
+                       while (!usb_hub_is_root_hub(hub->parent))
                                hub = hub->parent;
                        uhop = dev_get_parent_priv(hub);
                        root_portnr = uhop->portnr;
index a266677677130f4f7fb543093df376e557b904cd..64dfa84a9bef8d726c172e1269a67af1efe0c76f 100644 (file)
@@ -775,6 +775,14 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index);
 int usb_setup_device(struct usb_device *dev, bool do_read,
                     struct usb_device *parent);
 
+/**
+ * usb_hub_is_root_hub() - Test whether a hub device is root hub or not
+ *
+ * @hub:       USB hub device to test
+ * @return:    true if the hub device is root hub, false otherwise.
+ */
+bool usb_hub_is_root_hub(struct udevice *hub);
+
 /**
  * usb_hub_scan() - Scan a hub and find its devices
  *