[PATCH] usb: dwc3: gadget: set device in disconnected state when unplugged
From: Ravineet Singh
Date: Mon Mar 02 2026 - 10:44:46 EST
When a USB cable is disconnected on an LS1028 device, the DWC3
controller only sends DWC3_DEVICE_EVENT_SUSPEND and not a
DWC3_DEVICE_EVENT_DISCONNECT.
Set device in disconnected state by issuing
DWC3_DEVICE_EVENT_DISCONNECT.
Signed-off-by: Ravineet Singh <ravineet.a.singh@xxxxxxxx>
---
drivers/usb/dwc3/gadget.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 6e90f2ad0426..94e191a9ceb8 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -4440,9 +4440,22 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
{
enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
- if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
- dwc->suspended = true;
- dwc3_suspend_gadget(dwc);
+ if (next == DWC3_LINK_STATE_U3) {
+ u8 speed;
+ u32 reg;
+
+ reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+ speed = reg & DWC3_DSTS_CONNECTSPD;
+ if (dwc->gadget->speed != USB_SPEED_UNKNOWN &&
+ speed == USB_SPEED_UNKNOWN) {
+ dwc3_gadget_disconnect_interrupt(dwc);
+ return;
+ }
+
+ if (!dwc->suspended) {
+ dwc->suspended = true;
+ dwc3_suspend_gadget(dwc);
+ }
}
dwc->link_state = next;
--
2.43.0
--em3xqypvsvj66tfm--