From 4508ef09d187de4f2cb0c7a15a9708b09d892af1 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 12 Jun 2020 12:47:14 -0700 Subject: PB: Make CONFIG_POWER_BUTTON_INIT_IDLE common Currently CONFIG_POWER_BUTTON_INIT_IDLE is available only for NPCX chips. This patch moves the code to common/power_button.c. There is no functionality change. BUG=b:37536389 BRANCH=none TEST=Verify no functionality change on Puff. Signed-off-by: Daisuke Nojiri Change-Id: Ib4b1182900acea21e5210a2f9a699da18fe55611 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242661 Reviewed-by: Aseda Aboagye --- chip/npcx/system.c | 32 -------------------------------- common/power_button.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/chip/npcx/system.c b/chip/npcx/system.c index 64ba4d8e23..14e5b4ced6 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -318,38 +318,6 @@ uint32_t chip_read_reset_flags(void) return bbram_data_read(BBRM_DATA_INDEX_SAVED_RESET_FLAGS); } -#ifdef CONFIG_POWER_BUTTON_INIT_IDLE -/* - * Set/clear AP_OFF flag. It's set when the system gracefully shuts down and - * it's cleared when the system boots up. The result is the system tries to - * go back to the previous state upon AC plug-in. If the system uncleanly - * shuts down, it boots immediately. If the system shuts down gracefully, - * it'll stay at S5 and wait for power button press. - */ -static void board_chipset_startup(void) -{ - uint32_t flags = chip_read_reset_flags(); - flags &= ~EC_RESET_FLAG_AP_IDLE; - chip_save_reset_flags(flags); - system_clear_reset_flags(EC_RESET_FLAG_AP_IDLE); - CPRINTS("Cleared AP_IDLE flag"); -} -DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); - -static void board_chipset_shutdown(void) -{ - uint32_t flags = chip_read_reset_flags(); - flags |= EC_RESET_FLAG_AP_IDLE; - chip_save_reset_flags(flags); - system_set_reset_flags(EC_RESET_FLAG_AP_IDLE); - CPRINTS("Saved AP_IDLE flag"); -} -DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, - /* Slightly higher than handle_pending_reboot because - * it may clear AP_OFF flag. */ - HOOK_PRIO_DEFAULT - 1); -#endif - static void check_reset_cause(void) { uint32_t hib_wake_flags = bbram_data_read(BBRM_DATA_INDEX_WAKE); diff --git a/common/power_button.c b/common/power_button.c index f6aea4edb7..2b4668b733 100644 --- a/common/power_button.c +++ b/common/power_button.c @@ -14,6 +14,7 @@ #include "keyboard_scan.h" #include "lid_switch.h" #include "power_button.h" +#include "system.h" #include "task.h" #include "timer.h" #include "util.h" @@ -108,6 +109,36 @@ static void power_button_init(void) } DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_INIT_POWER_BUTTON); +#ifdef CONFIG_POWER_BUTTON_INIT_IDLE +/* + * Set/clear AP_IDLE flag. It's set when the system gracefully shuts down and + * it's cleared when the system boots up. The result is the system tries to + * go back to the previous state upon AC plug-in. If the system uncleanly + * shuts down, it boots immediately. If the system shuts down gracefully, + * it'll stay at S5 and wait for power button press. + */ +static void pb_chipset_startup(void) +{ + chip_save_reset_flags(chip_read_reset_flags() & ~EC_RESET_FLAG_AP_IDLE); + system_clear_reset_flags(EC_RESET_FLAG_AP_IDLE); + CPRINTS("Cleared AP_IDLE flag"); +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pb_chipset_startup, HOOK_PRIO_DEFAULT); + +static void pb_chipset_shutdown(void) +{ + chip_save_reset_flags(chip_read_reset_flags() | EC_RESET_FLAG_AP_IDLE); + system_set_reset_flags(EC_RESET_FLAG_AP_IDLE); + CPRINTS("Saved AP_IDLE flag"); +} +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, pb_chipset_shutdown, + /* + * Slightly higher than handle_pending_reboot because + * it may clear AP_IDLE flag. + */ + HOOK_PRIO_DEFAULT - 1); +#endif + /** * Handle debounced power button changing state. */ -- cgit v1.2.1