public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 bsp-development.geo@leica-geosystems.com
Subject: Re: [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent
Date: Fri, 30 Jan 2026 22:19:19 +0100	[thread overview]
Message-ID: <aX0dmorBDaipndP7@venus> (raw)
In-Reply-To: <20251231093152.2817579-1-Qing-wu.Li@leica-geosystems.com.cn>

[-- Attachment #1: Type: text/plain, Size: 2431 bytes --]

Hi,

On Wed, Dec 31, 2025 at 09:31:51AM +0000, LI Qingwu wrote:
> The driver reports battery present when status register read succeeds,
> without checking the actual register values. Some systems return all
> zeros when no battery is connected, causing false presence detection.
> 
> Add validation: when status reads zero, cross-check voltage and capacity.
> Report battery absent only if all three registers return zero.
> 
> Tested on i.MX 8M Plus platform with SBS-compliant battery.
> 
> Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> ---

Can you provide some more details about the platform / SBS compliant
battery?

The SBS battery chip is supposed to be part of the battery [*], so
by removing the battery you are removing the I2C device. Accessing a
non-existing device surely should not give you 0, but an error. That
suggests either your hardware design is broken and you disconnect
the battery cells from the IC or your I2C/SMbus driver is buggy and
should be fixed.

[*] This is the whole point of calling it a 'smart battery'. The
    battery cells and the chip are supposed to be one unit. This
    allows the chip to use a coloumb counter to measure energy
    stored/taken out of the battery and learn how the battery
    behaves.

Greetings,

-- Sebastian

>  drivers/power/supply/sbs-battery.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
> index 943c82ee978f..0b9ecfc1f3f7 100644
> --- a/drivers/power/supply/sbs-battery.c
> +++ b/drivers/power/supply/sbs-battery.c
> @@ -594,9 +594,19 @@ static int sbs_get_battery_presence_and_health(
>  		return ret;
>  	}
>  
> -	if (psp == POWER_SUPPLY_PROP_PRESENT)
> +	if (psp == POWER_SUPPLY_PROP_PRESENT) {
>  		val->intval = 1; /* battery present */
> -	else { /* POWER_SUPPLY_PROP_HEALTH */
> +		if (ret == 0) {
> +			int voltage, capacity;
> +
> +			voltage = sbs_read_word_data(
> +				client, sbs_data[REG_VOLTAGE].addr);
> +			capacity = sbs_read_word_data(
> +				client, sbs_data[REG_CAPACITY].addr);
> +			if (voltage == 0 && capacity == 0)
> +				val->intval = 0;
> +		}
> +	} else { /* POWER_SUPPLY_PROP_HEALTH */
>  		if (sbs_bat_needs_calibration(client)) {
>  			val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
>  		} else {
> -- 
> 2.43.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2026-01-30 21:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31  9:31 [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent LI Qingwu
2025-12-31  9:31 ` [PATCH 2/2] power: supply: sbs-battery: Add support for polling battery status LI Qingwu
2026-01-30 21:37   ` Sebastian Reichel
2026-01-30 21:19 ` Sebastian Reichel [this message]

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=aX0dmorBDaipndP7@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=Qing-wu.Li@leica-geosystems.com.cn \
    --cc=bsp-development.geo@leica-geosystems.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.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