From 8b3ceacd93f09447b53173f5b99527fc9249e60c Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 2 Dec 2025 13:18:47 +0000 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/90334 Reviewed-by: Kapil Porwal Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel --- src/ec/google/chromeec/ec.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index b881fa47dc..03ae01c03d 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -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, ¶ms, &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)); } /*