From 103108ec216e67a4937d9a51f7134d4923dd31f5 Mon Sep 17 00:00:00 2001 From: Dino Li Date: Thu, 7 Sep 2017 10:47:44 +0800 Subject: tcpm: it83xx: enable cc voltage detector after vconn is offed We found a potential risk that voltage might fed back into EC Vcore. If the CC pin voltage detector is enabled and there is an unexpected voltage source over 3.3v fed back into EC, this might cause an exception or unknown reset. BRANCH=none BUG=none TEST=The voltage detector is enabled after vconn is offed. Change-Id: I78975fa195eef0b96056a39ee3c6d92c3bb6f8c0 Signed-off-by: Dino Li Reviewed-on: https://chromium-review.googlesource.com/647673 Reviewed-by: Randall Spangler --- driver/tcpm/it83xx.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/driver/tcpm/it83xx.c b/driver/tcpm/it83xx.c index e1593b0d89..c8c2edbc38 100644 --- a/driver/tcpm/it83xx.c +++ b/driver/tcpm/it83xx.c @@ -17,6 +17,11 @@ #include "usb_pd.h" #include "usb_pd_tcpm.h" +/* Wait time for vconn power switch to turn off. */ +#ifndef PD_IT83XX_VCONN_TURN_OFF_DELAY_US +#define PD_IT83XX_VCONN_TURN_OFF_DELAY_US 500 +#endif + const struct usbpd_ctrl_t usbpd_ctrl_regs[] = { {&IT83XX_GPIO_GPCRF4, &IT83XX_GPIO_GPCRF5, IT83XX_IRQ_USBPD0}, {&IT83XX_GPIO_GPCRH1, &IT83XX_GPIO_GPCRH2, IT83XX_IRQ_USBPD1}, @@ -404,12 +409,23 @@ static int it83xx_tcpm_set_polarity(int port, int polarity) static int it83xx_tcpm_set_vconn(int port, int enable) { #ifdef CONFIG_USBC_VCONN - it83xx_enable_vconn(port, enable); - /* vconn switch */ + /* Disable cc voltage detector and enable 5v tolerant. */ + if (enable) + it83xx_enable_vconn(port, enable); + /* Turn on/off vconn power switch. */ board_pd_vconn_ctrl(port, USBPD_GET_PULL_CC_SELECTION(port) ? USBPD_CC_PIN_2 : USBPD_CC_PIN_1, enable); + if (!enable) { + /* + * We need to make sure cc voltage detector is enabled after + * vconn is turned off to avoid the potential risk of voltage + * fed back into Vcore. + */ + usleep(PD_IT83XX_VCONN_TURN_OFF_DELAY_US); + it83xx_enable_vconn(port, enable); + } #endif return EC_SUCCESS; -- cgit v1.2.1