From: Prachoday Sutar <prachodaysutar7@gmail.com>
To: sre@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, pali@kernel.org, afd@ti.com
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Prachoday Sutar <prachodaysutar7@gmail.com>
Subject: [PATCH v3 1/2] power: supply: bq27xxx: Use i2c_get_match_data()
Date: Sun, 6 Dec 2026 13:55:00 +0530 [thread overview]
Message-ID: <20261206082501.10506-2-prachodaysutar7@gmail.com> (raw)
In-Reply-To: <20261206082501.10506-1-prachodaysutar7@gmail.com>
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
next prev parent reply other threads:[~2026-12-06 8:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 8:24 [PATCH v3 0/2] Add TI BQ27Z558 fuel gauge support Prachoday Sutar
2026-12-06 8:25 ` Prachoday Sutar [this message]
2026-12-06 8:25 ` [PATCH v3 2/2] dt-bindings: power: supply: bq27xxx: Add BQ27Z558 Prachoday Sutar
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=20261206082501.10506-2-prachodaysutar7@gmail.com \
--to=prachodaysutar7@gmail.com \
--cc=afd@ti.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pali@kernel.org \
--cc=robh@kernel.org \
--cc=sre@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
all inboxes | Powered by JetHome®