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>
This commit is contained in:
Subrata Banik 2024-12-24 18:19:33 +00:00
commit 5ef70e5f22
2 changed files with 24 additions and 0 deletions

View file

@ -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, &params, &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 = {

View file

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