mb/google/bluey: Use safe SPMI reads for battery current telemetry

Update `get_battery_icurr_ma` to use the newly introduced
`spmi_read8_safe` helper. This ensures that transient SPMI arbiter
errors (0xfffffff7) are handled via retries rather than being
immediately treated as zero current.

By validating both the primary (SMB1) and secondary (SMB2) charger
registers with retries, the system avoids entering the power-off
path caused by spurious 0mA readings during early boot or rail
stabilization.

Additionally, using 5ms delay before charger SMB1/2 register read.

BUG=b:436391478
BRANCH=none
TEST=On Bluey, verify that battery current is reported correctly
even if the initial SPMI read encounters a transient failure.

Change-Id: I8dee77ba83798e8e50f8884604c588fe4fda0e0a
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91767
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Subrata Banik 2026-03-19 19:57:35 +00:00
commit 3f46d6fd93

View file

@ -58,11 +58,18 @@ enum charging_status {
static int get_battery_icurr_ma(void)
{
/* Read battery i-current value */
int icurr = spmi_read8(SMB1_CHGR_CHARGING_FCC);
if (icurr <= 0)
icurr = spmi_read8(SMB2_CHGR_CHARGING_FCC);
if (icurr < 0)
mdelay(5);
int icurr = spmi_read8_safe(SMB1_CHGR_CHARGING_FCC);
if (icurr <= 0) {
mdelay(5);
icurr = spmi_read8_safe(SMB2_CHGR_CHARGING_FCC);
}
/* Final safety: if both failed (still negative), treat as 0 */
if (icurr < 0) {
printk(BIOS_ERR, "Critical: Both SMB registers failed to read.\n");
icurr = 0;
}
icurr *= 50;
return icurr;