diff options
author | Diana Z <dzigterman@chromium.org> | 2020-09-22 16:57:03 -0600 |
---|---|---|
committer | Justin TerAvest <teravest@chromium.org> | 2020-10-01 23:04:47 +0000 |
commit | 8b05bdfc38ccc2b1eb694ad4d41096e08a5116c4 (patch) | |
tree | 243ed41da6da51bed4b650049a185536f0dd5243 /common/mock/tcpc_mock.c | |
parent | 9b4f53e42e7bfcb2d045eca422b0097cc309a8d2 (diff) | |
download | chrome-ec-8b05bdfc38ccc2b1eb694ad4d41096e08a5116c4.tar.gz |
TCPMv2: Add VBUS_REMOVED level
For boards which use Vbus ADCs, add a VBUS_REMOVED check level. The
level for VBUS_PRESENT should be used in any locations looking for
"Vbus is present" on transition, but in order to correctly detect
disconnection with a load on Vbus, VBUS_REMOVED (vSinkDisconnect)
is required. TODO statements have been added for places where work
will be needed to support vSinkDisconnectPD in the future.
For boards detecting Vbus through an external chip, the levels will
likely be indistinguishable due to the chips setting a lower threshold
for disconnect than for connection.
Unit test code has also been added to encourage new Vbus levels to be
added to the mock, and remind developers to update all locations using
the vbus_level enum.
BRANCH=None
BUG=b:168831161
TEST=make -j buildall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I04014ce54ec162dd9c62f545126d921c6d880741
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2436580
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'common/mock/tcpc_mock.c')
-rw-r--r-- | common/mock/tcpc_mock.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/common/mock/tcpc_mock.c b/common/mock/tcpc_mock.c index 64a1ce01cf..457868c96a 100644 --- a/common/mock/tcpc_mock.c +++ b/common/mock/tcpc_mock.c @@ -8,6 +8,7 @@ #include "console.h" #include "memory.h" #include "mock/tcpc_mock.h" +#include "test_util.h" #include "tests/enum_strings.h" #include "timer.h" #include "usb_pd_tcpm.h" @@ -51,8 +52,17 @@ static bool mock_check_vbus_level(int port, enum vbus_level level) { if (level == VBUS_PRESENT) return mock_tcpc.vbus_level; - else + else if (level == VBUS_SAFE0V || level == VBUS_REMOVED) return !mock_tcpc.vbus_level; + + /* + * Unknown vbus_level was added, force a failure. + * Note that TCPC drivers and pd_check_vbus_level() implementations + * should be carefully checked on new level additions in case they + * need updated. + */ + ccprints("[TCPC] Unhandled Vbus check %d", level); + TEST_ASSERT(0); } static int mock_select_rp_value(int port, int rp) |