From ae40b0d68c1dd02dafdb0ed4777747878655beff Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Fri, 31 Jul 2020 14:03:44 +0800 Subject: usb_pd: disable Vconn of PPC first then TCPC Disabling PPC's Vconn first in case the PPC's Vconn feed back to TCPC. On ITE EC, its CC pins have multi-function (analog module), and it needs to disable PPC's Vconn then can safely disable the 5V tolerance on the CC pin. Switching the PPC disable order should have no effect to the other TCPCs. BUG=b:162294637 TEST=On asurada(ITE EC) and lazor(NPCX EC), Vconn is enabled and disabled on hub plug/unplug BRANCH=none Change-Id: If2af04931d00c5c8a52908a3391a482a7571b5fc Signed-off-by: Eric Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2331987 Reviewed-by: Jett Rink Reviewed-by: Ting Shen --- common/usb_pd_protocol.c | 13 ++++++++++--- common/usbc/usb_tc_drp_acc_trysrc_sm.c | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index b3be338d64..ececdde8ed 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -423,6 +423,13 @@ void pd_vbus_low(int port) #ifdef CONFIG_USBC_VCONN static void set_vconn(int port, int enable) { + /* + * Disable PPC Vconn first then TCPC in case the voltage feeds back + * to TCPC and damages. + */ + if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && !enable) + ppc_set_vconn(port, 0); + /* * We always need to tell the TCPC to enable Vconn first, otherwise some * TCPCs get confused when a PPC sets secondary CC line to 5V and TCPC @@ -431,9 +438,9 @@ static void set_vconn(int port, int enable) * "make before break" electrical requirements when swapping anyway. */ tcpm_set_vconn(port, enable); -#ifdef CONFIG_USBC_PPC_VCONN - ppc_set_vconn(port, enable); -#endif + + if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && enable) + ppc_set_vconn(port, 1); } #endif /* defined(CONFIG_USBC_VCONN) */ diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 7491250088..a72b99a155 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -1507,6 +1507,13 @@ static void set_vconn(int port, int enable) else TC_CLR_FLAG(port, TC_FLAGS_VCONN_ON); + /* + * Disable PPC Vconn first then TCPC in case the voltage feeds back + * to TCPC and damages. + */ + if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && !enable) + ppc_set_vconn(port, 0); + /* * We always need to tell the TCPC to enable Vconn first, otherwise some * TCPCs get confused and think the CC line is in over voltage mode and @@ -1516,8 +1523,8 @@ static void set_vconn(int port, int enable) */ tcpm_set_vconn(port, enable); - if (IS_ENABLED(CONFIG_USBC_PPC_VCONN)) - ppc_set_vconn(port, enable); + if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && enable) + ppc_set_vconn(port, 1); } /* This must only be called from the PD task */ -- cgit v1.2.1