Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/85759?usp=email )
Change subject: ec/google/chromeec: Add API to check if battery is critically low ......................................................................
ec/google/chromeec: Add API to check if battery is critically low
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 subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/85759 Reviewed-by: Kapil Porwal kapilporwal@google.com Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Jérémy Compostella jeremy.compostella@intel.com --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 24 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Jérémy Compostella: Looks good to me, approved Kapil Porwal: Looks good to me, but someone else must approve
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 8c80a3f..1ee242b 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -1614,6 +1614,22 @@ 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 afb1485..a50c311 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -448,6 +448,14 @@ 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. * * @return true: if the battery is present