[PATCH v3 0/3] usb: gadget: udc: Rework when the gadget connects

From: Alexey Charkov

Date: Tue Nov 17 2026 - 07:48:22 EST


The UDC core decides whether to enable the gadget's pullup in several
places: bind and unbind, VBUS events, usb_gadget_{de,}activate() and the
soft_connect attribute. Each applies its own rules, and
gadget->connected records both the pullup state and a request to connect
later. Since commit 62911bc82b03 ("usb: gadget: udc: skip pullup() if
already connected"), a VBUS event before bind leaves the gadget
invisible to the host until it is rebound. That happens on every boot
of an RK3576 board whose Type-C port controller sets the device role
before userspace binds a configfs gadget.

Patch 1 is the v1 fix, small enough for stable. Patches 2-3 implement
Alan's scheme: the gadget connects only while a driver is bound, VBUS is
present, the driver hasn't deactivated it and userspace hasn't
disconnected it through soft_connect. One helper records that in
udc->allow_connect under connect_lock and switches the pullup to match.
The UDC starts and stops only at bind and unbind, and the deactivation
and soft-disconnect requests are forgotten at unbind.

Signed-off-by: Alexey Charkov <alchark@xxxxxxxxxxx>
---
Changes in v3:
- Patch 1: collect Alan's Acked-by.
- Squash v2 patch 3 (configfs) into patch 2 and clear the deactivation
inline rather than through a helper (Alan).
- Patch 3: clear gadget->connected at unbind even if the pullup refuses
to switch off (Sashiko).
- Patch 3: check the pullup state before the ->pullup operation, so that
a call which changes nothing succeeds (Alan).
- Patch 3: warn when the pullup fails to switch, unless the UDC reports
-EOPNOTSUPP (Alan).
- Patch 3: set udc->allow_connect inside the renamed
usb_udc_update_allow_connect() (Alan).
- Patch 3: keep a soft_connect request even if the pullup fails to follow
it, so the next update retries it; the warning reports the failure.
- Link to v2: https://patch.msgid.link/20261113-udc-connect-v2-0-f51b11f07eb8@xxxxxxxxxxx

Changes in v2:
- Add patches 2-4, reworking the connection control as Alan suggested.
- Link to v1: https://patch.msgid.link/20261112-udc-connect-v1-1-03c73259642b@xxxxxxxxxxx

---
Alexey Charkov (3):
usb: gadget: udc: Clear a pending connection when starting the UDC
usb: gadget: udc: Forget a deactivation when the gadget driver unbinds
usb: gadget: udc: Decide on connecting in one place

drivers/usb/gadget/configfs.c | 1 -
drivers/usb/gadget/udc/core.c | 214 ++++++++++++++++++++++++------------------
include/linux/usb/gadget.h | 4 +-
3 files changed, 123 insertions(+), 96 deletions(-)
---
base-commit: 749a4de370409464cf8501ec5b2451df45c84eb4
change-id: 20261112-udc-connect-61e0f11cf93b

Best regards,
--
Alexey Charkov <alchark@xxxxxxxxxxx>