diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 8c80a3f0dc..1ee242b540 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -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, ¶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 afb1485f14..a50c31179a 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -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. *