summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamie Ryu <jamie.m.ryu@intel.com>2023-10-11 20:11:52 -0700
committerSubrata Banik <subratabanik@google.com>2023-10-16 03:41:29 +0000
commit19080a71c85eb8a62d18267f57cc1d01ba7b00dc (patch)
tree02940fb880cea2d8490da605138670478563b14a /src
parent9b230ae29557f09e67b4d9a598a794af3d092199 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/ec/google/chromeec/ec.c16
-rw-r--r--src/ec/google/chromeec/ec.h8
2 files changed, 24 insertions, 0 deletions
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, &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;
+}
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