diff options
author | Keith Short <keithshort@chromium.org> | 2021-04-24 14:26:16 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-29 18:34:01 +0000 |
commit | 13a437909f984da73327a8e4ce6ed8adb0ccdce6 (patch) | |
tree | 2091a3e14d33ae6bf9bc390f7cb450304ff7fbc4 /zephyr/shim/chip | |
parent | 85ea1cd0acb35b141d9f5deef26ff96e32d87365 (diff) | |
download | chrome-ec-13a437909f984da73327a8e4ce6ed8adb0ccdce6.tar.gz |
zephyr: npcx: Add power management support
Add power management support for the NPCX family.
BUG=b:184653704
BRANCH=none
TEST=zmake testall
TEST=Verify deep sleep on Volteer (with next CL) and measure power.
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: I86eef50c13742e7ca717da38a92636e589af6c58
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2855527
Reviewed-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com>
Diffstat (limited to 'zephyr/shim/chip')
-rw-r--r-- | zephyr/shim/chip/npcx/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/shim/chip/npcx/power_policy.c | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt index 86b7a9ae2f..79d81f720e 100644 --- a/zephyr/shim/chip/npcx/CMakeLists.txt +++ b/zephyr/shim/chip/npcx/CMakeLists.txt @@ -12,3 +12,4 @@ zephyr_library_sources_ifdef(CONFIG_CROS_EC system.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_EXTERNAL_STORAGE system_external_storage.c) +zephyr_library_sources_ifdef(CONFIG_PM_POLICY_APP power_policy.c) diff --git a/zephyr/shim/chip/npcx/power_policy.c b/zephyr/shim/chip/npcx/power_policy.c new file mode 100644 index 0000000000..e3f280438f --- /dev/null +++ b/zephyr/shim/chip/npcx/power_policy.c @@ -0,0 +1,39 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr.h> +#include <power/power.h> +#include <soc.h> + +#include "console.h" +#include "system.h" + +static const struct pm_state_info pm_min_residency[] = + PM_STATE_INFO_DT_ITEMS_LIST(DT_NODELABEL(cpu0)); + +/* CROS PM policy handler */ +struct pm_state_info pm_policy_next_state(int32_t ticks) +{ + /* Deep sleep is allowed and console is not in use. */ + if (DEEP_SLEEP_ALLOWED != 0 && !npcx_power_console_is_in_use()) { + for (int i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) { + /* Find suitable power state by residency time */ + if (ticks == K_TICKS_FOREVER || + ticks >= k_us_to_ticks_ceil32( + pm_min_residency[i] + .min_residency_us)) { + return pm_min_residency[i]; + } + } + } + + return (struct pm_state_info){ PM_STATE_ACTIVE, 0, 0 }; +} + +/* CROS PM device policy handler */ +bool pm_policy_low_power_devices(enum pm_state state) +{ + return pm_is_sleep_state(state); +} |