diff options
author | Jett Rink <jettrink@chromium.org> | 2018-07-17 15:50:44 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-19 12:13:57 -0700 |
commit | a6c2aec430dd4e614f104303cd2b998d5f82297c (patch) | |
tree | 27e32aae02265b0a6f5697a95071e449ddcac74f /driver | |
parent | 1e1dea7c3af29801bf853c60a960dd07b4920f3b (diff) | |
download | chrome-ec-a6c2aec430dd4e614f104303cd2b998d5f82297c.tar.gz |
nx20: track vbus sourcing state locally
This solves as few problems:
- We do not need to perform "expensive" i2c communication when we need
to determine the state of Vbus that we previously set.
-- This allows the is_sourcing_vbus call to be performed in an interrupt
context (see crrev.com/c/969701/7/board/cheza/board.c#85).
- This prevents the problem of the is_sourcing_vbus from being called
before init after a sysjump thus potentially preventing power on
(see b:80203727).
- This also papers over an issue where the TCPC stops sourcing Vbus
without our consent, because the logic work correctly if vbus is in the
same state we last set it to (see b:111404471)
This caching paradigm is apply to tcpc vbus level and other ppc is vbus
being sourced (See CL:1086115)
BRANCH=none
BUG=b:111404471
TEST=Vbus on phaser's C1 discharges correctly
Change-Id: I9c19c3d177a4a4e49be4372e8b01d84fcf2a0c4b
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1141111
Diffstat (limited to 'driver')
-rw-r--r-- | driver/ppc/nx20p3483.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/driver/ppc/nx20p3483.c b/driver/ppc/nx20p3483.c index e5d0055140..1a6a41bb04 100644 --- a/driver/ppc/nx20p3483.c +++ b/driver/ppc/nx20p3483.c @@ -21,11 +21,14 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define NX20P3483_DB_EXIT_FAIL_THRESHOLD 10 - static uint32_t irq_pending; /* Bitmask of ports signaling an interrupt. */ + +#define NX20P3483_DB_EXIT_FAIL_THRESHOLD 10 static int db_exit_fail_count[CONFIG_USB_PD_PORT_COUNT]; +#define NX20P3483_FLAGS_SOURCE_ENABLED (1 << 0) +static uint8_t flags[CONFIG_USB_PD_PORT_COUNT]; + static int read_reg(uint8_t port, int reg, int *regval) { return i2c_read8(ppc_chips[port].i2c_port, @@ -64,17 +67,7 @@ static int nx20p3483_set_ovp_limit(int port) static int nx20p3483_is_sourcing_vbus(int port) { - int mode; - int rv; - - rv = read_reg(port, NX20P3483_DEVICE_STATUS_REG, &mode); - if (rv) { - CPRINTS("p%d: Failed to determine NX20P device status! (%d)", - port, rv); - return 0; - } - - return ((mode & NX20P3483_DEVICE_MODE_MASK) == NX20P3483_MODE_5V_SRC); + return flags[port] & NX20P3483_FLAGS_SOURCE_ENABLED; } static int nx20p3483_set_vbus_source_current_limit(int port, @@ -201,8 +194,16 @@ static int nx20p3483_vbus_source_enable(int port, int enable) if (rv) return rv; - return ((status & NX20P3483_DEVICE_MODE_MASK) == desired_mode) ? - EC_SUCCESS : EC_ERROR_UNKNOWN; + if ((status & NX20P3483_DEVICE_MODE_MASK) != desired_mode) + return EC_ERROR_UNKNOWN; + + /* Cache the Vbus state */ + if (enable) + flags[port] |= NX20P3483_FLAGS_SOURCE_ENABLED; + else + flags[port] &= ~NX20P3483_FLAGS_SOURCE_ENABLED; + + return EC_SUCCESS; } static int nx20p3483_init(int port) |