summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-10-26 11:29:11 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-01 21:00:28 +0000
commit4fbecddd847e7adffff8843cdf93f4c68f44309a (patch)
tree482b8f34ca48d94f2cee737755c091f3959b852f
parentbafcc352e44498bde12a80da2c993ff7a6343047 (diff)
downloadchrome-ec-4fbecddd847e7adffff8843cdf93f4c68f44309a.tar.gz
zephyr: Bring qcom.c test coverage to 100%
Test the final lines in qcom.c. Make battery_is_present() test mockable. Change gpio_pmic_resin_l to be input|output so that it can be read. The gpio_emul is strict and doesn't allow reading output gpios. Add gpio_switchcap_pg, instead of using the output gpio as the input power-good-pin. Remove most all of the gpio device pointers, since all the gpios are on the same port. test_chipset_reset_success stopped working because the callback on pmic_resin_l wasn't getting called. Set the interrupt flags to fix. In test_power_button wait to set power_good until after pmic_kpd_pwr_odl is set. This is slightly more realistic. Add 2 more failures cases in power on sequence. Exclude an unreachable line from lcov. BRANCH=None BUG=None TEST=./twister Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: Ie38f53addfbc745e046f017f322dada4486405ec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3994229 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--include/battery.h2
-rw-r--r--power/qcom.c1
-rw-r--r--zephyr/test/qcom_power/boards/native_posix.overlay11
-rw-r--r--zephyr/test/qcom_power/src/main.c311
4 files changed, 175 insertions, 150 deletions
diff --git a/include/battery.h b/include/battery.h
index 51fcd68696..be93b44c21 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -220,7 +220,7 @@ enum battery_present battery_is_present(void);
* If battery support is not enabled and the board does not specifically
* provide its own implementation, assume a battery is never present.
*/
-static inline enum battery_present battery_is_present(void)
+test_mockable_static_inline enum battery_present battery_is_present(void)
{
return BP_NO;
}
diff --git a/power/qcom.c b/power/qcom.c
index 30374cd330..eba2d32442 100644
--- a/power/qcom.c
+++ b/power/qcom.c
@@ -1139,7 +1139,6 @@ test_mockable enum power_state power_handle_state(enum power_state state)
default:
CPRINTS("Unexpected power state %d", state);
ASSERT(0);
- break;
}
return state;
diff --git a/zephyr/test/qcom_power/boards/native_posix.overlay b/zephyr/test/qcom_power/boards/native_posix.overlay
index f062f27614..802721f430 100644
--- a/zephyr/test/qcom_power/boards/native_posix.overlay
+++ b/zephyr/test/qcom_power/boards/native_posix.overlay
@@ -65,7 +65,10 @@
enum-name = "GPIO_PMIC_KPD_PWR_ODL";
};
gpio_pmic_resin_l: pmic_resin_l {
- gpios = <&gpio0 21 GPIO_OUTPUT_HIGH>;
+ /* Real hardware will allow reading even if GPIO_INPUT
+ * is not set, but the gpio_emul will not.
+ */
+ gpios = <&gpio0 21 (GPIO_INPUT | GPIO_OUTPUT_HIGH)>;
enum-name = "GPIO_PMIC_RESIN_L";
};
gpio_warm_reset_l: warm_reset_l {
@@ -87,6 +90,10 @@
gpios = <&gpio0 25 (GPIO_INPUT | GPIO_PULL_UP)>;
enum-name = "GPIO_POWER_BUTTON_L";
};
+ gpio_switchcap_pg: src_vph_pwr_pg {
+ gpios = <&gpio0 26 GPIO_INPUT_PULL_DOWN>;
+ enum-name = "GPIO_SWITCHCAP_PG";
+ };
};
gpio-interrupts {
@@ -135,7 +142,7 @@
switchcap {
compatible = "switchcap-gpio";
enable-pin = <&gpio_switchcap_on>;
- power-good-pin = <&gpio_switchcap_pg_int_l>;
+ power-good-pin = <&gpio_switchcap_pg>;
};
};
diff --git a/zephyr/test/qcom_power/src/main.c b/zephyr/test/qcom_power/src/main.c
index 22dd1fe2ec..33288af05f 100644
--- a/zephyr/test/qcom_power/src/main.c
+++ b/zephyr/test/qcom_power/src/main.c
@@ -16,7 +16,6 @@
#include "gpio_signal.h"
#include "power/qcom.h"
-#include "battery.h"
#include "ec_app_main.h"
#include "power.h"
#include "console.h"
@@ -24,14 +23,35 @@
#include "hooks.h"
#include "host_command.h"
#include "lid_switch.h"
-
-#define AP_RST_L_NODE DT_PATH(named_gpios, ap_rst_l)
-#define POWER_GOOD_NODE DT_PATH(named_gpios, mb_power_good)
-#define AP_SUSPEND_NODE DT_PATH(named_gpios, ap_suspend)
-#define SWITCHCAP_PG_NODE DT_PATH(named_gpios, switchcap_pg_int_l)
-#define PMIC_RESIN_L_NODE DT_PATH(named_gpios, pmic_resin_l)
-#define EC_PWR_BTN_ODL_NODE DT_PATH(named_gpios, ec_pwr_btn_odl)
-#define LID_OPEN_EC_NODE DT_PATH(named_gpios, lid_open_ec)
+#include "gpio.h"
+
+/* For simplicity, enforce that all the gpios are on the same controller. */
+#define GPIO_DEVICE \
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_PATH(named_gpios, ap_rst_l), gpios))
+#define ASSERT_SAME_CONTROLLER(x) \
+ BUILD_ASSERT(DT_DEP_ORD(DT_GPIO_CTLR(DT_PATH(named_gpios, ap_rst_l), \
+ gpios)) == \
+ DT_DEP_ORD(DT_GPIO_CTLR(DT_PATH(named_gpios, x), gpios)))
+
+#define AP_RST_L_PIN DT_GPIO_PIN(DT_PATH(named_gpios, ap_rst_l), gpios)
+ASSERT_SAME_CONTROLLER(ap_rst_l);
+#define POWER_GOOD_PIN DT_GPIO_PIN(DT_PATH(named_gpios, mb_power_good), gpios)
+ASSERT_SAME_CONTROLLER(mb_power_good);
+#define AP_SUSPEND_PIN DT_GPIO_PIN(DT_PATH(named_gpios, ap_suspend), gpios)
+ASSERT_SAME_CONTROLLER(ap_suspend);
+#define SWITCHCAP_PG_PIN \
+ DT_GPIO_PIN(DT_PATH(named_gpios, src_vph_pwr_pg), gpios)
+ASSERT_SAME_CONTROLLER(src_vph_pwr_pg);
+#define PMIC_RESIN_L_PIN DT_GPIO_PIN(DT_PATH(named_gpios, pmic_resin_l), gpios)
+ASSERT_SAME_CONTROLLER(pmic_resin_l);
+#define EC_PWR_BTN_ODL_PIN \
+ DT_GPIO_PIN(DT_PATH(named_gpios, ec_pwr_btn_odl), gpios)
+ASSERT_SAME_CONTROLLER(ec_pwr_btn_odl);
+#define LID_OPEN_EC_PIN DT_GPIO_PIN(DT_PATH(named_gpios, lid_open_ec), gpios)
+ASSERT_SAME_CONTROLLER(lid_open_ec);
+#define PMIC_KPD_PWR_ODL_PIN \
+ DT_GPIO_PIN(DT_PATH(named_gpios, pmic_kpd_pwr_odl), gpios)
+ASSERT_SAME_CONTROLLER(pmic_kpd_pwr_odl);
static int chipset_reset_count;
static bool set_power_good_on_reset;
@@ -45,11 +65,9 @@ DECLARE_HOOK(HOOK_CHIPSET_RESET, do_chipset_reset, HOOK_PRIO_DEFAULT);
static void do_chipset_shutdown(void)
{
if (set_power_good_on_reset) {
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1);
+ gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 1);
}
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, do_chipset_shutdown, HOOK_PRIO_DEFAULT);
@@ -58,6 +76,10 @@ DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC(int, system_can_boot_ap);
FAKE_VALUE_FUNC(int, battery_wait_for_stable);
+int battery_is_present(void)
+{
+ return 1;
+}
/* Tests the chipset_ap_rst_interrupt() handler when in S3.
*
@@ -68,15 +90,11 @@ FAKE_VALUE_FUNC(int, battery_wait_for_stable);
*/
static void do_chipset_ap_rst_interrupt_in_s3(int times)
{
- static const struct device *ap_rst_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios));
- static const struct device *ap_suspend_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
/* Preconditions */
power_signal_enable_interrupt(GPIO_AP_SUSPEND);
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 1));
power_set_state(POWER_S3);
task_wake(TASK_ID_CHIPSET);
k_sleep(K_MSEC(10));
@@ -87,18 +105,15 @@ static void do_chipset_ap_rst_interrupt_in_s3(int times)
/* Pulse gpio_ap_rst_l `times` */
for (int i = 0; i < times; ++i) {
- zassert_ok(gpio_emul_input_set(
- ap_rst_dev, DT_GPIO_PIN(AP_RST_L_NODE, gpios), 0));
- zassert_ok(gpio_emul_input_set(
- ap_rst_dev, DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 1));
}
/* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */
k_sleep(K_MSEC(500));
/* Verify that gpio_ap_suspend is ignored. */
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 0));
k_sleep(K_MSEC(10));
zassert_equal(power_get_state(), POWER_S3);
/* Verify that HOOK_CHIPSET_RESET was called once. */
@@ -140,18 +155,15 @@ ZTEST(qcom_power, test_notify_chipset_reset_s3)
*/
static void do_chipset_ap_rst_interrupt_in_s0(int times)
{
- static const struct device *ap_rst_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
shell_backend_dummy_clear_output(get_ec_shell());
chipset_reset_count = 0;
/* Pulse gpio_ap_rst_l `times` */
for (int i = 0; i < times; ++i) {
- zassert_ok(gpio_emul_input_set(
- ap_rst_dev, DT_GPIO_PIN(AP_RST_L_NODE, gpios), 0));
- zassert_ok(gpio_emul_input_set(
- ap_rst_dev, DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 1));
}
/* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */
@@ -218,39 +230,57 @@ void warm_reset_callback(const struct device *gpio_dev,
struct gpio_callback *callback_struct,
gpio_port_pins_t pins)
{
- if ((pins & BIT(DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios))) == 0) {
+ if ((pins & BIT(PMIC_RESIN_L_PIN)) == 0) {
return;
}
- if (gpio_emul_output_get(gpio_dev,
- DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios))) {
- static const struct device *ap_rst_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios));
+ if (gpio_emul_output_get(gpio_dev, PMIC_RESIN_L_PIN)) {
+ gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 0);
+ }
+}
+
+static void set_power_good(struct k_work *work)
+{
+ static const struct device *gpio_dev = GPIO_DEVICE;
+
+ gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 1);
+}
+K_WORK_DEFINE(set_power_good_work, set_power_good);
- gpio_emul_input_set(ap_rst_dev,
- DT_GPIO_PIN(AP_RST_L_NODE, gpios), 0);
+/* PMIC_KPD_PWR_ODL is a signal to turn the power on. The signal that
+ * it worked is POWER_GOOD.
+ */
+void power_good_callback(const struct device *gpio_dev,
+ struct gpio_callback *callback_struct,
+ gpio_port_pins_t pins)
+{
+ if ((pins & BIT(PMIC_KPD_PWR_ODL_PIN)) == 0) {
+ return;
+ }
+ if (!gpio_emul_output_get(gpio_dev, PMIC_KPD_PWR_ODL_PIN)) {
+ /* Set power good in the work queue, instead of now. */
+ k_work_submit(&set_power_good_work);
}
}
/* Call chipset_reset, wait for PMIC_RESIN_L, pulse ap_rsl_l. */
ZTEST(qcom_power, test_chipset_reset_success)
{
- static const struct device *ap_rst_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios));
- static const struct device *pmic_resin_l_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
const char *buffer;
size_t buffer_size;
/* Setup callback. */
gpio_init_callback(&gpio_callback, warm_reset_callback,
- BIT(DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios)));
- zassert_ok(gpio_add_callback(pmic_resin_l_dev, &gpio_callback));
+ BIT(PMIC_RESIN_L_PIN));
+ zassert_ok(gpio_add_callback(gpio_dev, &gpio_callback));
+ zassert_ok(gpio_pin_interrupt_configure(gpio_dev, PMIC_RESIN_L_PIN,
+ GPIO_INT_EDGE_BOTH));
/* Reset. The reason doesn't really matter. */
shell_backend_dummy_clear_output(get_ec_shell());
chipset_reset(CHIPSET_RESET_KB_WARM_REBOOT);
k_sleep(K_MSEC(100));
- gpio_emul_input_set(ap_rst_dev, DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1);
+ gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 1);
/* Long enough for a cold reset, although we don't expect one. */
k_sleep(K_MSEC(1000));
@@ -268,8 +298,7 @@ ZTEST(qcom_power, test_chipset_reset_success)
/* Sent the host command, set the gpio, wait for transition to S3. */
ZTEST(qcom_power, test_request_sleep)
{
- static const struct device *ap_suspend_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
struct ec_params_host_sleep_event params = {
.sleep_event = HOST_SLEEP_EVENT_S3_SUSPEND,
};
@@ -277,8 +306,7 @@ ZTEST(qcom_power, test_request_sleep)
EC_CMD_HOST_SLEEP_EVENT, UINT8_C(0), params);
zassert_ok(host_command_process(&args));
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 1));
k_sleep(K_SECONDS(16));
zassert_equal(power_get_state(), POWER_S3);
zassert_false(host_is_event_set(EC_HOST_EVENT_HANG_DETECT));
@@ -314,53 +342,88 @@ ZTEST(qcom_power, test_chipset_force_shutdown)
ZTEST(qcom_power, test_power_button)
{
- static const struct device *ec_pwr_btn_odl_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
+
+ /* Setup callback. */
+ gpio_init_callback(&gpio_callback, power_good_callback,
+ BIT(PMIC_KPD_PWR_ODL_PIN));
+ zassert_ok(gpio_add_callback(gpio_dev, &gpio_callback));
power_set_state(POWER_G3);
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, PMIC_RESIN_L_PIN, 1));
k_sleep(K_MSEC(10));
zassert_equal(power_get_state(), POWER_G3);
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
k_sleep(K_MSEC(100));
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S0);
}
ZTEST(qcom_power, test_power_button_no_power_good)
{
- static const struct device *ec_pwr_btn_odl_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios));
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- zassert_ok(gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
power_set_state(POWER_G3);
k_sleep(K_MSEC(10));
zassert_equal(power_get_state(), POWER_G3);
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
k_sleep(K_MSEC(100));
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
k_sleep(K_MSEC(1500));
zassert_equal(power_get_state(), POWER_S5, "power_state=%d",
power_get_state());
}
+ZTEST(qcom_power, test_power_button_no_switchcap_good)
+{
+ static const struct device *gpio_dev = GPIO_DEVICE;
+
+ zassert_ok(gpio_emul_input_set(gpio_dev, SWITCHCAP_PG_PIN, 0));
+ power_set_state(POWER_G3);
+ k_sleep(K_MSEC(10));
+ zassert_equal(power_get_state(), POWER_G3);
+
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
+ k_sleep(K_SECONDS(10));
+ zassert_equal(power_get_state(), POWER_S5, "power_state=%d",
+ power_get_state());
+}
+
+ZTEST(qcom_power, test_power_button_no_pmic_resin_pullup)
+{
+ const char *buffer;
+ size_t buffer_size;
+ static const struct device *gpio_dev = GPIO_DEVICE;
+
+ power_set_state(POWER_G3);
+ k_sleep(K_MSEC(10));
+ zassert_equal(power_get_state(), POWER_G3);
+
+ shell_backend_dummy_clear_output(get_ec_shell());
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, PMIC_RESIN_L_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
+ k_sleep(K_SECONDS(10));
+ zassert_equal(power_get_state(), POWER_S5, "power_state=%d",
+ power_get_state());
+
+ buffer = shell_backend_dummy_get_output(get_ec_shell(), &buffer_size);
+ zassert_not_null(strstr(buffer, "PMIC_RESIN_L not pulled up by PMIC"),
+ "Invalid console output %s", buffer);
+}
+
ZTEST(qcom_power, test_power_button_battery_low)
{
- static const struct device *ec_pwr_btn_odl_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
RESET_FAKE(system_can_boot_ap);
system_can_boot_ap_fake.return_val = 0;
@@ -369,13 +432,9 @@ ZTEST(qcom_power, test_power_button_battery_low)
k_sleep(K_MSEC(10));
zassert_equal(power_get_state(), POWER_G3);
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
k_sleep(K_MSEC(100));
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
/* > CAN_BOOT_AP_CHECK_TIMEOUT + CAN_BOOT_AP_CHECK_WAIT */
k_sleep(K_MSEC(1800));
zassert_equal(power_get_state(), POWER_S5);
@@ -383,8 +442,7 @@ ZTEST(qcom_power, test_power_button_battery_low)
ZTEST(qcom_power, test_host_sleep_event_resume)
{
- static const struct device *ap_suspend_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
struct ec_params_host_sleep_event params = {
.sleep_event = HOST_SLEEP_EVENT_S3_RESUME,
};
@@ -393,16 +451,14 @@ ZTEST(qcom_power, test_host_sleep_event_resume)
/* Get into S3 first */
power_signal_enable_interrupt(GPIO_AP_SUSPEND);
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 1));
power_set_state(POWER_S3);
task_wake(TASK_ID_CHIPSET);
k_sleep(K_MSEC(10));
zassert_equal(power_get_state(), POWER_S3);
/* Exit suspend via gpio. */
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 0));
k_sleep(K_MSEC(100));
zassert_equal(power_get_state(), POWER_S0, "power_state=%d",
power_get_state());
@@ -414,40 +470,29 @@ ZTEST(qcom_power, test_host_sleep_event_resume)
power_get_state());
/* Check that AP_SUSPEND interrupts are disabled & we are in S0. */
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 1));
k_sleep(K_MSEC(100));
zassert_equal(power_get_state(), POWER_S0);
}
ZTEST(qcom_power, test_power_button_off)
{
- static const struct device *ec_pwr_btn_odl_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
k_sleep(K_SECONDS(9));
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S5);
}
ZTEST(qcom_power, test_power_button_off_cancel)
{
- static const struct device *ec_pwr_btn_odl_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 0));
k_sleep(K_SECONDS(4));
- zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev,
- DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios),
- 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, EC_PWR_BTN_ODL_PIN, 1));
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S0);
}
@@ -456,12 +501,10 @@ ZTEST(qcom_power, test_no_power_good)
{
const char *buffer;
size_t buffer_size;
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
shell_backend_dummy_clear_output(get_ec_shell());
- zassert_ok(gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S5, "power_state=%d",
power_get_state());
@@ -474,12 +517,10 @@ ZTEST(qcom_power, test_no_power_good_then_good)
{
const char *buffer;
size_t buffer_size;
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
shell_backend_dummy_clear_output(get_ec_shell());
- zassert_ok(gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
set_power_good_on_reset = true;
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S5, "power_state=%d",
@@ -493,18 +534,15 @@ ZTEST(qcom_power, test_no_power_good_then_good)
ZTEST(qcom_power, test_lid_open_power_on)
{
- static const struct device *lid_open_ec_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(LID_OPEN_EC_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- zassert_ok(gpio_emul_input_set(
- lid_open_ec_dev, DT_GPIO_PIN(LID_OPEN_EC_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, LID_OPEN_EC_PIN, 0));
power_set_state(POWER_G3);
k_sleep(K_MSEC(100));
zassert_equal(power_get_state(), POWER_G3);
zassert_false(lid_is_open());
- zassert_ok(gpio_emul_input_set(
- lid_open_ec_dev, DT_GPIO_PIN(LID_OPEN_EC_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, LID_OPEN_EC_PIN, 1));
k_sleep(K_MSEC(500));
zassert_equal(power_get_state(), POWER_S0, "power_state=%d",
power_get_state());
@@ -556,11 +594,9 @@ ZTEST(qcom_power, test_power_chipset_init_sysjump_power_good)
ZTEST(qcom_power, test_power_chipset_init_sysjump_power_off)
{
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
- zassert_ok(gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 0));
system_set_reset_flags(EC_RESET_FLAG_SYSJUMP);
zassert_equal(power_chipset_init(), POWER_G3);
power_set_state(POWER_G3);
@@ -585,18 +621,7 @@ ZTEST(qcom_power, test_power_chipset_init_ap_off)
void start_in_s0(void *fixture)
{
- static const struct device *ap_rst_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios));
- static const struct device *power_good_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios));
- static const struct device *ap_suspend_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios));
- static const struct device *switchcap_pg_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios));
- static const struct device *pmic_resin_l_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios));
- static const struct device *lid_open_ec_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(LID_OPEN_EC_NODE, gpios));
+ static const struct device *gpio_dev = GPIO_DEVICE;
RESET_FAKE(system_can_boot_ap);
system_can_boot_ap_fake.return_val = 1;
@@ -604,18 +629,12 @@ void start_in_s0(void *fixture)
power_signal_disable_interrupt(GPIO_AP_SUSPEND);
power_signal_enable_interrupt(GPIO_AP_RST_L);
- zassert_ok(gpio_emul_input_set(power_good_dev,
- DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1));
- zassert_ok(gpio_emul_input_set(ap_suspend_dev,
- DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0));
- zassert_ok(gpio_emul_input_set(ap_rst_dev,
- DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1));
- zassert_ok(gpio_emul_input_set(
- switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1));
- zassert_ok(gpio_pin_set(pmic_resin_l_dev,
- DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios), 1));
- zassert_ok(gpio_emul_input_set(
- lid_open_ec_dev, DT_GPIO_PIN(LID_OPEN_EC_NODE, gpios), 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, POWER_GOOD_PIN, 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_SUSPEND_PIN, 0));
+ zassert_ok(gpio_emul_input_set(gpio_dev, AP_RST_L_PIN, 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, SWITCHCAP_PG_PIN, 1));
+ zassert_ok(gpio_pin_set(gpio_dev, PMIC_RESIN_L_PIN, 1));
+ zassert_ok(gpio_emul_input_set(gpio_dev, LID_OPEN_EC_PIN, 1));
power_set_state(POWER_S0);
power_signal_interrupt(GPIO_AP_SUSPEND);
task_wake(TASK_ID_CHIPSET);
@@ -629,9 +648,9 @@ void start_in_s0(void *fixture)
void qcom_cleanup(void *fixture)
{
if (gpio_callback.handler != NULL) {
- static const struct device *pmic_resin_l_dev =
- DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios));
- gpio_remove_callback(pmic_resin_l_dev, &gpio_callback);
+ static const struct device *gpio_dev = GPIO_DEVICE;
+
+ gpio_remove_callback(gpio_dev, &gpio_callback);
gpio_callback.handler = NULL;
}
host_clear_events(EC_HOST_EVENT_MASK(EC_HOST_EVENT_HANG_DETECT));