From 31815b74ffdcd3979ba075e04f39e7fb704957f8 Mon Sep 17 00:00:00 2001 From: Edward Hill Date: Mon, 4 Jun 2018 11:12:16 -0600 Subject: sn5s330: Track source enabled state locally sn5s330_init() will turn off the PP1 (source) FET, but sn5s330_is_sourcing_vbus() can be called before PPC init: by usb_charger_init() and pd_power_supply_reset() from pd_task(). Keep track of the PP1 (source) FET state locally, and use this for sn5s330_is_sourcing_vbus(), instead of reading the state from the PPC chip over I2C every time. This solves the problem of sn5s330_is_sourcing_vbus() being called before sn5s330_init(), and also avoids other problems caused by sn5s330_is_sourcing_vbus() doing I2C communication: crrev.com/c/969701/7/board/cheza/board.c#85 BUG=b:80203727 BRANCH=none TEST=Reboot Grunt EC while one USB-C port is VBUS source. Change-Id: Ie0fdd3d672bc747fcdbb746586149e194165fdac Signed-off-by: Edward Hill Reviewed-on: https://chromium-review.googlesource.com/1086115 Commit-Ready: ChromeOS CL Exonerator Bot Reviewed-by: Jett Rink --- driver/ppc/sn5s330.c | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'driver/ppc') diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c index c20a665f75..07ff202436 100644 --- a/driver/ppc/sn5s330.c +++ b/driver/ppc/sn5s330.c @@ -26,6 +26,7 @@ #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) static uint32_t irq_pending; /* Bitmask of ports signaling an interrupt. */ +static int source_enabled[CONFIG_USB_PD_PORT_COUNT]; static int read_reg(uint8_t port, int reg, int *regval) { @@ -132,29 +133,6 @@ static int get_func_set3(uint8_t port, int *regval) return status; } -static int sn5s330_is_pp_fet_enabled(uint8_t port, enum sn5s330_pp_idx pp, - int *is_enabled) -{ - int pp_bit; - int status; - int regval; - - if (pp == SN5S330_PP1) - pp_bit = SN5S330_PP1_EN; - else if (pp == SN5S330_PP2) - pp_bit = SN5S330_PP2_EN; - else - return EC_ERROR_INVAL; - - status = get_func_set3(port, ®val); - if (status) - return status; - - *is_enabled = !!(pp_bit & regval); - - return EC_SUCCESS; -} - static int sn5s330_pp_fet_enable(uint8_t port, enum sn5s330_pp_idx pp, int enable) { @@ -184,6 +162,9 @@ static int sn5s330_pp_fet_enable(uint8_t port, enum sn5s330_pp_idx pp, return status; } + if (pp == SN5S330_PP1) + source_enabled[port] = enable; + return EC_SUCCESS; } @@ -466,17 +447,7 @@ static int sn5s330_is_vbus_present(int port) static int sn5s330_is_sourcing_vbus(int port) { - int is_sourcing_vbus = 0; - int rv; - - rv = sn5s330_is_pp_fet_enabled(port, SN5S330_PP1, &is_sourcing_vbus); - if (rv) { - CPRINTS("ppc p%d: Failed to determine source FET status! (%d)", - port, rv); - return 0; - } - - return is_sourcing_vbus; + return source_enabled[port]; } #ifdef CONFIG_USBC_PPC_POLARITY -- cgit v1.2.1