From 56370d028310509b5f5687ee8333ef0013cd2633 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Mon, 23 Dec 2024 11:19:21 +0530 Subject: [PATCH] ec/google/chromeec: Add API to check if a USB PD charger is attached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/85743 Tested-by: build bot (Jenkins) Reviewed-by: Jérémy Compostella --- src/ec/google/chromeec/ec.c | 19 +++++++++++++++++++ src/ec/google/chromeec/ec.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index af5c235309..4c1bbe7ed7 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -966,6 +966,25 @@ int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type, 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 31c76714b9..cdea70f0b9 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -137,6 +137,9 @@ int google_chromeec_set_usb_pd_role(uint8_t port, enum usb_pd_control_role role) 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. *