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 <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/86228
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Subrata Banik 2025-02-06 12:17:08 +00:00
commit 1a58ae5e09
2 changed files with 37 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,34 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <ec/google/chromeec/ec.h>
#include <fsp/api.h>
/*
* 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;
}