mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Heidelberg <david@ixit.cz>
To: Rinat Muhamedgaliev <rinat.muhamedgaliev@gmail.com>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	Sebastian Reichel <sre@kernel.org>
Cc: "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Pali Rohár" <pali@kernel.org>, "Andrew F . Davis" <afd@ti.com>,
	linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] power: supply: bq27xxx: autodetect bq27411 and bq27541
Date: Thu, 10 Sep 2026 02:09:27 +0200	[thread overview]
Message-ID: <c29fdce5-0710-430a-90b9-e08d5b6c6780@ixit.cz> (raw)
In-Reply-To: <20260909234744.1177153-3-rinat.muhamedgaliev@gmail.com>

On 10/09/2026 01:47, Rinat Muhamedgaliev wrote:
> Some replaceable battery packs used by OnePlus 6 and OnePlus 6T
> phones contain a bq27411, while others contain a bq27541. These
> devices require different register maps.
> 
> Add support for the generic ti,bq27xxx compatible. At probe time,
> issue the DeviceType control command and select the bq27411 or bq27541
> register map from the returned value.
> 
> Signed-off-by: Rinat Muhamedgaliev <rinat.muhamedgaliev@gmail.com>
> ---
>   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 868e95f..718f8e8 100644
> --- a/drivers/power/supply/bq27xxx_battery_i2c.c
> +++ b/drivers/power/supply/bq27xxx_battery_i2c.c
> @@ -16,6 +16,11 @@
>   
>   static DEFINE_IDA(battery_id);
>   
> +#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;
> @@ -153,6 +158,32 @@ static void bq27xxx_battery_i2c_devm_ida_free(void *data)
>   	ida_free(&battery_id, num);
>   }
>   
> +static int bq27xxx_battery_i2c_detect_chip(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:
> +		di->chip = BQ27411;
> +		return 0;
> +	case BQ27541_DEVICE_TYPE:
> +		di->chip = BQ27541;
> +		return 0;
> +	default:
> +		dev_err(di->dev, "unsupported device type 0x%04x\n", ret);
> +		return -ENODEV;
> +	}
> +}
> +
>   static int bq27xxx_battery_i2c_probe(struct i2c_client *client)
>   {
>   	const struct i2c_device_id *id = i2c_client_get_device_id(client);
> @@ -188,6 +219,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;
>   
> +	if (!di->chip) {
> +		ret = bq27xxx_battery_i2c_detect_chip(di);
> +		if (ret)
> +			return ret;
> +	}
> +
>   	ret = bq27xxx_battery_setup(di);
>   	if (ret)
>   		return ret;
> @@ -225,6 +262,7 @@ static void bq27xxx_battery_i2c_remove(struct i2c_client *client)
>   }
>   
>   static const struct i2c_device_id bq27xxx_i2c_id_table[] = {
> +	{ "bq27xxx", 0 },
>   	{ "bq27200", BQ27000 },
>   	{ "bq27210", BQ27010 },
>   	{ "bq27500", BQ2750X },
> @@ -262,6 +300,7 @@ 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,bq27xxx" },

Maybe some comment suggesting to use this compatible when autodetection is needed?

David

>   	{ .compatible = "ti,bq27200" },
>   	{ .compatible = "ti,bq27210" },
>   	{ .compatible = "ti,bq27500" },


  reply	other threads:[~2026-09-10  0:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 23:38 [PATCH] arm64: dts: qcom: sdm845-oneplus: fix fuel gauge compatible Rinat Muhamedgaliev
2026-08-27 21:43 ` Krzysztof Kozlowski
2026-08-28 10:05 ` Konrad Dybcio
2026-08-29 21:03   ` Rinat Muhamedgaliev
2026-09-08 13:15     ` Konrad Dybcio
2026-08-29 20:52 ` [PATCH v2] " Rinat Muhamedgaliev
2026-09-09 23:47   ` [PATCH v3 0/3] bq27xxx: support interchangeable OnePlus 6/6T fuel gauges Rinat Muhamedgaliev
2026-09-09 23:47     ` [PATCH v3 1/3] dt-bindings: power: supply: bq27xxx: add generic compatible Rinat Muhamedgaliev
2026-09-11  8:20       ` Krzysztof Kozlowski
2026-09-09 23:47     ` [PATCH v3 2/3] power: supply: bq27xxx: autodetect bq27411 and bq27541 Rinat Muhamedgaliev
2026-09-10  0:09       ` David Heidelberg [this message]
2026-09-10  7:42       ` Konrad Dybcio
2026-09-09 23:47     ` [PATCH v3 3/3] arm64: dts: qcom: sdm845-oneplus: use generic fuel gauge compatible Rinat Muhamedgaliev
2026-09-10  0:12       ` David Heidelberg
2026-09-11  8:21       ` Krzysztof Kozlowski
2026-09-11 13:37         ` Andrew Davis
2026-09-11 18:41           ` David Heidelberg
2026-09-11 20:00           ` David Heidelberg
2026-09-12  7:47           ` Krzysztof Kozlowski
2026-09-10  0:08     ` [PATCH v3 0/3] bq27xxx: support interchangeable OnePlus 6/6T fuel gauges David Heidelberg
2026-09-07  8:38 ` [PATCH] arm64: dts: qcom: sdm845-oneplus: fix fuel gauge compatible David Heidelberg

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=c29fdce5-0710-430a-90b9-e08d5b6c6780@ixit.cz \
    --to=david@ixit.cz \
    --cc=afd@ti.com \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=rinat.muhamedgaliev@gmail.com \
    --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®