From 915826d69199d56319a028f3eec4e0e03a46263b Mon Sep 17 00:00:00 2001 From: William Wu Date: Wed, 29 May 2024 15:41:17 +0800 Subject: [PATCH] phy: rockchip: inno-usb2: Clear charger state in host mode Test on RK3576 Tablet Android 14 GKI, when plug in U disk, it will trigger the usb2 phy to do charging detection logic in the following process. 1. Type-C PD controller chip (e.g HUSB311) detect DFP mode; 2. Type-C tcpm call usb_role_switch_set_role() to notify the usb controller to set USB_ROLE_HOST; 3. The usb dwc3 controller driver do dwc3_set_mode() to initialize the controller and phy for host mode; 4. In the __dwc3_set_mode(), it do pm_runtime_get_sync() -> dwc3_runtime_resume() -> dwc3_resume_common() -> dwc3_core_init() -> phy_init(dwc->usb2_generic_phy); 5. In the usb2 phy driver, it do rockchip_usb2phy_init() -> schedule otg_sm_work -> rockchip_chg_detect_work() 6. Detect dcp cable is connected, and call extcon_set_state_sync() to send charger notification with true state. Later, if plug out the U disk and plug in a USB charger, it will fail to send charger notification because its extcon state still in true state. To fix this issue, we need to clear the charger state in the otg_sm_work if it's already in host mode. Signed-off-by: William Wu Change-Id: I6a30429162290927cae3e5f3495f51db61bf15b6 --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 7345cc289193..c1c1a79e54c5 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -1253,6 +1253,10 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; mutex_unlock(&rport->mutex); rockchip_usb2phy_power_on(rport->phy); + if (extcon_get_state(rphy->edev, cable)) { + extcon_set_state_sync(rphy->edev, cable, false); + cable = EXTCON_NONE; + } return; } else if (rport->vbus_attached) { dev_dbg(&rport->phy->dev, "vbus_attach\n");