linux/drivers/phy
Louis Chauvet 028e8ca7b2 phy: rockchip: inno-usb2: fix disconnection in gadget mode
When the OTG USB port is used to power the SoC, configured as peripheral
and used in gadget mode, there is a disconnection about 6 seconds after the
gadget is configured and enumerated.

The problem was observed on a Radxa Rock Pi S board, which can only be
powered by the only USB-C connector. That connector is the only one usable
in gadget mode. This implies the USB cable is connected from before boot
and never disconnects while the kernel runs.

The problem happens because of the PHY driver code flow, summarized as:

 * UDC start code (triggered via configfs at any time after boot)
   -> phy_init
       -> rockchip_usb2phy_init
           -> schedule_delayed_work(otg_sm_work [A], 6 sec)
   -> phy_power_on
       -> rockchip_usb2phy_power_on
           -> enable clock
           -> rockchip_usb2phy_reset

 * Now the gadget interface is up and running.

 * 6 seconds later otg_sm_work starts [A]
   -> rockchip_usb2phy_otg_sm_work():
       if (B_IDLE state && VBUS present && ...):
           schedule_delayed_work(&rport->chg_work [B], 0);

 * immediately the chg_detect_work starts [B]
   -> rockchip_chg_detect_work():
       if chg_state is UNDEFINED:
           if (!rport->suspended):
               rockchip_usb2phy_power_off() <--- [X]

At [X], the PHY is powered off, causing a disconnection. This quickly
triggers a new connection and following re-enumeration, but any connection
that had been established during the 6 seconds is broken.

The code already checks for !rport->suspended (which, somewhat
counter-intuitively, means the PHY is powered on), so add a guard for VBUS
as well to avoid a disconnection when a cable is connected.

Fixes: 98898f3bc8 ("phy: rockchip-inno-usb2: support otg-port for rk3399")
Cc: stable@vger.kernel.org
Closes: https://lore.kernel.org/lkml/20250414185458.7767aabc@booty/
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
Co-developed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://patch.msgid.link/20251127-rk3308-fix-usb-gadget-phy-disconnect-v2-1-dac8a02cd2ca@bootlin.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
2025-12-23 22:56:07 +05:30
..
allwinner phy: sun4i-usb: drop num_phys assumption 2025-08-20 21:43:33 +05:30
amlogic phy: amlogic: phy-meson-axg-pcie: Fix PHY creation order in axg-pcie probe 2025-04-11 17:07:15 +05:30
broadcom phy: broadcom: bcm63xx-usbh: fix section mismatches 2025-11-20 22:01:55 +05:30
cadence phy: cadence: cdns-dphy: Enable lower resolutions in dphy 2025-09-10 21:22:22 +05:30
freescale phy: fsl-imx8mq-usb: Clear the PCS_TX_SWING_FULL field before using it 2025-12-23 20:53:45 +05:30
hisilicon phy: hisilicon: Remove redundant ternary operators 2025-09-01 18:13:54 +05:30
ingenic phy: ingenic: use core driver model helper to handle probe errors 2025-08-20 22:25:38 +05:30
intel phy: Switch back to struct platform_driver::remove() 2024-10-17 20:33:03 +05:30
lantiq phy: constify of_phandle_args in xlate 2024-02-23 17:43:14 +05:30
marvell phy: drop probe registration printks 2025-06-16 22:54:21 +05:30
mediatek phy: mediatek: tphy: Cleanup and document slew calibration 2025-06-26 16:33:42 -07:00
microchip phy: sparx5-serdes: make it selectable for ARCH_LAN969X 2025-12-23 22:52:42 +05:30
motorola phy: mapphone-mdm6600: use gpiod_multi_set_value_cansleep 2025-02-17 14:27:34 +01:00
mscc phy: constify of_phandle_args in xlate 2024-02-23 17:43:14 +05:30
nuvoton phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-29 23:52:37 +05:30
qualcomm phy: qcom-qusb2: Fix NULL pointer dereference on early suspend 2025-12-23 20:59:13 +05:30
ralink phy: constify of_phandle_args in xlate 2024-02-23 17:43:14 +05:30
realtek USB / Thunderbolt (USB4) changes for 6.13-rc1 2024-11-29 11:19:31 -08:00
renesas phy: renesas: Remove unneeded semicolons 2025-11-20 22:19:11 +05:30
rockchip phy: rockchip: inno-usb2: fix disconnection in gadget mode 2025-12-23 22:56:07 +05:30
samsung phy: exynos5-usbdrd: fix clock prepare imbalance 2025-11-20 22:10:17 +05:30
socionext phy: constify of_phandle_args in xlate 2024-02-23 17:43:14 +05:30
sophgo phy: sophgo: Remove unused of_gpio.h 2025-11-12 20:35:50 +05:30
st phy: stm32-usphyc: Fix off by one in probe() 2025-12-23 21:53:45 +05:30
starfive phy: starfive: jh7110-usb: Fix USB 2.0 host occasional detection failure 2025-05-14 09:45:12 +01:00
sunplus phy: sunplus: return negative error code in sp_usb_phy_probe 2023-11-27 18:39:18 +05:30
tegra phy: tegra: xusb: fix device and OF node leak at probe 2025-08-12 21:30:00 +05:30
ti phy: ti: gmii-sel: fix regmap leak on probe failure 2025-12-23 22:54:58 +05:30
xilinx phy-zynqmp: Postpone getting clock rate until actually needed 2025-05-14 09:48:01 +01:00
Kconfig phy: sophgo: Add USB 2.0 PHY driver for Sophgo CV18XX/SG200X 2025-09-10 20:52:42 +05:30
Makefile phy: sophgo: Add USB 2.0 PHY driver for Sophgo CV18XX/SG200X 2025-09-10 20:52:42 +05:30
phy-airoha-pcie-regs.h phy: airoha: Fix REG_CSR_2L_RX{0,1}_REV0 definitions 2024-10-17 20:52:48 +05:30
phy-airoha-pcie.c phy: airoha: Fix REG_CSR_2L_JCPLL_SDM_HREN config in airoha_pcie_phy_init_ssc_jcpll() 2024-10-17 20:52:48 +05:30
phy-can-transceiver.c phy: phy-can-transceiver: Add support for TJA105{1,7} 2025-11-12 20:11:16 +05:30
phy-core-mipi-dphy.c phy: dphy: add support to calculate the timing based on hs_clk_rate 2022-10-27 14:38:04 +03:00
phy-core.c phy: core: Remove extra space after '=' 2025-11-18 22:28:34 +05:30
phy-lgm-usb.c phy: Switch back to struct platform_driver::remove() 2024-10-17 20:33:03 +05:30
phy-lpc18xx-usb-otg.c
phy-nxp-ptn3222.c phy: add NXP PTN3222 eUSB2 to USB2 redriver 2024-10-17 20:48:27 +05:30
phy-pistachio-usb.c
phy-snps-eusb2.c phy-for-6.17 2025-08-01 12:31:50 -07:00
phy-xgene.c phy: constify of_phandle_args in xlate 2024-02-23 17:43:14 +05:30