Linux USB
 help / color / mirror / Atom feed
* [PATCH v3 0/3] usb: gadget: udc: Rework when the gadget connects
@ 2026-11-17 12:48 Alexey Charkov
  2026-11-17 12:48 ` [PATCH v3 1/3] usb: gadget: udc: Clear a pending connection when starting the UDC Alexey Charkov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexey Charkov @ 2026-11-17 12:48 UTC (permalink / raw)
  To: Neill Kapron, Greg Kroah-Hartman, Xu Yang, Alan Stern
  Cc: linux-usb, linux-kernel, Sebastian Reichel, Alexey Charkov,
	stable

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@flipper.net>
---
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@flipper.net

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@flipper.net

---
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@flipper.net>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-17 13:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 12:48 [PATCH v3 0/3] usb: gadget: udc: Rework when the gadget connects Alexey Charkov
2026-11-17 12:48 ` [PATCH v3 1/3] usb: gadget: udc: Clear a pending connection when starting the UDC Alexey Charkov
2026-11-17 13:03   ` sashiko-bot
2026-11-17 12:48 ` [PATCH v3 2/3] usb: gadget: udc: Forget a deactivation when the gadget driver unbinds Alexey Charkov
2026-11-17 13:06   ` sashiko-bot
2026-11-17 12:48 ` [PATCH v3 3/3] usb: gadget: udc: Decide on connecting in one place Alexey Charkov
2026-11-17 13:19   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox