[PATCH 2/3] power: supply: bq27xxx: retry a failed register read once
From: Michael Auer
Date: Sat Nov 21 2026 - 15:41:56 EST
A bq27541 on a OnePlus 6 now and then NAKs an I2C read right after
system resume (-ENXIO on i2c-qcom-geni). If that is the flags read of
the update queued at resume, the driver caches the error: for the next
5 s "present" reads 0 and every other property fails. UPower then
reports the battery as missing at 0 %, and the desktop starts its
critical battery action on a battery that is at 25 %:
power_supply bq27541-0: driver failed to report `status' property: -6
The I2C read already retries -EBUSY. Retry any other failed read once
after 10 ms, in the bus independent read helper, but not -ENODEV (no
I2C adapter). A gauge that does not answer at all now costs 10 ms more
per read.
Signed-off-by: Michael Auer <mick@xxxxxxxx>
---
I did not put the retry into the I2C read next to the -EBUSY retry,
because the error code for a NAK differs between adapters (-ENXIO,
-EREMOTEIO, -EIO).
drivers/power/supply/bq27xxx_battery.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 032eea030f2f..dccb0f84ea1d 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -1141,6 +1141,17 @@ static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index,
return -EINVAL;
ret = di->bus.read(di, di->regs[reg_index], single);
+ if (ret < 0 && ret != -ENODEV) {
+ /*
+ * The gauge can miss a single transfer, e.g. right after system
+ * resume (bq27541 NAKs it). Without the retry the whole update
+ * fails and userspace sees the battery as absent.
+ */
+ dev_dbg(di->dev, "failed to read register 0x%02x (index %d): %d, retrying\n",
+ di->regs[reg_index], reg_index, ret);
+ usleep_range(10000, 11000);
+ ret = di->bus.read(di, di->regs[reg_index], single);
+ }
if (ret < 0)
dev_dbg(di->dev, "failed to read register 0x%02x (index %d)\n",
di->regs[reg_index], reg_index);
--
2.43.0