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 <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91547
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
This commit is contained in:
Subrata Banik 2026-03-05 14:15:26 +05:30
commit 762b564f3b

View file

@ -7,6 +7,7 @@
#include <reset.h>
#include <soc/pmic.h>
#include <soc/qcom_spmi.h>
#include <timer.h>
#include <types.h>
#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);