From 52136462413ff5bfb7b699fa8a820f5fcc804adc Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Wed, 25 Dec 2024 11:32:59 +0530 Subject: [PATCH] ec/google/chromeec: Add function to detect barrel charger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces a new function, google_chromeec_is_barrel_charger_present(), which checks if a barrel charger is present. The function uses the following logic to determine if a barrel charger is present: - If both a barrel charger and USB-C PD are present, then the barrel charger takes precedence over USB-C PD. As a result, google_chromeec_is_usb_pd_attached() will return false. This logic can be used to deterministically say if a barrel charger is present even when both a barrel charger and USB-C PD are attached. - If an AC charger is detected and USB-C PD is not present, then a barrel charger must be present. This change allows the EC to accurately detect the presence of a barrel charger, even when a USB-C PD charger is also attached. BUG=b:377798581 TEST=Able to read the charger status correctly while booting google/fatcat. Experiment #1: - USB-C PD Attached = yes - Barrel Attached = No - Charger Detected = Yes ``` fatcat-rev257 ~ # cbmem -c | grep -5 "ac_charger_present" [INFO ] ac_charger_present: yes [INFO ] usb_pd_present: yes [INFO ] baseboard_devtree_update: Barrel Absent ``` Experiment #2: - USB-C PD Attached = No - Barrel Attached = Yes - Charger Detected = Yes ``` [INFO ] ac_charger_present: yes [INFO ] usb_pd_present: no [INFO ] baseboard_devtree_update: Barrel Present ``` Experiment #3: - USB-C PD Attached = Yes - Barrel Attached = Yes - Charger Detected = Yes ``` [INFO ] ac_charger_present: yes [INFO ] usb_pd_present: no [INFO ] baseboard_devtree_update: Barrel Present ``` Experiment #4: - USB-C PD Attached = No - Barrel Attached = No - Charger Detected = No ``` [INFO ] ac_charger_present: no [INFO ] usb_pd_present: no [INFO ] baseboard_devtree_update: Barrel Absent ``` Change-Id: I9644f0dec057f95bb0a22cdc18edc1a0234ee3a9 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/85765 Tested-by: build bot (Jenkins) Reviewed-by: Jérémy Compostella --- src/ec/google/chromeec/ec.c | 24 ++++++++++++++++++++++++ src/ec/google/chromeec/ec.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 1ee242b540..2e8961f5f2 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -1002,6 +1002,30 @@ bool google_chromeec_is_charger_present(void) return false; } +/* + * Using below scenarios to conclude if device has a barrel charger attached. + * +-----------+-----------------+------------------+---------------------------------+ + * | Scenarios | Charger Present | USB-C PD Present | Conclusion: Barrel Present ? | + * +-----------+-----------------+------------------+---------------------------------+ + * | #1 | Yes | Yes | Non Conclusive (comments below) | + * | #2 | No | Yes | Not possible | + * | #3 | Yes | No | Must be barrel charger | + * | #4 | No | No | Barrel not present | + * +-----------+-----------------+------------------+---------------------------------+ + */ +bool google_chromeec_is_barrel_charger_present(void) +{ + /* + * If both the barrel charger and USB-C PD are connected, the barrel charger takes + * precedence over USB-C PD. This means google_chromeec_is_usb_pd_attached() + * will return false in such a scenario. + * + * This behavior allows us to reliably detect the presence of a barrel + * charger, even when a USB-C PD charger is also connected. + */ + return google_chromeec_is_charger_present() && !google_chromeec_is_usb_pd_attached(); +} + 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 a50c31179a..b11b7a834a 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -148,6 +148,14 @@ bool google_chromeec_is_usb_pd_attached(void); */ bool google_chromeec_is_charger_present(void); +/** + * Check if barrel charger is present. + * + * @return true: if the barrel charger is present + * false: if the barrel charger is not present + */ +bool google_chromeec_is_barrel_charger_present(void); + /* * Set max current and voltage of a dedicated charger. *