linux/drivers/usb/dwc2
Fabrice Gasnier 5021383242 usb: dwc2: fix a race, don't power off/on phy for dual-role mode
When in dual role mode (dr_mode == USB_DR_MODE_OTG), platform probe
successively basically calls:
- dwc2_gadget_init()
- dwc2_hcd_init()
- dwc2_lowlevel_hw_disable() since recent change [1]
- usb_add_gadget_udc()

The PHYs (and so the clocks it may provide) shouldn't be disabled for all
SoCs, in OTG mode, as the HCD part has been initialized.

On STM32 this creates some weird race condition upon boot, when:
- initially attached as a device, to a HOST
- and there is a gadget script invoked to setup the device part.
Below issue becomes systematic, as long as the gadget script isn't
started by userland: the hardware PHYs (and so the clocks provided by the
PHYs) remains disabled.
It ends up in having an endless interrupt storm, before the watchdog
resets the platform.

[   16.924163] dwc2 49000000.usb-otg: EPs: 9, dedicated fifos, 952 entries in SPRAM
[   16.962704] dwc2 49000000.usb-otg: DWC OTG Controller
[   16.966488] dwc2 49000000.usb-otg: new USB bus registered, assigned bus number 2
[   16.974051] dwc2 49000000.usb-otg: irq 77, io mem 0x49000000
[   17.032170] hub 2-0:1.0: USB hub found
[   17.042299] hub 2-0:1.0: 1 port detected
[   17.175408] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[   17.181741] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[   17.189303] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
...

The host part is also not functional, until the gadget part is configured.

The HW may only be disabled for peripheral mode (original init), e.g.
dr_mode == USB_DR_MODE_PERIPHERAL, until the gadget driver initializes.

But when in USB_DR_MODE_OTG, the HW should remain enabled, as the HCD part
is able to run, while the gadget part isn't necessarily configured.

I don't fully get the of purpose the original change, that claims disabling
the hardware is missing. It creates conditions on SOCs using the PHY
initialization to be completely non working in OTG mode. Original
change [1] should be reworked to be platform specific.

[1] https://lore.kernel.org/r/20221206-dwc2-gadget-dual-role-v1-2-36515e1092cd@theobroma-systems.com

Fixes: ade23d7b7e ("usb: dwc2: power on/off phy for peripheral mode in dual-role mode")
Cc: stable <stable@kernel.org>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Reviewed-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Tested-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Link: https://lore.kernel.org/r/20230315144433.3095859-1-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-23 19:13:16 +01:00
..
core_intr.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
core.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
core.h usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
debug.h USB: dwc2: Use the correct style for SPDX License Identifier 2020-05-05 10:58:50 +03:00
debugfs.c usb: dwc2: add otg_rev and otg_caps information for gadget driver 2021-10-25 09:20:26 +02:00
drd.c usb: dwc2: drd: fix inconsistent mode if role-switch-default-mode="host" 2023-03-09 15:38:24 +01:00
gadget.c usb: dwc2: fix a race, don't power off/on phy for dual-role mode 2023-03-23 19:13:16 +01:00
hcd_ddma.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
hcd_intr.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
hcd_queue.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
hcd.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
hcd.h usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
hw.h usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
Kconfig usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
Makefile usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
params.c usb: dwc2: disable lpm feature on Rockchip SoCs 2022-12-08 16:50:56 +01:00
pci.c usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
platform.c usb: dwc2: fix a race, don't power off/on phy for dual-role mode 2023-03-23 19:13:16 +01:00