summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2021-11-02 11:00:11 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 16:39:13 +0000
commit7207addef4052e968159278983e9b79c34743533 (patch)
tree88c485db9ead6b3d6516033081399f36c79941df
parentf4fd96d6bdfae2fcffd2e395b5d87e64bd6c9f2d (diff)
downloadchrome-ec-7207addef4052e968159278983e9b79c34743533.tar.gz
zephyr test: Cover SYV682 FRS
Enable FRS detection via the PPC. Enable FRS detection and then trigger an FRS. Test that the PPC switches from Sink to Source. Increase line coverage of syv682x.c from 70.3% to 78.5%. BUG=b:190519131 TEST=zmake coverage build/zephyr BRANCH=none Change-Id: I88381b1696d45fb7c7905001216559b94fd85a15 Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3260832 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--zephyr/emul/emul_syv682x.c3
-rw-r--r--zephyr/test/drivers/prj.conf2
-rw-r--r--zephyr/test/drivers/src/ppc.c58
3 files changed, 61 insertions, 2 deletions
diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c
index 3a4aba8189..2a181fea23 100644
--- a/zephyr/emul/emul_syv682x.c
+++ b/zephyr/emul/emul_syv682x.c
@@ -78,7 +78,8 @@ void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val)
* 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.
+ * interrupt continuously. Relatedly, the emulator should only generate
+ * an FRS alert if the EC is asserting the FRS GPIO.
*/
}
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index c2931fbf77..ed41ea5357 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -61,6 +61,8 @@ CONFIG_PLATFORM_EC_CHARGER_ISL9238=y
CONFIG_PLATFORM_EC_CHARGER_ISL9241=y
CONFIG_PLATFORM_EC_CHIP_INIT_ROM_REGION=y
CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y
+CONFIG_PLATFORM_EC_USB_PD_FRS=y
+CONFIG_PLATFORM_EC_USB_PD_FRS_PPC=y
CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
CONFIG_PLATFORM_EC_HOSTCMD=y
CONFIG_PLATFORM_EC_USB_PD_TCPM_TUSB422=y
diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c
index 9c1d77a21c..95c8abf564 100644
--- a/zephyr/test/drivers/src/ppc.c
+++ b/zephyr/test/drivers/src/ppc.c
@@ -167,7 +167,7 @@ static void test_ppc_syv682x_interrupt(void)
zassert_false(reg &
(SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2),
"VCONN enabled after long VCONN OC");
- syv682x_emul_set_control_4(emul, 0x0);
+ syv682x_emul_set_control_4(emul, 0);
/*
* A VCONN over-voltage (VBAT_OVP) event will cause the device to
@@ -194,6 +194,61 @@ static void test_ppc_syv682x_interrupt(void)
* to a CC over-voltage event. There is currently no easy way to test
* that a Hard Reset occurred.
*/
+ syv682x_emul_set_control_4(emul, 0);
+}
+
+static void test_ppc_syv682x_frs(void)
+{
+ struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
+ uint8_t reg;
+
+ /*
+ * Enabling FRS should enable only the appropriate CC line based on
+ * polarity. Disabling FRS should enable both CC lines.
+ */
+ ppc_vbus_sink_enable(syv682x_port, true);
+ zassert_false(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is sourcing VBUS after sink enabled");
+ ppc_set_polarity(syv682x_port, 0 /* CC1 */);
+ ppc_set_frs_enable(syv682x_port, true);
+ zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, &reg),
+ "Reading CONTROL_4 failed");
+ zassert_equal(reg &
+ (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS),
+ SYV682X_CONTROL_4_CC1_BPS,
+ "FRS enabled with CC1 polarity, but CONTROL_4 is 0x%x",
+ reg);
+ ppc_set_frs_enable(syv682x_port, false);
+ zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, &reg),
+ "Reading CONTROL_4 failed");
+ zassert_equal(reg &
+ (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS),
+ SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS,
+ "FRS enabled with CC1 polarity, but CONTROL_4 is 0x%x",
+ reg);
+
+ ppc_set_polarity(syv682x_port, 1 /* CC2 */);
+ ppc_set_frs_enable(syv682x_port, true);
+ zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, &reg),
+ "Reading CONTROL_4 failed");
+ zassert_equal(reg &
+ (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS),
+ SYV682X_CONTROL_4_CC2_BPS,
+ "FRS enabled with CC2 polarity, but CONTROL_4 is 0x%x",
+ reg);
+
+ /*
+ * An FRS event when the PPC is Sink should cause the PPC to switch from
+ * Sink to Source.
+ */
+ syv682x_emul_set_status(emul, SYV682X_STATUS_FRS);
+ syv682x_interrupt(syv682x_port);
+ /* TODO(b/201420132): Simulate passage of time instead of sleeping. */
+ msleep(1);
+ zassert_true(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is not sourcing VBUS after FRS signal handled");
+ syv682x_emul_set_status(emul, 0);
+
}
static void test_ppc_syv682x(void)
@@ -202,6 +257,7 @@ static void test_ppc_syv682x(void)
test_ppc_syv682x_vbus_enable();
test_ppc_syv682x_interrupt();
+ test_ppc_syv682x_frs();
}
void test_suite_ppc(void)