From eb4e3c97221d4304a976a51a14a1a35aa18801aa 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:56070 BRANCH=firmware-strago-7287.B TEST=Manual with subsequent commit on chell. Verify board-level hibernate callback is called when "hibernate" is run on EC console. Ported from the master branch to strago branch. Change-Id: Ie1da044037a74ff8bce5c822f28ce837c62ceec0 Reviewed-on: https://chromium-review.googlesource.com/324086 Change-Id: I1665e56bf471f04180467513f5a7bdc4976bcc55 Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/367884 Reviewed-by: Shawn N (cherry picked from commit 7d5f758795ba0b9178335c2f08f4b2e51e1bf880) Reviewed-on: https://chromium-review.googlesource.com/368344 --- chip/host/system.c | 3 +++ chip/it83xx/system.c | 3 +++ chip/lm4/system.c | 4 ++++ chip/mec1322/system.c | 3 +++ chip/npcx/system.c | 3 +++ chip/nrf51/system.c | 3 +++ chip/stm32/system.c | 4 ++++ include/system.h | 7 +++++++ power/braswell.c | 5 +++++ 9 files changed, 35 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 8d434c9c5c..5247ea332f 100644 --- a/chip/it83xx/system.c +++ b/chip/it83xx/system.c @@ -24,6 +24,9 @@ enum system_bram_indices { void system_hibernate(uint32_t seconds, uint32_t microseconds) { + if (board_hibernate) + board_hibernate(); + /* TODO(crosbug.com/p/23575): IMPLEMENT ME ! */ } diff --git a/chip/lm4/system.c b/chip/lm4/system.c index 38cde27e1c..737c9e24b3 100644 --- a/chip/lm4/system.c +++ b/chip/lm4/system.c @@ -385,6 +385,10 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) { /* Flush console before hibernating */ cflush(); + + if (board_hibernate) + board_hibernate(); + hibernate(seconds, microseconds, HIBDATA_WAKE_PIN); } diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index 2526704b0c..4c8631a616 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -287,6 +287,9 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) cflush(); + if (board_hibernate) + board_hibernate(); + /* Disable interrupts */ interrupt_disable(); for (i = 0; i < 3; ++i) diff --git a/chip/npcx/system.c b/chip/npcx/system.c index 2a872d0b66..8d8dc42830 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -427,6 +427,9 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) /* Flush console before hibernating */ cflush(); + if (board_hibernate) + board_hibernate(); + #if SUPPORT_HIB /* Add additional hibernate operations here */ __enter_hibernate(seconds, microseconds); diff --git a/chip/nrf51/system.c b/chip/nrf51/system.c index 86d78b3170..94c36202e4 100644 --- a/chip/nrf51/system.c +++ b/chip/nrf51/system.c @@ -36,6 +36,9 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) /* Flush console before hibernating */ cflush(); + if (board_hibernate) + board_hibernate(); + /* chip specific standby mode */ CPRINTS("TODO: implement %s()", __func__); } diff --git a/chip/stm32/system.c b/chip/stm32/system.c index 88cde274fd..051340dbf6 100644 --- a/chip/stm32/system.c +++ b/chip/stm32/system.c @@ -106,6 +106,10 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) { /* Flush console before hibernating */ cflush(); + + if (board_hibernate) + board_hibernate(); + /* chip specific standby mode */ __enter_hibernate(seconds, microseconds); } diff --git a/include/system.h b/include/system.h index 320410b160..fe079aa646 100644 --- a/include/system.h +++ b/include/system.h @@ -264,6 +264,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 diff --git a/power/braswell.c b/power/braswell.c index 22659f5309..8086dcb5a1 100644 --- a/power/braswell.c +++ b/power/braswell.c @@ -340,6 +340,11 @@ enum power_state power_handle_state(enum power_state state) } #ifdef CONFIG_LOW_POWER_PSEUDO_G3 +void board_hibernate(void) +{ + enter_pseudo_g3(); +} + void enter_pseudo_g3(void) { CPRINTS("Enter Psuedo G3"); -- cgit v1.2.1