public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Sebastian Reichel <sre@kernel.org>, Marek Vasut <marex@denx.de>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-pm@vger.kernel.org
Subject: [PATCH 08/10] power: supply: bq25890: Support boards with more then one charger IC
Date: Sun, 27 Nov 2022 19:02:31 +0100	[thread overview]
Message-ID: <20221127180233.103678-9-hdegoede@redhat.com> (raw)
In-Reply-To: <20221127180233.103678-1-hdegoede@redhat.com>

Some devices, such as the Lenovo Yoga Tab 3 Pro (YT3-X90F) have
multiple batteries with a separate bq25890 charger for each battery.

This requires the bq25890_charger code to use a unique name per
registered power_supply class device, rather then hardcoding
"bq25890-charger" as power_supply class device name.

Add a "-%d" prefix to the name, allocated through idr in the same way
as several other power_supply drivers are already doing this.

Note this also updates: drivers/platform/x86/x86-android-tablets.c
which refers to the charger by power_supply-class-device-name for
the purpose of setting the "supplied-from" property on the fuel-gauge
to this name.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
As the subsystem maintainer for drivers/platform/x86 I'm fine with
the small x86-android-tablets.c being merged through the
linux-power-supply tree.

Also note I did a full grep for "bq25890-charger" and
x86-android-tablets.c is the only file in the kernel tree referring
to this name.
---
 drivers/platform/x86/x86-android-tablets.c |  2 +-
 drivers/power/supply/bq25890_charger.c     | 29 +++++++++++++++++++---
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index dd933cf32b38..916e37a4f85e 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -187,7 +187,7 @@ struct x86_dev_info {
 /* Generic / shared charger / battery settings */
 static const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
 static const char * const bq24190_psy[] = { "bq24190-charger" };
-static const char * const bq25890_psy[] = { "bq25890-charger" };
+static const char * const bq25890_psy[] = { "bq25890-charger-0" };
 
 static const struct property_entry fg_bq24190_supply_props[] = {
 	PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 03e31c5b0df5..a0e20cbadeb8 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -108,6 +108,9 @@ struct bq25890_device {
 	struct i2c_client *client;
 	struct device *dev;
 	struct power_supply *charger;
+	struct power_supply_desc desc;
+	char name[28]; /* "bq25890-charger-%d" */
+	int id;
 
 	struct usb_phy *usb_phy;
 	struct notifier_block usb_nb;
@@ -129,6 +132,9 @@ struct bq25890_device {
 	struct mutex lock; /* protect state data */
 };
 
+static DEFINE_IDR(bq25890_id);
+static DEFINE_MUTEX(bq25890_id_mutex);
+
 static const struct regmap_range bq25890_readonly_reg_ranges[] = {
 	regmap_reg_range(0x0b, 0x0c),
 	regmap_reg_range(0x0e, 0x13),
@@ -989,7 +995,6 @@ static char *bq25890_charger_supplied_to[] = {
 };
 
 static const struct power_supply_desc bq25890_power_supply_desc = {
-	.name = "bq25890-charger",
 	.type = POWER_SUPPLY_TYPE_USB,
 	.properties = bq25890_power_supply_props,
 	.num_properties = ARRAY_SIZE(bq25890_power_supply_props),
@@ -1003,12 +1008,21 @@ static int bq25890_power_supply_init(struct bq25890_device *bq)
 {
 	struct power_supply_config psy_cfg = { .drv_data = bq, };
 
+	/* Get ID for the device */
+	mutex_lock(&bq25890_id_mutex);
+	bq->id = idr_alloc(&bq25890_id, bq, 0, 0, GFP_KERNEL);
+	mutex_unlock(&bq25890_id_mutex);
+	if (bq->id < 0)
+		return bq->id;
+
+	snprintf(bq->name, sizeof(bq->name), "bq25890-charger-%d", bq->id);
+	bq->desc = bq25890_power_supply_desc;
+	bq->desc.name = bq->name;
+
 	psy_cfg.supplied_to = bq25890_charger_supplied_to;
 	psy_cfg.num_supplicants = ARRAY_SIZE(bq25890_charger_supplied_to);
 
-	bq->charger = devm_power_supply_register(bq->dev,
-						 &bq25890_power_supply_desc,
-						 &psy_cfg);
+	bq->charger = devm_power_supply_register(bq->dev, &bq->desc, &psy_cfg);
 
 	return PTR_ERR_OR_ZERO(bq->charger);
 }
@@ -1354,6 +1368,12 @@ static void bq25890_non_devm_cleanup(void *data)
 	struct bq25890_device *bq = data;
 
 	cancel_delayed_work_sync(&bq->pump_express_work);
+
+	if (bq->id >= 0) {
+		mutex_lock(&bq25890_id_mutex);
+		idr_remove(&bq25890_id, bq->id);
+		mutex_unlock(&bq25890_id_mutex);
+	}
 }
 
 static int bq25890_probe(struct i2c_client *client)
@@ -1368,6 +1388,7 @@ static int bq25890_probe(struct i2c_client *client)
 
 	bq->client = client;
 	bq->dev = dev;
+	bq->id = -1;
 
 	mutex_init(&bq->lock);
 	INIT_DELAYED_WORK(&bq->pump_express_work, bq25890_pump_express_work);
-- 
2.38.1


  parent reply	other threads:[~2022-11-27 18:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-27 18:02 [PATCH 00/10] power: supply: bq25890: Fixes for 6.2 + further work for 6.3 Hans de Goede
2022-11-27 18:02 ` [PATCH 01/10] power: supply: bq25890: Only use pdata->regulator_init_data for vbus Hans de Goede
2022-11-27 21:16   ` Marek Vasut
2022-11-27 23:30     ` Sebastian Reichel
2022-11-27 18:02 ` [PATCH 02/10] power: supply: bq25890: Ensure pump_express_work is cancelled on remove Hans de Goede
2022-11-27 21:17   ` Marek Vasut
2022-11-27 23:17   ` Sebastian Reichel
2022-11-28  7:20     ` Hans de Goede
2022-11-27 18:02 ` [PATCH 03/10] power: supply: bq25890: Fix usb-notifier probe and remove races Hans de Goede
2022-11-27 21:19   ` Marek Vasut
2022-11-27 18:02 ` [PATCH 04/10] power: supply: bq25890: Factor out chip state update Hans de Goede
2022-11-27 18:02 ` [PATCH 05/10] power: supply: bq25890: Add HiZ mode support Hans de Goede
2022-11-27 18:02 ` [PATCH 06/10] power: supply: bq25890: Fix setting of F_CONV_RATE rate when disabling HiZ mode Hans de Goede
2022-11-27 21:24   ` Marek Vasut
2022-11-27 18:02 ` [PATCH 07/10] power: supply: bq25890: Always take HiZ mode into account for ADC rate Hans de Goede
2022-11-27 21:25   ` Marek Vasut
2022-11-27 18:02 ` Hans de Goede [this message]
2022-11-27 21:27   ` [PATCH 08/10] power: supply: bq25890: Support boards with more then one charger IC Marek Vasut
2022-11-27 18:02 ` [PATCH 09/10] power: supply: bq25890: Add support for having a secondary " Hans de Goede
2022-11-27 21:33   ` Marek Vasut
2022-11-27 18:02 ` [PATCH 10/10] power: supply: bq25890: Add new linux,iinlim-percentage property Hans de Goede
2022-11-27 21:34   ` Marek Vasut
2022-11-28  9:16     ` Hans de Goede

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=20221127180233.103678-9-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=marex@denx.de \
    --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