Re: dwc3-am62/usb-conn-gpio: USB gadget not added when booting in host mode
From: Ernest Van Hoecke
Date: Thu Jul 03 2025 - 09:21:00 EST
On Tue, Jun 24, 2025 at 05:08:32PM +0200, Ernest Van Hoecke wrote:
> On the TI AM62 when using a USB OTG port, I found some unexpected
> behaviour when booting with this port in host mode.
>
> This happens, for example, when booting with a USB pen drive inserted
> When the pen drive is later removed, the OTG port correctly switches
> to "device" mode instead of "host" mode, but the related USB gadget
> does not come up (in my case, a CDC NCM configuration).
>
> This issue only occurs when CONFIG_USB_CONN_GPIO and
> CONFIG_USB_DWC3_AM62 are set to m and not when these modules are
> built-in.
>
Hi all,
This turned out not to be a kernel issue. For future reference and
anyone else running into this I'll document what our problem was
below.
The systemd target `usb-gadget.target` is triggered by udev when a UDC
first comes up. It can happen that by the time gadget-start runs, this
UDC has been removed from the system again.
For example, we saw such a situation using the DWC3 USB controller and
usb-conn-gpio kernel modules as loadables. By the time of the DWC3 init,
udev was active, and during init DWC3 started the USB OTG port in device
mode. If a pen drive was plugged in at boot, it would quickly switch to
host mode right after initialisation, emitting another udev event for
the removal of the UDC. The systemd target was thus reached, but by the
time gadget-start ran, the UDC was gone.
dwc3 init usb-conn-gpio role switch
│ │
▼ ▼
udev: add UDC─┐ udev: del UDC─────►/sys/class/udc empty
│ │
│ x
│ │
│ ▼
└────────────►usb-gadget.target─────►gadget-start
For us the solution was to add a udev rule to bind the gadget every
time the UDC comes up, so the situation can resolve itself.
Kind regards,
Ernest