summaryrefslogtreecommitdiff
path: root/payloads/libpayload/drivers/usb/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/drivers/usb/usb.c')
-rw-r--r--payloads/libpayload/drivers/usb/usb.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c
index 6174d639d2..e00d92f00a 100644
--- a/payloads/libpayload/drivers/usb/usb.c
+++ b/payloads/libpayload/drivers/usb/usb.c
@@ -653,3 +653,29 @@ usb_generic_init (usbdev_t *dev)
usb_detach_device(dev->controller, dev->address);
}
}
+
+/*
+ * returns the address of the closest USB2.0 hub, which is responsible for
+ * split transactions, along with the number of the used downstream port
+ */
+int closest_usb2_hub(const usbdev_t *dev, int *const addr, int *const port)
+{
+ const usbdev_t *usb1dev;
+
+ do {
+ usb1dev = dev;
+ if ((dev->hub >= 0) && (dev->hub < 128))
+ dev = dev->controller->devices[dev->hub];
+ else
+ dev = NULL;
+ } while (dev && (dev->speed < 2));
+
+ if (dev) {
+ *addr = usb1dev->hub;
+ *port = usb1dev->port;
+ return 0;
+ }
+
+ usb_debug("Couldn't find closest USB2.0 hub.\n");
+ return 1;
+}