summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_lis2dw12.c
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-09-18 21:58:27 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-21 02:41:41 +0000
commit26e3f0f8596300e1b7f64f426c0469f9bfee669f (patch)
tree39b2dba11ab9d9b73a73a66f07cd307c452e230c /zephyr/emul/emul_lis2dw12.c
parentdf6a8a118ba190cecd14d7e8b56e1945d739f390 (diff)
downloadchrome-ec-26e3f0f8596300e1b7f64f426c0469f9bfee669f.tar.gz
zephyr: test: lis2dw12 fail setting bdu on init
BRANCH=none BUG=b:200046770 TEST=zmake configure --test zephyr/projects/drivers Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I5e109001cf19010c2a4edc68be9b043a14070480 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3170539 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Yuval Peress <peress@google.com> Tested-by: Yuval Peress <peress@google.com>
Diffstat (limited to 'zephyr/emul/emul_lis2dw12.c')
-rw-r--r--zephyr/emul/emul_lis2dw12.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/zephyr/emul/emul_lis2dw12.c b/zephyr/emul/emul_lis2dw12.c
index fba6dbe758..6fa8b31cc9 100644
--- a/zephyr/emul/emul_lis2dw12.c
+++ b/zephyr/emul/emul_lis2dw12.c
@@ -31,6 +31,8 @@ struct lis2dw12_emul_data {
uint8_t who_am_i_reg;
/** Emulated ctrl2 register */
uint8_t ctrl2_reg;
+ /** Soft reset count */
+ uint32_t soft_reset_count;
};
struct lis2dw12_emul_cfg {
@@ -48,13 +50,17 @@ struct i2c_emul *lis2dw12_emul_to_i2c_emul(const struct emul *emul)
void lis2dw12_emul_reset(const struct emul *emul)
{
struct lis2dw12_emul_data *data = emul->data;
+ struct i2c_emul *i2c_emul = lis2dw12_emul_to_i2c_emul(emul);
- i2c_common_emul_set_read_fail_reg(lis2dw12_emul_to_i2c_emul(emul),
+ i2c_common_emul_set_read_fail_reg(i2c_emul,
I2C_COMMON_EMUL_NO_FAIL_REG);
- i2c_common_emul_set_write_fail_reg(lis2dw12_emul_to_i2c_emul(emul),
+ i2c_common_emul_set_write_fail_reg(i2c_emul,
I2C_COMMON_EMUL_NO_FAIL_REG);
+ i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
+ i2c_common_emul_set_write_func(i2c_emul, NULL, NULL);
data->who_am_i_reg = LIS2DW12_WHO_AM_I;
data->ctrl2_reg = 0;
+ data->soft_reset_count = 0;
}
void lis2dw12_emul_set_who_am_i(const struct emul *emul, uint8_t who_am_i)
@@ -64,6 +70,13 @@ void lis2dw12_emul_set_who_am_i(const struct emul *emul, uint8_t who_am_i)
data->who_am_i_reg = who_am_i;
}
+uint32_t lis2dw12_emul_get_soft_reset_count(const struct emul *emul)
+{
+ struct lis2dw12_emul_data *data = emul->data;
+
+ return data->soft_reset_count;
+}
+
static int lis2dw12_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
int bytes)
{
@@ -95,7 +108,11 @@ static int lis2dw12_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
return -EINVAL;
case LIS2DW12_CTRL2_ADDR:
__ASSERT_NO_MSG(bytes == 1);
- data->ctrl2_reg = val;
+ if ((val & LIS2DW12_SOFT_RESET_MASK) != 0) {
+ /* Soft reset */
+ data->soft_reset_count++;
+ }
+ data->ctrl2_reg = val & ~LIS2DW12_SOFT_RESET_MASK;
break;
default:
return -EINVAL;