mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Michael Auer <mick@yoxcu.de>
Cc: Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] power: supply: bq27xxx: retry a failed register read once
Date: Sun, 22 Nov 2026 13:03:41 +0100	[thread overview]
Message-ID: <20261122120341.runjq4rjjgvob5y6@pali> (raw)
In-Reply-To: <20261121204137.848173-3-mick@yoxcu.de>

On Saturday 21 November 2026 21:41:36 Michael Auer wrote:
> 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.

So... should not be there rather a resume hook in the driver which waits
until the battery is ready (instead of adding retires on many places in
the driver)?

> 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@yoxcu.de>
> ---
> 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
> 

  reply	other threads:[~2026-11-22 12:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 20:41 [PATCH 0/3] power: supply: bq27xxx: fix wrong battery states after resume Michael Auer
2026-11-21 20:41 ` [PATCH 1/3] power: supply: bq27xxx: report discharging at zero current without a charger Michael Auer
2026-11-21 21:33   ` Michael Auer
2026-11-21 20:41 ` [PATCH 2/3] power: supply: bq27xxx: retry a failed register read once Michael Auer
2026-11-22 12:03   ` Pali Rohár [this message]
2026-11-22 20:16     ` Michael Auer
2026-11-21 20:41 ` [PATCH 3/3] power: supply: bq27xxx: keep the last values over a short read failure Michael Auer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122120341.runjq4rjjgvob5y6@pali \
    --to=pali@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mick@yoxcu.de \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®