diff options
author | Diana Z <dzigterman@chromium.org> | 2022-11-09 17:56:43 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-09 19:40:31 +0000 |
commit | e25163f03927764caa20c7751964a683c597355f (patch) | |
tree | 2d5a286d9c193d33b55ad8d369e4750570caa91b | |
parent | e8dbeb2cd4b075b3d26c2ea7a4f853ebee5ac093 (diff) | |
download | chrome-ec-e25163f03927764caa20c7751964a683c597355f.tar.gz |
Revert "hibernate: Add hibernate support to ap power code"
This reverts commit 16c8fce71986d50d9e10ea089d9d9352818129ad.
Reason for revert: Breaks hibernation on PSL boards (undefines CONFIG_HIBERNATE, which disables hibernate in common/system.c)
BUG=b:258093781
Original change's description:
> hibernate: Add hibernate support to ap power code
>
> Add hibernate support to the AP power sequence code.
>
> The smart discharge system isn't supported yet.
>
> The system will hibernate after a delay when the AP is in G3
> and there is no external power connected.
>
> v2: add tests
>
> BUG=b:246643307
> TEST=Run on nivviks with short delay
> BRANCH=none
>
> Signed-off-by: Andrew McRae <amcrae@google.com>
> Cq-Depend: chromium:3985352
> Change-Id: Ib7bb62c3d650a607343a6ea243645346f4b2a797
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3983631
> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Bug: b:246643307
Change-Id: Ia33273d4ebd1903b628cd163a5e3b35882badf14
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4017054
Auto-Submit: Diana Z <dzigterman@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Diana Z <dzigterman@chromium.org>
-rw-r--r-- | power/hibernate.c | 181 | ||||
-rw-r--r-- | util/config_allowed.txt | 2 | ||||
-rw-r--r-- | zephyr/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/Kconfig.system | 19 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 9 | ||||
-rw-r--r-- | zephyr/test/ap_power/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/test/ap_power/include/test_mocks.h | 21 | ||||
-rw-r--r-- | zephyr/test/ap_power/prj.conf | 3 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/board.c | 5 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/hibdelay.c | 37 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/hibernate.c | 41 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/host_command.c | 28 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/test_mocks.c | 30 |
13 files changed, 7 insertions, 374 deletions
diff --git a/power/hibernate.c b/power/hibernate.c deleted file mode 100644 index 322adca3ea..0000000000 --- a/power/hibernate.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/init.h> -#include <zephyr/logging/log.h> - -#include <ap_power/ap_power.h> -#include <ap_power/ap_power_interface.h> - -#include "console.h" -#include "extpower.h" -#include "hooks.h" -#include "host_command.h" -#include "system.h" -#include "util.h" - -LOG_MODULE_DECLARE(ap_pwrseq, CONFIG_AP_PWRSEQ_LOG_LEVEL); - -/* - * Hibernate processing. - * - * When enabled, the system will be put into an extreme low - * power state after the AP is in G3 for a configurable period of time, - * and there is no external power connected (i.e on battery). - * - * The delay has a configurable default, and may be set dynamically - * via a host command, or an EC console command. A typical delay - * may be 1 hour (3600 seconds). - * - * AP events such as AP_POWER_HARD_OFF are listened for, and - * a timer is used to detect when the AP has been off for the - * selected delay time. If the AP is started again, the timer is canceled. - * Once the timer expires, the system_hibernate() function is called, - * and this will suspend the EC until a wake signal is received. - */ -static uint32_t hibernate_delay = CONFIG_HIBERNATE_DELAY_SEC; - -/* - * Return true if conditions are right for hibernation. - */ -static inline bool ready_to_hibernate(void) -{ - return ap_power_in_or_transitioning_to_state(AP_POWER_STATE_HARD_OFF) && - !extpower_is_present(); -} - -/* - * The AP has been off for the delay period, so hibernate the system, - * if ready. Called from system work queue. - */ -static void hibernate_handler(struct k_work *unused) -{ - if (ready_to_hibernate()) { - LOG_INF("System hibernating due to %d seconds AP off", - hibernate_delay); - system_hibernate(0, 0); - } -} - -K_WORK_DEFINE(hibernate_work, hibernate_handler); - -/* - * Hibernate timer handler. - * Called when timer has expired. - * Schedule hibernate_handler to run via system work queue. - */ -static void timer_handler(struct k_timer *timer) -{ - k_work_submit(&hibernate_work); -} - -K_TIMER_DEFINE(hibernate_timer, timer_handler, NULL); - -/* - * A change has been detected in either the AP state or the - * external power supply. - */ -static void change_detected(void) -{ - if (ready_to_hibernate()) { - /* - * AP is off, and there is no external power. - * Start the timer if it is not already running. - */ - if (k_timer_remaining_get(&hibernate_timer) == 0) { - k_timer_start(&hibernate_timer, - K_SECONDS(hibernate_delay), K_NO_WAIT); - } - - } else { - /* - * AP is either on, or external power is on. - * Either way, no hibernation is done. - * Make sure the timer is not running. - */ - k_timer_stop(&hibernate_timer); - } -} - -static void ap_change(struct ap_power_ev_callback *callback, - struct ap_power_ev_data data) -{ - change_detected(); -} - -/* - * Hook to listen for external power supply changes. - */ -DECLARE_HOOK(HOOK_AC_CHANGE, change_detected, HOOK_PRIO_DEFAULT); - -/* - * EC Console command to get/set the hibernation delay - */ -static int command_hibernation_delay(int argc, const char **argv) -{ - char *e; - uint32_t remaining; - - if (argc >= 2) { - uint32_t s = strtoi(argv[1], &e, 0); - - if (*e) - return EC_ERROR_PARAM1; - - hibernate_delay = s; - } - - /* Print the current setting */ - ccprintf("Hibernation delay: %d s\n", hibernate_delay); - remaining = k_timer_remaining_get(&hibernate_timer); - if (remaining == 0) { - ccprintf("Timer not running\n"); - } else { - ccprintf("Time remaining: %d s\n", remaining / 1000); - } - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(hibdelay, command_hibernation_delay, "[sec]", - "Set the delay before going into hibernation"); -/* - * Host command to set the hibernation delay - */ -static enum ec_status -host_command_hibernation_delay(struct host_cmd_handler_args *args) -{ - const struct ec_params_hibernation_delay *p = args->params; - struct ec_response_hibernation_delay *r = args->response; - - /* Only change the hibernation delay if seconds is non-zero. */ - if (p->seconds) - hibernate_delay = p->seconds; - - r->hibernate_delay = hibernate_delay; - /* - * It makes no sense to try and set these values since - * they are only valid when the AP is in G3 (so this - * host command will never be called at that point). - */ - r->time_g3 = 0; - r->time_remaining = 0; - - args->response_size = sizeof(struct ec_response_hibernation_delay); - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_HIBERNATION_DELAY, host_command_hibernation_delay, - EC_VER_MASK(0)); - -static int hibernate_init(const struct device *unused) -{ - static struct ap_power_ev_callback cb; - - ap_power_ev_init_callback(&cb, ap_change, - AP_POWER_INITIALIZED | AP_POWER_HARD_OFF | - AP_POWER_STARTUP); - ap_power_ev_add_callback(&cb); - return 0; -} - -SYS_INIT(hibernate_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/util/config_allowed.txt b/util/config_allowed.txt index bdf8e0eca8..66109880ed 100644 --- a/util/config_allowed.txt +++ b/util/config_allowed.txt @@ -455,8 +455,10 @@ CONFIG_H2RAM_BASE CONFIG_H2RAM_HOST_LPC_IO_BASE CONFIG_H2RAM_SIZE CONFIG_HAS_TASK_PD_INT +CONFIG_HIBERNATE CONFIG_HIBERNATE_BATT_PCT CONFIG_HIBERNATE_BATT_SEC +CONFIG_HIBERNATE_DELAY_SEC CONFIG_HIBERNATE_PSL_COMPENSATE_RTC CONFIG_HIBERNATE_PSL_OUT_FLAGS CONFIG_HIBERNATE_PSL_VCC1_RST_WAKEUP diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index ec88fa7e43..65f5c5b92d 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -361,9 +361,6 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_POWERSEQ_SC7180 "${PLATFORM_EC}/power/qcom.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_POWERSEQ_SC7280 "${PLATFORM_EC}/power/qcom.c") -if (CONFIG_PLATFORM_EC_HIBERNATE AND CONFIG_AP_PWRSEQ) - zephyr_library_sources( "${PLATFORM_EC}/power/hibernate.c") -endif () zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PANIC "${PLATFORM_EC}/common/panic_output.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SHA256_SW diff --git a/zephyr/Kconfig.system b/zephyr/Kconfig.system index ffba537558..5467bc7422 100644 --- a/zephyr/Kconfig.system +++ b/zephyr/Kconfig.system @@ -28,25 +28,6 @@ config PLATFORM_EC_HIBERNATE_PSL rail for ultra-low power consumption and uses PSL inputs rely on VSBY power rail to wake up ec and the whole system. -config PLATFORM_EC_HIBERNATE - bool "System hibernating with wake-source pins" - default y - depends on !PLATFORM_EC_HIBERNATE_PSL - help - Use wake source pins for hibernating. It turns off VCC power - rail for ultra-low power consumption and uses a low power - power rail. Changes on wake source pins will wake up the EC. - By default this is enabled if PLATFORM_EC_HIBERNATE_PSL is not - enabled. - -config PLATFORM_EC_HIBERNATE_DELAY_SEC - int "Delay in seconds from AP power off to hibernate" - depends on PLATFORM_EC_HIBERNATE - default 3600 - help - This value is the delay in seconds from when the AP enters G3 - to when the system is hibernated. - config PLATFORM_EC_SYSTEM_PRE_INIT_PRIORITY int "System pre-initialization priority" default 20 diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 3ecfd5baf7..d2b5bbf577 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -2434,15 +2434,6 @@ extern char mock_jump_data[sizeof(struct jump_data) + 256]; #define CONFIG_HIBERNATE_PSL #endif -#undef CONFIG_HIBERNATE -#ifdef CONFIG_PLATFORM_EC_HIBERNATE -#define CONFIG_HIBERNATE -#ifdef CONFIG_PLATFORM_EC_HIBERNATE_DELAY_SEC -#undef CONFIG_HIBERNATE_DELAY_SEC -#define CONFIG_HIBERNATE_DELAY_SEC CONFIG_PLATFORM_EC_HIBERNATE_DELAY_SEC -#endif -#endif - #undef CONFIG_BATTERY_DEVICE_CHEMISTRY #ifdef CONFIG_PLATFORM_EC_USE_BATTERY_DEVICE_CHEMISTRY #define CONFIG_BATTERY_DEVICE_CHEMISTRY \ diff --git a/zephyr/test/ap_power/CMakeLists.txt b/zephyr/test/ap_power/CMakeLists.txt index 4669dac07e..7b44013961 100644 --- a/zephyr/test/ap_power/CMakeLists.txt +++ b/zephyr/test/ap_power/CMakeLists.txt @@ -6,8 +6,6 @@ cmake_minimum_required(VERSION 3.13.1) find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}") project(ap_power) -add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils) - # Include the local test directory for shimmed_test_tasks.h zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}") zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") diff --git a/zephyr/test/ap_power/include/test_mocks.h b/zephyr/test/ap_power/include/test_mocks.h deleted file mode 100644 index 8e9c80ad43..0000000000 --- a/zephyr/test/ap_power/include/test_mocks.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef __TEST_AP_POWER_TEST_MOCKS_H -#define __TEST_AP_POWER_TEST_MOCKS_H - -#include <zephyr/fff.h> - -/* - * Mock declarations - */ - -/* Mocks for common/extpower_gpio.c */ -DECLARE_FAKE_VALUE_FUNC(int, extpower_is_present); - -/* Mocks for common/system.c */ -DECLARE_FAKE_VOID_FUNC(system_hibernate, uint32_t, uint32_t); - -#endif /* __TEST_AP_POWER_TEST_MOCKS_H */ diff --git a/zephyr/test/ap_power/prj.conf b/zephyr/test/ap_power/prj.conf index 122b84e877..c72eace288 100644 --- a/zephyr/test/ap_power/prj.conf +++ b/zephyr/test/ap_power/prj.conf @@ -52,9 +52,6 @@ CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD=y CONFIG_PLATFORM_EC_HOSTCMD=y CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK=y -# Short delay for hibernate -CONFIG_PLATFORM_EC_HIBERNATE_DELAY_SEC=20 - # These items are not required. CONFIG_PLATFORM_EC_BACKLIGHT_LID=n CONFIG_PLATFORM_EC_SWITCH=n diff --git a/zephyr/test/ap_power/src/board.c b/zephyr/test/ap_power/src/board.c index bada154bb3..294cb942c9 100644 --- a/zephyr/test/ap_power/src/board.c +++ b/zephyr/test/ap_power/src/board.c @@ -102,3 +102,8 @@ bool board_ap_power_check_power_rails_enabled(void) { return true; } + +int extpower_is_present(void) +{ + return 0; +} diff --git a/zephyr/test/ap_power/src/hibdelay.c b/zephyr/test/ap_power/src/hibdelay.c deleted file mode 100644 index 02442adec8..0000000000 --- a/zephyr/test/ap_power/src/hibdelay.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/shell/shell.h> -#include <zephyr/ztest.h> - -#include "console.h" -#include "ec_commands.h" -#include "test_state.h" - -ZTEST_SUITE(console_cmd_hibdelay, ap_power_predicate_post_main, NULL, NULL, - NULL, NULL); - -ZTEST_USER(console_cmd_hibdelay, test_too_many_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay 1 2"), NULL); -} - -ZTEST_USER(console_cmd_hibdelay, test_no_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay"), NULL); -} - -ZTEST_USER(console_cmd_hibdelay, test_invalid_arg) -{ - int rv = shell_execute_cmd(get_ec_shell(), "hibdelay 3.4"); - - zassert_equal(rv, EC_ERROR_PARAM1, "Expected %d, but got %d", - EC_ERROR_PARAM1, rv); -} - -ZTEST_USER(console_cmd_hibdelay, test_valid_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay 5"), NULL); -} diff --git a/zephyr/test/ap_power/src/hibernate.c b/zephyr/test/ap_power/src/hibernate.c deleted file mode 100644 index 2309508f4b..0000000000 --- a/zephyr/test/ap_power/src/hibernate.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/device.h> - -#include <zephyr/logging/log.h> -#include <zephyr/kernel.h> -#include <zephyr/ztest.h> - -#include <ap_power/ap_power.h> -#include <ap_power/ap_power_events.h> -#include <ap_power/ap_power_interface.h> - -#include "hooks.h" - -#include "test_mocks.h" -#include "test_state.h" - -ZTEST(hibernate, test_g3_hibernate) -{ - extpower_is_present_fake.return_val = 0; - ap_power_ev_send_callbacks(AP_POWER_HARD_OFF); - k_sleep(K_SECONDS(30)); - zassert_equal(1, system_hibernate_fake.call_count); -} - -ZTEST(hibernate, test_ac_changed) -{ - extpower_is_present_fake.return_val = 1; - hook_notify(HOOK_AC_CHANGE); - k_sleep(K_SECONDS(30)); - zassert_equal(0, system_hibernate_fake.call_count); - extpower_is_present_fake.return_val = 0; - hook_notify(HOOK_AC_CHANGE); - k_sleep(K_SECONDS(30)); - zassert_equal(1, system_hibernate_fake.call_count); -} - -ZTEST_SUITE(hibernate, ap_power_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/ap_power/src/host_command.c b/zephyr/test/ap_power/src/host_command.c deleted file mode 100644 index 4367f8fa44..0000000000 --- a/zephyr/test/ap_power/src/host_command.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/ztest.h> - -#include "ec_commands.h" -#include "host_command.h" -#include "test_state.h" - -ZTEST(host_cmd, test_hibernate_get) -{ - struct ec_response_hibernation_delay response; - struct ec_params_hibernation_delay params = { - .seconds = 0, - }; - - struct host_cmd_handler_args args = BUILD_HOST_COMMAND( - EC_CMD_HIBERNATION_DELAY, 0, response, params); - - zassert_ok(host_command_process(&args)); - params.seconds = 123; - zassert_ok(host_command_process(&args)); - zassert_equal(123, response.hibernate_delay, NULL); -} - -ZTEST_SUITE(host_cmd, ap_power_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/ap_power/src/test_mocks.c b/zephyr/test/ap_power/src/test_mocks.c deleted file mode 100644 index 5dae36a6ab..0000000000 --- a/zephyr/test/ap_power/src/test_mocks.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/fff.h> -#include <zephyr/ztest.h> - -#include "test_mocks.h" - -/* Mocks for common/extpower_gpio.c */ -DEFINE_FAKE_VALUE_FUNC(int, extpower_is_present); - -/* Mocks for common/system.c */ -DEFINE_FAKE_VOID_FUNC(system_hibernate, uint32_t, uint32_t); - -/** - * @brief Reset all the fakes before each test. - */ -static void fff_reset_rule_before(const struct ztest_unit_test *test, - void *data) -{ - ARG_UNUSED(test); - ARG_UNUSED(data); - - RESET_FAKE(extpower_is_present); - RESET_FAKE(system_hibernate); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); |