From: Stefan Eichenberger <[email protected]> ci_udc has no device tree match of its own, so bind it here for the ports it can serve. This driver already owns the controller node.
A peripheral-only port is of no use as a host, so hand the node over completely and decline to bind. An OTG port serves both roles, so bind ci_udc in addition and stay bound. Neither device is probed at bind time, so "usb start" probes this one and puts the controller into host mode, while "ums" and "fastboot" probe the gadget one and put it into device mode. Boards that do not enable both CI_UDC and DM_USB_GADGET are unaffected. Signed-off-by: Stefan Eichenberger <[email protected]> --- drivers/usb/host/ehci-mx6.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 25907f22612..8b997e88946 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -20,6 +20,8 @@ #include <asm/mach-imx/sys_proto.h> #include <dm.h> #include <asm/mach-types.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include <power/regulator.h> #include <linux/usb/otg.h> #include <linux/usb/phy.h> @@ -553,6 +555,41 @@ static int ehci_usb_phy_mode(struct udevice *dev) return 0; } +static int ehci_usb_bind(struct udevice *dev) +{ + ofnode node = dev_ofnode(dev); + enum usb_dr_mode dr_mode; + int ret; + + /* + * The ChipIdea gadget driver has no device tree match of its own: it + * shares this node, so this driver owns it and decides which roles + * are wanted here. + */ + if (!IS_ENABLED(CONFIG_CI_UDC) || !CONFIG_IS_ENABLED(DM_USB_GADGET)) + return 0; + + dr_mode = usb_get_dr_mode(node); + if (dr_mode != USB_DR_MODE_PERIPHERAL && dr_mode != USB_DR_MODE_OTG) + return 0; + + ret = device_bind_driver_to_node(dev->parent, "ci_udc", + ofnode_get_name(node), node, NULL); + if (ret) { + dev_err(dev, "failed to bind ChipIdea gadget: %d\n", ret); + return ret; + } + + /* + * An OTG port serves both roles, so stay bound as well. Neither + * device is probed here: "usb start" probes this one and puts the + * controller into host mode, "ums" and "fastboot" probe the gadget + * one and put it into device mode. A peripheral-only port is of no + * use as a host, so hand the node over completely. + */ + return dr_mode == USB_DR_MODE_OTG ? 0 : -ENODEV; +} + static int ehci_usb_of_to_plat(struct udevice *dev) { struct usb_plat *plat = dev_get_plat(dev); @@ -774,6 +811,7 @@ U_BOOT_DRIVER(usb_mx6) = { .name = "ehci_mx6", .id = UCLASS_USB, .of_match = mx6_usb_ids, + .bind = ehci_usb_bind, .of_to_plat = ehci_usb_of_to_plat, .probe = ehci_usb_probe, .remove = ehci_usb_remove, -- 2.55.0
