From 60ddb3987a60a4a8b3a9daad9150021d017d0497 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Mon, 20 Oct 2014 16:44:18 -0700 Subject: samus: change hibernate delay to 7 days Add macro for default hibernate delay, and set to 7 days on samus. Also, adds CONFIG_ option for hibernating early if low on battery. For samus, setting early hibernate at 1 day when battery < 10%. BUG=chrome-os-partner:33088 BRANCH=samus TEST=make buildall Added ccprintf("Target shutdown: %.6ld\n", target_time); to print out target shutdown time after setting it. Verifed the following on samus 1) If CONFIG_HIBERNATE_DELAY_SEC is left at default 3600 (samus board.h does not overwrite it), then target time is 3600s. 2) If CONFIG_HIBERNATE_DELAY_SEC is defined in samus/board.h, then target time equals that value. 3) If CONFIG_HIBERNATE_DELAY_SEC is defined as 1 week and CONFIG_HIBERNATE_BATT_PCT is defined to 10% and CONFIG_HIBERNATE_BATT_SEC is 1 day, then when battery is between 8-10% target time is 1 day and if battery is at 11%, target time is 1 week. Change-Id: Ief155ad6c327775fa348d3458fc47ee9dd8569c3 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/224520 Reviewed-by: Randall Spangler --- power/common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'power/common.c') 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 -- cgit v1.2.1