diff options
-rw-r--r-- | board/samus/board.h | 4 | ||||
-rw-r--r-- | include/config.h | 13 | ||||
-rw-r--r-- | power/common.c | 13 |
3 files changed, 27 insertions, 3 deletions
diff --git a/board/samus/board.h b/board/samus/board.h index 394b621d74..d3bcc6a169 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -49,6 +49,10 @@ #define CONFIG_FANS 2 #define CONFIG_GESTURE_DETECTION #define CONFIG_GESTURE_SAMPLING_INTERVAL_MS 5 +#undef CONFIG_HIBERNATE_DELAY_SEC +#define CONFIG_HIBERNATE_DELAY_SEC (3600 * 24 * 7) +#define CONFIG_HIBERNATE_BATT_PCT 10 +#define CONFIG_HIBERNATE_BATT_SEC (3600 * 24) #define CONFIG_PECI_TJMAX 100 #define CONFIG_PWM #define CONFIG_PWM_KBLIGHT diff --git a/include/config.h b/include/config.h index 59256c816a..ba9efeb4c7 100644 --- a/include/config.h +++ b/include/config.h @@ -587,6 +587,19 @@ /* Enable system hibernate */ #define CONFIG_HIBERNATE +/* Default delay after shutting down before hibernating */ +#define CONFIG_HIBERNATE_DELAY_SEC 3600 + +/* + * Use to define going in to hibernate early if low on battery. + * CONFIG_HIBERNATE_BATT_PCT specifies the low battery threshold + * for going into hibernate early, and CONFIG_HIBERNATE_BATT_SEC defines + * the minimum amount of time to stay in G3 before checking for low + * battery hibernate. + */ +#undef CONFIG_HIBERNATE_BATT_PCT +#undef CONFIG_HIBERNATE_BATT_SEC + /* For ECs with multiple wakeup pins, define enabled wakeup pins */ #undef CONFIG_HIBERNATE_WAKEUP_PINS 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 |