From 9148a4dc0188a92e239521feae12871ff8bd9626 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Wed, 27 Jan 2016 15:59:48 -0800 Subject: system: Add hibernate board-level callback Allow boards to take action (such as entering a custom low-power hibernate-like state) before putting the chip into hibernate state. BUG=chrome-os-partner:48835 BRANCH=glados TEST=Manual with subsequent commit on chell. Verify board-level hibernate callback is called when "hibernate" is run on EC console. Change-Id: Ie1da044037a74ff8bce5c822f28ce837c62ceec0 Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/324086 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Vincent Palatin --- chip/host/system.c | 3 +++ chip/it83xx/system.c | 3 +++ chip/mec1322/system.c | 3 +++ chip/npcx/system.c | 3 +++ chip/nrf51/system.c | 3 +++ chip/stm32/system.c | 3 +++ include/system.h | 7 +++++++ 7 files changed, 25 insertions(+) diff --git a/chip/host/system.c b/chip/host/system.c index b6a2fe6ab7..3de4ab10cd 100644 --- a/chip/host/system.c +++ b/chip/host/system.c @@ -154,6 +154,9 @@ test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds) { uint32_t i; + if (board_hibernate) + board_hibernate(); + save_reset_flags(RESET_FLAG_HIBERNATE); if (!seconds && !microseconds) diff --git a/chip/it83xx/system.c b/chip/it83xx/system.c index 90e234ce86..e81d84f423 100644 --- a/chip/it83xx/system.c +++ b/chip/it83xx/system.c @@ -36,6 +36,9 @@ void __enter_hibernate(uint32_t seconds, uint32_t microseconds) void system_hibernate(uint32_t seconds, uint32_t microseconds) { + if (board_hibernate) + board_hibernate(); + #ifdef CONFIG_HOSTCMD_PD /* Inform the PD MCU that we are going to hibernate. */ host_command_pd_request_hibernate(); diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index fd38321d39..f7fa770388 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -190,6 +190,9 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) { int i; + if (board_hibernate) + board_hibernate(); + #ifdef CONFIG_HOSTCMD_PD /* Inform the PD MCU that we are going to hibernate. */ host_command_pd_request_hibernate(); diff --git a/chip/npcx/system.c b/chip/npcx/system.c index 8123b9afcc..8e01f9955c 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -491,6 +491,9 @@ void system_enable_hib_interrupt(void) void system_hibernate(uint32_t seconds, uint32_t microseconds) { + if (board_hibernate) + board_hibernate(); + /* Flush console before hibernating */ cflush(); diff --git a/chip/nrf51/system.c b/chip/nrf51/system.c index 86d78b3170..7c6e6b1347 100644 --- a/chip/nrf51/system.c +++ b/chip/nrf51/system.c @@ -33,6 +33,9 @@ const char *system_get_chip_revision(void) void system_hibernate(uint32_t seconds, uint32_t microseconds) { + if (board_hibernate) + board_hibernate(); + /* Flush console before hibernating */ cflush(); diff --git a/chip/stm32/system.c b/chip/stm32/system.c index b1daf1ce4c..85b3ad9012 100644 --- a/chip/stm32/system.c +++ b/chip/stm32/system.c @@ -105,6 +105,9 @@ void __enter_hibernate(uint32_t seconds, uint32_t microseconds) void system_hibernate(uint32_t seconds, uint32_t microseconds) { + if (board_hibernate) + board_hibernate(); + #ifdef CONFIG_HOSTCMD_PD /* Inform the PD MCU that we are going to hibernate. */ host_command_pd_request_hibernate(); diff --git a/include/system.h b/include/system.h index 2a1c1784ca..9ae0da1bf0 100644 --- a/include/system.h +++ b/include/system.h @@ -267,6 +267,13 @@ int system_set_vbnvcontext(const uint8_t *block); */ void system_hibernate(uint32_t seconds, uint32_t microseconds); +/** + * Optional board-level callback function called prior to initiating chip-level + * hibernate sequence. This function may or may not return, depending if the + * board implements an alternate hibernate method. + */ +void board_hibernate(void) __attribute__((weak)); + /* Minimum duration to get proper hibernation */ #define SYSTEM_HIB_MINIMUM_DURATION 0, 150000 -- cgit v1.2.1