diff options
-rw-r--r-- | zephyr/shim/src/ztest_system.c | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/include/utils.h | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 15 | ||||
-rw-r--r-- | zephyr/test/drivers/src/bb_retimer.c | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/src/power_common.c | 18 | ||||
-rw-r--r-- | zephyr/test/drivers/src/stubs.c | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/src/usb_mux.c | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/src/utils.c | 33 |
8 files changed, 71 insertions, 17 deletions
diff --git a/zephyr/shim/src/ztest_system.c b/zephyr/shim/src/ztest_system.c index 7df64d3b2b..7c9d938f53 100644 --- a/zephyr/shim/src/ztest_system.c +++ b/zephyr/shim/src/ztest_system.c @@ -62,7 +62,10 @@ int system_is_in_rw(void) uint32_t system_get_reset_flags(void) { - return 0; + /* Don't power up the AP automatically, let the tests do it if they + * need to. + */ + return EC_RESET_FLAG_AP_OFF; } void system_print_banner(void) diff --git a/zephyr/test/drivers/include/utils.h b/zephyr/test/drivers/include/utils.h index 1f0e830697..b6237aae89 100644 --- a/zephyr/test/drivers/include/utils.h +++ b/zephyr/test/drivers/include/utils.h @@ -11,4 +11,7 @@ /** @brief Set chipset to S0 state. Call all necessary hooks. */ void test_set_chipset_to_s0(void); +/** @brief Set chipset to G3 state. Call all necessary hooks. */ +void test_set_chipset_to_g3(void); + #endif /* ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ */ diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index e5d700665c..1f92adc633 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -85,7 +85,7 @@ enum-name = "GPIO_USB_C0_PPC_INT_ODL"; }; gpio_switchcap_pg_int_l: switchcap_pg_int_l { - gpios = <&gpio0 15 GPIO_INPUT>; + gpios = <&gpio0 15 (GPIO_OUTPUT | GPIO_INPUT)>; }; gpio_ap_rst_l: ap_rst_l { gpios = <&gpio0 16 GPIO_INPUT>; @@ -96,7 +96,8 @@ enum-name = "GPIO_PS_HOLD"; }; gpio_mb_power_good: mb_power_good { - gpios = <&gpio0 18 (GPIO_INPUT | GPIO_PULL_DOWN)>; + gpios = <&gpio0 18 (GPIO_OUTPUT | GPIO_INPUT | + GPIO_PULL_DOWN)>; enum-name = "GPIO_POWER_GOOD"; }; gpio_ap_suspend: ap_suspend { @@ -120,7 +121,7 @@ enum-name = "GPIO_LID_OPEN"; }; gpio_switchcap_on: switchcap_on { - gpios = <&gpio0 24 GPIO_OUT_LOW>; + gpios = <&gpio0 24 (GPIO_INPUT | GPIO_OUT_LOW)>; enum-name = "GPIO_SWITCHCAP_ON"; }; gpio_ec_pwr_btn_odl: ec_pwr_btn_odl { @@ -128,7 +129,8 @@ enum-name = "GPIO_POWER_BUTTON_L"; }; gpio_src_vph_pwr_pg: src_vph_pwr_pg { - gpios = <&gpio0 26 (GPIO_INPUT | GPIO_PULL_DOWN)>; + gpios = <&gpio0 26 (GPIO_INPUT | GPIO_OUTPUT | + GPIO_PULL_DOWN)>; enum-name = "GPIO_SWITCHCAP_PG"; }; gpio_test: test { @@ -175,6 +177,11 @@ flags = <GPIO_INT_EDGE_BOTH>; handler = "gpio_test_interrupt"; }; + int_mb_power_good: mb_power_good { + irq-pin = <&gpio_mb_power_good>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; }; named-i2c-ports { diff --git a/zephyr/test/drivers/src/bb_retimer.c b/zephyr/test/drivers/src/bb_retimer.c index 518cb8970a..3d13fd8c51 100644 --- a/zephyr/test/drivers/src/bb_retimer.c +++ b/zephyr/test/drivers/src/bb_retimer.c @@ -17,9 +17,11 @@ #include "stubs.h" #include "usb_prl_sm.h" #include "usb_tc_sm.h" +#include "chipset.h" #include "driver/retimer/bb_retimer.h" #include "test_state.h" +#include "utils.h" #define GPIO_USB_C1_LS_EN_PATH DT_PATH(named_gpios, usb_c1_ls_en) #define GPIO_USB_C1_LS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_LS_EN_PATH, gpios) @@ -446,7 +448,7 @@ ZTEST_USER(bb_retimer, test_bb_init) emul = bb_emul_get(BB_RETIMER_ORD); /* Set AP to normal state and wait for chipset task */ - power_set_state(POWER_S0); + test_set_chipset_to_s0(); /* Setup emulator fail on read */ i2c_common_emul_set_read_fail_reg(emul, BB_RETIMER_REG_VENDOR_ID); @@ -507,7 +509,7 @@ ZTEST_USER(bb_retimer, test_bb_init) NULL); /* Set AP to off state and wait for chipset task */ - power_set_state(POWER_G3); + test_set_chipset_to_g3(); /* With AP off, init should fail and pins should be unset */ zassert_equal(EC_ERROR_NOT_POWERED, diff --git a/zephyr/test/drivers/src/power_common.c b/zephyr/test/drivers/src/power_common.c index ee055745af..04250f6b77 100644 --- a/zephyr/test/drivers/src/power_common.c +++ b/zephyr/test/drivers/src/power_common.c @@ -25,6 +25,7 @@ #include "battery.h" #include "battery_smart.h" +#include "utils.h" #define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery)) @@ -111,7 +112,7 @@ static int in_state_test_masks[] = { }; /** Test chipset_in_state() for each state */ -ZTEST(power_common, test_power_chipset_in_state) +ZTEST(power_common_no_tasks, test_power_chipset_in_state) { bool expected_in_state; bool transition_from; @@ -146,7 +147,7 @@ ZTEST(power_common, test_power_chipset_in_state) } /** Test chipset_in_or_transitioning_to_state() for each state */ -ZTEST(power_common, test_power_chipset_in_or_transitioning_to_state) +ZTEST(power_common_no_tasks, test_power_chipset_in_or_transitioning_to_state) { bool expected_in_state; bool in_state; @@ -482,8 +483,7 @@ static void setup_hibernation_delay(void *state) bat->volt = battery_get_info()->voltage_normal; /* Force initial state */ - power_set_state(POWER_G3); - zassert_equal(POWER_G3, power_get_state(), NULL); + test_set_chipset_to_g3(); /* Disable AC */ zassert_ok(gpio_emul_input_set(acok_dev, GPIO_ACOK_OD_PIN, 0), NULL); @@ -505,6 +505,11 @@ ZTEST(power_common_hibernation, test_power_hc_hibernation_delay) uint32_t h_delay; int sleep_time; + zassert_equal(power_get_state(), POWER_G3, + "Power state is %d, expected G3", power_get_state()); + /* This is a no-op, but it will reset the last_shutdown_time. */ + power_set_state(POWER_G3); + /* Set hibernate delay */ h_delay = 9; params.seconds = h_delay; @@ -616,6 +621,11 @@ ZTEST(power_common_hibernation, test_power_cmd_hibernation_delay) uint32_t h_delay; int sleep_time; + zassert_equal(power_get_state(), POWER_G3, + "Power state is %d, expected G3", power_get_state()); + /* This is a no-op, but it will reset the last_shutdown_time. */ + power_set_state(POWER_G3); + /* Test success on call without argument */ zassert_equal(EC_SUCCESS, shell_execute_cmd(shell_backend_uart_get_ptr(), diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c index 85d7e99d13..ca33bff089 100644 --- a/zephyr/test/drivers/src/stubs.c +++ b/zephyr/test/drivers/src/stubs.c @@ -385,6 +385,11 @@ DECLARE_HOOK(HOOK_INIT, stubs_interrupt_init, HOOK_PRIO_INIT_I2C + 1); void board_set_switchcap_power(int enable) { gpio_set_level(GPIO_SWITCHCAP_ON, enable); + /* TODO(b/217554681): So, the ln9310 emul should probably be setting + * this instead of setting it here. + */ + gpio_set_level(GPIO_SWITCHCAP_PG, enable); + gpio_set_level(GPIO_POWER_GOOD, enable); } int board_is_switchcap_enabled(void) diff --git a/zephyr/test/drivers/src/usb_mux.c b/zephyr/test/drivers/src/usb_mux.c index c49091f37f..d9ab2901a3 100644 --- a/zephyr/test/drivers/src/usb_mux.c +++ b/zephyr/test/drivers/src/usb_mux.c @@ -27,6 +27,7 @@ #include "usb_mux.h" #include "test_state.h" +#include "utils.h" /** Copy of original usb_muxes[USB_PORT_C1] */ struct usb_mux usb_mux_c1; @@ -404,7 +405,7 @@ ZTEST(usb_uninit_mux, test_usb_mux_init) set_test_runner_tid(); /* Set AP to normal state to init BB retimer */ - power_set_state(POWER_S0); + test_set_chipset_to_s0(); /* Test successful initialisation */ usb_mux_init(USBC_PORT_C1); diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index 1fcfcfa52f..83b465b84c 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -5,6 +5,8 @@ #include <zephyr.h> #include <ztest.h> +#include <shell/shell_uart.h> +#include <drivers/gpio/gpio_emul.h> #include "battery.h" #include "battery_smart.h" @@ -12,14 +14,20 @@ #include "hooks.h" #include "power.h" #include "stubs.h" +#include "chipset.h" #define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery)) +#define GPIO_BATT_PRES_ODL_PATH DT_PATH(named_gpios, ec_batt_pres_odl) +#define GPIO_BATT_PRES_ODL_PORT DT_GPIO_PIN(GPIO_BATT_PRES_ODL_PATH, gpios) void test_set_chipset_to_s0(void) { struct sbat_emul_bat_data *bat; struct i2c_emul *emul; + const struct device *battery_gpio_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_BATT_PRES_ODL_PATH, gpios)); + printk("%s: Forcing power on\n", __func__); emul = sbat_emul_get_ptr(BATTERY_ORD); bat = sbat_emul_get_bat_data(emul); @@ -34,13 +42,28 @@ void test_set_chipset_to_s0(void) bat->volt = battery_get_info()->voltage_normal; bat->design_mv = bat->volt; - power_set_state(POWER_S0); - test_power_common_state(); + /* Set battery present gpio. */ + zassert_ok(gpio_emul_input_set(battery_gpio_dev, + GPIO_BATT_PRES_ODL_PORT, 0), + NULL); - /* Run all hooks on chipset */ - hook_notify(HOOK_CHIPSET_RESUME); - k_msleep(1); + /* The easiest way to power on seems to be the shell command. */ + zassert_equal(EC_SUCCESS, + shell_execute_cmd(shell_backend_uart_get_ptr(), + "power on"), + NULL); + + k_sleep(K_SECONDS(1)); /* Check if chipset is in correct state */ zassert_equal(POWER_S0, power_get_state(), NULL); } + +void test_set_chipset_to_g3(void) +{ + printk("%s: Forcing shutdown\n", __func__); + chipset_force_shutdown(CHIPSET_RESET_KB_SYSRESET); + k_sleep(K_SECONDS(20)); + /* Check if chipset is in correct state */ + zassert_equal(POWER_G3, power_get_state(), NULL); +} |