Skip to content

Commit 82f5332

Browse files
hzyitcgregkh
authored andcommitted
usb: dwc2: drd: fix inconsistent mode if role-switch-default-mode="host"
Some boards might use USB-A female connector for USB ports, however, the port could be connected to a dual-mode USB controller, making it also behaves as a peripheral device if male-to-male cable is connected. In this case, the dts looks like this: &usb0 { status = "okay"; dr_mode = "otg"; usb-role-switch; role-switch-default-mode = "host"; }; After boot, dwc2_ovr_init() sets GOTGCTL to GOTGCTL_AVALOVAL and call dwc2_force_mode() with parameter host=false, which causes inconsistent mode - The hardware is in peripheral mode while the kernel status is in host mode. What we can do now is to call dwc2_drd_role_sw_set() to switch to device mode, and everything should work just fine now, even switching back to none(default) mode afterwards. Fixes: e14acb8 ("usb: dwc2: drd: add role-switch-default-node support") Cc: stable <[email protected]> Signed-off-by: Ziyang Huang <[email protected]> Tested-by: Fabrice Gasnier <[email protected]> Acked-by: Minas Harutyunyan <[email protected]> Reviewed-by: Amelie Delaunay <[email protected]> Link: https://lore.kernel.org/r/SG2PR01MB204837BF68EDB0E343D2A375C9A59@SG2PR01MB2048.apcprd01.prod.exchangelabs.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 094f391 commit 82f5332

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/usb/dwc2/drd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static void dwc2_ovr_init(struct dwc2_hsotg *hsotg)
3535

3636
spin_unlock_irqrestore(&hsotg->lock, flags);
3737

38-
dwc2_force_mode(hsotg, (hsotg->dr_mode == USB_DR_MODE_HOST));
38+
dwc2_force_mode(hsotg, (hsotg->dr_mode == USB_DR_MODE_HOST) ||
39+
(hsotg->role_sw_default_mode == USB_DR_MODE_HOST));
3940
}
4041

4142
static int dwc2_ovr_avalid(struct dwc2_hsotg *hsotg, bool valid)

0 commit comments

Comments
 (0)