summaryrefslogtreecommitdiff
path: root/power/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'power/common.c')
-rw-r--r--power/common.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/power/common.c b/power/common.c
index 96c6966900..e08fcf369c 100644
--- a/power/common.c
+++ b/power/common.c
@@ -5,6 +5,7 @@
/* Common functionality across all chipsets */
+#include "charge_state.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -54,7 +55,7 @@ static uint64_t last_shutdown_time; /* When did we enter G3? */
#ifdef CONFIG_HIBERNATE
/* Delay before hibernating, in seconds */
-static uint32_t hibernate_delay = 3600;
+static uint32_t hibernate_delay = CONFIG_HIBERNATE_DELAY_SEC;
#endif
/**
@@ -146,9 +147,15 @@ static enum power_state power_common_state(enum power_state state)
if (extpower_is_present())
task_wait_event(-1);
else {
- uint64_t target_time = last_shutdown_time +
- hibernate_delay * 1000000ull;
+ uint64_t target_time;
uint64_t time_now = get_time().val;
+ uint32_t delay = hibernate_delay;
+#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_time = last_shutdown_time + delay * 1000000ull;
if (time_now > target_time) {
/*
* Time's up. Hibernate until wake pin