[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250624140930.25887-1-drew.hamilton@zetier.com>
Date: Tue, 24 Jun 2025 10:09:30 -0400
From: Drew Hamilton <drew.hamilton@...ier.com>
To: Bin Liu <b-liu@...com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
Drew Hamilton <drew.hamilton@...ier.com>,
Yehowshua Immanuel <yehowshua.immanuel@...sixtech.com>
Subject: [PATCH] usb: musb: fix gadget state on disconnect
When unplugging the USB cable or disconnecting a gadget in usb peripheral mode with
echo "" > /sys/kernel/config/usb_gadget/<your_gadget>/UDC,
/sys/class/udc/musb-hdrc.0/state does not change from USB_STATE_CONFIGURED.
Testing on dwc2/3 shows they both update the state to USB_STATE_NOTATTACHED.
Add calls to usb_gadget_set_state in musb_g_disconnect and musb_gadget_stop
to fix both cases.
Tested against 82f2b0b97b36ee3fcddf0f0780a9a0825d52fec3.
Co-authored-by: Yehowshua Immanuel <yehowshua.immanuel@...sixtech.com>
Signed-off-by: Yehowshua Immanuel <yehowshua.immanuel@...sixtech.com>
Signed-off-by: Drew Hamilton <drew.hamilton@...ier.com>
---
drivers/usb/musb/musb_gadget.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 6869c58367f2..caf4d4cd4b75 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1913,6 +1913,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
* gadget driver here and have everything work;
* that currently misbehaves.
*/
+ usb_gadget_set_state(g, USB_STATE_NOTATTACHED);
/* Force check of devctl register for PM runtime */
pm_runtime_mark_last_busy(musb->controller);
@@ -2019,6 +2020,7 @@ void musb_g_disconnect(struct musb *musb)
case OTG_STATE_B_PERIPHERAL:
case OTG_STATE_B_IDLE:
musb_set_state(musb, OTG_STATE_B_IDLE);
+ usb_gadget_set_state(&musb->g, USB_STATE_NOTATTACHED);
break;
case OTG_STATE_B_SRP_INIT:
break;
--
2.34.1
Powered by blists - more mailing lists