Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/85758?usp=email )
Change subject: ec/google/chromeec: Add API to check if charger is present ......................................................................
ec/google/chromeec: Add API to check if charger is present
This patch introduces a new API, `google_chromeec_is_charger_present()`, to determine if a charger is connected.
The API leverages the existing `ec_cmd_battery_get_dynamic()` command to retrieve battery flags and checks the `EC_BATT_FLAG_AC_PRESENT` flag to ascertain charger presence.
Other components can leverage this API to query the charger status, which is particularly useful for distinguishing between barrel chargers and USB-C chargers after relying on the `google_chromeec_is_usb_pd_attached()` API.
BUG=b:377798581 TEST=Able to read the charger status (w/ barrel and/or w/ USB-PD) correctly while booting google/fatcat.
Change-Id: Iadf81400f71a51c093f71fe995cacc107c50c7af Signed-off-by: Subrata Banik subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/85758 Reviewed-by: Jérémy Compostella jeremy.compostella@intel.com Reviewed-by: Kapil Porwal kapilporwal@google.com Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 25 insertions(+), 0 deletions(-)
Approvals: Jérémy Compostella: Looks good to me, approved build bot (Jenkins): Verified Kapil Porwal: Looks good to me, but someone else must approve
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 4c1bbe7..8c80a3f 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -985,6 +985,23 @@ return resp.type == USB_CHG_TYPE_PD; }
+/* 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; +} + int google_chromeec_override_dedicated_charger_limit(uint16_t current_lim, uint16_t voltage_lim) { diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index cdea70f..afb1485 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -140,6 +140,14 @@ /* Check if a USB Power Delivery (PD) charger is attached */ bool google_chromeec_is_usb_pd_attached(void);
+/** + * Check if charger is present. + * + * @return true: if the charger is present + * false: if the charger is not present + */ +bool google_chromeec_is_charger_present(void); + /* * Set max current and voltage of a dedicated charger. *