From 31752262229d96f78021d02a8176f0ee2bea7020 Mon Sep 17 00:00:00 2001 From: Abe Levkoy Date: Mon, 6 Dec 2021 10:08:18 -0700 Subject: zephyr test: Test VBUS sink enable/disable Verify register values after enabling VBUS sink and after disabling it. BUG=b:190519131 TEST=zmake congfigure --test zephyr/test/drivers BRANCH=none Signed-off-by: Abe Levkoy Change-Id: Ibfb17252d3c31131101a6ba5682584148f747164 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3318726 Reviewed-by: Jack Rosenthal --- zephyr/test/drivers/src/ppc.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c index 314543b316..0484d98c86 100644 --- a/zephyr/test/drivers/src/ppc.c +++ b/zephyr/test/drivers/src/ppc.c @@ -335,6 +335,49 @@ static void test_ppc_syv682x_dev_is_connected(void) "Could not connect device as source"); } +static void test_ppc_syv682x_vbus_sink_enable(void) +{ + struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + uint8_t reg; + int ilim; + + /* + * If VBUS source is already enabled, disabling VBUS sink should + * trivially succeed. + */ + zassert_ok(ppc_vbus_source_enable(syv682x_port, true), + "VBUS enable failed"); + zassert_ok(ppc_vbus_sink_enable(syv682x_port, false), + "Sink disable failed"); + + /* + * After enabling VBUS sink, the HV power path should be enabled in sink + * mode with the configured current limit. + */ + zassert_ok(ppc_vbus_source_enable(syv682x_port, false), + "VBUS enable failed"); + zassert_ok(ppc_vbus_sink_enable(syv682x_port, true), + "Sink disable failed"); + zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + NULL); + zassert_true(reg & SYV682X_CONTROL_1_CH_SEL, + "Sink enabled, but CH_SEL set to 5V power path"); + zassert_false(reg & SYV682X_CONTROL_1_PWR_ENB, + "Sink enabled, but power path disabled"); + zassert_false(reg & SYV682X_CONTROL_1_HV_DR, + "Sink enabled, but high-voltage path in source mode"); + ilim = (reg & SYV682X_HV_ILIM_MASK) >> SYV682X_HV_ILIM_BIT_SHIFT; + zassert_equal(ilim, CONFIG_PLATFORM_EC_USBC_PPC_SYV682X_HV_ILIM, + "Sink enabled, but HV current limit set to %d", ilim); + + zassert_ok(ppc_vbus_sink_enable(syv682x_port, false), + "Sink disable failed"); + zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + NULL); + zassert_true(reg & SYV682X_CONTROL_1_PWR_ENB, + "Sink disabled, but power path enabled"); +} + static void test_ppc_syv682x(void) { zassert_ok(ppc_init(syv682x_port), "PPC init failed"); @@ -345,6 +388,7 @@ static void test_ppc_syv682x(void) test_ppc_syv682x_source_current_limit(); test_ppc_syv682x_write_busy(); test_ppc_syv682x_dev_is_connected(); + test_ppc_syv682x_vbus_sink_enable(); } void test_suite_ppc(void) -- cgit v1.2.1