summaryrefslogtreecommitdiff
path: root/common/power_button.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2020-06-12 12:47:14 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-13 02:14:49 +0000
commit4508ef09d187de4f2cb0c7a15a9708b09d892af1 (patch)
treee62394dcf82a46e18d5a8b79113d12d760af3460 /common/power_button.c
parentb6a6fc50137bc012079f78b5e627689ea0199cdf (diff)
downloadchrome-ec-4508ef09d187de4f2cb0c7a15a9708b09d892af1.tar.gz
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 <dnojiri@chromium.org> Change-Id: Ib4b1182900acea21e5210a2f9a699da18fe55611 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242661 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/power_button.c')
-rw-r--r--common/power_button.c31
1 files changed, 31 insertions, 0 deletions
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.
*/