From 13a437909f984da73327a8e4ce6ed8adb0ccdce6 Mon Sep 17 00:00:00 2001 From: Keith Short Date: Sat, 24 Apr 2021 14:26:16 -0600 Subject: 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 Change-Id: I86eef50c13742e7ca717da38a92636e589af6c58 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2855527 Reviewed-by: Wealian Liao --- zephyr/shim/chip/npcx/CMakeLists.txt | 1 + zephyr/shim/chip/npcx/power_policy.c | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 zephyr/shim/chip/npcx/power_policy.c (limited to 'zephyr/shim/chip') 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 +#include +#include + +#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); +} -- cgit v1.2.1