summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2022-01-28 14:10:53 -0700
committerCommit Bot <commit-bot@chromium.org>2022-01-31 23:22:25 +0000
commitf14049585fa02c3df1254deb34082f25b0c94e3d (patch)
tree753e48c81d2613a9230116bb4b25003fb4275294
parent33b568c05d6b1851895c167b2d333821e4e73793 (diff)
downloadchrome-ec-f14049585fa02c3df1254deb34082f25b0c94e3d.tar.gz
zephyr test: Set ISL923x in natural units
Accept voltage in mV as an argument to isl923x_emul_set_adc_vbus. Test using this interface. BUG=b:216497851 TEST=zmake testall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I8a0ec6019f1d4ef7853d731b11726e4fb1bdf136 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3425638 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/emul/emul_isl923x.c5
-rw-r--r--zephyr/include/emul/emul_isl923x.h5
-rw-r--r--zephyr/test/drivers/src/integration_usb.c10
-rw-r--r--zephyr/test/drivers/src/isl923x.c20
4 files changed, 19 insertions, 21 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c
index 56287d531e..399bf167a5 100644
--- a/zephyr/emul/emul_isl923x.c
+++ b/zephyr/emul/emul_isl923x.c
@@ -174,13 +174,12 @@ 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)
+void isl923x_emul_set_adc_vbus(const struct emul *emulator, uint16_t vbus_mv)
{
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);
+ data->adc_vbus_reg = ((vbus_mv / 96) << 6) & GENMASK(13, 6);
}
void raa489000_emul_set_acok_pin(const struct emul *emulator, uint16_t value)
diff --git a/zephyr/include/emul/emul_isl923x.h b/zephyr/include/emul/emul_isl923x.h
index 659b620f21..93a29a9c09 100644
--- a/zephyr/include/emul/emul_isl923x.h
+++ b/zephyr/include/emul/emul_isl923x.h
@@ -74,10 +74,9 @@ void isl923x_emul_set_learn_mode_enabled(const struct emul *emulator,
* @brief Set the emulator's ADC vbus register
*
* @param emulator The emulator to modify
- * @param value The new ADC register value
+ * @param vbus_mv VBUS voltage in mV
*/
-void isl923x_emul_set_adc_vbus(const struct emul *emulator,
- uint16_t value);
+void isl923x_emul_set_adc_vbus(const struct emul *emulator, uint16_t vbus_mv);
/**
* @brief Set the state of the ACOK pin, which is reflected in the INFO2
diff --git a/zephyr/test/drivers/src/integration_usb.c b/zephyr/test/drivers/src/integration_usb.c
index b9f3bc1cf6..320d3ebb7b 100644
--- a/zephyr/test/drivers/src/integration_usb.c
+++ b/zephyr/test/drivers/src/integration_usb.c
@@ -203,8 +203,7 @@ ZTEST(integration_usb, test_attach_5v_pd_charger)
&my_charger.common_data,
&my_charger.ops, tcpci_emul),
NULL);
- /* This corresponds to 4.992V. */
- isl923x_emul_set_adc_vbus(charger_emul, 0x0d00);
+ isl923x_emul_set_adc_vbus(charger_emul, 5000);
/* Wait for current ramp. */
k_sleep(K_SECONDS(10));
@@ -249,12 +248,7 @@ ZTEST(integration_usb, test_attach_20v_pd_charger)
&my_charger.common_data,
&my_charger.ops, tcpci_emul),
NULL);
- /* This corresponds to 20.352V according to the scheme used by
- * isl923x_get_vbus_voltage, which is slightly different than that
- * described in the ISL9238 datasheet.
- * TODO(b/216497851): Specify this in natural units.
- */
- isl923x_emul_set_adc_vbus(charger_emul, 0x3500);
+ isl923x_emul_set_adc_vbus(charger_emul, 20000);
/* Wait for PD negotiation and current ramp.
* TODO(b/213906889): Check message timing and contents.
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index a5abee0fc5..c2e0f00c76 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -545,8 +545,8 @@ ZTEST(isl923x, test_get_vbus_voltage)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
- int reg_values[] = { BIT(6), BIT(7), BIT(8), BIT(9),
- BIT(10), BIT(11), BIT(12), BIT(13) };
+ /* Standard fixed-power PD source voltages. */
+ int test_voltage_mv[] = { 5000, 9000, 15000, 20000 };
int voltage;
/* Test fail to read the ADC vbus register */
@@ -557,15 +557,21 @@ ZTEST(isl923x, test_get_vbus_voltage)
i2c_common_emul_set_read_fail_reg(i2c_emul,
I2C_COMMON_EMUL_NO_FAIL_REG);
- for (int i = 0; i < ARRAY_SIZE(reg_values); ++i) {
- int expected_voltage = (reg_values[i] >> 6) * 96;
+ for (int i = 0; i < ARRAY_SIZE(test_voltage_mv); ++i) {
+ int expected_voltage_mv = test_voltage_mv[i];
- isl923x_emul_set_adc_vbus(isl923x_emul, reg_values[i]);
+ isl923x_emul_set_adc_vbus(isl923x_emul, expected_voltage_mv);
zassert_ok(isl923x_drv.get_vbus_voltage(CHARGER_NUM, 0,
&voltage),
NULL);
- zassert_equal(expected_voltage, voltage,
- "Expected %dmV but got %dmV", expected_voltage,
+ /* isl923x_get_vbus_voltage treats the measured voltage as
+ * having an effective step size of 96 mV. This is slightly
+ * different than the scheme described in the ISL9238 datasheet.
+ * Reported VBUS should therefore be within 100 mV of nominal
+ * VBUS.
+ */
+ zassert_within(expected_voltage_mv, voltage, 100,
+ "Expected %dmV but got %dmV", expected_voltage_mv,
voltage);
}
}