diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ec/google/chromeec/ec.c | 16 | ||||
-rw-r--r-- | src/ec/google/chromeec/ec.h | 8 |
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, ¶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 |