summaryrefslogtreecommitdiff
path: root/power
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-03-08 10:38:03 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-28 19:04:16 -0700
commita029c7a27f3bd1a1066db9c167c6166688fe4ef3 (patch)
treec619eee562bbc8af7cddeda7b602e41a8b086ded /power
parent9c7428ea97fb6606979607457a86a1ebf8ec9b19 (diff)
downloadchrome-ec-a029c7a27f3bd1a1066db9c167c6166688fe4ef3.tar.gz
power: Allow board to take custom action on G3 timer expiration
This patch introduces board_system_is_idle callback function. It's called when system is in G3. A board can customize its action taken when system is idle in G3 using battery thresholds, expiration timer, etc. determined at runtime. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=nami,strago,coral TEST=Verify Vayne cut off battery on G3 idle expiration while other Nami's hibernate. Change-Id: I6118a074ac7d844b99d9c0f3eb638b72d5894008 Reviewed-on: https://chromium-review.googlesource.com/1512623 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'power')
-rw-r--r--power/common.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/power/common.c b/power/common.c
index c548425296..cccb34911a 100644
--- a/power/common.c
+++ b/power/common.c
@@ -5,6 +5,7 @@
/* Common functionality across all chipsets */
+#include "battery.h"
#include "charge_state.h"
#include "chipset.h"
#include "common.h"
@@ -281,6 +282,14 @@ static void power_set_active_wake_mask(void)
static void power_set_active_wake_mask(void) { }
#endif
+__attribute__((weak))
+enum critical_shutdown board_system_is_idle(uint64_t last_shutdown_time,
+ uint64_t *target, uint64_t now)
+{
+ return now > *target ?
+ CRITICAL_SHUTDOWN_HIBERNATE : CRITICAL_SHUTDOWN_IGNORE;
+}
+
/**
* Common handler for steady states
*
@@ -300,22 +309,28 @@ static enum power_state power_common_state(enum power_state state)
#ifdef CONFIG_HIBERNATE
{
uint64_t target, now, wait;
- uint32_t delay = hibernate_delay;
if (extpower_is_present()) {
task_wait_event(-1);
break;
}
now = get_time().val;
-#ifdef CONFIG_HIBERNATE_BATT_PCT
- if (charge_get_percent() <= CONFIG_HIBERNATE_BATT_PCT
- && CONFIG_HIBERNATE_BATT_SEC < delay)
- delay = CONFIG_HIBERNATE_BATT_SEC;
-#endif
- target = last_shutdown_time + delay * SECOND;
- if (now > target) {
- CPRINTS("hibernating");
+ target = last_shutdown_time + hibernate_delay * SECOND;
+ switch (board_system_is_idle(last_shutdown_time,
+ &target, now)) {
+ case CRITICAL_SHUTDOWN_HIBERNATE:
+ CPRINTS("Hibernate due to G3 idle");
system_hibernate(0, 0);
+ break;
+#ifdef CONFIG_BATTERY_CUT_OFF
+ case CRITICAL_SHUTDOWN_CUTOFF:
+ CPRINTS("Cutoff due to G3 idle");
+ board_cut_off_battery();
+ break;
+#endif
+ case CRITICAL_SHUTDOWN_IGNORE:
+ default:
+ break;
}
wait = MIN(target - now, TASK_MAX_WAIT_US);