summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-09-30 11:32:35 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-02 02:28:10 +0000
commit1b804b2e071c9fd520ac12de3d493cb2a1f28baf (patch)
tree98396cb2e23c21d6984c4cc1fa1f9121d9e8b61f
parenta7ef9770338570a2ce71af97b80687844b109691 (diff)
downloadchrome-ec-1b804b2e071c9fd520ac12de3d493cb2a1f28baf.tar.gz
zephyr: test: verify isl923x get/set ctrl 0/1 registers
Test the code paths for the options in control 0 and 1 registers. Including the expected bits 23 and 0 which will always be 0 when reading. BRANCH=none BUG=b:201602829 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I9fd4e00b8a3f6fcc7a7295f1084987b7bb493e56 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3198238 Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--zephyr/emul/emul_isl923x.c38
-rw-r--r--zephyr/test/drivers/src/isl923x.c44
2 files changed, 81 insertions, 1 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c
index 0adbb86c00..66d7d4c5e9 100644
--- a/zephyr/emul/emul_isl923x.c
+++ b/zephyr/emul/emul_isl923x.c
@@ -37,6 +37,12 @@ LOG_MODULE_REGISTER(isl923x_emul, CONFIG_ISL923X_EMUL_LOG_LEVEL);
/** Mask used for the adapter current limit 2 register */
#define REG_ADAPTER_CURRENT_LIMIT2_MASK GENMASK(12, 2)
+/** Mask used for the control 0 register */
+#define REG_CONTROL0_MASK GENMASK(15, 1)
+
+/** Mask used for the control 1 register */
+#define REG_CONTROL1_MASK (GENMASK(15, 8) | GENMASK(6, 0))
+
struct isl923x_emul_data {
/** Common I2C data */
struct i2c_common_emul_data common;
@@ -52,6 +58,10 @@ struct isl923x_emul_data {
uint16_t manufacturer_id_reg;
/** Emulated device ID register */
uint16_t device_id_reg;
+ /** Emulated control 0 register */
+ uint16_t control_0_reg;
+ /** Emulated control 1 register */
+ uint16_t control_1_reg;
};
struct isl923x_emul_cfg {
@@ -137,6 +147,20 @@ static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
else
*val = (uint8_t)((data->device_id_reg >> 8) & 0xff);
break;
+ case ISL923X_REG_CONTROL0:
+ __ASSERT_NO_MSG(bytes == 0 || bytes == 1);
+ if (bytes == 0)
+ *val = (uint8_t)(data->control_0_reg & 0xff);
+ else
+ *val = (uint8_t)((data->control_0_reg >> 8) & 0xff);
+ break;
+ case ISL923X_REG_CONTROL1:
+ __ASSERT_NO_MSG(bytes == 0 || bytes == 1);
+ if (bytes == 0)
+ *val = (uint8_t)(data->control_1_reg & 0xff);
+ else
+ *val = (uint8_t)((data->control_1_reg >> 8) & 0xff);
+ break;
default:
return -EINVAL;
}
@@ -183,6 +207,20 @@ static int isl923x_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
data->adapter_current_limit2_reg |=
(val << 8) & REG_ADAPTER_CURRENT_LIMIT2_MASK;
break;
+ case ISL923X_REG_CONTROL0:
+ __ASSERT_NO_MSG(bytes == 1 || bytes == 2);
+ if (bytes == 1)
+ data->control_0_reg = val & REG_CONTROL0_MASK;
+ else
+ data->control_0_reg |= (val << 8) & REG_CONTROL0_MASK;
+ break;
+ case ISL923X_REG_CONTROL1:
+ __ASSERT_NO_MSG(bytes == 1 || bytes == 2);
+ if (bytes == 1)
+ data->control_1_reg = val & REG_CONTROL1_MASK;
+ else
+ data->control_1_reg |= (val << 8) & REG_CONTROL1_MASK;
+ break;
default:
return -EINVAL;
}
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index d6a9fb0c59..022eccb98b 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -200,6 +200,47 @@ void test_device_id(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
+void test_options(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+ uint32_t option;
+
+ /* Test failed control 0 read */
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL0);
+ zassert_equal(EC_ERROR_INVAL,
+ isl923x_drv.get_option(CHARGER_NUM, &option), NULL);
+
+ /* Test failed control 1 read */
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL1);
+ zassert_equal(EC_ERROR_INVAL,
+ isl923x_drv.get_option(CHARGER_NUM, &option), NULL);
+
+ /* Reset failed read */
+ i2c_common_emul_set_read_fail_reg(i2c_emul,
+ I2C_COMMON_EMUL_NO_FAIL_REG);
+
+ /* Test failed control 0 write */
+ i2c_common_emul_set_write_fail_reg(i2c_emul, ISL923X_REG_CONTROL0);
+ zassert_equal(EC_ERROR_INVAL,
+ isl923x_drv.set_option(CHARGER_NUM, option), NULL);
+
+ /* Test failed control 1 write */
+ i2c_common_emul_set_write_fail_reg(i2c_emul, ISL923X_REG_CONTROL1);
+ zassert_equal(EC_ERROR_INVAL,
+ isl923x_drv.set_option(CHARGER_NUM, option), NULL);
+
+ /* Reset failed write */
+ i2c_common_emul_set_write_fail_reg(i2c_emul,
+ I2C_COMMON_EMUL_NO_FAIL_REG);
+
+ /* Test normal write/read, note that bits 23 and 0 are always 0 */
+ zassert_ok(isl923x_drv.set_option(CHARGER_NUM, 0xffffffff), NULL);
+ zassert_ok(isl923x_drv.get_option(CHARGER_NUM, &option), NULL);
+ zassert_equal(0xff7ffffe, option,
+ "Expected options 0xff7ffffe but got 0x%x", option);
+}
+
void test_suite_isl923x(void)
{
ztest_test_suite(isl923x,
@@ -207,6 +248,7 @@ void test_suite_isl923x(void)
ztest_unit_test(test_isl923x_set_voltage),
ztest_unit_test(test_isl923x_set_input_current_limit),
ztest_unit_test(test_manufacturer_id),
- ztest_unit_test(test_device_id));
+ ztest_unit_test(test_device_id),
+ ztest_unit_test(test_options));
ztest_run_test_suite(isl923x);
}