From 8ebdf9a0f15a0d95c60823c23b479f324d2607b5 Mon Sep 17 00:00:00 2001 From: Robert Zieba Date: Thu, 19 Jan 2023 00:43:01 +0000 Subject: zephyr/app/ec/ec_app_main: Add support for disabling sleep from boot Legacy EC code on some platforms disables sleep for the first 15 seconds following boot by default. Add the same functionality to zephyr. BRANCH=none BUG=b:249314949 TEST=Built and ran on skyrim device, verified sleep disabled Change-Id: I9c3f868d6d5a4d55d14b341bc1c4b304edd5be88 Signed-off-by: Robert Zieba Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4179368 Reviewed-by: Diana Z Reviewed-by: Keith Short --- zephyr/Kconfig | 12 ++++++++++++ zephyr/app/ec/ec_app_main.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 597e6ee250..38e2efe751 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -137,6 +137,18 @@ config PLATFORM_EC_BOARD_RESET_AFTER_POWER_ON the EC starts up, performs some amount of processing and then gets a reset that it is not expecting. +config PLATFORM_EC_BOOT_NO_SLEEP + bool "Disable deep sleep after boot" + default y if !ZTEST + help + Disable deep sleep for PLATFORM_EC_BOOT_NO_SLEEP_MS after boot. + +config PLATFORM_EC_BOOT_NO_SLEEP_MS + int "No deep sleep after boot duration" + default 15000 + help + Duration for PLATFORM_EC_BOOT_NO_SLEEP in ms. + config PLATFORM_EC_WAIT_RESET_CYCLES_PER_ITERATION int "CPU execution cycle per iteration for waiting the H1 reset" default 4 diff --git a/zephyr/app/ec/ec_app_main.c b/zephyr/app/ec/ec_app_main.c index 961e4f5ce2..d2dad10b2d 100644 --- a/zephyr/app/ec/ec_app_main.c +++ b/zephyr/app/ec/ec_app_main.c @@ -18,9 +18,15 @@ #include "zephyr_espi_shim.h" #include +#include #include #include +static void console_allow_sleep(struct k_timer *timer) +{ + pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); +} + /* For testing purposes this is not named main. See main_shim.c for the real * main() function. */ @@ -42,6 +48,18 @@ void ec_app_main(void) watchdog_init(); } + if (IS_ENABLED(CONFIG_PLATFORM_EC_BOOT_NO_SLEEP)) { + struct k_timer timer; + k_timeout_t duration = + K_MSEC(CONFIG_PLATFORM_EC_BOOT_NO_SLEEP_MS); + + k_timer_init(&timer, console_allow_sleep, NULL); + k_timer_start(&timer, duration, K_NO_WAIT); + + pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, + PM_ALL_SUBSTATES); + } + /* * Keyboard scan init/Button init can set recovery events to * indicate to host entry into recovery mode. Before this is -- cgit v1.2.1