From 1a58ae5e09137853e1356ad421f58baddd94adac Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Thu, 6 Feb 2025 12:17:08 +0000 Subject: [PATCH] vc/google/chromeos: Implement platform callback for critical shutdown This commit implements `platform_is_low_battery_shutdown_needed` and callback for ChromeOS. - platform_is_low_battery_shutdown_needed: API to check if low battery shutdown is needed. BUG=b:339673254 TEST=Verified low battery boot event logging and controlled shutdown. Change-Id: I119f80a45c045a6095cae98f179c755a2e948e9c Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/86228 Tested-by: build bot (Jenkins) Reviewed-by: Karthik Ramasubramanian Reviewed-by: Julius Werner --- src/vendorcode/google/chromeos/Makefile.mk | 3 ++ src/vendorcode/google/chromeos/battery.c | 34 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/vendorcode/google/chromeos/battery.c diff --git a/src/vendorcode/google/chromeos/Makefile.mk b/src/vendorcode/google/chromeos/Makefile.mk index 67b50f6bdd..6eb010e8eb 100644 --- a/src/vendorcode/google/chromeos/Makefile.mk +++ b/src/vendorcode/google/chromeos/Makefile.mk @@ -19,7 +19,10 @@ verstage-y += watchdog.c romstage-y += watchdog.c ramstage-y += watchdog.c +romstage-$(CONFIG_PLATFORM_HAS_EARLY_LOW_BATTERY_INDICATOR) += battery.c romstage-$(CONFIG_CHROMEOS_DRAM_PART_NUMBER_IN_CBI) += dram_part_num_override.c + +ramstage-$(CONFIG_PLATFORM_HAS_LOW_BATTERY_INDICATOR) += battery.c ramstage-$(CONFIG_CHROMEOS_FW_SPLASH_SCREEN) += splash.c # Add logo to the cbfs image diff --git a/src/vendorcode/google/chromeos/battery.c b/src/vendorcode/google/chromeos/battery.c new file mode 100644 index 0000000000..febc4dcc02 --- /dev/null +++ b/src/vendorcode/google/chromeos/battery.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +/* + * Check if low battery shutdown is needed + * + * This function checks if the system needs to shut down due to a critically low + * battery level. It performs the following actions: + * + * 1. If Chrome EC is not supported, returns false (no shutdown needed). + * 2. Uses static variables to cache the result and avoid repeated checks. + * 3. If the battery level has not been checked yet: + * - Queries the Chrome EC to determine if the battery is below the critical threshold. + * - If the battery is below the threshold, sets the result to true. + * 4. Returns the cached result. + */ +bool platform_is_low_battery_shutdown_needed(void) +{ + if (!CONFIG(EC_GOOGLE_CHROMEEC)) + return false; + + static bool result = false; + static bool checked = false; + + if (!checked) { + if (google_chromeec_is_below_critical_threshold()) + result = true; + checked = true; + } + + return result; +}