summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Marheine <pmarheine@chromium.org>2023-04-21 14:53:03 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-24 00:24:04 +0000
commit3693fe33b5748bdc777457a4294a76d8ca0c69f9 (patch)
tree496dbf100633cdd162157675276790dc9d7a5db3
parent0e580733f98bbc62be8ec3c7bfdad9300fb2cb9f (diff)
downloadchrome-ec-3693fe33b5748bdc777457a4294a76d8ca0c69f9.tar.gz
nissa: implement test for preventing buck-boost on SM5803
With the SM5803 emulator landed, this uses the required functionality to test the board implementation of pd_is_valid_input_voltage(). The emulator is modified to explicitly cast dt_flags for the interrupt GPIO, because not doing so causes a warning (promoted to error) if using EC GPIO flags that lie outside the 16-bit range supported by gpio_dt_spec. BUG=b:267959470 TEST=twister -T zephyr/test/nissa BRANCH=nissa Change-Id: I7192cce5e7e3f08a148cddbf71d68b901d93dc2d Signed-off-by: Peter Marheine <pmarheine@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4458507 Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/emul/emul_sm5803.c3
-rw-r--r--zephyr/program/nissa/src/common.c2
-rw-r--r--zephyr/test/nissa/boards/chargers.dts15
-rw-r--r--zephyr/test/nissa/src/common.c21
4 files changed, 28 insertions, 13 deletions
diff --git a/zephyr/emul/emul_sm5803.c b/zephyr/emul/emul_sm5803.c
index 01038765ef..39dda70598 100644
--- a/zephyr/emul/emul_sm5803.c
+++ b/zephyr/emul/emul_sm5803.c
@@ -699,7 +699,8 @@ static int sm5803_emul_init(const struct emul *emul,
.port = DEVICE_DT_GET(DT_GPIO_CTLR(DT_DRV_INST(n), \
interrupt_gpios)), \
.pin = DT_INST_GPIO_PIN(n, interrupt_gpios), \
- .dt_flags = DT_INST_GPIO_FLAGS(n, interrupt_gpios), \
+ .dt_flags = (gpio_dt_flags_t) \
+ DT_INST_GPIO_FLAGS(n, interrupt_gpios), \
}, \
}; \
EMUL_DT_INST_DEFINE(n, sm5803_emul_init, &sm5803_emul_data_##n, \
diff --git a/zephyr/program/nissa/src/common.c b/zephyr/program/nissa/src/common.c
index 435ef95e29..def29ccd02 100644
--- a/zephyr/program/nissa/src/common.c
+++ b/zephyr/program/nissa/src/common.c
@@ -81,7 +81,7 @@ __override void ocpc_get_pid_constants(int *kp, int *kp_div, int *ki,
static int battery_cells;
-void board_get_battery_cells(void)
+test_export_static void board_get_battery_cells(void)
{
if (charger_get_battery_cells(CHARGER_PRIMARY, &battery_cells) ==
EC_SUCCESS) {
diff --git a/zephyr/test/nissa/boards/chargers.dts b/zephyr/test/nissa/boards/chargers.dts
index a14e9fbf10..5d72d197a7 100644
--- a/zephyr/test/nissa/boards/chargers.dts
+++ b/zephyr/test/nissa/boards/chargers.dts
@@ -23,19 +23,20 @@
};
&i2c_ctrl3 {
- chg_port0: isl923x@9 {
- compatible = "cros,isl923x-emul", "intersil,isl923x";
+ chg_port0: sm5803_primary@32 {
+ compatible = "cros,sm5803-emul", "siliconmitus,sm5803";
status = "okay";
- reg = <0x9>;
- battery = <&battery>;
+ reg = <0x32>;
+ interrupt-gpios = <&gpio0 1 GPIO_INPUT_PULL_UP>;
};
};
&i2c_ctrl5 {
- chg_port1: isl923x@9 {
- compatible = "cros,isl923x-emul", "intersil,isl923x";
+ chg_port1: sm5803_secondary@32 {
+ compatible = "cros,sm5803-emul", "siliconmitus,sm5803";
status = "okay";
- reg = <0x9>;
+ reg = <0x32>;
+ interrupt-gpios = <&gpio0 2 GPIO_INPUT_PULL_UP>;
};
};
diff --git a/zephyr/test/nissa/src/common.c b/zephyr/test/nissa/src/common.c
index a90520902a..2c97fb4e76 100644
--- a/zephyr/test/nissa/src/common.c
+++ b/zephyr/test/nissa/src/common.c
@@ -6,6 +6,7 @@
#include "ap_power/ap_power_events.h"
#include "battery.h"
#include "charger.h"
+#include "emul/emul_sm5803.h"
#include "hooks.h"
#include "ocpc.h"
#include "usb_pd.h"
@@ -23,6 +24,7 @@ static void suite_before(void *fixture)
{
RESET_FAKE(battery_is_present);
RESET_FAKE(board_get_usb_pd_port_count);
+ board_get_usb_pd_port_count_fake.return_val = 2;
RESET_FAKE(board_set_active_charge_port);
RESET_FAKE(power_button_is_pressed);
}
@@ -104,12 +106,23 @@ ZTEST(nissa_common, test_ocpc_configuration)
zassert_equal(ocpc_data.chg_flags[1], OCPC_NO_ISYS_MEAS_CAP);
}
+void board_get_battery_cells(void);
+
ZTEST(nissa_common, test_sm5803_buck_boost_forbidden)
{
+ const struct emul *const charger_emul =
+ EMUL_DT_GET(DT_NODELABEL(chg_port0));
+ int cells;
+
+ /* Default 2S PMODE allows 12V charging. */
+ zassert_ok(charger_get_battery_cells(0, &cells));
+ zassert_equal(cells, 2);
zassert_true(pd_is_valid_input_voltage(12000));
- /*
- * TODO(b:267959470): use SM5803 emulator for this test so behavior can
- * be verified with assorted battery cell counts.
- */
+ /* 3S forbids 12V charging. */
+ sm5803_emul_set_pmode(charger_emul, 0x16 /* 3S, 1.5A with BFET */);
+ zassert_ok(charger_get_battery_cells(0, &cells));
+ zassert_equal(cells, 3);
+ board_get_battery_cells(); /* Refresh cached cell count */
+ zassert_false(pd_is_valid_input_voltage(12000));
}