summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2021-10-01 13:12:23 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-01 22:03:20 +0000
commit066a846f76f8fd03408de6fd86e1d8270d4a1475 (patch)
treeee23ed79b98096b54e3e110c28785c36e765bfdc
parentf5ba5ec8361d7dadefb3860a05bf80e4ad230a44 (diff)
downloadchrome-ec-066a846f76f8fd03408de6fd86e1d8270d4a1475.tar.gz
zephyr: test: SYV682X TSD and OVP alerts
Emulate interrupts caused by TSD or OVP events. Verify that the driver disables sourcing VBUS. Increase coverage of syv682x.c: (lines 52.8% -> 54.8%, branches 15.5% -> 16.1%). BUG=b:190519131 TEST=zmake configure --test zephyr/test/drivers BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: If5bc6305758a6bd05d4ceefd7c41e0ad5954e85e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3200056 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/emul/emul_syv682x.c32
-rw-r--r--zephyr/test/drivers/src/ppc.c24
2 files changed, 54 insertions, 2 deletions
diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c
index 3d76d10492..e565e06958 100644
--- a/zephyr/emul/emul_syv682x.c
+++ b/zephyr/emul/emul_syv682x.c
@@ -67,6 +67,17 @@ void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val)
data = CONTAINER_OF(emul, struct syv682x_emul_data, emul);
data->status_cond = val;
data->reg[SYV682X_STATUS_REG] |= val;
+
+ if (val & (SYV682X_STATUS_TSD | SYV682X_STATUS_OVP))
+ data->reg[SYV682X_CONTROL_1_REG] |= SYV682X_CONTROL_1_PWR_ENB;
+
+ /*
+ * TODO(b/190519131): Make this emulator trigger GPIO-based interrupts
+ * by itself based on the status. In real life, the device should turn
+ * the power path off when either of these conditions occurs, and they
+ * should quickly dissipate. If they somehow stay set, the device should
+ * interrupt continuously.
+ */
}
int syv682x_emul_get_reg(struct i2c_emul *emul, int reg, uint8_t *val)
@@ -110,13 +121,30 @@ static int syv682x_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs,
i2c_dump_msgs("emul", msgs, num_msgs, addr);
if (num_msgs == 1) {
+ int reg = msgs[0].buf[0];
+ uint8_t val = msgs[0].buf[1];
+
if (!((msgs[0].flags & I2C_MSG_RW_MASK) == I2C_MSG_WRITE
&& msgs[0].len == 2)) {
LOG_ERR("Unexpected write msgs");
return -EIO;
}
- return syv682x_emul_set_reg(emul, msgs[0].buf[0],
- msgs[0].buf[1]);
+
+ switch (reg) {
+ case SYV682X_CONTROL_1_REG:
+ /*
+ * If OVP or TSD is active, the power path stays
+ * disabled.
+ */
+ if (data->status_cond & (SYV682X_STATUS_TSD |
+ SYV682X_STATUS_OVP))
+ val |= SYV682X_CONTROL_1_PWR_ENB;
+ break;
+ default:
+ break;
+ }
+
+ return syv682x_emul_set_reg(emul, msgs[0].buf[0], val);
} else if (num_msgs == 2) {
int ret;
int reg;
diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c
index dced25c227..0cc84f0bf4 100644
--- a/zephyr/test/drivers/src/ppc.c
+++ b/zephyr/test/drivers/src/ppc.c
@@ -66,6 +66,30 @@ static void test_ppc_syv682x_interrupt(void)
* port back on without a detach. This could frustrate efforts to test
* the TC.
*/
+
+ /*
+ * A TSD event should cause the driver to disable source and sink paths.
+ * (The device will have already physically disabled them.) The state of
+ * the sink path is not part of the driver's API.
+ */
+ zassert_ok(ppc_vbus_source_enable(syv682x_port, true),
+ "Source enable failed");
+ syv682x_emul_set_status(emul, SYV682X_STATUS_TSD);
+ syv682x_interrupt(syv682x_port);
+ msleep(1);
+ zassert_false(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is sourcing power after TSD");
+ syv682x_emul_set_status(emul, 0);
+
+ /* An OVP event should cause the driver to disable the source path. */
+ zassert_ok(ppc_vbus_source_enable(syv682x_port, true),
+ "Source enable failed");
+ syv682x_emul_set_status(emul, SYV682X_STATUS_OVP);
+ syv682x_interrupt(syv682x_port);
+ msleep(1);
+ zassert_false(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is sourcing power after TSD");
+ syv682x_emul_set_status(emul, 0);
}
static void test_ppc_syv682x(void)