diff options
author | Tom Rini <trini@konsulko.com> | 2020-08-03 22:20:22 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-08-03 22:20:22 -0400 |
commit | d6faedca7670a0b4862cace2f3189998cbec87d8 (patch) | |
tree | 387ca6154bbfb29b7ff30946cac70036146c5cb6 /drivers/usb/musb-new/musb_uboot.c | |
parent | 68941e3b2c217907a49aa66af8bb65729b913397 (diff) | |
parent | 23552ba142860205c4ddec414417cdc251f8cb79 (diff) | |
download | u-boot-WIP/03Aug2020.tar.gz |
Merge branch '2020-08-01-misc-cleanups'WIP/03Aug2020
- Further cleanup of common.h and dm.h usage in headers
Diffstat (limited to 'drivers/usb/musb-new/musb_uboot.c')
-rw-r--r-- | drivers/usb/musb-new/musb_uboot.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index 988071a61d..8ac2f0a78a 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -1,5 +1,6 @@ #include <common.h> #include <console.h> +#include <dm.h> #include <malloc.h> #include <watchdog.h> #include <linux/delay.h> @@ -452,3 +453,39 @@ struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata, return *musbp; } + +#if CONFIG_IS_ENABLED(DM_USB) +struct usb_device *usb_dev_get_parent(struct usb_device *udev) +{ + struct udevice *parent = udev->dev->parent; + + /* + * When called from usb-uclass.c: usb_scan_device() udev->dev points + * to the parent udevice, not the actual udevice belonging to the + * udev as the device is not instantiated yet. + * + * If dev is an usb-bus, then we are called from usb_scan_device() for + * an usb-device plugged directly into the root port, return NULL. + */ + if (device_get_uclass_id(udev->dev) == UCLASS_USB) + return NULL; + + /* + * If these 2 are not the same we are being called from + * usb_scan_device() and udev itself is the parent. + */ + if (dev_get_parent_priv(udev->dev) != udev) + return udev; + + /* We are being called normally, use the parent pointer */ + if (device_get_uclass_id(parent) == UCLASS_USB_HUB) + return dev_get_parent_priv(parent); + + return NULL; +} +#else +struct usb_device *usb_dev_get_parent(struct usb_device *udev) +{ + return udev->parent; +} +#endif |