From c03b975591d68ae87fdcec339b33f81ce92f1f29 Mon Sep 17 00:00:00 2001 From: William Wu Date: Wed, 24 Feb 2021 17:27:02 +0800 Subject: [PATCH] phy: rockchip: inno-usb2: fix charger detection error We found a charger detection error on RK3566 Tablet. 1. Plug in a Type-C to Type-A cable and connect to PC USB Host or USB charger, then the charger detection is normal. 2. Plug out the cable, then the charger disconnection detection is normal. 3. Plug in a Type-C to Type-A receptacle and plug out again. Then the charger is detected unexpectedly. To fix this issue, reinitialize the cable state of USB charger to EXTCON_NONE when USB charger is disconnected. Signed-off-by: William Wu Change-Id: Ic56e4ee865af129c222f4c90c3d6e753f4e785bd --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 4deac4c71695..bd6cf4a14de2 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -1125,11 +1125,14 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) return; } - if (extcon_get_state(rphy->edev, cable) != rport->vbus_attached) + if (extcon_get_state(rphy->edev, cable) != rport->vbus_attached) { extcon_set_state_sync(rphy->edev, cable, rport->vbus_attached); - else if (rport->state == OTG_STATE_A_HOST && - extcon_get_state(rphy->edev, cable)) + + if (!rport->vbus_attached) + cable = EXTCON_NONE; + } else if (rport->state == OTG_STATE_A_HOST && + extcon_get_state(rphy->edev, cable)) { /* * If plug in OTG host cable when the rport state is * OTG_STATE_B_PERIPHERAL, the vbus voltage will stay @@ -1137,6 +1140,8 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) * changed. We need to set cable state here. */ extcon_set_state_sync(rphy->edev, cable, false); + cable = EXTCON_NONE; + } if (rphy->edev_self && (extcon_get_state(rphy->edev, EXTCON_USB) !=