From 762b564f3b78f12cae1e9534085cefffecf6d133 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Thu, 5 Mar 2026 14:15:26 +0530 Subject: [PATCH] mb/google/bluey: Add timeout for charging rail stabilization In the charger applet, it is possible for the PMIC to take some time to negotiate and enable the charging current. Previously, the code proceeded immediately, which could lead to false-positive power-off triggers if current hadn't started flowing yet. This change: 1. Implements a 3000ms stopwatch-based timeout. 2. Polls get_battery_icurr_ma() until a non-zero current is detected. 3. Aborts the applet if current fails to stabilize within the window. 4. Adds logging to track the actual duration of the power-up sequence. BUG=none BRANCH=none TEST=Verified that the system enters off-mode charging more reliably without powering off. ``` [INFO ] Inside launch_charger_applet. Initiating charging ... ... [INFO ] Issuing power-off due to change in charging state. ... ... ``` Change-Id: Ie3501dff06aadf81d527658c4042de7c92de24b5 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/91547 Tested-by: build bot (Jenkins) Reviewed-by: Kapil Porwal --- src/mainboard/google/bluey/charging.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mainboard/google/bluey/charging.c b/src/mainboard/google/bluey/charging.c index 690f30964f..f81d5b9650 100644 --- a/src/mainboard/google/bluey/charging.c +++ b/src/mainboard/google/bluey/charging.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #define SMB1_SLAVE_ID 0x07 @@ -41,6 +42,7 @@ #define PERPH_EN 0x80 #define DELAY_CHARGING_APPLET_MS 2000 /* 2sec */ +#define CHARGING_RAIL_STABILIZATION_DELAY_MS 3000 /* 3sec */ enum charging_status { CHRG_DISABLE, @@ -86,11 +88,25 @@ void launch_charger_applet(void) if (!CONFIG(EC_GOOGLE_CHROMEEC)) return; + static const long charging_enable_timeout_ms = CHARGING_RAIL_STABILIZATION_DELAY_MS; + struct stopwatch sw; + printk(BIOS_INFO, "Inside %s. Initiating charging\n", __func__); /* clear any pending power button press and lid open event */ clear_ec_manual_poweron_event(); + stopwatch_init_msecs_expire(&sw, charging_enable_timeout_ms); + while (!get_battery_icurr_ma()) { + if (stopwatch_expired(&sw)) { + printk(BIOS_WARNING, "Charging not enabled %ld ms. Abort.\n", + charging_enable_timeout_ms); + return; + } + mdelay(200); + } + printk(BIOS_INFO, "Charging ready after %lld ms\n", stopwatch_duration_msecs(&sw)); + do { /* Add static delay before reading the charging applet pre-requisites */ mdelay(DELAY_CHARGING_APPLET_MS);