From d1b3ebc265a2631edee3ea0d9ab8da0d2f5ad246 Mon Sep 17 00:00:00 2001 From: Diana Z Date: Wed, 24 Oct 2018 14:32:07 -0600 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/1298400 Reviewed-by: Scott Collyer Reviewed-by: Furquan Shaikh Reviewed-by: Jett Rink --- driver/ppc/nx20p348x.c | 21 +++++++++++++-------- 1 file 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; } -- cgit v1.2.1