summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_syv682x.c
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2021-09-01 12:15:29 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-15 22:42:36 +0000
commitf47bf498f741c04bdfdd6b961f4e579f34279096 (patch)
treeef18a5d94244b37c6f7316fe495e5b79e45a326e /zephyr/emul/emul_syv682x.c
parentd7884389d0c8d4c29719cf75a1efc3ca3fc02bf7 (diff)
downloadchrome-ec-f47bf498f741c04bdfdd6b961f4e579f34279096.tar.gz
zephyr: Test SYV682 5V_OC interrupt handling
Simulate a 5V OC condition and verify that the driver turns VBUS off. Support status interrupt conditions and clear-on-read registers in SYV682x emulator. Increase line coverage of syv682x.c from 37.9% to 52.8%. BUG=b:190519131 TEST=zmake -l DEBUG configure --test zephyr/test/drivers BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I9c5b419057cf4ccb1531527a71760533240d1f47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3059218 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/emul/emul_syv682x.c')
-rw-r--r--zephyr/emul/emul_syv682x.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c
index dff9df651c..3d76d10492 100644
--- a/zephyr/emul/emul_syv682x.c
+++ b/zephyr/emul/emul_syv682x.c
@@ -12,6 +12,7 @@
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(syv682x);
+#include <stdint.h>
#include <string.h>
#include "emul/emul_syv682x.h"
@@ -28,6 +29,12 @@ struct syv682x_emul_data {
const struct syv682x_emul_cfg *cfg;
/** Current state of all emulated SYV682x registers */
uint8_t reg[EMUL_REG_COUNT];
+ /**
+ * Current state of conditions affecting interrupt bits, as distinct
+ * from the current values of those bits stored in reg.
+ */
+ uint8_t status_cond;
+ uint8_t control_4_cond;
};
/** Static configuration for the emulator */
@@ -53,6 +60,15 @@ int syv682x_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val)
return 0;
}
+void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val)
+{
+ struct syv682x_emul_data *data;
+
+ data = CONTAINER_OF(emul, struct syv682x_emul_data, emul);
+ data->status_cond = val;
+ data->reg[SYV682X_STATUS_REG] |= val;
+}
+
int syv682x_emul_get_reg(struct i2c_emul *emul, int reg, uint8_t *val)
{
struct syv682x_emul_data *data;
@@ -102,6 +118,10 @@ static int syv682x_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs,
return syv682x_emul_set_reg(emul, msgs[0].buf[0],
msgs[0].buf[1]);
} else if (num_msgs == 2) {
+ int ret;
+ int reg;
+ uint8_t *buf;
+
if (!((msgs[0].flags & I2C_MSG_RW_MASK) == I2C_MSG_WRITE
&& msgs[0].len == 1
&& (msgs[1].flags & I2C_MSG_RW_MASK) ==
@@ -110,8 +130,27 @@ static int syv682x_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs,
LOG_ERR("Unexpected read msgs");
return -EIO;
}
- return syv682x_emul_get_reg(emul, msgs[0].buf[0],
- &msgs[1].buf[0]);
+
+ reg = msgs[0].buf[0];
+ buf = &msgs[1].buf[0];
+ ret = syv682x_emul_get_reg(emul, reg, buf);
+
+ switch (reg) {
+ /*
+ * These registers are clear-on-read (if the underlying
+ * condition has cleared).
+ */
+ case SYV682X_STATUS_REG:
+ syv682x_emul_set_reg(emul, reg, data->status_cond);
+ break;
+ case SYV682X_CONTROL_4_REG:
+ syv682x_emul_set_reg(emul, reg, data->control_4_cond);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
} else {
LOG_ERR("Unexpected num_msgs");
return -EIO;