diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2023-03-10 15:18:36 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-13 08:59:48 +0000 |
commit | 45ffe7ad069930957bb7e4f9e0d718dc47406e7c (patch) | |
tree | 5bed68b594f07cdb423879513468a47218c277d3 /zephyr/emul | |
parent | 7434ca9a4c641813589ea93fbf446b3efbd125b5 (diff) | |
download | chrome-ec-45ffe7ad069930957bb7e4f9e0d718dc47406e7c.tar.gz |
tcpci: test: add get_vbus_voltage test
Add the test for TCPCI get_vbus_voltage API.
BUG=b:272664811
TEST=./twister -c -i -T zephyr/test/drivers
BRANCH=none
Change-Id: I5b26e1e0d43225b4318694d3e76d2133905013e2
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4328914
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Auto-Submit: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Diffstat (limited to 'zephyr/emul')
-rw-r--r-- | zephyr/emul/tcpc/emul_tcpci.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c index 0deb0c2727..15859afd65 100644 --- a/zephyr/emul/tcpc/emul_tcpci.c +++ b/zephyr/emul/tcpc/emul_tcpci.c @@ -462,6 +462,29 @@ void tcpci_emul_set_rev(const struct emul *emul, enum tcpci_emul_rev rev) } } +void tcpci_emul_set_vbus_voltage(const struct emul *emul, uint32_t vbus_mv) +{ + uint16_t meas; + uint16_t scale = 0; + + __ASSERT(!(vbus_mv % TCPC_REG_VBUS_VOLTAGE_LSB), + "vbus_mv must be divisible by %d (%d)", + TCPC_REG_VBUS_VOLTAGE_LSB, vbus_mv); + + meas = vbus_mv / TCPC_REG_VBUS_VOLTAGE_LSB; + + while (meas >= (1 << 10) && scale < 3) { + __ASSERT(!(meas & 1), "vbus_mv %d does not fit into the reg.", + vbus_mv); + meas >>= 1; + scale += 1; + } + __ASSERT(scale < 3, "scale %d, meas %d doesn't fit into the reg.", + scale, meas); + + tcpci_emul_set_reg(emul, TCPC_REG_VBUS_VOLTAGE, (scale << 10) | meas); +} + /** Check description in emul_tcpci.h */ void tcpci_emul_set_alert_callback(const struct emul *emul, tcpci_emul_alert_state_func alert_callback, |