[PATCH v2 0/4] usb: gadget: udc: Rework when the gadget connects

From: Alexey Charkov

Date: Fri Nov 13 2026 - 07:04:19 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-4 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 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 (4):
usb: gadget: udc: Clear a pending connection when starting the UDC
usb: gadget: udc: Forget a deactivation when the gadget driver unbinds
usb: gadget: configfs: Leave resetting the deactivation to the UDC core
usb: gadget: udc: Decide on connecting in one place

drivers/usb/gadget/configfs.c | 1 -
drivers/usb/gadget/udc/core.c | 197 +++++++++++++++++++++++-------------------
include/linux/usb/gadget.h | 4 +-
3 files changed, 111 insertions(+), 91 deletions(-)
---
base-commit: 6d582d78fad9d828e575ca0cdcff8ea47a77220b
change-id: 20261112-udc-connect-61e0f11cf93b

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