ec/google: Check AC charger presence by reading host event register

The google_chromeec_is_charger_present function previously relied on
executing the EC_CMD_BATTERY_DYNAMIC_INFO command to check the
EC_BATT_FLAG_AC_PRESENT flag.

This commit refactors the function to directly read the host event
register (EC events B) and check for the EC_HOST_EVENT_AC_CONNECTED
event flag instead.

This approach is much more efficient as it avoids the overhead of
sending and receiving a full EC command (savings ~25-30ms), using a
readily available cached status instead.

TEST=Able to build and boot google/quenbi.

Change-Id: I2ec9aca5991394ed1d4998da37e074e9324bd672
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90334
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
Subrata Banik 2025-12-02 13:18:47 +00:00 committed by Matt DeVillier
commit 8b3ceacd93

View file

@ -1167,18 +1167,9 @@ bool google_chromeec_is_usb_pd_attached(void)
/* This API checks if charger is present. */
bool google_chromeec_is_charger_present(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 AC charger is present */
if (resp.flags & EC_BATT_FLAG_AC_PRESENT)
return true;
}
return false;
/* Check if the EC has posted the AC connect event. */
return !!(google_chromeec_get_events_b() &
EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_CONNECTED));
}
/*