summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_isl923x.c
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-10-03 23:05:13 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-05 14:23:58 +0000
commit021f2754aa8722288cff2362c470a82ef352436b (patch)
tree25c1257f8d92222ff0594617b1af50895ec1bc3e /zephyr/emul/emul_isl923x.c
parent366647d37e1a248575d8b74844cafbabf6563374 (diff)
downloadchrome-ec-021f2754aa8722288cff2362c470a82ef352436b.tar.gz
zephyr: test: isl923x::get_vbus_voltage
Verify all the code paths in get_vbus_voltage (including calculated mV value). BRANCH=none BUG=b:201819565 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I508880a8af30c2d546655424b289d521f3c22626 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3201915 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Diffstat (limited to 'zephyr/emul/emul_isl923x.c')
-rw-r--r--zephyr/emul/emul_isl923x.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c
index f97af88da0..9b3aaec4f5 100644
--- a/zephyr/emul/emul_isl923x.c
+++ b/zephyr/emul/emul_isl923x.c
@@ -82,6 +82,8 @@ struct isl923x_emul_data {
uint16_t ac_prochot_reg;
/** Emulated DC PROCHOT register */
uint16_t dc_prochot_reg;
+ /** Emulated ADC vbus register */
+ uint16_t adc_vbus_reg;
};
struct isl923x_emul_cfg {
@@ -137,6 +139,15 @@ void isl923x_emul_set_learn_mode_enabled(const struct emul *emulator,
data->control_1_reg &= ~ISL923X_C1_LEARN_MODE_ENABLE;
}
+void isl923x_emul_set_adc_vbus(const struct emul *emulator,
+ uint16_t value)
+{
+ struct isl923x_emul_data *data = emulator->data;
+
+ /* The VBUS voltage is returned in bits 13:6. The LSB is 96mV. */
+ data->adc_vbus_reg = value & GENMASK(13, 6);
+}
+
static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
int bytes)
{
@@ -234,6 +245,13 @@ static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
else
*val = (uint8_t)((data->dc_prochot_reg >> 8) & 0xff);
break;
+ case RAA489000_REG_ADC_VBUS:
+ __ASSERT_NO_MSG(bytes == 0 || bytes == 1);
+ if (bytes == 0)
+ *val = (uint8_t)(data->adc_vbus_reg & 0xff);
+ else
+ *val = (uint8_t)((data->adc_vbus_reg >> 8) & 0xff);
+ break;
default:
return -EINVAL;
}