From 5ef70e5f2233be3dfc14de9775d719c15d53aa35 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 24 Dec 2024 18:19:33 +0000 Subject: [PATCH] ec/google/chromeec: Add API to check if battery is critically low MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a new API `google_chromeec_is_below_critical_threshold() ` to check if the battery level is below the critical threshold. The API uses the existing `ec_cmd_battery_get_dynamic()` command to retrieve the battery flags and checks the `EC_BATT_FLAG_LEVEL_CRITICAL` flag to determine if the battery level is critical. This API can be used by other components to query the battery critical status and take necessary actions, for example, while the system is booting with low battery fuel with and/or without an AC charger attached. This addresses the need to implement a low battery charger icon and detect when the system is booting with low battery fuel. The existing `google_chromeec_is_battery_present_and_above_critical_threshold()` API is not suitable for this purpose because any negative decision (like battery not present and/or battery is critically low) implemented around this existing API will also render the lower battery indicator when the system is booting into battery cut-off mode. Ideally, we do not wish to render any icon and simply allow boot to the OS during system battery cut-off boot. BUG=b:377798581 TEST=Able to read the battery status correctly while booting google/fatcat. Change-Id: Id1fc1df374fb4c663becc371c69b285d8b9957ff Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/85759 Reviewed-by: Kapil Porwal Tested-by: build bot (Jenkins) Reviewed-by: Jérémy Compostella --- src/ec/google/chromeec/ec.c | 16 ++++++++++++++++ src/ec/google/chromeec/ec.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 8c80a3f0dc..1ee242b540 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -1614,6 +1614,22 @@ bool google_chromeec_is_battery_present_and_above_critical_threshold(void) return false; } +bool google_chromeec_is_below_critical_threshold(void) +{ + struct ec_params_battery_dynamic_info params = { + .index = 0, + }; + struct ec_response_battery_dynamic_info resp; + + if (ec_cmd_battery_get_dynamic(PLAT_EC, ¶ms, &resp) == 0) { + /* Check if battery LEVEL_CRITICAL is set */ + if (resp.flags & EC_BATT_FLAG_LEVEL_CRITICAL) + return true; + } + + return false; +} + bool google_chromeec_is_battery_present(void) { struct ec_params_battery_dynamic_info params = { diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index afb1485f14..a50c31179a 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -447,6 +447,14 @@ void google_chromeec_clear_ec_ap_idle(void); */ bool google_chromeec_is_battery_present_and_above_critical_threshold(void); +/** + * Check if battery level is below critical threshold. + * + * @return true: if the battery level is below critical threshold + * false: any the above conditions is not true + */ +bool google_chromeec_is_below_critical_threshold(void); + /** * Check if battery is present. *