[PATCH 2/4] usb: typec: wire USB role changes to OTG device
Sascha Hauer
s.hauer at pengutronix.de
Mon Apr 20 05:02:09 PDT 2026
On Mon, Apr 20, 2026 at 01:08:41PM +0200, Ahmad Fatoum wrote:
> > +static bool typec_apply_otg_role(struct typec_port *port)
> > +{
> > + struct device_node *connector = port->dev.of_node;
> > + struct device_node *ep, *remote;
> > + struct device *dev;
> > + enum usb_dr_mode dr_mode;
> > + bool applied = false;
> > +
> > + if (!IS_ENABLED(CONFIG_USB_OTGDEV) || !connector)
> > + return false;
> > +
> > + if (port->usb_role == USB_ROLE_HOST)
> > + dr_mode = USB_DR_MODE_HOST;
> > + else if (port->usb_role == USB_ROLE_DEVICE)
> > + dr_mode = USB_DR_MODE_PERIPHERAL;
> > + else
> > + return false;
> > +
> > + for_each_endpoint_of_node(connector, ep) {
> > + remote = of_graph_get_remote_port_parent(ep);
> > + if (!remote)
> > + continue;
> > +
> > + bus_for_each_device(&otg_bus_type, dev) {
> > + if (dev->parent && dev->parent->of_node == remote) {
>
> I believe board code could've set the mode before we come here.
>
> Also, I think there must be a way to opt out of this.
>
> Let's assume you load barebox via USB on a Type C port. You may not be
> able to yank the cable away fast enough before barebox does the one-way
> otg -> peripheral transition.
Should have sent this as RFC, because these are the questions I had as
well. Ideally the otg->host or otg->device transition shouldn't be
oneway, but that might open a can of worms.
> > +late_initcall(typec_apply_otg_roles);
>
> Does postenvironment not make more sense, so the environment can
> override this?
Sounds good, but then you don't have a chance anymore to do something
with the device from board code.
Ok, so we need something to opt in/out from that mechanism and also
something for board code to call the role transition earlier when
needed.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list