From e5cc73cb9499adecbf8f8254f18ff44142c25397 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 11 Feb 2025 09:09:56 +0000 Subject: [PATCH] soc/intel/common: Add low battery shutdown function This commit adds a `do_low_battery_poweroff()` function to handle platform power off due to critically low battery levels. This provides a standardized way to handle low battery shutdowns across platforms. Additionally, the delay to the `do_low_battery_poweroff()` function, allowing time for the low battery indicator to be displayed before powering off. The delay is configurable through the `PLATFORM_LOW_BATTERY_SHUTDOWN_DELAY_SEC` Kconfig option. Finally, a low battery indicator event is logged using `elog` before the delay. This functionality (elog and delay) is enabled when the `PLATFORM_HAS_LOW_BATTERY_INDICATOR` Kconfig option is selected. BUG=b:339673254 TEST=Able to build and boot google/brox. Change-Id: I92e9003c70c2608770972f1a302f954ebdf17bc4 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/86361 Reviewed-by: Karthik Ramasubramanian Tested-by: build bot (Jenkins) --- src/soc/intel/common/reset.c | 12 ++++++++++++ src/soc/intel/common/reset.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/soc/intel/common/reset.c b/src/soc/intel/common/reset.c index c6c394bd44..3fefa57d30 100644 --- a/src/soc/intel/common/reset.c +++ b/src/soc/intel/common/reset.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include @@ -21,3 +23,13 @@ void do_board_reset(void) { full_reset(); } + +void do_low_battery_poweroff(void) +{ + if (CONFIG(PLATFORM_HAS_LOW_BATTERY_INDICATOR)) { + elog_add_event_byte(ELOG_TYPE_LOW_BATTERY_INDICATOR, ELOG_FW_ISSUE_SHUTDOWN); + delay(CONFIG_PLATFORM_LOW_BATTERY_SHUTDOWN_DELAY_SEC); + } + + poweroff(); +} diff --git a/src/soc/intel/common/reset.h b/src/soc/intel/common/reset.h index 658223c32a..8331853023 100644 --- a/src/soc/intel/common/reset.h +++ b/src/soc/intel/common/reset.h @@ -25,4 +25,11 @@ __noreturn void global_reset(void); */ efi_return_status_t fsp_get_pch_reset_status(void); +/* + * Issue power off due to low battery + * + * Call this function to power off the platform if the battery level is critically low. + */ +void do_low_battery_poweroff(void); + #endif /* _INTEL_COMMON_RESET_H_ */