diff options
author | Aaron Massey <aaronmassey@google.com> | 2021-11-05 12:59:33 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-22 20:00:17 +0000 |
commit | 1a04290cf0d6b4d7e4044ef489bef2f1e3473404 (patch) | |
tree | 921d2021f5e8ab12bb673b30b57d1fb4b798f863 | |
parent | 62fb2d16161f66d1d2a3bd6cf394af9d0e2d0eb0 (diff) | |
download | chrome-ec-1a04290cf0d6b4d7e4044ef489bef2f1e3473404.tar.gz |
zephyr: test: sn5s330 dead battery boot init
Verify sn5s330 PP2 are force enabled.
BRANCH=none
BUG=b:203364783
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I118b05140228b89d27790863a3c8ddc62793fedc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3271367
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r-- | driver/ppc/sn5s330.c | 9 | ||||
-rw-r--r-- | zephyr/test/drivers/src/ppc_sn5s330.c | 72 |
2 files changed, 80 insertions, 1 deletions
diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c index 1aac04af02..3fa44ae803 100644 --- a/driver/ppc/sn5s330.c +++ b/driver/ppc/sn5s330.c @@ -464,7 +464,14 @@ static int sn5s330_init(int port) i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_STATUS_REG4, regval); - /* Turn on PP2 FET. */ + /* + * Turn on PP2 FET. + * Although PP2 FET is already enabled during dead batter boot + * by the spec, we force that state here. + * + * TODO(207034759): Verify need or remove redundant PP2 set. + */ + status = sn5s330_pp_fet_enable(port, SN5S330_PP2, 1); if (status) { ppc_prints("Failed to turn on PP2 FET!", port); diff --git a/zephyr/test/drivers/src/ppc_sn5s330.c b/zephyr/test/drivers/src/ppc_sn5s330.c index 95556e28cf..aa06cf3bd9 100644 --- a/zephyr/test/drivers/src/ppc_sn5s330.c +++ b/zephyr/test/drivers/src/ppc_sn5s330.c @@ -23,6 +23,39 @@ * to avoid test flakiness */ +struct intercept_write_data { + int reg_to_intercept; + uint8_t val_intercepted; +}; + +struct intercept_read_data { + int reg_to_intercept; + bool replace_reg_val; + uint8_t replacement_val; +}; + +static int intercept_read_func(struct i2c_emul *emul, int reg, uint8_t *val, + int bytes, void *data) +{ + struct intercept_read_data *test_data = data; + + if (test_data->reg_to_intercept && test_data->replace_reg_val) + *val = test_data->replacement_val; + + return EC_SUCCESS; +} + +static int intercept_write_func(struct i2c_emul *emul, int reg, uint8_t val, + int bytes, void *data) +{ + struct intercept_write_data *test_data = data; + + if (test_data->reg_to_intercept == reg) + test_data->val_intercepted = val; + + return 1; +} + static int fail_until_write_func(struct i2c_emul *emul, int reg, uint8_t val, int bytes, void *data) { @@ -53,8 +86,44 @@ static void test_fail_once_func_set1(void) i2c_common_emul_set_write_func(i2c_emul, NULL, NULL); } +static void test_dead_battery_boot_force_pp2_fets_set(void) +{ + const struct emul *emul = EMUL; + struct i2c_emul *i2c_emul = sn5s330_emul_to_i2c_emul(emul); + struct intercept_write_data test_write_data = { + .reg_to_intercept = SN5S330_FUNC_SET3, + .val_intercepted = 0, + }; + struct intercept_read_data test_read_data = { + .reg_to_intercept = SN5S330_INT_STATUS_REG4, + .replace_reg_val = true, + .replacement_val = SN5S330_DB_BOOT, + }; + + i2c_common_emul_set_write_func(i2c_emul, intercept_write_func, + &test_write_data); + i2c_common_emul_set_read_func(i2c_emul, intercept_read_func, + &test_read_data); + + zassert_ok(sn5s330_drv.init(SN5S330_PORT), NULL); + + /* + * Although the device enables PP2_FET on dead battery boot by setting + * the PP2_EN bit, the driver also force sets this bit during dead + * battery boot by writing that bit to the FUNC_SET3 reg. + * + * TODO(207034759): Verify need or remove redundant PP2 set. + */ + zassert_true(test_write_data.val_intercepted & SN5S330_PP2_EN, NULL); + zassert_false(sn5s330_drv.is_sourcing_vbus(SN5S330_PORT), NULL); +} + static void reset_sn5s330_state(void) { + struct i2c_emul *i2c_emul = sn5s330_emul_to_i2c_emul(EMUL); + + i2c_common_emul_set_write_func(i2c_emul, NULL, NULL); + i2c_common_emul_set_read_func(i2c_emul, NULL, NULL); sn5s330_emul_reset(EMUL); } @@ -62,6 +131,9 @@ void test_suite_ppc_sn5s330(void) { ztest_test_suite(ppc_sn5s330, ztest_unit_test_setup_teardown( + test_dead_battery_boot_force_pp2_fets_set, + reset_sn5s330_state, reset_sn5s330_state), + ztest_unit_test_setup_teardown( test_fail_once_func_set1, reset_sn5s330_state, reset_sn5s330_state)); ztest_run_test_suite(ppc_sn5s330); |