summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-09-30 23:48:01 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-05 14:22:18 +0000
commit6bc606c6427b2aa8bad9de0e31afb887ad44dae5 (patch)
treeca5abb90f48791c4aec68e9572cb5dfc0d684e9a
parentf48b29920036c69793eb1fdca0af7f8d945a20ab (diff)
downloadchrome-ec-6bc606c6427b2aa8bad9de0e31afb887ad44dae5.tar.gz
zephyr: test: isl923x::set_mode always turns off learn mode
BRANCH=none BUG=b:201602829 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Ic2481c0de52268cc65475de8e79f1db7834358d2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3198686 Reviewed-by: Sam Hurst <shurst@google.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/emul/emul_isl923x.c18
-rw-r--r--zephyr/include/emul/emul_isl923x.h17
-rw-r--r--zephyr/test/drivers/src/isl923x.c21
3 files changed, 55 insertions, 1 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c
index 66d7d4c5e9..b4ab16ce68 100644
--- a/zephyr/emul/emul_isl923x.c
+++ b/zephyr/emul/emul_isl923x.c
@@ -92,6 +92,24 @@ void isl923x_emul_set_device_id(const struct emul *emulator,
data->device_id_reg = device_id;
}
+bool isl923x_emul_is_learn_mode_enabled(const struct emul *emulator)
+{
+ struct isl923x_emul_data *data = emulator->data;
+
+ return (data->control_1_reg & ISL923X_C1_LEARN_MODE_ENABLE) != 0;
+}
+
+void isl923x_emul_set_learn_mode_enabled(const struct emul *emulator,
+ bool enabled)
+{
+ struct isl923x_emul_data *data = emulator->data;
+
+ if (enabled)
+ data->control_1_reg |= ISL923X_C1_LEARN_MODE_ENABLE;
+ else
+ data->control_1_reg &= ~ISL923X_C1_LEARN_MODE_ENABLE;
+}
+
static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
int bytes)
{
diff --git a/zephyr/include/emul/emul_isl923x.h b/zephyr/include/emul/emul_isl923x.h
index 3de7475207..8b34f7b519 100644
--- a/zephyr/include/emul/emul_isl923x.h
+++ b/zephyr/include/emul/emul_isl923x.h
@@ -37,4 +37,21 @@ void isl923x_emul_set_manufacturer_id(const struct emul *emulator,
void isl923x_emul_set_device_id(const struct emul *emulator,
uint16_t device_id);
+/**
+ * @brief Check whether or not learn mode is enabled
+ *
+ * @param emulator The emulator to probe
+ * @return True if the emulator is in learn mode
+ */
+bool isl923x_emul_is_learn_mode_enabled(const struct emul *emulator);
+
+/**
+ * @brief Set the emulator's learn mode manually without affecting the driver
+ *
+ * @param emulator The emulator to modify
+ * @param enabled Whether or not learn mode should be enabled
+ */
+void isl923x_emul_set_learn_mode_enabled(const struct emul *emulator,
+ bool enabled);
+
#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_ISL923X_H_ */
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index 996fb87487..c4d0bfc38b 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -273,6 +273,24 @@ void test_status(void)
zassert_equal(CHARGER_LEVEL_2, status, NULL);
}
+void test_set_mode(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+
+ /* Enable learn mode and set mode (actual value doesn't matter) */
+ zassert_ok(isl923x_drv.discharge_on_ac(CHARGER_NUM, true), NULL);
+ zassert_ok(isl923x_drv.set_mode(CHARGER_NUM, 0), NULL);
+ /* Learn mode should still be set */
+ zassert_true(isl923x_emul_is_learn_mode_enabled(isl923x_emul), NULL);
+
+ /* Disable learn mode, but keep the bits */
+ zassert_ok(isl923x_drv.discharge_on_ac(CHARGER_NUM, false), NULL);
+ isl923x_emul_set_learn_mode_enabled(isl923x_emul, true);
+ zassert_ok(isl923x_drv.set_mode(CHARGER_NUM, 0), NULL);
+ /* Learn mode should still be off */
+ zassert_true(!isl923x_emul_is_learn_mode_enabled(isl923x_emul), NULL);
+}
+
void test_suite_isl923x(void)
{
ztest_test_suite(isl923x,
@@ -283,6 +301,7 @@ void test_suite_isl923x(void)
ztest_unit_test(test_device_id),
ztest_unit_test(test_options),
ztest_unit_test(test_get_info),
- ztest_unit_test(test_status));
+ ztest_unit_test(test_status),
+ ztest_unit_test(test_set_mode));
ztest_run_test_suite(isl923x);
}