diff options
author | Diana Z <dzigterman@chromium.org> | 2018-10-24 14:32:07 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-25 15:19:04 -0700 |
commit | d1b3ebc265a2631edee3ea0d9ab8da0d2f5ad246 (patch) | |
tree | 7b16e0cefd00fe7257b0e972f019dd29bbd37384 | |
parent | a8aeccd43fb34fac1c69a935d1d88b71befdf854 (diff) | |
download | chrome-ec-d1b3ebc265a2631edee3ea0d9ab8da0d2f5ad246.tar.gz |
Octopus: Vbus gone from USB-C port after cold reboot with USB-A drive
When Vbus turns on while we're in the process of running
nx20p348x_vbus_source_enable(), a sink can incorrectly be detected as a
charger. This change moves the initialization of the flag indicating
we're attempting to source Vbus, and will restore the previous flag
state on failure.
BRANCH=None
BUG=b:117616479
TEST=on yorp, cold booted with USB key and saw it was not detected as a
charger on both ports, cold booted with actual charger to verify it was
correctly detected on both ports
Change-Id: Ie8de18f4b4cd335118d5d44e1476b0ececbcc029
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1298400
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | driver/ppc/nx20p348x.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/driver/ppc/nx20p348x.c b/driver/ppc/nx20p348x.c index 48ee5ca9b2..18523c196b 100644 --- a/driver/ppc/nx20p348x.c +++ b/driver/ppc/nx20p348x.c @@ -167,6 +167,7 @@ static int nx20p348x_vbus_source_enable(int port, int enable) { int status; int rv; + uint8_t previous_flags = flags[port]; int control = enable ? NX20P348X_SWITCH_CONTROL_5VSRC : 0; enable = !!enable; @@ -185,6 +186,12 @@ static int nx20p348x_vbus_source_enable(int port, int enable) if (rv) return rv; + /* Cache the anticipated Vbus state */ + if (enable) + flags[port] |= NX20P348X_FLAGS_SOURCE_ENABLED; + else + flags[port] &= ~NX20P348X_FLAGS_SOURCE_ENABLED; + /* * Read switch status register. The bit definitions for switch control * and switch status resister are identical, so the control value can be @@ -193,17 +200,15 @@ static int nx20p348x_vbus_source_enable(int port, int enable) */ msleep(NX20P348X_SWITCH_STATUS_DEBOUNCE_MSEC); rv = read_reg(port, NX20P348X_SWITCH_STATUS_REG, &status); - if (rv) + if (rv) { + flags[port] = previous_flags; return rv; + } - if ((status & NX20P348X_SWITCH_STATUS_MASK) != control) + if ((status & NX20P348X_SWITCH_STATUS_MASK) != control) { + flags[port] = previous_flags; return EC_ERROR_UNKNOWN; - - /* Cache the Vbus state */ - if (enable) - flags[port] |= NX20P348X_FLAGS_SOURCE_ENABLED; - else - flags[port] &= ~NX20P348X_FLAGS_SOURCE_ENABLED; + } return EC_SUCCESS; } |