Skip to contentSkip to conversation

power: supply: bq27xxx: bug fixes

PATCH Applied H. Nikolaus Schaller 6 participants 10 messages Aug 23, 2025 – Sep 6, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover power: supply: bq27xxx: bug fixes

PATCH V2 2025-08-23 12:33:18:
Changes:
* improved commit description of main fix
* new patch: adds a restriction of historical no-battery-detection logic to the bq27000 chip

PATCH V1 2025-07-21 14:46:09:

H. Nikolaus Schaller (2):
power: supply: bq27xxx: fix error return in case of no bq27000 hdq
battery
power: supply: bq27xxx: restrict no-battery detection to bq27000

 drivers/power/supply/bq27xxx_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/2 power: supply: bq27xxx: fix error return in case of no bq27000 hdq battery

Since commit

commit f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")

the console log of some devices with hdq enabled but no bq27000 battery (like e.g. the Pandaboard) is flooded with messages like:

[   34.247833] power_supply bq27000-battery: driver failed to report 'status' property: -1

as soon as user-space is finding a /sys entry and trying to read the "status" property.

It turns out that the offending commit changes the logic to now return the value of cache.flags if it is <0. This is likely under the assumption that it is an error number. In normal errors from bq27xxx_read() this is indeed the case.

But there is special code to detect if no bq27000 is installed or accessible through hdq/1wire and wants to report this. In that case, the cache.flags are set historically by

	commit 3dd843e1c26a ("bq27000: report missing device better.")

to constant -1 which did make reading properties return -ENODEV. So everything appeared to be fine before the return value was passed upwards.

Now the -1 is returned as -EPERM instead of -ENODEV, triggering the error condition in power_supply_format_property() which then floods the console log.

So we change the detection of missing bq27000 battery to simply set

cache.flags = -ENODEV

instead of -1.

Fixes f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")
Cc Jerry Lv <[email protected]>

---

Notes:
Changes to v1:
* improved commit description of main fix

 drivers/power/supply/bq27xxx_battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/bq27xxx_battery.c +1 -1
index c3616b1c07e6f..dadd8754a73a8 100644
@@ -1945,7 +1945,7 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
 
 	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
 	if ((cache.flags & 0xff) == 0xff)
