Skip to content

Commit 2c6b6af

Browse files
Tomas Marekgregkh
authored andcommitted
usb: dwc2: drd: fix clock gating on USB role switch
The dwc2_handle_usb_suspend_intr() function disables gadget clocks in USB peripheral mode when no other power-down mode is available (introduced by commit 0112b7c ("usb: dwc2: Update dwc2_handle_usb_suspend_intr function.")). However, the dwc2_drd_role_sw_set() USB role update handler attempts to read DWC2 registers if the USB role has changed while the USB is in suspend mode (when the clocks are gated). This causes the system to hang. Release the gadget clocks before handling the USB role update. Fixes: 0112b7c ("usb: dwc2: Update dwc2_handle_usb_suspend_intr function.") Cc: [email protected] Signed-off-by: Tomas Marek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1702bec commit 2c6b6af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/usb/dwc2/drd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
127127
role = USB_ROLE_DEVICE;
128128
}
129129

130+
if ((IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) ||
131+
IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)) &&
132+
dwc2_is_device_mode(hsotg) &&
133+
hsotg->lx_state == DWC2_L2 &&
134+
hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
135+
hsotg->bus_suspended &&
136+
!hsotg->params.no_clock_gating)
137+
dwc2_gadget_exit_clock_gating(hsotg, 0);
138+
130139
if (role == USB_ROLE_HOST) {
131140
already = dwc2_ovr_avalid(hsotg, true);
132141
} else if (role == USB_ROLE_DEVICE) {

0 commit comments

Comments
 (0)