From 19080a71c85eb8a62d18267f57cc1d01ba7b00dc Mon Sep 17 00:00:00 2001 From: Jamie Ryu Date: Wed, 11 Oct 2023 20:11:52 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/78321 Tested-by: build bot (Jenkins) Reviewed-by: Subrata Banik --- 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 9a1d08358e..fbb0033d59 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -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, ¶ms, &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; +} diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index f6a2e60ff4..0e1df9cf6a 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -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