Commit 297d716f authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Sebastian Reichel

power_supply: Change ownership from driver to core

Change the ownership of power_supply structure from each driver
implementing the class to the power supply core.

The patch changes power_supply_register() function thus all drivers
implementing power supply class are adjusted.

Each driver provides the implementation of power supply. However it
should not be the owner of power supply class instance because it is
exposed by core to other subsystems with power_supply_get_by_name().
These other subsystems have no knowledge when the driver will unregister
the power supply. This leads to several issues when driver is unbound -
mostly because user of power supply accesses freed memory.

Instead let the core own the instance of struct 'power_supply'.  Other
users of this power supply will still access valid memory because it
will be freed when device reference count reaches 0. Currently this
means "it will leak" but power_supply_put() call in next patches will
solve it.

This solves invalid memory references in following race condition
scenario:

Thread 1: charger manager
Thread 2: power supply driver, used by charger manager

THREAD 1 (charger manager)         THREAD 2 (power supply driver)
==========================         ==============================
psy = power_supply_get_by_name()
                                   Driver unbind, .remove
                                     power_supply_unregister()
                                     Device fully removed
psy->get_property()

The 'get_property' call is executed in invalid context because the driver was
unbound and struct 'power_supply' memory was freed.

This could be observed easily with charger manager driver (here compiled
with max17040 fuel gauge):

$ cat /sys/devices/virtual/power_supply/cm-battery/capacity &
$ echo "1-0036" > /sys/bus/i2c/drivers/max17040/unbind
[   55.725123] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[   55.732584] pgd = d98d4000
[   55.734060] [00000000] *pgd=5afa2831, *pte=00000000, *ppte=00000000
[   55.740318] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
[   55.746210] Modules linked in:
[   55.749259] CPU: 1 PID: 2936 Comm: cat Tainted: G        W       3.19.0-rc1-next-20141226-00048-gf79f475f3c44-dirty #1496
[   55.760190] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[   55.766270] task: d9b76f00 ti: daf54000 task.ti: daf54000
[   55.771647] PC is at 0x0
[   55.774182] LR is at charger_get_property+0x2f4/0x36c
[   55.779201] pc : [<00000000>]    lr : [<c034b0b4>]    psr: 60000013
[   55.779201] sp : daf55e90  ip : 00000003  fp : 00000000
[   55.790657] r10: 00000000  r9 : c06e2878  r8 : d9b26c68
[   55.795865] r7 : dad81610  r6 : daec7410  r5 : daf55ebc  r4 : 00000000
[   55.802367] r3 : 00000000  r2 : daf55ebc  r1 : 0000002a  r0 : d9b26c68
[   55.808879] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[   55.815994] Control: 10c5387d  Table: 598d406a  DAC: 00000015
[   55.821723] Process cat (pid: 2936, stack limit = 0xdaf54210)
[   55.827451] Stack: (0xdaf55e90 to 0xdaf56000)
[   55.831795] 5e80:                                     60000013 c01459c4 0000002a c06f8ef8
[   55.839956] 5ea0: db651000 c06f8ef8 daebac00 c04cb668 daebac08 c0346864 00000000 c01459c4
[   55.848115] 5ec0: d99eaa80 c06f8ef8 00000fff 00001000 db651000 c027f25c c027f240 d99eaa80
[   55.856274] 5ee0: d9a06c00 c0146218 daf55f18 00001000 d99eaa80 db4c18c0 00000001 00000001
[   55.864468] 5f00: daf55f80 c0144c78 c0144c54 c0107f90 00015000 d99eaab0 00000000 00000000
[   55.872603] 5f20: 000051c7 00000000 db4c18c0 c04a9370 00015000 00001000 daf55f80 00001000
[   55.880763] 5f40: daf54000 00015000 00000000 c00e53dc db4c18c0 c00e548c 0000000d 00008124
[   55.888937] 5f60: 00000001 00000000 00000000 db4c18c0 db4c18c0 00001000 00015000 c00e5550
[   55.897099] 5f80: 00000000 00000000 00001000 00001000 00015000 00000003 00000003 c000f364
[   55.905239] 5fa0: 00000000 c000f1a0 00001000 00015000 00000003 00015000 00001000 0001333c
[   55.913399] 5fc0: 00001000 00015000 00000003 00000003 00000002 00000000 00000000 00000000
[   55.921560] 5fe0: 7fffe000 be999850 0000a225 b6f3c19c 60000010 00000003 00000000 00000000
[   55.929744] [<c034b0b4>] (charger_get_property) from [<c0346864>] (power_supply_show_property+0x48/0x20c)
[   55.939286] [<c0346864>] (power_supply_show_property) from [<c027f25c>] (dev_attr_show+0x1c/0x48)
[   55.948130] [<c027f25c>] (dev_attr_show) from [<c0146218>] (sysfs_kf_seq_show+0x84/0x104)
[   55.956298] [<c0146218>] (sysfs_kf_seq_show) from [<c0144c78>] (kernfs_seq_show+0x24/0x28)
[   55.964536] [<c0144c78>] (kernfs_seq_show) from [<c0107f90>] (seq_read+0x1b0/0x484)
[   55.972172] [<c0107f90>] (seq_read) from [<c00e53dc>] (__vfs_read+0x18/0x4c)
[   55.979188] [<c00e53dc>] (__vfs_read) from [<c00e548c>] (vfs_read+0x7c/0x100)
[   55.986304] [<c00e548c>] (vfs_read) from [<c00e5550>] (SyS_read+0x40/0x8c)
[   55.993164] [<c00e5550>] (SyS_read) from [<c000f1a0>] (ret_fast_syscall+0x0/0x48)
[   56.000626] Code: bad PC value
[   56.011652] ---[ end trace 7b64343fbdae8ef1 ]---
Signed-off-by: default avatarKrzysztof Kozlowski <k.kozlowski@samsung.com>
Reviewed-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>

[for the nvec part]
Reviewed-by: default avatarMarc Dietrich <marvin24@gmx.de>

[for compal-laptop.c]
Acked-by: default avatarDarren Hart <dvhart@linux.intel.com>

[for the mfd part]
Acked-by: default avatarLee Jones <lee.jones@linaro.org>

[for the hid part]
Acked-by: default avatarJiri Kosina <jkosina@suse.cz>

[for the acpi part]
Acked-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent b70229bc
......@@ -61,7 +61,7 @@ static void battery_status_changed(void)
if (psy) {
power_supply_changed(psy);
put_device(psy->dev);
put_device(&psy->dev);
}
}
......@@ -71,7 +71,7 @@ static void ac_status_changed(void)
if (psy) {
power_supply_changed(psy);
put_device(psy->dev);
put_device(&psy->dev);
}
}
......
......@@ -83,7 +83,7 @@ static void battery_status_changed(void)
if (psy) {
power_supply_changed(psy);
put_device(psy->dev);
put_device(&psy->dev);
}
}
......@@ -93,7 +93,7 @@ static void ac_status_changed(void)
if (psy) {
power_supply_changed(psy);
put_device(psy->dev);
put_device(&psy->dev);
}
}
......
......@@ -95,13 +95,14 @@ static struct acpi_driver acpi_ac_driver = {
};
struct acpi_ac {
struct power_supply charger;
struct power_supply *charger;
struct power_supply_desc charger_desc;
struct acpi_device * device;
unsigned long long state;
struct notifier_block battery_nb;
};
#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)
#define to_acpi_ac(x) power_supply_get_drvdata(x)
#ifdef CONFIG_ACPI_PROCFS_POWER
static const struct file_operations acpi_ac_fops = {
......@@ -275,7 +276,7 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event)
dev_name(&device->dev), event,
(u32) ac->state);
acpi_notifier_call_chain(device, event, (u32) ac->state);
kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
}
return;
......@@ -321,6 +322,7 @@ static struct dmi_system_id ac_dmi_table[] = {
static int acpi_ac_add(struct acpi_device *device)
{
struct power_supply_config psy_cfg = {};
int result = 0;
struct acpi_ac *ac = NULL;
......@@ -341,19 +343,24 @@ static int acpi_ac_add(struct acpi_device *device)
if (result)
goto end;
ac->charger.name = acpi_device_bid(device);
psy_cfg.drv_data = ac;
ac->charger_desc.name = acpi_device_bid(device);
#ifdef CONFIG_ACPI_PROCFS_POWER
result = acpi_ac_add_fs(ac);
if (result)
goto end;
#endif
ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
ac->charger.properties = ac_props;
ac->charger.num_properties = ARRAY_SIZE(ac_props);
ac->charger.get_property = get_ac_property;
result = power_supply_register(&ac->device->dev, &ac->charger, NULL);
if (result)
ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
ac->charger_desc.properties = ac_props;
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
ac->charger_desc.get_property = get_ac_property;
ac->charger = power_supply_register(&ac->device->dev,
&ac->charger_desc, &psy_cfg);
if (IS_ERR(ac->charger)) {
result = PTR_ERR(ac->charger);
goto end;
}
printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
acpi_device_name(device), acpi_device_bid(device),
......@@ -390,7 +397,7 @@ static int acpi_ac_resume(struct device *dev)
if (acpi_ac_get_state(ac))
return 0;
if (old_state != ac->state)
kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
return 0;
}
#else
......@@ -407,8 +414,7 @@ static int acpi_ac_remove(struct acpi_device *device)
ac = acpi_driver_data(device);
if (ac->charger.dev)
power_supply_unregister(&ac->charger);
power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);
#ifdef CONFIG_ACPI_PROCFS_POWER
......
......@@ -117,7 +117,8 @@ enum {
struct acpi_battery {
struct mutex lock;
struct mutex sysfs_lock;
struct power_supply bat;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct acpi_device *device;
struct notifier_block pm_nb;
unsigned long update_time;
......@@ -149,7 +150,7 @@ struct acpi_battery {
unsigned long flags;
};
#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat)
#define to_acpi_battery(x) power_supply_get_drvdata(x)
static inline int acpi_battery_present(struct acpi_battery *battery)
{
......@@ -608,41 +609,45 @@ static struct device_attribute alarm_attr = {
static int sysfs_add_battery(struct acpi_battery *battery)
{
int result;
struct power_supply_config psy_cfg = { .drv_data = battery, };
if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) {
battery->bat.properties = charge_battery_props;
battery->bat.num_properties =
battery->bat_desc.properties = charge_battery_props;
battery->bat_desc.num_properties =
ARRAY_SIZE(charge_battery_props);
} else {
battery->bat.properties = energy_battery_props;
battery->bat.num_properties =
battery->bat_desc.properties = energy_battery_props;
battery->bat_desc.num_properties =
ARRAY_SIZE(energy_battery_props);
}
battery->bat.name = acpi_device_bid(battery->device);
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
battery->bat.get_property = acpi_battery_get_property;
battery->bat_desc.name = acpi_device_bid(battery->device);
battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
battery->bat_desc.get_property = acpi_battery_get_property;
result = power_supply_register_no_ws(&battery->device->dev,
&battery->bat, NULL);
battery->bat = power_supply_register_no_ws(&battery->device->dev,
&battery->bat_desc, &psy_cfg);
if (result)
if (IS_ERR(battery->bat)) {
int result = PTR_ERR(battery->bat);
battery->bat = NULL;
return result;
return device_create_file(battery->bat.dev, &alarm_attr);
}
return device_create_file(&battery->bat->dev, &alarm_attr);
}
static void sysfs_remove_battery(struct acpi_battery *battery)
{
mutex_lock(&battery->sysfs_lock);
if (!battery->bat.dev) {
if (!battery->bat) {
mutex_unlock(&battery->sysfs_lock);
return;
}
device_remove_file(battery->bat.dev, &alarm_attr);
power_supply_unregister(&battery->bat);
battery->bat.dev = NULL;
device_remove_file(&battery->bat->dev, &alarm_attr);
power_supply_unregister(battery->bat);
battery->bat = NULL;
mutex_unlock(&battery->sysfs_lock);
}
......@@ -739,7 +744,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
return result;
acpi_battery_init_alarm(battery);
}
if (!battery->bat.dev) {
if (!battery->bat) {
result = sysfs_add_battery(battery);
if (result)
return result;
......@@ -765,7 +770,7 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
{
int power_unit;
if (!battery->bat.dev)
if (!battery->bat)
return;
power_unit = battery->power_unit;
......@@ -1063,11 +1068,11 @@ static void acpi_battery_remove_fs(struct acpi_device *device)
static void acpi_battery_notify(struct acpi_device *device, u32 event)
{
struct acpi_battery *battery = acpi_driver_data(device);
struct device *old;
struct power_supply *old;
if (!battery)
return;
old = battery->bat.dev;
old = battery->bat;
/*
* On Acer Aspire V5-573G notifications are sometimes triggered too
* early. For example, when AC is unplugged and notification is
......@@ -1084,8 +1089,8 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event)
acpi_battery_present(battery));
acpi_notifier_call_chain(device, event, acpi_battery_present(battery));
/* acpi_battery_update could remove power_supply object */
if (old && battery->bat.dev)
power_supply_changed(&battery->bat);
if (old && battery->bat)
power_supply_changed(battery->bat);
}
static int battery_notify(struct notifier_block *nb,
......@@ -1101,7 +1106,7 @@ static int battery_notify(struct notifier_block *nb,
if (!acpi_battery_present(battery))
return 0;
if (!battery->bat.dev) {
if (battery->bat) {
result = acpi_battery_get_info(battery);
if (result)
return result;
......
......@@ -74,7 +74,8 @@ static const struct acpi_device_id sbs_device_ids[] = {
MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
struct acpi_battery {
struct power_supply bat;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct acpi_sbs *sbs;
unsigned long update_time;
char name[8];
......@@ -101,10 +102,10 @@ struct acpi_battery {
u8 have_sysfs_alarm:1;
};
#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat)
#define to_acpi_battery(x) power_supply_get_drvdata(x)
struct acpi_sbs {
struct power_supply charger;
struct power_supply *charger;
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
......@@ -115,7 +116,7 @@ struct acpi_sbs {
u8 charger_exists:1;
};
#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger)
#define to_acpi_sbs(x) power_supply_get_drvdata(x)
static int acpi_sbs_remove(struct acpi_device *device);
static int acpi_battery_get_state(struct acpi_battery *battery);
......@@ -303,6 +304,13 @@ static enum power_supply_property sbs_energy_battery_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
};
static const struct power_supply_desc acpi_sbs_charger_desc = {
.name = "sbs-charger",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = sbs_ac_props,
.num_properties = ARRAY_SIZE(sbs_ac_props),
.get_property = sbs_get_ac_property,
};
/* --------------------------------------------------------------------------
Smart Battery System Management
......@@ -519,6 +527,7 @@ static int acpi_battery_read(struct acpi_battery *battery)
static int acpi_battery_add(struct acpi_sbs *sbs, int id)
{
struct acpi_battery *battery = &sbs->battery[id];
struct power_supply_config psy_cfg = { .drv_data = battery, };
int result;
battery->id = id;
......@@ -528,23 +537,27 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
return result;
sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
battery->bat.name = battery->name;
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
battery->bat_desc.name = battery->name;
battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
if (!acpi_battery_mode(battery)) {
battery->bat.properties = sbs_charge_battery_props;
battery->bat.num_properties =
battery->bat_desc.properties = sbs_charge_battery_props;
battery->bat_desc.num_properties =
ARRAY_SIZE(sbs_charge_battery_props);
} else {
battery->bat.properties = sbs_energy_battery_props;
battery->bat.num_properties =
battery->bat_desc.properties = sbs_energy_battery_props;
battery->bat_desc.num_properties =
ARRAY_SIZE(sbs_energy_battery_props);
}
battery->bat.get_property = acpi_sbs_battery_get_property;
result = power_supply_register(&sbs->device->dev, &battery->bat, NULL);
if (result)
battery->bat_desc.get_property = acpi_sbs_battery_get_property;
battery->bat = power_supply_register(&sbs->device->dev,
&battery->bat_desc, &psy_cfg);
if (IS_ERR(battery->bat)) {
result = PTR_ERR(battery->bat);
battery->bat = NULL;
goto end;
}
result = device_create_file(battery->bat.dev, &alarm_attr);
result = device_create_file(&battery->bat->dev, &alarm_attr);
if (result)
goto end;
battery->have_sysfs_alarm = 1;
......@@ -559,28 +572,29 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
{
struct acpi_battery *battery = &sbs->battery[id];
if (battery->bat.dev) {
if (battery->bat) {
if (battery->have_sysfs_alarm)
device_remove_file(battery->bat.dev, &alarm_attr);
power_supply_unregister(&battery->bat);
device_remove_file(&battery->bat->dev, &alarm_attr);
power_supply_unregister(battery->bat);
}
}
static int acpi_charger_add(struct acpi_sbs *sbs)
{
int result;
struct power_supply_config psy_cfg = { .drv_data = sbs, };
result = acpi_ac_get_present(sbs);
if (result)
goto end;
sbs->charger_exists = 1;
sbs->charger.name = "sbs-charger";
sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
sbs->charger.properties = sbs_ac_props;
sbs->charger.num_properties = ARRAY_SIZE(sbs_ac_props);
sbs->charger.get_property = sbs_get_ac_property;
power_supply_register(&sbs->device->dev, &sbs->charger, NULL);
sbs->charger = power_supply_register(&sbs->device->dev,
&acpi_sbs_charger_desc, &psy_cfg);
if (IS_ERR(sbs->charger)) {
result = PTR_ERR(sbs->charger);
sbs->charger = NULL;
}
printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");
......@@ -590,8 +604,8 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
static void acpi_charger_remove(struct acpi_sbs *sbs)
{
if (sbs->charger.dev)
power_supply_unregister(&sbs->charger);
if (sbs->charger)
power_supply_unregister(sbs->charger);
}
static void acpi_sbs_callback(void *context)
......@@ -605,7 +619,7 @@ static void acpi_sbs_callback(void *context)
if (sbs->charger_exists) {
acpi_ac_get_present(sbs);
if (sbs->charger_present != saved_charger_state)
kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE);
kobject_uevent(&sbs->charger->dev.kobj, KOBJ_CHANGE);
}
if (sbs->manager_present) {
......@@ -617,7 +631,7 @@ static void acpi_sbs_callback(void *context)
acpi_battery_read(bat);
if (saved_battery_state == bat->present)
continue;
kobject_uevent(&bat->bat.dev->kobj, KOBJ_CHANGE);
kobject_uevent(&bat->bat->dev.kobj, KOBJ_CHANGE);
}
}
}
......
......@@ -339,7 +339,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
enum power_supply_property prop,
union power_supply_propval *val)
{
struct hid_device *dev = container_of(psy, struct hid_device, battery);
struct hid_device *dev = power_supply_get_drvdata(psy);
int ret = 0;
__u8 *buf;
......@@ -397,26 +397,32 @@ static int hidinput_get_battery_property(struct power_supply *psy,
static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field)
{
struct power_supply *battery = &dev->battery;
int ret;
struct power_supply_desc *psy_desc = NULL;
struct power_supply_config psy_cfg = { .drv_data = dev, };
unsigned quirks;
s32 min, max;
if (field->usage->hid != HID_DC_BATTERYSTRENGTH)
return false; /* no match */
if (battery->name != NULL)
if (dev->battery != NULL)
goto out; /* already initialized? */
battery->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);
if (battery->name == NULL)
psy_desc = kzalloc(sizeof(*psy_desc), GFP_KERNEL);
if (psy_desc == NULL)
goto out;
battery->type = POWER_SUPPLY_TYPE_BATTERY;
battery->properties = hidinput_battery_props;
battery->num_properties = ARRAY_SIZE(hidinput_battery_props);
battery->use_for_apm = 0;
battery->get_property = hidinput_get_battery_property;
psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);
if (psy_desc->name == NULL) {
kfree(psy_desc);
goto out;
}
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->properties = hidinput_battery_props;
psy_desc->num_properties = ARRAY_SIZE(hidinput_battery_props);
psy_desc->use_for_apm = 0;
psy_desc->get_property = hidinput_get_battery_property;
quirks = find_battery_quirk(dev);
......@@ -439,14 +445,16 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
dev->battery_report_type = report_type;
dev->battery_report_id = field->report->id;
ret = power_supply_register(&dev->dev, battery, NULL);
if (ret != 0) {
hid_warn(dev, "can't register power supply: %d\n", ret);
kfree(battery->name);
battery->name = NULL;
dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
if (IS_ERR(dev->battery)) {
hid_warn(dev, "can't register power supply: %ld\n",
PTR_ERR(dev->battery));
kfree(psy_desc->name);
kfree(psy_desc);
dev->battery = NULL;
}
power_supply_powers(battery, &dev->dev);
power_supply_powers(dev->battery, &dev->dev);
out:
return true;
......@@ -454,12 +462,13 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
static void hidinput_cleanup_battery(struct hid_device *dev)
{
if (!dev->battery.name)
if (!dev->battery)
return;
power_supply_unregister(&dev->battery);
kfree(dev->battery.name);
dev->battery.name = NULL;
power_supply_unregister(dev->battery);
kfree(dev->battery->desc->name);
kfree(dev->battery->desc);
dev->battery = NULL;
}
#else /* !CONFIG_HID_BATTERY_STRENGTH */
static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
......
......@@ -815,7 +815,8 @@ struct sony_sc {
struct led_classdev *leds[MAX_LEDS];
unsigned long quirks;
struct work_struct state_worker;
struct power_supply battery;
struct power_supply *battery;
struct power_supply_desc battery_desc;
int device_id;
__u8 *output_report_dmabuf;
......@@ -1660,7 +1661,7 @@ static int sony_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct sony_sc *sc = container_of(psy, struct sony_sc, battery);
struct sony_sc *sc = power_supply_get_drvdata(psy);
unsigned long flags;
int ret = 0;
u8 battery_charging, battery_capacity, cable_state;
......@@ -1699,6 +1700,7 @@ static int sony_battery_get_property(struct power_supply *psy,
static int sony_battery_probe(struct sony_sc *sc)
{
struct power_supply_config psy_cfg = { .drv_data = sc, };
struct hid_device *hdev = sc->hdev;
int ret;
......@@ -1708,39 +1710,42 @@ static int sony_battery_probe(struct sony_sc *sc)
*/
sc->battery_capacity = 100;
sc->battery.properties = sony_battery_props;
sc->battery.num_properties = ARRAY_SIZE(sony_battery_props);
sc->battery.get_property = sony_battery_get_property;
sc->battery.type = POWER_SUPPLY_TYPE_BATTERY;
sc->battery.use_for_apm = 0;
sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%pMR",
sc->mac_address);
if (!sc->battery.name)
sc->battery_desc.properties = sony_battery_props;
sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);
sc->battery_desc.get_property = sony_battery_get_property;
sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
sc->battery_desc.use_for_apm = 0;
sc->battery_desc.name = kasprintf(GFP_KERNEL,
"sony_controller_battery_%pMR",
sc->mac_address);
if (!sc->battery_desc.name)
return -ENOMEM;
ret = power_supply_register(&hdev->dev, &sc->battery, NULL);
if (ret) {
sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc,
&psy_cfg);
if (IS_ERR(sc->battery)) {
ret = PTR_ERR(sc->battery);
hid_err(hdev, "Unable to register battery device\n");
goto err_free;
}
power_supply_powers(&sc->battery, &hdev->dev);
power_supply_powers(sc->battery, &hdev->dev);
return 0;
err_free:
kfree(sc->battery.name);
sc->battery.name = NULL;
kfree(sc->battery_desc.name);
sc->battery_desc.name = NULL;
return ret;
}
static void sony_battery_remove(struct sony_sc *sc)
{
if (!sc->battery.name)
if (!sc->battery_desc.name)
return;
power_supply_unregister(&sc->battery);
kfree(sc->battery.name);
sc->battery.name = NULL;
power_supply_unregister(sc->battery);
kfree(sc->battery_desc.name);
sc->battery_desc.name = NULL;
}
/*
......
......@@ -203,8 +203,7 @@ static int wiimod_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct wiimote_data *wdata = container_of(psy, struct wiimote_data,
battery);
struct wiimote_data *wdata = power_supply_get_drvdata(psy);
int ret = 0, state;
unsigned long flags;
......@@ -238,42 +237,46 @@ static int wiimod_battery_get_property(struct power_supply *psy,
static int wiimod_battery_probe(const struct wiimod_ops *ops,
struct wiimote_data *wdata)
{
struct power_supply_config psy_cfg = { .drv_data = wdata, };
int ret;
wdata->battery.properties = wiimod_battery_props;
wdata->battery.num_properties = ARRAY_SIZE(wiimod_battery_props);
wdata->battery.get_property = wiimod_battery_get_property;
wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
wdata->battery.use_for_apm = 0;
wdata->battery.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",
wdata->hdev->uniq);
if (!wdata->battery.name)
wdata->battery_desc.properties = wiimod_battery_props;
wdata->battery_desc.num_properties = ARRAY_SIZE(wiimod_battery_props);
wdata->battery_desc.get_property = wiimod_battery_get_property;
wdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
wdata->battery_desc.use_for_apm = 0;
wdata->battery_desc.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",
wdata->hdev->uniq);
if (!wdata->battery_desc.name)
return -ENOMEM;
ret = power_supply_register(&wdata->hdev->dev, &wdata->battery, NULL);
if (ret) {
wdata->battery = power_supply_register(&wdata->hdev->dev,
&wdata->battery_desc,
&psy_cfg);
if (IS_ERR(wdata->battery)) {
hid_err(wdata->hdev, "cannot register battery device\n");
ret = PTR_ERR(wdata->battery);
goto err_free;
}
power_supply_powers(&wdata->battery, &wdata->hdev->dev);
power_supply_powers(wdata->battery, &wdata->hdev->dev);
return 0;
err_free:
kfree(wdata->battery.name);
wdata->battery.name = NULL;
kfree(wdata->battery_desc.name);
wdata->battery_desc.name = NULL;
return ret;
}
static void wiimod_battery_remove(const struct wiimod_ops *ops,
struct wiimote_data *wdata)
{
if (!wdata->battery.name)
if (!wdata->battery_desc.name)
return;
power_supply_unregister(&wdata->battery);
kfree(wdata->battery.name);
wdata->battery.name = NULL;
power_supply_unregister(wdata->battery);
kfree(wdata->battery_desc.name);
wdata->battery_desc.name = NULL;
}
static const struct wiimod_ops wiimod_battery = {
......
......@@ -147,7 +147,8 @@ struct wiimote_data {
struct led_classdev *leds[4];
struct input_dev *accel;
struct input_dev *ir;
struct power_supply battery;
struct power_supply *battery;
struct power_supply_desc battery_desc;
struct input_dev *mp;
struct timer_list timer;
struct wiimote_debug *debug;
......
......@@ -119,8 +119,10 @@ struct wacom {
u8 img_lum; /* OLED matrix display brightness */
} led;
bool led_initialized;
struct power_supply battery;
struct power_supply ac;
struct power_supply *battery;
struct power_supply *ac;
struct power_supply_desc battery_desc;
struct power_supply_desc ac_desc;
};
static inline void wacom_schedule_work(struct wacom_wac *wacom_wac)
......@@ -133,7 +135,7 @@ static inline void wacom_notify_battery(struct wacom_wac *wacom_wac)
{
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
power_supply_changed(&wacom->battery);
power_supply_changed(wacom->battery);
}
extern const struct hid_device_id wacom_ids[];
......
......@@ -944,7 +944,7 @@ static int wacom_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct wacom *wacom = container_of(psy, struct wacom, battery);
struct wacom *wacom = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
......@@ -976,7 +976,7 @@ static int wacom_ac_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct wacom *wacom = container_of(psy, struct wacom, ac);
struct wacom *wacom = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
......@@ -998,43 +998,46 @@ static int wacom_ac_get_property(struct power_supply *psy,
static int wacom_initialize_battery(struct wacom *wacom)
{
static atomic_t battery_no = ATOMIC_INIT(0);
int error;
struct power_supply_config psy_cfg = { .drv_data = wacom, };
unsigned long n;
if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
struct power_supply_desc *bat_desc = &wacom->battery_desc;
struct power_supply_desc *ac_desc = &wacom->ac_desc;
n = atomic_inc_return(&battery_no) - 1;
wacom->battery.properties = wacom_battery_props;
wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
wacom->battery.get_property = wacom_battery_get_property;
bat_desc->properties = wacom_battery_props;
bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
bat_desc->get_property = wacom_battery_get_property;
sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
wacom->battery.name = wacom->wacom_wac.bat_name;
wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
wacom->battery.use_for_apm = 0;
bat_desc->name = wacom->wacom_wac.bat_name;
bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
bat_desc->use_for_apm = 0;
wacom->ac.properties = wacom_ac_props;
wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
wacom->ac.get_property = wacom_ac_get_property;
ac_desc->properties = wacom_ac_props;
ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
ac_desc->get_property = wacom_ac_get_property;
sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
wacom->ac.name = wacom->wacom_wac.ac_name;
wacom->ac.type = POWER_SUPPLY_TYPE_MAINS;
wacom->ac.use_for_apm = 0;
error = power_supply_register(&wacom->hdev->dev,
&wacom->battery, NULL);
if (error)
return error;
power_supply_powers(&wacom->battery, &wacom->hdev->dev);
error = power_supply_register(&wacom->hdev->dev, &wacom->ac,
NULL);
if (error) {
power_supply_unregister(&wacom->battery);
return error;
ac_desc->name = wacom->wacom_wac.ac_name;
ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
ac_desc->use_for_apm = 0;
wacom->battery = power_supply_register(&wacom->hdev->dev,
&wacom->battery_desc, &psy_cfg);
if (IS_ERR(wacom->battery))
return PTR_ERR(wacom->battery);
power_supply_powers(wacom->battery, &wacom->hdev->dev);
wacom->ac = power_supply_register(&wacom->hdev->dev,
&wacom->ac_desc,
&psy_cfg);
if (IS_ERR(wacom->ac)) {
power_supply_unregister(wacom->battery);
return PTR_ERR(wacom->ac);
}
power_supply_powers(&wacom->ac, &wacom->hdev->dev);
power_supply_powers(wacom->ac, &wacom->hdev->dev);
}
return 0;
......@@ -1043,11 +1046,11 @@ static int wacom_initialize_battery(struct wacom *wacom)
static void wacom_destroy_battery(struct wacom *wacom)
{
if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
wacom->battery.dev) {
power_supply_unregister(&wacom->battery);
wacom->battery.dev = NULL;
power_supply_unregister(&wacom->ac);
wacom->ac.dev = NULL;
wacom->battery) {
power_supply_unregister(wacom->battery);
wacom->battery = NULL;
power_supply_unregister(wacom->ac);
wacom->ac = NULL;
}
}
......
......@@ -177,7 +177,7 @@ struct compal_data{
unsigned char curr_pwm;
/* Power supply */
struct power_supply psy;
struct power_supply *psy;
struct power_supply_info psy_info;
char bat_model_name[BAT_MODEL_NAME_LEN + 1];
char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1];
......@@ -565,8 +565,7 @@ static int bat_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct compal_data *data;
data = container_of(psy, struct compal_data, psy);
struct compal_data *data = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
......@@ -875,13 +874,16 @@ static struct dmi_system_id __initdata compal_dmi_table[] = {
};
MODULE_DEVICE_TABLE(dmi, compal_dmi_table);
static const struct power_supply_desc psy_bat_desc = {
.name = DRIVER_NAME,
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = compal_bat_properties,
.num_properties = ARRAY_SIZE(compal_bat_properties),
.get_property = bat_get_property,
};
static void initialize_power_supply_data(struct compal_data *data)
{
data->psy.name = DRIVER_NAME;
data->psy.type = POWER_SUPPLY_TYPE_BATTERY;
data->psy.properties = compal_bat_properties;
data->psy.num_properties = ARRAY_SIZE(compal_bat_properties);
data->psy.get_property = bat_get_property;
ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR,
data->bat_manufacturer_name,
......@@ -1011,6 +1013,7 @@ static int compal_probe(struct platform_device *pdev)
int err;
struct compal_data *data;
struct device *hwmon_dev;
struct power_supply_config psy_cfg = {};
if (!extra_features)
return 0;
......@@ -1036,9 +1039,13 @@ static int compal_probe(struct platform_device *pdev)
/* Power supply */
initialize_power_supply_data(data);
err = power_supply_register(&compal_device->dev, &data->psy, NULL);
if (err < 0)
psy_cfg.drv_data = data;
data->psy = power_supply_register(&compal_device->dev, &psy_bat_desc,
&psy_cfg);
if (IS_ERR(data->psy)) {
err = PTR_ERR(data->psy);
goto remove;
}
platform_set_drvdata(pdev, data);
......@@ -1073,7 +1080,7 @@ static int compal_remove(struct platform_device *pdev)
pwm_disable_control();
data = platform_get_drvdata(pdev);
power_supply_unregister(&data->psy);
power_supply_unregister(data->psy);
sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);
......
......@@ -98,7 +98,7 @@ struct pm860x_battery_info {
struct i2c_client *i2c;
struct device *dev;
struct power_supply battery;
struct power_supply *battery;
struct mutex lock;
int status;
int irq_cc;
......@@ -798,9 +798,8 @@ static int calc_capacity(struct pm860x_battery_info *info, int *cap)
static void pm860x_external_power_changed(struct power_supply *psy)
{
struct pm860x_battery_info *info;
struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
info = container_of(psy, struct pm860x_battery_info, battery);
calc_resistor(info);
}
......@@ -808,7 +807,7 @@ static int pm860x_batt_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent);
struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
int data;
int ret;
......@@ -874,7 +873,7 @@ static int pm860x_batt_set_prop(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent);
struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_FULL:
......@@ -901,6 +900,16 @@ static enum power_supply_property pm860x_batt_props[] = {
POWER_SUPPLY_PROP_TEMP,
};
static const struct power_supply_desc pm860x_battery_desc = {
.name = "battery-monitor",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = pm860x_batt_props,
.num_properties = ARRAY_SIZE(pm860x_batt_props),
.get_property = pm860x_batt_get_prop,
.set_property = pm860x_batt_set_prop,
.external_power_changed = pm860x_external_power_changed,
};
static int pm860x_battery_probe(struct platform_device *pdev)
{
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
......@@ -936,14 +945,6 @@ static int pm860x_battery_probe(struct platform_device *pdev)
pm860x_init_battery(info);
info->battery.name = "battery-monitor";
info->battery.type = POWER_SUPPLY_TYPE_BATTERY;
info->battery.properties = pm860x_batt_props;
info->battery.num_properties = ARRAY_SIZE(pm860x_batt_props);
info->battery.get_property = pm860x_batt_get_prop;
info->battery.set_property = pm860x_batt_set_prop;
info->battery.external_power_changed = pm860x_external_power_changed;
if (pdata && pdata->max_capacity)
info->max_capacity = pdata->max_capacity;
else
......@@ -953,10 +954,11 @@ static int pm860x_battery_probe(struct platform_device *pdev)
else
info->resistor = 300; /* set default internal resistor */
ret = power_supply_register(&pdev->dev, &info->battery, NULL);
if (ret)
return ret;
info->battery.dev->parent = &pdev->dev;
info->battery = power_supply_register(&pdev->dev, &pm860x_battery_desc,
NULL);
if (IS_ERR(info->battery))
return PTR_ERR(info->battery);
info->battery->dev.parent = &pdev->dev;
ret = request_threaded_irq(info->irq_cc, NULL,
pm860x_coulomb_handler, IRQF_ONESHOT,
......@@ -981,7 +983,7 @@ static int pm860x_battery_probe(struct platform_device *pdev)
out_coulomb:
free_irq(info->irq_cc, info);
out_reg:
power_supply_unregister(&info->battery);
power_supply_unregister(info->battery);
return ret;
}
......@@ -991,7 +993,7 @@ static int pm860x_battery_remove(struct platform_device *pdev)
free_irq(info->irq_batt, info);
free_irq(info->irq_cc, info);
power_supply_unregister(&info->battery);
power_supply_unregister(info->battery);
return 0;
}
......
......@@ -102,7 +102,7 @@ struct pm860x_charger_info {
struct i2c_client *i2c_8606;
struct device *dev;
struct power_supply usb;
struct power_supply *usb;
struct mutex lock;
int irq_nums;
int irq[7];
......@@ -415,7 +415,7 @@ static irqreturn_t pm860x_charger_handler(int irq, void *data)
set_charging_fsm(info);
power_supply_changed(&info->usb);
power_supply_changed(info->usb);
out:
return IRQ_HANDLED;
}
......@@ -587,8 +587,7 @@ static int pm860x_usb_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct pm860x_charger_info *info =
dev_get_drvdata(psy->dev->parent);
struct pm860x_charger_info *info = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
......@@ -648,6 +647,14 @@ static struct pm860x_irq_desc {
{ "vchg", pm860x_vchg_handler },
};
static const struct power_supply_desc pm860x_charger_desc = {
.name = "usb",
.type = POWER_SUPPLY_TYPE_USB,
.properties = pm860x_usb_props,
.num_properties = ARRAY_SIZE(pm860x_usb_props),
.get_property = pm860x_usb_get_prop,
};
static int pm860x_charger_probe(struct platform_device *pdev)
{
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
......@@ -689,16 +696,15 @@ static int pm860x_charger_probe(struct platform_device *pdev)
mutex_init(&info->lock);
platform_set_drvdata(pdev, info);
info->usb.name = "usb";
info->usb.type = POWER_SUPPLY_TYPE_USB;
info->usb.properties = pm860x_usb_props;
info->usb.num_properties = ARRAY_SIZE(pm860x_usb_props);
info->usb.get_property = pm860x_usb_get_prop;
psy_cfg.drv_data = info;
psy_cfg.supplied_to = pm860x_supplied_to;
psy_cfg.num_supplicants = ARRAY_SIZE(pm860x_supplied_to);
ret = power_supply_register(&pdev->dev, &info->usb, &psy_cfg);
if (ret)
info->usb = power_supply_register(&pdev->dev, &pm860x_charger_desc,
&psy_cfg);
if (IS_ERR(info->usb)) {
ret = PTR_ERR(info->usb);
goto out;
}
pm860x_init_charger(info);
......@@ -715,7 +721,7 @@ static int pm860x_charger_probe(struct platform_device *pdev)
return 0;
out_irq:
power_supply_unregister(&info->usb);
power_supply_unregister(info->usb);
while (--i >= 0)
free_irq(info->irq[i], info);
out:
......@@ -727,7 +733,7 @@ static int pm860x_charger_remove(struct platform_device *pdev)
struct pm860x_charger_info *info = platform_get_drvdata(pdev);
int i;
power_supply_unregister(&info->usb);
power_supply_unregister(info->usb);
free_irq(info->irq[0], info);
for (i = 0; i < info->irq_nums; i++)
free_irq(info->irq[i], info);
......
......@@ -45,9 +45,6 @@
#define BTEMP_BATCTRL_CURR_SRC_60UA 60
#define BTEMP_BATCTRL_CURR_SRC_120UA 120
#define to_ab8500_btemp_device_info(x) container_of((x), \
struct ab8500_btemp, btemp_psy);
/**
* struct ab8500_btemp_interrupts - ab8500 interrupts
* @name: name of the interrupt
......@@ -102,7 +99,7 @@ struct ab8500_btemp {
struct ab8500_gpadc *gpadc;
struct ab8500_fg *fg;
struct abx500_bm_data *bm;
struct power_supply btemp_psy;
struct power_supply *btemp_psy;
struct ab8500_btemp_events events;
struct ab8500_btemp_ranges btemp_ranges;
struct workqueue_struct *btemp_wq;
......@@ -654,14 +651,14 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) {
di->initialized = true;
di->bat_temp = bat_temp;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
}
} else if (bat_temp < di->prev_bat_temp) {
di->bat_temp--;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
} else if (bat_temp > di->prev_bat_temp) {
di->bat_temp++;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
}
di->prev_bat_temp = bat_temp;
......@@ -689,7 +686,7 @@ static irqreturn_t ab8500_btemp_batctrlindb_handler(int irq, void *_di)
dev_err(di->dev, "Battery removal detected!\n");
di->events.batt_rem = true;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
return IRQ_HANDLED;
}
......@@ -715,7 +712,7 @@ static irqreturn_t ab8500_btemp_templow_handler(int irq, void *_di)
di->events.btemp_high = false;
di->events.btemp_medhigh = false;
di->events.btemp_lowmed = false;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
}
return IRQ_HANDLED;
......@@ -738,7 +735,7 @@ static irqreturn_t ab8500_btemp_temphigh_handler(int irq, void *_di)
di->events.btemp_medhigh = false;
di->events.btemp_lowmed = false;
di->events.btemp_low = false;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
return IRQ_HANDLED;
}
......@@ -760,7 +757,7 @@ static irqreturn_t ab8500_btemp_lowmed_handler(int irq, void *_di)
di->events.btemp_medhigh = false;
di->events.btemp_high = false;
di->events.btemp_low = false;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
return IRQ_HANDLED;
}
......@@ -782,7 +779,7 @@ static irqreturn_t ab8500_btemp_medhigh_handler(int irq, void *_di)
di->events.btemp_lowmed = false;
di->events.btemp_high = false;
di->events.btemp_low = false;
power_supply_changed(&di->btemp_psy);
power_supply_changed(di->btemp_psy);
return IRQ_HANDLED;
}
......@@ -884,9 +881,7 @@ static int ab8500_btemp_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct ab8500_btemp *di;
di = to_ab8500_btemp_device_info(psy);
struct ab8500_btemp *di = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_PRESENT:
......@@ -919,14 +914,14 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
psy = (struct power_supply *)data;
ext = dev_get_drvdata(dev);
di = to_ab8500_btemp_device_info(psy);
di = power_supply_get_drvdata(psy);
/*
* For all psy where the name of your driver
* appears in any supplied_to
*/
for (i = 0; i < ext->num_supplicants; i++) {
if (!strcmp(ext->supplied_to[i], psy->name))
if (!strcmp(ext->supplied_to[i], psy->desc->name))
psy_found = true;
}
......@@ -934,16 +929,16 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
return 0;
/* Go through all properties for the psy */
for (j = 0; j < ext->num_properties; j++) {
for (j = 0; j < ext->desc->num_properties; j++) {
enum power_supply_property prop;
prop = ext->properties[j];
prop = ext->desc->properties[j];
if (power_supply_get_property(ext, prop, &ret))
continue;
switch (prop) {
case POWER_SUPPLY_PROP_PRESENT:
switch (ext->type) {
switch (ext->desc->type) {
case POWER_SUPPLY_TYPE_MAINS:
/* AC disconnected */
if (!ret.intval && di->events.ac_conn) {
......@@ -990,10 +985,10 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
*/
static void ab8500_btemp_external_power_changed(struct power_supply *psy)
{
struct ab8500_btemp *di = to_ab8500_btemp_device_info(psy);
struct ab8500_btemp *di = power_supply_get_drvdata(psy);
class_for_each_device(power_supply_class, NULL,
&di->btemp_psy, ab8500_btemp_get_ext_psy_data);
di->btemp_psy, ab8500_btemp_get_ext_psy_data);
}
/* ab8500 btemp driver interrupts and their respective isr */
......@@ -1044,7 +1039,7 @@ static int ab8500_btemp_remove(struct platform_device *pdev)
destroy_workqueue(di->btemp_wq);
flush_scheduled_work();
power_supply_unregister(&di->btemp_psy);
power_supply_unregister(di->btemp_psy);
return 0;
}
......@@ -1054,6 +1049,15 @@ static char *supply_interface[] = {
"ab8500_fg",
};
static const struct power_supply_desc ab8500_btemp_desc = {
.name = "ab8500_btemp",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = ab8500_btemp_props,
.num_properties = ARRAY_SIZE(ab8500_btemp_props),
.get_property = ab8500_btemp_get_property,
.external_power_changed = ab8500_btemp_external_power_changed,
};
static int ab8500_btemp_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
......@@ -1090,17 +1094,9 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
di->initialized = false;
/* BTEMP supply */
di->btemp_psy.name = "ab8500_btemp";
di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY;
di->btemp_psy.properties = ab8500_btemp_props;
di->btemp_psy.num_properties = ARRAY_SIZE(ab8500_btemp_props);
di->btemp_psy.get_property = ab8500_btemp_get_property;
di->btemp_psy.external_power_changed =
ab8500_btemp_external_power_changed;
psy_cfg.supplied_to = supply_interface;
psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
psy_cfg.drv_data = di;
/* Create a work queue for the btemp */
di->btemp_wq =
......@@ -1141,9 +1137,11 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
}
/* Register BTEMP power supply class */
ret = power_supply_register(di->dev, &di->btemp_psy, &psy_cfg);
if (ret) {
di->btemp_psy = power_supply_register(di->dev, &ab8500_btemp_desc,
&psy_cfg);
if (IS_ERR(di->btemp_psy)) {
dev_err(di->dev, "failed to register BTEMP psy\n");
ret = PTR_ERR(di->btemp_psy);
goto free_btemp_wq;
}
......@@ -1172,7 +1170,7 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
return ret;
free_irq:
power_supply_unregister(&di->btemp_psy);
power_supply_unregister(di->btemp_psy);
/* We also have to free all successfully registered irqs */
for (i = i - 1; i >= 0; i--) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -48,7 +48,7 @@ static int __find_main_battery(struct device *dev, void *data)
bp->bat = dev_get_drvdata(dev);
if (bp->bat->use_for_apm) {
if (bp->bat->desc->use_for_apm) {
/* nice, we explicitly asked to report this battery. */
bp->main = bp->bat;
return 1;
......
......@@ -127,7 +127,7 @@ struct axp288_fg_info {
struct regmap *regmap;
struct regmap_irq_chip_data *regmap_irqc;
int irq[AXP288_FG_INTR_NUM];
struct power_supply bat;
struct power_supply *bat;
struct mutex lock;
int status;
struct delayed_work status_monitor;
......@@ -588,8 +588,7 @@ static int fuel_gauge_get_property(struct power_supply *ps,
enum power_supply_property prop,
union power_supply_propval *val)
{
struct axp288_fg_info *info = container_of(ps,
struct axp288_fg_info, bat);
struct axp288_fg_info *info = power_supply_get_drvdata(ps);
int ret = 0, value;
mutex_lock(&info->lock);
......@@ -715,8 +714,7 @@ static int fuel_gauge_set_property(struct power_supply *ps,
enum power_supply_property prop,
const union power_supply_propval *val)
{
struct axp288_fg_info *info = container_of(ps,
struct axp288_fg_info, bat);
struct axp288_fg_info *info = power_supply_get_drvdata(ps);
int ret = 0;
mutex_lock(&info->lock);
......@@ -798,7 +796,7 @@ static void fuel_gauge_status_monitor(struct work_struct *work)
struct axp288_fg_info, status_monitor.work);
fuel_gauge_get_status(info);
power_supply_changed(&info->bat);
power_supply_changed(info->bat);
schedule_delayed_work(&info->status_monitor, STATUS_MON_DELAY_JIFFIES);
}
......@@ -844,18 +842,28 @@ static irqreturn_t fuel_gauge_thread_handler(int irq, void *dev)
dev_warn(&info->pdev->dev, "Spurious Interrupt!!!\n");
}
power_supply_changed(&info->bat);
power_supply_changed(info->bat);
return IRQ_HANDLED;
}
static void fuel_gauge_external_power_changed(struct power_supply *psy)
{
struct axp288_fg_info *info = container_of(psy,
struct axp288_fg_info, bat);
struct axp288_fg_info *info = power_supply_get_drvdata(psy);
power_supply_changed(&info->bat);
power_supply_changed(info->bat);
}
static const struct power_supply_desc fuel_gauge_desc = {
.name = DEV_NAME,
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = fuel_gauge_props,
.num_properties = ARRAY_SIZE(fuel_gauge_props),
.get_property = fuel_gauge_get_property,
.set_property = fuel_gauge_set_property,
.property_is_writeable = fuel_gauge_property_is_writeable,
.external_power_changed = fuel_gauge_external_power_changed,
};
static int fuel_gauge_set_lowbatt_thresholds(struct axp288_fg_info *info)
{
int ret;
......@@ -1070,9 +1078,10 @@ static void fuel_gauge_init_hw_regs(struct axp288_fg_info *info)
static int axp288_fuel_gauge_probe(struct platform_device *pdev)
{
int ret;
int ret = 0;
struct axp288_fg_info *info;
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
struct power_supply_config psy_cfg = {};
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
if (!info)
......@@ -1091,16 +1100,10 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
mutex_init(&info->lock);
INIT_DELAYED_WORK(&info->status_monitor, fuel_gauge_status_monitor);
info->bat.name = DEV_NAME;
info->bat.type = POWER_SUPPLY_TYPE_BATTERY;
info->bat.properties = fuel_gauge_props;
info->bat.num_properties = ARRAY_SIZE(fuel_gauge_props);
info->bat.get_property = fuel_gauge_get_property;
info->bat.set_property = fuel_gauge_set_property;
info->bat.property_is_writeable = fuel_gauge_property_is_writeable;
info->bat.external_power_changed = fuel_gauge_external_power_changed;
ret = power_supply_register(&pdev->dev, &info->bat, NULL);
if (ret) {
psy_cfg.drv_data = info;
info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg);
if (IS_ERR(info->bat)) {
ret = PTR_ERR(info->bat);
dev_err(&pdev->dev, "failed to register battery: %d\n", ret);
return ret;
}
......@@ -1125,7 +1128,7 @@ static int axp288_fuel_gauge_remove(struct platform_device *pdev)
int i;
cancel_delayed_work_sync(&info->status_monitor);
power_supply_unregister(&info->bat);
power_supply_unregister(info->bat);
fuel_gauge_remove_debugfs(info);
for (i = 0; i < AXP288_FG_INTR_NUM; i++)
......
......@@ -166,7 +166,8 @@ static char *bq2415x_chip_name[] = {
struct bq2415x_device {
struct device *dev;
struct bq2415x_platform_data init_data;
struct power_supply charger;
struct power_supply *charger;
struct power_supply_desc charger_desc;
struct delayed_work work;
struct power_supply *notify_psy;
struct notifier_block nb;
......@@ -784,7 +785,7 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode)
bq2415x_set_default_value(bq, battery_regulation_voltage);
bq->mode = mode;
sysfs_notify(&bq->charger.dev->kobj, NULL, "mode");
sysfs_notify(&bq->charger->dev.kobj, NULL, "mode");
return 0;
......@@ -868,7 +869,7 @@ static void bq2415x_set_autotimer(struct bq2415x_device *bq, int state)
static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg)
{
bq->timer_error = msg;
sysfs_notify(&bq->charger.dev->kobj, NULL, "timer");
sysfs_notify(&bq->charger->dev.kobj, NULL, "timer");
dev_err(bq->dev, "%s\n", msg);
if (bq->automode > 0)
bq->automode = 0;
......@@ -886,7 +887,7 @@ static void bq2415x_timer_work(struct work_struct *work)
int boost;
if (bq->automode > 0 && (bq->reported_mode != bq->mode)) {
sysfs_notify(&bq->charger.dev->kobj, NULL, "reported_mode");
sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode");
bq2415x_set_mode(bq, bq->reported_mode);
}
......@@ -992,8 +993,7 @@ static int bq2415x_power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
int ret;
switch (psp) {
......@@ -1024,12 +1024,14 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
int ret;
int chip;
char revstr[8];
struct power_supply_config psy_cfg = { .drv_data = bq, };
bq->charger.name = bq->name;
bq->charger.type = POWER_SUPPLY_TYPE_USB;
bq->charger.properties = bq2415x_power_supply_props;
bq->charger.num_properties = ARRAY_SIZE(bq2415x_power_supply_props);
bq->charger.get_property = bq2415x_power_supply_get_property;
bq->charger_desc.name = bq->name;
bq->charger_desc.type = POWER_SUPPLY_TYPE_USB;
bq->charger_desc.properties = bq2415x_power_supply_props;
bq->charger_desc.num_properties =
ARRAY_SIZE(bq2415x_power_supply_props);
bq->charger_desc.get_property = bq2415x_power_supply_get_property;
ret = bq2415x_detect_chip(bq);
if (ret < 0)
......@@ -1052,10 +1054,11 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
return -ENOMEM;
}
ret = power_supply_register(bq->dev, &bq->charger, NULL);
if (ret) {
bq->charger = power_supply_register(bq->dev, &bq->charger_desc,
&psy_cfg);
if (IS_ERR(bq->charger)) {
kfree(bq->model);
return ret;
return PTR_ERR(bq->charger);
}
return 0;
......@@ -1067,7 +1070,7 @@ static void bq2415x_power_supply_exit(struct bq2415x_device *bq)
if (bq->automode > 0)
bq->automode = 0;
cancel_delayed_work_sync(&bq->work);
power_supply_unregister(&bq->charger);
power_supply_unregister(bq->charger);
kfree(bq->model);
}
......@@ -1079,8 +1082,7 @@ static ssize_t bq2415x_sysfs_show_status(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
enum bq2415x_command command;
int ret;
......@@ -1113,8 +1115,7 @@ static ssize_t bq2415x_sysfs_set_timer(struct device *dev,
size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
int ret = 0;
if (strncmp(buf, "auto", 4) == 0)
......@@ -1135,8 +1136,7 @@ static ssize_t bq2415x_sysfs_show_timer(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
if (bq->timer_error)
return sprintf(buf, "%s\n", bq->timer_error);
......@@ -1160,8 +1160,7 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
enum bq2415x_mode mode;
int ret = 0;
......@@ -1213,8 +1212,7 @@ static ssize_t bq2415x_sysfs_show_mode(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
ssize_t ret = 0;
if (bq->automode > 0)
......@@ -1251,8 +1249,7 @@ static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
if (bq->automode < 0)
return -EINVAL;
......@@ -1280,8 +1277,7 @@ static ssize_t bq2415x_sysfs_set_registers(struct device *dev,
size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
ssize_t ret = 0;
unsigned int reg;
unsigned int val;
......@@ -1316,8 +1312,7 @@ static ssize_t bq2415x_sysfs_show_registers(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
ssize_t ret = 0;
ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_STATUS, buf+ret);
......@@ -1335,8 +1330,7 @@ static ssize_t bq2415x_sysfs_set_limit(struct device *dev,
size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
long val;
int ret;
......@@ -1367,8 +1361,7 @@ static ssize_t bq2415x_sysfs_show_limit(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
int ret;
if (strcmp(attr->attr.name, "current_limit") == 0)
......@@ -1396,8 +1389,7 @@ static ssize_t bq2415x_sysfs_set_enable(struct device *dev,
size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
enum bq2415x_command command;
long val;
int ret;
......@@ -1432,8 +1424,7 @@ static ssize_t bq2415x_sysfs_show_enable(struct device *dev,
char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq2415x_device *bq = container_of(psy, struct bq2415x_device,
charger);
struct bq2415x_device *bq = power_supply_get_drvdata(psy);
enum bq2415x_command command;
int ret;
......@@ -1524,13 +1515,13 @@ static const struct attribute_group bq2415x_sysfs_attr_group = {
static int bq2415x_sysfs_init(struct bq2415x_device *bq)
{
return sysfs_create_group(&bq->charger.dev->kobj,
return sysfs_create_group(&bq->charger->dev.kobj,
&bq2415x_sysfs_attr_group);
}
static void bq2415x_sysfs_exit(struct bq2415x_device *bq)
{
sysfs_remove_group(&bq->charger.dev->kobj, &bq2415x_sysfs_attr_group);
sysfs_remove_group(&bq->charger->dev.kobj, &bq2415x_sysfs_attr_group);
}
/* main bq2415x probe function */
......
......@@ -152,8 +152,8 @@
struct bq24190_dev_info {
struct i2c_client *client;
struct device *dev;
struct power_supply charger;
struct power_supply battery;
struct power_supply *charger;
struct power_supply *battery;
char model_name[I2C_NAME_SIZE];
kernel_ulong_t model;
unsigned int gpio_int;
......@@ -423,8 +423,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, charger);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
struct bq24190_sysfs_field_info *info;
int ret;
u8 v;
......@@ -444,8 +443,7 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct power_supply *psy = dev_get_drvdata(dev);
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, charger);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
struct bq24190_sysfs_field_info *info;
int ret;
u8 v;
......@@ -469,13 +467,13 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
{
bq24190_sysfs_init_attrs();
return sysfs_create_group(&bdi->charger.dev->kobj,
return sysfs_create_group(&bdi->charger->dev.kobj,
&bq24190_sysfs_attr_group);
}
static void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi)
{
sysfs_remove_group(&bdi->charger.dev->kobj, &bq24190_sysfs_attr_group);
sysfs_remove_group(&bdi->charger->dev.kobj, &bq24190_sysfs_attr_group);
}
#else
static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
......@@ -807,8 +805,7 @@ static int bq24190_charger_set_voltage(struct bq24190_dev_info *bdi,
static int bq24190_charger_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, charger);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
int ret;
dev_dbg(bdi->dev, "prop: %d\n", psp);
......@@ -861,8 +858,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, charger);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
int ret;
dev_dbg(bdi->dev, "prop: %d\n", psp);
......@@ -922,18 +918,15 @@ static char *bq24190_charger_supplied_to[] = {
"main-battery",
};
static void bq24190_charger_init(struct power_supply *charger)
{
charger->name = "bq24190-charger";
charger->type = POWER_SUPPLY_TYPE_USB;
charger->properties = bq24190_charger_properties;
charger->num_properties = ARRAY_SIZE(bq24190_charger_properties);
charger->supplied_to = bq24190_charger_supplied_to;
charger->num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to);
charger->get_property = bq24190_charger_get_property;
charger->set_property = bq24190_charger_set_property;
charger->property_is_writeable = bq24190_charger_property_is_writeable;
}
static const struct power_supply_desc bq24190_charger_desc = {
.name = "bq24190-charger",
.type = POWER_SUPPLY_TYPE_USB,
.properties = bq24190_charger_properties,
.num_properties = ARRAY_SIZE(bq24190_charger_properties),
.get_property = bq24190_charger_get_property,
.set_property = bq24190_charger_set_property,
.property_is_writeable = bq24190_charger_property_is_writeable,
};
/* Battery power supply property routines */
......@@ -1102,8 +1095,7 @@ static int bq24190_battery_set_temp_alert_max(struct bq24190_dev_info *bdi,
static int bq24190_battery_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, battery);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
int ret;
dev_dbg(bdi->dev, "prop: %d\n", psp);
......@@ -1144,8 +1136,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
struct bq24190_dev_info *bdi =
container_of(psy, struct bq24190_dev_info, battery);
struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
int ret;
dev_dbg(bdi->dev, "prop: %d\n", psp);
......@@ -1193,16 +1184,15 @@ static enum power_supply_property bq24190_battery_properties[] = {
POWER_SUPPLY_PROP_SCOPE,
};
static void bq24190_battery_init(struct power_supply *battery)
{
battery->name = "bq24190-battery";
battery->type = POWER_SUPPLY_TYPE_BATTERY;
battery->properties = bq24190_battery_properties;
battery->num_properties = ARRAY_SIZE(bq24190_battery_properties);
battery->get_property = bq24190_battery_get_property;
battery->set_property = bq24190_battery_set_property;
battery->property_is_writeable = bq24190_battery_property_is_writeable;
}
static const struct power_supply_desc bq24190_battery_desc = {
.name = "bq24190-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = bq24190_battery_properties,
.num_properties = ARRAY_SIZE(bq24190_battery_properties),
.get_property = bq24190_battery_get_property,
.set_property = bq24190_battery_set_property,
.property_is_writeable = bq24190_battery_property_is_writeable,
};
static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
{
......@@ -1269,8 +1259,8 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
* interrupt received).
*/
if (alert_userspace && !bdi->first_time) {
power_supply_changed(&bdi->charger);
power_supply_changed(&bdi->battery);
power_supply_changed(bdi->charger);
power_supply_changed(bdi->battery);
bdi->first_time = false;
}
......@@ -1362,6 +1352,7 @@ static int bq24190_probe(struct i2c_client *client,
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct device *dev = &client->dev;
struct bq24190_platform_data *pdata = client->dev.platform_data;
struct power_supply_config charger_cfg = {}, battery_cfg = {};
struct bq24190_dev_info *bdi;
int ret;
......@@ -1416,19 +1407,23 @@ static int bq24190_probe(struct i2c_client *client,
goto out2;
}
bq24190_charger_init(&bdi->charger);
ret = power_supply_register(dev, &bdi->charger, NULL);
if (ret) {
charger_cfg.drv_data = bdi;
charger_cfg.supplied_to = bq24190_charger_supplied_to;
charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to),
bdi->charger = power_supply_register(dev, &bq24190_charger_desc,
&charger_cfg);
if (IS_ERR(bdi->charger)) {
dev_err(dev, "Can't register charger\n");
ret = PTR_ERR(bdi->charger);
goto out2;
}
bq24190_battery_init(&bdi->battery);
ret = power_supply_register(dev, &bdi->battery, NULL);
if (ret) {
battery_cfg.drv_data = bdi;
bdi->battery = power_supply_register(dev, &bq24190_battery_desc,
&battery_cfg);
if (IS_ERR(bdi->battery)) {
dev_err(dev, "Can't register battery\n");
ret = PTR_ERR(bdi->battery);
goto out3;
}
......@@ -1441,9 +1436,9 @@ static int bq24190_probe(struct i2c_client *client,
return 0;
out4:
power_supply_unregister(&bdi->battery);
power_supply_unregister(bdi->battery);
out3:
power_supply_unregister(&bdi->charger);
power_supply_unregister(bdi->charger);
out2:
pm_runtime_disable(dev);
out1:
......@@ -1462,8 +1457,8 @@ static int bq24190_remove(struct i2c_client *client)
pm_runtime_put_sync(bdi->dev);
bq24190_sysfs_remove_group(bdi);
power_supply_unregister(&bdi->battery);
power_supply_unregister(&bdi->charger);
power_supply_unregister(bdi->battery);
power_supply_unregister(bdi->charger);
pm_runtime_disable(bdi->dev);
if (bdi->gpio_int)
......@@ -1499,8 +1494,8 @@ static int bq24190_pm_resume(struct device *dev)
pm_runtime_put_sync(bdi->dev);
/* Things may have changed while suspended so alert upper layer */
power_supply_changed(&bdi->charger);
power_supply_changed(&bdi->battery);
power_supply_changed(bdi->charger);
power_supply_changed(bdi->battery);
return 0;
}
......
......@@ -44,14 +44,15 @@
#define BQ24735_DEVICE_ID 0xff
struct bq24735 {
struct power_supply charger;
struct i2c_client *client;
struct bq24735_platform *pdata;
struct power_supply *charger;
struct power_supply_desc charger_desc;
struct i2c_client *client;
struct bq24735_platform *pdata;
};
static inline struct bq24735 *to_bq24735(struct power_supply *psy)
{
return container_of(psy, struct bq24735, charger);
return power_supply_get_drvdata(psy);
}
static enum power_supply_property bq24735_charger_properties[] = {
......@@ -192,9 +193,7 @@ static int bq24735_charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct bq24735 *charger;
charger = container_of(psy, struct bq24735, charger);
struct bq24735 *charger = to_bq24735(psy);
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
......@@ -248,7 +247,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
{
int ret;
struct bq24735 *charger;
struct power_supply *supply;
struct power_supply_desc *supply_desc;
struct power_supply_config psy_cfg = {};
char *name;
......@@ -278,17 +277,18 @@ static int bq24735_charger_probe(struct i2c_client *client,
charger->client = client;
supply = &charger->charger;
supply_desc = &charger->charger_desc;
supply->name = name;
supply->type = POWER_SUPPLY_TYPE_MAINS;
supply->properties = bq24735_charger_properties;
supply->num_properties = ARRAY_SIZE(bq24735_charger_properties);
supply->get_property = bq24735_charger_get_property;
supply_desc->name = name;
supply_desc->type = POWER_SUPPLY_TYPE_MAINS;
supply_desc->properties = bq24735_charger_properties;
supply_desc->num_properties = ARRAY_SIZE(bq24735_charger_properties);
supply_desc->get_property = bq24735_charger_get_property;
psy_cfg.supplied_to = charger->pdata->supplied_to;
psy_cfg.num_supplicants = charger->pdata->num_supplicants;
psy_cfg.of_node = client->dev.of_node;
psy_cfg.drv_data = charger;
i2c_set_clientdata(client, charger);
......@@ -343,8 +343,10 @@ static int bq24735_charger_probe(struct i2c_client *client,
}
}
ret = power_supply_register(&client->dev, supply, &psy_cfg);
if (ret < 0) {
charger->charger = power_supply_register(&client->dev, supply_desc,
&psy_cfg);
if (IS_ERR(charger->charger)) {
ret = PTR_ERR(charger->charger);
dev_err(&client->dev, "Failed to register power supply: %d\n",
ret);
goto err_free_name;
......@@ -356,7 +358,8 @@ static int bq24735_charger_probe(struct i2c_client *client,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING |
IRQF_ONESHOT,
supply->name, supply);
supply_desc->name,
charger->charger);
if (ret) {
dev_err(&client->dev,
"Unable to register IRQ %d err %d\n",
......@@ -367,7 +370,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
return 0;
err_unregister_supply:
power_supply_unregister(supply);
power_supply_unregister(charger->charger);
err_free_name:
if (name != charger->pdata->name)
kfree(name);
......@@ -383,10 +386,10 @@ static int bq24735_charger_remove(struct i2c_client *client)
devm_free_irq(&charger->client->dev, charger->client->irq,
&charger->charger);
power_supply_unregister(&charger->charger);
power_supply_unregister(charger->charger);
if (charger->charger.name != charger->pdata->name)
kfree(charger->charger.name);
if (charger->charger_desc.name != charger->pdata->name)
kfree(charger->charger_desc.name);
return 0;
}
......
......@@ -116,7 +116,7 @@ struct bq27x00_device_info {
unsigned long last_update;
struct delayed_work work;
struct power_supply bat;
struct power_supply *bat;
struct bq27x00_access_methods bus;
......@@ -531,7 +531,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
}
if (di->cache.capacity != cache.capacity)
power_supply_changed(&di->bat);
power_supply_changed(di->bat);
if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
di->cache = cache;
......@@ -603,7 +603,7 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,
status = POWER_SUPPLY_STATUS_FULL;
else if (di->cache.flags & BQ27000_FLAG_CHGS)
status = POWER_SUPPLY_STATUS_CHARGING;
else if (power_supply_am_i_supplied(&di->bat))
else if (power_supply_am_i_supplied(di->bat))
status = POWER_SUPPLY_STATUS_NOT_CHARGING;
else
status = POWER_SUPPLY_STATUS_DISCHARGING;
......@@ -675,15 +675,12 @@ static int bq27x00_simple_value(int value,
return 0;
}
#define to_bq27x00_device_info(x) container_of((x), \
struct bq27x00_device_info, bat);
static int bq27x00_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
int ret = 0;
struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
struct bq27x00_device_info *di = power_supply_get_drvdata(psy);
mutex_lock(&di->lock);
if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
......@@ -761,38 +758,47 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
static void bq27x00_external_power_changed(struct power_supply *psy)
{
struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
struct bq27x00_device_info *di = power_supply_get_drvdata(psy);
cancel_delayed_work_sync(&di->work);
schedule_delayed_work(&di->work, 0);
}
static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
static int bq27x00_powersupply_init(struct bq27x00_device_info *di,
const char *name)
{
int ret;
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = { .drv_data = di, };
psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL);
if (!psy_desc)
return -ENOMEM;
di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->name = name;
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
if (di->chip == BQ27425) {
di->bat.properties = bq27425_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props);
psy_desc->properties = bq27425_battery_props;
psy_desc->num_properties = ARRAY_SIZE(bq27425_battery_props);
} else if (di->chip == BQ27742) {
di->bat.properties = bq27742_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27742_battery_props);
psy_desc->properties = bq27742_battery_props;
psy_desc->num_properties = ARRAY_SIZE(bq27742_battery_props);
} else if (di->chip == BQ27510) {
di->bat.properties = bq27510_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27510_battery_props);
psy_desc->properties = bq27510_battery_props;
psy_desc->num_properties = ARRAY_SIZE(bq27510_battery_props);
} else {
di->bat.properties = bq27x00_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
psy_desc->properties = bq27x00_battery_props;
psy_desc->num_properties = ARRAY_SIZE(bq27x00_battery_props);
}
di->bat.get_property = bq27x00_battery_get_property;
di->bat.external_power_changed = bq27x00_external_power_changed;
psy_desc->get_property = bq27x00_battery_get_property;
psy_desc->external_power_changed = bq27x00_external_power_changed;
INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
mutex_init(&di->lock);
ret = power_supply_register_no_ws(di->dev, &di->bat, NULL);
if (ret) {
di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg);
if (IS_ERR(di->bat)) {
ret = PTR_ERR(di->bat);
dev_err(di->dev, "failed to register battery: %d\n", ret);
return ret;
}
......@@ -816,7 +822,7 @@ static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
cancel_delayed_work_sync(&di->work);
power_supply_unregister(&di->bat);
power_supply_unregister(di->bat);
mutex_destroy(&di->lock);
}
......@@ -880,37 +886,34 @@ static int bq27x00_battery_probe(struct i2c_client *client,
if (num < 0)
return num;
name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
if (!name) {
dev_err(&client->dev, "failed to allocate device name\n");
retval = -ENOMEM;
goto batt_failed_1;
goto batt_failed;
}
di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
if (!di) {
dev_err(&client->dev, "failed to allocate device info data\n");
retval = -ENOMEM;
goto batt_failed_2;
goto batt_failed;
}
di->id = num;
di->dev = &client->dev;
di->chip = id->driver_data;
di->bat.name = name;
di->bus.read = &bq27x00_read_i2c;
retval = bq27x00_powersupply_init(di);
retval = bq27x00_powersupply_init(di, name);
if (retval)
goto batt_failed_2;
goto batt_failed;
i2c_set_clientdata(client, di);
return 0;
batt_failed_2:
kfree(name);
batt_failed_1:
batt_failed:
mutex_lock(&battery_mutex);
idr_remove(&battery_id, num);
mutex_unlock(&battery_mutex);
......@@ -924,8 +927,6 @@ static int bq27x00_battery_remove(struct i2c_client *client)
bq27x00_powersupply_unregister(di);
kfree(di->bat.name);
mutex_lock(&battery_mutex);
idr_remove(&battery_id, di->id);
mutex_unlock(&battery_mutex);
......@@ -1014,6 +1015,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
{
struct bq27x00_device_info *di;
struct bq27000_platform_data *pdata = pdev->dev.platform_data;
const char *name;
if (!pdata) {
dev_err(&pdev->dev, "no platform_data supplied\n");
......@@ -1036,10 +1038,10 @@ static int bq27000_battery_probe(struct platform_device *pdev)
di->dev = &pdev->dev;
di->chip = BQ27000;
di->bat.name = pdata->name ?: dev_name(&pdev->dev);
name = pdata->name ?: dev_name(&pdev->dev);
di->bus.read = &bq27000_read_platform;
return bq27x00_powersupply_init(di);
return bq27x00_powersupply_init(di, name);
}
static int bq27000_battery_remove(struct platform_device *pdev)
......
......@@ -864,8 +864,7 @@ static int charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct charger_manager *cm = container_of(psy,
struct charger_manager, charger_psy);
struct charger_manager *cm = power_supply_get_drvdata(psy);
struct charger_desc *desc = cm->desc;
struct power_supply *fuel_gauge;
int ret = 0;
......@@ -1018,7 +1017,7 @@ static enum power_supply_property default_charger_props[] = {
*/
};
static struct power_supply psy_default = {
static const struct power_supply_desc psy_default = {
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = default_charger_props,
......@@ -1399,7 +1398,7 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
dev_info(cm->dev, "'%s' regulator's externally_control is %d\n",
charger->regulator_name, charger->externally_control);
ret = sysfs_create_group(&cm->charger_psy.dev->kobj,
ret = sysfs_create_group(&cm->charger_psy->dev.kobj,
&charger->attr_g);
if (ret < 0) {
dev_err(cm->dev, "Cannot create sysfs entry of %s regulator\n",
......@@ -1431,9 +1430,9 @@ static int cm_init_thermal_data(struct charger_manager *cm,
POWER_SUPPLY_PROP_TEMP, &val);
if (!ret) {
cm->charger_psy.properties[cm->charger_psy.num_properties] =
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_TEMP;
cm->charger_psy.num_properties++;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true;
}
#ifdef CONFIG_THERMAL
......@@ -1444,9 +1443,9 @@ static int cm_init_thermal_data(struct charger_manager *cm,
return PTR_ERR(cm->tzd_batt);
/* Use external thermometer */
cm->charger_psy.properties[cm->charger_psy.num_properties] =
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_TEMP_AMBIENT;
cm->charger_psy.num_properties++;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true;
ret = 0;
}
......@@ -1606,6 +1605,7 @@ static int charger_manager_probe(struct platform_device *pdev)
int j = 0;
union power_supply_propval val;
struct power_supply *fuel_gauge;
struct power_supply_config psy_cfg = {};
if (IS_ERR(desc)) {
dev_err(&pdev->dev, "No platform data (desc) found\n");
......@@ -1620,6 +1620,7 @@ static int charger_manager_probe(struct platform_device *pdev)
/* Basic Values. Unspecified are Null or 0 */
cm->dev = &pdev->dev;
cm->desc = desc;
psy_cfg.drv_data = cm;
/* Initialize alarm timer */
if (alarmtimer_get_rtcdev()) {
......@@ -1699,40 +1700,40 @@ static int charger_manager_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, cm);
memcpy(&cm->charger_psy, &psy_default, sizeof(psy_default));
memcpy(&cm->charger_psy_desc, &psy_default, sizeof(psy_default));
if (!desc->psy_name)
strncpy(cm->psy_name_buf, psy_default.name, PSY_NAME_MAX);
else
strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX);
cm->charger_psy.name = cm->psy_name_buf;
cm->charger_psy_desc.name = cm->psy_name_buf;
/* Allocate for psy properties because they may vary */
cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
cm->charger_psy_desc.properties = devm_kzalloc(&pdev->dev,
sizeof(enum power_supply_property)
* (ARRAY_SIZE(default_charger_props) +
NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
if (!cm->charger_psy.properties)
if (!cm->charger_psy_desc.properties)
return -ENOMEM;
memcpy(cm->charger_psy.properties, default_charger_props,
memcpy(cm->charger_psy_desc.properties, default_charger_props,
sizeof(enum power_supply_property) *
ARRAY_SIZE(default_charger_props));
cm->charger_psy.num_properties = psy_default.num_properties;
cm->charger_psy_desc.num_properties = psy_default.num_properties;
/* Find which optional psy-properties are available */
if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
cm->charger_psy.properties[cm->charger_psy.num_properties] =
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_CHARGE_NOW;
cm->charger_psy.num_properties++;
cm->charger_psy_desc.num_properties++;
}
if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CURRENT_NOW,
&val)) {
cm->charger_psy.properties[cm->charger_psy.num_properties] =
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_CURRENT_NOW;
cm->charger_psy.num_properties++;
cm->charger_psy_desc.num_properties++;
}
ret = cm_init_thermal_data(cm, fuel_gauge);
......@@ -1743,11 +1744,12 @@ static int charger_manager_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
ret = power_supply_register(NULL, &cm->charger_psy, NULL);
if (ret) {
cm->charger_psy = power_supply_register(NULL, &cm->charger_psy_desc,
&psy_cfg);
if (IS_ERR(cm->charger_psy)) {
dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
cm->charger_psy.name);
return ret;
cm->charger_psy->desc->name);
return PTR_ERR(cm->charger_psy);
}
/* Register extcon device for charger cable */
......@@ -1793,7 +1795,7 @@ static int charger_manager_probe(struct platform_device *pdev)
struct charger_regulator *charger;
charger = &desc->charger_regulators[i];
sysfs_remove_group(&cm->charger_psy.dev->kobj,
sysfs_remove_group(&cm->charger_psy->dev.kobj,
&charger->attr_g);
}
err_reg_extcon:
......@@ -1811,7 +1813,7 @@ static int charger_manager_probe(struct platform_device *pdev)
regulator_put(desc->charger_regulators[i].consumer);
}
power_supply_unregister(&cm->charger_psy);
power_supply_unregister(cm->charger_psy);
return ret;
}
......@@ -1843,7 +1845,7 @@ static int charger_manager_remove(struct platform_device *pdev)
for (i = 0 ; i < desc->num_charger_regulators ; i++)
regulator_put(desc->charger_regulators[i].consumer);
power_supply_unregister(&cm->charger_psy);
power_supply_unregister(cm->charger_psy);
try_charger_enable(cm, false);
......@@ -2002,7 +2004,7 @@ static bool find_power_supply(struct charger_manager *cm,
bool found = false;
for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
if (!strcmp(psy->name, cm->desc->psy_charger_stat[i])) {
if (!strcmp(psy->desc->name, cm->desc->psy_charger_stat[i])) {
found = true;
break;
}
......
......@@ -30,7 +30,7 @@ static int wakeup_enabled;
struct collie_bat {
int status;
struct power_supply psy;
struct power_supply *psy;
int full_chrg;
struct mutex work_lock; /* protects data */
......@@ -98,7 +98,7 @@ static int collie_bat_get_property(struct power_supply *psy,
union power_supply_propval *val)
{
int ret = 0;
struct collie_bat *bat = container_of(psy, struct collie_bat, psy);
struct collie_bat *bat = power_supply_get_drvdata(psy);
if (bat->is_present && !bat->is_present(bat)
&& psp != POWER_SUPPLY_PROP_PRESENT) {
......@@ -155,14 +155,14 @@ static irqreturn_t collie_bat_gpio_isr(int irq, void *data)
static void collie_bat_update(struct collie_bat *bat)
{
int old;
struct power_supply *psy = &bat->psy;
struct power_supply *psy = bat->psy;
mutex_lock(&bat->work_lock);
old = bat->status;
if (bat->is_present && !bat->is_present(bat)) {
printk(KERN_NOTICE "%s not present\n", psy->name);
printk(KERN_NOTICE "%s not present\n", psy->desc->name);
bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
bat->full_chrg = -1;
} else if (power_supply_am_i_supplied(psy)) {
......@@ -220,18 +220,20 @@ static enum power_supply_property collie_bat_bu_props[] = {
POWER_SUPPLY_PROP_PRESENT,
};
static const struct power_supply_desc collie_bat_main_desc = {
.name = "main-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = collie_bat_main_props,
.num_properties = ARRAY_SIZE(collie_bat_main_props),
.get_property = collie_bat_get_property,
.external_power_changed = collie_bat_external_power_changed,
.use_for_apm = 1,
};
static struct collie_bat collie_bat_main = {
.status = POWER_SUPPLY_STATUS_DISCHARGING,
.full_chrg = -1,
.psy = {
.name = "main-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = collie_bat_main_props,
.num_properties = ARRAY_SIZE(collie_bat_main_props),
.get_property = collie_bat_get_property,
.external_power_changed = collie_bat_external_power_changed,
.use_for_apm = 1,
},
.psy = NULL,
.gpio_full = COLLIE_GPIO_CO,
.gpio_charge_on = COLLIE_GPIO_CHARGE_ON,
......@@ -249,18 +251,19 @@ static struct collie_bat collie_bat_main = {
.adc_temp_divider = 10000,
};
static const struct power_supply_desc collie_bat_bu_desc = {
.name = "backup-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = collie_bat_bu_props,
.num_properties = ARRAY_SIZE(collie_bat_bu_props),
.get_property = collie_bat_get_property,
.external_power_changed = collie_bat_external_power_changed,
};
static struct collie_bat collie_bat_bu = {
.status = POWER_SUPPLY_STATUS_UNKNOWN,
.full_chrg = -1,
.psy = {
.name = "backup-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = collie_bat_bu_props,
.num_properties = ARRAY_SIZE(collie_bat_bu_props),
.get_property = collie_bat_get_property,
.external_power_changed = collie_bat_external_power_changed,
},
.psy = NULL,
.gpio_full = -1,
.gpio_charge_on = -1,
......@@ -319,6 +322,7 @@ static int collie_bat_resume(struct ucb1x00_dev *dev)
static int collie_bat_probe(struct ucb1x00_dev *dev)
{
int ret;
struct power_supply_config psy_main_cfg = {}, psy_bu_cfg = {};
if (!machine_is_collie())
return -ENODEV;
......@@ -334,12 +338,23 @@ static int collie_bat_probe(struct ucb1x00_dev *dev)
INIT_WORK(&bat_work, collie_bat_work);
ret = power_supply_register(&dev->ucb->dev, &collie_bat_main.psy, NULL);
if (ret)
psy_main_cfg.drv_data = &collie_bat_main;
collie_bat_main.psy = power_supply_register(&dev->ucb->dev,
&collie_bat_main_desc,
&psy_main_cfg);
if (IS_ERR(collie_bat_main.psy)) {
ret = PTR_ERR(collie_bat_main.psy);
goto err_psy_reg_main;
ret = power_supply_register(&dev->ucb->dev, &collie_bat_bu.psy, NULL);
if (ret)
}
psy_main_cfg.drv_data = &collie_bat_bu;
collie_bat_bu.psy = power_supply_register(&dev->ucb->dev,
&collie_bat_bu_desc,
&psy_bu_cfg);
if (IS_ERR(collie_bat_bu.psy)) {
ret = PTR_ERR(collie_bat_bu.psy);
goto err_psy_reg_bu;
}
ret = request_irq(gpio_to_irq(COLLIE_GPIO_CO),
collie_bat_gpio_isr,
......@@ -354,9 +369,9 @@ static int collie_bat_probe(struct ucb1x00_dev *dev)
return 0;
err_irq:
power_supply_unregister(&collie_bat_bu.psy);
power_supply_unregister(collie_bat_bu.psy);
err_psy_reg_bu:
power_supply_unregister(&collie_bat_main.psy);
power_supply_unregister(collie_bat_main.psy);
err_psy_reg_main:
/* see comment in collie_bat_remove */
......@@ -369,8 +384,8 @@ static void collie_bat_remove(struct ucb1x00_dev *dev)
{
free_irq(gpio_to_irq(COLLIE_GPIO_CO), &collie_bat_main);
power_supply_unregister(&collie_bat_bu.psy);
power_supply_unregister(&collie_bat_main.psy);
power_supply_unregister(collie_bat_bu.psy);
power_supply_unregister(collie_bat_main.psy);
/*
* Now cancel the bat_work. We won't get any more schedules,
......
......@@ -89,7 +89,8 @@ struct da9030_battery_thresholds {
};
struct da9030_charger {
struct power_supply psy;
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct device *master;
......@@ -245,7 +246,7 @@ static void da9030_set_charge(struct da9030_charger *charger, int on)
da903x_write(charger->master, DA9030_CHARGE_CONTROL, val);
power_supply_changed(&charger->psy);
power_supply_changed(charger->psy);
}
static void da9030_charger_check_state(struct da9030_charger *charger)
......@@ -341,8 +342,7 @@ static int da9030_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct da9030_charger *charger;
charger = container_of(psy, struct da9030_charger, psy);
struct da9030_charger *charger = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
......@@ -447,16 +447,16 @@ static void da9030_battery_convert_thresholds(struct da9030_charger *charger,
static void da9030_battery_setup_psy(struct da9030_charger *charger)
{
struct power_supply *psy = &charger->psy;
struct power_supply_desc *psy_desc = &charger->psy_desc;
struct power_supply_info *info = charger->battery_info;
psy->name = info->name;
psy->use_for_apm = info->use_for_apm;
psy->type = POWER_SUPPLY_TYPE_BATTERY;
psy->get_property = da9030_battery_get_property;
psy_desc->name = info->name;
psy_desc->use_for_apm = info->use_for_apm;
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->get_property = da9030_battery_get_property;
psy->properties = da9030_battery_props;
psy->num_properties = ARRAY_SIZE(da9030_battery_props);
psy_desc->properties = da9030_battery_props;
psy_desc->num_properties = ARRAY_SIZE(da9030_battery_props);
};
static int da9030_battery_charger_init(struct da9030_charger *charger)
......@@ -494,6 +494,7 @@ static int da9030_battery_charger_init(struct da9030_charger *charger)
static int da9030_battery_probe(struct platform_device *pdev)
{
struct da9030_charger *charger;
struct power_supply_config psy_cfg = {};
struct da9030_battery_info *pdata = pdev->dev.platform_data;
int ret;
......@@ -541,9 +542,13 @@ static int da9030_battery_probe(struct platform_device *pdev)
goto err_notifier;
da9030_battery_setup_psy(charger);
ret = power_supply_register(&pdev->dev, &charger->psy, NULL);
if (ret)
psy_cfg.drv_data = charger;
charger->psy = power_supply_register(&pdev->dev, &charger->psy_desc,
&psy_cfg);
if (IS_ERR(charger->psy)) {
ret = PTR_ERR(charger->psy);
goto err_ps_register;
}
charger->debug_file = da9030_bat_create_debugfs(charger);
platform_set_drvdata(pdev, charger);
......@@ -571,7 +576,7 @@ static int da9030_battery_remove(struct platform_device *dev)
DA9030_EVENT_CHIOVER | DA9030_EVENT_TBAT);
cancel_delayed_work_sync(&charger->work);
da9030_set_charge(charger, 0);
power_supply_unregister(&charger->psy);
power_supply_unregister(charger->psy);
return 0;
}
......
......@@ -169,7 +169,7 @@ static u32 const vc_tbl[3][68][2] = {
struct da9052_battery {
struct da9052 *da9052;
struct power_supply psy;
struct power_supply *psy;
struct notifier_block nb;
int charger_type;
int status;
......@@ -452,7 +452,7 @@ static irqreturn_t da9052_bat_irq(int irq, void *data)
if (irq == DA9052_IRQ_CHGEND || irq == DA9052_IRQ_DCIN ||
irq == DA9052_IRQ_VBUS || irq == DA9052_IRQ_TBAT) {
power_supply_changed(&bat->psy);
power_supply_changed(bat->psy);
}
return IRQ_HANDLED;
......@@ -499,8 +499,7 @@ static int da9052_bat_get_property(struct power_supply *psy,
{
int ret;
int illegal;
struct da9052_battery *bat = container_of(psy, struct da9052_battery,
psy);
struct da9052_battery *bat = power_supply_get_drvdata(psy);
ret = da9052_bat_check_presence(bat, &illegal);
if (ret < 0)
......@@ -561,7 +560,7 @@ static enum power_supply_property da9052_bat_props[] = {
POWER_SUPPLY_PROP_TECHNOLOGY,
};
static struct power_supply template_battery = {
static struct power_supply_desc psy_desc = {
.name = "da9052-bat",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = da9052_bat_props,
......@@ -591,6 +590,7 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
{
struct da9052_pdata *pdata;
struct da9052_battery *bat;
struct power_supply_config psy_cfg = {};
int ret;
int i;
......@@ -599,8 +599,9 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
if (!bat)
return -ENOMEM;
psy_cfg.drv_data = bat;
bat->da9052 = dev_get_drvdata(pdev->dev.parent);
bat->psy = template_battery;
bat->charger_type = DA9052_NOCHARGER;
bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
bat->health = POWER_SUPPLY_HEALTH_UNKNOWN;
......@@ -608,9 +609,9 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
pdata = bat->da9052->dev->platform_data;
if (pdata != NULL && pdata->use_for_apm)
bat->psy.use_for_apm = pdata->use_for_apm;
psy_desc.use_for_apm = pdata->use_for_apm;
else
bat->psy.use_for_apm = 1;
psy_desc.use_for_apm = 1;
for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++) {
ret = da9052_request_irq(bat->da9052,
......@@ -625,9 +626,11 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
}
}
ret = power_supply_register(&pdev->dev, &bat->psy, NULL);
if (ret)
bat->psy = power_supply_register(&pdev->dev, &psy_desc, &psy_cfg);
if (IS_ERR(bat->psy)) {
ret = PTR_ERR(bat->psy);
goto err;
}
platform_set_drvdata(pdev, bat);
return 0;
......@@ -646,7 +649,7 @@ static int da9052_bat_remove(struct platform_device *pdev)
for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++)
da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat);
power_supply_unregister(&bat->psy);
power_supply_unregister(bat->psy);
return 0;
}
......
......@@ -30,8 +30,8 @@ struct da9150_charger {
struct da9150 *da9150;
struct device *dev;
struct power_supply usb;
struct power_supply battery;
struct power_supply *usb;
struct power_supply *battery;
struct power_supply *supply_online;
struct usb_phy *usb_phy;
......@@ -114,7 +114,7 @@ static int da9150_charger_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct da9150_charger *charger = dev_get_drvdata(psy->dev->parent);
struct da9150_charger *charger = dev_get_drvdata(psy->dev.parent);
int ret;
switch (psp) {
......@@ -326,7 +326,7 @@ static int da9150_charger_battery_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct da9150_charger *charger = dev_get_drvdata(psy->dev->parent);
struct da9150_charger *charger = dev_get_drvdata(psy->dev.parent);
int ret;
switch (psp) {
......@@ -369,7 +369,7 @@ static irqreturn_t da9150_charger_chg_irq(int irq, void *data)
{
struct da9150_charger *charger = data;
power_supply_changed(&charger->battery);
power_supply_changed(charger->battery);
return IRQ_HANDLED;
}
......@@ -380,7 +380,7 @@ static irqreturn_t da9150_charger_tjunc_irq(int irq, void *data)
/* Nothing we can really do except report this. */
dev_crit(charger->dev, "TJunc over temperature!!!\n");
power_supply_changed(&charger->usb);
power_supply_changed(charger->usb);
return IRQ_HANDLED;
}
......@@ -391,8 +391,8 @@ static irqreturn_t da9150_charger_vfault_irq(int irq, void *data)
/* Nothing we can really do except report this. */
dev_crit(charger->dev, "VSYS under voltage!!!\n");
power_supply_changed(&charger->usb);
power_supply_changed(&charger->battery);
power_supply_changed(charger->usb);
power_supply_changed(charger->battery);
return IRQ_HANDLED;
}
......@@ -408,10 +408,10 @@ static irqreturn_t da9150_charger_vbus_irq(int irq, void *data)
switch (reg & DA9150_VBUS_STAT_MASK) {
case DA9150_VBUS_STAT_OFF:
case DA9150_VBUS_STAT_WAIT:
charger->supply_online = &charger->battery;
charger->supply_online = charger->battery;
break;
case DA9150_VBUS_STAT_CHG:
charger->supply_online = &charger->usb;
charger->supply_online = charger->usb;
break;
default:
dev_warn(charger->dev, "Unknown VBUS state - reg = 0x%x\n",
......@@ -420,8 +420,8 @@ static irqreturn_t da9150_charger_vbus_irq(int irq, void *data)
break;
}
power_supply_changed(&charger->usb);
power_supply_changed(&charger->battery);
power_supply_changed(charger->usb);
power_supply_changed(charger->battery);
return IRQ_HANDLED;
}
......@@ -439,8 +439,8 @@ static void da9150_charger_otg_work(struct work_struct *data)
break;
case USB_EVENT_NONE:
/* Revert to charge mode */
power_supply_changed(&charger->usb);
power_supply_changed(&charger->battery);
power_supply_changed(charger->usb);
power_supply_changed(charger->battery);
da9150_set_bits(charger->da9150, DA9150_PPR_BKCTRL_A,
DA9150_VBUS_MODE_MASK, DA9150_VBUS_MODE_CHG);
break;
......@@ -499,12 +499,27 @@ static void da9150_charger_unregister_irq(struct platform_device *pdev,
free_irq(irq, charger);
}
static const struct power_supply_desc usb_desc = {
.name = "da9150-usb",
.type = POWER_SUPPLY_TYPE_USB,
.properties = da9150_charger_props,
.num_properties = ARRAY_SIZE(da9150_charger_props),
.get_property = da9150_charger_get_prop,
};
static const struct power_supply_desc battery_desc = {
.name = "da9150-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = da9150_charger_bat_props,
.num_properties = ARRAY_SIZE(da9150_charger_bat_props),
.get_property = da9150_charger_battery_get_prop,
};
static int da9150_charger_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct da9150 *da9150 = dev_get_drvdata(dev->parent);
struct da9150_charger *charger;
struct power_supply *usb, *battery;
u8 reg;
int ret;
......@@ -542,26 +557,17 @@ static int da9150_charger_probe(struct platform_device *pdev)
}
/* Register power supplies */
usb = &charger->usb;
battery = &charger->battery;
usb->name = "da9150-usb",
usb->type = POWER_SUPPLY_TYPE_USB;
usb->properties = da9150_charger_props;
usb->num_properties = ARRAY_SIZE(da9150_charger_props);
usb->get_property = da9150_charger_get_prop;
ret = power_supply_register(dev, usb, NULL);
if (ret)
charger->usb = power_supply_register(dev, &usb_desc, NULL);
if (IS_ERR(charger->usb)) {
ret = PTR_ERR(charger->usb);
goto usb_fail;
}
battery->name = "da9150-battery";
battery->type = POWER_SUPPLY_TYPE_BATTERY;
battery->properties = da9150_charger_bat_props;
battery->num_properties = ARRAY_SIZE(da9150_charger_bat_props);
battery->get_property = da9150_charger_battery_get_prop;
ret = power_supply_register(dev, battery, NULL);
if (ret)
charger->battery = power_supply_register(dev, &battery_desc, NULL);
if (IS_ERR(charger->battery)) {
ret = PTR_ERR(charger->battery);
goto battery_fail;
}
/* Get initial online supply */
reg = da9150_reg_read(da9150, DA9150_STATUS_H);
......@@ -569,10 +575,10 @@ static int da9150_charger_probe(struct platform_device *pdev)
switch (reg & DA9150_VBUS_STAT_MASK) {
case DA9150_VBUS_STAT_OFF:
case DA9150_VBUS_STAT_WAIT:
charger->supply_online = &charger->battery;
charger->supply_online = charger->battery;
break;
case DA9150_VBUS_STAT_CHG:
charger->supply_online = &charger->usb;
charger->supply_online = charger->usb;
break;
default:
dev_warn(dev, "Unknown VBUS state - reg = 0x%x\n", reg);
......@@ -622,7 +628,7 @@ static int da9150_charger_probe(struct platform_device *pdev)
if (!IS_ERR_OR_NULL(charger->usb_phy))
usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
battery_fail:
power_supply_unregister(usb);
power_supply_unregister(charger->usb);
usb_fail:
iio_channel_release(charger->vbat_chan);
......@@ -661,8 +667,8 @@ static int da9150_charger_remove(struct platform_device *pdev)
if (!IS_ERR_OR_NULL(charger->usb_phy))
usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
power_supply_unregister(&charger->battery);
power_supply_unregister(&charger->usb);
power_supply_unregister(charger->battery);
power_supply_unregister(charger->usb);
/* Release ADC channels */
iio_channel_release(charger->ibus_chan);
......
......@@ -53,7 +53,8 @@ struct ds2760_device_info {
int charge_status; /* POWER_SUPPLY_STATUS_* */
int full_counter;
struct power_supply bat;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct device *w1_dev;
struct workqueue_struct *monitor_wqueue;
struct delayed_work monitor_work;
......@@ -254,7 +255,7 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN)
di->full_counter = 0;
if (power_supply_am_i_supplied(&di->bat)) {
if (power_supply_am_i_supplied(di->bat)) {
if (di->current_uA > 10000) {
di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
di->full_counter = 0;
......@@ -287,7 +288,7 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
}
if (di->charge_status != old_charge_status)
power_supply_changed(&di->bat);
power_supply_changed(di->bat);
}
static void ds2760_battery_write_status(struct ds2760_device_info *di,
......@@ -346,12 +347,9 @@ static void ds2760_battery_work(struct work_struct *work)
queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval);
}
#define to_ds2760_device_info(x) container_of((x), struct ds2760_device_info, \
bat);
static void ds2760_battery_external_power_changed(struct power_supply *psy)
{
struct ds2760_device_info *di = to_ds2760_device_info(psy);
struct ds2760_device_info *di = power_supply_get_drvdata(psy);
dev_dbg(di->dev, "%s\n", __func__);
......@@ -377,7 +375,7 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
* that error.
*/
if (!power_supply_am_i_supplied(&di->bat))
if (!power_supply_am_i_supplied(di->bat))
return;
bias = (signed char) di->current_raw +
......@@ -396,7 +394,7 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
static void ds2760_battery_set_charged(struct power_supply *psy)
{
struct ds2760_device_info *di = to_ds2760_device_info(psy);
struct ds2760_device_info *di = power_supply_get_drvdata(psy);
/* postpone the actual work by 20 secs. This is for debouncing GPIO
* signals and to let the current value settle. See AN4188. */
......@@ -407,7 +405,7 @@ static int ds2760_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct ds2760_device_info *di = to_ds2760_device_info(psy);
struct ds2760_device_info *di = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
......@@ -458,7 +456,7 @@ static int ds2760_battery_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
struct ds2760_device_info *di = to_ds2760_device_info(psy);
struct ds2760_device_info *di = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_FULL:
......@@ -508,6 +506,7 @@ static enum power_supply_property ds2760_battery_props[] = {
static int ds2760_battery_probe(struct platform_device *pdev)
{
struct power_supply_config psy_cfg = {};
char status;
int retval = 0;
struct ds2760_device_info *di;
......@@ -520,20 +519,22 @@ static int ds2760_battery_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, di);
di->dev = &pdev->dev;
di->w1_dev = pdev->dev.parent;
di->bat.name = dev_name(&pdev->dev);
di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
di->bat.properties = ds2760_battery_props;
di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props);
di->bat.get_property = ds2760_battery_get_property;
di->bat.set_property = ds2760_battery_set_property;
di->bat.property_is_writeable =
di->dev = &pdev->dev;
di->w1_dev = pdev->dev.parent;
di->bat_desc.name = dev_name(&pdev->dev);
di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
di->bat_desc.properties = ds2760_battery_props;
di->bat_desc.num_properties = ARRAY_SIZE(ds2760_battery_props);
di->bat_desc.get_property = ds2760_battery_get_property;
di->bat_desc.set_property = ds2760_battery_set_property;
di->bat_desc.property_is_writeable =
ds2760_battery_property_is_writeable;
di->bat.set_charged = ds2760_battery_set_charged;
di->bat.external_power_changed =
di->bat_desc.set_charged = ds2760_battery_set_charged;
di->bat_desc.external_power_changed =
ds2760_battery_external_power_changed;
psy_cfg.drv_data = di;
di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
/* enable sleep mode feature */
......@@ -555,9 +556,10 @@ static int ds2760_battery_probe(struct platform_device *pdev)
if (current_accum)
ds2760_battery_set_current_accum(di, current_accum);
retval = power_supply_register(&pdev->dev, &di->bat, NULL);
if (retval) {
di->bat = power_supply_register(&pdev->dev, &di->bat_desc, &psy_cfg);
if (IS_ERR(di->bat)) {
dev_err(di->dev, "failed to register battery\n");
retval = PTR_ERR(di->bat);
goto batt_failed;
}
......@@ -574,7 +576,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
goto success;
workqueue_failed:
power_supply_unregister(&di->bat);
power_supply_unregister(di->bat);
batt_failed:
di_alloc_failed:
success:
......@@ -588,7 +590,7 @@ static int ds2760_battery_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&di->monitor_work);
cancel_delayed_work_sync(&di->set_charged_work);
destroy_workqueue(di->monitor_wqueue);
power_supply_unregister(&di->bat);
power_supply_unregister(di->bat);
return 0;
}
......@@ -610,7 +612,7 @@ static int ds2760_battery_resume(struct platform_device *pdev)
struct ds2760_device_info *di = platform_get_drvdata(pdev);
di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
power_supply_changed(&di->bat);
power_supply_changed(di->bat);
mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
......
......@@ -37,7 +37,8 @@
struct ds2780_device_info {
struct device *dev;
struct power_supply bat;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct device *w1_dev;
};
......@@ -52,7 +53,7 @@ static const char manufacturer[] = "Maxim/Dallas";
static inline struct ds2780_device_info *
to_ds2780_device_info(struct power_supply *psy)
{
return container_of(psy, struct ds2780_device_info, bat);
return power_supply_get_drvdata(psy);
}
static inline struct power_supply *to_power_supply(struct device *dev)
......@@ -757,6 +758,7 @@ static const struct attribute_group ds2780_attr_group = {
static int ds2780_battery_probe(struct platform_device *pdev)
{
struct power_supply_config psy_cfg = {};
int ret = 0;
struct ds2780_device_info *dev_info;
......@@ -770,25 +772,29 @@ static int ds2780_battery_probe(struct platform_device *pdev)
dev_info->dev = &pdev->dev;
dev_info->w1_dev = pdev->dev.parent;
dev_info->bat.name = dev_name(&pdev->dev);
dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY;
dev_info->bat.properties = ds2780_battery_props;
dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props);
dev_info->bat.get_property = ds2780_battery_get_property;
dev_info->bat_desc.name = dev_name(&pdev->dev);
dev_info->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
dev_info->bat_desc.properties = ds2780_battery_props;
dev_info->bat_desc.num_properties = ARRAY_SIZE(ds2780_battery_props);
dev_info->bat_desc.get_property = ds2780_battery_get_property;
ret = power_supply_register(&pdev->dev, &dev_info->bat, NULL);
if (ret) {
psy_cfg.drv_data = dev_info;
dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
&psy_cfg);
if (IS_ERR(dev_info->bat)) {
dev_err(dev_info->dev, "failed to register battery\n");
ret = PTR_ERR(dev_info->bat);
goto fail;
}
ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
if (ret) {
dev_err(dev_info->dev, "failed to create sysfs group\n");
goto fail_unregister;
}
ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
&ds2780_param_eeprom_bin_attr);
if (ret) {
dev_err(dev_info->dev,
......@@ -796,7 +802,7 @@ static int ds2780_battery_probe(struct platform_device *pdev)
goto fail_remove_group;
}
ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
&ds2780_user_eeprom_bin_attr);
if (ret) {
dev_err(dev_info->dev,
......@@ -807,12 +813,12 @@ static int ds2780_battery_probe(struct platform_device *pdev)
return 0;
fail_remove_bin_file:
sysfs_remove_bin_file(&dev_info->bat.dev->kobj,
sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
&ds2780_param_eeprom_bin_attr);
fail_remove_group:
sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
fail_unregister:
power_supply_unregister(&dev_info->bat);
power_supply_unregister(dev_info->bat);
fail:
return ret;
}
......@@ -821,10 +827,13 @@ static int ds2780_battery_remove(struct platform_device *pdev)
{
struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
/* remove attributes */
sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
/*
* Remove attributes before unregistering power supply
* because 'bat' will be freed on power_supply_unregister() call.
*/
sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
power_supply_unregister(&dev_info->bat);
power_supply_unregister(dev_info->bat);
return 0;
}
......
......@@ -35,7 +35,8 @@
struct ds2781_device_info {
struct device *dev;
struct power_supply bat;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct device *w1_dev;
};
......@@ -50,7 +51,7 @@ static const char manufacturer[] = "Maxim/Dallas";
static inline struct ds2781_device_info *
to_ds2781_device_info(struct power_supply *psy)
{
return container_of(psy, struct ds2781_device_info, bat);
return power_supply_get_drvdata(psy);
}
static inline struct power_supply *to_power_supply(struct device *dev)
......@@ -328,7 +329,7 @@ static int ds2781_get_status(struct ds2781_device_info *dev_info, int *status)
if (ret < 0)
return ret;
if (power_supply_am_i_supplied(&dev_info->bat)) {
if (power_supply_am_i_supplied(dev_info->bat)) {
if (capacity == 100)
*status = POWER_SUPPLY_STATUS_FULL;
else if (current_uA > 50000)
......@@ -752,6 +753,7 @@ static const struct attribute_group ds2781_attr_group = {
static int ds2781_battery_probe(struct platform_device *pdev)
{
struct power_supply_config psy_cfg = {};
int ret = 0;
struct ds2781_device_info *dev_info;
......@@ -763,25 +765,29 @@ static int ds2781_battery_probe(struct platform_device *pdev)
dev_info->dev = &pdev->dev;
dev_info->w1_dev = pdev->dev.parent;
dev_info->bat.name = dev_name(&pdev->dev);
dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY;
dev_info->bat.properties = ds2781_battery_props;
dev_info->bat.num_properties = ARRAY_SIZE(ds2781_battery_props);
dev_info->bat.get_property = ds2781_battery_get_property;
dev_info->bat_desc.name = dev_name(&pdev->dev);
dev_info->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
dev_info->bat_desc.properties = ds2781_battery_props;
dev_info->bat_desc.num_properties = ARRAY_SIZE(ds2781_battery_props);
dev_info->bat_desc.get_property = ds2781_battery_get_property;
ret = power_supply_register(&pdev->dev, &dev_info->bat, NULL);
if (ret) {
psy_cfg.drv_data = dev_info;
dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
&psy_cfg);
if (IS_ERR(dev_info->bat)) {
dev_err(dev_info->dev, "failed to register battery\n");
ret = PTR_ERR(dev_info->bat);
goto fail;
}
ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
if (ret) {
dev_err(dev_info->dev, "failed to create sysfs group\n");
goto fail_unregister;
}
ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
&ds2781_param_eeprom_bin_attr);
if (ret) {
dev_err(dev_info->dev,
......@@ -789,7 +795,7 @@ static int ds2781_battery_probe(struct platform_device *pdev)
goto fail_remove_group;
}
ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
&ds2781_user_eeprom_bin_attr);
if (ret) {
dev_err(dev_info->dev,
......@@ -800,12 +806,12 @@ static int ds2781_battery_probe(struct platform_device *pdev)
return 0;
fail_remove_bin_file:
sysfs_remove_bin_file(&dev_info->bat.dev->kobj,
sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
&ds2781_param_eeprom_bin_attr);
fail_remove_group:
sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
fail_unregister:
power_supply_unregister(&dev_info->bat);
power_supply_unregister(dev_info->bat);
fail:
return ret;
}
......@@ -814,10 +820,13 @@ static int ds2781_battery_remove(struct platform_device *pdev)
{
struct ds2781_device_info *dev_info = platform_get_drvdata(pdev);
/* remove attributes */
sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group);
/*
* Remove attributes before unregistering power supply
* because 'bat' will be freed on power_supply_unregister() call.
*/
sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
power_supply_unregister(&dev_info->bat);
power_supply_unregister(dev_info->bat);
return 0;
}
......
......@@ -53,11 +53,12 @@ struct ds278x_battery_ops {
int (*get_battery_capacity)(struct ds278x_info *info, int *capacity);
};
#define to_ds278x_info(x) container_of(x, struct ds278x_info, battery)
#define to_ds278x_info(x) power_supply_get_drvdata(x)
struct ds278x_info {
struct i2c_client *client;
struct power_supply battery;
struct power_supply *battery;
struct power_supply_desc battery_desc;
struct ds278x_battery_ops *ops;
struct delayed_work bat_work;
int id;
......@@ -285,7 +286,7 @@ static void ds278x_bat_update(struct ds278x_info *info)
ds278x_get_status(info, &info->status);
if ((old_status != info->status) || (old_capacity != info->capacity))
power_supply_changed(&info->battery);
power_supply_changed(info->battery);
}
static void ds278x_bat_work(struct work_struct *work)
......@@ -306,7 +307,7 @@ static enum power_supply_property ds278x_battery_props[] = {
POWER_SUPPLY_PROP_TEMP,
};
static void ds278x_power_supply_init(struct power_supply *battery)
static void ds278x_power_supply_init(struct power_supply_desc *battery)
{
battery->type = POWER_SUPPLY_TYPE_BATTERY;
battery->properties = ds278x_battery_props;
......@@ -319,8 +320,8 @@ static int ds278x_battery_remove(struct i2c_client *client)
{
struct ds278x_info *info = i2c_get_clientdata(client);
power_supply_unregister(&info->battery);
kfree(info->battery.name);
power_supply_unregister(info->battery);
kfree(info->battery_desc.name);
mutex_lock(&battery_lock);
idr_remove(&battery_id, info->id);
......@@ -377,6 +378,7 @@ static int ds278x_battery_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct ds278x_platform_data *pdata = client->dev.platform_data;
struct power_supply_config psy_cfg = {};
struct ds278x_info *info;
int ret;
int num;
......@@ -404,8 +406,9 @@ static int ds278x_battery_probe(struct i2c_client *client,
goto fail_info;
}
info->battery.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num);
if (!info->battery.name) {
info->battery_desc.name = kasprintf(GFP_KERNEL, "%s-%d",
client->name, num);
if (!info->battery_desc.name) {
ret = -ENOMEM;
goto fail_name;
}
......@@ -417,16 +420,19 @@ static int ds278x_battery_probe(struct i2c_client *client,
info->client = client;
info->id = num;
info->ops = &ds278x_ops[id->driver_data];
ds278x_power_supply_init(&info->battery);
ds278x_power_supply_init(&info->battery_desc);
psy_cfg.drv_data = info;
info->capacity = 100;
info->status = POWER_SUPPLY_STATUS_FULL;
INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work);
ret = power_supply_register(&client->dev, &info->battery, NULL);
if (ret) {
info->battery = power_supply_register(&client->dev,
&info->battery_desc, &psy_cfg);
if (IS_ERR(info->battery)) {
dev_err(&client->dev, "failed to register battery\n");
ret = PTR_ERR(info->battery);
goto fail_register;
} else {
schedule_delayed_work(&info->bat_work, DS278x_DELAY);
......@@ -435,7 +441,7 @@ static int ds278x_battery_probe(struct i2c_client *client,
return 0;
fail_register:
kfree(info->battery.name);
kfree(info->battery_desc.name);
fail_name:
kfree(info);
fail_info:
......
......@@ -44,7 +44,8 @@ static const char *const gab_chan_name[] = {
};
struct gab {
struct power_supply psy;
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
struct gab_platform_data *pdata;
struct delayed_work bat_work;
......@@ -55,7 +56,7 @@ struct gab {
static struct gab *to_generic_bat(struct power_supply *psy)
{
return container_of(psy, struct gab, psy);
return power_supply_get_drvdata(psy);
}
static void gab_ext_power_changed(struct power_supply *psy)
......@@ -151,7 +152,7 @@ static int gab_get_property(struct power_supply *psy,
adc_bat = to_generic_bat(psy);
if (!adc_bat) {
dev_err(psy->dev, "no battery infos ?!\n");
dev_err(&psy->dev, "no battery infos ?!\n");
return -EINVAL;
}
pdata = adc_bat->pdata;
......@@ -210,7 +211,7 @@ static void gab_work(struct work_struct *work)
pdata = adc_bat->pdata;
status = adc_bat->status;
is_plugged = power_supply_am_i_supplied(&adc_bat->psy);
is_plugged = power_supply_am_i_supplied(adc_bat->psy);
adc_bat->cable_plugged = is_plugged;
if (!is_plugged)
......@@ -221,7 +222,7 @@ static void gab_work(struct work_struct *work)
adc_bat->status = POWER_SUPPLY_STATUS_CHARGING;
if (status != adc_bat->status)
power_supply_changed(&adc_bat->psy);
power_supply_changed(adc_bat->psy);
}
static irqreturn_t gab_charged(int irq, void *dev_id)
......@@ -239,7 +240,8 @@ static irqreturn_t gab_charged(int irq, void *dev_id)
static int gab_probe(struct platform_device *pdev)
{
struct gab *adc_bat;
struct power_supply *psy;
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
struct gab_platform_data *pdata = pdev->dev.platform_data;
enum power_supply_property *properties;
int ret = 0;
......@@ -252,32 +254,34 @@ static int gab_probe(struct platform_device *pdev)
return -ENOMEM;
}
psy = &adc_bat->psy;
psy->name = pdata->battery_info.name;
psy_cfg.drv_data = adc_bat;
psy_desc = &adc_bat->psy_desc;
psy_desc->name = pdata->battery_info.name;
/* bootup default values for the battery */
adc_bat->cable_plugged = false;
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
psy->type = POWER_SUPPLY_TYPE_BATTERY;
psy->get_property = gab_get_property;
psy->external_power_changed = gab_ext_power_changed;
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
psy_desc->get_property = gab_get_property;
psy_desc->external_power_changed = gab_ext_power_changed;
adc_bat->pdata = pdata;
/*
* copying the static properties and allocating extra memory for holding
* the extra configurable properties received from platform data.
*/
psy->properties = kcalloc(ARRAY_SIZE(gab_props) +
psy_desc->properties = kcalloc(ARRAY_SIZE(gab_props) +
ARRAY_SIZE(gab_chan_name),
sizeof(*psy->properties), GFP_KERNEL);
if (!psy->properties) {
sizeof(*psy_desc->properties),
GFP_KERNEL);
if (!psy_desc->properties) {
ret = -ENOMEM;
goto first_mem_fail;
}
memcpy(psy->properties, gab_props, sizeof(gab_props));
memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
properties = (enum power_supply_property *)
((char *)psy->properties + sizeof(gab_props));
((char *)psy_desc->properties + sizeof(gab_props));
/*
* getting channel from iio and copying the battery properties
......@@ -291,7 +295,7 @@ static int gab_probe(struct platform_device *pdev)
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
memcpy(properties + sizeof(*(psy->properties)) * index,
memcpy(properties + sizeof(*(psy_desc->properties)) * index,
&gab_dyn_props[chan],
sizeof(gab_dyn_props[chan]));
index++;
......@@ -310,11 +314,13 @@ static int gab_probe(struct platform_device *pdev)
* as come channels may be not be supported by the device.So
* we need to take care of that.
*/
psy->num_properties = ARRAY_SIZE(gab_props) + index;
psy_desc->num_properties = ARRAY_SIZE(gab_props) + index;
ret = power_supply_register(&pdev->dev, psy, NULL);
if (ret)
adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
if (IS_ERR(adc_bat->psy)) {
ret = PTR_ERR(adc_bat->psy);
goto err_reg_fail;
}
INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
......@@ -342,14 +348,14 @@ static int gab_probe(struct platform_device *pdev)
err_gpio:
gpio_free(pdata->gpio_charge_finished);
gpio_req_fail:
power_supply_unregister(psy);
power_supply_unregister(adc_bat->psy);
err_reg_fail:
for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
if (adc_bat->channel[chan])
iio_channel_release(adc_bat->channel[chan]);
}
second_mem_fail:
kfree(psy->properties);
kfree(psy_desc->properties);
first_mem_fail:
return ret;
}
......@@ -360,7 +366,7 @@ static int gab_remove(struct platform_device *pdev)
struct gab *adc_bat = platform_get_drvdata(pdev);
struct gab_platform_data *pdata = adc_bat->pdata;
power_supply_unregister(&adc_bat->psy);
power_supply_unregister(adc_bat->psy);
if (gpio_is_valid(pdata->gpio_charge_finished)) {
free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat);
......@@ -372,7 +378,7 @@ static int gab_remove(struct platform_device *pdev)
iio_channel_release(adc_bat->channel[chan]);
}
kfree(adc_bat->psy.properties);
kfree(adc_bat->psy_desc.properties);
cancel_delayed_work(&adc_bat->bat_work);
return 0;
}
......
......@@ -30,8 +30,8 @@ struct goldfish_battery_data {
int irq;
spinlock_t lock;
struct power_supply battery;
struct power_supply ac;
struct power_supply *battery;
struct power_supply *ac;
};
#define GOLDFISH_BATTERY_READ(data, addr) \
......@@ -67,8 +67,7 @@ static int goldfish_ac_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct goldfish_battery_data *data = container_of(psy,
struct goldfish_battery_data, ac);
struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
......@@ -86,8 +85,7 @@ static int goldfish_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct goldfish_battery_data *data = container_of(psy,
struct goldfish_battery_data, battery);
struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
......@@ -139,20 +137,36 @@ static irqreturn_t goldfish_battery_interrupt(int irq, void *dev_id)
status &= BATTERY_INT_MASK;
if (status & BATTERY_STATUS_CHANGED)
power_supply_changed(&data->battery);
power_supply_changed(data->battery);
if (status & AC_STATUS_CHANGED)
power_supply_changed(&data->ac);
power_supply_changed(data->ac);
spin_unlock_irqrestore(&data->lock, irq_flags);
return status ? IRQ_HANDLED : IRQ_NONE;
}
static const struct power_supply_desc battery_desc = {
.properties = goldfish_battery_props,
.num_properties = ARRAY_SIZE(goldfish_battery_props),
.get_property = goldfish_battery_get_property,
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
};
static const struct power_supply_desc ac_desc = {
.properties = goldfish_ac_props,
.num_properties = ARRAY_SIZE(goldfish_ac_props),
.get_property = goldfish_ac_get_property,
.name = "ac",
.type = POWER_SUPPLY_TYPE_MAINS,
};
static int goldfish_battery_probe(struct platform_device *pdev)
{
int ret;
struct resource *r;
struct goldfish_battery_data *data;
struct power_supply_config psy_cfg = {};
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (data == NULL)
......@@ -160,18 +174,6 @@ static int goldfish_battery_probe(struct platform_device *pdev)
spin_lock_init(&data->lock);
data->battery.properties = goldfish_battery_props;
data->battery.num_properties = ARRAY_SIZE(goldfish_battery_props);
data->battery.get_property = goldfish_battery_get_property;
data->battery.name = "battery";
data->battery.type = POWER_SUPPLY_TYPE_BATTERY;
data->ac.properties = goldfish_ac_props;
data->ac.num_properties = ARRAY_SIZE(goldfish_ac_props);
data->ac.get_property = goldfish_ac_get_property;
data->ac.name = "ac";
data->ac.type = POWER_SUPPLY_TYPE_MAINS;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (r == NULL) {
dev_err(&pdev->dev, "platform_get_resource failed\n");
......@@ -195,14 +197,17 @@ static int goldfish_battery_probe(struct platform_device *pdev)
if (ret)
return ret;
ret = power_supply_register(&pdev->dev, &data->ac, NULL);
if (ret)
return ret;
psy_cfg.drv_data = data;
ret = power_supply_register(&pdev->dev, &data->battery, NULL);
if (ret) {
power_supply_unregister(&data->ac);
return ret;
data->ac = power_supply_register(&pdev->dev, &ac_desc, &psy_cfg);
if (IS_ERR(data->ac))
return PTR_ERR(data->ac);
data->battery = power_supply_register(&pdev->dev, &battery_desc,
&psy_cfg);
if (IS_ERR(data->battery)) {
power_supply_unregister(data->ac);
return PTR_ERR(data->battery);
}
platform_set_drvdata(pdev, data);
......@@ -216,8 +221,8 @@ static int goldfish_battery_remove(struct platform_device *pdev)
{
struct goldfish_battery_data *data = platform_get_drvdata(pdev);
power_supply_unregister(&data->battery);
power_supply_unregister(&data->ac);
power_supply_unregister(data->battery);
power_supply_unregister(data->ac);
battery_data = NULL;
return 0;
}
......
......@@ -32,7 +32,8 @@ struct gpio_charger {
unsigned int irq;
bool wakeup_enabled;
struct power_supply charger;
struct power_supply *charger;
struct power_supply_desc charger_desc;
};
static irqreturn_t gpio_charger_irq(int irq, void *devid)
......@@ -46,7 +47,7 @@ static irqreturn_t gpio_charger_irq(int irq, void *devid)
static inline struct gpio_charger *psy_to_gpio_charger(struct power_supply *psy)
{
return container_of(psy, struct gpio_charger, charger);
return power_supply_get_drvdata(psy);
}
static int gpio_charger_get_property(struct power_supply *psy,
......@@ -129,7 +130,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data;
struct power_supply_config psy_cfg = {};
struct gpio_charger *gpio_charger;
struct power_supply *charger;
struct power_supply_desc *charger_desc;
int ret;
int irq;
......@@ -155,17 +156,18 @@ static int gpio_charger_probe(struct platform_device *pdev)
return -ENOMEM;
}
charger = &gpio_charger->charger;
charger_desc = &gpio_charger->charger_desc;
charger->name = pdata->name ? pdata->name : "gpio-charger";
charger->type = pdata->type;
charger->properties = gpio_charger_properties;
charger->num_properties = ARRAY_SIZE(gpio_charger_properties);
charger->get_property = gpio_charger_get_property;
charger_desc->name = pdata->name ? pdata->name : "gpio-charger";
charger_desc->type = pdata->type;
charger_desc->properties = gpio_charger_properties;
charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties);
charger_desc->get_property = gpio_charger_get_property;
psy_cfg.supplied_to = pdata->supplied_to;
psy_cfg.num_supplicants = pdata->num_supplicants;
psy_cfg.of_node = pdev->dev.of_node;
psy_cfg.drv_data = gpio_charger;
ret = gpio_request(pdata->gpio, dev_name(&pdev->dev));
if (ret) {
......@@ -180,8 +182,10 @@ static int gpio_charger_probe(struct platform_device *pdev)
gpio_charger->pdata = pdata;
ret = power_supply_register(&pdev->dev, charger, &psy_cfg);
if (ret < 0) {
gpio_charger->charger = power_supply_register(&pdev->dev,
charger_desc, &psy_cfg);
if (IS_ERR(gpio_charger->charger)) {
ret = PTR_ERR(gpio_charger->charger);
dev_err(&pdev->dev, "Failed to register power supply: %d\n",
ret);
goto err_gpio_free;
......@@ -191,7 +195,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
if (irq > 0) {
ret = request_any_context_irq(irq, gpio_charger_irq,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
dev_name(&pdev->dev), charger);
dev_name(&pdev->dev), gpio_charger->charger);
if (ret < 0)
dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret);
else
......@@ -215,9 +219,9 @@ static int gpio_charger_remove(struct platform_device *pdev)
struct gpio_charger *gpio_charger = platform_get_drvdata(pdev);
if (gpio_charger->irq)
free_irq(gpio_charger->irq, &gpio_charger->charger);
free_irq(gpio_charger->irq, gpio_charger->charger);
power_supply_unregister(&gpio_charger->charger);
power_supply_unregister(gpio_charger->charger);
gpio_free(gpio_charger->pdata->gpio);
......@@ -243,7 +247,7 @@ static int gpio_charger_resume(struct device *dev)
if (device_may_wakeup(dev) && gpio_charger->wakeup_enabled)
disable_irq_wake(gpio_charger->irq);
power_supply_changed(&gpio_charger->charger);
power_supply_changed(gpio_charger->charger);
return 0;
}
......
......@@ -107,8 +107,8 @@ struct pmic_power_module_info {
unsigned int batt_prev_charge_full; /* in mAS */
unsigned int batt_charge_rate; /* in units per second */
struct power_supply usb;
struct power_supply batt;
struct power_supply *usb;
struct power_supply *batt;
int irq; /* GPE_ID or IRQ# */
struct workqueue_struct *monitor_wqueue;
struct delayed_work monitor_battery;
......@@ -404,8 +404,7 @@ static int pmic_usb_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct pmic_power_module_info *pbi = container_of(psy,
struct pmic_power_module_info, usb);
struct pmic_power_module_info *pbi = power_supply_get_drvdata(psy);
/* update pmic_power_module_info members */
pmic_battery_read_status(pbi);
......@@ -444,8 +443,7 @@ static int pmic_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct pmic_power_module_info *pbi = container_of(psy,
struct pmic_power_module_info, batt);
struct pmic_power_module_info *pbi = power_supply_get_drvdata(psy);
/* update pmic_power_module_info members */
pmic_battery_read_status(pbi);
......@@ -640,6 +638,25 @@ static void pmic_battery_handle_intrpt(struct work_struct *work)
__func__);
}
/*
* Description of power supplies
*/
static const struct power_supply_desc pmic_usb_desc = {
.name = "pmic-usb",
.type = POWER_SUPPLY_TYPE_USB,
.properties = pmic_usb_props,
.num_properties = ARRAY_SIZE(pmic_usb_props),
.get_property = pmic_usb_get_property,
};
static const struct power_supply_desc pmic_batt_desc = {
.name = "pmic-batt",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = pmic_battery_props,
.num_properties = ARRAY_SIZE(pmic_battery_props),
.get_property = pmic_battery_get_property,
};
/**
* pmic_battery_probe - pmic battery initialize
* @irq: pmic battery device irq
......@@ -653,6 +670,7 @@ static int probe(int irq, struct device *dev)
{
int retval = 0;
struct pmic_power_module_info *pbi;
struct power_supply_config psy_cfg = {};
dev_dbg(dev, "pmic-battery: found pmic battery device\n");
......@@ -666,6 +684,7 @@ static int probe(int irq, struct device *dev)
pbi->dev = dev;
pbi->irq = irq;
dev_set_drvdata(dev, pbi);
psy_cfg.drv_data = pbi;
/* initialize all required framework before enabling interrupts */
INIT_WORK(&pbi->handler, pmic_battery_handle_intrpt);
......@@ -687,16 +706,12 @@ static int probe(int irq, struct device *dev)
}
/* register pmic-batt with power supply subsystem */
pbi->batt.name = "pmic-batt";
pbi->batt.type = POWER_SUPPLY_TYPE_BATTERY;
pbi->batt.properties = pmic_battery_props;
pbi->batt.num_properties = ARRAY_SIZE(pmic_battery_props);
pbi->batt.get_property = pmic_battery_get_property;
retval = power_supply_register(dev, &pbi->batt, NULL);
if (retval) {
pbi->batt = power_supply_register(dev, &pmic_usb_desc, &psy_cfg);
if (IS_ERR(pbi->batt)) {
dev_err(dev,
"%s(): failed to register pmic battery device with power supply subsystem\n",
__func__);
retval = PTR_ERR(pbi->batt);
goto power_reg_failed;
}
......@@ -707,16 +722,12 @@ static int probe(int irq, struct device *dev)
queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 1);
/* register pmic-usb with power supply subsystem */
pbi->usb.name = "pmic-usb";
pbi->usb.type = POWER_SUPPLY_TYPE_USB;
pbi->usb.properties = pmic_usb_props;
pbi->usb.num_properties = ARRAY_SIZE(pmic_usb_props);
pbi->usb.get_property = pmic_usb_get_property;
retval = power_supply_register(dev, &pbi->usb, NULL);
if (retval) {
pbi->usb = power_supply_register(dev, &pmic_batt_desc, &psy_cfg);
if (IS_ERR(pbi->usb)) {
dev_err(dev,
"%s(): failed to register pmic usb device with power supply subsystem\n",
__func__);
retval = PTR_ERR(pbi->usb);
goto power_reg_failed_1;
}
......@@ -728,7 +739,7 @@ static int probe(int irq, struct device *dev)
return retval;
power_reg_failed_1:
power_supply_unregister(&pbi->batt);
power_supply_unregister(pbi->batt);
power_reg_failed:
cancel_delayed_work_sync(&pbi->monitor_battery);
requestirq_failed:
......@@ -762,8 +773,8 @@ static int platform_pmic_battery_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&pbi->monitor_battery);
destroy_workqueue(pbi->monitor_wqueue);
power_supply_unregister(&pbi->usb);
power_supply_unregister(&pbi->batt);
power_supply_unregister(pbi->usb);
power_supply_unregister(pbi->batt);
cancel_work_sync(&pbi->handler);
kfree(pbi);
......
......@@ -93,7 +93,7 @@ static void micro_battery_work(struct work_struct *work)
static int get_capacity(struct power_supply *b)
{
struct micro_battery *mb = dev_get_drvdata(b->dev->parent);
struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
switch (mb->flag & 0x07) {
case MICRO_BATT_STATUS_HIGH:
......@@ -113,7 +113,7 @@ static int get_capacity(struct power_supply *b)
static int get_status(struct power_supply *b)
{
struct micro_battery *mb = dev_get_drvdata(b->dev->parent);
struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
if (mb->flag == MICRO_BATT_STATUS_UNKNOWN)
return POWER_SUPPLY_STATUS_UNKNOWN;
......@@ -132,7 +132,7 @@ static int micro_batt_get_property(struct power_supply *b,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct micro_battery *mb = dev_get_drvdata(b->dev->parent);
struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
switch (psp) {
case POWER_SUPPLY_PROP_TECHNOLOGY:
......@@ -180,7 +180,7 @@ static int micro_ac_get_property(struct power_supply *b,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct micro_battery *mb = dev_get_drvdata(b->dev->parent);
struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
......@@ -202,7 +202,7 @@ static enum power_supply_property micro_batt_power_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
};
static struct power_supply micro_batt_power = {
static const struct power_supply_desc micro_batt_power_desc = {
.name = "main-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = micro_batt_power_props,
......@@ -215,7 +215,7 @@ static enum power_supply_property micro_ac_power_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
static struct power_supply micro_ac_power = {
static const struct power_supply_desc micro_ac_power_desc = {
.name = "ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = micro_ac_power_props,
......@@ -223,6 +223,8 @@ static struct power_supply micro_ac_power = {
.get_property = micro_ac_get_property,
};
static struct power_supply *micro_batt_power, *micro_ac_power;
static int micro_batt_probe(struct platform_device *pdev)
{
struct micro_battery *mb;
......@@ -241,19 +243,25 @@ static int micro_batt_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, mb);
queue_delayed_work(mb->wq, &mb->update, 1);
ret = power_supply_register(&pdev->dev, &micro_batt_power, NULL);
if (ret < 0)
micro_batt_power = power_supply_register(&pdev->dev,
&micro_batt_power_desc, NULL);
if (IS_ERR(micro_batt_power)) {
ret = PTR_ERR(micro_batt_power);
goto batt_err;
}
ret = power_supply_register(&pdev->dev, &micro_ac_power, NULL);
if (ret < 0)
micro_ac_power = power_supply_register(&pdev->dev,
&micro_ac_power_desc, NULL);
if (IS_ERR(micro_ac_power)) {
ret = PTR_ERR(micro_ac_power);
goto ac_err;
}
dev_info(&pdev->dev, "iPAQ micro battery driver\n");
return 0;
ac_err:
power_supply_unregister(&micro_ac_power);
power_supply_unregister(micro_ac_power);
batt_err:
cancel_delayed_work_sync(&mb->update);
destroy_workqueue(mb->wq);
......@@ -265,8 +273,8 @@ static int micro_batt_remove(struct platform_device *pdev)
{
struct micro_battery *mb = platform_get_drvdata(pdev);
power_supply_unregister(&micro_ac_power);
power_supply_unregister(&micro_batt_power);
power_supply_unregister(micro_ac_power);
power_supply_unregister(micro_batt_power);
cancel_delayed_work_sync(&mb->update);
destroy_workqueue(mb->wq);
......
......@@ -57,11 +57,12 @@ static u16 isp170x_id[] = {
};
struct isp1704_charger {
struct device *dev;
struct power_supply psy;
struct usb_phy *phy;
struct notifier_block nb;
struct work_struct work;
struct device *dev;
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct usb_phy *phy;
struct notifier_block nb;
struct work_struct work;
/* properties */
char model[8];
......@@ -259,10 +260,10 @@ static void isp1704_charger_work(struct work_struct *data)
/* detect wall charger */
if (isp1704_charger_detect_dcp(isp)) {
isp->psy.type = POWER_SUPPLY_TYPE_USB_DCP;
isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_DCP;
isp->current_max = 1800;
} else {
isp->psy.type = POWER_SUPPLY_TYPE_USB;
isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
isp->current_max = 500;
}
......@@ -271,7 +272,7 @@ static void isp1704_charger_work(struct work_struct *data)
usb_gadget_connect(isp->phy->otg->gadget);
}
if (isp->psy.type != POWER_SUPPLY_TYPE_USB_DCP) {
if (isp->psy_desc.type != POWER_SUPPLY_TYPE_USB_DCP) {
/*
* Only 500mA here or high speed chirp
* handshaking may break
......@@ -280,14 +281,14 @@ static void isp1704_charger_work(struct work_struct *data)
isp->current_max = 500;
if (isp->current_max > 100)
isp->psy.type = POWER_SUPPLY_TYPE_USB_CDP;
isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_CDP;
}
break;
case USB_EVENT_NONE:
isp->online = false;
isp->present = 0;
isp->current_max = 0;
isp->psy.type = POWER_SUPPLY_TYPE_USB;
isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
/*
* Disable data pullups. We need to prevent the controller from
......@@ -306,7 +307,7 @@ static void isp1704_charger_work(struct work_struct *data)
goto out;
}
power_supply_changed(&isp->psy);
power_supply_changed(isp->psy);
out:
mutex_unlock(&lock);
}
......@@ -326,8 +327,7 @@ static int isp1704_charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct isp1704_charger *isp =
container_of(psy, struct isp1704_charger, psy);
struct isp1704_charger *isp = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_PRESENT:
......@@ -403,6 +403,7 @@ static int isp1704_charger_probe(struct platform_device *pdev)
{
struct isp1704_charger *isp;
int ret = -ENODEV;
struct power_supply_config psy_cfg = {};
struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev);
struct device_node *np = pdev->dev.of_node;
......@@ -454,15 +455,19 @@ static int isp1704_charger_probe(struct platform_device *pdev)
if (ret < 0)
goto fail1;
isp->psy.name = "isp1704";
isp->psy.type = POWER_SUPPLY_TYPE_USB;
isp->psy.properties = power_props;
isp->psy.num_properties = ARRAY_SIZE(power_props);
isp->psy.get_property = isp1704_charger_get_property;
isp->psy_desc.name = "isp1704";
isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
isp->psy_desc.properties = power_props;
isp->psy_desc.num_properties = ARRAY_SIZE(power_props);
isp->psy_desc.get_property = isp1704_charger_get_property;
ret = power_supply_register(isp->dev, &isp->psy, NULL);
if (ret)
psy_cfg.drv_data = isp;
isp->psy = power_supply_register(isp->dev, &isp->psy_desc, &psy_cfg);
if (IS_ERR(isp->psy)) {
ret = PTR_ERR(isp->psy);
goto fail1;
}
/*
* REVISIT: using work in order to allow the usb notifications to be
......@@ -498,7 +503,7 @@ static int isp1704_charger_probe(struct platform_device *pdev)
return 0;
fail2:
power_supply_unregister(&isp->psy);
power_supply_unregister(isp->psy);
fail1:
isp1704_charger_set_power(isp, 0);
fail0:
......@@ -512,7 +517,7 @@ static int isp1704_charger_remove(struct platform_device *pdev)
struct isp1704_charger *isp = platform_get_drvdata(pdev);
usb_unregister_notifier(isp->phy, &isp->nb);
power_supply_unregister(&isp->psy);
power_supply_unregister(isp->psy);
isp1704_charger_set_power(isp, 0);
return 0;
......
......@@ -46,7 +46,8 @@ struct jz_battery {
struct completion read_completion;
struct power_supply battery;
struct power_supply *battery;
struct power_supply_desc battery_desc;
struct delayed_work work;
struct mutex lock;
......@@ -54,7 +55,7 @@ struct jz_battery {
static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy)
{
return container_of(psy, struct jz_battery, battery);
return power_supply_get_drvdata(psy);
}
static irqreturn_t jz_battery_irq_handler(int irq, void *devid)
......@@ -213,7 +214,7 @@ static void jz_battery_update(struct jz_battery *jz_battery)
}
if (has_changed)
power_supply_changed(&jz_battery->battery);
power_supply_changed(jz_battery->battery);
}
static enum power_supply_property jz_battery_properties[] = {
......@@ -242,8 +243,9 @@ static int jz_battery_probe(struct platform_device *pdev)
{
int ret = 0;
struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data;
struct power_supply_config psy_cfg = {};
struct jz_battery *jz_battery;
struct power_supply *battery;
struct power_supply_desc *battery_desc;
struct resource *mem;
if (!pdata) {
......@@ -271,14 +273,17 @@ static int jz_battery_probe(struct platform_device *pdev)
if (IS_ERR(jz_battery->base))
return PTR_ERR(jz_battery->base);
battery = &jz_battery->battery;
battery->name = pdata->info.name;
battery->type = POWER_SUPPLY_TYPE_BATTERY;
battery->properties = jz_battery_properties;
battery->num_properties = ARRAY_SIZE(jz_battery_properties);
battery->get_property = jz_battery_get_property;
battery->external_power_changed = jz_battery_external_power_changed;
battery->use_for_apm = 1;
battery_desc = &jz_battery->battery_desc;
battery_desc->name = pdata->info.name;
battery_desc->type = POWER_SUPPLY_TYPE_BATTERY;
battery_desc->properties = jz_battery_properties;
battery_desc->num_properties = ARRAY_SIZE(jz_battery_properties);
battery_desc->get_property = jz_battery_get_property;
battery_desc->external_power_changed =
jz_battery_external_power_changed;
battery_desc->use_for_apm = 1;
psy_cfg.drv_data = jz_battery;
jz_battery->pdata = pdata;
jz_battery->pdev = pdev;
......@@ -330,9 +335,11 @@ static int jz_battery_probe(struct platform_device *pdev)
else
jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0);
ret = power_supply_register(&pdev->dev, &jz_battery->battery, NULL);
if (ret) {
jz_battery->battery = power_supply_register(&pdev->dev, battery_desc,
&psy_cfg);
if (IS_ERR(jz_battery->battery)) {
dev_err(&pdev->dev, "power supply battery register failed.\n");
ret = PTR_ERR(jz_battery->battery);
goto err_free_charge_irq;
}
......@@ -364,7 +371,7 @@ static int jz_battery_remove(struct platform_device *pdev)
gpio_free(jz_battery->pdata->gpio_charge);
}
power_supply_unregister(&jz_battery->battery);
power_supply_unregister(jz_battery->battery);
free_irq(jz_battery->irq, jz_battery);
......
This diff is collapsed.
......@@ -105,8 +105,8 @@ struct lp8788_chg_irq {
*/
struct lp8788_charger {
struct lp8788 *lp;
struct power_supply charger;
struct power_supply battery;
struct power_supply *charger;
struct power_supply *battery;
struct work_struct charger_work;
struct iio_channel *chan[LP8788_NUM_CHG_ADC];
struct lp8788_chg_irq irqs[LP8788_MAX_CHG_IRQS];
......@@ -148,7 +148,7 @@ static int lp8788_charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct lp8788_charger *pchg = dev_get_drvdata(psy->dev->parent);
struct lp8788_charger *pchg = dev_get_drvdata(psy->dev.parent);
u8 read;
switch (psp) {
......@@ -337,7 +337,7 @@ static int lp8788_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct lp8788_charger *pchg = dev_get_drvdata(psy->dev->parent);
struct lp8788_charger *pchg = dev_get_drvdata(psy->dev.parent);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
......@@ -397,31 +397,40 @@ static int lp8788_update_charger_params(struct platform_device *pdev,
return 0;
}
static const struct power_supply_desc lp8788_psy_charger_desc = {
.name = LP8788_CHARGER_NAME,
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = lp8788_charger_prop,
.num_properties = ARRAY_SIZE(lp8788_charger_prop),
.get_property = lp8788_charger_get_property,
};
static const struct power_supply_desc lp8788_psy_battery_desc = {
.name = LP8788_BATTERY_NAME,
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = lp8788_battery_prop,
.num_properties = ARRAY_SIZE(lp8788_battery_prop),
.get_property = lp8788_battery_get_property,
};
static int lp8788_psy_register(struct platform_device *pdev,
struct lp8788_charger *pchg)
{
struct power_supply_config charger_cfg = {};
pchg->charger.name = LP8788_CHARGER_NAME;
pchg->charger.type = POWER_SUPPLY_TYPE_MAINS;
pchg->charger.properties = lp8788_charger_prop;
pchg->charger.num_properties = ARRAY_SIZE(lp8788_charger_prop);
pchg->charger.get_property = lp8788_charger_get_property;
charger_cfg.supplied_to = battery_supplied_to;
charger_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to);
if (power_supply_register(&pdev->dev, &pchg->charger, &charger_cfg))
pchg->charger = power_supply_register(&pdev->dev,
&lp8788_psy_charger_desc,
&charger_cfg);
if (IS_ERR(pchg->charger))
return -EPERM;
pchg->battery.name = LP8788_BATTERY_NAME;
pchg->battery.type = POWER_SUPPLY_TYPE_BATTERY;
pchg->battery.properties = lp8788_battery_prop;
pchg->battery.num_properties = ARRAY_SIZE(lp8788_battery_prop);
pchg->battery.get_property = lp8788_battery_get_property;
if (power_supply_register(&pdev->dev, &pchg->battery, NULL)) {
power_supply_unregister(&pchg->charger);
pchg->battery = power_supply_register(&pdev->dev,
&lp8788_psy_battery_desc, NULL);
if (IS_ERR(pchg->battery)) {
power_supply_unregister(pchg->charger);
return -EPERM;
}
......@@ -430,8 +439,8 @@ static int lp8788_psy_register(struct platform_device *pdev,
static void lp8788_psy_unregister(struct lp8788_charger *pchg)
{
power_supply_unregister(&pchg->battery);
power_supply_unregister(&pchg->charger);
power_supply_unregister(pchg->battery);
power_supply_unregister(pchg->charger);
}
static void lp8788_charger_event(struct work_struct *work)
......@@ -475,8 +484,8 @@ static irqreturn_t lp8788_charger_irq_thread(int virq, void *ptr)
case LP8788_INT_EOC:
case LP8788_INT_BATT_LOW:
case LP8788_INT_NO_BATT:
power_supply_changed(&pchg->charger);
power_supply_changed(&pchg->battery);
power_supply_changed(pchg->charger);
power_supply_changed(pchg->battery);
break;
default:
break;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -486,6 +486,7 @@ struct pm2xxx_charger {
struct work_struct check_main_thermal_prot_work;
struct delayed_work check_hw_failure_work;
struct ux500_charger ac_chg;
struct power_supply_desc ac_chg_desc;
struct pm2xxx_charger_event_flags flags;
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -514,10 +514,10 @@ struct hid_device { /* device report descriptor */
#ifdef CONFIG_HID_BATTERY_STRENGTH
/*
* Power supply information for HID devices which report
* battery strength. power_supply is registered iff
* battery.name is non-NULL.
* battery strength. power_supply was successfully registered if
* battery is non-NULL.
*/
struct power_supply battery;
struct power_supply *battery;
__s32 battery_min;
__s32 battery_max;
__s32 battery_report_type;
......
This diff is collapsed.
......@@ -39,7 +39,7 @@ struct rt5033_battery {
struct i2c_client *client;
struct rt5033_dev *rt5033;
struct regmap *regmap;
struct power_supply psy;
struct power_supply *psy;
};
/* RT5033 charger platform data */
......
......@@ -123,9 +123,9 @@ struct wm8350_charger_policy {
struct wm8350_power {
struct platform_device *pdev;
struct power_supply battery;
struct power_supply usb;
struct power_supply ac;
struct power_supply *battery;
struct power_supply *usb;
struct power_supply *ac;
struct wm8350_charger_policy *policy;
int rev_g_coeff;
......
This diff is collapsed.
This diff is collapsed.
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