vc/google/chromeos: Add platform hook for emergency battery shutdown

Introduce platform_handle_emergency_low_battery() to handle the
pre-shutdown sequence when battery levels are critical.

This hook ensures:
1. Visual feedback is provided (Lightbar set to red).
2. The event is logged to ELOG for post-mortem analysis.
3. A delay is enforced to ensure logs are committed and the user
   notices the alert before the AP powers off.

BUG=none
BRANCH=none
TEST=Verified lightbar turns red and ELOG is recorded on low battery
     boot.

Change-Id: I3f1b2757002d7a2a76dfb51d24a04e2d81b061bb
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91409
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
This commit is contained in:
Subrata Banik 2026-02-24 12:35:30 +05:30
commit 5c44e689ee
2 changed files with 31 additions and 0 deletions

View file

@ -191,8 +191,15 @@ void bmp_release_logo(void);
*/
#if CONFIG(PLATFORM_HAS_LOW_BATTERY_INDICATOR)
bool platform_is_low_battery_shutdown_needed(void);
/*
* Platform hooks for system shutdown due to critical battery levels.
* Provides visual feedback via the Lightbar/LEDs and logs the event
* to non-volatile storage before signaling to cut power.
*/
void platform_handle_emergency_low_battery(void);
#else
static inline bool platform_is_low_battery_shutdown_needed(void) { return false; }
static inline void platform_handle_emergency_low_battery(void) { /* nop */ }
#endif
/*

View file

@ -2,6 +2,8 @@
#include <ec/google/chromeec/ec.h>
#include <bootsplash.h>
#include <elog.h>
#include <delay.h>
/*
* Check if low battery shutdown is needed
@ -32,3 +34,25 @@ bool platform_is_low_battery_shutdown_needed(void)
return result;
}
/*
* Platform hooks for system shutdown due to critical battery levels.
* Provides visual feedback via the Lightbar/LEDs and logs the event
* to non-volatile storage before signaling to cut power.
*/
void platform_handle_emergency_low_battery(void)
{
if (!CONFIG(EC_GOOGLE_CHROMEEC))
return;
/* Visual alert: Set Lightbar to solid Red */
google_chromeec_set_lightbar_rgb(0xff, 0xff, 0x00, 0x00);
/* Record the event for post-mortem diagnostics (stored in CMOS/Flash) */
elog_add_event_byte(ELOG_TYPE_LOW_BATTERY_INDICATOR, ELOG_FW_ISSUE_SHUTDOWN);
/* * Pause briefly to ensure the user perceives the LED change and
* the event log is safely committed to storage.
*/
delay(CONFIG_PLATFORM_POST_RENDER_DELAY_SEC);
}