Commit 9aafabc7 authored by Ivaylo Dimitrov's avatar Ivaylo Dimitrov Committed by Sebastian Reichel

power: bq27xxx_battery: Restore device name

Patch <703df6c0> ("power: bq27xxx_battery: Reorganize I2C
into a module") has removed the device name numbering from
bq27xxx_battery_i2c_probe. Fix that by restoring the code.

Fixes: 703df6c0Signed-off-by: default avatarIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Reviewed-by: default avatarPali Rohár <pali.rohar@gmail.com>
Tested-by: default avatarPali Rohár <pali.rohar@gmail.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent e35a49b1
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include <linux/power/bq27xxx_battery.h> #include <linux/power/bq27xxx_battery.h>
static DEFINE_IDR(battery_id);
static DEFINE_MUTEX(battery_mutex);
static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data) static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
{ {
struct bq27xxx_device_info *di = data; struct bq27xxx_device_info *di = data;
...@@ -70,19 +73,33 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, ...@@ -70,19 +73,33 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
{ {
struct bq27xxx_device_info *di; struct bq27xxx_device_info *di;
int ret; int ret;
char *name;
int num;
/* Get new ID for the new battery device */
mutex_lock(&battery_mutex);
num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
mutex_unlock(&battery_mutex);
if (num < 0)
return num;
name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
if (!name)
goto err_mem;
di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
if (!di) if (!di)
return -ENOMEM; goto err_mem;
di->id = num;
di->dev = &client->dev; di->dev = &client->dev;
di->chip = id->driver_data; di->chip = id->driver_data;
di->name = id->name; di->name = name;
di->bus.read = bq27xxx_battery_i2c_read; di->bus.read = bq27xxx_battery_i2c_read;
ret = bq27xxx_battery_setup(di); ret = bq27xxx_battery_setup(di);
if (ret) if (ret)
return ret; goto err_failed;
/* Schedule a polling after about 1 min */ /* Schedule a polling after about 1 min */
schedule_delayed_work(&di->work, 60 * HZ); schedule_delayed_work(&di->work, 60 * HZ);
...@@ -103,6 +120,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, ...@@ -103,6 +120,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
} }
return 0; return 0;
err_mem:
ret = -ENOMEM;
err_failed:
mutex_lock(&battery_mutex);
idr_remove(&battery_id, num);
mutex_unlock(&battery_mutex);
return ret;
} }
static int bq27xxx_battery_i2c_remove(struct i2c_client *client) static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
...@@ -111,6 +138,10 @@ static int bq27xxx_battery_i2c_remove(struct i2c_client *client) ...@@ -111,6 +138,10 @@ static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
bq27xxx_battery_teardown(di); bq27xxx_battery_teardown(di);
mutex_lock(&battery_mutex);
idr_remove(&battery_id, di->id);
mutex_unlock(&battery_mutex);
return 0; return 0;
} }
......
...@@ -49,6 +49,7 @@ struct bq27xxx_reg_cache { ...@@ -49,6 +49,7 @@ struct bq27xxx_reg_cache {
struct bq27xxx_device_info { struct bq27xxx_device_info {
struct device *dev; struct device *dev;
int id;
enum bq27xxx_chip chip; enum bq27xxx_chip chip;
const char *name; const char *name;
struct bq27xxx_access_methods bus; struct bq27xxx_access_methods bus;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment