From e3297d725517de90a657e157f3ceafe53b2b13f2 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Fri, 29 Jul 2016 11:25:09 +0800 Subject: [PATCH] anx7688: Add custom vbus function On ANX7688, POWER_STATUS.VBusPresent is averaged 16 times, so its value may not be set to 1 quickly enough during power role swap. Therefore, we use a proprietary register to read the unfiltered VBus value. BRANCH=oak BUG=chrome-os-partner:55221 TEST=LG monitor works over type-C, power role swap looks good Change-Id: I68572c34440be65882f431bb892ed032da05bd0a Reviewed-on: https://chromium-review.googlesource.com/364351 Commit-Ready: Nicolas Boichat Tested-by: Nicolas Boichat Reviewed-by: Vincent Palatin --- driver/tcpm/anx7688.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/driver/tcpm/anx7688.c b/driver/tcpm/anx7688.c index 7e499629a8..ae1dd32124 100644 --- a/driver/tcpm/anx7688.c +++ b/driver/tcpm/anx7688.c @@ -160,12 +160,27 @@ static int anx7688_mux_set(int i2c_addr, mux_state_t mux_state) return tcpc_write(port, TCPC_REG_CONFIG_STD_OUTPUT, reg); } +#ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC +static int anx7688_tcpm_get_vbus_level(int port) +{ + int reg = 0; + + /* On ANX7688, POWER_STATUS.VBusPresent (bit 2) is averaged 16 times, so + * its value may not be set to 1 quickly enough during power role swap. + * Therefore, we use a proprietary register to read the unfiltered VBus + * value. See crosbug.com/p/55221 . + */ + i2c_read8(I2C_PORT_TCPC, 0x50, 0x40, ®); + return ((reg & 0x10) ? 1 : 0); +} +#endif + /* ANX7688 is a TCPCI compatible port controller */ const struct tcpm_drv anx7688_tcpm_drv = { .init = &anx7688_init, .get_cc = &tcpci_tcpm_get_cc, #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC - .get_vbus_level = &tcpci_tcpm_get_vbus_level, + .get_vbus_level = &anx7688_tcpm_get_vbus_level, #endif .set_cc = &tcpci_tcpm_set_cc, .set_polarity = &tcpci_tcpm_set_polarity,