-		cache.flags = -1; /* read error */
+		cache.flags = -ENODEV; /* read error */
 	if (cache.flags >= 0) {
 		cache.capacity = bq27xxx_battery_read_soc(di);
 
Signature · 1 line
2.50.1
#3 lore raw

Re: [PATCH v2 1/2] power: supply: bq27xxx: fix error return in case of no bq27000 hdq battery

Quoted 10 lines · Markus Elfring

…

Quoted 1 line

So we change the detection of missing bq27000 battery to simply set

…

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc2#n94

Regards,
Markus

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless review comment to a patch submission on a Linux kernel developer mailing list. I strongly suggest that you not do this anymore. Please do not bother developers who are actively working to produce patches and features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to follow it at all. The person/bot/AI that sent it is being ignored by almost all Linux kernel maintainers for having a persistent pattern of behavior of producing distracting and pointless commentary, and inability to adapt to feedback. Please feel free to also ignore emails from them.

thanks,

greg k-h's patch email bot

#4 lore raw

PATCH v2 2/2 power: supply: bq27xxx: restrict no-battery detection to bq27000

In reply to H. Nikolaus Schaller

There are fuel gauges in the bq27xxx series (e.g. bq27z561) which may in some cases report 0xff as the value of BQ27XXX_REG_FLAGS that should not be interpreted as "no battery" like for a disconnected battery with some built in bq27000 chip.

So restrict the no-battery detection originally introduced by

    commit 3dd843e1c26a ("bq27000: report missing device better.")

to the bq27000.

There is no need to backport further because this was hidden before

commit f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")

Fixes f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")
---
 drivers/power/supply/bq27xxx_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/bq27xxx_battery.c +2 -2
index dadd8754a73a8..3363af24017ae 100644
@@ -1944,8 +1944,8 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
 	bool has_singe_flag = di->opts & BQ27XXX_O_ZERO;
 
 	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
-	if ((cache.flags & 0xff) == 0xff)
-		cache.flags = -ENODEV; /* read error */
+	if (di->chip == BQ27000 && (cache.flags & 0xff) == 0xff)
+		cache.flags = -ENODEV; /* bq27000 hdq read error */
 	if (cache.flags >= 0) {
 		cache.capacity = bq27xxx_battery_read_soc(di);
 
Signature · 1 line
2.50.1
#5 lore raw

Re: [PATCH v2 2/2] power: supply: bq27xxx: restrict no-battery detection to bq27000

Quoted 28 lines · H. Nikolaus Schaller

There are fuel gauges in the bq27xxx series (e.g. bq27z561) which may in some cases report 0xff as the value of BQ27XXX_REG_FLAGS that should not be interpreted as "no battery" like for a disconnected battery with some built in bq27000 chip.

So restrict the no-battery detection originally introduced by

     commit 3dd843e1c26a ("bq27000: report missing device better.")

to the bq27000.

There is no need to backport further because this was hidden before

commit f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")

Fixes f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")
---
  drivers/power/supply/bq27xxx_battery.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/bq27xxx_battery.c +0 -0
index dadd8754a73a8..3363af24017ae 100644

drivers/power/supply/bq27xxx_battery.c static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di) · line 1951

Quoted 10 lines
drivers/power/supply/bq27xxx_battery.c +2 -2
@@ -1944,8 +1944,8 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
  	bool has_singe_flag = di->opts & BQ27XXX_O_ZERO;
 
  	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
-	if ((cache.flags & 0xff) == 0xff)
-		cache.flags = -ENODEV; /* read error */
+	if (di->chip == BQ27000 && (cache.flags & 0xff) == 0xff)
+		cache.flags = -ENODEV; /* bq27000 hdq read error */
  	if (cache.flags >= 0) {
  		cache.capacity = bq27xxx_battery_read_soc(di);
 

This change works fine for BQ27z561

#6 lore raw

Re: [Letux-kernel] [PATCH v2 2/2] power: supply: bq27xxx: restrict no-battery detection to bq27000

Quoted 28 lines

Am 28.08.2025 um 09:33 schrieb Jerry Lv <[email protected]>:

Quoted 23 lines · H. Nikolaus Schaller

There are fuel gauges in the bq27xxx series (e.g. bq27z561) which may in some cases report 0xff as the value of BQ27XXX_REG_FLAGS that should not be interpreted as "no battery" like for a disconnected battery with some built in bq27000 chip.

So restrict the no-battery detection originally introduced by

    commit 3dd843e1c26a ("bq27000: report missing device better.")

to the bq27000.

There is no need to backport further because this was hidden before

commit f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")

Fixes f16d9fb6cf03 ("power: supply: bq27xxx: Retrieve again when busy")
---
 drivers/power/supply/bq27xxx_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 5 lines
drivers/power/supply/bq27xxx_battery.c +0 -0
index dadd8754a73a8..3363af24017ae 100644

drivers/power/supply/bq27xxx_battery.c static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di) · line 1950

Quoted 9 lines
drivers/power/supply/bq27xxx_battery.c +2 -2
@@ -1944,8 +1944,8 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
 	bool has_singe_flag = di->opts & BQ27XXX_O_ZERO;
   	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
-	if ((cache.flags & 0xff) == 0xff)
-		cache.flags = -ENODEV; /* read error */
+	if (di->chip == BQ27000 && (cache.flags & 0xff) == 0xff)
+		cache.flags = -ENODEV; /* bq27000 hdq read error */
 	if (cache.flags >= 0) {
 		cache.capacity = bq27xxx_battery_read_soc(di);
 

This change works fine for BQ27z561

Thanks for testing!

So it appears we need a maintainer to pick up these patches...

BR,
Nikolaus

#7 lore raw
In reply to H. Nikolaus Schaller

Am Sat, 23 Aug 2025 12:34:55 +0200
schrieb "H. Nikolaus Schaller" <[email protected]>:

Quoted 5 lines

PATCH V2 2025-08-23 12:33:18:
Changes:
* improved commit description of main fix
* new patch: adds a restriction of historical no-battery-detection logic to the bq27000 chip

Quoted 8 lines

PATCH V1 2025-07-21 14:46:09:

H. Nikolaus Schaller (2):
power: supply: bq27xxx: fix error return in case of no bq27000 hdq
battery
power: supply: bq27xxx: restrict no-battery detection to bq27000

hmm, is the order correct? To me to be bisectable, should it be turned around? Maybe Sebastian just can do that while picking it.

Regards,
Andreas

#8 lore raw
Quoted 15 lines

Am 28.08.2025 um 20:24 schrieb Andreas Kemnade <[email protected]>:

Am Sat, 23 Aug 2025 12:34:55 +0200
schrieb "H. Nikolaus Schaller" <[email protected]>:

Quoted 8 lines

PATCH V2 2025-08-23 12:33:18:
Changes:
* improved commit description of main fix
* new patch: adds a restriction of historical no-battery-detection logic to the bq27000 chip

PATCH V1 2025-07-21 14:46:09:

Quoted 7 lines
Quoted 5 lines

H. Nikolaus Schaller (2):
power: supply: bq27xxx: fix error return in case of no bq27000 hdq
battery
power: supply: bq27xxx: restrict no-battery detection to bq27000

hmm, is the order correct? To me to be bisectable, should it be turned around? Maybe Sebastian just can do that while picking it.

Well, it is to decide which of the two fuel gauges fix first...

The bq27000 is working again after the first one and the bq27z561 is no longer influenced after the second.

BR,
Nikolaus

#9 lore raw
In reply to H. Nikolaus Schaller
Quoted 8 lines · H. Nikolaus Schaller

PATCH V2 2025-08-23 12:33:18:
Changes:
* improved commit description of main fix
* new patch: adds a restriction of historical no-battery-detection logic to the bq27000 chip

PATCH V1 2025-07-21 14:46:09:

[...]

Applied, thanks!

[1/2] power: supply: bq27xxx: fix error return in case of no bq27000 hdq battery

      commit: 2c334d038466ac509468fbe06905a32d202117db
[2/2] power: supply: bq27xxx: restrict no-battery detection to bq27000
      commit: 1e451977e1703b6db072719b37cd1b8e250b9cc9

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>