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; +}