diff options
author | Abe Levkoy <alevkoy@chromium.org> | 2021-10-27 16:13:17 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-28 19:01:18 +0000 |
commit | 3deccd4a73122a5da91a9d47b4983ec426eca73c (patch) | |
tree | b765b993ea8a8f5551f633a13d3a82bd1b0e6538 | |
parent | a645d15ee4a2341ebdae05481c3fad0139c8d7fd (diff) | |
download | chrome-ec-3deccd4a73122a5da91a9d47b4983ec426eca73c.tar.gz |
zephyr test: SYV682x VBAT_OVP interrupt
Emulate VCONN over-voltage conditions. Check that the driver handles
them by reinitializing the PPC. Increase syv682x.c line coverage from
68.8% to 70.3%.
BUG=b:190519131
TEST=zmake configure --test zephyr/test/drivers
BRANCH=none
Signed-off-by: Abe Levkoy <alevkoy@chromium.org>
Change-Id: I172aade75df8b52202c3a214a44423d899cca7ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3249159
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | zephyr/emul/emul_syv682x.c | 8 | ||||
-rw-r--r-- | zephyr/test/drivers/src/ppc.c | 26 |
2 files changed, 34 insertions, 0 deletions
diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c index 2bc18b7089..3a4aba8189 100644 --- a/zephyr/emul/emul_syv682x.c +++ b/zephyr/emul/emul_syv682x.c @@ -100,6 +100,14 @@ void syv682x_emul_set_control_4(struct i2c_emul *emul, uint8_t val) * current. The latter behavior is observed in practice, and this * emulator does not currently model it. */ + + /* VBAT_OVP disconnects CC and VCONN. */ + if (val_interrupt & SYV682X_CONTROL_4_VBAT_OVP) { + data->reg[SYV682X_CONTROL_4_REG] &= ~(SYV682X_CONTROL_4_CC1_BPS + | SYV682X_CONTROL_4_CC2_BPS + | SYV682X_CONTROL_4_VCONN1 + | SYV682X_CONTROL_4_VCONN2); + } } int syv682x_emul_get_reg(struct i2c_emul *emul, int reg, uint8_t *val) diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c index d8d5550f56..9c1d77a21c 100644 --- a/zephyr/test/drivers/src/ppc.c +++ b/zephyr/test/drivers/src/ppc.c @@ -168,6 +168,32 @@ static void test_ppc_syv682x_interrupt(void) (SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2), "VCONN enabled after long VCONN OC"); syv682x_emul_set_control_4(emul, 0x0); + + /* + * A VCONN over-voltage (VBAT_OVP) event will cause the device to + * disconnect CC and VCONN. The driver should then reinitialize the + * device, which will enable both CC lines but leave VCONN disabled. The + * driver should then run generic CC over-voltage handling. + */ + ppc_set_vconn(syv682x_port, true); + syv682x_emul_set_control_4(emul, SYV682X_CONTROL_4_VBAT_OVP); + syv682x_interrupt(syv682x_port); + /* TODO(b/201420132): Simulate passage of time instead of sleeping. */ + msleep(1); + zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + "Reading CONTROL_4 failed"); + zassert_true(reg & SYV682X_CONTROL_4_CC1_BPS, + "CC1 disabled after handling VBAT_OVP"); + zassert_true(reg & SYV682X_CONTROL_4_CC2_BPS, + "CC2 disabled after handling VBAT_OVP"); + zassert_false(reg & + (SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2), + "VCONN enabled after handling VBAT_OVP"); + /* + * TODO(b/190519131): The PD stack should generate a Reset in response + * to a CC over-voltage event. There is currently no easy way to test + * that a Hard Reset occurred. + */ } static void test_ppc_syv682x(void) |