Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support
@ 2026-11-26 20:19 Prachoday Sutar
  2026-11-26 20:19 ` [PATCH v2 1/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Prachoday Sutar @ 2026-11-26 20:19 UTC (permalink / raw)
  To: sre, robh, krzk+dt, conor+dt, pali, afd
  Cc: linux-pm, devicetree, Prachoday Sutar

The TI BQ27Z558 is a single-cell fuel gauge documented in the same
Technical Reference Manual as the BQ27Z561-R2 (SLUUC54) and is register
compatible with the BQ27Z561.

Patch 1 adds the compatible to the binding with "ti,bq27z561" as the
fallback. Patch 2 adds a matching I2C device ID so the driver probes
correctly when the client is named after the first compatible.

Tested on a Kneron KL630-based board with a BQ27Z558, using a vendor
Linux 4.9 kernel with the equivalent bq27xxx changes and the fallback
compatible in DT. Voltage, current, capacity, status and temperature
read correctly through /sys/class/power_supply.

Changes in v2:
- Add patch 2. Binding via the fallback compatible alone left
  i2c_client_get_device_id() returning NULL in probe, causing a NULL
  pointer dereference (reported by the Sashiko AI review).
- Patch 1: drop the claim from the commit message that no driver
  changes are needed.

Link to v1: https://lore.kernel.org/r/20261126191906.25708-1-prachodaysutar7@gmail.com

Prachoday Sutar (2):
  dt-bindings: power: supply: bq27xxx: Add BQ27Z558
  power: supply: bq27xxx: Add BQ27Z558 I2C device ID

 .../bindings/power/supply/bq27xxx.yaml        | 72 ++++++++++---------
 drivers/power/supply/bq27xxx_battery_i2c.c    |  1 +
 2 files changed, 39 insertions(+), 34 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558
  2026-11-26 20:19 [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
@ 2026-11-26 20:19 ` Prachoday Sutar
  2026-11-26 20:19 ` [PATCH v2 2/2] power: supply: bq27xxx: Add BQ27Z558 I2C device ID Prachoday Sutar
  2026-11-27 16:43 ` [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Andrew Davis
  2 siblings, 0 replies; 6+ messages in thread
From: Prachoday Sutar @ 2026-11-26 20:19 UTC (permalink / raw)
  To: sre, robh, krzk+dt, conor+dt, pali, afd
  Cc: linux-pm, devicetree, Prachoday Sutar

The TI BQ27Z558 is a single-cell fuel gauge documented in the same
Technical Reference Manual as the BQ27Z561-R2 (SLUUC54). It uses the
same standard command set and register layout as the BQ27Z561.

Add a compatible for the BQ27Z558 with "ti,bq27z561" as the fallback.

Signed-off-by: Prachoday Sutar <prachodaysutar7@gmail.com>
---
 .../bindings/power/supply/bq27xxx.yaml        | 72 ++++++++++---------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/Documentation/devicetree/bindings/power/supply/bq27xxx.yaml b/Documentation/devicetree/bindings/power/supply/bq27xxx.yaml
index be0f1f729..28b04732e 100644
--- a/Documentation/devicetree/bindings/power/supply/bq27xxx.yaml
+++ b/Documentation/devicetree/bindings/power/supply/bq27xxx.yaml
@@ -18,40 +18,44 @@ description: |
 
 properties:
   compatible:
-    enum:
-      - ti,bq27200
-      - ti,bq27210
-      - ti,bq27500 # deprecated, use revision specific property below
-      - ti,bq27510 # deprecated, use revision specific property below
-      - ti,bq27520 # deprecated, use revision specific property below
-      - ti,bq27500-1
-      - ti,bq27510g1
-      - ti,bq27510g2
-      - ti,bq27510g3
-      - ti,bq27520g1
-      - ti,bq27520g2
-      - ti,bq27520g3
-      - ti,bq27520g4
-      - ti,bq27521
-      - ti,bq27530
-      - ti,bq27531
-      - ti,bq27541
-      - ti,bq27542
-      - ti,bq27546
-      - ti,bq27742
-      - ti,bq27545
-      - ti,bq27411
-      - ti,bq27421
-      - ti,bq27425
-      - ti,bq27426
-      - ti,bq27441
-      - ti,bq27621
-      - ti,bq27z561
-      - ti,bq27z746
-      - ti,bq28z610
-      - ti,bq28z620
-      - ti,bq34z100
-      - ti,bq78z100
+    oneOf:
+      - enum:
+          - ti,bq27200
+          - ti,bq27210
+          - ti,bq27500 # deprecated, use revision specific property below
+          - ti,bq27510 # deprecated, use revision specific property below
+          - ti,bq27520 # deprecated, use revision specific property below
+          - ti,bq27500-1
+          - ti,bq27510g1
+          - ti,bq27510g2
+          - ti,bq27510g3
+          - ti,bq27520g1
+          - ti,bq27520g2
+          - ti,bq27520g3
+          - ti,bq27520g4
+          - ti,bq27521
+          - ti,bq27530
+          - ti,bq27531
+          - ti,bq27541
+          - ti,bq27542
+          - ti,bq27546
+          - ti,bq27742
+          - ti,bq27545
+          - ti,bq27411
+          - ti,bq27421
+          - ti,bq27425
+          - ti,bq27426
+          - ti,bq27441
+          - ti,bq27621
+          - ti,bq27z561
+          - ti,bq27z746
+          - ti,bq28z610
+          - ti,bq28z620
+          - ti,bq34z100
+          - ti,bq78z100
+      - items:
+          - const: ti,bq27z558
+          - const: ti,bq27z561
 
   reg:
     maxItems: 1
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] power: supply: bq27xxx: Add BQ27Z558 I2C device ID
  2026-11-26 20:19 [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
  2026-11-26 20:19 ` [PATCH v2 1/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
@ 2026-11-26 20:19 ` Prachoday Sutar
  2026-11-27 16:43 ` [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Andrew Davis
  2 siblings, 0 replies; 6+ messages in thread
From: Prachoday Sutar @ 2026-11-26 20:19 UTC (permalink / raw)
  To: sre, robh, krzk+dt, conor+dt, pali, afd
  Cc: linux-pm, devicetree, Prachoday Sutar

The BQ27Z558 is register compatible with the BQ27Z561 and is described
in DT with "ti,bq27z561" as a fallback compatible.

When an I2C client is instantiated from DT, its name is taken from the
first compatible string, so the client is named "bq27z558".
bq27xxx_battery_i2c_probe() gets the chip type from
i2c_client_get_device_id(), which matches on the client name. Without
a matching entry in the I2C ID table it returns NULL, and probe then
dereferences it.

Add a "bq27z558" entry to the I2C ID table that maps to BQ27Z561.

Signed-off-by: Prachoday Sutar <prachodaysutar7@gmail.com>
---
 drivers/power/supply/bq27xxx_battery_i2c.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
index bd1d5d046..6c0cea193 100644
--- a/drivers/power/supply/bq27xxx_battery_i2c.c
+++ b/drivers/power/supply/bq27xxx_battery_i2c.c
@@ -252,6 +252,7 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = {
 	{ .name = "bq27426", .driver_data = BQ27426 },
 	{ .name = "bq27441", .driver_data = BQ27441 },
 	{ .name = "bq27621", .driver_data = BQ27621 },
+	{ .name = "bq27z558", .driver_data = BQ27Z561 },
 	{ .name = "bq27z561", .driver_data = BQ27Z561 },
 	{ .name = "bq27z746", .driver_data = BQ27Z746 },
 	{ .name = "bq28z610", .driver_data = BQ28Z610 },
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support
  2026-11-26 20:19 [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
  2026-11-26 20:19 ` [PATCH v2 1/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
  2026-11-26 20:19 ` [PATCH v2 2/2] power: supply: bq27xxx: Add BQ27Z558 I2C device ID Prachoday Sutar
@ 2026-11-27 16:43 ` Andrew Davis
  2026-11-29 14:25   ` Prachoday Sutar
  2 siblings, 1 reply; 6+ messages in thread
From: Andrew Davis @ 2026-11-27 16:43 UTC (permalink / raw)
  To: Prachoday Sutar, sre, robh, krzk+dt, conor+dt, pali; +Cc: linux-pm, devicetree

On 11/26/26 2:19 PM, Prachoday Sutar wrote:
> The TI BQ27Z558 is a single-cell fuel gauge documented in the same
> Technical Reference Manual as the BQ27Z561-R2 (SLUUC54) and is register
> compatible with the BQ27Z561.
> 
> Patch 1 adds the compatible to the binding with "ti,bq27z561" as the
> fallback. Patch 2 adds a matching I2C device ID so the driver probes
> correctly when the client is named after the first compatible.
> 
> Tested on a Kneron KL630-based board with a BQ27Z558, using a vendor
> Linux 4.9 kernel with the equivalent bq27xxx changes and the fallback
> compatible in DT. Voltage, current, capacity, status and temperature
> read correctly through /sys/class/power_supply.
> 
> Changes in v2:
> - Add patch 2. Binding via the fallback compatible alone left
>    i2c_client_get_device_id() returning NULL in probe, causing a NULL
>    pointer dereference (reported by the Sashiko AI review).

I thought you said you tested this with the fallback? And Sashiko
says fallback will cause a NULL dereference, one of these must not
be true then..

I can see what Sashiko might be talking about here. I think a
couple things need fixed.

First, the `bq27xxx_battery_i2c_of_match_table` and the
`bq27xxx_i2c_id_table` are out of sync, so we match with OF
compatible, but use the I2C ID table to get the mach data.
The OF match data is currently empty, that needs updated.

Second, `i2c_client_get_device_id()` is only used as we need to
fetch the name, but we only use the name in `request_threaded_irq()`,
and we could use `client->name` instead. Then for getting the match
data use `i2c_get_match_data()`.

Third, I'd just skip the fallback stuff. If you have to modify the
driver anyway, just add a normal compatible and use it in your DT.

Andrew

> - Patch 1: drop the claim from the commit message that no driver
>    changes are needed.
> 
> Link to v1: https://lore.kernel.org/r/20261126191906.25708-1-prachodaysutar7@gmail.com
> 
> Prachoday Sutar (2):
>    dt-bindings: power: supply: bq27xxx: Add BQ27Z558
>    power: supply: bq27xxx: Add BQ27Z558 I2C device ID
> 
>   .../bindings/power/supply/bq27xxx.yaml        | 72 ++++++++++---------
>   drivers/power/supply/bq27xxx_battery_i2c.c    |  1 +
>   2 files changed, 39 insertions(+), 34 deletions(-)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support
  2026-11-27 16:43 ` [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Andrew Davis
@ 2026-11-29 14:25   ` Prachoday Sutar
  2026-12-05 18:37     ` Sebastian Reichel
  0 siblings, 1 reply; 6+ messages in thread
From: Prachoday Sutar @ 2026-11-29 14:25 UTC (permalink / raw)
  To: Andrew Davis; +Cc: sre, robh, krzk+dt, conor+dt, pali, linux-pm, devicetree

Hi Andrew,

Thanks for the review.

On Fri, Nov 27, 2026, Andrew Davis wrote:
> I thought you said you tested this with the fallback? And Sashiko
> says fallback will cause a NULL dereference, one of these must not
> be true then..

You're right, the test note was wrong, sorry about that. The testing
was done on a vendor 4.9 kernel with a local backport of BQ27Z561
support, and the board DT used only "ti,bq27z558", not the fallback.
In that tree "bq27z558" was in both the I2C ID table and the OF match
table, so the I2C ID lookup succeeded and the fallback-only path that
Sashiko flagged was never exercised. So that test only shows that the
BQ27Z558 works with the BQ27Z561 register map and status bits; it did
not run the mainline driver. I'll describe the testing accurately in
v3.

> First, the `bq27xxx_battery_i2c_of_match_table` and the
> `bq27xxx_i2c_id_table` are out of sync, so we match with OF
> compatible, but use the I2C ID table to get the mach data.
> The OF match data is currently empty, that needs updated.

Agreed. In v3 I'll add the chip type as .data to every entry in the
OF match table, so the two tables no longer need to be kept in sync
by hand.

> Second, `i2c_client_get_device_id()` is only used as we need to
> fetch the name, but we only use the name in `request_threaded_irq()`,
> and we could use `client->name` instead. Then for getting the match
> data use `i2c_get_match_data()`.

Will do. For all existing compatibles client->name is the same as the
matched I2C ID name, so the battery names seen by userspace don't
change.

> Third, I'd just skip the fallback stuff. If you have to modify the
> driver anyway, just add a normal compatible and use it in your DT.

OK, I'll drop the fallback and add "ti,bq27z558" as a plain
compatible, which also matches how it was set up in the tree I tested.
One question first: once the OF match data is in place, the fallback
would work without any BQ27Z558-specific driver change. If the DT
binding maintainers would prefer to keep the fallback for that reason,
I'm happy to do that instead. Otherwise I'll go with the plain
compatible.

Planned v3:
  1/3 dt-bindings: power: supply: bq27xxx: Add BQ27Z558
  2/3 power: supply: bq27xxx: Use i2c_get_match_data()
  3/3 power: supply: bq27xxx: Add BQ27Z558 support

Thanks,
Prachoday

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support
  2026-11-29 14:25   ` Prachoday Sutar
@ 2026-12-05 18:37     ` Sebastian Reichel
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2026-12-05 18:37 UTC (permalink / raw)
  To: Prachoday Sutar
  Cc: Andrew Davis, robh, krzk+dt, conor+dt, pali, linux-pm, devicetree

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

Hi,

On Sun, Nov 29, 2026 at 07:55:18PM +0530, Prachoday Sutar wrote:
> On Fri, Nov 27, 2026, Andrew Davis wrote:
> > I thought you said you tested this with the fallback? And Sashiko
> > says fallback will cause a NULL dereference, one of these must not
> > be true then..
> 
> You're right, the test note was wrong, sorry about that. The testing
> was done on a vendor 4.9 kernel with a local backport of BQ27Z561
> support, and the board DT used only "ti,bq27z558", not the fallback.
> In that tree "bq27z558" was in both the I2C ID table and the OF match
> table, so the I2C ID lookup succeeded and the fallback-only path that
> Sashiko flagged was never exercised. So that test only shows that the
> BQ27Z558 works with the BQ27Z561 register map and status bits; it did
> not run the mainline driver. I'll describe the testing accurately in
> v3.
>
> > First, the `bq27xxx_battery_i2c_of_match_table` and the
> > `bq27xxx_i2c_id_table` are out of sync, so we match with OF
> > compatible, but use the I2C ID table to get the mach data.
> > The OF match data is currently empty, that needs updated.
> 
> Agreed. In v3 I'll add the chip type as .data to every entry in the
> OF match table, so the two tables no longer need to be kept in sync
> by hand.
> 
> > Second, `i2c_client_get_device_id()` is only used as we need to
> > fetch the name, but we only use the name in `request_threaded_irq()`,
> > and we could use `client->name` instead. Then for getting the match
> > data use `i2c_get_match_data()`.
> 
> Will do. For all existing compatibles client->name is the same as the
> matched I2C ID name, so the battery names seen by userspace don't
> change.
> 
> > Third, I'd just skip the fallback stuff. If you have to modify the
> > driver anyway, just add a normal compatible and use it in your DT.
> 
> OK, I'll drop the fallback and add "ti,bq27z558" as a plain
> compatible, which also matches how it was set up in the tree I tested.

The fallback is the correct thing to do. The binding is not just
for the Linux driver and the only reason the Linux driver needs
the specific entry is the exact chip name.

> One question first: once the OF match data is in place, the
> fallback would work without any BQ27Z558-specific driver change.
> If the DT binding maintainers would prefer to keep the fallback
> for that reason, I'm happy to do that instead. Otherwise I'll go
> with the plain compatible.
>
> 
> Planned v3:
>   1/3 dt-bindings: power: supply: bq27xxx: Add BQ27Z558
>   2/3 power: supply: bq27xxx: Use i2c_get_match_data()
>   3/3 power: supply: bq27xxx: Add BQ27Z558 support
> 
> Thanks,
> Prachoday

Greetings,

-- Sebastian

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-05 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 20:19 [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
2026-11-26 20:19 ` [PATCH v2 1/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
2026-11-26 20:19 ` [PATCH v2 2/2] power: supply: bq27xxx: Add BQ27Z558 I2C device ID Prachoday Sutar
2026-11-27 16:43 ` [PATCH v2 0/2] Add TI BQ27Z558 fuel gauge support Andrew Davis
2026-11-29 14:25   ` Prachoday Sutar
2026-12-05 18:37     ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox