summaryrefslogtreecommitdiffstats
path: root/drivers/power/ltc2941-battery-gauge.c
diff options
context:
space:
mode:
authorLinus Torvalds2015-04-14 00:21:34 +0200
committerLinus Torvalds2015-04-14 00:21:34 +0200
commita21c1ea65615f5323575d84508637a9481ca79c6 (patch)
tree669d5bf3171cc42e82cc8396c61f56a48634313c /drivers/power/ltc2941-battery-gauge.c
parentMerge tag 'regulator-v4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/b... (diff)
parentpower: twl4030_madc_battery: Add missing MODULE_ALIAS (diff)
downloadkernel-qcow2-linux-a21c1ea65615f5323575d84508637a9481ca79c6.tar.gz
kernel-qcow2-linux-a21c1ea65615f5323575d84508637a9481ca79c6.tar.xz
kernel-qcow2-linux-a21c1ea65615f5323575d84508637a9481ca79c6.zip
Merge tag 'for-v4.1' of git://git.infradead.org/battery-2.6
Pull power supply and reset changes from Sebastian Reichel: - new API for safe access of power supply function attrs - devres support for power supply (un)registration - new drivers / chips: - generic syscon based poweroff driver - iio & charger driver for da9150 - fuel gauge driver for axp288 - bq27x00: add support for bq27510 - bq2415x: add support for bq24157s - twl4030-madc-battery: convert to iio consumer - misc fixes * tag 'for-v4.1' of git://git.infradead.org/battery-2.6: (66 commits) power: twl4030_madc_battery: Add missing MODULE_ALIAS power: twl4030-madc-battery: Convert to iio consumer. dt: power: Add docs for generic SYSCON poweroff driver. power: reset: Add generic SYSCON register mapped poweroff. power: max17042_battery: add missed blank power: max17042_battery: Use reg type instead of chip type power/reset: at91: big endian fixes for atsama5d3x power_supply: charger-manager: Fix dereferencing of ERR_PTR HID: input: Fix NULL pointer dereference when power_supply_register fails power: constify of_device_id array power/reset/rmobile-reset.c: Fix !HAS_IOMEM build power_supply: 88pm860x_charger: Fix possible NULL pointer dereference and use of initialized variable arm: mach-pxa: Decrement the power supply's device reference counter mfd: ab8500: Decrement the power supply's device reference counter power_supply: bq2415x_charger: Decrement the power supply's device reference counter power_supply: 88pm860x_charger: Decrement the power supply's device reference counter x86/olpc/xo15/sci: Use newly added power_supply_put API x86/olpc/xo1/sci: Use newly added power_supply_put API power_supply: charger-manager: Decrement the power supply's device reference counter power_supply: Increment power supply use counter when obtaining references ...
Diffstat (limited to 'drivers/power/ltc2941-battery-gauge.c')
-rw-r--r--drivers/power/ltc2941-battery-gauge.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/drivers/power/ltc2941-battery-gauge.c b/drivers/power/ltc2941-battery-gauge.c
index e31c927a6d16..daeb0860736c 100644
--- a/drivers/power/ltc2941-battery-gauge.c
+++ b/drivers/power/ltc2941-battery-gauge.c
@@ -59,7 +59,8 @@ enum ltc294x_reg {
struct ltc294x_info {
struct i2c_client *client; /* I2C Client pointer */
- struct power_supply supply; /* Supply pointer */
+ struct power_supply *supply; /* Supply pointer */
+ struct power_supply_desc supply_desc; /* Supply description */
struct delayed_work work; /* Work scheduler */
int num_regs; /* Number of registers (chip type) */
int id; /* Identifier of ltc294x chip */
@@ -294,8 +295,7 @@ static int ltc294x_get_property(struct power_supply *psy,
enum power_supply_property prop,
union power_supply_propval *val)
{
- struct ltc294x_info *info =
- container_of(psy, struct ltc294x_info, supply);
+ struct ltc294x_info *info = power_supply_get_drvdata(psy);
switch (prop) {
case POWER_SUPPLY_PROP_CHARGE_NOW:
@@ -317,8 +317,7 @@ static int ltc294x_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
- struct ltc294x_info *info =
- container_of(psy, struct ltc294x_info, supply);
+ struct ltc294x_info *info = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_NOW:
@@ -345,7 +344,7 @@ static void ltc294x_update(struct ltc294x_info *info)
if (charge != info->charge) {
info->charge = charge;
- power_supply_changed(&info->supply);
+ power_supply_changed(info->supply);
}
}
@@ -371,8 +370,8 @@ static int ltc294x_i2c_remove(struct i2c_client *client)
struct ltc294x_info *info = i2c_get_clientdata(client);
cancel_delayed_work(&info->work);
- power_supply_unregister(&info->supply);
- kfree(info->supply.name);
+ power_supply_unregister(info->supply);
+ kfree(info->supply_desc.name);
mutex_lock(&ltc294x_lock);
idr_remove(&ltc294x_id, info->id);
mutex_unlock(&ltc294x_lock);
@@ -382,6 +381,7 @@ static int ltc294x_i2c_remove(struct i2c_client *client)
static int ltc294x_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct power_supply_config psy_cfg = {};
struct ltc294x_info *info;
int ret;
int num;
@@ -406,8 +406,9 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
i2c_set_clientdata(client, info);
info->num_regs = id->driver_data;
- info->supply.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num);
- if (!info->supply.name) {
+ info->supply_desc.name = kasprintf(GFP_KERNEL, "%s-%d", client->name,
+ num);
+ if (!info->supply_desc.name) {
ret = -ENOMEM;
goto fail_name;
}
@@ -440,30 +441,32 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
} else {
if (prescaler_exp > LTC2941_MAX_PRESCALER_EXP)
prescaler_exp = LTC2941_MAX_PRESCALER_EXP;
- info->Qlsb = ((58 * 50000) / r_sense) /
+ info->Qlsb = ((85 * 50000) / r_sense) /
(128 / (1 << prescaler_exp));
}
info->client = client;
info->id = num;
- info->supply.type = POWER_SUPPLY_TYPE_BATTERY;
- info->supply.properties = ltc294x_properties;
+ info->supply_desc.type = POWER_SUPPLY_TYPE_BATTERY;
+ info->supply_desc.properties = ltc294x_properties;
if (info->num_regs >= LTC294X_REG_TEMPERATURE_LSB)
- info->supply.num_properties =
+ info->supply_desc.num_properties =
ARRAY_SIZE(ltc294x_properties);
else if (info->num_regs >= LTC294X_REG_CURRENT_LSB)
- info->supply.num_properties =
+ info->supply_desc.num_properties =
ARRAY_SIZE(ltc294x_properties) - 1;
else if (info->num_regs >= LTC294X_REG_VOLTAGE_LSB)
- info->supply.num_properties =
+ info->supply_desc.num_properties =
ARRAY_SIZE(ltc294x_properties) - 2;
else
- info->supply.num_properties =
+ info->supply_desc.num_properties =
ARRAY_SIZE(ltc294x_properties) - 3;
- info->supply.get_property = ltc294x_get_property;
- info->supply.set_property = ltc294x_set_property;
- info->supply.property_is_writeable = ltc294x_property_is_writeable;
- info->supply.external_power_changed = NULL;
+ info->supply_desc.get_property = ltc294x_get_property;
+ info->supply_desc.set_property = ltc294x_set_property;
+ info->supply_desc.property_is_writeable = ltc294x_property_is_writeable;
+ info->supply_desc.external_power_changed = NULL;
+
+ psy_cfg.drv_data = info;
INIT_DELAYED_WORK(&info->work, ltc294x_work);
@@ -473,9 +476,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
goto fail_comm;
}
- ret = power_supply_register(&client->dev, &info->supply);
- if (ret) {
+ info->supply = power_supply_register(&client->dev, &info->supply_desc,
+ &psy_cfg);
+ if (IS_ERR(info->supply)) {
dev_err(&client->dev, "failed to register ltc2941\n");
+ ret = PTR_ERR(info->supply);
goto fail_register;
} else {
schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
@@ -484,7 +489,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
return 0;
fail_register:
- kfree(info->supply.name);
+ kfree(info->supply_desc.name);
fail_comm:
fail_name:
fail_info: