Skip to content

Commit 4e9498b

Browse files
jwrdegoedesre
authored andcommitted
power: supply: bq25890: Support boards with more then one charger IC
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. Reviewed-by: Marek Vasut <marex@denx.de> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent dee0df8 commit 4e9498b

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

drivers/platform/x86/x86-android-tablets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ struct x86_dev_info {
187187
/* Generic / shared charger / battery settings */
188188
static const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
189189
static const char * const bq24190_psy[] = { "bq24190-charger" };
190-
static const char * const bq25890_psy[] = { "bq25890-charger" };
190+
static const char * const bq25890_psy[] = { "bq25890-charger-0" };
191191

192192
static const struct property_entry fg_bq24190_supply_props[] = {
193193
PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),

drivers/power/supply/bq25890_charger.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ struct bq25890_device {
108108
struct i2c_client *client;
109109
struct device *dev;
110110
struct power_supply *charger;
111+
struct power_supply_desc desc;
112+
char name[28]; /* "bq25890-charger-%d" */
113+
int id;
111114

112115
struct usb_phy *usb_phy;
113116
struct notifier_block usb_nb;
@@ -129,6 +132,9 @@ struct bq25890_device {
129132
struct mutex lock; /* protect state data */
130133
};
131134

135+
static DEFINE_IDR(bq25890_id);
136+
static DEFINE_MUTEX(bq25890_id_mutex);
137+
132138
static const struct regmap_range bq25890_readonly_reg_ranges[] = {
133139
regmap_reg_range(0x0b, 0x0c),
134140
regmap_reg_range(0x0e, 0x13),
@@ -989,7 +995,6 @@ static char *bq25890_charger_supplied_to[] = {
989995
};
990996

991997
static const struct power_supply_desc bq25890_power_supply_desc = {
992-
.name = "bq25890-charger",
993998
.type = POWER_SUPPLY_TYPE_USB,
994999
.properties = bq25890_power_supply_props,
9951000
.num_properties = ARRAY_SIZE(bq25890_power_supply_props),
@@ -1003,12 +1008,21 @@ static int bq25890_power_supply_init(struct bq25890_device *bq)
10031008
{
10041009
struct power_supply_config psy_cfg = { .drv_data = bq, };
10051010

1011+
/* Get ID for the device */
1012+
mutex_lock(&bq25890_id_mutex);
1013+
bq->id = idr_alloc(&bq25890_id, bq, 0, 0, GFP_KERNEL);
1014+
mutex_unlock(&bq25890_id_mutex);
1015+
if (bq->id < 0)
1016+
return bq->id;
1017+
1018+
snprintf(bq->name, sizeof(bq->name), "bq25890-charger-%d", bq->id);
1019+
bq->desc = bq25890_power_supply_desc;
1020+
bq->desc.name = bq->name;
1021+
10061022
psy_cfg.supplied_to = bq25890_charger_supplied_to;
10071023
psy_cfg.num_supplicants = ARRAY_SIZE(bq25890_charger_supplied_to);
10081024

1009-
bq->charger = devm_power_supply_register(bq->dev,
1010-
&bq25890_power_supply_desc,
1011-
&psy_cfg);
1025+
bq->charger = devm_power_supply_register(bq->dev, &bq->desc, &psy_cfg);
10121026

10131027
return PTR_ERR_OR_ZERO(bq->charger);
10141028
}
@@ -1354,6 +1368,12 @@ static void bq25890_non_devm_cleanup(void *data)
13541368
struct bq25890_device *bq = data;
13551369

13561370
cancel_delayed_work_sync(&bq->pump_express_work);
1371+
1372+
if (bq->id >= 0) {
1373+
mutex_lock(&bq25890_id_mutex);
1374+
idr_remove(&bq25890_id, bq->id);
1375+
mutex_unlock(&bq25890_id_mutex);
1376+
}
13571377
}
13581378

13591379
static int bq25890_probe(struct i2c_client *client)
@@ -1368,6 +1388,7 @@ static int bq25890_probe(struct i2c_client *client)
13681388

13691389
bq->client = client;
13701390
bq->dev = dev;
1391+
bq->id = -1;
13711392

13721393
mutex_init(&bq->lock);
13731394
INIT_DELAYED_WORK(&bq->pump_express_work, bq25890_pump_express_work);

0 commit comments

Comments
 (0)