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; 4+ 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] 4+ 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; 4+ 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] 4+ 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; 4+ 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] 4+ 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
  2 siblings, 0 replies; 4+ 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] 4+ messages in thread

end of thread, other threads:[~2026-11-27 16:43 UTC | newest]

Thread overview: 4+ 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

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