Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/85743?usp=email )
Change subject: ec/google/chromeec: Add API to check if a USB PD charger is attached ......................................................................
ec/google/chromeec: Add API to check if a USB PD charger is attached
This change introduces a new API, `google_chromeec_is_usb_pd_attached()` which checks the current status of the USB-C port and returns whether a USB Power Delivery (PD) charger is currently connected.
This API is useful for determining if the system is currently being powered by a PD charger.
BUG=b:377798581 TEST=Able to read the PD status correctly while booting google/fatcat.
Change-Id: I47c934ee8a7563d4ba5124bff5613e61dd66e923 Signed-off-by: Subrata Banik subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/85743 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Jérémy Compostella jeremy.compostella@intel.com --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 22 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Jérémy Compostella: Looks good to me, approved
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index af5c235..4c1bbe7 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -966,6 +966,25 @@ return 0; }
+/* + * This API checks the current status of the USB-C port and returns + * whether a USB Power Delivery (PD) charger is currently connected. + */ +bool google_chromeec_is_usb_pd_attached(void) +{ + const struct ec_params_usb_pd_power_info params = { + .port = PD_POWER_CHARGING_PORT, + }; + struct ec_response_usb_pd_power_info resp = {}; + int rv; + + rv = ec_cmd_usb_pd_power_info(PLAT_EC, ¶ms, &resp); + if (rv != 0) + return false; + + return resp.type == USB_CHG_TYPE_PD; +} + 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 31c7671..cdea70f 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -137,6 +137,9 @@ int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type, uint16_t *current_max, uint16_t *voltage_max);
+/* Check if a USB Power Delivery (PD) charger is attached */ +bool google_chromeec_is_usb_pd_attached(void); + /* * Set max current and voltage of a dedicated charger. *