* [PATCH v3 1/2] power: supply: bq27xxx: Use i2c_get_match_data()
2026-12-06 8:24 [PATCH v3 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
@ 2026-12-06 8:25 ` Prachoday Sutar
2026-12-06 8:25 ` [PATCH v3 2/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
1 sibling, 0 replies; 3+ messages in thread
From: Prachoday Sutar @ 2026-12-06 8:25 UTC (permalink / raw)
To: sre, robh, krzk+dt, conor+dt, pali, afd
Cc: linux-pm, devicetree, linux-kernel, Prachoday Sutar
bq27xxx_battery_i2c_probe() gets the chip type and the battery name
from i2c_client_get_device_id(), which looks up the client name in the
I2C ID table. The OF match table has no .data, so even when the device
is matched through a DT compatible, the chip type comes from the I2C
ID table.
This only works as long as the two tables are kept in sync and the
client name, which is taken from the first DT compatible, has an entry
in the I2C ID table. A device described with a fallback compatible,
where only the fallback is known to the driver, gets a NULL ID and
probe dereferences it.
Add the chip type as .data to every OF match entry and get it with
i2c_get_match_data(), which uses the OF match data and falls back to
the I2C ID table. Use client->name for the battery name. For every
compatible in the OF match table, client->name is the same as the
matching I2C ID name, so the names seen by userspace do not change.
Suggested-by: Andrew Davis <afd@ti.com>
Signed-off-by: Prachoday Sutar <prachodaysutar7@gmail.com>
---
drivers/power/supply/bq27xxx_battery_i2c.c | 76 ++++++++++++----------
1 file changed, 40 insertions(+), 36 deletions(-)
diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
index 63bfc868a6d..8e54dbfee2d 100644
--- a/drivers/power/supply/bq27xxx_battery_i2c.c
+++ b/drivers/power/supply/bq27xxx_battery_i2c.c
@@ -157,12 +157,16 @@ static void bq27xxx_battery_i2c_devm_ida_free(void *data)
static int bq27xxx_battery_i2c_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
struct bq27xxx_device_info *di;
+ enum bq27xxx_chip chip;
int ret;
char *name;
long num;
+ chip = (uintptr_t)i2c_get_match_data(client);
+ if (!chip)
+ return -ENODEV;
+
/* Get new ID for the new battery device */
num = ida_alloc(&battery_id, GFP_KERNEL);
if (num < 0)
@@ -173,7 +177,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client)
if (ret)
return ret;
- name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", id->name, num);
+ name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", client->name, num);
if (!name)
return -ENOMEM;
@@ -182,7 +186,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client)
return -ENOMEM;
di->dev = &client->dev;
- di->chip = id->driver_data;
+ di->chip = chip;
di->name = name;
di->bus.read = bq27xxx_battery_i2c_read;
@@ -266,39 +270,39 @@ MODULE_DEVICE_TABLE(i2c, bq27xxx_i2c_id_table);
#ifdef CONFIG_OF
static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = {
- { .compatible = "ti,bq27200" },
- { .compatible = "ti,bq27210" },
- { .compatible = "ti,bq27500" },
- { .compatible = "ti,bq27510" },
- { .compatible = "ti,bq27520" },
- { .compatible = "ti,bq27500-1" },
- { .compatible = "ti,bq27510g1" },
- { .compatible = "ti,bq27510g2" },
- { .compatible = "ti,bq27510g3" },
- { .compatible = "ti,bq27520g1" },
- { .compatible = "ti,bq27520g2" },
- { .compatible = "ti,bq27520g3" },
- { .compatible = "ti,bq27520g4" },
- { .compatible = "ti,bq27521" },
- { .compatible = "ti,bq27530" },
- { .compatible = "ti,bq27531" },
- { .compatible = "ti,bq27541" },
- { .compatible = "ti,bq27542" },
- { .compatible = "ti,bq27546" },
- { .compatible = "ti,bq27742" },
- { .compatible = "ti,bq27545" },
- { .compatible = "ti,bq27411" },
- { .compatible = "ti,bq27421" },
- { .compatible = "ti,bq27425" },
- { .compatible = "ti,bq27426" },
- { .compatible = "ti,bq27441" },
- { .compatible = "ti,bq27621" },
- { .compatible = "ti,bq27z561" },
- { .compatible = "ti,bq27z746" },
- { .compatible = "ti,bq28z610" },
- { .compatible = "ti,bq28z620" },
- { .compatible = "ti,bq34z100" },
- { .compatible = "ti,bq78z100" },
+ { .compatible = "ti,bq27200", .data = (void *)BQ27000 },
+ { .compatible = "ti,bq27210", .data = (void *)BQ27010 },
+ { .compatible = "ti,bq27500", .data = (void *)BQ2750X },
+ { .compatible = "ti,bq27510", .data = (void *)BQ2751X },
+ { .compatible = "ti,bq27520", .data = (void *)BQ2752X },
+ { .compatible = "ti,bq27500-1", .data = (void *)BQ27500 },
+ { .compatible = "ti,bq27510g1", .data = (void *)BQ27510G1 },
+ { .compatible = "ti,bq27510g2", .data = (void *)BQ27510G2 },
+ { .compatible = "ti,bq27510g3", .data = (void *)BQ27510G3 },
+ { .compatible = "ti,bq27520g1", .data = (void *)BQ27520G1 },
+ { .compatible = "ti,bq27520g2", .data = (void *)BQ27520G2 },
+ { .compatible = "ti,bq27520g3", .data = (void *)BQ27520G3 },
+ { .compatible = "ti,bq27520g4", .data = (void *)BQ27520G4 },
+ { .compatible = "ti,bq27521", .data = (void *)BQ27521 },
+ { .compatible = "ti,bq27530", .data = (void *)BQ27530 },
+ { .compatible = "ti,bq27531", .data = (void *)BQ27531 },
+ { .compatible = "ti,bq27541", .data = (void *)BQ27541 },
+ { .compatible = "ti,bq27542", .data = (void *)BQ27542 },
+ { .compatible = "ti,bq27546", .data = (void *)BQ27546 },
+ { .compatible = "ti,bq27742", .data = (void *)BQ27742 },
+ { .compatible = "ti,bq27545", .data = (void *)BQ27545 },
+ { .compatible = "ti,bq27411", .data = (void *)BQ27411 },
+ { .compatible = "ti,bq27421", .data = (void *)BQ27421 },
+ { .compatible = "ti,bq27425", .data = (void *)BQ27425 },
+ { .compatible = "ti,bq27426", .data = (void *)BQ27426 },
+ { .compatible = "ti,bq27441", .data = (void *)BQ27441 },
+ { .compatible = "ti,bq27621", .data = (void *)BQ27621 },
+ { .compatible = "ti,bq27z561", .data = (void *)BQ27Z561 },
+ { .compatible = "ti,bq27z746", .data = (void *)BQ27Z746 },
+ { .compatible = "ti,bq28z610", .data = (void *)BQ28Z610 },
+ { .compatible = "ti,bq28z620", .data = (void *)BQ28Z620 },
+ { .compatible = "ti,bq34z100", .data = (void *)BQ34Z100 },
+ { .compatible = "ti,bq78z100", .data = (void *)BQ78Z100 },
{},
};
MODULE_DEVICE_TABLE(of, bq27xxx_battery_i2c_of_match_table);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v3 2/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558
2026-12-06 8:24 [PATCH v3 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
2026-12-06 8:25 ` [PATCH v3 1/2] power: supply: bq27xxx: Use i2c_get_match_data() Prachoday Sutar
@ 2026-12-06 8:25 ` Prachoday Sutar
1 sibling, 0 replies; 3+ messages in thread
From: Prachoday Sutar @ 2026-12-06 8:25 UTC (permalink / raw)
To: sre, robh, krzk+dt, conor+dt, pali, afd
Cc: linux-pm, devicetree, linux-kernel, 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 be0f1f7292c..28b04732e08 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.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread