Re: [PATCH v5] power: supply: bq27xxx: detect bq27541 behind bq27411 compatible

From: David Heidelberg

Date: Sun Oct 18 2026 - 06:43:34 EST


On 18/10/2026 02:51, Rinat Muhamedgaliev wrote:
OnePlus 6 and 6T replacement battery packs may contain either a bq27411
or a bq27541 fuel gauge at I2C address 0x55. The device tree currently
identifies the gauge as bq27411, but a bq27541 uses a different register
map and then reports invalid battery values.

Read the DeviceType control subcommand when probing a bq27411. Keep the
existing profile for DeviceType 0x0421, but select the bq27541 profile
for DeviceType 0x0541. This retains the established DT ABI and supports
replacement packs without introducing a generic compatible.

Tested on OnePlus 6T (fajita) with DeviceType 0x0541: voltage, state of
charge, and temperature were reported correctly. Testing on hardware with
DeviceType 0x0421 would be appreciated.

Signed-off-by: Rinat Muhamedgaliev <rinat.muhamedgaliev@xxxxxxxxx>
---
drivers/power/supply/bq27xxx_battery_i2c.c | 39 ++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
index 94b00bb89c17..8c05740f1173 100644
--- a/drivers/power/supply/bq27xxx_battery_i2c.c
+++ b/drivers/power/supply/bq27xxx_battery_i2c.c
@@ -16,6 +16,11 @@
static DEFINE_IDR(battery_id);
static DEFINE_MUTEX(battery_mutex);
+#define BQ27XXX_REG_CTRL 0x00
+#define BQ27XXX_DEVICE_TYPE 0x0001
+#define BQ27411_DEVICE_TYPE 0x0421
+#define BQ27541_DEVICE_TYPE 0x0541
+
static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
{
struct bq27xxx_device_info *di = data;
@@ -136,6 +141,34 @@ static int bq27xxx_battery_i2c_bulk_write(struct bq27xxx_device_info *di,
return 0;
}
+static int bq27xxx_battery_i2c_check_device_type(struct bq27xxx_device_info *di)
+{
+ int ret;
+
+ ret = di->bus.write(di, BQ27XXX_REG_CTRL, BQ27XXX_DEVICE_TYPE,
+ false);
+ if (ret < 0)
+ return ret;
+
+ ret = di->bus.read(di, BQ27XXX_REG_CTRL, false);
+ if (ret < 0)
+ return ret;
+
+ switch (ret) {
+ case BQ27411_DEVICE_TYPE:
+ return 0;

Hello Rinat.

Thanks for the next version, comments below :)

you made the function generic, that's good, but then when it's BQ27411 returning success. The switch should account that you comparing model acquired from compatible against the model you detected, not blindly assume original chip is 27411.

+ case BQ27541_DEVICE_TYPE:
+ dev_warn(di->dev,
+ "detected DeviceType 0x%04x instead of expected 0x%04x\n",
+ ret, BQ27411_DEVICE_TYPE);
+ di->chip = BQ27541;
+ return 0;
+ default:
+ dev_err(di->dev, "unrecognized DeviceType 0x%04x\n", ret);
+ return -ENODEV;
+ }
+}
+
static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -169,6 +202,12 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
di->bus.read_bulk = bq27xxx_battery_i2c_bulk_read;
di->bus.write_bulk = bq27xxx_battery_i2c_bulk_write;

I would suggest dropping comment here that's a list of models which we can detect verify.

+ if (di->chip == BQ27411) {

With our data, can should be able detect BQ27541 -> BQ27411 too. I would suggest transforming this into some switch statement block.

Thank you
David

+ ret = bq27xxx_battery_i2c_check_device_type(di);
+ if (ret)
+ goto err_failed;
+ }
+
ret = bq27xxx_battery_setup(di);
if (ret)
goto err_failed;