From 57c6f5e995345d92418d3a1d36bcc9e41c15d9e5 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Wed, 28 Jan 2026 06:35:12 +0000 Subject: [PATCH] ec/google/chromeec: Add helper for critical battery state detection Implement google_chromeec_is_critically_low_on_battery() to check if the system is at risk of an imminent power-off. This function returns true only if the battery is below the critical threshold and no charger is detected. Combining these checks into a single helper ensures that firmware notifications (like a red lightbar) or emergency power-down logic do not trigger while the device is successfully connected to AC power. - Implement google_chromeec_is_critically_low_on_battery in ec.c. - Export the function in ec.h for use in romstage/ramstage. TEST=Verified on Fatcat & Bluey that the function correctly identifies the low-power state and suppresses warnings when a charger is plugged in. Change-Id: I9f0f268d6660d913f989a9deffa24ab1f585b508 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/90963 Reviewed-by: Caveh Jalali Reviewed-by: Kapil Porwal Reviewed-by: Jayvik Desai Tested-by: build bot (Jenkins) --- src/ec/google/chromeec/ec.c | 11 +++++++++++ src/ec/google/chromeec/ec.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index b9d53e7788..804bda0c81 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -1981,3 +1981,14 @@ int google_chromeec_set_lightbar_rgb(unsigned int led, int red, int green, return google_chromeec_command(&cmd); } + +/* + * Check if the battery is critically low and not currently charging. + * + * Return true if battery is below threshold and AC is not present. + */ +bool google_chromeec_is_critically_low_on_battery(void) +{ + return google_chromeec_is_below_critical_threshold() && + !google_chromeec_is_charger_present(); +} diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index e5a4b0647d..075694bd4a 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -562,4 +562,11 @@ int google_chromeec_read_batt_state_of_charge(uint32_t *state); int google_chromeec_set_lightbar_rgb(unsigned int led, int red, int green, int blue); +/* + * Check if the battery is critically low and AC is not present. + * + * Return true if battery is below threshold and AC is not present. + */ +bool google_chromeec_is_critically_low_on_battery(void); + #endif /* _EC_GOOGLE_CHROMEEC_EC_H */