ec/google/chromeec: Add is_battery_present_and_above_critical_threshold

This adds is_battery_present_and_above_critical_threshold to check the
battery is present and the battery level is above critical level.

BUG=b:296952944
TEST=Build rex and check is_battery_present_and_above_critical_threshold
returns the correct battery status.

Change-Id: Ib38be55bc42559bab4f12d5e8580ddc3e1a6acc1
Signed-off-by: Jamie Ryu <jamie.m.ryu@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78321
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Subrata Banik <subratabanik@google.com>
This commit is contained in:
Jamie Ryu 2023-10-11 20:11:52 -07:00 committed by Subrata Banik
parent 9b230ae295
commit 19080a71c8
2 changed files with 24 additions and 0 deletions

View file

@ -1532,3 +1532,19 @@ void google_chromeec_clear_ec_ap_idle(void)
else
printk(BIOS_ERR, "Failed to clear EC AP_IDLE flag\n");
}
bool google_chromeec_is_battery_present_and_above_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 is present and LEVEL_CRITICAL is not set */
if (resp.flags && !(resp.flags & EC_BATT_FLAG_LEVEL_CRITICAL))
return true;
}
return false;
}

View file

@ -416,6 +416,14 @@ int google_chromeec_regulator_get_voltage(uint32_t index, uint32_t *voltage_mv);
*/
void google_chromeec_clear_ec_ap_idle(void);
/**
* Check if battery is present and battery level is above critical threshold.
*
* @return true: if the battery is present and battery level is above critical threshold
* false: any of the above conditions is not true
*/
bool google_chromeec_is_battery_present_and_above_critical_threshold(void);
#if CONFIG(HAVE_ACPI_TABLES)
/**
* Writes USB Type-C PD related information to the SSDT