usb: dwc2: Improve gadget state disconnection handling
Subsystems (2)
RFC PATCH 1/2 usb: dwc2: Improve gadget state disconnection handling
In the earlier commit dad3f793f20f ("usb: dwc2: Make sure we disconnect the gadget state"), I was trying to fix up the fact that we somehow weren't disconnecting the gadget state, so that when the OTG port was plugged in the second time we would get warnings about the state tracking being wrong.
The fix there was somewhat simple, as it just made sure to call dwc2_hsotg_disconnect() before we connected things up in OTG mode.
But in looking at a different issue I was seeing with UDC state handling, I realized that it would be much better to call dwc2_hsotg_disconnect when we get the state change signal moving to host mode.
Thus, this patch removes the earlier disconnect call I added and moves it (and the needed locking) to the host mode transition.
Suggestions or feedback would be grealy appreciated!
--- drivers/usb/dwc2/hcd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/dwc2/hcd.c +6 -2
@@ -3277,7 +3277,6 @@ static void dwc2_conn_id_status_change(struct work_struct *work)dwc2_core_init (hsotg, false);dwc2_enable_global_interrupts (hsotg);spin_lock_irqsave (&hsotg->lock, flags); -dwc2_hsotg_disconnect (hsotg);dwc2_hsotg_core_init_disconnected (hsotg, false);spin_unlock_irqrestore (&hsotg->lock, flags);dwc2_hsotg_core_connect (hsotg);
@@ -3296,8 +3295,13 @@ static void dwc2_conn_id_status_change(struct work_struct *work)if (count >250 )dev_err (hsotg->dev,"Connection id status change timed out\n" ); - hsotg->op_state =OTG_STATE_A_HOST ; +spin_lock_irqsave (&hsotg->lock, flags); +dwc2_hsotg_disconnect (hsotg); +dwc2_hsotg_core_init_disconnected (hsotg, false); +spin_unlock_irqrestore (&hsotg->lock, flags); + + hsotg->op_state =OTG_STATE_A_HOST ;/* Initialize the Core for Host mode */ dwc2_core_init (hsotg, false);dwc2_enable_global_interrupts (hsotg);
Signature · 1 line
2.7.4
RFC PATCH 2/2 usb: dwc2: Fix UDC state tracking
It has been noticed that the dwc2 udc state reporting doesn't seem to work (at least on HiKey boards). Where after the initial setup, the sysfs /sys/class/udc/f72c0000.usb/state file would report "configured" no matter the state of the OTG port.
This patch adds a call so that we report to the UDC layer when the gadget device is disconnected.
Feedback or suggestions would be greatly appreciated!
--- drivers/usb/dwc2/gadget.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc2/gadget.c +2 -0
@@ -3202,6 +3202,8 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg)call_gadget (hsotg, disconnect); hsotg->lx_state =DWC2_L3 ; + +usb_gadget_set_state (&hsotg->gadget,USB_STATE_NOTATTACHED ); }/**
Signature · 1 line
2.7.4