aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>2015-03-12 03:44:11 -0400
committerSebastian Reichel <sre@kernel.org>2015-03-13 18:15:51 -0400
commit297d716f6260cc9421d971b124ca196b957ee458 (patch)
tree32a666d3374d7f0653258c766252bd6a841f05ab /drivers
parentb70229bca127283c3d30e5f471d30b1acccd7096 (diff)
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: Krzysztof Kozlowski <k.kozlowski@samsung.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> [for the nvec part] Reviewed-by: Marc Dietrich <marvin24@gmx.de> [for compal-laptop.c] Acked-by: Darren Hart <dvhart@linux.intel.com> [for the mfd part] Acked-by: Lee Jones <lee.jones@linaro.org> [for the hid part] Acked-by: Jiri Kosina <jkosina@suse.cz> [for the acpi part] Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/ac.c32
-rw-r--r--drivers/acpi/battery.c55
-rw-r--r--drivers/acpi/sbs.c68
-rw-r--r--drivers/hid/hid-input.c51
-rw-r--r--drivers/hid/hid-sony.c43
-rw-r--r--drivers/hid/hid-wiimote-modules.c41
-rw-r--r--drivers/hid/hid-wiimote.h3
-rw-r--r--drivers/hid/wacom.h8
-rw-r--r--drivers/hid/wacom_sys.c71
-rw-r--r--drivers/platform/x86/compal-laptop.c29
-rw-r--r--drivers/power/88pm860x_battery.c40
-rw-r--r--drivers/power/88pm860x_charger.c32
-rw-r--r--drivers/power/ab8500_btemp.c68
-rw-r--r--drivers/power/ab8500_charger.c136
-rw-r--r--drivers/power/ab8500_fg.c124
-rw-r--r--drivers/power/abx500_chargalg.c90
-rw-r--r--drivers/power/apm_power.c2
-rw-r--r--drivers/power/axp288_fuel_gauge.c47
-rw-r--r--drivers/power/bq2415x_charger.c73
-rw-r--r--drivers/power/bq24190_charger.c103
-rw-r--r--drivers/power/bq24735-charger.c45
-rw-r--r--drivers/power/bq27x00_battery.c74
-rw-r--r--drivers/power/charger-manager.c54
-rw-r--r--drivers/power/collie_battery.c75
-rw-r--r--drivers/power/da9030_battery.c33
-rw-r--r--drivers/power/da9052-battery.c25
-rw-r--r--drivers/power/da9150-charger.c80
-rw-r--r--drivers/power/ds2760_battery.c56
-rw-r--r--drivers/power/ds2780_battery.c45
-rw-r--r--drivers/power/ds2781_battery.c47
-rw-r--r--drivers/power/ds2782_battery.c30
-rw-r--r--drivers/power/generic-adc-battery.c54
-rw-r--r--drivers/power/goldfish_battery.c63
-rw-r--r--drivers/power/gpio-charger.c34
-rw-r--r--drivers/power/intel_mid_battery.c57
-rw-r--r--drivers/power/ipaq_micro_battery.c34
-rw-r--r--drivers/power/isp1704_charger.c49
-rw-r--r--drivers/power/jz4740-battery.c37
-rw-r--r--drivers/power/lp8727_charger.c88
-rw-r--r--drivers/power/lp8788-charger.c55
-rw-r--r--drivers/power/ltc2941-battery-gauge.c51
-rw-r--r--drivers/power/max14577_charger.c34
-rw-r--r--drivers/power/max17040_battery.c31
-rw-r--r--drivers/power/max17042_battery.c45
-rw-r--r--drivers/power/max77693_charger.c32
-rw-r--r--drivers/power/max8903_charger.c52
-rw-r--r--drivers/power/max8925_power.c88
-rw-r--r--drivers/power/max8997_charger.c31
-rw-r--r--drivers/power/max8998_charger.c32
-rw-r--r--drivers/power/olpc_battery.c54
-rw-r--r--drivers/power/pcf50633-charger.c95
-rw-r--r--drivers/power/pda_power.c52
-rw-r--r--drivers/power/pm2301_charger.c42
-rw-r--r--drivers/power/pm2301_charger.h1
-rw-r--r--drivers/power/pmu_battery.c42
-rw-r--r--drivers/power/power_supply_core.c242
-rw-r--r--drivers/power/power_supply_leds.c25
-rw-r--r--drivers/power/power_supply_sysfs.c20
-rw-r--r--drivers/power/rt5033_battery.c27
-rw-r--r--drivers/power/rx51_battery.c27
-rw-r--r--drivers/power/s3c_adc_battery.c77
-rw-r--r--drivers/power/sbs-battery.c69
-rw-r--r--drivers/power/smb347-charger.c107
-rw-r--r--drivers/power/test_power.c34
-rw-r--r--drivers/power/tosa_battery.c112
-rw-r--r--drivers/power/tps65090-charger.c35
-rw-r--r--drivers/power/twl4030_charger.c65
-rw-r--r--drivers/power/twl4030_madc_battery.c41
-rw-r--r--drivers/power/wm831x_backup.c26
-rw-r--r--drivers/power/wm831x_power.c95
-rw-r--r--drivers/power/wm8350_power.c89
-rw-r--r--drivers/power/wm97xx_battery.c37
-rw-r--r--drivers/power/z2_battery.c60
-rw-r--r--drivers/staging/nvec/nvec_power.c29
74 files changed, 2245 insertions, 1805 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 8bf516885ede..bbcc2b5a70d4 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -95,13 +95,14 @@ static struct acpi_driver acpi_ac_driver = {
95}; 95};
96 96
97struct acpi_ac { 97struct acpi_ac {
98 struct power_supply charger; 98 struct power_supply *charger;
99 struct power_supply_desc charger_desc;
99 struct acpi_device * device; 100 struct acpi_device * device;
100 unsigned long long state; 101 unsigned long long state;
101 struct notifier_block battery_nb; 102 struct notifier_block battery_nb;
102}; 103};
103 104
104#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger) 105#define to_acpi_ac(x) power_supply_get_drvdata(x)
105 106
106#ifdef CONFIG_ACPI_PROCFS_POWER 107#ifdef CONFIG_ACPI_PROCFS_POWER
107static const struct file_operations acpi_ac_fops = { 108static const struct file_operations acpi_ac_fops = {
@@ -275,7 +276,7 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event)
275 dev_name(&device->dev), event, 276 dev_name(&device->dev), event,
276 (u32) ac->state); 277 (u32) ac->state);
277 acpi_notifier_call_chain(device, event, (u32) ac->state); 278 acpi_notifier_call_chain(device, event, (u32) ac->state);
278 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); 279 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
279 } 280 }
280 281
281 return; 282 return;
@@ -321,6 +322,7 @@ static struct dmi_system_id ac_dmi_table[] = {
321 322
322static int acpi_ac_add(struct acpi_device *device) 323static int acpi_ac_add(struct acpi_device *device)
323{ 324{
325 struct power_supply_config psy_cfg = {};
324 int result = 0; 326 int result = 0;
325 struct acpi_ac *ac = NULL; 327 struct acpi_ac *ac = NULL;
326 328
@@ -341,19 +343,24 @@ static int acpi_ac_add(struct acpi_device *device)
341 if (result) 343 if (result)
342 goto end; 344 goto end;
343 345
344 ac->charger.name = acpi_device_bid(device); 346 psy_cfg.drv_data = ac;
347
348 ac->charger_desc.name = acpi_device_bid(device);
345#ifdef CONFIG_ACPI_PROCFS_POWER 349#ifdef CONFIG_ACPI_PROCFS_POWER
346 result = acpi_ac_add_fs(ac); 350 result = acpi_ac_add_fs(ac);
347 if (result) 351 if (result)
348 goto end; 352 goto end;
349#endif 353#endif
350 ac->charger.type = POWER_SUPPLY_TYPE_MAINS; 354 ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
351 ac->charger.properties = ac_props; 355 ac->charger_desc.properties = ac_props;
352 ac->charger.num_properties = ARRAY_SIZE(ac_props); 356 ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
353 ac->charger.get_property = get_ac_property; 357 ac->charger_desc.get_property = get_ac_property;
354 result = power_supply_register(&ac->device->dev, &ac->charger, NULL); 358 ac->charger = power_supply_register(&ac->device->dev,
355 if (result) 359 &ac->charger_desc, &psy_cfg);
360 if (IS_ERR(ac->charger)) {
361 result = PTR_ERR(ac->charger);
356 goto end; 362 goto end;
363 }
357 364
358 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", 365 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
359 acpi_device_name(device), acpi_device_bid(device), 366 acpi_device_name(device), acpi_device_bid(device),
@@ -390,7 +397,7 @@ static int acpi_ac_resume(struct device *dev)
390 if (acpi_ac_get_state(ac)) 397 if (acpi_ac_get_state(ac))
391 return 0; 398 return 0;
392 if (old_state != ac->state) 399 if (old_state != ac->state)
393 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); 400 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
394 return 0; 401 return 0;
395} 402}
396#else 403#else
@@ -407,8 +414,7 @@ static int acpi_ac_remove(struct acpi_device *device)
407 414
408 ac = acpi_driver_data(device); 415 ac = acpi_driver_data(device);
409 416
410 if (ac->charger.dev) 417 power_supply_unregister(ac->charger);
411 power_supply_unregister(&ac->charger);
412 unregister_acpi_notifier(&ac->battery_nb); 418 unregister_acpi_notifier(&ac->battery_nb);
413 419
414#ifdef CONFIG_ACPI_PROCFS_POWER 420#ifdef CONFIG_ACPI_PROCFS_POWER
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index fd8c06f492a1..fdc16ce9d272 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -117,7 +117,8 @@ enum {
117struct acpi_battery { 117struct acpi_battery {
118 struct mutex lock; 118 struct mutex lock;
119 struct mutex sysfs_lock; 119 struct mutex sysfs_lock;
120 struct power_supply bat; 120 struct power_supply *bat;
121 struct power_supply_desc bat_desc;
121 struct acpi_device *device; 122 struct acpi_device *device;
122 struct notifier_block pm_nb; 123 struct notifier_block pm_nb;
123 unsigned long update_time; 124 unsigned long update_time;
@@ -149,7 +150,7 @@ struct acpi_battery {
149 unsigned long flags; 150 unsigned long flags;
150}; 151};
151 152
152#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat) 153#define to_acpi_battery(x) power_supply_get_drvdata(x)
153 154
154static inline int acpi_battery_present(struct acpi_battery *battery) 155static inline int acpi_battery_present(struct acpi_battery *battery)
155{ 156{
@@ -608,41 +609,45 @@ static struct device_attribute alarm_attr = {
608 609
609static int sysfs_add_battery(struct acpi_battery *battery) 610static int sysfs_add_battery(struct acpi_battery *battery)
610{ 611{
611 int result; 612 struct power_supply_config psy_cfg = { .drv_data = battery, };
612 613
613 if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) { 614 if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) {
614 battery->bat.properties = charge_battery_props; 615 battery->bat_desc.properties = charge_battery_props;
615 battery->bat.num_properties = 616 battery->bat_desc.num_properties =
616 ARRAY_SIZE(charge_battery_props); 617 ARRAY_SIZE(charge_battery_props);
617 } else { 618 } else {
618 battery->bat.properties = energy_battery_props; 619 battery->bat_desc.properties = energy_battery_props;
619 battery->bat.num_properties = 620 battery->bat_desc.num_properties =
620 ARRAY_SIZE(energy_battery_props); 621 ARRAY_SIZE(energy_battery_props);
621 } 622 }
622 623
623 battery->bat.name = acpi_device_bid(battery->device); 624 battery->bat_desc.name = acpi_device_bid(battery->device);
624 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; 625 battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
625 battery->bat.get_property = acpi_battery_get_property; 626 battery->bat_desc.get_property = acpi_battery_get_property;
626 627
627 result = power_supply_register_no_ws(&battery->device->dev, 628 battery->bat = power_supply_register_no_ws(&battery->device->dev,
628 &battery->bat, NULL); 629 &battery->bat_desc, &psy_cfg);
629 630
630 if (result) 631 if (IS_ERR(battery->bat)) {
632 int result = PTR_ERR(battery->bat);
633
634 battery->bat = NULL;
631 return result; 635 return result;
632 return device_create_file(battery->bat.dev, &alarm_attr); 636 }
637 return device_create_file(&battery->bat->dev, &alarm_attr);
633} 638}
634 639
635static void sysfs_remove_battery(struct acpi_battery *battery) 640static void sysfs_remove_battery(struct acpi_battery *battery)
636{ 641{
637 mutex_lock(&battery->sysfs_lock); 642 mutex_lock(&battery->sysfs_lock);
638 if (!battery->bat.dev) { 643 if (!battery->bat) {
639 mutex_unlock(&battery->sysfs_lock); 644 mutex_unlock(&battery->sysfs_lock);
640 return; 645 return;
641 } 646 }
642 647
643 device_remove_file(battery->bat.dev, &alarm_attr); 648 device_remove_file(&battery->bat->dev, &alarm_attr);
644 power_supply_unregister(&battery->bat); 649 power_supply_unregister(battery->bat);
645 battery->bat.dev = NULL; 650 battery->bat = NULL;
646 mutex_unlock(&battery->sysfs_lock); 651 mutex_unlock(&battery->sysfs_lock);
647} 652}
648 653
@@ -739,7 +744,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
739 return result; 744 return result;
740 acpi_battery_init_alarm(battery); 745 acpi_battery_init_alarm(battery);
741 } 746 }
742 if (!battery->bat.dev) { 747 if (!battery->bat) {
743 result = sysfs_add_battery(battery); 748 result = sysfs_add_battery(battery);
744 if (result) 749 if (result)
745 return result; 750 return result;
@@ -765,7 +770,7 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
765{ 770{
766 int power_unit; 771 int power_unit;
767 772
768 if (!battery->bat.dev) 773 if (!battery->bat)
769 return; 774 return;
770 775
771 power_unit = battery->power_unit; 776 power_unit = battery->power_unit;
@@ -1063,11 +1068,11 @@ static void acpi_battery_remove_fs(struct acpi_device *device)
1063static void acpi_battery_notify(struct acpi_device *device, u32 event) 1068static void acpi_battery_notify(struct acpi_device *device, u32 event)
1064{ 1069{
1065 struct acpi_battery *battery = acpi_driver_data(device); 1070 struct acpi_battery *battery = acpi_driver_data(device);
1066 struct device *old; 1071 struct power_supply *old;
1067 1072
1068 if (!battery) 1073 if (!battery)
1069 return; 1074 return;
1070 old = battery->bat.dev; 1075 old = battery->bat;
1071 /* 1076 /*
1072 * On Acer Aspire V5-573G notifications are sometimes triggered too 1077 * On Acer Aspire V5-573G notifications are sometimes triggered too
1073 * early. For example, when AC is unplugged and notification is 1078 * 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)
1084 acpi_battery_present(battery)); 1089 acpi_battery_present(battery));
1085 acpi_notifier_call_chain(device, event, acpi_battery_present(battery)); 1090 acpi_notifier_call_chain(device, event, acpi_battery_present(battery));
1086 /* acpi_battery_update could remove power_supply object */ 1091 /* acpi_battery_update could remove power_supply object */
1087 if (old && battery->bat.dev) 1092 if (old && battery->bat)
1088 power_supply_changed(&battery->bat); 1093 power_supply_changed(battery->bat);
1089} 1094}
1090 1095
1091static int battery_notify(struct notifier_block *nb, 1096static int battery_notify(struct notifier_block *nb,
@@ -1101,7 +1106,7 @@ static int battery_notify(struct notifier_block *nb,
1101 if (!acpi_battery_present(battery)) 1106 if (!acpi_battery_present(battery))
1102 return 0; 1107 return 0;
1103 1108
1104 if (!battery->bat.dev) { 1109 if (battery->bat) {
1105 result = acpi_battery_get_info(battery); 1110 result = acpi_battery_get_info(battery);
1106 if (result) 1111 if (result)
1107 return result; 1112 return result;
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 2038ec1d021d..cd827625cf07 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -74,7 +74,8 @@ static const struct acpi_device_id sbs_device_ids[] = {
74MODULE_DEVICE_TABLE(acpi, sbs_device_ids); 74MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
75 75
76struct acpi_battery { 76struct acpi_battery {
77 struct power_supply bat; 77 struct power_supply *bat;
78 struct power_supply_desc bat_desc;
78 struct acpi_sbs *sbs; 79 struct acpi_sbs *sbs;
79 unsigned long update_time; 80 unsigned long update_time;
80 char name[8]; 81 char name[8];
@@ -101,10 +102,10 @@ struct acpi_battery {
101 u8 have_sysfs_alarm:1; 102 u8 have_sysfs_alarm:1;
102}; 103};
103 104
104#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat) 105#define to_acpi_battery(x) power_supply_get_drvdata(x)
105 106
106struct acpi_sbs { 107struct acpi_sbs {
107 struct power_supply charger; 108 struct power_supply *charger;
108 struct acpi_device *device; 109 struct acpi_device *device;
109 struct acpi_smb_hc *hc; 110 struct acpi_smb_hc *hc;
110 struct mutex lock; 111 struct mutex lock;
@@ -115,7 +116,7 @@ struct acpi_sbs {
115 u8 charger_exists:1; 116 u8 charger_exists:1;
116}; 117};
117 118
118#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger) 119#define to_acpi_sbs(x) power_supply_get_drvdata(x)
119 120
120static int acpi_sbs_remove(struct acpi_device *device); 121static int acpi_sbs_remove(struct acpi_device *device);
121static int acpi_battery_get_state(struct acpi_battery *battery); 122static int acpi_battery_get_state(struct acpi_battery *battery);
@@ -303,6 +304,13 @@ static enum power_supply_property sbs_energy_battery_props[] = {
303 POWER_SUPPLY_PROP_MANUFACTURER, 304 POWER_SUPPLY_PROP_MANUFACTURER,
304}; 305};
305 306
307static const struct power_supply_desc acpi_sbs_charger_desc = {
308 .name = "sbs-charger",
309 .type = POWER_SUPPLY_TYPE_MAINS,
310 .properties = sbs_ac_props,
311 .num_properties = ARRAY_SIZE(sbs_ac_props),
312 .get_property = sbs_get_ac_property,
313};
306 314
307/* -------------------------------------------------------------------------- 315/* --------------------------------------------------------------------------
308 Smart Battery System Management 316 Smart Battery System Management
@@ -519,6 +527,7 @@ static int acpi_battery_read(struct acpi_battery *battery)
519static int acpi_battery_add(struct acpi_sbs *sbs, int id) 527static int acpi_battery_add(struct acpi_sbs *sbs, int id)
520{ 528{
521 struct acpi_battery *battery = &sbs->battery[id]; 529 struct acpi_battery *battery = &sbs->battery[id];
530 struct power_supply_config psy_cfg = { .drv_data = battery, };
522 int result; 531 int result;
523 532
524 battery->id = id; 533 battery->id = id;
@@ -528,23 +537,27 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
528 return result; 537 return result;
529 538
530 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id); 539 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
531 battery->bat.name = battery->name; 540 battery->bat_desc.name = battery->name;
532 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; 541 battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
533 if (!acpi_battery_mode(battery)) { 542 if (!acpi_battery_mode(battery)) {
534 battery->bat.properties = sbs_charge_battery_props; 543 battery->bat_desc.properties = sbs_charge_battery_props;
535 battery->bat.num_properties = 544 battery->bat_desc.num_properties =
536 ARRAY_SIZE(sbs_charge_battery_props); 545 ARRAY_SIZE(sbs_charge_battery_props);
537 } else { 546 } else {
538 battery->bat.properties = sbs_energy_battery_props; 547 battery->bat_desc.properties = sbs_energy_battery_props;
539 battery->bat.num_properties = 548 battery->bat_desc.num_properties =
540 ARRAY_SIZE(sbs_energy_battery_props); 549 ARRAY_SIZE(sbs_energy_battery_props);
541 } 550 }
542 battery->bat.get_property = acpi_sbs_battery_get_property; 551 battery->bat_desc.get_property = acpi_sbs_battery_get_property;
543 result = power_supply_register(&sbs->device->dev, &battery->bat, NULL); 552 battery->bat = power_supply_register(&sbs->device->dev,
544 if (result) 553 &battery->bat_desc, &psy_cfg);
554 if (IS_ERR(battery->bat)) {
555 result = PTR_ERR(battery->bat);
556 battery->bat = NULL;
545 goto end; 557 goto end;
558 }
546 559
547 result = device_create_file(battery->bat.dev, &alarm_attr); 560 result = device_create_file(&battery->bat->dev, &alarm_attr);
548 if (result) 561 if (result)
549 goto end; 562 goto end;
550 battery->have_sysfs_alarm = 1; 563 battery->have_sysfs_alarm = 1;
@@ -559,28 +572,29 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
559{ 572{
560 struct acpi_battery *battery = &sbs->battery[id]; 573 struct acpi_battery *battery = &sbs->battery[id];
561 574
562 if (battery->bat.dev) { 575 if (battery->bat) {
563 if (battery->have_sysfs_alarm) 576 if (battery->have_sysfs_alarm)
564 device_remove_file(battery->bat.dev, &alarm_attr); 577 device_remove_file(&battery->bat->dev, &alarm_attr);
565 power_supply_unregister(&battery->bat); 578 power_supply_unregister(battery->bat);
566 } 579 }
567} 580}
568 581
569static int acpi_charger_add(struct acpi_sbs *sbs) 582static int acpi_charger_add(struct acpi_sbs *sbs)
570{ 583{
571 int result; 584 int result;
585 struct power_supply_config psy_cfg = { .drv_data = sbs, };
572 586
573 result = acpi_ac_get_present(sbs); 587 result = acpi_ac_get_present(sbs);
574 if (result) 588 if (result)
575 goto end; 589 goto end;
576 590
577 sbs->charger_exists = 1; 591 sbs->charger_exists = 1;
578 sbs->charger.name = "sbs-charger"; 592 sbs->charger = power_supply_register(&sbs->device->dev,
579 sbs->charger.type = POWER_SUPPLY_TYPE_MAINS; 593 &acpi_sbs_charger_desc, &psy_cfg);
580 sbs->charger.properties = sbs_ac_props; 594 if (IS_ERR(sbs->charger)) {
581 sbs->charger.num_properties = ARRAY_SIZE(sbs_ac_props); 595 result = PTR_ERR(sbs->charger);
582 sbs->charger.get_property = sbs_get_ac_property; 596 sbs->charger = NULL;
583 power_supply_register(&sbs->device->dev, &sbs->charger, NULL); 597 }
584 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n", 598 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
585 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), 599 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
586 ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line"); 600 ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");
@@ -590,8 +604,8 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
590 604
591static void acpi_charger_remove(struct acpi_sbs *sbs) 605static void acpi_charger_remove(struct acpi_sbs *sbs)
592{ 606{
593 if (sbs->charger.dev) 607 if (sbs->charger)
594 power_supply_unregister(&sbs->charger); 608 power_supply_unregister(sbs->charger);
595} 609}
596 610
597static void acpi_sbs_callback(void *context) 611static void acpi_sbs_callback(void *context)
@@ -605,7 +619,7 @@ static void acpi_sbs_callback(void *context)
605 if (sbs->charger_exists) { 619 if (sbs->charger_exists) {
606 acpi_ac_get_present(sbs); 620 acpi_ac_get_present(sbs);
607 if (sbs->charger_present != saved_charger_state) 621 if (sbs->charger_present != saved_charger_state)
608 kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE); 622 kobject_uevent(&sbs->charger->dev.kobj, KOBJ_CHANGE);
609 } 623 }
610 624
611 if (sbs->manager_present) { 625 if (sbs->manager_present) {
@@ -617,7 +631,7 @@ static void acpi_sbs_callback(void *context)
617 acpi_battery_read(bat); 631 acpi_battery_read(bat);
618 if (saved_battery_state == bat->present) 632 if (saved_battery_state == bat->present)
619 continue; 633 continue;
620 kobject_uevent(&bat->bat.dev->kobj, KOBJ_CHANGE); 634 kobject_uevent(&bat->bat->dev.kobj, KOBJ_CHANGE);
621 } 635 }
622 } 636 }
623} 637}
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 6182265a6571..5d5a8c42645f 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -339,7 +339,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
339 enum power_supply_property prop, 339 enum power_supply_property prop,
340 union power_supply_propval *val) 340 union power_supply_propval *val)
341{ 341{
342 struct hid_device *dev = container_of(psy, struct hid_device, battery); 342 struct hid_device *dev = power_supply_get_drvdata(psy);
343 int ret = 0; 343 int ret = 0;
344 __u8 *buf; 344 __u8 *buf;
345 345
@@ -397,26 +397,32 @@ static int hidinput_get_battery_property(struct power_supply *psy,
397 397
398static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field) 398static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field)
399{ 399{
400 struct power_supply *battery = &dev->battery; 400 struct power_supply_desc *psy_desc = NULL;
401 int ret; 401 struct power_supply_config psy_cfg = { .drv_data = dev, };
402 unsigned quirks; 402 unsigned quirks;
403 s32 min, max; 403 s32 min, max;
404 404
405 if (field->usage->hid != HID_DC_BATTERYSTRENGTH) 405 if (field->usage->hid != HID_DC_BATTERYSTRENGTH)
406 return false; /* no match */ 406 return false; /* no match */
407 407
408 if (battery->name != NULL) 408 if (dev->battery != NULL)
409 goto out; /* already initialized? */ 409 goto out; /* already initialized? */
410 410
411 battery->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq); 411 psy_desc = kzalloc(sizeof(*psy_desc), GFP_KERNEL);
412 if (battery->name == NULL) 412 if (psy_desc == NULL)
413 goto out; 413 goto out;
414 414
415 battery->type = POWER_SUPPLY_TYPE_BATTERY; 415 psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);
416 battery->properties = hidinput_battery_props; 416 if (psy_desc->name == NULL) {
417 battery->num_properties = ARRAY_SIZE(hidinput_battery_props); 417 kfree(psy_desc);
418 battery->use_for_apm = 0; 418 goto out;
419 battery->get_property = hidinput_get_battery_property; 419 }
420
421 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
422 psy_desc->properties = hidinput_battery_props;
423 psy_desc->num_properties = ARRAY_SIZE(hidinput_battery_props);
424 psy_desc->use_for_apm = 0;
425 psy_desc->get_property = hidinput_get_battery_property;
420 426
421 quirks = find_battery_quirk(dev); 427 quirks = find_battery_quirk(dev);
422 428
@@ -439,14 +445,16 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
439 dev->battery_report_type = report_type; 445 dev->battery_report_type = report_type;
440 dev->battery_report_id = field->report->id; 446 dev->battery_report_id = field->report->id;
441 447
442 ret = power_supply_register(&dev->dev, battery, NULL); 448 dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
443 if (ret != 0) { 449 if (IS_ERR(dev->battery)) {
444 hid_warn(dev, "can't register power supply: %d\n", ret); 450 hid_warn(dev, "can't register power supply: %ld\n",
445 kfree(battery->name); 451 PTR_ERR(dev->battery));
446 battery->name = NULL; 452 kfree(psy_desc->name);
453 kfree(psy_desc);
454 dev->battery = NULL;
447 } 455 }
448 456
449 power_supply_powers(battery, &dev->dev); 457 power_supply_powers(dev->battery, &dev->dev);
450 458
451out: 459out:
452 return true; 460 return true;
@@ -454,12 +462,13 @@ out:
454 462
455static void hidinput_cleanup_battery(struct hid_device *dev) 463static void hidinput_cleanup_battery(struct hid_device *dev)
456{ 464{
457 if (!dev->battery.name) 465 if (!dev->battery)
458 return; 466 return;
459 467
460 power_supply_unregister(&dev->battery); 468 power_supply_unregister(dev->battery);
461 kfree(dev->battery.name); 469 kfree(dev->battery->desc->name);
462 dev->battery.name = NULL; 470 kfree(dev->battery->desc);
471 dev->battery = NULL;
463} 472}
464#else /* !CONFIG_HID_BATTERY_STRENGTH */ 473#else /* !CONFIG_HID_BATTERY_STRENGTH */
465static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, 474static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 16fc6a17ac63..65007ec2d96e 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -815,7 +815,8 @@ struct sony_sc {
815 struct led_classdev *leds[MAX_LEDS]; 815 struct led_classdev *leds[MAX_LEDS];
816 unsigned long quirks; 816 unsigned long quirks;
817 struct work_struct state_worker; 817 struct work_struct state_worker;
818 struct power_supply battery; 818 struct power_supply *battery;
819 struct power_supply_desc battery_desc;
819 int device_id; 820 int device_id;
820 __u8 *output_report_dmabuf; 821 __u8 *output_report_dmabuf;
821 822
@@ -1660,7 +1661,7 @@ static int sony_battery_get_property(struct power_supply *psy,
1660 enum power_supply_property psp, 1661 enum power_supply_property psp,
1661 union power_supply_propval *val) 1662 union power_supply_propval *val)
1662{ 1663{
1663 struct sony_sc *sc = container_of(psy, struct sony_sc, battery); 1664 struct sony_sc *sc = power_supply_get_drvdata(psy);
1664 unsigned long flags; 1665 unsigned long flags;
1665 int ret = 0; 1666 int ret = 0;
1666 u8 battery_charging, battery_capacity, cable_state; 1667 u8 battery_charging, battery_capacity, cable_state;
@@ -1699,6 +1700,7 @@ static int sony_battery_get_property(struct power_supply *psy,
1699 1700
1700static int sony_battery_probe(struct sony_sc *sc) 1701static int sony_battery_probe(struct sony_sc *sc)
1701{ 1702{
1703 struct power_supply_config psy_cfg = { .drv_data = sc, };
1702 struct hid_device *hdev = sc->hdev; 1704 struct hid_device *hdev = sc->hdev;
1703 int ret; 1705 int ret;
1704 1706
@@ -1708,39 +1710,42 @@ static int sony_battery_probe(struct sony_sc *sc)
1708 */ 1710 */
1709 sc->battery_capacity = 100; 1711 sc->battery_capacity = 100;
1710 1712
1711 sc->battery.properties = sony_battery_props; 1713 sc->battery_desc.properties = sony_battery_props;
1712 sc->battery.num_properties = ARRAY_SIZE(sony_battery_props); 1714 sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);
1713 sc->battery.get_property = sony_battery_get_property; 1715 sc->battery_desc.get_property = sony_battery_get_property;
1714 sc->battery.type = POWER_SUPPLY_TYPE_BATTERY; 1716 sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
1715 sc->battery.use_for_apm = 0; 1717 sc->battery_desc.use_for_apm = 0;
1716 sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%pMR", 1718 sc->battery_desc.name = kasprintf(GFP_KERNEL,
1717 sc->mac_address); 1719 "sony_controller_battery_%pMR",
1718 if (!sc->battery.name) 1720 sc->mac_address);
1721 if (!sc->battery_desc.name)
1719 return -ENOMEM; 1722 return -ENOMEM;
1720 1723
1721 ret = power_supply_register(&hdev->dev, &sc->battery, NULL); 1724 sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc,
1722 if (ret) { 1725 &psy_cfg);
1726 if (IS_ERR(sc->battery)) {
1727 ret = PTR_ERR(sc->battery);
1723 hid_err(hdev, "Unable to register battery device\n"); 1728 hid_err(hdev, "Unable to register battery device\n");
1724 goto err_free; 1729 goto err_free;
1725 } 1730 }
1726 1731
1727 power_supply_powers(&sc->battery, &hdev->dev); 1732 power_supply_powers(sc->battery, &hdev->dev);
1728 return 0; 1733 return 0;
1729 1734
1730err_free: 1735err_free:
1731 kfree(sc->battery.name); 1736 kfree(sc->battery_desc.name);
1732 sc->battery.name = NULL; 1737 sc->battery_desc.name = NULL;
1733 return ret; 1738 return ret;
1734} 1739}
1735 1740
1736static void sony_battery_remove(struct sony_sc *sc) 1741static void sony_battery_remove(struct sony_sc *sc)
1737{ 1742{
1738 if (!sc->battery.name) 1743 if (!sc->battery_desc.name)
1739 return; 1744 return;
1740 1745
1741 power_supply_unregister(&sc->battery); 1746 power_supply_unregister(sc->battery);
1742 kfree(sc->battery.name); 1747 kfree(sc->battery_desc.name);
1743 sc->battery.name = NULL; 1748 sc->battery_desc.name = NULL;
1744} 1749}
1745 1750
1746/* 1751/*
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index 91cb00abcb8e..05e23c417d50 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -203,8 +203,7 @@ static int wiimod_battery_get_property(struct power_supply *psy,
203 enum power_supply_property psp, 203 enum power_supply_property psp,
204 union power_supply_propval *val) 204 union power_supply_propval *val)
205{ 205{
206 struct wiimote_data *wdata = container_of(psy, struct wiimote_data, 206 struct wiimote_data *wdata = power_supply_get_drvdata(psy);
207 battery);
208 int ret = 0, state; 207 int ret = 0, state;
209 unsigned long flags; 208 unsigned long flags;
210 209
@@ -238,42 +237,46 @@ static int wiimod_battery_get_property(struct power_supply *psy,
238static int wiimod_battery_probe(const struct wiimod_ops *ops, 237static int wiimod_battery_probe(const struct wiimod_ops *ops,
239 struct wiimote_data *wdata) 238 struct wiimote_data *wdata)
240{ 239{
240 struct power_supply_config psy_cfg = { .drv_data = wdata, };
241 int ret; 241 int ret;
242 242
243 wdata->battery.properties = wiimod_battery_props; 243 wdata->battery_desc.properties = wiimod_battery_props;
244 wdata->battery.num_properties = ARRAY_SIZE(wiimod_battery_props); 244 wdata->battery_desc.num_properties = ARRAY_SIZE(wiimod_battery_props);
245 wdata->battery.get_property = wiimod_battery_get_property; 245 wdata->battery_desc.get_property = wiimod_battery_get_property;
246 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; 246 wdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
247 wdata->battery.use_for_apm = 0; 247 wdata->battery_desc.use_for_apm = 0;
248 wdata->battery.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s", 248 wdata->battery_desc.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",
249 wdata->hdev->uniq); 249 wdata->hdev->uniq);
250 if (!wdata->battery.name) 250 if (!wdata->battery_desc.name)
251 return -ENOMEM; 251 return -ENOMEM;
252 252
253 ret = power_supply_register(&wdata->hdev->dev, &wdata->battery, NULL); 253 wdata->battery = power_supply_register(&wdata->hdev->dev,
254 if (ret) { 254 &wdata->battery_desc,
255 &psy_cfg);
256 if (IS_ERR(wdata->battery)) {
255 hid_err(wdata->hdev, "cannot register battery device\n"); 257 hid_err(wdata->hdev, "cannot register battery device\n");
258 ret = PTR_ERR(wdata->battery);
256 goto err_free; 259 goto err_free;
257 } 260 }
258 261
259 power_supply_powers(&wdata->battery, &wdata->hdev->dev); 262 power_supply_powers(wdata->battery, &wdata->hdev->dev);
260 return 0; 263 return 0;
261 264
262err_free: 265err_free:
263 kfree(wdata->battery.name); 266 kfree(wdata->battery_desc.name);
264 wdata->battery.name = NULL; 267 wdata->battery_desc.name = NULL;
265 return ret; 268 return ret;
266} 269}
267 270
268static void wiimod_battery_remove(const struct wiimod_ops *ops, 271static void wiimod_battery_remove(const struct wiimod_ops *ops,
269 struct wiimote_data *wdata) 272 struct wiimote_data *wdata)
270{ 273{
271 if (!wdata->battery.name) 274 if (!wdata->battery_desc.name)
272 return; 275 return;
273 276
274 power_supply_unregister(&wdata->battery); 277 power_supply_unregister(wdata->battery);
275 kfree(wdata->battery.name); 278 kfree(wdata->battery_desc.name);
276 wdata->battery.name = NULL; 279 wdata->battery_desc.name = NULL;
277} 280}
278 281
279static const struct wiimod_ops wiimod_battery = { 282static const struct wiimod_ops wiimod_battery = {
diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h
index 10934aa129fb..875694d43e4d 100644
--- a/drivers/hid/hid-wiimote.h
+++ b/drivers/hid/hid-wiimote.h
@@ -147,7 +147,8 @@ struct wiimote_data {
147 struct led_classdev *leds[4]; 147 struct led_classdev *leds[4];
148 struct input_dev *accel; 148 struct input_dev *accel;
149 struct input_dev *ir; 149 struct input_dev *ir;
150 struct power_supply battery; 150 struct power_supply *battery;
151 struct power_supply_desc battery_desc;
151 struct input_dev *mp; 152 struct input_dev *mp;
152 struct timer_list timer; 153 struct timer_list timer;
153 struct wiimote_debug *debug; 154 struct wiimote_debug *debug;
diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h
index 7db432809e9e..0d0d0dd89d17 100644
--- a/drivers/hid/wacom.h
+++ b/drivers/hid/wacom.h
@@ -119,8 +119,10 @@ struct wacom {
119 u8 img_lum; /* OLED matrix display brightness */ 119 u8 img_lum; /* OLED matrix display brightness */
120 } led; 120 } led;
121 bool led_initialized; 121 bool led_initialized;
122 struct power_supply battery; 122 struct power_supply *battery;
123 struct power_supply ac; 123 struct power_supply *ac;
124 struct power_supply_desc battery_desc;
125 struct power_supply_desc ac_desc;
124}; 126};
125 127
126static inline void wacom_schedule_work(struct wacom_wac *wacom_wac) 128static 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)
133{ 135{
134 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); 136 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
135 137
136 power_supply_changed(&wacom->battery); 138 power_supply_changed(wacom->battery);
137} 139}
138 140
139extern const struct hid_device_id wacom_ids[]; 141extern const struct hid_device_id wacom_ids[];
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 148949c0e039..ba9af470bea0 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -944,7 +944,7 @@ static int wacom_battery_get_property(struct power_supply *psy,
944 enum power_supply_property psp, 944 enum power_supply_property psp,
945 union power_supply_propval *val) 945 union power_supply_propval *val)
946{ 946{
947 struct wacom *wacom = container_of(psy, struct wacom, battery); 947 struct wacom *wacom = power_supply_get_drvdata(psy);
948 int ret = 0; 948 int ret = 0;
949 949
950 switch (psp) { 950 switch (psp) {
@@ -976,7 +976,7 @@ static int wacom_ac_get_property(struct power_supply *psy,
976 enum power_supply_property psp, 976 enum power_supply_property psp,
977 union power_supply_propval *val) 977 union power_supply_propval *val)
978{ 978{
979 struct wacom *wacom = container_of(psy, struct wacom, ac); 979 struct wacom *wacom = power_supply_get_drvdata(psy);
980 int ret = 0; 980 int ret = 0;
981 981
982 switch (psp) { 982 switch (psp) {
@@ -998,43 +998,46 @@ static int wacom_ac_get_property(struct power_supply *psy,
998static int wacom_initialize_battery(struct wacom *wacom) 998static int wacom_initialize_battery(struct wacom *wacom)
999{ 999{
1000 static atomic_t battery_no = ATOMIC_INIT(0); 1000 static atomic_t battery_no = ATOMIC_INIT(0);
1001 int error; 1001 struct power_supply_config psy_cfg = { .drv_data = wacom, };
1002 unsigned long n; 1002 unsigned long n;
1003 1003
1004 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) { 1004 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
1005 struct power_supply_desc *bat_desc = &wacom->battery_desc;
1006 struct power_supply_desc *ac_desc = &wacom->ac_desc;
1005 n = atomic_inc_return(&battery_no) - 1; 1007 n = atomic_inc_return(&battery_no) - 1;
1006 1008
1007 wacom->battery.properties = wacom_battery_props; 1009 bat_desc->properties = wacom_battery_props;
1008 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); 1010 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1009 wacom->battery.get_property = wacom_battery_get_property; 1011 bat_desc->get_property = wacom_battery_get_property;
1010 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n); 1012 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
1011 wacom->battery.name = wacom->wacom_wac.bat_name; 1013 bat_desc->name = wacom->wacom_wac.bat_name;
1012 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; 1014 bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
1013 wacom->battery.use_for_apm = 0; 1015 bat_desc->use_for_apm = 0;
1014 1016
1015 wacom->ac.properties = wacom_ac_props; 1017 ac_desc->properties = wacom_ac_props;
1016 wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props); 1018 ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
1017 wacom->ac.get_property = wacom_ac_get_property; 1019 ac_desc->get_property = wacom_ac_get_property;
1018 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n); 1020 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
1019 wacom->ac.name = wacom->wacom_wac.ac_name; 1021 ac_desc->name = wacom->wacom_wac.ac_name;
1020 wacom->ac.type = POWER_SUPPLY_TYPE_MAINS; 1022 ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
1021 wacom->ac.use_for_apm = 0; 1023 ac_desc->use_for_apm = 0;
1022 1024
1023 error = power_supply_register(&wacom->hdev->dev, 1025 wacom->battery = power_supply_register(&wacom->hdev->dev,
1024 &wacom->battery, NULL); 1026 &wacom->battery_desc, &psy_cfg);
1025 if (error) 1027 if (IS_ERR(wacom->battery))
1026 return error; 1028 return PTR_ERR(wacom->battery);
1027 1029
1028 power_supply_powers(&wacom->battery, &wacom->hdev->dev); 1030 power_supply_powers(wacom->battery, &wacom->hdev->dev);
1029 1031
1030 error = power_supply_register(&wacom->hdev->dev, &wacom->ac, 1032 wacom->ac = power_supply_register(&wacom->hdev->dev,
1031 NULL); 1033 &wacom->ac_desc,
1032 if (error) { 1034 &psy_cfg);
1033 power_supply_unregister(&wacom->battery); 1035 if (IS_ERR(wacom->ac)) {
1034 return error; 1036 power_supply_unregister(wacom->battery);
1037 return PTR_ERR(wacom->ac);
1035 } 1038 }
1036 1039
1037 power_supply_powers(&wacom->ac, &wacom->hdev->dev); 1040 power_supply_powers(wacom->ac, &wacom->hdev->dev);
1038 } 1041 }
1039 1042
1040 return 0; 1043 return 0;
@@ -1043,11 +1046,11 @@ static int wacom_initialize_battery(struct wacom *wacom)
1043static void wacom_destroy_battery(struct wacom *wacom) 1046static void wacom_destroy_battery(struct wacom *wacom)
1044{ 1047{
1045 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && 1048 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1046 wacom->battery.dev) { 1049 wacom->battery) {
1047 power_supply_unregister(&wacom->battery); 1050 power_supply_unregister(wacom->battery);
1048 wacom->battery.dev = NULL; 1051 wacom->battery = NULL;
1049 power_supply_unregister(&wacom->ac); 1052 power_supply_unregister(wacom->ac);
1050 wacom->ac.dev = NULL; 1053 wacom->ac = NULL;
1051 } 1054 }
1052} 1055}
1053 1056
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 041a592fe753..b4e94471f3d5 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -177,7 +177,7 @@ struct compal_data{
177 unsigned char curr_pwm; 177 unsigned char curr_pwm;
178 178
179 /* Power supply */ 179 /* Power supply */
180 struct power_supply psy; 180 struct power_supply *psy;
181 struct power_supply_info psy_info; 181 struct power_supply_info psy_info;
182 char bat_model_name[BAT_MODEL_NAME_LEN + 1]; 182 char bat_model_name[BAT_MODEL_NAME_LEN + 1];
183 char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1]; 183 char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1];
@@ -565,8 +565,7 @@ static int bat_get_property(struct power_supply *psy,
565 enum power_supply_property psp, 565 enum power_supply_property psp,
566 union power_supply_propval *val) 566 union power_supply_propval *val)
567{ 567{
568 struct compal_data *data; 568 struct compal_data *data = power_supply_get_drvdata(psy);
569 data = container_of(psy, struct compal_data, psy);
570 569
571 switch (psp) { 570 switch (psp) {
572 case POWER_SUPPLY_PROP_STATUS: 571 case POWER_SUPPLY_PROP_STATUS:
@@ -875,13 +874,16 @@ static struct dmi_system_id __initdata compal_dmi_table[] = {
875}; 874};
876MODULE_DEVICE_TABLE(dmi, compal_dmi_table); 875MODULE_DEVICE_TABLE(dmi, compal_dmi_table);
877 876
877static const struct power_supply_desc psy_bat_desc = {
878 .name = DRIVER_NAME,
879 .type = POWER_SUPPLY_TYPE_BATTERY,
880 .properties = compal_bat_properties,
881 .num_properties = ARRAY_SIZE(compal_bat_properties),
882 .get_property = bat_get_property,
883};
884
878static void initialize_power_supply_data(struct compal_data *data) 885static void initialize_power_supply_data(struct compal_data *data)
879{ 886{
880 data->psy.name = DRIVER_NAME;
881 data->psy.type = POWER_SUPPLY_TYPE_BATTERY;
882 data->psy.properties = compal_bat_properties;
883 data->psy.num_properties = ARRAY_SIZE(compal_bat_properties);
884 data->psy.get_property = bat_get_property;
885 887
886 ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR, 888 ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR,
887 data->bat_manufacturer_name, 889 data->bat_manufacturer_name,
@@ -1011,6 +1013,7 @@ static int compal_probe(struct platform_device *pdev)
1011 int err; 1013 int err;
1012 struct compal_data *data; 1014 struct compal_data *data;
1013 struct device *hwmon_dev; 1015 struct device *hwmon_dev;
1016 struct power_supply_config psy_cfg = {};
1014 1017
1015 if (!extra_features) 1018 if (!extra_features)
1016 return 0; 1019 return 0;
@@ -1036,9 +1039,13 @@ static int compal_probe(struct platform_device *pdev)
1036 1039
1037 /* Power supply */ 1040 /* Power supply */
1038 initialize_power_supply_data(data); 1041 initialize_power_supply_data(data);
1039 err = power_supply_register(&compal_device->dev, &data->psy, NULL); 1042 psy_cfg.drv_data = data;
1040 if (err < 0) 1043 data->psy = power_supply_register(&compal_device->dev, &psy_bat_desc,
1044 &psy_cfg);
1045 if (IS_ERR(data->psy)) {
1046 err = PTR_ERR(data->psy);
1041 goto remove; 1047 goto remove;
1048 }
1042 1049
1043 platform_set_drvdata(pdev, data); 1050 platform_set_drvdata(pdev, data);
1044 1051
@@ -1073,7 +1080,7 @@ static int compal_remove(struct platform_device *pdev)
1073 pwm_disable_control(); 1080 pwm_disable_control();
1074 1081
1075 data = platform_get_drvdata(pdev); 1082 data = platform_get_drvdata(pdev);
1076 power_supply_unregister(&data->psy); 1083 power_supply_unregister(data->psy);
1077 1084
1078 sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group); 1085 sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);
1079 1086
diff --git a/drivers/power/88pm860x_battery.c b/drivers/power/88pm860x_battery.c
index a99d7f2829a7..d49579b227ec 100644
--- a/drivers/power/88pm860x_battery.c
+++ b/drivers/power/88pm860x_battery.c
@@ -98,7 +98,7 @@ struct pm860x_battery_info {
98 struct i2c_client *i2c; 98 struct i2c_client *i2c;
99 struct device *dev; 99 struct device *dev;
100 100
101 struct power_supply battery; 101 struct power_supply *battery;
102 struct mutex lock; 102 struct mutex lock;
103 int status; 103 int status;
104 int irq_cc; 104 int irq_cc;
@@ -798,9 +798,8 @@ out:
798 798
799static void pm860x_external_power_changed(struct power_supply *psy) 799static void pm860x_external_power_changed(struct power_supply *psy)
800{ 800{
801 struct pm860x_battery_info *info; 801 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
802 802
803 info = container_of(psy, struct pm860x_battery_info, battery);
804 calc_resistor(info); 803 calc_resistor(info);
805} 804}
806 805
@@ -808,7 +807,7 @@ static int pm860x_batt_get_prop(struct power_supply *psy,
808 enum power_supply_property psp, 807 enum power_supply_property psp,
809 union power_supply_propval *val) 808 union power_supply_propval *val)
810{ 809{
811 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent); 810 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
812 int data; 811 int data;
813 int ret; 812 int ret;
814 813
@@ -874,7 +873,7 @@ static int pm860x_batt_set_prop(struct power_supply *psy,
874 enum power_supply_property psp, 873 enum power_supply_property psp,
875 const union power_supply_propval *val) 874 const union power_supply_propval *val)
876{ 875{
877 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent); 876 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent);
878 877
879 switch (psp) { 878 switch (psp) {
880 case POWER_SUPPLY_PROP_CHARGE_FULL: 879 case POWER_SUPPLY_PROP_CHARGE_FULL:
@@ -901,6 +900,16 @@ static enum power_supply_property pm860x_batt_props[] = {
901 POWER_SUPPLY_PROP_TEMP, 900 POWER_SUPPLY_PROP_TEMP,
902}; 901};
903 902
903static const struct power_supply_desc pm860x_battery_desc = {
904 .name = "battery-monitor",
905 .type = POWER_SUPPLY_TYPE_BATTERY,
906 .properties = pm860x_batt_props,
907 .num_properties = ARRAY_SIZE(pm860x_batt_props),
908 .get_property = pm860x_batt_get_prop,
909 .set_property = pm860x_batt_set_prop,
910 .external_power_changed = pm860x_external_power_changed,
911};
912
904static int pm860x_battery_probe(struct platform_device *pdev) 913static int pm860x_battery_probe(struct platform_device *pdev)
905{ 914{
906 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 915 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
@@ -936,14 +945,6 @@ static int pm860x_battery_probe(struct platform_device *pdev)
936 945
937 pm860x_init_battery(info); 946 pm860x_init_battery(info);
938 947
939 info->battery.name = "battery-monitor";
940 info->battery.type = POWER_SUPPLY_TYPE_BATTERY;
941 info->battery.properties = pm860x_batt_props;
942 info->battery.num_properties = ARRAY_SIZE(pm860x_batt_props);
943 info->battery.get_property = pm860x_batt_get_prop;
944 info->battery.set_property = pm860x_batt_set_prop;
945 info->battery.external_power_changed = pm860x_external_power_changed;
946
947 if (pdata && pdata->max_capacity) 948 if (pdata && pdata->max_capacity)
948 info->max_capacity = pdata->max_capacity; 949 info->max_capacity = pdata->max_capacity;
949 else 950 else
@@ -953,10 +954,11 @@ static int pm860x_battery_probe(struct platform_device *pdev)
953 else 954 else
954 info->resistor = 300; /* set default internal resistor */ 955 info->resistor = 300; /* set default internal resistor */
955 956
956 ret = power_supply_register(&pdev->dev, &info->battery, NULL); 957 info->battery = power_supply_register(&pdev->dev, &pm860x_battery_desc,
957 if (ret) 958 NULL);
958 return ret; 959 if (IS_ERR(info->battery))
959 info->battery.dev->parent = &pdev->dev; 960 return PTR_ERR(info->battery);
961 info->battery->dev.parent = &pdev->dev;
960 962
961 ret = request_threaded_irq(info->irq_cc, NULL, 963 ret = request_threaded_irq(info->irq_cc, NULL,
962 pm860x_coulomb_handler, IRQF_ONESHOT, 964 pm860x_coulomb_handler, IRQF_ONESHOT,
@@ -981,7 +983,7 @@ static int pm860x_battery_probe(struct platform_device *pdev)
981out_coulomb: 983out_coulomb:
982 free_irq(info->irq_cc, info); 984 free_irq(info->irq_cc, info);
983out_reg: 985out_reg:
984 power_supply_unregister(&info->battery); 986 power_supply_unregister(info->battery);
985 return ret; 987 return ret;
986} 988}
987 989
@@ -991,7 +993,7 @@ static int pm860x_battery_remove(struct platform_device *pdev)
991 993
992 free_irq(info->irq_batt, info); 994 free_irq(info->irq_batt, info);
993 free_irq(info->irq_cc, info); 995 free_irq(info->irq_cc, info);
994 power_supply_unregister(&info->battery); 996 power_supply_unregister(info->battery);
995 return 0; 997 return 0;
996} 998}
997 999
diff --git a/drivers/power/88pm860x_charger.c b/drivers/power/88pm860x_charger.c
index 98e31419d9cf..a7f32a5b2299 100644
--- a/drivers/power/88pm860x_charger.c
+++ b/drivers/power/88pm860x_charger.c
@@ -102,7 +102,7 @@ struct pm860x_charger_info {
102 struct i2c_client *i2c_8606; 102 struct i2c_client *i2c_8606;
103 struct device *dev; 103 struct device *dev;
104 104
105 struct power_supply usb; 105 struct power_supply *usb;
106 struct mutex lock; 106 struct mutex lock;
107 int irq_nums; 107 int irq_nums;
108 int irq[7]; 108 int irq[7];
@@ -415,7 +415,7 @@ static irqreturn_t pm860x_charger_handler(int irq, void *data)
415 415
416 set_charging_fsm(info); 416 set_charging_fsm(info);
417 417
418 power_supply_changed(&info->usb); 418 power_supply_changed(info->usb);
419out: 419out:
420 return IRQ_HANDLED; 420 return IRQ_HANDLED;
421} 421}
@@ -587,8 +587,7 @@ static int pm860x_usb_get_prop(struct power_supply *psy,
587 enum power_supply_property psp, 587 enum power_supply_property psp,
588 union power_supply_propval *val) 588 union power_supply_propval *val)
589{ 589{
590 struct pm860x_charger_info *info = 590 struct pm860x_charger_info *info = power_supply_get_drvdata(psy);
591 dev_get_drvdata(psy->dev->parent);
592 591
593 switch (psp) { 592 switch (psp) {
594 case POWER_SUPPLY_PROP_STATUS: 593 case POWER_SUPPLY_PROP_STATUS:
@@ -648,6 +647,14 @@ static struct pm860x_irq_desc {
648 { "vchg", pm860x_vchg_handler }, 647 { "vchg", pm860x_vchg_handler },
649}; 648};
650 649
650static const struct power_supply_desc pm860x_charger_desc = {
651 .name = "usb",
652 .type = POWER_SUPPLY_TYPE_USB,
653 .properties = pm860x_usb_props,
654 .num_properties = ARRAY_SIZE(pm860x_usb_props),
655 .get_property = pm860x_usb_get_prop,
656};
657
651static int pm860x_charger_probe(struct platform_device *pdev) 658static int pm860x_charger_probe(struct platform_device *pdev)
652{ 659{
653 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 660 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
@@ -689,16 +696,15 @@ static int pm860x_charger_probe(struct platform_device *pdev)
689 mutex_init(&info->lock); 696 mutex_init(&info->lock);
690 platform_set_drvdata(pdev, info); 697 platform_set_drvdata(pdev, info);
691 698
692 info->usb.name = "usb"; 699 psy_cfg.drv_data = info;
693 info->usb.type = POWER_SUPPLY_TYPE_USB;
694 info->usb.properties = pm860x_usb_props;
695 info->usb.num_properties = ARRAY_SIZE(pm860x_usb_props);
696 info->usb.get_property = pm860x_usb_get_prop;
697 psy_cfg.supplied_to = pm860x_supplied_to; 700 psy_cfg.supplied_to = pm860x_supplied_to;
698 psy_cfg.num_supplicants = ARRAY_SIZE(pm860x_supplied_to); 701 psy_cfg.num_supplicants = ARRAY_SIZE(pm860x_supplied_to);
699 ret = power_supply_register(&pdev->dev, &info->usb, &psy_cfg); 702 info->usb = power_supply_register(&pdev->dev, &pm860x_charger_desc,
700 if (ret) 703 &psy_cfg);
704 if (IS_ERR(info->usb)) {
705 ret = PTR_ERR(info->usb);
701 goto out; 706 goto out;
707 }
702 708
703 pm860x_init_charger(info); 709 pm860x_init_charger(info);
704 710
@@ -715,7 +721,7 @@ static int pm860x_charger_probe(struct platform_device *pdev)
715 return 0; 721 return 0;
716 722
717out_irq: 723out_irq:
718 power_supply_unregister(&info->usb); 724 power_supply_unregister(info->usb);
719 while (--i >= 0) 725 while (--i >= 0)
720 free_irq(info->irq[i], info); 726 free_irq(info->irq[i], info);
721out: 727out:
@@ -727,7 +733,7 @@ static int pm860x_charger_remove(struct platform_device *pdev)
727 struct pm860x_charger_info *info = platform_get_drvdata(pdev); 733 struct pm860x_charger_info *info = platform_get_drvdata(pdev);
728 int i; 734 int i;
729 735
730 power_supply_unregister(&info->usb); 736 power_supply_unregister(info->usb);
731 free_irq(info->irq[0], info); 737 free_irq(info->irq[0], info);
732 for (i = 0; i < info->irq_nums; i++) 738 for (i = 0; i < info->irq_nums; i++)
733 free_irq(info->irq[i], info); 739 free_irq(info->irq[i], info);
diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c
index 4d18464d6400..8f8044e1acf3 100644
--- a/drivers/power/ab8500_btemp.c
+++ b/drivers/power/ab8500_btemp.c
@@ -45,9 +45,6 @@
45#define BTEMP_BATCTRL_CURR_SRC_60UA 60 45#define BTEMP_BATCTRL_CURR_SRC_60UA 60
46#define BTEMP_BATCTRL_CURR_SRC_120UA 120 46#define BTEMP_BATCTRL_CURR_SRC_120UA 120
47 47
48#define to_ab8500_btemp_device_info(x) container_of((x), \
49 struct ab8500_btemp, btemp_psy);
50
51/** 48/**
52 * struct ab8500_btemp_interrupts - ab8500 interrupts 49 * struct ab8500_btemp_interrupts - ab8500 interrupts
53 * @name: name of the interrupt 50 * @name: name of the interrupt
@@ -102,7 +99,7 @@ struct ab8500_btemp {
102 struct ab8500_gpadc *gpadc; 99 struct ab8500_gpadc *gpadc;
103 struct ab8500_fg *fg; 100 struct ab8500_fg *fg;
104 struct abx500_bm_data *bm; 101 struct abx500_bm_data *bm;
105 struct power_supply btemp_psy; 102 struct power_supply *btemp_psy;
106 struct ab8500_btemp_events events; 103 struct ab8500_btemp_events events;
107 struct ab8500_btemp_ranges btemp_ranges; 104 struct ab8500_btemp_ranges btemp_ranges;
108 struct workqueue_struct *btemp_wq; 105 struct workqueue_struct *btemp_wq;
@@ -654,14 +651,14 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
654 if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) { 651 if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) {
655 di->initialized = true; 652 di->initialized = true;
656 di->bat_temp = bat_temp; 653 di->bat_temp = bat_temp;
657 power_supply_changed(&di->btemp_psy); 654 power_supply_changed(di->btemp_psy);
658 } 655 }
659 } else if (bat_temp < di->prev_bat_temp) { 656 } else if (bat_temp < di->prev_bat_temp) {
660 di->bat_temp--; 657 di->bat_temp--;
661 power_supply_changed(&di->btemp_psy); 658 power_supply_changed(di->btemp_psy);
662 } else if (bat_temp > di->prev_bat_temp) { 659 } else if (bat_temp > di->prev_bat_temp) {
663 di->bat_temp++; 660 di->bat_temp++;
664 power_supply_changed(&di->btemp_psy); 661 power_supply_changed(di->btemp_psy);
665 } 662 }
666 di->prev_bat_temp = bat_temp; 663 di->prev_bat_temp = bat_temp;
667 664
@@ -689,7 +686,7 @@ static irqreturn_t ab8500_btemp_batctrlindb_handler(int irq, void *_di)
689 dev_err(di->dev, "Battery removal detected!\n"); 686 dev_err(di->dev, "Battery removal detected!\n");
690 687
691 di->events.batt_rem = true; 688 di->events.batt_rem = true;
692 power_supply_changed(&di->btemp_psy); 689 power_supply_changed(di->btemp_psy);
693 690
694 return IRQ_HANDLED; 691 return IRQ_HANDLED;
695} 692}
@@ -715,7 +712,7 @@ static irqreturn_t ab8500_btemp_templow_handler(int irq, void *_di)
715 di->events.btemp_high = false; 712 di->events.btemp_high = false;
716 di->events.btemp_medhigh = false; 713 di->events.btemp_medhigh = false;
717 di->events.btemp_lowmed = false; 714 di->events.btemp_lowmed = false;
718 power_supply_changed(&di->btemp_psy); 715 power_supply_changed(di->btemp_psy);
719 } 716 }
720 717
721 return IRQ_HANDLED; 718 return IRQ_HANDLED;
@@ -738,7 +735,7 @@ static irqreturn_t ab8500_btemp_temphigh_handler(int irq, void *_di)
738 di->events.btemp_medhigh = false; 735 di->events.btemp_medhigh = false;
739 di->events.btemp_lowmed = false; 736 di->events.btemp_lowmed = false;
740 di->events.btemp_low = false; 737 di->events.btemp_low = false;
741 power_supply_changed(&di->btemp_psy); 738 power_supply_changed(di->btemp_psy);
742 739
743 return IRQ_HANDLED; 740 return IRQ_HANDLED;
744} 741}
@@ -760,7 +757,7 @@ static irqreturn_t ab8500_btemp_lowmed_handler(int irq, void *_di)
760 di->events.btemp_medhigh = false; 757 di->events.btemp_medhigh = false;
761 di->events.btemp_high = false; 758 di->events.btemp_high = false;
762 di->events.btemp_low = false; 759 di->events.btemp_low = false;
763 power_supply_changed(&di->btemp_psy); 760 power_supply_changed(di->btemp_psy);
764 761
765 return IRQ_HANDLED; 762 return IRQ_HANDLED;
766} 763}
@@ -782,7 +779,7 @@ static irqreturn_t ab8500_btemp_medhigh_handler(int irq, void *_di)
782 di->events.btemp_lowmed = false; 779 di->events.btemp_lowmed = false;
783 di->events.btemp_high = false; 780 di->events.btemp_high = false;
784 di->events.btemp_low = false; 781 di->events.btemp_low = false;
785 power_supply_changed(&di->btemp_psy); 782 power_supply_changed(di->btemp_psy);
786 783
787 return IRQ_HANDLED; 784 return IRQ_HANDLED;
788} 785}
@@ -884,9 +881,7 @@ static int ab8500_btemp_get_property(struct power_supply *psy,
884 enum power_supply_property psp, 881 enum power_supply_property psp,
885 union power_supply_propval *val) 882 union power_supply_propval *val)
886{ 883{
887 struct ab8500_btemp *di; 884 struct ab8500_btemp *di = power_supply_get_drvdata(psy);
888
889 di = to_ab8500_btemp_device_info(psy);
890 885
891 switch (psp) { 886 switch (psp) {
892 case POWER_SUPPLY_PROP_PRESENT: 887 case POWER_SUPPLY_PROP_PRESENT:
@@ -919,14 +914,14 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
919 914
920 psy = (struct power_supply *)data; 915 psy = (struct power_supply *)data;
921 ext = dev_get_drvdata(dev); 916 ext = dev_get_drvdata(dev);
922 di = to_ab8500_btemp_device_info(psy); 917 di = power_supply_get_drvdata(psy);
923 918
924 /* 919 /*
925 * For all psy where the name of your driver 920 * For all psy where the name of your driver
926 * appears in any supplied_to 921 * appears in any supplied_to
927 */ 922 */
928 for (i = 0; i < ext->num_supplicants; i++) { 923 for (i = 0; i < ext->num_supplicants; i++) {
929 if (!strcmp(ext->supplied_to[i], psy->name)) 924 if (!strcmp(ext->supplied_to[i], psy->desc->name))
930 psy_found = true; 925 psy_found = true;
931 } 926 }
932 927
@@ -934,16 +929,16 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
934 return 0; 929 return 0;
935 930
936 /* Go through all properties for the psy */ 931 /* Go through all properties for the psy */
937 for (j = 0; j < ext->num_properties; j++) { 932 for (j = 0; j < ext->desc->num_properties; j++) {
938 enum power_supply_property prop; 933 enum power_supply_property prop;
939 prop = ext->properties[j]; 934 prop = ext->desc->properties[j];
940 935
941 if (power_supply_get_property(ext, prop, &ret)) 936 if (power_supply_get_property(ext, prop, &ret))
942 continue; 937 continue;
943 938
944 switch (prop) { 939 switch (prop) {
945 case POWER_SUPPLY_PROP_PRESENT: 940 case POWER_SUPPLY_PROP_PRESENT:
946 switch (ext->type) { 941 switch (ext->desc->type) {
947 case POWER_SUPPLY_TYPE_MAINS: 942 case POWER_SUPPLY_TYPE_MAINS:
948 /* AC disconnected */ 943 /* AC disconnected */
949 if (!ret.intval && di->events.ac_conn) { 944 if (!ret.intval && di->events.ac_conn) {
@@ -990,10 +985,10 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
990 */ 985 */
991static void ab8500_btemp_external_power_changed(struct power_supply *psy) 986static void ab8500_btemp_external_power_changed(struct power_supply *psy)
992{ 987{
993 struct ab8500_btemp *di = to_ab8500_btemp_device_info(psy); 988 struct ab8500_btemp *di = power_supply_get_drvdata(psy);
994 989
995 class_for_each_device(power_supply_class, NULL, 990 class_for_each_device(power_supply_class, NULL,
996 &di->btemp_psy, ab8500_btemp_get_ext_psy_data); 991 di->btemp_psy, ab8500_btemp_get_ext_psy_data);
997} 992}
998 993
999/* ab8500 btemp driver interrupts and their respective isr */ 994/* ab8500 btemp driver interrupts and their respective isr */
@@ -1044,7 +1039,7 @@ static int ab8500_btemp_remove(struct platform_device *pdev)
1044 destroy_workqueue(di->btemp_wq); 1039 destroy_workqueue(di->btemp_wq);
1045 1040
1046 flush_scheduled_work(); 1041 flush_scheduled_work();
1047 power_supply_unregister(&di->btemp_psy); 1042 power_supply_unregister(di->btemp_psy);
1048 1043
1049 return 0; 1044 return 0;
1050} 1045}
@@ -1054,6 +1049,15 @@ static char *supply_interface[] = {
1054 "ab8500_fg", 1049 "ab8500_fg",
1055}; 1050};
1056 1051
1052static const struct power_supply_desc ab8500_btemp_desc = {
1053 .name = "ab8500_btemp",
1054 .type = POWER_SUPPLY_TYPE_BATTERY,
1055 .properties = ab8500_btemp_props,
1056 .num_properties = ARRAY_SIZE(ab8500_btemp_props),
1057 .get_property = ab8500_btemp_get_property,
1058 .external_power_changed = ab8500_btemp_external_power_changed,
1059};
1060
1057static int ab8500_btemp_probe(struct platform_device *pdev) 1061static int ab8500_btemp_probe(struct platform_device *pdev)
1058{ 1062{
1059 struct device_node *np = pdev->dev.of_node; 1063 struct device_node *np = pdev->dev.of_node;
@@ -1090,17 +1094,9 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
1090 1094
1091 di->initialized = false; 1095 di->initialized = false;
1092 1096
1093 /* BTEMP supply */
1094 di->btemp_psy.name = "ab8500_btemp";
1095 di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY;
1096 di->btemp_psy.properties = ab8500_btemp_props;
1097 di->btemp_psy.num_properties = ARRAY_SIZE(ab8500_btemp_props);
1098 di->btemp_psy.get_property = ab8500_btemp_get_property;
1099 di->btemp_psy.external_power_changed =
1100 ab8500_btemp_external_power_changed;
1101
1102 psy_cfg.supplied_to = supply_interface; 1097 psy_cfg.supplied_to = supply_interface;
1103 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 1098 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
1099 psy_cfg.drv_data = di;
1104 1100
1105 /* Create a work queue for the btemp */ 1101 /* Create a work queue for the btemp */
1106 di->btemp_wq = 1102 di->btemp_wq =
@@ -1141,9 +1137,11 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
1141 } 1137 }
1142 1138
1143 /* Register BTEMP power supply class */ 1139 /* Register BTEMP power supply class */
1144 ret = power_supply_register(di->dev, &di->btemp_psy, &psy_cfg); 1140 di->btemp_psy = power_supply_register(di->dev, &ab8500_btemp_desc,
1145 if (ret) { 1141 &psy_cfg);
1142 if (IS_ERR(di->btemp_psy)) {
1146 dev_err(di->dev, "failed to register BTEMP psy\n"); 1143 dev_err(di->dev, "failed to register BTEMP psy\n");
1144 ret = PTR_ERR(di->btemp_psy);
1147 goto free_btemp_wq; 1145 goto free_btemp_wq;
1148 } 1146 }
1149 1147
@@ -1172,7 +1170,7 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
1172 return ret; 1170 return ret;
1173 1171
1174free_irq: 1172free_irq:
1175 power_supply_unregister(&di->btemp_psy); 1173 power_supply_unregister(di->btemp_psy);
1176 1174
1177 /* We also have to free all successfully registered irqs */ 1175 /* We also have to free all successfully registered irqs */
1178 for (i = i - 1; i >= 0; i--) { 1176 for (i = i - 1; i >= 0; i--) {
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index f9eb7fff1d65..e388171f4e58 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -435,7 +435,7 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,
435 if (!connected) 435 if (!connected)
436 di->flags.vbus_drop_end = false; 436 di->flags.vbus_drop_end = false;
437 437
438 sysfs_notify(&di->usb_chg.psy.dev->kobj, NULL, "present"); 438 sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, "present");
439 439
440 if (connected) { 440 if (connected) {
441 mutex_lock(&di->charger_attached_mutex); 441 mutex_lock(&di->charger_attached_mutex);
@@ -1516,7 +1516,7 @@ static int ab8500_charger_ac_en(struct ux500_charger *charger,
1516 1516
1517 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__); 1517 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__);
1518 } 1518 }
1519 ab8500_power_supply_changed(di, &di->ac_chg.psy); 1519 ab8500_power_supply_changed(di, di->ac_chg.psy);
1520 1520
1521 return ret; 1521 return ret;
1522} 1522}
@@ -1672,7 +1672,7 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1672 cancel_delayed_work(&di->check_vbat_work); 1672 cancel_delayed_work(&di->check_vbat_work);
1673 1673
1674 } 1674 }
1675 ab8500_power_supply_changed(di, &di->usb_chg.psy); 1675 ab8500_power_supply_changed(di, di->usb_chg.psy);
1676 1676
1677 return ret; 1677 return ret;
1678} 1678}
@@ -1811,9 +1811,9 @@ static int ab8500_charger_watchdog_kick(struct ux500_charger *charger)
1811 int ret; 1811 int ret;
1812 struct ab8500_charger *di; 1812 struct ab8500_charger *di;
1813 1813
1814 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS) 1814 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)
1815 di = to_ab8500_charger_ac_device_info(charger); 1815 di = to_ab8500_charger_ac_device_info(charger);
1816 else if (charger->psy.type == POWER_SUPPLY_TYPE_USB) 1816 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)
1817 di = to_ab8500_charger_usb_device_info(charger); 1817 di = to_ab8500_charger_usb_device_info(charger);
1818 else 1818 else
1819 return -ENXIO; 1819 return -ENXIO;
@@ -1839,9 +1839,9 @@ static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
1839 int ret; 1839 int ret;
1840 struct ab8500_charger *di; 1840 struct ab8500_charger *di;
1841 1841
1842 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS) 1842 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)
1843 di = to_ab8500_charger_ac_device_info(charger); 1843 di = to_ab8500_charger_ac_device_info(charger);
1844 else if (charger->psy.type == POWER_SUPPLY_TYPE_USB) 1844 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)
1845 di = to_ab8500_charger_usb_device_info(charger); 1845 di = to_ab8500_charger_usb_device_info(charger);
1846 else 1846 else
1847 return -ENXIO; 1847 return -ENXIO;
@@ -1879,7 +1879,7 @@ static int ab8540_charger_power_path_enable(struct ux500_charger *charger,
1879 int ret; 1879 int ret;
1880 struct ab8500_charger *di; 1880 struct ab8500_charger *di;
1881 1881
1882 if (charger->psy.type == POWER_SUPPLY_TYPE_USB) 1882 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)
1883 di = to_ab8500_charger_usb_device_info(charger); 1883 di = to_ab8500_charger_usb_device_info(charger);
1884 else 1884 else
1885 return -ENXIO; 1885 return -ENXIO;
@@ -1910,7 +1910,7 @@ static int ab8540_charger_usb_pre_chg_enable(struct ux500_charger *charger,
1910 int ret; 1910 int ret;
1911 struct ab8500_charger *di; 1911 struct ab8500_charger *di;
1912 1912
1913 if (charger->psy.type == POWER_SUPPLY_TYPE_USB) 1913 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB)
1914 di = to_ab8500_charger_usb_device_info(charger); 1914 di = to_ab8500_charger_usb_device_info(charger);
1915 else 1915 else
1916 return -ENXIO; 1916 return -ENXIO;
@@ -1937,7 +1937,7 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
1937 struct ux500_charger *usb_chg; 1937 struct ux500_charger *usb_chg;
1938 1938
1939 usb_chg = (struct ux500_charger *)data; 1939 usb_chg = (struct ux500_charger *)data;
1940 psy = &usb_chg->psy; 1940 psy = usb_chg->psy;
1941 1941
1942 di = to_ab8500_charger_usb_device_info(usb_chg); 1942 di = to_ab8500_charger_usb_device_info(usb_chg);
1943 1943
@@ -1945,7 +1945,7 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
1945 1945
1946 /* For all psy where the driver name appears in any supplied_to */ 1946 /* For all psy where the driver name appears in any supplied_to */
1947 for (i = 0; i < ext->num_supplicants; i++) { 1947 for (i = 0; i < ext->num_supplicants; i++) {
1948 if (!strcmp(ext->supplied_to[i], psy->name)) 1948 if (!strcmp(ext->supplied_to[i], psy->desc->name))
1949 psy_found = true; 1949 psy_found = true;
1950 } 1950 }
1951 1951
@@ -1953,16 +1953,16 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
1953 return 0; 1953 return 0;
1954 1954
1955 /* Go through all properties for the psy */ 1955 /* Go through all properties for the psy */
1956 for (j = 0; j < ext->num_properties; j++) { 1956 for (j = 0; j < ext->desc->num_properties; j++) {
1957 enum power_supply_property prop; 1957 enum power_supply_property prop;
1958 prop = ext->properties[j]; 1958 prop = ext->desc->properties[j];
1959 1959
1960 if (power_supply_get_property(ext, prop, &ret)) 1960 if (power_supply_get_property(ext, prop, &ret))
1961 continue; 1961 continue;
1962 1962
1963 switch (prop) { 1963 switch (prop) {
1964 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 1964 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1965 switch (ext->type) { 1965 switch (ext->desc->type) {
1966 case POWER_SUPPLY_TYPE_BATTERY: 1966 case POWER_SUPPLY_TYPE_BATTERY:
1967 di->vbat = ret.intval / 1000; 1967 di->vbat = ret.intval / 1000;
1968 break; 1968 break;
@@ -1993,7 +1993,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)
1993 struct ab8500_charger, check_vbat_work.work); 1993 struct ab8500_charger, check_vbat_work.work);
1994 1994
1995 class_for_each_device(power_supply_class, NULL, 1995 class_for_each_device(power_supply_class, NULL,
1996 &di->usb_chg.psy, ab8500_charger_get_ext_psy_data); 1996 di->usb_chg.psy, ab8500_charger_get_ext_psy_data);
1997 1997
1998 /* First run old_vbat is 0. */ 1998 /* First run old_vbat is 0. */
1999 if (di->old_vbat == 0) 1999 if (di->old_vbat == 0)
@@ -2009,7 +2009,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)
2009 di->vbat, di->old_vbat); 2009 di->vbat, di->old_vbat);
2010 ab8500_charger_set_vbus_in_curr(di, 2010 ab8500_charger_set_vbus_in_curr(di,
2011 di->max_usb_in_curr.usb_type_max); 2011 di->max_usb_in_curr.usb_type_max);
2012 power_supply_changed(&di->usb_chg.psy); 2012 power_supply_changed(di->usb_chg.psy);
2013 } 2013 }
2014 2014
2015 di->old_vbat = di->vbat; 2015 di->old_vbat = di->vbat;
@@ -2049,7 +2049,7 @@ static void ab8500_charger_check_hw_failure_work(struct work_struct *work)
2049 } 2049 }
2050 if (!(reg_value & MAIN_CH_NOK)) { 2050 if (!(reg_value & MAIN_CH_NOK)) {
2051 di->flags.mainextchnotok = false; 2051 di->flags.mainextchnotok = false;
2052 ab8500_power_supply_changed(di, &di->ac_chg.psy); 2052 ab8500_power_supply_changed(di, di->ac_chg.psy);
2053 } 2053 }
2054 } 2054 }
2055 if (di->flags.vbus_ovv) { 2055 if (di->flags.vbus_ovv) {
@@ -2062,7 +2062,7 @@ static void ab8500_charger_check_hw_failure_work(struct work_struct *work)
2062 } 2062 }
2063 if (!(reg_value & VBUS_OVV_TH)) { 2063 if (!(reg_value & VBUS_OVV_TH)) {
2064 di->flags.vbus_ovv = false; 2064 di->flags.vbus_ovv = false;
2065 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2065 ab8500_power_supply_changed(di, di->usb_chg.psy);
2066 } 2066 }
2067 } 2067 }
2068 /* If we still have a failure, schedule a new check */ 2068 /* If we still have a failure, schedule a new check */
@@ -2132,8 +2132,8 @@ static void ab8500_charger_ac_work(struct work_struct *work)
2132 di->ac.charger_connected = 0; 2132 di->ac.charger_connected = 0;
2133 } 2133 }
2134 2134
2135 ab8500_power_supply_changed(di, &di->ac_chg.psy); 2135 ab8500_power_supply_changed(di, di->ac_chg.psy);
2136 sysfs_notify(&di->ac_chg.psy.dev->kobj, NULL, "present"); 2136 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present");
2137} 2137}
2138 2138
2139static void ab8500_charger_usb_attached_work(struct work_struct *work) 2139static void ab8500_charger_usb_attached_work(struct work_struct *work)
@@ -2240,7 +2240,7 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
2240 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__); 2240 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__);
2241 di->vbus_detected = false; 2241 di->vbus_detected = false;
2242 ab8500_charger_set_usb_connected(di, false); 2242 ab8500_charger_set_usb_connected(di, false);
2243 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2243 ab8500_power_supply_changed(di, di->usb_chg.psy);
2244 } else { 2244 } else {
2245 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__); 2245 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__);
2246 di->vbus_detected = true; 2246 di->vbus_detected = true;
@@ -2250,7 +2250,7 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
2250 if (!ret) { 2250 if (!ret) {
2251 ab8500_charger_set_usb_connected(di, true); 2251 ab8500_charger_set_usb_connected(di, true);
2252 ab8500_power_supply_changed(di, 2252 ab8500_power_supply_changed(di,
2253 &di->usb_chg.psy); 2253 di->usb_chg.psy);
2254 } 2254 }
2255 } else { 2255 } else {
2256 /* 2256 /*
@@ -2267,7 +2267,7 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
2267 ab8500_charger_set_usb_connected(di, 2267 ab8500_charger_set_usb_connected(di,
2268 true); 2268 true);
2269 ab8500_power_supply_changed(di, 2269 ab8500_power_supply_changed(di,
2270 &di->usb_chg.psy); 2270 di->usb_chg.psy);
2271 } 2271 }
2272 } 2272 }
2273 } 2273 }
@@ -2295,7 +2295,7 @@ static void ab8500_charger_usb_link_attach_work(struct work_struct *work)
2295 } 2295 }
2296 2296
2297 ab8500_charger_set_usb_connected(di, true); 2297 ab8500_charger_set_usb_connected(di, true);
2298 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2298 ab8500_power_supply_changed(di, di->usb_chg.psy);
2299} 2299}
2300 2300
2301/** 2301/**
@@ -2393,7 +2393,7 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
2393 if (!(detected_chargers & USB_PW_CONN)) { 2393 if (!(detected_chargers & USB_PW_CONN)) {
2394 di->vbus_detected = false; 2394 di->vbus_detected = false;
2395 ab8500_charger_set_usb_connected(di, false); 2395 ab8500_charger_set_usb_connected(di, false);
2396 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2396 ab8500_power_supply_changed(di, di->usb_chg.psy);
2397 return; 2397 return;
2398 } 2398 }
2399 2399
@@ -2404,7 +2404,7 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
2404 if (ret == -ENXIO) { 2404 if (ret == -ENXIO) {
2405 /* No valid charger type detected */ 2405 /* No valid charger type detected */
2406 ab8500_charger_set_usb_connected(di, false); 2406 ab8500_charger_set_usb_connected(di, false);
2407 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2407 ab8500_power_supply_changed(di, di->usb_chg.psy);
2408 } 2408 }
2409 return; 2409 return;
2410 } 2410 }
@@ -2463,7 +2463,7 @@ static void ab8500_charger_usb_state_changed_work(struct work_struct *work)
2463 case AB8500_BM_USB_STATE_SUSPEND: 2463 case AB8500_BM_USB_STATE_SUSPEND:
2464 case AB8500_BM_USB_STATE_MAX: 2464 case AB8500_BM_USB_STATE_MAX:
2465 ab8500_charger_set_usb_connected(di, false); 2465 ab8500_charger_set_usb_connected(di, false);
2466 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2466 ab8500_power_supply_changed(di, di->usb_chg.psy);
2467 break; 2467 break;
2468 2468
2469 case AB8500_BM_USB_STATE_RESUME: 2469 case AB8500_BM_USB_STATE_RESUME:
@@ -2486,7 +2486,7 @@ static void ab8500_charger_usb_state_changed_work(struct work_struct *work)
2486 return; 2486 return;
2487 2487
2488 ab8500_charger_set_usb_connected(di, true); 2488 ab8500_charger_set_usb_connected(di, true);
2489 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2489 ab8500_power_supply_changed(di, di->usb_chg.psy);
2490 } 2490 }
2491 break; 2491 break;
2492 2492
@@ -2530,7 +2530,7 @@ static void ab8500_charger_check_usbchargernotok_work(struct work_struct *work)
2530 } 2530 }
2531 2531
2532 if (prev_status != di->flags.usbchargernotok) 2532 if (prev_status != di->flags.usbchargernotok)
2533 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2533 ab8500_power_supply_changed(di, di->usb_chg.psy);
2534} 2534}
2535 2535
2536/** 2536/**
@@ -2560,7 +2560,7 @@ static void ab8500_charger_check_main_thermal_prot_work(
2560 else 2560 else
2561 di->flags.main_thermal_prot = false; 2561 di->flags.main_thermal_prot = false;
2562 2562
2563 ab8500_power_supply_changed(di, &di->ac_chg.psy); 2563 ab8500_power_supply_changed(di, di->ac_chg.psy);
2564} 2564}
2565 2565
2566/** 2566/**
@@ -2590,7 +2590,7 @@ static void ab8500_charger_check_usb_thermal_prot_work(
2590 else 2590 else
2591 di->flags.usb_thermal_prot = false; 2591 di->flags.usb_thermal_prot = false;
2592 2592
2593 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2593 ab8500_power_supply_changed(di, di->usb_chg.psy);
2594} 2594}
2595 2595
2596/** 2596/**
@@ -2651,7 +2651,7 @@ static irqreturn_t ab8500_charger_mainextchnotok_handler(int irq, void *_di)
2651 2651
2652 dev_dbg(di->dev, "Main charger not ok\n"); 2652 dev_dbg(di->dev, "Main charger not ok\n");
2653 di->flags.mainextchnotok = true; 2653 di->flags.mainextchnotok = true;
2654 ab8500_power_supply_changed(di, &di->ac_chg.psy); 2654 ab8500_power_supply_changed(di, di->ac_chg.psy);
2655 2655
2656 /* Schedule a new HW failure check */ 2656 /* Schedule a new HW failure check */
2657 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); 2657 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0);
@@ -2880,11 +2880,11 @@ static irqreturn_t ab8500_charger_chwdexp_handler(int irq, void *_di)
2880 */ 2880 */
2881 if (di->ac.charger_online) { 2881 if (di->ac.charger_online) {
2882 di->ac.wd_expired = true; 2882 di->ac.wd_expired = true;
2883 ab8500_power_supply_changed(di, &di->ac_chg.psy); 2883 ab8500_power_supply_changed(di, di->ac_chg.psy);
2884 } 2884 }
2885 if (di->usb.charger_online) { 2885 if (di->usb.charger_online) {
2886 di->usb.wd_expired = true; 2886 di->usb.wd_expired = true;
2887 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2887 ab8500_power_supply_changed(di, di->usb_chg.psy);
2888 } 2888 }
2889 2889
2890 return IRQ_HANDLED; 2890 return IRQ_HANDLED;
@@ -2927,7 +2927,7 @@ static irqreturn_t ab8500_charger_vbusovv_handler(int irq, void *_di)
2927 2927
2928 dev_dbg(di->dev, "VBUS overvoltage detected\n"); 2928 dev_dbg(di->dev, "VBUS overvoltage detected\n");
2929 di->flags.vbus_ovv = true; 2929 di->flags.vbus_ovv = true;
2930 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2930 ab8500_power_supply_changed(di, di->usb_chg.psy);
2931 2931
2932 /* Schedule a new HW failure check */ 2932 /* Schedule a new HW failure check */
2933 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); 2933 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0);
@@ -3428,10 +3428,10 @@ static int ab8500_charger_remove(struct platform_device *pdev)
3428 3428
3429 flush_scheduled_work(); 3429 flush_scheduled_work();
3430 if (di->usb_chg.enabled) 3430 if (di->usb_chg.enabled)
3431 power_supply_unregister(&di->usb_chg.psy); 3431 power_supply_unregister(di->usb_chg.psy);
3432 3432
3433 if (di->ac_chg.enabled && !di->ac_chg.external) 3433 if (di->ac_chg.enabled && !di->ac_chg.external)
3434 power_supply_unregister(&di->ac_chg.psy); 3434 power_supply_unregister(di->ac_chg.psy);
3435 3435
3436 return 0; 3436 return 0;
3437} 3437}
@@ -3442,11 +3442,27 @@ static char *supply_interface[] = {
3442 "ab8500_btemp", 3442 "ab8500_btemp",
3443}; 3443};
3444 3444
3445static const struct power_supply_desc ab8500_ac_chg_desc = {
3446 .name = "ab8500_ac",
3447 .type = POWER_SUPPLY_TYPE_MAINS,
3448 .properties = ab8500_charger_ac_props,
3449 .num_properties = ARRAY_SIZE(ab8500_charger_ac_props),
3450 .get_property = ab8500_charger_ac_get_property,
3451};
3452
3453static const struct power_supply_desc ab8500_usb_chg_desc = {
3454 .name = "ab8500_usb",
3455 .type = POWER_SUPPLY_TYPE_USB,
3456 .properties = ab8500_charger_usb_props,
3457 .num_properties = ARRAY_SIZE(ab8500_charger_usb_props),
3458 .get_property = ab8500_charger_usb_get_property,
3459};
3460
3445static int ab8500_charger_probe(struct platform_device *pdev) 3461static int ab8500_charger_probe(struct platform_device *pdev)
3446{ 3462{
3447 struct device_node *np = pdev->dev.of_node; 3463 struct device_node *np = pdev->dev.of_node;
3448 struct abx500_bm_data *plat = pdev->dev.platform_data; 3464 struct abx500_bm_data *plat = pdev->dev.platform_data;
3449 struct power_supply_config psy_cfg = {}; 3465 struct power_supply_config ac_psy_cfg = {}, usb_psy_cfg = {};
3450 struct ab8500_charger *di; 3466 struct ab8500_charger *di;
3451 int irq, i, charger_status, ret = 0, ch_stat; 3467 int irq, i, charger_status, ret = 0, ch_stat;
3452 3468
@@ -3485,16 +3501,14 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3485 di->invalid_charger_detect_state = 0; 3501 di->invalid_charger_detect_state = 0;
3486 3502
3487 /* AC and USB supply config */ 3503 /* AC and USB supply config */
3488 psy_cfg.supplied_to = supply_interface; 3504 ac_psy_cfg.supplied_to = supply_interface;
3489 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 3505 ac_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
3506 ac_psy_cfg.drv_data = &di->ac_chg;
3507 usb_psy_cfg.supplied_to = supply_interface;
3508 usb_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
3509 usb_psy_cfg.drv_data = &di->usb_chg;
3490 3510
3491 /* AC supply */ 3511 /* AC supply */
3492 /* power_supply base class */
3493 di->ac_chg.psy.name = "ab8500_ac";
3494 di->ac_chg.psy.type = POWER_SUPPLY_TYPE_MAINS;
3495 di->ac_chg.psy.properties = ab8500_charger_ac_props;
3496 di->ac_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_ac_props);
3497 di->ac_chg.psy.get_property = ab8500_charger_ac_get_property;
3498 /* ux500_charger sub-class */ 3512 /* ux500_charger sub-class */
3499 di->ac_chg.ops.enable = &ab8500_charger_ac_en; 3513 di->ac_chg.ops.enable = &ab8500_charger_ac_en;
3500 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable; 3514 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable;
@@ -3514,12 +3528,6 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3514 &charger_notifier_list, &charger_nb); 3528 &charger_notifier_list, &charger_nb);
3515 3529
3516 /* USB supply */ 3530 /* USB supply */
3517 /* power_supply base class */
3518 di->usb_chg.psy.name = "ab8500_usb";
3519 di->usb_chg.psy.type = POWER_SUPPLY_TYPE_USB;
3520 di->usb_chg.psy.properties = ab8500_charger_usb_props;
3521 di->usb_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_usb_props);
3522 di->usb_chg.psy.get_property = ab8500_charger_usb_get_property;
3523 /* ux500_charger sub-class */ 3531 /* ux500_charger sub-class */
3524 di->usb_chg.ops.enable = &ab8500_charger_usb_en; 3532 di->usb_chg.ops.enable = &ab8500_charger_usb_en;
3525 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable; 3533 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable;
@@ -3617,20 +3625,24 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3617 3625
3618 /* Register AC charger class */ 3626 /* Register AC charger class */
3619 if (di->ac_chg.enabled) { 3627 if (di->ac_chg.enabled) {
3620 ret = power_supply_register(di->dev, &di->ac_chg.psy, 3628 di->ac_chg.psy = power_supply_register(di->dev,
3621 &psy_cfg); 3629 &ab8500_ac_chg_desc,
3622 if (ret) { 3630 &ac_psy_cfg);
3631 if (IS_ERR(di->ac_chg.psy)) {
3623 dev_err(di->dev, "failed to register AC charger\n"); 3632 dev_err(di->dev, "failed to register AC charger\n");
3633 ret = PTR_ERR(di->ac_chg.psy);
3624 goto free_charger_wq; 3634 goto free_charger_wq;
3625 } 3635 }
3626 } 3636 }
3627 3637
3628 /* Register USB charger class */ 3638 /* Register USB charger class */
3629 if (di->usb_chg.enabled) { 3639 if (di->usb_chg.enabled) {
3630 ret = power_supply_register(di->dev, &di->usb_chg.psy, 3640 di->usb_chg.psy = power_supply_register(di->dev,
3631 &psy_cfg); 3641 &ab8500_usb_chg_desc,
3632 if (ret) { 3642 &usb_psy_cfg);
3643 if (IS_ERR(di->usb_chg.psy)) {
3633 dev_err(di->dev, "failed to register USB charger\n"); 3644 dev_err(di->dev, "failed to register USB charger\n");
3645 ret = PTR_ERR(di->usb_chg.psy);
3634 goto free_ac; 3646 goto free_ac;
3635 } 3647 }
3636 } 3648 }
@@ -3653,8 +3665,8 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3653 if (charger_status & AC_PW_CONN) { 3665 if (charger_status & AC_PW_CONN) {
3654 di->ac.charger_connected = 1; 3666 di->ac.charger_connected = 1;
3655 di->ac_conn = true; 3667 di->ac_conn = true;
3656 ab8500_power_supply_changed(di, &di->ac_chg.psy); 3668 ab8500_power_supply_changed(di, di->ac_chg.psy);
3657 sysfs_notify(&di->ac_chg.psy.dev->kobj, NULL, "present"); 3669 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present");
3658 } 3670 }
3659 3671
3660 if (charger_status & USB_PW_CONN) { 3672 if (charger_status & USB_PW_CONN) {
@@ -3715,10 +3727,10 @@ put_usb_phy:
3715 usb_put_phy(di->usb_phy); 3727 usb_put_phy(di->usb_phy);
3716free_usb: 3728free_usb:
3717 if (di->usb_chg.enabled) 3729 if (di->usb_chg.enabled)
3718 power_supply_unregister(&di->usb_chg.psy); 3730 power_supply_unregister(di->usb_chg.psy);
3719free_ac: 3731free_ac:
3720 if (di->ac_chg.enabled) 3732 if (di->ac_chg.enabled)
3721 power_supply_unregister(&di->ac_chg.psy); 3733 power_supply_unregister(di->ac_chg.psy);
3722free_charger_wq: 3734free_charger_wq:
3723 destroy_workqueue(di->charger_wq); 3735 destroy_workqueue(di->charger_wq);
3724 return ret; 3736 return ret;
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 7a2e3ac44cf3..3830dade5d69 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -57,9 +57,6 @@
57#define interpolate(x, x1, y1, x2, y2) \ 57#define interpolate(x, x1, y1, x2, y2) \
58 ((y1) + ((((y2) - (y1)) * ((x) - (x1))) / ((x2) - (x1)))); 58 ((y1) + ((((y2) - (y1)) * ((x) - (x1))) / ((x2) - (x1))));
59 59
60#define to_ab8500_fg_device_info(x) container_of((x), \
61 struct ab8500_fg, fg_psy);
62
63/** 60/**
64 * struct ab8500_fg_interrupts - ab8500 fg interupts 61 * struct ab8500_fg_interrupts - ab8500 fg interupts
65 * @name: name of the interrupt 62 * @name: name of the interrupt
@@ -229,7 +226,7 @@ struct ab8500_fg {
229 struct ab8500 *parent; 226 struct ab8500 *parent;
230 struct ab8500_gpadc *gpadc; 227 struct ab8500_gpadc *gpadc;
231 struct abx500_bm_data *bm; 228 struct abx500_bm_data *bm;
232 struct power_supply fg_psy; 229 struct power_supply *fg_psy;
233 struct workqueue_struct *fg_wq; 230 struct workqueue_struct *fg_wq;
234 struct delayed_work fg_periodic_work; 231 struct delayed_work fg_periodic_work;
235 struct delayed_work fg_low_bat_work; 232 struct delayed_work fg_low_bat_work;
@@ -1391,7 +1388,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1391 di->bat_cap.prev_percent, 1388 di->bat_cap.prev_percent,
1392 di->bat_cap.cap_scale.scaled_cap); 1389 di->bat_cap.cap_scale.scaled_cap);
1393 } 1390 }
1394 power_supply_changed(&di->fg_psy); 1391 power_supply_changed(di->fg_psy);
1395 if (di->flags.fully_charged && di->flags.force_full) { 1392 if (di->flags.fully_charged && di->flags.force_full) {
1396 dev_dbg(di->dev, "Battery full, notifying.\n"); 1393 dev_dbg(di->dev, "Battery full, notifying.\n");
1397 di->flags.force_full = false; 1394 di->flags.force_full = false;
@@ -1850,7 +1847,7 @@ static void ab8500_fg_check_hw_failure_work(struct work_struct *work)
1850 if (!di->flags.bat_ovv) { 1847 if (!di->flags.bat_ovv) {
1851 dev_dbg(di->dev, "Battery OVV\n"); 1848 dev_dbg(di->dev, "Battery OVV\n");
1852 di->flags.bat_ovv = true; 1849 di->flags.bat_ovv = true;
1853 power_supply_changed(&di->fg_psy); 1850 power_supply_changed(di->fg_psy);
1854 } 1851 }
1855 /* Not yet recovered from ovv, reschedule this test */ 1852 /* Not yet recovered from ovv, reschedule this test */
1856 queue_delayed_work(di->fg_wq, &di->fg_check_hw_failure_work, 1853 queue_delayed_work(di->fg_wq, &di->fg_check_hw_failure_work,
@@ -1858,7 +1855,7 @@ static void ab8500_fg_check_hw_failure_work(struct work_struct *work)
1858 } else { 1855 } else {
1859 dev_dbg(di->dev, "Battery recovered from OVV\n"); 1856 dev_dbg(di->dev, "Battery recovered from OVV\n");
1860 di->flags.bat_ovv = false; 1857 di->flags.bat_ovv = false;
1861 power_supply_changed(&di->fg_psy); 1858 power_supply_changed(di->fg_psy);
1862 } 1859 }
1863} 1860}
1864 1861
@@ -2096,9 +2093,7 @@ static int ab8500_fg_get_property(struct power_supply *psy,
2096 enum power_supply_property psp, 2093 enum power_supply_property psp,
2097 union power_supply_propval *val) 2094 union power_supply_propval *val)
2098{ 2095{
2099 struct ab8500_fg *di; 2096 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2100
2101 di = to_ab8500_fg_device_info(psy);
2102 2097
2103 /* 2098 /*
2104 * If battery is identified as unknown and charging of unknown 2099 * If battery is identified as unknown and charging of unknown
@@ -2181,14 +2176,14 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2181 2176
2182 psy = (struct power_supply *)data; 2177 psy = (struct power_supply *)data;
2183 ext = dev_get_drvdata(dev); 2178 ext = dev_get_drvdata(dev);
2184 di = to_ab8500_fg_device_info(psy); 2179 di = power_supply_get_drvdata(psy);
2185 2180
2186 /* 2181 /*
2187 * For all psy where the name of your driver 2182 * For all psy where the name of your driver
2188 * appears in any supplied_to 2183 * appears in any supplied_to
2189 */ 2184 */
2190 for (i = 0; i < ext->num_supplicants; i++) { 2185 for (i = 0; i < ext->num_supplicants; i++) {
2191 if (!strcmp(ext->supplied_to[i], psy->name)) 2186 if (!strcmp(ext->supplied_to[i], psy->desc->name))
2192 psy_found = true; 2187 psy_found = true;
2193 } 2188 }
2194 2189
@@ -2196,16 +2191,16 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2196 return 0; 2191 return 0;
2197 2192
2198 /* Go through all properties for the psy */ 2193 /* Go through all properties for the psy */
2199 for (j = 0; j < ext->num_properties; j++) { 2194 for (j = 0; j < ext->desc->num_properties; j++) {
2200 enum power_supply_property prop; 2195 enum power_supply_property prop;
2201 prop = ext->properties[j]; 2196 prop = ext->desc->properties[j];
2202 2197
2203 if (power_supply_get_property(ext, prop, &ret)) 2198 if (power_supply_get_property(ext, prop, &ret))
2204 continue; 2199 continue;
2205 2200
2206 switch (prop) { 2201 switch (prop) {
2207 case POWER_SUPPLY_PROP_STATUS: 2202 case POWER_SUPPLY_PROP_STATUS:
2208 switch (ext->type) { 2203 switch (ext->desc->type) {
2209 case POWER_SUPPLY_TYPE_BATTERY: 2204 case POWER_SUPPLY_TYPE_BATTERY:
2210 switch (ret.intval) { 2205 switch (ret.intval) {
2211 case POWER_SUPPLY_STATUS_UNKNOWN: 2206 case POWER_SUPPLY_STATUS_UNKNOWN:
@@ -2244,7 +2239,7 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2244 }; 2239 };
2245 break; 2240 break;
2246 case POWER_SUPPLY_PROP_TECHNOLOGY: 2241 case POWER_SUPPLY_PROP_TECHNOLOGY:
2247 switch (ext->type) { 2242 switch (ext->desc->type) {
2248 case POWER_SUPPLY_TYPE_BATTERY: 2243 case POWER_SUPPLY_TYPE_BATTERY:
2249 if (!di->flags.batt_id_received && 2244 if (!di->flags.batt_id_received &&
2250 di->bm->batt_id != BATTERY_UNKNOWN) { 2245 di->bm->batt_id != BATTERY_UNKNOWN) {
@@ -2274,7 +2269,7 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2274 } 2269 }
2275 break; 2270 break;
2276 case POWER_SUPPLY_PROP_TEMP: 2271 case POWER_SUPPLY_PROP_TEMP:
2277 switch (ext->type) { 2272 switch (ext->desc->type) {
2278 case POWER_SUPPLY_TYPE_BATTERY: 2273 case POWER_SUPPLY_TYPE_BATTERY:
2279 if (di->flags.batt_id_received) 2274 if (di->flags.batt_id_received)
2280 di->bat_temp = ret.intval; 2275 di->bat_temp = ret.intval;
@@ -2399,10 +2394,10 @@ out:
2399 */ 2394 */
2400static void ab8500_fg_external_power_changed(struct power_supply *psy) 2395static void ab8500_fg_external_power_changed(struct power_supply *psy)
2401{ 2396{
2402 struct ab8500_fg *di = to_ab8500_fg_device_info(psy); 2397 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2403 2398
2404 class_for_each_device(power_supply_class, NULL, 2399 class_for_each_device(power_supply_class, NULL,
2405 &di->fg_psy, ab8500_fg_get_ext_psy_data); 2400 di->fg_psy, ab8500_fg_get_ext_psy_data);
2406} 2401}
2407 2402
2408/** 2403/**
@@ -2580,9 +2575,7 @@ static ssize_t ab8505_powercut_flagtime_read(struct device *dev,
2580 int ret; 2575 int ret;
2581 u8 reg_value; 2576 u8 reg_value;
2582 struct power_supply *psy = dev_get_drvdata(dev); 2577 struct power_supply *psy = dev_get_drvdata(dev);
2583 struct ab8500_fg *di; 2578 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2584
2585 di = to_ab8500_fg_device_info(psy);
2586 2579
2587 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2580 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2588 AB8505_RTC_PCUT_FLAG_TIME_REG, &reg_value); 2581 AB8505_RTC_PCUT_FLAG_TIME_REG, &reg_value);
@@ -2605,9 +2598,7 @@ static ssize_t ab8505_powercut_flagtime_write(struct device *dev,
2605 int ret; 2598 int ret;
2606 long unsigned reg_value; 2599 long unsigned reg_value;
2607 struct power_supply *psy = dev_get_drvdata(dev); 2600 struct power_supply *psy = dev_get_drvdata(dev);
2608 struct ab8500_fg *di; 2601 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2609
2610 di = to_ab8500_fg_device_info(psy);
2611 2602
2612 reg_value = simple_strtoul(buf, NULL, 10); 2603 reg_value = simple_strtoul(buf, NULL, 10);
2613 2604
@@ -2633,9 +2624,7 @@ static ssize_t ab8505_powercut_maxtime_read(struct device *dev,
2633 int ret; 2624 int ret;
2634 u8 reg_value; 2625 u8 reg_value;
2635 struct power_supply *psy = dev_get_drvdata(dev); 2626 struct power_supply *psy = dev_get_drvdata(dev);
2636 struct ab8500_fg *di; 2627 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2637
2638 di = to_ab8500_fg_device_info(psy);
2639 2628
2640 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2629 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2641 AB8505_RTC_PCUT_MAX_TIME_REG, &reg_value); 2630 AB8505_RTC_PCUT_MAX_TIME_REG, &reg_value);
@@ -2659,9 +2648,7 @@ static ssize_t ab8505_powercut_maxtime_write(struct device *dev,
2659 int ret; 2648 int ret;
2660 int reg_value; 2649 int reg_value;
2661 struct power_supply *psy = dev_get_drvdata(dev); 2650 struct power_supply *psy = dev_get_drvdata(dev);
2662 struct ab8500_fg *di; 2651 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2663
2664 di = to_ab8500_fg_device_info(psy);
2665 2652
2666 reg_value = simple_strtoul(buf, NULL, 10); 2653 reg_value = simple_strtoul(buf, NULL, 10);
2667 if (reg_value > 0x7F) { 2654 if (reg_value > 0x7F) {
@@ -2686,9 +2673,7 @@ static ssize_t ab8505_powercut_restart_read(struct device *dev,
2686 int ret; 2673 int ret;
2687 u8 reg_value; 2674 u8 reg_value;
2688 struct power_supply *psy = dev_get_drvdata(dev); 2675 struct power_supply *psy = dev_get_drvdata(dev);
2689 struct ab8500_fg *di; 2676 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2690
2691 di = to_ab8500_fg_device_info(psy);
2692 2677
2693 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2678 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2694 AB8505_RTC_PCUT_RESTART_REG, &reg_value); 2679 AB8505_RTC_PCUT_RESTART_REG, &reg_value);
@@ -2711,9 +2696,7 @@ static ssize_t ab8505_powercut_restart_write(struct device *dev,
2711 int ret; 2696 int ret;
2712 int reg_value; 2697 int reg_value;
2713 struct power_supply *psy = dev_get_drvdata(dev); 2698 struct power_supply *psy = dev_get_drvdata(dev);
2714 struct ab8500_fg *di; 2699 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2715
2716 di = to_ab8500_fg_device_info(psy);
2717 2700
2718 reg_value = simple_strtoul(buf, NULL, 10); 2701 reg_value = simple_strtoul(buf, NULL, 10);
2719 if (reg_value > 0xF) { 2702 if (reg_value > 0xF) {
@@ -2739,9 +2722,7 @@ static ssize_t ab8505_powercut_timer_read(struct device *dev,
2739 int ret; 2722 int ret;
2740 u8 reg_value; 2723 u8 reg_value;
2741 struct power_supply *psy = dev_get_drvdata(dev); 2724 struct power_supply *psy = dev_get_drvdata(dev);
2742 struct ab8500_fg *di; 2725 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2743
2744 di = to_ab8500_fg_device_info(psy);
2745 2726
2746 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2727 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2747 AB8505_RTC_PCUT_TIME_REG, &reg_value); 2728 AB8505_RTC_PCUT_TIME_REG, &reg_value);
@@ -2764,9 +2745,7 @@ static ssize_t ab8505_powercut_restart_counter_read(struct device *dev,
2764 int ret; 2745 int ret;
2765 u8 reg_value; 2746 u8 reg_value;
2766 struct power_supply *psy = dev_get_drvdata(dev); 2747 struct power_supply *psy = dev_get_drvdata(dev);
2767 struct ab8500_fg *di; 2748 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2768
2769 di = to_ab8500_fg_device_info(psy);
2770 2749
2771 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2750 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2772 AB8505_RTC_PCUT_RESTART_REG, &reg_value); 2751 AB8505_RTC_PCUT_RESTART_REG, &reg_value);
@@ -2789,9 +2768,7 @@ static ssize_t ab8505_powercut_read(struct device *dev,
2789 int ret; 2768 int ret;
2790 u8 reg_value; 2769 u8 reg_value;
2791 struct power_supply *psy = dev_get_drvdata(dev); 2770 struct power_supply *psy = dev_get_drvdata(dev);
2792 struct ab8500_fg *di; 2771 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2793
2794 di = to_ab8500_fg_device_info(psy);
2795 2772
2796 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2773 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2797 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value); 2774 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
@@ -2812,9 +2789,7 @@ static ssize_t ab8505_powercut_write(struct device *dev,
2812 int ret; 2789 int ret;
2813 int reg_value; 2790 int reg_value;
2814 struct power_supply *psy = dev_get_drvdata(dev); 2791 struct power_supply *psy = dev_get_drvdata(dev);
2815 struct ab8500_fg *di; 2792 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2816
2817 di = to_ab8500_fg_device_info(psy);
2818 2793
2819 reg_value = simple_strtoul(buf, NULL, 10); 2794 reg_value = simple_strtoul(buf, NULL, 10);
2820 if (reg_value > 0x1) { 2795 if (reg_value > 0x1) {
@@ -2840,9 +2815,7 @@ static ssize_t ab8505_powercut_flag_read(struct device *dev,
2840 int ret; 2815 int ret;
2841 u8 reg_value; 2816 u8 reg_value;
2842 struct power_supply *psy = dev_get_drvdata(dev); 2817 struct power_supply *psy = dev_get_drvdata(dev);
2843 struct ab8500_fg *di; 2818 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2844
2845 di = to_ab8500_fg_device_info(psy);
2846 2819
2847 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2820 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2848 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value); 2821 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
@@ -2865,9 +2838,7 @@ static ssize_t ab8505_powercut_debounce_read(struct device *dev,
2865 int ret; 2838 int ret;
2866 u8 reg_value; 2839 u8 reg_value;
2867 struct power_supply *psy = dev_get_drvdata(dev); 2840 struct power_supply *psy = dev_get_drvdata(dev);
2868 struct ab8500_fg *di; 2841 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2869
2870 di = to_ab8500_fg_device_info(psy);
2871 2842
2872 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2843 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2873 AB8505_RTC_PCUT_DEBOUNCE_REG, &reg_value); 2844 AB8505_RTC_PCUT_DEBOUNCE_REG, &reg_value);
@@ -2890,9 +2861,7 @@ static ssize_t ab8505_powercut_debounce_write(struct device *dev,
2890 int ret; 2861 int ret;
2891 int reg_value; 2862 int reg_value;
2892 struct power_supply *psy = dev_get_drvdata(dev); 2863 struct power_supply *psy = dev_get_drvdata(dev);
2893 struct ab8500_fg *di; 2864 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2894
2895 di = to_ab8500_fg_device_info(psy);
2896 2865
2897 reg_value = simple_strtoul(buf, NULL, 10); 2866 reg_value = simple_strtoul(buf, NULL, 10);
2898 if (reg_value > 0x7) { 2867 if (reg_value > 0x7) {
@@ -2917,9 +2886,7 @@ static ssize_t ab8505_powercut_enable_status_read(struct device *dev,
2917 int ret; 2886 int ret;
2918 u8 reg_value; 2887 u8 reg_value;
2919 struct power_supply *psy = dev_get_drvdata(dev); 2888 struct power_supply *psy = dev_get_drvdata(dev);
2920 struct ab8500_fg *di; 2889 struct ab8500_fg *di = power_supply_get_drvdata(psy);
2921
2922 di = to_ab8500_fg_device_info(psy);
2923 2890
2924 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC, 2891 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2925 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value); 2892 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
@@ -2962,15 +2929,16 @@ static int ab8500_fg_sysfs_psy_create_attrs(struct ab8500_fg *di)
2962 abx500_get_chip_id(di->dev) >= AB8500_CUT2P0) 2929 abx500_get_chip_id(di->dev) >= AB8500_CUT2P0)
2963 || is_ab8540(di->parent)) { 2930 || is_ab8540(di->parent)) {
2964 for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++) 2931 for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++)
2965 if (device_create_file(di->fg_psy.dev, 2932 if (device_create_file(&di->fg_psy->dev,
2966 &ab8505_fg_sysfs_psy_attrs[i])) 2933 &ab8505_fg_sysfs_psy_attrs[i]))
2967 goto sysfs_psy_create_attrs_failed_ab8505; 2934 goto sysfs_psy_create_attrs_failed_ab8505;
2968 } 2935 }
2969 return 0; 2936 return 0;
2970sysfs_psy_create_attrs_failed_ab8505: 2937sysfs_psy_create_attrs_failed_ab8505:
2971 dev_err(di->fg_psy.dev, "Failed creating sysfs psy attrs for ab8505.\n"); 2938 dev_err(&di->fg_psy->dev, "Failed creating sysfs psy attrs for ab8505.\n");
2972 while (i--) 2939 while (i--)
2973 device_remove_file(di->fg_psy.dev, &ab8505_fg_sysfs_psy_attrs[i]); 2940 device_remove_file(&di->fg_psy->dev,
2941 &ab8505_fg_sysfs_psy_attrs[i]);
2974 2942
2975 return -EIO; 2943 return -EIO;
2976} 2944}
@@ -2983,7 +2951,7 @@ static void ab8500_fg_sysfs_psy_remove_attrs(struct ab8500_fg *di)
2983 abx500_get_chip_id(di->dev) >= AB8500_CUT2P0) 2951 abx500_get_chip_id(di->dev) >= AB8500_CUT2P0)
2984 || is_ab8540(di->parent)) { 2952 || is_ab8540(di->parent)) {
2985 for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++) 2953 for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++)
2986 (void)device_remove_file(di->fg_psy.dev, 2954 (void)device_remove_file(&di->fg_psy->dev,
2987 &ab8505_fg_sysfs_psy_attrs[i]); 2955 &ab8505_fg_sysfs_psy_attrs[i]);
2988 } 2956 }
2989} 2957}
@@ -3050,7 +3018,7 @@ static int ab8500_fg_remove(struct platform_device *pdev)
3050 3018
3051 flush_scheduled_work(); 3019 flush_scheduled_work();
3052 ab8500_fg_sysfs_psy_remove_attrs(di); 3020 ab8500_fg_sysfs_psy_remove_attrs(di);
3053 power_supply_unregister(&di->fg_psy); 3021 power_supply_unregister(di->fg_psy);
3054 return ret; 3022 return ret;
3055} 3023}
3056 3024
@@ -3071,6 +3039,15 @@ static char *supply_interface[] = {
3071 "ab8500_usb", 3039 "ab8500_usb",
3072}; 3040};
3073 3041
3042static const struct power_supply_desc ab8500_fg_desc = {
3043 .name = "ab8500_fg",
3044 .type = POWER_SUPPLY_TYPE_BATTERY,
3045 .properties = ab8500_fg_props,
3046 .num_properties = ARRAY_SIZE(ab8500_fg_props),
3047 .get_property = ab8500_fg_get_property,
3048 .external_power_changed = ab8500_fg_external_power_changed,
3049};
3050
3074static int ab8500_fg_probe(struct platform_device *pdev) 3051static int ab8500_fg_probe(struct platform_device *pdev)
3075{ 3052{
3076 struct device_node *np = pdev->dev.of_node; 3053 struct device_node *np = pdev->dev.of_node;
@@ -3107,15 +3084,9 @@ static int ab8500_fg_probe(struct platform_device *pdev)
3107 di->parent = dev_get_drvdata(pdev->dev.parent); 3084 di->parent = dev_get_drvdata(pdev->dev.parent);
3108 di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 3085 di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
3109 3086
3110 di->fg_psy.name = "ab8500_fg";
3111 di->fg_psy.type = POWER_SUPPLY_TYPE_BATTERY;
3112 di->fg_psy.properties = ab8500_fg_props;
3113 di->fg_psy.num_properties = ARRAY_SIZE(ab8500_fg_props);
3114 di->fg_psy.get_property = ab8500_fg_get_property;
3115 di->fg_psy.external_power_changed = ab8500_fg_external_power_changed;
3116
3117 psy_cfg.supplied_to = supply_interface; 3087 psy_cfg.supplied_to = supply_interface;
3118 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 3088 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
3089 psy_cfg.drv_data = di;
3119 3090
3120 di->bat_cap.max_mah_design = MILLI_TO_MICRO * 3091 di->bat_cap.max_mah_design = MILLI_TO_MICRO *
3121 di->bm->bat_type[di->bm->batt_id].charge_full_design; 3092 di->bm->bat_type[di->bm->batt_id].charge_full_design;
@@ -3176,9 +3147,10 @@ static int ab8500_fg_probe(struct platform_device *pdev)
3176 di->flags.batt_id_received = false; 3147 di->flags.batt_id_received = false;
3177 3148
3178 /* Register FG power supply class */ 3149 /* Register FG power supply class */
3179 ret = power_supply_register(di->dev, &di->fg_psy, &psy_cfg); 3150 di->fg_psy = power_supply_register(di->dev, &ab8500_fg_desc, &psy_cfg);
3180 if (ret) { 3151 if (IS_ERR(di->fg_psy)) {
3181 dev_err(di->dev, "failed to register FG psy\n"); 3152 dev_err(di->dev, "failed to register FG psy\n");
3153 ret = PTR_ERR(di->fg_psy);
3182 goto free_inst_curr_wq; 3154 goto free_inst_curr_wq;
3183 } 3155 }
3184 3156
@@ -3256,7 +3228,7 @@ static int ab8500_fg_probe(struct platform_device *pdev)
3256 return ret; 3228 return ret;
3257 3229
3258free_irq: 3230free_irq:
3259 power_supply_unregister(&di->fg_psy); 3231 power_supply_unregister(di->fg_psy);
3260 3232
3261 /* We also have to free all registered irqs */ 3233 /* We also have to free all registered irqs */
3262 for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq_th); i++) { 3234 for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq_th); i++) {
diff --git a/drivers/power/abx500_chargalg.c b/drivers/power/abx500_chargalg.c
index ac6f4a22f846..541f702e0451 100644
--- a/drivers/power/abx500_chargalg.c
+++ b/drivers/power/abx500_chargalg.c
@@ -50,9 +50,6 @@
50#define CHARGALG_CURR_STEP_LOW 0 50#define CHARGALG_CURR_STEP_LOW 0
51#define CHARGALG_CURR_STEP_HIGH 100 51#define CHARGALG_CURR_STEP_HIGH 100
52 52
53#define to_abx500_chargalg_device_info(x) container_of((x), \
54 struct abx500_chargalg, chargalg_psy);
55
56enum abx500_chargers { 53enum abx500_chargers {
57 NO_CHG, 54 NO_CHG,
58 AC_CHG, 55 AC_CHG,
@@ -256,7 +253,7 @@ struct abx500_chargalg {
256 struct ab8500 *parent; 253 struct ab8500 *parent;
257 struct abx500_chargalg_current_step_status curr_status; 254 struct abx500_chargalg_current_step_status curr_status;
258 struct abx500_bm_data *bm; 255 struct abx500_bm_data *bm;
259 struct power_supply chargalg_psy; 256 struct power_supply *chargalg_psy;
260 struct ux500_charger *ac_chg; 257 struct ux500_charger *ac_chg;
261 struct ux500_charger *usb_chg; 258 struct ux500_charger *usb_chg;
262 struct abx500_chargalg_events events; 259 struct abx500_chargalg_events events;
@@ -695,7 +692,7 @@ static void abx500_chargalg_stop_charging(struct abx500_chargalg *di)
695 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; 692 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
696 di->maintenance_chg = false; 693 di->maintenance_chg = false;
697 cancel_delayed_work(&di->chargalg_wd_work); 694 cancel_delayed_work(&di->chargalg_wd_work);
698 power_supply_changed(&di->chargalg_psy); 695 power_supply_changed(di->chargalg_psy);
699} 696}
700 697
701/** 698/**
@@ -715,7 +712,7 @@ static void abx500_chargalg_hold_charging(struct abx500_chargalg *di)
715 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 712 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
716 di->maintenance_chg = false; 713 di->maintenance_chg = false;
717 cancel_delayed_work(&di->chargalg_wd_work); 714 cancel_delayed_work(&di->chargalg_wd_work);
718 power_supply_changed(&di->chargalg_psy); 715 power_supply_changed(di->chargalg_psy);
719} 716}
720 717
721/** 718/**
@@ -842,7 +839,7 @@ static void abx500_chargalg_end_of_charge(struct abx500_chargalg *di)
842 di->charge_status = POWER_SUPPLY_STATUS_FULL; 839 di->charge_status = POWER_SUPPLY_STATUS_FULL;
843 di->maintenance_chg = true; 840 di->maintenance_chg = true;
844 dev_dbg(di->dev, "EOC reached!\n"); 841 dev_dbg(di->dev, "EOC reached!\n");
845 power_supply_changed(&di->chargalg_psy); 842 power_supply_changed(di->chargalg_psy);
846 } else { 843 } else {
847 dev_dbg(di->dev, 844 dev_dbg(di->dev,
848 " EOC limit reached for the %d" 845 " EOC limit reached for the %d"
@@ -987,10 +984,10 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
987 984
988 psy = (struct power_supply *)data; 985 psy = (struct power_supply *)data;
989 ext = dev_get_drvdata(dev); 986 ext = dev_get_drvdata(dev);
990 di = to_abx500_chargalg_device_info(psy); 987 di = power_supply_get_drvdata(psy);
991 /* For all psy where the driver name appears in any supplied_to */ 988 /* For all psy where the driver name appears in any supplied_to */
992 for (i = 0; i < ext->num_supplicants; i++) { 989 for (i = 0; i < ext->num_supplicants; i++) {
993 if (!strcmp(ext->supplied_to[i], psy->name)) 990 if (!strcmp(ext->supplied_to[i], psy->desc->name))
994 psy_found = true; 991 psy_found = true;
995 } 992 }
996 if (!psy_found) 993 if (!psy_found)
@@ -1007,23 +1004,25 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1007 } 1004 }
1008 1005
1009 /* Go through all properties for the psy */ 1006 /* Go through all properties for the psy */
1010 for (j = 0; j < ext->num_properties; j++) { 1007 for (j = 0; j < ext->desc->num_properties; j++) {
1011 enum power_supply_property prop; 1008 enum power_supply_property prop;
1012 prop = ext->properties[j]; 1009 prop = ext->desc->properties[j];
1013 1010
1014 /* Initialize chargers if not already done */ 1011 /*
1012 * Initialize chargers if not already done.
1013 * The ab8500_charger*/
1015 if (!di->ac_chg && 1014 if (!di->ac_chg &&
1016 ext->type == POWER_SUPPLY_TYPE_MAINS) 1015 ext->desc->type == POWER_SUPPLY_TYPE_MAINS)
1017 di->ac_chg = psy_to_ux500_charger(ext); 1016 di->ac_chg = psy_to_ux500_charger(ext);
1018 else if (!di->usb_chg && 1017 else if (!di->usb_chg &&
1019 ext->type == POWER_SUPPLY_TYPE_USB) 1018 ext->desc->type == POWER_SUPPLY_TYPE_USB)
1020 di->usb_chg = psy_to_ux500_charger(ext); 1019 di->usb_chg = psy_to_ux500_charger(ext);
1021 1020
1022 if (power_supply_get_property(ext, prop, &ret)) 1021 if (power_supply_get_property(ext, prop, &ret))
1023 continue; 1022 continue;
1024 switch (prop) { 1023 switch (prop) {
1025 case POWER_SUPPLY_PROP_PRESENT: 1024 case POWER_SUPPLY_PROP_PRESENT:
1026 switch (ext->type) { 1025 switch (ext->desc->type) {
1027 case POWER_SUPPLY_TYPE_BATTERY: 1026 case POWER_SUPPLY_TYPE_BATTERY:
1028 /* Battery present */ 1027 /* Battery present */
1029 if (ret.intval) 1028 if (ret.intval)
@@ -1070,7 +1069,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1070 break; 1069 break;
1071 1070
1072 case POWER_SUPPLY_PROP_ONLINE: 1071 case POWER_SUPPLY_PROP_ONLINE:
1073 switch (ext->type) { 1072 switch (ext->desc->type) {
1074 case POWER_SUPPLY_TYPE_BATTERY: 1073 case POWER_SUPPLY_TYPE_BATTERY:
1075 break; 1074 break;
1076 case POWER_SUPPLY_TYPE_MAINS: 1075 case POWER_SUPPLY_TYPE_MAINS:
@@ -1115,7 +1114,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1115 break; 1114 break;
1116 1115
1117 case POWER_SUPPLY_PROP_HEALTH: 1116 case POWER_SUPPLY_PROP_HEALTH:
1118 switch (ext->type) { 1117 switch (ext->desc->type) {
1119 case POWER_SUPPLY_TYPE_BATTERY: 1118 case POWER_SUPPLY_TYPE_BATTERY:
1120 break; 1119 break;
1121 case POWER_SUPPLY_TYPE_MAINS: 1120 case POWER_SUPPLY_TYPE_MAINS:
@@ -1198,7 +1197,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1198 break; 1197 break;
1199 1198
1200 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 1199 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1201 switch (ext->type) { 1200 switch (ext->desc->type) {
1202 case POWER_SUPPLY_TYPE_BATTERY: 1201 case POWER_SUPPLY_TYPE_BATTERY:
1203 di->batt_data.volt = ret.intval / 1000; 1202 di->batt_data.volt = ret.intval / 1000;
1204 break; 1203 break;
@@ -1214,7 +1213,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1214 break; 1213 break;
1215 1214
1216 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 1215 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
1217 switch (ext->type) { 1216 switch (ext->desc->type) {
1218 case POWER_SUPPLY_TYPE_MAINS: 1217 case POWER_SUPPLY_TYPE_MAINS:
1219 /* AVG is used to indicate when we are 1218 /* AVG is used to indicate when we are
1220 * in CV mode */ 1219 * in CV mode */
@@ -1239,7 +1238,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1239 break; 1238 break;
1240 1239
1241 case POWER_SUPPLY_PROP_TECHNOLOGY: 1240 case POWER_SUPPLY_PROP_TECHNOLOGY:
1242 switch (ext->type) { 1241 switch (ext->desc->type) {
1243 case POWER_SUPPLY_TYPE_BATTERY: 1242 case POWER_SUPPLY_TYPE_BATTERY:
1244 if (ret.intval) 1243 if (ret.intval)
1245 di->events.batt_unknown = false; 1244 di->events.batt_unknown = false;
@@ -1257,7 +1256,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1257 break; 1256 break;
1258 1257
1259 case POWER_SUPPLY_PROP_CURRENT_NOW: 1258 case POWER_SUPPLY_PROP_CURRENT_NOW:
1260 switch (ext->type) { 1259 switch (ext->desc->type) {
1261 case POWER_SUPPLY_TYPE_MAINS: 1260 case POWER_SUPPLY_TYPE_MAINS:
1262 di->chg_info.ac_curr = 1261 di->chg_info.ac_curr =
1263 ret.intval / 1000; 1262 ret.intval / 1000;
@@ -1275,7 +1274,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1275 break; 1274 break;
1276 1275
1277 case POWER_SUPPLY_PROP_CURRENT_AVG: 1276 case POWER_SUPPLY_PROP_CURRENT_AVG:
1278 switch (ext->type) { 1277 switch (ext->desc->type) {
1279 case POWER_SUPPLY_TYPE_BATTERY: 1278 case POWER_SUPPLY_TYPE_BATTERY:
1280 di->batt_data.avg_curr = ret.intval / 1000; 1279 di->batt_data.avg_curr = ret.intval / 1000;
1281 break; 1280 break;
@@ -1311,7 +1310,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1311 */ 1310 */
1312static void abx500_chargalg_external_power_changed(struct power_supply *psy) 1311static void abx500_chargalg_external_power_changed(struct power_supply *psy)
1313{ 1312{
1314 struct abx500_chargalg *di = to_abx500_chargalg_device_info(psy); 1313 struct abx500_chargalg *di = power_supply_get_drvdata(psy);
1315 1314
1316 /* 1315 /*
1317 * Trigger execution of the algorithm instantly and read 1316 * Trigger execution of the algorithm instantly and read
@@ -1336,7 +1335,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1336 1335
1337 /* Collect data from all power_supply class devices */ 1336 /* Collect data from all power_supply class devices */
1338 class_for_each_device(power_supply_class, NULL, 1337 class_for_each_device(power_supply_class, NULL,
1339 &di->chargalg_psy, abx500_chargalg_get_ext_psy_data); 1338 di->chargalg_psy, abx500_chargalg_get_ext_psy_data);
1340 1339
1341 abx500_chargalg_end_of_charge(di); 1340 abx500_chargalg_end_of_charge(di);
1342 abx500_chargalg_check_temp(di); 1341 abx500_chargalg_check_temp(di);
@@ -1478,7 +1477,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1478 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; 1477 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1479 di->maintenance_chg = false; 1478 di->maintenance_chg = false;
1480 abx500_chargalg_state_to(di, STATE_SUSPENDED); 1479 abx500_chargalg_state_to(di, STATE_SUSPENDED);
1481 power_supply_changed(&di->chargalg_psy); 1480 power_supply_changed(di->chargalg_psy);
1482 /* Intentional fallthrough */ 1481 /* Intentional fallthrough */
1483 1482
1484 case STATE_SUSPENDED: 1483 case STATE_SUSPENDED:
@@ -1576,7 +1575,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1576 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 1575 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
1577 di->eoc_cnt = 0; 1576 di->eoc_cnt = 0;
1578 di->maintenance_chg = false; 1577 di->maintenance_chg = false;
1579 power_supply_changed(&di->chargalg_psy); 1578 power_supply_changed(di->chargalg_psy);
1580 1579
1581 break; 1580 break;
1582 1581
@@ -1624,7 +1623,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1624 di->bm->bat_type[ 1623 di->bm->bat_type[
1625 di->bm->batt_id].maint_a_cur_lvl); 1624 di->bm->batt_id].maint_a_cur_lvl);
1626 abx500_chargalg_state_to(di, STATE_MAINTENANCE_A); 1625 abx500_chargalg_state_to(di, STATE_MAINTENANCE_A);
1627 power_supply_changed(&di->chargalg_psy); 1626 power_supply_changed(di->chargalg_psy);
1628 /* Intentional fallthrough*/ 1627 /* Intentional fallthrough*/
1629 1628
1630 case STATE_MAINTENANCE_A: 1629 case STATE_MAINTENANCE_A:
@@ -1644,7 +1643,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1644 di->bm->bat_type[ 1643 di->bm->bat_type[
1645 di->bm->batt_id].maint_b_cur_lvl); 1644 di->bm->batt_id].maint_b_cur_lvl);
1646 abx500_chargalg_state_to(di, STATE_MAINTENANCE_B); 1645 abx500_chargalg_state_to(di, STATE_MAINTENANCE_B);
1647 power_supply_changed(&di->chargalg_psy); 1646 power_supply_changed(di->chargalg_psy);
1648 /* Intentional fallthrough*/ 1647 /* Intentional fallthrough*/
1649 1648
1650 case STATE_MAINTENANCE_B: 1649 case STATE_MAINTENANCE_B:
@@ -1663,7 +1662,7 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1663 abx500_chargalg_stop_maintenance_timer(di); 1662 abx500_chargalg_stop_maintenance_timer(di);
1664 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 1663 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
1665 abx500_chargalg_state_to(di, STATE_TEMP_LOWHIGH); 1664 abx500_chargalg_state_to(di, STATE_TEMP_LOWHIGH);
1666 power_supply_changed(&di->chargalg_psy); 1665 power_supply_changed(di->chargalg_psy);
1667 /* Intentional fallthrough */ 1666 /* Intentional fallthrough */
1668 1667
1669 case STATE_TEMP_LOWHIGH: 1668 case STATE_TEMP_LOWHIGH:
@@ -1779,9 +1778,7 @@ static int abx500_chargalg_get_property(struct power_supply *psy,
1779 enum power_supply_property psp, 1778 enum power_supply_property psp,
1780 union power_supply_propval *val) 1779 union power_supply_propval *val)
1781{ 1780{
1782 struct abx500_chargalg *di; 1781 struct abx500_chargalg *di = power_supply_get_drvdata(psy);
1783
1784 di = to_abx500_chargalg_device_info(psy);
1785 1782
1786 switch (psp) { 1783 switch (psp) {
1787 case POWER_SUPPLY_PROP_STATUS: 1784 case POWER_SUPPLY_PROP_STATUS:
@@ -2034,7 +2031,7 @@ static int abx500_chargalg_remove(struct platform_device *pdev)
2034 /* Delete the work queue */ 2031 /* Delete the work queue */
2035 destroy_workqueue(di->chargalg_wq); 2032 destroy_workqueue(di->chargalg_wq);
2036 2033
2037 power_supply_unregister(&di->chargalg_psy); 2034 power_supply_unregister(di->chargalg_psy);
2038 2035
2039 return 0; 2036 return 0;
2040} 2037}
@@ -2043,6 +2040,15 @@ static char *supply_interface[] = {
2043 "ab8500_fg", 2040 "ab8500_fg",
2044}; 2041};
2045 2042
2043static const struct power_supply_desc abx500_chargalg_desc = {
2044 .name = "abx500_chargalg",
2045 .type = POWER_SUPPLY_TYPE_BATTERY,
2046 .properties = abx500_chargalg_props,
2047 .num_properties = ARRAY_SIZE(abx500_chargalg_props),
2048 .get_property = abx500_chargalg_get_property,
2049 .external_power_changed = abx500_chargalg_external_power_changed,
2050};
2051
2046static int abx500_chargalg_probe(struct platform_device *pdev) 2052static int abx500_chargalg_probe(struct platform_device *pdev)
2047{ 2053{
2048 struct device_node *np = pdev->dev.of_node; 2054 struct device_node *np = pdev->dev.of_node;
@@ -2075,17 +2081,9 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
2075 di->dev = &pdev->dev; 2081 di->dev = &pdev->dev;
2076 di->parent = dev_get_drvdata(pdev->dev.parent); 2082 di->parent = dev_get_drvdata(pdev->dev.parent);
2077 2083
2078 /* chargalg supply */
2079 di->chargalg_psy.name = "abx500_chargalg";
2080 di->chargalg_psy.type = POWER_SUPPLY_TYPE_BATTERY;
2081 di->chargalg_psy.properties = abx500_chargalg_props;
2082 di->chargalg_psy.num_properties = ARRAY_SIZE(abx500_chargalg_props);
2083 di->chargalg_psy.get_property = abx500_chargalg_get_property;
2084 di->chargalg_psy.external_power_changed =
2085 abx500_chargalg_external_power_changed;
2086
2087 psy_cfg.supplied_to = supply_interface; 2084 psy_cfg.supplied_to = supply_interface;
2088 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 2085 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
2086 psy_cfg.drv_data = di;
2089 2087
2090 /* Initilialize safety timer */ 2088 /* Initilialize safety timer */
2091 hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 2089 hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
@@ -2117,9 +2115,11 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
2117 di->chg_info.prev_conn_chg = -1; 2115 di->chg_info.prev_conn_chg = -1;
2118 2116
2119 /* Register chargalg power supply class */ 2117 /* Register chargalg power supply class */
2120 ret = power_supply_register(di->dev, &di->chargalg_psy, &psy_cfg); 2118 di->chargalg_psy = power_supply_register(di->dev, &abx500_chargalg_desc,
2121 if (ret) { 2119 &psy_cfg);
2120 if (IS_ERR(di->chargalg_psy)) {
2122 dev_err(di->dev, "failed to register chargalg psy\n"); 2121 dev_err(di->dev, "failed to register chargalg psy\n");
2122 ret = PTR_ERR(di->chargalg_psy);
2123 goto free_chargalg_wq; 2123 goto free_chargalg_wq;
2124 } 2124 }
2125 2125
@@ -2140,7 +2140,7 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
2140 return ret; 2140 return ret;
2141 2141
2142free_psy: 2142free_psy:
2143 power_supply_unregister(&di->chargalg_psy); 2143 power_supply_unregister(di->chargalg_psy);
2144free_chargalg_wq: 2144free_chargalg_wq:
2145 destroy_workqueue(di->chargalg_wq); 2145 destroy_workqueue(di->chargalg_wq);
2146 return ret; 2146 return ret;
diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index 2206f9ff6488..9d1a7fbcaed4 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -48,7 +48,7 @@ static int __find_main_battery(struct device *dev, void *data)
48 48
49 bp->bat = dev_get_drvdata(dev); 49 bp->bat = dev_get_drvdata(dev);
50 50
51 if (bp->bat->use_for_apm) { 51 if (bp->bat->desc->use_for_apm) {
52 /* nice, we explicitly asked to report this battery. */ 52 /* nice, we explicitly asked to report this battery. */
53 bp->main = bp->bat; 53 bp->main = bp->bat;
54 return 1; 54 return 1;
diff --git a/drivers/power/axp288_fuel_gauge.c b/drivers/power/axp288_fuel_gauge.c
index 2bec8d241e62..ca1cc5a47eb1 100644
--- a/drivers/power/axp288_fuel_gauge.c
+++ b/drivers/power/axp288_fuel_gauge.c
@@ -127,7 +127,7 @@ struct axp288_fg_info {
127 struct regmap *regmap; 127 struct regmap *regmap;
128 struct regmap_irq_chip_data *regmap_irqc; 128 struct regmap_irq_chip_data *regmap_irqc;
129 int irq[AXP288_FG_INTR_NUM]; 129 int irq[AXP288_FG_INTR_NUM];
130 struct power_supply bat; 130 struct power_supply *bat;
131 struct mutex lock; 131 struct mutex lock;
132 int status; 132 int status;
133 struct delayed_work status_monitor; 133 struct delayed_work status_monitor;
@@ -588,8 +588,7 @@ static int fuel_gauge_get_property(struct power_supply *ps,
588 enum power_supply_property prop, 588 enum power_supply_property prop,
589 union power_supply_propval *val) 589 union power_supply_propval *val)
590{ 590{
591 struct axp288_fg_info *info = container_of(ps, 591 struct axp288_fg_info *info = power_supply_get_drvdata(ps);
592 struct axp288_fg_info, bat);
593 int ret = 0, value; 592 int ret = 0, value;
594 593
595 mutex_lock(&info->lock); 594 mutex_lock(&info->lock);
@@ -715,8 +714,7 @@ static int fuel_gauge_set_property(struct power_supply *ps,
715 enum power_supply_property prop, 714 enum power_supply_property prop,
716 const union power_supply_propval *val) 715 const union power_supply_propval *val)
717{ 716{
718 struct axp288_fg_info *info = container_of(ps, 717 struct axp288_fg_info *info = power_supply_get_drvdata(ps);
719 struct axp288_fg_info, bat);
720 int ret = 0; 718 int ret = 0;
721 719
722 mutex_lock(&info->lock); 720 mutex_lock(&info->lock);
@@ -798,7 +796,7 @@ static void fuel_gauge_status_monitor(struct work_struct *work)
798 struct axp288_fg_info, status_monitor.work); 796 struct axp288_fg_info, status_monitor.work);
799 797
800 fuel_gauge_get_status(info); 798 fuel_gauge_get_status(info);
801 power_supply_changed(&info->bat); 799 power_supply_changed(info->bat);
802 schedule_delayed_work(&info->status_monitor, STATUS_MON_DELAY_JIFFIES); 800 schedule_delayed_work(&info->status_monitor, STATUS_MON_DELAY_JIFFIES);
803} 801}
804 802
@@ -844,18 +842,28 @@ static irqreturn_t fuel_gauge_thread_handler(int irq, void *dev)
844 dev_warn(&info->pdev->dev, "Spurious Interrupt!!!\n"); 842 dev_warn(&info->pdev->dev, "Spurious Interrupt!!!\n");
845 } 843 }
846 844
847 power_supply_changed(&info->bat); 845 power_supply_changed(info->bat);
848 return IRQ_HANDLED; 846 return IRQ_HANDLED;
849} 847}
850 848
851static void fuel_gauge_external_power_changed(struct power_supply *psy) 849static void fuel_gauge_external_power_changed(struct power_supply *psy)
852{ 850{
853 struct axp288_fg_info *info = container_of(psy, 851 struct axp288_fg_info *info = power_supply_get_drvdata(psy);
854 struct axp288_fg_info, bat);
855 852
856 power_supply_changed(&info->bat); 853 power_supply_changed(info->bat);
857} 854}
858 855
856static const struct power_supply_desc fuel_gauge_desc = {
857 .name = DEV_NAME,
858 .type = POWER_SUPPLY_TYPE_BATTERY,
859 .properties = fuel_gauge_props,
860 .num_properties = ARRAY_SIZE(fuel_gauge_props),
861 .get_property = fuel_gauge_get_property,
862 .set_property = fuel_gauge_set_property,
863 .property_is_writeable = fuel_gauge_property_is_writeable,
864 .external_power_changed = fuel_gauge_external_power_changed,
865};
866
859static int fuel_gauge_set_lowbatt_thresholds(struct axp288_fg_info *info) 867static int fuel_gauge_set_lowbatt_thresholds(struct axp288_fg_info *info)
860{ 868{
861 int ret; 869 int ret;
@@ -1070,9 +1078,10 @@ static void fuel_gauge_init_hw_regs(struct axp288_fg_info *info)
1070 1078
1071static int axp288_fuel_gauge_probe(struct platform_device *pdev) 1079static int axp288_fuel_gauge_probe(struct platform_device *pdev)
1072{ 1080{
1073 int ret; 1081 int ret = 0;
1074 struct axp288_fg_info *info; 1082 struct axp288_fg_info *info;
1075 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); 1083 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
1084 struct power_supply_config psy_cfg = {};
1076 1085
1077 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 1086 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
1078 if (!info) 1087 if (!info)
@@ -1091,16 +1100,10 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
1091 mutex_init(&info->lock); 1100 mutex_init(&info->lock);
1092 INIT_DELAYED_WORK(&info->status_monitor, fuel_gauge_status_monitor); 1101 INIT_DELAYED_WORK(&info->status_monitor, fuel_gauge_status_monitor);
1093 1102
1094 info->bat.name = DEV_NAME; 1103 psy_cfg.drv_data = info;
1095 info->bat.type = POWER_SUPPLY_TYPE_BATTERY; 1104 info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg);
1096 info->bat.properties = fuel_gauge_props; 1105 if (IS_ERR(info->bat)) {
1097 info->bat.num_properties = ARRAY_SIZE(fuel_gauge_props); 1106 ret = PTR_ERR(info->bat);
1098 info->bat.get_property = fuel_gauge_get_property;
1099 info->bat.set_property = fuel_gauge_set_property;
1100 info->bat.property_is_writeable = fuel_gauge_property_is_writeable;
1101 info->bat.external_power_changed = fuel_gauge_external_power_changed;
1102 ret = power_supply_register(&pdev->dev, &info->bat, NULL);
1103 if (ret) {
1104 dev_err(&pdev->dev, "failed to register battery: %d\n", ret); 1107 dev_err(&pdev->dev, "failed to register battery: %d\n", ret);
1105 return ret; 1108 return ret;
1106 } 1109 }
@@ -1125,7 +1128,7 @@ static int axp288_fuel_gauge_remove(struct platform_device *pdev)
1125 int i; 1128 int i;
1126 1129
1127 cancel_delayed_work_sync(&info->status_monitor); 1130 cancel_delayed_work_sync(&info->status_monitor);
1128 power_supply_unregister(&info->bat); 1131 power_supply_unregister(info->bat);
1129 fuel_gauge_remove_debugfs(info); 1132 fuel_gauge_remove_debugfs(info);
1130 1133
1131 for (i = 0; i < AXP288_FG_INTR_NUM; i++) 1134 for (i = 0; i < AXP288_FG_INTR_NUM; i++)
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index d31ccc7935d0..c745d278815d 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -166,7 +166,8 @@ static char *bq2415x_chip_name[] = {
166struct bq2415x_device { 166struct bq2415x_device {
167 struct device *dev; 167 struct device *dev;
168 struct bq2415x_platform_data init_data; 168 struct bq2415x_platform_data init_data;
169 struct power_supply charger; 169 struct power_supply *charger;
170 struct power_supply_desc charger_desc;
170 struct delayed_work work; 171 struct delayed_work work;
171 struct power_supply *notify_psy; 172 struct power_supply *notify_psy;
172 struct notifier_block nb; 173 struct notifier_block nb;
@@ -784,7 +785,7 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode)
784 bq2415x_set_default_value(bq, battery_regulation_voltage); 785 bq2415x_set_default_value(bq, battery_regulation_voltage);
785 786
786 bq->mode = mode; 787 bq->mode = mode;
787 sysfs_notify(&bq->charger.dev->kobj, NULL, "mode"); 788 sysfs_notify(&bq->charger->dev.kobj, NULL, "mode");
788 789
789 return 0; 790 return 0;
790 791
@@ -868,7 +869,7 @@ static void bq2415x_set_autotimer(struct bq2415x_device *bq, int state)
868static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg) 869static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg)
869{ 870{
870 bq->timer_error = msg; 871 bq->timer_error = msg;
871 sysfs_notify(&bq->charger.dev->kobj, NULL, "timer"); 872 sysfs_notify(&bq->charger->dev.kobj, NULL, "timer");
872 dev_err(bq->dev, "%s\n", msg); 873 dev_err(bq->dev, "%s\n", msg);
873 if (bq->automode > 0) 874 if (bq->automode > 0)
874 bq->automode = 0; 875 bq->automode = 0;
@@ -886,7 +887,7 @@ static void bq2415x_timer_work(struct work_struct *work)
886 int boost; 887 int boost;
887 888
888 if (bq->automode > 0 && (bq->reported_mode != bq->mode)) { 889 if (bq->automode > 0 && (bq->reported_mode != bq->mode)) {
889 sysfs_notify(&bq->charger.dev->kobj, NULL, "reported_mode"); 890 sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode");
890 bq2415x_set_mode(bq, bq->reported_mode); 891 bq2415x_set_mode(bq, bq->reported_mode);
891 } 892 }
892 893
@@ -992,8 +993,7 @@ static int bq2415x_power_supply_get_property(struct power_supply *psy,
992 enum power_supply_property psp, 993 enum power_supply_property psp,
993 union power_supply_propval *val) 994 union power_supply_propval *val)
994{ 995{
995 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 996 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
996 charger);
997 int ret; 997 int ret;
998 998
999 switch (psp) { 999 switch (psp) {
@@ -1024,12 +1024,14 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
1024 int ret; 1024 int ret;
1025 int chip; 1025 int chip;
1026 char revstr[8]; 1026 char revstr[8];
1027 struct power_supply_config psy_cfg = { .drv_data = bq, };
1027 1028
1028 bq->charger.name = bq->name; 1029 bq->charger_desc.name = bq->name;
1029 bq->charger.type = POWER_SUPPLY_TYPE_USB; 1030 bq->charger_desc.type = POWER_SUPPLY_TYPE_USB;
1030 bq->charger.properties = bq2415x_power_supply_props; 1031 bq->charger_desc.properties = bq2415x_power_supply_props;
1031 bq->charger.num_properties = ARRAY_SIZE(bq2415x_power_supply_props); 1032 bq->charger_desc.num_properties =
1032 bq->charger.get_property = bq2415x_power_supply_get_property; 1033 ARRAY_SIZE(bq2415x_power_supply_props);
1034 bq->charger_desc.get_property = bq2415x_power_supply_get_property;
1033 1035
1034 ret = bq2415x_detect_chip(bq); 1036 ret = bq2415x_detect_chip(bq);
1035 if (ret < 0) 1037 if (ret < 0)
@@ -1052,10 +1054,11 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
1052 return -ENOMEM; 1054 return -ENOMEM;
1053 } 1055 }
1054 1056
1055 ret = power_supply_register(bq->dev, &bq->charger, NULL); 1057 bq->charger = power_supply_register(bq->dev, &bq->charger_desc,
1056 if (ret) { 1058 &psy_cfg);
1059 if (IS_ERR(bq->charger)) {
1057 kfree(bq->model); 1060 kfree(bq->model);
1058 return ret; 1061 return PTR_ERR(bq->charger);
1059 } 1062 }
1060 1063
1061 return 0; 1064 return 0;
@@ -1067,7 +1070,7 @@ static void bq2415x_power_supply_exit(struct bq2415x_device *bq)
1067 if (bq->automode > 0) 1070 if (bq->automode > 0)
1068 bq->automode = 0; 1071 bq->automode = 0;
1069 cancel_delayed_work_sync(&bq->work); 1072 cancel_delayed_work_sync(&bq->work);
1070 power_supply_unregister(&bq->charger); 1073 power_supply_unregister(bq->charger);
1071 kfree(bq->model); 1074 kfree(bq->model);
1072} 1075}
1073 1076
@@ -1079,8 +1082,7 @@ static ssize_t bq2415x_sysfs_show_status(struct device *dev,
1079 char *buf) 1082 char *buf)
1080{ 1083{
1081 struct power_supply *psy = dev_get_drvdata(dev); 1084 struct power_supply *psy = dev_get_drvdata(dev);
1082 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1085 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1083 charger);
1084 enum bq2415x_command command; 1086 enum bq2415x_command command;
1085 int ret; 1087 int ret;
1086 1088
@@ -1113,8 +1115,7 @@ static ssize_t bq2415x_sysfs_set_timer(struct device *dev,
1113 size_t count) 1115 size_t count)
1114{ 1116{
1115 struct power_supply *psy = dev_get_drvdata(dev); 1117 struct power_supply *psy = dev_get_drvdata(dev);
1116 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1118 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1117 charger);
1118 int ret = 0; 1119 int ret = 0;
1119 1120
1120 if (strncmp(buf, "auto", 4) == 0) 1121 if (strncmp(buf, "auto", 4) == 0)
@@ -1135,8 +1136,7 @@ static ssize_t bq2415x_sysfs_show_timer(struct device *dev,
1135 char *buf) 1136 char *buf)
1136{ 1137{
1137 struct power_supply *psy = dev_get_drvdata(dev); 1138 struct power_supply *psy = dev_get_drvdata(dev);
1138 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1139 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1139 charger);
1140 1140
1141 if (bq->timer_error) 1141 if (bq->timer_error)
1142 return sprintf(buf, "%s\n", bq->timer_error); 1142 return sprintf(buf, "%s\n", bq->timer_error);
@@ -1160,8 +1160,7 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
1160 size_t count) 1160 size_t count)
1161{ 1161{
1162 struct power_supply *psy = dev_get_drvdata(dev); 1162 struct power_supply *psy = dev_get_drvdata(dev);
1163 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1163 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1164 charger);
1165 enum bq2415x_mode mode; 1164 enum bq2415x_mode mode;
1166 int ret = 0; 1165 int ret = 0;
1167 1166
@@ -1213,8 +1212,7 @@ static ssize_t bq2415x_sysfs_show_mode(struct device *dev,
1213 char *buf) 1212 char *buf)
1214{ 1213{
1215 struct power_supply *psy = dev_get_drvdata(dev); 1214 struct power_supply *psy = dev_get_drvdata(dev);
1216 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1215 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1217 charger);
1218 ssize_t ret = 0; 1216 ssize_t ret = 0;
1219 1217
1220 if (bq->automode > 0) 1218 if (bq->automode > 0)
@@ -1251,8 +1249,7 @@ static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev,
1251 char *buf) 1249 char *buf)
1252{ 1250{
1253 struct power_supply *psy = dev_get_drvdata(dev); 1251 struct power_supply *psy = dev_get_drvdata(dev);
1254 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1252 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1255 charger);
1256 1253
1257 if (bq->automode < 0) 1254 if (bq->automode < 0)
1258 return -EINVAL; 1255 return -EINVAL;
@@ -1280,8 +1277,7 @@ static ssize_t bq2415x_sysfs_set_registers(struct device *dev,
1280 size_t count) 1277 size_t count)
1281{ 1278{
1282 struct power_supply *psy = dev_get_drvdata(dev); 1279 struct power_supply *psy = dev_get_drvdata(dev);
1283 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1280 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1284 charger);
1285 ssize_t ret = 0; 1281 ssize_t ret = 0;
1286 unsigned int reg; 1282 unsigned int reg;
1287 unsigned int val; 1283 unsigned int val;
@@ -1316,8 +1312,7 @@ static ssize_t bq2415x_sysfs_show_registers(struct device *dev,
1316 char *buf) 1312 char *buf)
1317{ 1313{
1318 struct power_supply *psy = dev_get_drvdata(dev); 1314 struct power_supply *psy = dev_get_drvdata(dev);
1319 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1315 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1320 charger);
1321 ssize_t ret = 0; 1316 ssize_t ret = 0;
1322 1317
1323 ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_STATUS, buf+ret); 1318 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,
1335 size_t count) 1330 size_t count)
1336{ 1331{
1337 struct power_supply *psy = dev_get_drvdata(dev); 1332 struct power_supply *psy = dev_get_drvdata(dev);
1338 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1333 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1339 charger);
1340 long val; 1334 long val;
1341 int ret; 1335 int ret;
1342 1336
@@ -1367,8 +1361,7 @@ static ssize_t bq2415x_sysfs_show_limit(struct device *dev,
1367 char *buf) 1361 char *buf)
1368{ 1362{
1369 struct power_supply *psy = dev_get_drvdata(dev); 1363 struct power_supply *psy = dev_get_drvdata(dev);
1370 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1364 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1371 charger);
1372 int ret; 1365 int ret;
1373 1366
1374 if (strcmp(attr->attr.name, "current_limit") == 0) 1367 if (strcmp(attr->attr.name, "current_limit") == 0)
@@ -1396,8 +1389,7 @@ static ssize_t bq2415x_sysfs_set_enable(struct device *dev,
1396 size_t count) 1389 size_t count)
1397{ 1390{
1398 struct power_supply *psy = dev_get_drvdata(dev); 1391 struct power_supply *psy = dev_get_drvdata(dev);
1399 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1392 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1400 charger);
1401 enum bq2415x_command command; 1393 enum bq2415x_command command;
1402 long val; 1394 long val;
1403 int ret; 1395 int ret;
@@ -1432,8 +1424,7 @@ static ssize_t bq2415x_sysfs_show_enable(struct device *dev,
1432 char *buf) 1424 char *buf)
1433{ 1425{
1434 struct power_supply *psy = dev_get_drvdata(dev); 1426 struct power_supply *psy = dev_get_drvdata(dev);
1435 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1427 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1436 charger);
1437 enum bq2415x_command command; 1428 enum bq2415x_command command;
1438 int ret; 1429 int ret;
1439 1430
@@ -1524,13 +1515,13 @@ static const struct attribute_group bq2415x_sysfs_attr_group = {
1524 1515
1525static int bq2415x_sysfs_init(struct bq2415x_device *bq) 1516static int bq2415x_sysfs_init(struct bq2415x_device *bq)
1526{ 1517{
1527 return sysfs_create_group(&bq->charger.dev->kobj, 1518 return sysfs_create_group(&bq->charger->dev.kobj,
1528 &bq2415x_sysfs_attr_group); 1519 &bq2415x_sysfs_attr_group);
1529} 1520}
1530 1521
1531static void bq2415x_sysfs_exit(struct bq2415x_device *bq) 1522static void bq2415x_sysfs_exit(struct bq2415x_device *bq)
1532{ 1523{
1533 sysfs_remove_group(&bq->charger.dev->kobj, &bq2415x_sysfs_attr_group); 1524 sysfs_remove_group(&bq->charger->dev.kobj, &bq2415x_sysfs_attr_group);
1534} 1525}
1535 1526
1536/* main bq2415x probe function */ 1527/* main bq2415x probe function */
diff --git a/drivers/power/bq24190_charger.c b/drivers/power/bq24190_charger.c
index 54eb58485d55..407c4af83891 100644
--- a/drivers/power/bq24190_charger.c
+++ b/drivers/power/bq24190_charger.c
@@ -152,8 +152,8 @@
152struct bq24190_dev_info { 152struct bq24190_dev_info {
153 struct i2c_client *client; 153 struct i2c_client *client;
154 struct device *dev; 154 struct device *dev;
155 struct power_supply charger; 155 struct power_supply *charger;
156 struct power_supply battery; 156 struct power_supply *battery;
157 char model_name[I2C_NAME_SIZE]; 157 char model_name[I2C_NAME_SIZE];
158 kernel_ulong_t model; 158 kernel_ulong_t model;
159 unsigned int gpio_int; 159 unsigned int gpio_int;
@@ -423,8 +423,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
423 struct device_attribute *attr, char *buf) 423 struct device_attribute *attr, char *buf)
424{ 424{
425 struct power_supply *psy = dev_get_drvdata(dev); 425 struct power_supply *psy = dev_get_drvdata(dev);
426 struct bq24190_dev_info *bdi = 426 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
427 container_of(psy, struct bq24190_dev_info, charger);
428 struct bq24190_sysfs_field_info *info; 427 struct bq24190_sysfs_field_info *info;
429 int ret; 428 int ret;
430 u8 v; 429 u8 v;
@@ -444,8 +443,7 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
444 struct device_attribute *attr, const char *buf, size_t count) 443 struct device_attribute *attr, const char *buf, size_t count)
445{ 444{
446 struct power_supply *psy = dev_get_drvdata(dev); 445 struct power_supply *psy = dev_get_drvdata(dev);
447 struct bq24190_dev_info *bdi = 446 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
448 container_of(psy, struct bq24190_dev_info, charger);
449 struct bq24190_sysfs_field_info *info; 447 struct bq24190_sysfs_field_info *info;
450 int ret; 448 int ret;
451 u8 v; 449 u8 v;
@@ -469,13 +467,13 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
469{ 467{
470 bq24190_sysfs_init_attrs(); 468 bq24190_sysfs_init_attrs();
471 469
472 return sysfs_create_group(&bdi->charger.dev->kobj, 470 return sysfs_create_group(&bdi->charger->dev.kobj,
473 &bq24190_sysfs_attr_group); 471 &bq24190_sysfs_attr_group);
474} 472}
475 473
476static void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) 474static void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi)
477{ 475{
478 sysfs_remove_group(&bdi->charger.dev->kobj, &bq24190_sysfs_attr_group); 476 sysfs_remove_group(&bdi->charger->dev.kobj, &bq24190_sysfs_attr_group);
479} 477}
480#else 478#else
481static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi) 479static 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,
807static int bq24190_charger_get_property(struct power_supply *psy, 805static int bq24190_charger_get_property(struct power_supply *psy,
808 enum power_supply_property psp, union power_supply_propval *val) 806 enum power_supply_property psp, union power_supply_propval *val)
809{ 807{
810 struct bq24190_dev_info *bdi = 808 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
811 container_of(psy, struct bq24190_dev_info, charger);
812 int ret; 809 int ret;
813 810
814 dev_dbg(bdi->dev, "prop: %d\n", psp); 811 dev_dbg(bdi->dev, "prop: %d\n", psp);
@@ -861,8 +858,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
861 enum power_supply_property psp, 858 enum power_supply_property psp,
862 const union power_supply_propval *val) 859 const union power_supply_propval *val)
863{ 860{
864 struct bq24190_dev_info *bdi = 861 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
865 container_of(psy, struct bq24190_dev_info, charger);
866 int ret; 862 int ret;
867 863
868 dev_dbg(bdi->dev, "prop: %d\n", psp); 864 dev_dbg(bdi->dev, "prop: %d\n", psp);
@@ -922,18 +918,15 @@ static char *bq24190_charger_supplied_to[] = {
922 "main-battery", 918 "main-battery",
923}; 919};
924 920
925static void bq24190_charger_init(struct power_supply *charger) 921static const struct power_supply_desc bq24190_charger_desc = {
926{ 922 .name = "bq24190-charger",
927 charger->name = "bq24190-charger"; 923 .type = POWER_SUPPLY_TYPE_USB,
928 charger->type = POWER_SUPPLY_TYPE_USB; 924 .properties = bq24190_charger_properties,
929 charger->properties = bq24190_charger_properties; 925 .num_properties = ARRAY_SIZE(bq24190_charger_properties),
930 charger->num_properties = ARRAY_SIZE(bq24190_charger_properties); 926 .get_property = bq24190_charger_get_property,
931 charger->supplied_to = bq24190_charger_supplied_to; 927 .set_property = bq24190_charger_set_property,
932 charger->num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to); 928 .property_is_writeable = bq24190_charger_property_is_writeable,
933 charger->get_property = bq24190_charger_get_property; 929};
934 charger->set_property = bq24190_charger_set_property;
935 charger->property_is_writeable = bq24190_charger_property_is_writeable;
936}
937 930
938/* Battery power supply property routines */ 931/* Battery power supply property routines */
939 932
@@ -1102,8 +1095,7 @@ static int bq24190_battery_set_temp_alert_max(struct bq24190_dev_info *bdi,
1102static int bq24190_battery_get_property(struct power_supply *psy, 1095static int bq24190_battery_get_property(struct power_supply *psy,
1103 enum power_supply_property psp, union power_supply_propval *val) 1096 enum power_supply_property psp, union power_supply_propval *val)
1104{ 1097{
1105 struct bq24190_dev_info *bdi = 1098 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
1106 container_of(psy, struct bq24190_dev_info, battery);
1107 int ret; 1099 int ret;
1108 1100
1109 dev_dbg(bdi->dev, "prop: %d\n", psp); 1101 dev_dbg(bdi->dev, "prop: %d\n", psp);
@@ -1144,8 +1136,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
1144 enum power_supply_property psp, 1136 enum power_supply_property psp,
1145 const union power_supply_propval *val) 1137 const union power_supply_propval *val)
1146{ 1138{
1147 struct bq24190_dev_info *bdi = 1139 struct bq24190_dev_info *bdi = power_supply_get_drvdata(psy);
1148 container_of(psy, struct bq24190_dev_info, battery);
1149 int ret; 1140 int ret;
1150 1141
1151 dev_dbg(bdi->dev, "prop: %d\n", psp); 1142 dev_dbg(bdi->dev, "prop: %d\n", psp);
@@ -1193,16 +1184,15 @@ static enum power_supply_property bq24190_battery_properties[] = {
1193 POWER_SUPPLY_PROP_SCOPE, 1184 POWER_SUPPLY_PROP_SCOPE,
1194}; 1185};
1195 1186
1196static void bq24190_battery_init(struct power_supply *battery) 1187static const struct power_supply_desc bq24190_battery_desc = {
1197{ 1188 .name = "bq24190-battery",
1198 battery->name = "bq24190-battery"; 1189 .type = POWER_SUPPLY_TYPE_BATTERY,
1199 battery->type = POWER_SUPPLY_TYPE_BATTERY; 1190 .properties = bq24190_battery_properties,
1200 battery->properties = bq24190_battery_properties; 1191 .num_properties = ARRAY_SIZE(bq24190_battery_properties),
1201 battery->num_properties = ARRAY_SIZE(bq24190_battery_properties); 1192 .get_property = bq24190_battery_get_property,
1202 battery->get_property = bq24190_battery_get_property; 1193 .set_property = bq24190_battery_set_property,
1203 battery->set_property = bq24190_battery_set_property; 1194 .property_is_writeable = bq24190_battery_property_is_writeable,
1204 battery->property_is_writeable = bq24190_battery_property_is_writeable; 1195};
1205}
1206 1196
1207static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) 1197static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
1208{ 1198{
@@ -1269,8 +1259,8 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
1269 * interrupt received). 1259 * interrupt received).
1270 */ 1260 */
1271 if (alert_userspace && !bdi->first_time) { 1261 if (alert_userspace && !bdi->first_time) {
1272 power_supply_changed(&bdi->charger); 1262 power_supply_changed(bdi->charger);
1273 power_supply_changed(&bdi->battery); 1263 power_supply_changed(bdi->battery);
1274 bdi->first_time = false; 1264 bdi->first_time = false;
1275 } 1265 }
1276 1266
@@ -1362,6 +1352,7 @@ static int bq24190_probe(struct i2c_client *client,
1362 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1352 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1363 struct device *dev = &client->dev; 1353 struct device *dev = &client->dev;
1364 struct bq24190_platform_data *pdata = client->dev.platform_data; 1354 struct bq24190_platform_data *pdata = client->dev.platform_data;
1355 struct power_supply_config charger_cfg = {}, battery_cfg = {};
1365 struct bq24190_dev_info *bdi; 1356 struct bq24190_dev_info *bdi;
1366 int ret; 1357 int ret;
1367 1358
@@ -1416,19 +1407,23 @@ static int bq24190_probe(struct i2c_client *client,
1416 goto out2; 1407 goto out2;
1417 } 1408 }
1418 1409
1419 bq24190_charger_init(&bdi->charger); 1410 charger_cfg.drv_data = bdi;
1420 1411 charger_cfg.supplied_to = bq24190_charger_supplied_to;
1421 ret = power_supply_register(dev, &bdi->charger, NULL); 1412 charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to),
1422 if (ret) { 1413 bdi->charger = power_supply_register(dev, &bq24190_charger_desc,
1414 &charger_cfg);
1415 if (IS_ERR(bdi->charger)) {
1423 dev_err(dev, "Can't register charger\n"); 1416 dev_err(dev, "Can't register charger\n");
1417 ret = PTR_ERR(bdi->charger);
1424 goto out2; 1418 goto out2;
1425 } 1419 }
1426 1420
1427 bq24190_battery_init(&bdi->battery); 1421 battery_cfg.drv_data = bdi;
1428 1422 bdi->battery = power_supply_register(dev, &bq24190_battery_desc,
1429 ret = power_supply_register(dev, &bdi->battery, NULL); 1423 &battery_cfg);
1430 if (ret) { 1424 if (IS_ERR(bdi->battery)) {
1431 dev_err(dev, "Can't register battery\n"); 1425 dev_err(dev, "Can't register battery\n");
1426 ret = PTR_ERR(bdi->battery);
1432 goto out3; 1427 goto out3;
1433 } 1428 }
1434 1429
@@ -1441,9 +1436,9 @@ static int bq24190_probe(struct i2c_client *client,
1441 return 0; 1436 return 0;
1442 1437
1443out4: 1438out4:
1444 power_supply_unregister(&bdi->battery); 1439 power_supply_unregister(bdi->battery);
1445out3: 1440out3:
1446 power_supply_unregister(&bdi->charger); 1441 power_supply_unregister(bdi->charger);
1447out2: 1442out2:
1448 pm_runtime_disable(dev); 1443 pm_runtime_disable(dev);
1449out1: 1444out1:
@@ -1462,8 +1457,8 @@ static int bq24190_remove(struct i2c_client *client)
1462 pm_runtime_put_sync(bdi->dev); 1457 pm_runtime_put_sync(bdi->dev);
1463 1458
1464 bq24190_sysfs_remove_group(bdi); 1459 bq24190_sysfs_remove_group(bdi);
1465 power_supply_unregister(&bdi->battery); 1460 power_supply_unregister(bdi->battery);
1466 power_supply_unregister(&bdi->charger); 1461 power_supply_unregister(bdi->charger);
1467 pm_runtime_disable(bdi->dev); 1462 pm_runtime_disable(bdi->dev);
1468 1463
1469 if (bdi->gpio_int) 1464 if (bdi->gpio_int)
@@ -1499,8 +1494,8 @@ static int bq24190_pm_resume(struct device *dev)
1499 pm_runtime_put_sync(bdi->dev); 1494 pm_runtime_put_sync(bdi->dev);
1500 1495
1501 /* Things may have changed while suspended so alert upper layer */ 1496 /* Things may have changed while suspended so alert upper layer */
1502 power_supply_changed(&bdi->charger); 1497 power_supply_changed(bdi->charger);
1503 power_supply_changed(&bdi->battery); 1498 power_supply_changed(bdi->battery);
1504 1499
1505 return 0; 1500 return 0;
1506} 1501}
diff --git a/drivers/power/bq24735-charger.c b/drivers/power/bq24735-charger.c
index 242e79bfe217..961a18930027 100644
--- a/drivers/power/bq24735-charger.c
+++ b/drivers/power/bq24735-charger.c
@@ -44,14 +44,15 @@
44#define BQ24735_DEVICE_ID 0xff 44#define BQ24735_DEVICE_ID 0xff
45 45
46struct bq24735 { 46struct bq24735 {
47 struct power_supply charger; 47 struct power_supply *charger;
48 struct i2c_client *client; 48 struct power_supply_desc charger_desc;
49 struct bq24735_platform *pdata; 49 struct i2c_client *client;
50 struct bq24735_platform *pdata;
50}; 51};
51 52
52static inline struct bq24735 *to_bq24735(struct power_supply *psy) 53static inline struct bq24735 *to_bq24735(struct power_supply *psy)
53{ 54{
54 return container_of(psy, struct bq24735, charger); 55 return power_supply_get_drvdata(psy);
55} 56}
56 57
57static enum power_supply_property bq24735_charger_properties[] = { 58static enum power_supply_property bq24735_charger_properties[] = {
@@ -192,9 +193,7 @@ static int bq24735_charger_get_property(struct power_supply *psy,
192 enum power_supply_property psp, 193 enum power_supply_property psp,
193 union power_supply_propval *val) 194 union power_supply_propval *val)
194{ 195{
195 struct bq24735 *charger; 196 struct bq24735 *charger = to_bq24735(psy);
196
197 charger = container_of(psy, struct bq24735, charger);
198 197
199 switch (psp) { 198 switch (psp) {
200 case POWER_SUPPLY_PROP_ONLINE: 199 case POWER_SUPPLY_PROP_ONLINE:
@@ -248,7 +247,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
248{ 247{
249 int ret; 248 int ret;
250 struct bq24735 *charger; 249 struct bq24735 *charger;
251 struct power_supply *supply; 250 struct power_supply_desc *supply_desc;
252 struct power_supply_config psy_cfg = {}; 251 struct power_supply_config psy_cfg = {};
253 char *name; 252 char *name;
254 253
@@ -278,17 +277,18 @@ static int bq24735_charger_probe(struct i2c_client *client,
278 277
279 charger->client = client; 278 charger->client = client;
280 279
281 supply = &charger->charger; 280 supply_desc = &charger->charger_desc;
282 281
283 supply->name = name; 282 supply_desc->name = name;
284 supply->type = POWER_SUPPLY_TYPE_MAINS; 283 supply_desc->type = POWER_SUPPLY_TYPE_MAINS;
285 supply->properties = bq24735_charger_properties; 284 supply_desc->properties = bq24735_charger_properties;
286 supply->num_properties = ARRAY_SIZE(bq24735_charger_properties); 285 supply_desc->num_properties = ARRAY_SIZE(bq24735_charger_properties);
287 supply->get_property = bq24735_charger_get_property; 286 supply_desc->get_property = bq24735_charger_get_property;
288 287
289 psy_cfg.supplied_to = charger->pdata->supplied_to; 288 psy_cfg.supplied_to = charger->pdata->supplied_to;
290 psy_cfg.num_supplicants = charger->pdata->num_supplicants; 289 psy_cfg.num_supplicants = charger->pdata->num_supplicants;
291 psy_cfg.of_node = client->dev.of_node; 290 psy_cfg.of_node = client->dev.of_node;
291 psy_cfg.drv_data = charger;
292 292
293 i2c_set_clientdata(client, charger); 293 i2c_set_clientdata(client, charger);
294 294
@@ -343,8 +343,10 @@ static int bq24735_charger_probe(struct i2c_client *client,
343 } 343 }
344 } 344 }
345 345
346 ret = power_supply_register(&client->dev, supply, &psy_cfg); 346 charger->charger = power_supply_register(&client->dev, supply_desc,
347 if (ret < 0) { 347 &psy_cfg);
348 if (IS_ERR(charger->charger)) {
349 ret = PTR_ERR(charger->charger);
348 dev_err(&client->dev, "Failed to register power supply: %d\n", 350 dev_err(&client->dev, "Failed to register power supply: %d\n",
349 ret); 351 ret);
350 goto err_free_name; 352 goto err_free_name;
@@ -356,7 +358,8 @@ static int bq24735_charger_probe(struct i2c_client *client,
356 IRQF_TRIGGER_RISING | 358 IRQF_TRIGGER_RISING |
357 IRQF_TRIGGER_FALLING | 359 IRQF_TRIGGER_FALLING |
358 IRQF_ONESHOT, 360 IRQF_ONESHOT,
359 supply->name, supply); 361 supply_desc->name,
362 charger->charger);
360 if (ret) { 363 if (ret) {
361 dev_err(&client->dev, 364 dev_err(&client->dev,
362 "Unable to register IRQ %d err %d\n", 365 "Unable to register IRQ %d err %d\n",
@@ -367,7 +370,7 @@ static int bq24735_charger_probe(struct i2c_client *client,
367 370
368 return 0; 371 return 0;
369err_unregister_supply: 372err_unregister_supply:
370 power_supply_unregister(supply); 373 power_supply_unregister(charger->charger);
371err_free_name: 374err_free_name:
372 if (name != charger->pdata->name) 375 if (name != charger->pdata->name)
373 kfree(name); 376 kfree(name);
@@ -383,10 +386,10 @@ static int bq24735_charger_remove(struct i2c_client *client)
383 devm_free_irq(&charger->client->dev, charger->client->irq, 386 devm_free_irq(&charger->client->dev, charger->client->irq,
384 &charger->charger); 387 &charger->charger);
385 388
386 power_supply_unregister(&charger->charger); 389 power_supply_unregister(charger->charger);
387 390
388 if (charger->charger.name != charger->pdata->name) 391 if (charger->charger_desc.name != charger->pdata->name)
389 kfree(charger->charger.name); 392 kfree(charger->charger_desc.name);
390 393
391 return 0; 394 return 0;
392} 395}
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index a992e43908a2..a57433de5c24 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -116,7 +116,7 @@ struct bq27x00_device_info {
116 unsigned long last_update; 116 unsigned long last_update;
117 struct delayed_work work; 117 struct delayed_work work;
118 118
119 struct power_supply bat; 119 struct power_supply *bat;
120 120
121 struct bq27x00_access_methods bus; 121 struct bq27x00_access_methods bus;
122 122
@@ -531,7 +531,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
531 } 531 }
532 532
533 if (di->cache.capacity != cache.capacity) 533 if (di->cache.capacity != cache.capacity)
534 power_supply_changed(&di->bat); 534 power_supply_changed(di->bat);
535 535
536 if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) 536 if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
537 di->cache = cache; 537 di->cache = cache;
@@ -603,7 +603,7 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,
603 status = POWER_SUPPLY_STATUS_FULL; 603 status = POWER_SUPPLY_STATUS_FULL;
604 else if (di->cache.flags & BQ27000_FLAG_CHGS) 604 else if (di->cache.flags & BQ27000_FLAG_CHGS)
605 status = POWER_SUPPLY_STATUS_CHARGING; 605 status = POWER_SUPPLY_STATUS_CHARGING;
606 else if (power_supply_am_i_supplied(&di->bat)) 606 else if (power_supply_am_i_supplied(di->bat))
607 status = POWER_SUPPLY_STATUS_NOT_CHARGING; 607 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
608 else 608 else
609 status = POWER_SUPPLY_STATUS_DISCHARGING; 609 status = POWER_SUPPLY_STATUS_DISCHARGING;
@@ -675,15 +675,12 @@ static int bq27x00_simple_value(int value,
675 return 0; 675 return 0;
676} 676}
677 677
678#define to_bq27x00_device_info(x) container_of((x), \
679 struct bq27x00_device_info, bat);
680
681static int bq27x00_battery_get_property(struct power_supply *psy, 678static int bq27x00_battery_get_property(struct power_supply *psy,
682 enum power_supply_property psp, 679 enum power_supply_property psp,
683 union power_supply_propval *val) 680 union power_supply_propval *val)
684{ 681{
685 int ret = 0; 682 int ret = 0;
686 struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 683 struct bq27x00_device_info *di = power_supply_get_drvdata(psy);
687 684
688 mutex_lock(&di->lock); 685 mutex_lock(&di->lock);
689 if (time_is_before_jiffies(di->last_update + 5 * HZ)) { 686 if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
@@ -761,38 +758,47 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
761 758
762static void bq27x00_external_power_changed(struct power_supply *psy) 759static void bq27x00_external_power_changed(struct power_supply *psy)
763{ 760{
764 struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 761 struct bq27x00_device_info *di = power_supply_get_drvdata(psy);
765 762
766 cancel_delayed_work_sync(&di->work); 763 cancel_delayed_work_sync(&di->work);
767 schedule_delayed_work(&di->work, 0); 764 schedule_delayed_work(&di->work, 0);
768} 765}
769 766
770static int bq27x00_powersupply_init(struct bq27x00_device_info *di) 767static int bq27x00_powersupply_init(struct bq27x00_device_info *di,
768 const char *name)
771{ 769{
772 int ret; 770 int ret;
771 struct power_supply_desc *psy_desc;
772 struct power_supply_config psy_cfg = { .drv_data = di, };
773
774 psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL);
775 if (!psy_desc)
776 return -ENOMEM;
773 777
774 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 778 psy_desc->name = name;
779 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
775 if (di->chip == BQ27425) { 780 if (di->chip == BQ27425) {
776 di->bat.properties = bq27425_battery_props; 781 psy_desc->properties = bq27425_battery_props;
777 di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); 782 psy_desc->num_properties = ARRAY_SIZE(bq27425_battery_props);
778 } else if (di->chip == BQ27742) { 783 } else if (di->chip == BQ27742) {
779 di->bat.properties = bq27742_battery_props; 784 psy_desc->properties = bq27742_battery_props;
780 di->bat.num_properties = ARRAY_SIZE(bq27742_battery_props); 785 psy_desc->num_properties = ARRAY_SIZE(bq27742_battery_props);
781 } else if (di->chip == BQ27510) { 786 } else if (di->chip == BQ27510) {
782 di->bat.properties = bq27510_battery_props; 787 psy_desc->properties = bq27510_battery_props;
783 di->bat.num_properties = ARRAY_SIZE(bq27510_battery_props); 788 psy_desc->num_properties = ARRAY_SIZE(bq27510_battery_props);
784 } else { 789 } else {
785 di->bat.properties = bq27x00_battery_props; 790 psy_desc->properties = bq27x00_battery_props;
786 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); 791 psy_desc->num_properties = ARRAY_SIZE(bq27x00_battery_props);
787 } 792 }
788 di->bat.get_property = bq27x00_battery_get_property; 793 psy_desc->get_property = bq27x00_battery_get_property;
789 di->bat.external_power_changed = bq27x00_external_power_changed; 794 psy_desc->external_power_changed = bq27x00_external_power_changed;
790 795
791 INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll); 796 INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
792 mutex_init(&di->lock); 797 mutex_init(&di->lock);
793 798
794 ret = power_supply_register_no_ws(di->dev, &di->bat, NULL); 799 di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg);
795 if (ret) { 800 if (IS_ERR(di->bat)) {
801 ret = PTR_ERR(di->bat);
796 dev_err(di->dev, "failed to register battery: %d\n", ret); 802 dev_err(di->dev, "failed to register battery: %d\n", ret);
797 return ret; 803 return ret;
798 } 804 }
@@ -816,7 +822,7 @@ static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
816 822
817 cancel_delayed_work_sync(&di->work); 823 cancel_delayed_work_sync(&di->work);
818 824
819 power_supply_unregister(&di->bat); 825 power_supply_unregister(di->bat);
820 826
821 mutex_destroy(&di->lock); 827 mutex_destroy(&di->lock);
822} 828}
@@ -880,37 +886,34 @@ static int bq27x00_battery_probe(struct i2c_client *client,
880 if (num < 0) 886 if (num < 0)
881 return num; 887 return num;
882 888
883 name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); 889 name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num);
884 if (!name) { 890 if (!name) {
885 dev_err(&client->dev, "failed to allocate device name\n"); 891 dev_err(&client->dev, "failed to allocate device name\n");
886 retval = -ENOMEM; 892 retval = -ENOMEM;
887 goto batt_failed_1; 893 goto batt_failed;
888 } 894 }
889 895
890 di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); 896 di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
891 if (!di) { 897 if (!di) {
892 dev_err(&client->dev, "failed to allocate device info data\n"); 898 dev_err(&client->dev, "failed to allocate device info data\n");
893 retval = -ENOMEM; 899 retval = -ENOMEM;
894 goto batt_failed_2; 900 goto batt_failed;
895 } 901 }
896 902
897 di->id = num; 903 di->id = num;
898 di->dev = &client->dev; 904 di->dev = &client->dev;
899 di->chip = id->driver_data; 905 di->chip = id->driver_data;
900 di->bat.name = name;
901 di->bus.read = &bq27x00_read_i2c; 906 di->bus.read = &bq27x00_read_i2c;
902 907
903 retval = bq27x00_powersupply_init(di); 908 retval = bq27x00_powersupply_init(di, name);
904 if (retval) 909 if (retval)
905 goto batt_failed_2; 910 goto batt_failed;
906 911
907 i2c_set_clientdata(client, di); 912 i2c_set_clientdata(client, di);
908 913
909 return 0; 914 return 0;
910 915
911batt_failed_2: 916batt_failed:
912 kfree(name);
913batt_failed_1:
914 mutex_lock(&battery_mutex); 917 mutex_lock(&battery_mutex);
915 idr_remove(&battery_id, num); 918 idr_remove(&battery_id, num);
916 mutex_unlock(&battery_mutex); 919 mutex_unlock(&battery_mutex);
@@ -924,8 +927,6 @@ static int bq27x00_battery_remove(struct i2c_client *client)
924 927
925 bq27x00_powersupply_unregister(di); 928 bq27x00_powersupply_unregister(di);
926 929
927 kfree(di->bat.name);
928
929 mutex_lock(&battery_mutex); 930 mutex_lock(&battery_mutex);
930 idr_remove(&battery_id, di->id); 931 idr_remove(&battery_id, di->id);
931 mutex_unlock(&battery_mutex); 932 mutex_unlock(&battery_mutex);
@@ -1014,6 +1015,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
1014{ 1015{
1015 struct bq27x00_device_info *di; 1016 struct bq27x00_device_info *di;
1016 struct bq27000_platform_data *pdata = pdev->dev.platform_data; 1017 struct bq27000_platform_data *pdata = pdev->dev.platform_data;
1018 const char *name;
1017 1019
1018 if (!pdata) { 1020 if (!pdata) {
1019 dev_err(&pdev->dev, "no platform_data supplied\n"); 1021 dev_err(&pdev->dev, "no platform_data supplied\n");
@@ -1036,10 +1038,10 @@ static int bq27000_battery_probe(struct platform_device *pdev)
1036 di->dev = &pdev->dev; 1038 di->dev = &pdev->dev;
1037 di->chip = BQ27000; 1039 di->chip = BQ27000;
1038 1040
1039 di->bat.name = pdata->name ?: dev_name(&pdev->dev); 1041 name = pdata->name ?: dev_name(&pdev->dev);
1040 di->bus.read = &bq27000_read_platform; 1042 di->bus.read = &bq27000_read_platform;
1041 1043
1042 return bq27x00_powersupply_init(di); 1044 return bq27x00_powersupply_init(di, name);
1043} 1045}
1044 1046
1045static int bq27000_battery_remove(struct platform_device *pdev) 1047static int bq27000_battery_remove(struct platform_device *pdev)
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index a5b86b60d244..5c47409c6889 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -864,8 +864,7 @@ static int charger_get_property(struct power_supply *psy,
864 enum power_supply_property psp, 864 enum power_supply_property psp,
865 union power_supply_propval *val) 865 union power_supply_propval *val)
866{ 866{
867 struct charger_manager *cm = container_of(psy, 867 struct charger_manager *cm = power_supply_get_drvdata(psy);
868 struct charger_manager, charger_psy);
869 struct charger_desc *desc = cm->desc; 868 struct charger_desc *desc = cm->desc;
870 struct power_supply *fuel_gauge; 869 struct power_supply *fuel_gauge;
871 int ret = 0; 870 int ret = 0;
@@ -1018,7 +1017,7 @@ static enum power_supply_property default_charger_props[] = {
1018 */ 1017 */
1019}; 1018};
1020 1019
1021static struct power_supply psy_default = { 1020static const struct power_supply_desc psy_default = {
1022 .name = "battery", 1021 .name = "battery",
1023 .type = POWER_SUPPLY_TYPE_BATTERY, 1022 .type = POWER_SUPPLY_TYPE_BATTERY,
1024 .properties = default_charger_props, 1023 .properties = default_charger_props,
@@ -1399,7 +1398,7 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
1399 dev_info(cm->dev, "'%s' regulator's externally_control is %d\n", 1398 dev_info(cm->dev, "'%s' regulator's externally_control is %d\n",
1400 charger->regulator_name, charger->externally_control); 1399 charger->regulator_name, charger->externally_control);
1401 1400
1402 ret = sysfs_create_group(&cm->charger_psy.dev->kobj, 1401 ret = sysfs_create_group(&cm->charger_psy->dev.kobj,
1403 &charger->attr_g); 1402 &charger->attr_g);
1404 if (ret < 0) { 1403 if (ret < 0) {
1405 dev_err(cm->dev, "Cannot create sysfs entry of %s regulator\n", 1404 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,
1431 POWER_SUPPLY_PROP_TEMP, &val); 1430 POWER_SUPPLY_PROP_TEMP, &val);
1432 1431
1433 if (!ret) { 1432 if (!ret) {
1434 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1433 cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
1435 POWER_SUPPLY_PROP_TEMP; 1434 POWER_SUPPLY_PROP_TEMP;
1436 cm->charger_psy.num_properties++; 1435 cm->charger_psy_desc.num_properties++;
1437 cm->desc->measure_battery_temp = true; 1436 cm->desc->measure_battery_temp = true;
1438 } 1437 }
1439#ifdef CONFIG_THERMAL 1438#ifdef CONFIG_THERMAL
@@ -1444,9 +1443,9 @@ static int cm_init_thermal_data(struct charger_manager *cm,
1444 return PTR_ERR(cm->tzd_batt); 1443 return PTR_ERR(cm->tzd_batt);
1445 1444
1446 /* Use external thermometer */ 1445 /* Use external thermometer */
1447 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1446 cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
1448 POWER_SUPPLY_PROP_TEMP_AMBIENT; 1447 POWER_SUPPLY_PROP_TEMP_AMBIENT;
1449 cm->charger_psy.num_properties++; 1448 cm->charger_psy_desc.num_properties++;
1450 cm->desc->measure_battery_temp = true; 1449 cm->desc->measure_battery_temp = true;
1451 ret = 0; 1450 ret = 0;
1452 } 1451 }
@@ -1606,6 +1605,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1606 int j = 0; 1605 int j = 0;
1607 union power_supply_propval val; 1606 union power_supply_propval val;
1608 struct power_supply *fuel_gauge; 1607 struct power_supply *fuel_gauge;
1608 struct power_supply_config psy_cfg = {};
1609 1609
1610 if (IS_ERR(desc)) { 1610 if (IS_ERR(desc)) {
1611 dev_err(&pdev->dev, "No platform data (desc) found\n"); 1611 dev_err(&pdev->dev, "No platform data (desc) found\n");
@@ -1620,6 +1620,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1620 /* Basic Values. Unspecified are Null or 0 */ 1620 /* Basic Values. Unspecified are Null or 0 */
1621 cm->dev = &pdev->dev; 1621 cm->dev = &pdev->dev;
1622 cm->desc = desc; 1622 cm->desc = desc;
1623 psy_cfg.drv_data = cm;
1623 1624
1624 /* Initialize alarm timer */ 1625 /* Initialize alarm timer */
1625 if (alarmtimer_get_rtcdev()) { 1626 if (alarmtimer_get_rtcdev()) {
@@ -1699,40 +1700,40 @@ static int charger_manager_probe(struct platform_device *pdev)
1699 1700
1700 platform_set_drvdata(pdev, cm); 1701 platform_set_drvdata(pdev, cm);
1701 1702
1702 memcpy(&cm->charger_psy, &psy_default, sizeof(psy_default)); 1703 memcpy(&cm->charger_psy_desc, &psy_default, sizeof(psy_default));
1703 1704
1704 if (!desc->psy_name) 1705 if (!desc->psy_name)
1705 strncpy(cm->psy_name_buf, psy_default.name, PSY_NAME_MAX); 1706 strncpy(cm->psy_name_buf, psy_default.name, PSY_NAME_MAX);
1706 else 1707 else
1707 strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX); 1708 strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX);
1708 cm->charger_psy.name = cm->psy_name_buf; 1709 cm->charger_psy_desc.name = cm->psy_name_buf;
1709 1710
1710 /* Allocate for psy properties because they may vary */ 1711 /* Allocate for psy properties because they may vary */
1711 cm->charger_psy.properties = devm_kzalloc(&pdev->dev, 1712 cm->charger_psy_desc.properties = devm_kzalloc(&pdev->dev,
1712 sizeof(enum power_supply_property) 1713 sizeof(enum power_supply_property)
1713 * (ARRAY_SIZE(default_charger_props) + 1714 * (ARRAY_SIZE(default_charger_props) +
1714 NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL); 1715 NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
1715 if (!cm->charger_psy.properties) 1716 if (!cm->charger_psy_desc.properties)
1716 return -ENOMEM; 1717 return -ENOMEM;
1717 1718
1718 memcpy(cm->charger_psy.properties, default_charger_props, 1719 memcpy(cm->charger_psy_desc.properties, default_charger_props,
1719 sizeof(enum power_supply_property) * 1720 sizeof(enum power_supply_property) *
1720 ARRAY_SIZE(default_charger_props)); 1721 ARRAY_SIZE(default_charger_props));
1721 cm->charger_psy.num_properties = psy_default.num_properties; 1722 cm->charger_psy_desc.num_properties = psy_default.num_properties;
1722 1723
1723 /* Find which optional psy-properties are available */ 1724 /* Find which optional psy-properties are available */
1724 if (!power_supply_get_property(fuel_gauge, 1725 if (!power_supply_get_property(fuel_gauge,
1725 POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { 1726 POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
1726 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1727 cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
1727 POWER_SUPPLY_PROP_CHARGE_NOW; 1728 POWER_SUPPLY_PROP_CHARGE_NOW;
1728 cm->charger_psy.num_properties++; 1729 cm->charger_psy_desc.num_properties++;
1729 } 1730 }
1730 if (!power_supply_get_property(fuel_gauge, 1731 if (!power_supply_get_property(fuel_gauge,
1731 POWER_SUPPLY_PROP_CURRENT_NOW, 1732 POWER_SUPPLY_PROP_CURRENT_NOW,
1732 &val)) { 1733 &val)) {
1733 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1734 cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
1734 POWER_SUPPLY_PROP_CURRENT_NOW; 1735 POWER_SUPPLY_PROP_CURRENT_NOW;
1735 cm->charger_psy.num_properties++; 1736 cm->charger_psy_desc.num_properties++;
1736 } 1737 }
1737 1738
1738 ret = cm_init_thermal_data(cm, fuel_gauge); 1739 ret = cm_init_thermal_data(cm, fuel_gauge);
@@ -1743,11 +1744,12 @@ static int charger_manager_probe(struct platform_device *pdev)
1743 1744
1744 INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk); 1745 INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
1745 1746
1746 ret = power_supply_register(NULL, &cm->charger_psy, NULL); 1747 cm->charger_psy = power_supply_register(NULL, &cm->charger_psy_desc,
1747 if (ret) { 1748 &psy_cfg);
1749 if (IS_ERR(cm->charger_psy)) {
1748 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n", 1750 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
1749 cm->charger_psy.name); 1751 cm->charger_psy->desc->name);
1750 return ret; 1752 return PTR_ERR(cm->charger_psy);
1751 } 1753 }
1752 1754
1753 /* Register extcon device for charger cable */ 1755 /* Register extcon device for charger cable */
@@ -1793,7 +1795,7 @@ err_reg_sysfs:
1793 struct charger_regulator *charger; 1795 struct charger_regulator *charger;
1794 1796
1795 charger = &desc->charger_regulators[i]; 1797 charger = &desc->charger_regulators[i];
1796 sysfs_remove_group(&cm->charger_psy.dev->kobj, 1798 sysfs_remove_group(&cm->charger_psy->dev.kobj,
1797 &charger->attr_g); 1799 &charger->attr_g);
1798 } 1800 }
1799err_reg_extcon: 1801err_reg_extcon:
@@ -1811,7 +1813,7 @@ err_reg_extcon:
1811 regulator_put(desc->charger_regulators[i].consumer); 1813 regulator_put(desc->charger_regulators[i].consumer);
1812 } 1814 }
1813 1815
1814 power_supply_unregister(&cm->charger_psy); 1816 power_supply_unregister(cm->charger_psy);
1815 1817
1816 return ret; 1818 return ret;
1817} 1819}
@@ -1843,7 +1845,7 @@ static int charger_manager_remove(struct platform_device *pdev)
1843 for (i = 0 ; i < desc->num_charger_regulators ; i++) 1845 for (i = 0 ; i < desc->num_charger_regulators ; i++)
1844 regulator_put(desc->charger_regulators[i].consumer); 1846 regulator_put(desc->charger_regulators[i].consumer);
1845 1847
1846 power_supply_unregister(&cm->charger_psy); 1848 power_supply_unregister(cm->charger_psy);
1847 1849
1848 try_charger_enable(cm, false); 1850 try_charger_enable(cm, false);
1849 1851
@@ -2002,7 +2004,7 @@ static bool find_power_supply(struct charger_manager *cm,
2002 bool found = false; 2004 bool found = false;
2003 2005
2004 for (i = 0; cm->desc->psy_charger_stat[i]; i++) { 2006 for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
2005 if (!strcmp(psy->name, cm->desc->psy_charger_stat[i])) { 2007 if (!strcmp(psy->desc->name, cm->desc->psy_charger_stat[i])) {
2006 found = true; 2008 found = true;
2007 break; 2009 break;
2008 } 2010 }
diff --git a/drivers/power/collie_battery.c b/drivers/power/collie_battery.c
index e7a808d1758a..2da9ed8ccbb5 100644
--- a/drivers/power/collie_battery.c
+++ b/drivers/power/collie_battery.c
@@ -30,7 +30,7 @@ static int wakeup_enabled;
30 30
31struct collie_bat { 31struct collie_bat {
32 int status; 32 int status;
33 struct power_supply psy; 33 struct power_supply *psy;
34 int full_chrg; 34 int full_chrg;
35 35
36 struct mutex work_lock; /* protects data */ 36 struct mutex work_lock; /* protects data */
@@ -98,7 +98,7 @@ static int collie_bat_get_property(struct power_supply *psy,
98 union power_supply_propval *val) 98 union power_supply_propval *val)
99{ 99{
100 int ret = 0; 100 int ret = 0;
101 struct collie_bat *bat = container_of(psy, struct collie_bat, psy); 101 struct collie_bat *bat = power_supply_get_drvdata(psy);
102 102
103 if (bat->is_present && !bat->is_present(bat) 103 if (bat->is_present && !bat->is_present(bat)
104 && psp != POWER_SUPPLY_PROP_PRESENT) { 104 && psp != POWER_SUPPLY_PROP_PRESENT) {
@@ -155,14 +155,14 @@ static irqreturn_t collie_bat_gpio_isr(int irq, void *data)
155static void collie_bat_update(struct collie_bat *bat) 155static void collie_bat_update(struct collie_bat *bat)
156{ 156{
157 int old; 157 int old;
158 struct power_supply *psy = &bat->psy; 158 struct power_supply *psy = bat->psy;
159 159
160 mutex_lock(&bat->work_lock); 160 mutex_lock(&bat->work_lock);
161 161
162 old = bat->status; 162 old = bat->status;
163 163
164 if (bat->is_present && !bat->is_present(bat)) { 164 if (bat->is_present && !bat->is_present(bat)) {
165 printk(KERN_NOTICE "%s not present\n", psy->name); 165 printk(KERN_NOTICE "%s not present\n", psy->desc->name);
166 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; 166 bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
167 bat->full_chrg = -1; 167 bat->full_chrg = -1;
168 } else if (power_supply_am_i_supplied(psy)) { 168 } else if (power_supply_am_i_supplied(psy)) {
@@ -220,18 +220,20 @@ static enum power_supply_property collie_bat_bu_props[] = {
220 POWER_SUPPLY_PROP_PRESENT, 220 POWER_SUPPLY_PROP_PRESENT,
221}; 221};
222 222
223static const struct power_supply_desc collie_bat_main_desc = {
224 .name = "main-battery",
225 .type = POWER_SUPPLY_TYPE_BATTERY,
226 .properties = collie_bat_main_props,
227 .num_properties = ARRAY_SIZE(collie_bat_main_props),
228 .get_property = collie_bat_get_property,
229 .external_power_changed = collie_bat_external_power_changed,
230 .use_for_apm = 1,
231};
232
223static struct collie_bat collie_bat_main = { 233static struct collie_bat collie_bat_main = {
224 .status = POWER_SUPPLY_STATUS_DISCHARGING, 234 .status = POWER_SUPPLY_STATUS_DISCHARGING,
225 .full_chrg = -1, 235 .full_chrg = -1,
226 .psy = { 236 .psy = NULL,
227 .name = "main-battery",
228 .type = POWER_SUPPLY_TYPE_BATTERY,
229 .properties = collie_bat_main_props,
230 .num_properties = ARRAY_SIZE(collie_bat_main_props),
231 .get_property = collie_bat_get_property,
232 .external_power_changed = collie_bat_external_power_changed,
233 .use_for_apm = 1,
234 },
235 237
236 .gpio_full = COLLIE_GPIO_CO, 238 .gpio_full = COLLIE_GPIO_CO,
237 .gpio_charge_on = COLLIE_GPIO_CHARGE_ON, 239 .gpio_charge_on = COLLIE_GPIO_CHARGE_ON,
@@ -249,18 +251,19 @@ static struct collie_bat collie_bat_main = {
249 .adc_temp_divider = 10000, 251 .adc_temp_divider = 10000,
250}; 252};
251 253
254static const struct power_supply_desc collie_bat_bu_desc = {
255 .name = "backup-battery",
256 .type = POWER_SUPPLY_TYPE_BATTERY,
257 .properties = collie_bat_bu_props,
258 .num_properties = ARRAY_SIZE(collie_bat_bu_props),
259 .get_property = collie_bat_get_property,
260 .external_power_changed = collie_bat_external_power_changed,
261};
262
252static struct collie_bat collie_bat_bu = { 263static struct collie_bat collie_bat_bu = {
253 .status = POWER_SUPPLY_STATUS_UNKNOWN, 264 .status = POWER_SUPPLY_STATUS_UNKNOWN,
254 .full_chrg = -1, 265 .full_chrg = -1,
255 266 .psy = NULL,
256 .psy = {
257 .name = "backup-battery",
258 .type = POWER_SUPPLY_TYPE_BATTERY,
259 .properties = collie_bat_bu_props,
260 .num_properties = ARRAY_SIZE(collie_bat_bu_props),
261 .get_property = collie_bat_get_property,
262 .external_power_changed = collie_bat_external_power_changed,
263 },
264 267
265 .gpio_full = -1, 268 .gpio_full = -1,
266 .gpio_charge_on = -1, 269 .gpio_charge_on = -1,
@@ -319,6 +322,7 @@ static int collie_bat_resume(struct ucb1x00_dev *dev)
319static int collie_bat_probe(struct ucb1x00_dev *dev) 322static int collie_bat_probe(struct ucb1x00_dev *dev)
320{ 323{
321 int ret; 324 int ret;
325 struct power_supply_config psy_main_cfg = {}, psy_bu_cfg = {};
322 326
323 if (!machine_is_collie()) 327 if (!machine_is_collie())
324 return -ENODEV; 328 return -ENODEV;
@@ -334,12 +338,23 @@ static int collie_bat_probe(struct ucb1x00_dev *dev)
334 338
335 INIT_WORK(&bat_work, collie_bat_work); 339 INIT_WORK(&bat_work, collie_bat_work);
336 340
337 ret = power_supply_register(&dev->ucb->dev, &collie_bat_main.psy, NULL); 341 psy_main_cfg.drv_data = &collie_bat_main;
338 if (ret) 342 collie_bat_main.psy = power_supply_register(&dev->ucb->dev,
343 &collie_bat_main_desc,
344 &psy_main_cfg);
345 if (IS_ERR(collie_bat_main.psy)) {
346 ret = PTR_ERR(collie_bat_main.psy);
339 goto err_psy_reg_main; 347 goto err_psy_reg_main;
340 ret = power_supply_register(&dev->ucb->dev, &collie_bat_bu.psy, NULL); 348 }
341 if (ret) 349
350 psy_main_cfg.drv_data = &collie_bat_bu;
351 collie_bat_bu.psy = power_supply_register(&dev->ucb->dev,
352 &collie_bat_bu_desc,
353 &psy_bu_cfg);
354 if (IS_ERR(collie_bat_bu.psy)) {
355 ret = PTR_ERR(collie_bat_bu.psy);
342 goto err_psy_reg_bu; 356 goto err_psy_reg_bu;
357 }
343 358
344 ret = request_irq(gpio_to_irq(COLLIE_GPIO_CO), 359 ret = request_irq(gpio_to_irq(COLLIE_GPIO_CO),
345 collie_bat_gpio_isr, 360 collie_bat_gpio_isr,
@@ -354,9 +369,9 @@ static int collie_bat_probe(struct ucb1x00_dev *dev)
354 return 0; 369 return 0;
355 370
356err_irq: 371err_irq:
357 power_supply_unregister(&collie_bat_bu.psy); 372 power_supply_unregister(collie_bat_bu.psy);
358err_psy_reg_bu: 373err_psy_reg_bu:
359 power_supply_unregister(&collie_bat_main.psy); 374 power_supply_unregister(collie_bat_main.psy);
360err_psy_reg_main: 375err_psy_reg_main:
361 376
362 /* see comment in collie_bat_remove */ 377 /* see comment in collie_bat_remove */
@@ -369,8 +384,8 @@ static void collie_bat_remove(struct ucb1x00_dev *dev)
369{ 384{
370 free_irq(gpio_to_irq(COLLIE_GPIO_CO), &collie_bat_main); 385 free_irq(gpio_to_irq(COLLIE_GPIO_CO), &collie_bat_main);
371 386
372 power_supply_unregister(&collie_bat_bu.psy); 387 power_supply_unregister(collie_bat_bu.psy);
373 power_supply_unregister(&collie_bat_main.psy); 388 power_supply_unregister(collie_bat_main.psy);
374 389
375 /* 390 /*
376 * Now cancel the bat_work. We won't get any more schedules, 391 * Now cancel the bat_work. We won't get any more schedules,
diff --git a/drivers/power/da9030_battery.c b/drivers/power/da9030_battery.c
index a87406ef18ee..5ca0f4d90792 100644
--- a/drivers/power/da9030_battery.c
+++ b/drivers/power/da9030_battery.c
@@ -89,7 +89,8 @@ struct da9030_battery_thresholds {
89}; 89};
90 90
91struct da9030_charger { 91struct da9030_charger {
92 struct power_supply psy; 92 struct power_supply *psy;
93 struct power_supply_desc psy_desc;
93 94
94 struct device *master; 95 struct device *master;
95 96
@@ -245,7 +246,7 @@ static void da9030_set_charge(struct da9030_charger *charger, int on)
245 246
246 da903x_write(charger->master, DA9030_CHARGE_CONTROL, val); 247 da903x_write(charger->master, DA9030_CHARGE_CONTROL, val);
247 248
248 power_supply_changed(&charger->psy); 249 power_supply_changed(charger->psy);
249} 250}
250 251
251static void da9030_charger_check_state(struct da9030_charger *charger) 252static void da9030_charger_check_state(struct da9030_charger *charger)
@@ -341,8 +342,7 @@ static int da9030_battery_get_property(struct power_supply *psy,
341 enum power_supply_property psp, 342 enum power_supply_property psp,
342 union power_supply_propval *val) 343 union power_supply_propval *val)
343{ 344{
344 struct da9030_charger *charger; 345 struct da9030_charger *charger = power_supply_get_drvdata(psy);
345 charger = container_of(psy, struct da9030_charger, psy);
346 346
347 switch (psp) { 347 switch (psp) {
348 case POWER_SUPPLY_PROP_STATUS: 348 case POWER_SUPPLY_PROP_STATUS:
@@ -447,16 +447,16 @@ static void da9030_battery_convert_thresholds(struct da9030_charger *charger,
447 447
448static void da9030_battery_setup_psy(struct da9030_charger *charger) 448static void da9030_battery_setup_psy(struct da9030_charger *charger)
449{ 449{
450 struct power_supply *psy = &charger->psy; 450 struct power_supply_desc *psy_desc = &charger->psy_desc;
451 struct power_supply_info *info = charger->battery_info; 451 struct power_supply_info *info = charger->battery_info;
452 452
453 psy->name = info->name; 453 psy_desc->name = info->name;
454 psy->use_for_apm = info->use_for_apm; 454 psy_desc->use_for_apm = info->use_for_apm;
455 psy->type = POWER_SUPPLY_TYPE_BATTERY; 455 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
456 psy->get_property = da9030_battery_get_property; 456 psy_desc->get_property = da9030_battery_get_property;
457 457
458 psy->properties = da9030_battery_props; 458 psy_desc->properties = da9030_battery_props;
459 psy->num_properties = ARRAY_SIZE(da9030_battery_props); 459 psy_desc->num_properties = ARRAY_SIZE(da9030_battery_props);
460}; 460};
461 461
462static int da9030_battery_charger_init(struct da9030_charger *charger) 462static int da9030_battery_charger_init(struct da9030_charger *charger)
@@ -494,6 +494,7 @@ static int da9030_battery_charger_init(struct da9030_charger *charger)
494static int da9030_battery_probe(struct platform_device *pdev) 494static int da9030_battery_probe(struct platform_device *pdev)
495{ 495{
496 struct da9030_charger *charger; 496 struct da9030_charger *charger;
497 struct power_supply_config psy_cfg = {};
497 struct da9030_battery_info *pdata = pdev->dev.platform_data; 498 struct da9030_battery_info *pdata = pdev->dev.platform_data;
498 int ret; 499 int ret;
499 500
@@ -541,9 +542,13 @@ static int da9030_battery_probe(struct platform_device *pdev)
541 goto err_notifier; 542 goto err_notifier;
542 543
543 da9030_battery_setup_psy(charger); 544 da9030_battery_setup_psy(charger);
544 ret = power_supply_register(&pdev->dev, &charger->psy, NULL); 545 psy_cfg.drv_data = charger;
545 if (ret) 546 charger->psy = power_supply_register(&pdev->dev, &charger->psy_desc,
547 &psy_cfg);
548 if (IS_ERR(charger->psy)) {
549 ret = PTR_ERR(charger->psy);
546 goto err_ps_register; 550 goto err_ps_register;
551 }
547 552
548 charger->debug_file = da9030_bat_create_debugfs(charger); 553 charger->debug_file = da9030_bat_create_debugfs(charger);
549 platform_set_drvdata(pdev, charger); 554 platform_set_drvdata(pdev, charger);
@@ -571,7 +576,7 @@ static int da9030_battery_remove(struct platform_device *dev)
571 DA9030_EVENT_CHIOVER | DA9030_EVENT_TBAT); 576 DA9030_EVENT_CHIOVER | DA9030_EVENT_TBAT);
572 cancel_delayed_work_sync(&charger->work); 577 cancel_delayed_work_sync(&charger->work);
573 da9030_set_charge(charger, 0); 578 da9030_set_charge(charger, 0);
574 power_supply_unregister(&charger->psy); 579 power_supply_unregister(charger->psy);
575 580
576 return 0; 581 return 0;
577} 582}
diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
index 54ba9ddb6d4f..830ec46fe7d0 100644
--- a/drivers/power/da9052-battery.c
+++ b/drivers/power/da9052-battery.c
@@ -169,7 +169,7 @@ static u32 const vc_tbl[3][68][2] = {
169 169
170struct da9052_battery { 170struct da9052_battery {
171 struct da9052 *da9052; 171 struct da9052 *da9052;
172 struct power_supply psy; 172 struct power_supply *psy;
173 struct notifier_block nb; 173 struct notifier_block nb;
174 int charger_type; 174 int charger_type;
175 int status; 175 int status;
@@ -452,7 +452,7 @@ static irqreturn_t da9052_bat_irq(int irq, void *data)
452 452
453 if (irq == DA9052_IRQ_CHGEND || irq == DA9052_IRQ_DCIN || 453 if (irq == DA9052_IRQ_CHGEND || irq == DA9052_IRQ_DCIN ||
454 irq == DA9052_IRQ_VBUS || irq == DA9052_IRQ_TBAT) { 454 irq == DA9052_IRQ_VBUS || irq == DA9052_IRQ_TBAT) {
455 power_supply_changed(&bat->psy); 455 power_supply_changed(bat->psy);
456 } 456 }
457 457
458 return IRQ_HANDLED; 458 return IRQ_HANDLED;
@@ -499,8 +499,7 @@ static int da9052_bat_get_property(struct power_supply *psy,
499{ 499{
500 int ret; 500 int ret;
501 int illegal; 501 int illegal;
502 struct da9052_battery *bat = container_of(psy, struct da9052_battery, 502 struct da9052_battery *bat = power_supply_get_drvdata(psy);
503 psy);
504 503
505 ret = da9052_bat_check_presence(bat, &illegal); 504 ret = da9052_bat_check_presence(bat, &illegal);
506 if (ret < 0) 505 if (ret < 0)
@@ -561,7 +560,7 @@ static enum power_supply_property da9052_bat_props[] = {
561 POWER_SUPPLY_PROP_TECHNOLOGY, 560 POWER_SUPPLY_PROP_TECHNOLOGY,
562}; 561};
563 562
564static struct power_supply template_battery = { 563static struct power_supply_desc psy_desc = {
565 .name = "da9052-bat", 564 .name = "da9052-bat",
566 .type = POWER_SUPPLY_TYPE_BATTERY, 565 .type = POWER_SUPPLY_TYPE_BATTERY,
567 .properties = da9052_bat_props, 566 .properties = da9052_bat_props,
@@ -591,6 +590,7 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
591{ 590{
592 struct da9052_pdata *pdata; 591 struct da9052_pdata *pdata;
593 struct da9052_battery *bat; 592 struct da9052_battery *bat;
593 struct power_supply_config psy_cfg = {};
594 int ret; 594 int ret;
595 int i; 595 int i;
596 596
@@ -599,8 +599,9 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
599 if (!bat) 599 if (!bat)
600 return -ENOMEM; 600 return -ENOMEM;
601 601
602 psy_cfg.drv_data = bat;
603
602 bat->da9052 = dev_get_drvdata(pdev->dev.parent); 604 bat->da9052 = dev_get_drvdata(pdev->dev.parent);
603 bat->psy = template_battery;
604 bat->charger_type = DA9052_NOCHARGER; 605 bat->charger_type = DA9052_NOCHARGER;
605 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; 606 bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
606 bat->health = POWER_SUPPLY_HEALTH_UNKNOWN; 607 bat->health = POWER_SUPPLY_HEALTH_UNKNOWN;
@@ -608,9 +609,9 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
608 609
609 pdata = bat->da9052->dev->platform_data; 610 pdata = bat->da9052->dev->platform_data;
610 if (pdata != NULL && pdata->use_for_apm) 611 if (pdata != NULL && pdata->use_for_apm)
611 bat->psy.use_for_apm = pdata->use_for_apm; 612 psy_desc.use_for_apm = pdata->use_for_apm;
612 else 613 else
613 bat->psy.use_for_apm = 1; 614 psy_desc.use_for_apm = 1;
614 615
615 for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++) { 616 for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++) {
616 ret = da9052_request_irq(bat->da9052, 617 ret = da9052_request_irq(bat->da9052,
@@ -625,9 +626,11 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
625 } 626 }
626 } 627 }
627 628
628 ret = power_supply_register(&pdev->dev, &bat->psy, NULL); 629 bat->psy = power_supply_register(&pdev->dev, &psy_desc, &psy_cfg);
629 if (ret) 630 if (IS_ERR(bat->psy)) {
631 ret = PTR_ERR(bat->psy);
630 goto err; 632 goto err;
633 }
631 634
632 platform_set_drvdata(pdev, bat); 635 platform_set_drvdata(pdev, bat);
633 return 0; 636 return 0;
@@ -646,7 +649,7 @@ static int da9052_bat_remove(struct platform_device *pdev)
646 for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++) 649 for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++)
647 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat); 650 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat);
648 651
649 power_supply_unregister(&bat->psy); 652 power_supply_unregister(bat->psy);
650 653
651 return 0; 654 return 0;
652} 655}
diff --git a/drivers/power/da9150-charger.c b/drivers/power/da9150-charger.c
index db8ba5d8d1e3..60099815296e 100644
--- a/drivers/power/da9150-charger.c
+++ b/drivers/power/da9150-charger.c
@@ -30,8 +30,8 @@ struct da9150_charger {
30 struct da9150 *da9150; 30 struct da9150 *da9150;
31 struct device *dev; 31 struct device *dev;
32 32
33 struct power_supply usb; 33 struct power_supply *usb;
34 struct power_supply battery; 34 struct power_supply *battery;
35 struct power_supply *supply_online; 35 struct power_supply *supply_online;
36 36
37 struct usb_phy *usb_phy; 37 struct usb_phy *usb_phy;
@@ -114,7 +114,7 @@ static int da9150_charger_get_prop(struct power_supply *psy,
114 enum power_supply_property psp, 114 enum power_supply_property psp,
115 union power_supply_propval *val) 115 union power_supply_propval *val)
116{ 116{
117 struct da9150_charger *charger = dev_get_drvdata(psy->dev->parent); 117 struct da9150_charger *charger = dev_get_drvdata(psy->dev.parent);
118 int ret; 118 int ret;
119 119
120 switch (psp) { 120 switch (psp) {
@@ -326,7 +326,7 @@ static int da9150_charger_battery_get_prop(struct power_supply *psy,
326 enum power_supply_property psp, 326 enum power_supply_property psp,
327 union power_supply_propval *val) 327 union power_supply_propval *val)
328{ 328{
329 struct da9150_charger *charger = dev_get_drvdata(psy->dev->parent); 329 struct da9150_charger *charger = dev_get_drvdata(psy->dev.parent);
330 int ret; 330 int ret;
331 331
332 switch (psp) { 332 switch (psp) {
@@ -369,7 +369,7 @@ static irqreturn_t da9150_charger_chg_irq(int irq, void *data)
369{ 369{
370 struct da9150_charger *charger = data; 370 struct da9150_charger *charger = data;
371 371
372 power_supply_changed(&charger->battery); 372 power_supply_changed(charger->battery);
373 373
374 return IRQ_HANDLED; 374 return IRQ_HANDLED;
375} 375}
@@ -380,7 +380,7 @@ static irqreturn_t da9150_charger_tjunc_irq(int irq, void *data)
380 380
381 /* Nothing we can really do except report this. */ 381 /* Nothing we can really do except report this. */
382 dev_crit(charger->dev, "TJunc over temperature!!!\n"); 382 dev_crit(charger->dev, "TJunc over temperature!!!\n");
383 power_supply_changed(&charger->usb); 383 power_supply_changed(charger->usb);
384 384
385 return IRQ_HANDLED; 385 return IRQ_HANDLED;
386} 386}
@@ -391,8 +391,8 @@ static irqreturn_t da9150_charger_vfault_irq(int irq, void *data)
391 391
392 /* Nothing we can really do except report this. */ 392 /* Nothing we can really do except report this. */
393 dev_crit(charger->dev, "VSYS under voltage!!!\n"); 393 dev_crit(charger->dev, "VSYS under voltage!!!\n");
394 power_supply_changed(&charger->usb); 394 power_supply_changed(charger->usb);
395 power_supply_changed(&charger->battery); 395 power_supply_changed(charger->battery);
396 396
397 return IRQ_HANDLED; 397 return IRQ_HANDLED;
398} 398}
@@ -408,10 +408,10 @@ static irqreturn_t da9150_charger_vbus_irq(int irq, void *data)
408 switch (reg & DA9150_VBUS_STAT_MASK) { 408 switch (reg & DA9150_VBUS_STAT_MASK) {
409 case DA9150_VBUS_STAT_OFF: 409 case DA9150_VBUS_STAT_OFF:
410 case DA9150_VBUS_STAT_WAIT: 410 case DA9150_VBUS_STAT_WAIT:
411 charger->supply_online = &charger->battery; 411 charger->supply_online = charger->battery;
412 break; 412 break;
413 case DA9150_VBUS_STAT_CHG: 413 case DA9150_VBUS_STAT_CHG:
414 charger->supply_online = &charger->usb; 414 charger->supply_online = charger->usb;
415 break; 415 break;
416 default: 416 default:
417 dev_warn(charger->dev, "Unknown VBUS state - reg = 0x%x\n", 417 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)
420 break; 420 break;
421 } 421 }
422 422
423 power_supply_changed(&charger->usb); 423 power_supply_changed(charger->usb);
424 power_supply_changed(&charger->battery); 424 power_supply_changed(charger->battery);
425 425
426 return IRQ_HANDLED; 426 return IRQ_HANDLED;
427} 427}
@@ -439,8 +439,8 @@ static void da9150_charger_otg_work(struct work_struct *data)
439 break; 439 break;
440 case USB_EVENT_NONE: 440 case USB_EVENT_NONE:
441 /* Revert to charge mode */ 441 /* Revert to charge mode */
442 power_supply_changed(&charger->usb); 442 power_supply_changed(charger->usb);
443 power_supply_changed(&charger->battery); 443 power_supply_changed(charger->battery);
444 da9150_set_bits(charger->da9150, DA9150_PPR_BKCTRL_A, 444 da9150_set_bits(charger->da9150, DA9150_PPR_BKCTRL_A,
445 DA9150_VBUS_MODE_MASK, DA9150_VBUS_MODE_CHG); 445 DA9150_VBUS_MODE_MASK, DA9150_VBUS_MODE_CHG);
446 break; 446 break;
@@ -499,12 +499,27 @@ static void da9150_charger_unregister_irq(struct platform_device *pdev,
499 free_irq(irq, charger); 499 free_irq(irq, charger);
500} 500}
501 501
502static const struct power_supply_desc usb_desc = {
503 .name = "da9150-usb",
504 .type = POWER_SUPPLY_TYPE_USB,
505 .properties = da9150_charger_props,
506 .num_properties = ARRAY_SIZE(da9150_charger_props),
507 .get_property = da9150_charger_get_prop,
508};
509
510static const struct power_supply_desc battery_desc = {
511 .name = "da9150-battery",
512 .type = POWER_SUPPLY_TYPE_BATTERY,
513 .properties = da9150_charger_bat_props,
514 .num_properties = ARRAY_SIZE(da9150_charger_bat_props),
515 .get_property = da9150_charger_battery_get_prop,
516};
517
502static int da9150_charger_probe(struct platform_device *pdev) 518static int da9150_charger_probe(struct platform_device *pdev)
503{ 519{
504 struct device *dev = &pdev->dev; 520 struct device *dev = &pdev->dev;
505 struct da9150 *da9150 = dev_get_drvdata(dev->parent); 521 struct da9150 *da9150 = dev_get_drvdata(dev->parent);
506 struct da9150_charger *charger; 522 struct da9150_charger *charger;
507 struct power_supply *usb, *battery;
508 u8 reg; 523 u8 reg;
509 int ret; 524 int ret;
510 525
@@ -542,26 +557,17 @@ static int da9150_charger_probe(struct platform_device *pdev)
542 } 557 }
543 558
544 /* Register power supplies */ 559 /* Register power supplies */
545 usb = &charger->usb; 560 charger->usb = power_supply_register(dev, &usb_desc, NULL);
546 battery = &charger->battery; 561 if (IS_ERR(charger->usb)) {
547 562 ret = PTR_ERR(charger->usb);
548 usb->name = "da9150-usb",
549 usb->type = POWER_SUPPLY_TYPE_USB;
550 usb->properties = da9150_charger_props;
551 usb->num_properties = ARRAY_SIZE(da9150_charger_props);
552 usb->get_property = da9150_charger_get_prop;
553 ret = power_supply_register(dev, usb, NULL);
554 if (ret)
555 goto usb_fail; 563 goto usb_fail;
564 }
556 565
557 battery->name = "da9150-battery"; 566 charger->battery = power_supply_register(dev, &battery_desc, NULL);
558 battery->type = POWER_SUPPLY_TYPE_BATTERY; 567 if (IS_ERR(charger->battery)) {
559 battery->properties = da9150_charger_bat_props; 568 ret = PTR_ERR(charger->battery);
560 battery->num_properties = ARRAY_SIZE(da9150_charger_bat_props);
561 battery->get_property = da9150_charger_battery_get_prop;
562 ret = power_supply_register(dev, battery, NULL);
563 if (ret)
564 goto battery_fail; 569 goto battery_fail;
570 }
565 571
566 /* Get initial online supply */ 572 /* Get initial online supply */
567 reg = da9150_reg_read(da9150, DA9150_STATUS_H); 573 reg = da9150_reg_read(da9150, DA9150_STATUS_H);
@@ -569,10 +575,10 @@ static int da9150_charger_probe(struct platform_device *pdev)
569 switch (reg & DA9150_VBUS_STAT_MASK) { 575 switch (reg & DA9150_VBUS_STAT_MASK) {
570 case DA9150_VBUS_STAT_OFF: 576 case DA9150_VBUS_STAT_OFF:
571 case DA9150_VBUS_STAT_WAIT: 577 case DA9150_VBUS_STAT_WAIT:
572 charger->supply_online = &charger->battery; 578 charger->supply_online = charger->battery;
573 break; 579 break;
574 case DA9150_VBUS_STAT_CHG: 580 case DA9150_VBUS_STAT_CHG:
575 charger->supply_online = &charger->usb; 581 charger->supply_online = charger->usb;
576 break; 582 break;
577 default: 583 default:
578 dev_warn(dev, "Unknown VBUS state - reg = 0x%x\n", reg); 584 dev_warn(dev, "Unknown VBUS state - reg = 0x%x\n", reg);
@@ -622,7 +628,7 @@ chg_irq_fail:
622 if (!IS_ERR_OR_NULL(charger->usb_phy)) 628 if (!IS_ERR_OR_NULL(charger->usb_phy))
623 usb_unregister_notifier(charger->usb_phy, &charger->otg_nb); 629 usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
624battery_fail: 630battery_fail:
625 power_supply_unregister(usb); 631 power_supply_unregister(charger->usb);
626 632
627usb_fail: 633usb_fail:
628 iio_channel_release(charger->vbat_chan); 634 iio_channel_release(charger->vbat_chan);
@@ -661,8 +667,8 @@ static int da9150_charger_remove(struct platform_device *pdev)
661 if (!IS_ERR_OR_NULL(charger->usb_phy)) 667 if (!IS_ERR_OR_NULL(charger->usb_phy))
662 usb_unregister_notifier(charger->usb_phy, &charger->otg_nb); 668 usb_unregister_notifier(charger->usb_phy, &charger->otg_nb);
663 669
664 power_supply_unregister(&charger->battery); 670 power_supply_unregister(charger->battery);
665 power_supply_unregister(&charger->usb); 671 power_supply_unregister(charger->usb);
666 672
667 /* Release ADC channels */ 673 /* Release ADC channels */
668 iio_channel_release(charger->ibus_chan); 674 iio_channel_release(charger->ibus_chan);
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c
index e82dff0bbb20..80f73ccb77ab 100644
--- a/drivers/power/ds2760_battery.c
+++ b/drivers/power/ds2760_battery.c
@@ -53,7 +53,8 @@ struct ds2760_device_info {
53 int charge_status; /* POWER_SUPPLY_STATUS_* */ 53 int charge_status; /* POWER_SUPPLY_STATUS_* */
54 54
55 int full_counter; 55 int full_counter;
56 struct power_supply bat; 56 struct power_supply *bat;
57 struct power_supply_desc bat_desc;
57 struct device *w1_dev; 58 struct device *w1_dev;
58 struct workqueue_struct *monitor_wqueue; 59 struct workqueue_struct *monitor_wqueue;
59 struct delayed_work monitor_work; 60 struct delayed_work monitor_work;
@@ -254,7 +255,7 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
254 if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN) 255 if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN)
255 di->full_counter = 0; 256 di->full_counter = 0;
256 257
257 if (power_supply_am_i_supplied(&di->bat)) { 258 if (power_supply_am_i_supplied(di->bat)) {
258 if (di->current_uA > 10000) { 259 if (di->current_uA > 10000) {
259 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 260 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
260 di->full_counter = 0; 261 di->full_counter = 0;
@@ -287,7 +288,7 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
287 } 288 }
288 289
289 if (di->charge_status != old_charge_status) 290 if (di->charge_status != old_charge_status)
290 power_supply_changed(&di->bat); 291 power_supply_changed(di->bat);
291} 292}
292 293
293static void ds2760_battery_write_status(struct ds2760_device_info *di, 294static void ds2760_battery_write_status(struct ds2760_device_info *di,
@@ -346,12 +347,9 @@ static void ds2760_battery_work(struct work_struct *work)
346 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval); 347 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval);
347} 348}
348 349
349#define to_ds2760_device_info(x) container_of((x), struct ds2760_device_info, \
350 bat);
351
352static void ds2760_battery_external_power_changed(struct power_supply *psy) 350static void ds2760_battery_external_power_changed(struct power_supply *psy)
353{ 351{
354 struct ds2760_device_info *di = to_ds2760_device_info(psy); 352 struct ds2760_device_info *di = power_supply_get_drvdata(psy);
355 353
356 dev_dbg(di->dev, "%s\n", __func__); 354 dev_dbg(di->dev, "%s\n", __func__);
357 355
@@ -377,7 +375,7 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
377 * that error. 375 * that error.
378 */ 376 */
379 377
380 if (!power_supply_am_i_supplied(&di->bat)) 378 if (!power_supply_am_i_supplied(di->bat))
381 return; 379 return;
382 380
383 bias = (signed char) di->current_raw + 381 bias = (signed char) di->current_raw +
@@ -396,7 +394,7 @@ static void ds2760_battery_set_charged_work(struct work_struct *work)
396 394
397static void ds2760_battery_set_charged(struct power_supply *psy) 395static void ds2760_battery_set_charged(struct power_supply *psy)
398{ 396{
399 struct ds2760_device_info *di = to_ds2760_device_info(psy); 397 struct ds2760_device_info *di = power_supply_get_drvdata(psy);
400 398
401 /* postpone the actual work by 20 secs. This is for debouncing GPIO 399 /* postpone the actual work by 20 secs. This is for debouncing GPIO
402 * signals and to let the current value settle. See AN4188. */ 400 * signals and to let the current value settle. See AN4188. */
@@ -407,7 +405,7 @@ static int ds2760_battery_get_property(struct power_supply *psy,
407 enum power_supply_property psp, 405 enum power_supply_property psp,
408 union power_supply_propval *val) 406 union power_supply_propval *val)
409{ 407{
410 struct ds2760_device_info *di = to_ds2760_device_info(psy); 408 struct ds2760_device_info *di = power_supply_get_drvdata(psy);
411 409
412 switch (psp) { 410 switch (psp) {
413 case POWER_SUPPLY_PROP_STATUS: 411 case POWER_SUPPLY_PROP_STATUS:
@@ -458,7 +456,7 @@ static int ds2760_battery_set_property(struct power_supply *psy,
458 enum power_supply_property psp, 456 enum power_supply_property psp,
459 const union power_supply_propval *val) 457 const union power_supply_propval *val)
460{ 458{
461 struct ds2760_device_info *di = to_ds2760_device_info(psy); 459 struct ds2760_device_info *di = power_supply_get_drvdata(psy);
462 460
463 switch (psp) { 461 switch (psp) {
464 case POWER_SUPPLY_PROP_CHARGE_FULL: 462 case POWER_SUPPLY_PROP_CHARGE_FULL:
@@ -508,6 +506,7 @@ static enum power_supply_property ds2760_battery_props[] = {
508 506
509static int ds2760_battery_probe(struct platform_device *pdev) 507static int ds2760_battery_probe(struct platform_device *pdev)
510{ 508{
509 struct power_supply_config psy_cfg = {};
511 char status; 510 char status;
512 int retval = 0; 511 int retval = 0;
513 struct ds2760_device_info *di; 512 struct ds2760_device_info *di;
@@ -520,20 +519,22 @@ static int ds2760_battery_probe(struct platform_device *pdev)
520 519
521 platform_set_drvdata(pdev, di); 520 platform_set_drvdata(pdev, di);
522 521
523 di->dev = &pdev->dev; 522 di->dev = &pdev->dev;
524 di->w1_dev = pdev->dev.parent; 523 di->w1_dev = pdev->dev.parent;
525 di->bat.name = dev_name(&pdev->dev); 524 di->bat_desc.name = dev_name(&pdev->dev);
526 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 525 di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
527 di->bat.properties = ds2760_battery_props; 526 di->bat_desc.properties = ds2760_battery_props;
528 di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); 527 di->bat_desc.num_properties = ARRAY_SIZE(ds2760_battery_props);
529 di->bat.get_property = ds2760_battery_get_property; 528 di->bat_desc.get_property = ds2760_battery_get_property;
530 di->bat.set_property = ds2760_battery_set_property; 529 di->bat_desc.set_property = ds2760_battery_set_property;
531 di->bat.property_is_writeable = 530 di->bat_desc.property_is_writeable =
532 ds2760_battery_property_is_writeable; 531 ds2760_battery_property_is_writeable;
533 di->bat.set_charged = ds2760_battery_set_charged; 532 di->bat_desc.set_charged = ds2760_battery_set_charged;
534 di->bat.external_power_changed = 533 di->bat_desc.external_power_changed =
535 ds2760_battery_external_power_changed; 534 ds2760_battery_external_power_changed;
536 535
536 psy_cfg.drv_data = di;
537
537 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; 538 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
538 539
539 /* enable sleep mode feature */ 540 /* enable sleep mode feature */
@@ -555,9 +556,10 @@ static int ds2760_battery_probe(struct platform_device *pdev)
555 if (current_accum) 556 if (current_accum)
556 ds2760_battery_set_current_accum(di, current_accum); 557 ds2760_battery_set_current_accum(di, current_accum);
557 558
558 retval = power_supply_register(&pdev->dev, &di->bat, NULL); 559 di->bat = power_supply_register(&pdev->dev, &di->bat_desc, &psy_cfg);
559 if (retval) { 560 if (IS_ERR(di->bat)) {
560 dev_err(di->dev, "failed to register battery\n"); 561 dev_err(di->dev, "failed to register battery\n");
562 retval = PTR_ERR(di->bat);
561 goto batt_failed; 563 goto batt_failed;
562 } 564 }
563 565
@@ -574,7 +576,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
574 goto success; 576 goto success;
575 577
576workqueue_failed: 578workqueue_failed:
577 power_supply_unregister(&di->bat); 579 power_supply_unregister(di->bat);
578batt_failed: 580batt_failed:
579di_alloc_failed: 581di_alloc_failed:
580success: 582success:
@@ -588,7 +590,7 @@ static int ds2760_battery_remove(struct platform_device *pdev)
588 cancel_delayed_work_sync(&di->monitor_work); 590 cancel_delayed_work_sync(&di->monitor_work);
589 cancel_delayed_work_sync(&di->set_charged_work); 591 cancel_delayed_work_sync(&di->set_charged_work);
590 destroy_workqueue(di->monitor_wqueue); 592 destroy_workqueue(di->monitor_wqueue);
591 power_supply_unregister(&di->bat); 593 power_supply_unregister(di->bat);
592 594
593 return 0; 595 return 0;
594} 596}
@@ -610,7 +612,7 @@ static int ds2760_battery_resume(struct platform_device *pdev)
610 struct ds2760_device_info *di = platform_get_drvdata(pdev); 612 struct ds2760_device_info *di = platform_get_drvdata(pdev);
611 613
612 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; 614 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
613 power_supply_changed(&di->bat); 615 power_supply_changed(di->bat);
614 616
615 mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ); 617 mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ);
616 618
diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index b1d3570ea730..a7a0427343f3 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -37,7 +37,8 @@
37 37
38struct ds2780_device_info { 38struct ds2780_device_info {
39 struct device *dev; 39 struct device *dev;
40 struct power_supply bat; 40 struct power_supply *bat;
41 struct power_supply_desc bat_desc;
41 struct device *w1_dev; 42 struct device *w1_dev;
42}; 43};
43 44
@@ -52,7 +53,7 @@ static const char manufacturer[] = "Maxim/Dallas";
52static inline struct ds2780_device_info * 53static inline struct ds2780_device_info *
53to_ds2780_device_info(struct power_supply *psy) 54to_ds2780_device_info(struct power_supply *psy)
54{ 55{
55 return container_of(psy, struct ds2780_device_info, bat); 56 return power_supply_get_drvdata(psy);
56} 57}
57 58
58static inline struct power_supply *to_power_supply(struct device *dev) 59static inline struct power_supply *to_power_supply(struct device *dev)
@@ -757,6 +758,7 @@ static const struct attribute_group ds2780_attr_group = {
757 758
758static int ds2780_battery_probe(struct platform_device *pdev) 759static int ds2780_battery_probe(struct platform_device *pdev)
759{ 760{
761 struct power_supply_config psy_cfg = {};
760 int ret = 0; 762 int ret = 0;
761 struct ds2780_device_info *dev_info; 763 struct ds2780_device_info *dev_info;
762 764
@@ -770,25 +772,29 @@ static int ds2780_battery_probe(struct platform_device *pdev)
770 772
771 dev_info->dev = &pdev->dev; 773 dev_info->dev = &pdev->dev;
772 dev_info->w1_dev = pdev->dev.parent; 774 dev_info->w1_dev = pdev->dev.parent;
773 dev_info->bat.name = dev_name(&pdev->dev); 775 dev_info->bat_desc.name = dev_name(&pdev->dev);
774 dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY; 776 dev_info->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
775 dev_info->bat.properties = ds2780_battery_props; 777 dev_info->bat_desc.properties = ds2780_battery_props;
776 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props); 778 dev_info->bat_desc.num_properties = ARRAY_SIZE(ds2780_battery_props);
777 dev_info->bat.get_property = ds2780_battery_get_property; 779 dev_info->bat_desc.get_property = ds2780_battery_get_property;
778 780
779 ret = power_supply_register(&pdev->dev, &dev_info->bat, NULL); 781 psy_cfg.drv_data = dev_info;
780 if (ret) { 782
783 dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
784 &psy_cfg);
785 if (IS_ERR(dev_info->bat)) {
781 dev_err(dev_info->dev, "failed to register battery\n"); 786 dev_err(dev_info->dev, "failed to register battery\n");
787 ret = PTR_ERR(dev_info->bat);
782 goto fail; 788 goto fail;
783 } 789 }
784 790
785 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 791 ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
786 if (ret) { 792 if (ret) {
787 dev_err(dev_info->dev, "failed to create sysfs group\n"); 793 dev_err(dev_info->dev, "failed to create sysfs group\n");
788 goto fail_unregister; 794 goto fail_unregister;
789 } 795 }
790 796
791 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj, 797 ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
792 &ds2780_param_eeprom_bin_attr); 798 &ds2780_param_eeprom_bin_attr);
793 if (ret) { 799 if (ret) {
794 dev_err(dev_info->dev, 800 dev_err(dev_info->dev,
@@ -796,7 +802,7 @@ static int ds2780_battery_probe(struct platform_device *pdev)
796 goto fail_remove_group; 802 goto fail_remove_group;
797 } 803 }
798 804
799 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj, 805 ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
800 &ds2780_user_eeprom_bin_attr); 806 &ds2780_user_eeprom_bin_attr);
801 if (ret) { 807 if (ret) {
802 dev_err(dev_info->dev, 808 dev_err(dev_info->dev,
@@ -807,12 +813,12 @@ static int ds2780_battery_probe(struct platform_device *pdev)
807 return 0; 813 return 0;
808 814
809fail_remove_bin_file: 815fail_remove_bin_file:
810 sysfs_remove_bin_file(&dev_info->bat.dev->kobj, 816 sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
811 &ds2780_param_eeprom_bin_attr); 817 &ds2780_param_eeprom_bin_attr);
812fail_remove_group: 818fail_remove_group:
813 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 819 sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
814fail_unregister: 820fail_unregister:
815 power_supply_unregister(&dev_info->bat); 821 power_supply_unregister(dev_info->bat);
816fail: 822fail:
817 return ret; 823 return ret;
818} 824}
@@ -821,10 +827,13 @@ static int ds2780_battery_remove(struct platform_device *pdev)
821{ 827{
822 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev); 828 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
823 829
824 /* remove attributes */ 830 /*
825 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 831 * Remove attributes before unregistering power supply
832 * because 'bat' will be freed on power_supply_unregister() call.
833 */
834 sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2780_attr_group);
826 835
827 power_supply_unregister(&dev_info->bat); 836 power_supply_unregister(dev_info->bat);
828 837
829 return 0; 838 return 0;
830} 839}
diff --git a/drivers/power/ds2781_battery.c b/drivers/power/ds2781_battery.c
index 50686dc59711..56d583dae908 100644
--- a/drivers/power/ds2781_battery.c
+++ b/drivers/power/ds2781_battery.c
@@ -35,7 +35,8 @@
35 35
36struct ds2781_device_info { 36struct ds2781_device_info {
37 struct device *dev; 37 struct device *dev;
38 struct power_supply bat; 38 struct power_supply *bat;
39 struct power_supply_desc bat_desc;
39 struct device *w1_dev; 40 struct device *w1_dev;
40}; 41};
41 42
@@ -50,7 +51,7 @@ static const char manufacturer[] = "Maxim/Dallas";
50static inline struct ds2781_device_info * 51static inline struct ds2781_device_info *
51to_ds2781_device_info(struct power_supply *psy) 52to_ds2781_device_info(struct power_supply *psy)
52{ 53{
53 return container_of(psy, struct ds2781_device_info, bat); 54 return power_supply_get_drvdata(psy);
54} 55}
55 56
56static inline struct power_supply *to_power_supply(struct device *dev) 57static 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)
328 if (ret < 0) 329 if (ret < 0)
329 return ret; 330 return ret;
330 331
331 if (power_supply_am_i_supplied(&dev_info->bat)) { 332 if (power_supply_am_i_supplied(dev_info->bat)) {
332 if (capacity == 100) 333 if (capacity == 100)
333 *status = POWER_SUPPLY_STATUS_FULL; 334 *status = POWER_SUPPLY_STATUS_FULL;
334 else if (current_uA > 50000) 335 else if (current_uA > 50000)
@@ -752,6 +753,7 @@ static const struct attribute_group ds2781_attr_group = {
752 753
753static int ds2781_battery_probe(struct platform_device *pdev) 754static int ds2781_battery_probe(struct platform_device *pdev)
754{ 755{
756 struct power_supply_config psy_cfg = {};
755 int ret = 0; 757 int ret = 0;
756 struct ds2781_device_info *dev_info; 758 struct ds2781_device_info *dev_info;
757 759
@@ -763,25 +765,29 @@ static int ds2781_battery_probe(struct platform_device *pdev)
763 765
764 dev_info->dev = &pdev->dev; 766 dev_info->dev = &pdev->dev;
765 dev_info->w1_dev = pdev->dev.parent; 767 dev_info->w1_dev = pdev->dev.parent;
766 dev_info->bat.name = dev_name(&pdev->dev); 768 dev_info->bat_desc.name = dev_name(&pdev->dev);
767 dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY; 769 dev_info->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
768 dev_info->bat.properties = ds2781_battery_props; 770 dev_info->bat_desc.properties = ds2781_battery_props;
769 dev_info->bat.num_properties = ARRAY_SIZE(ds2781_battery_props); 771 dev_info->bat_desc.num_properties = ARRAY_SIZE(ds2781_battery_props);
770 dev_info->bat.get_property = ds2781_battery_get_property; 772 dev_info->bat_desc.get_property = ds2781_battery_get_property;
771 773
772 ret = power_supply_register(&pdev->dev, &dev_info->bat, NULL); 774 psy_cfg.drv_data = dev_info;
773 if (ret) { 775
776 dev_info->bat = power_supply_register(&pdev->dev, &dev_info->bat_desc,
777 &psy_cfg);
778 if (IS_ERR(dev_info->bat)) {
774 dev_err(dev_info->dev, "failed to register battery\n"); 779 dev_err(dev_info->dev, "failed to register battery\n");
780 ret = PTR_ERR(dev_info->bat);
775 goto fail; 781 goto fail;
776 } 782 }
777 783
778 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2781_attr_group); 784 ret = sysfs_create_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
779 if (ret) { 785 if (ret) {
780 dev_err(dev_info->dev, "failed to create sysfs group\n"); 786 dev_err(dev_info->dev, "failed to create sysfs group\n");
781 goto fail_unregister; 787 goto fail_unregister;
782 } 788 }
783 789
784 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj, 790 ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
785 &ds2781_param_eeprom_bin_attr); 791 &ds2781_param_eeprom_bin_attr);
786 if (ret) { 792 if (ret) {
787 dev_err(dev_info->dev, 793 dev_err(dev_info->dev,
@@ -789,7 +795,7 @@ static int ds2781_battery_probe(struct platform_device *pdev)
789 goto fail_remove_group; 795 goto fail_remove_group;
790 } 796 }
791 797
792 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj, 798 ret = sysfs_create_bin_file(&dev_info->bat->dev.kobj,
793 &ds2781_user_eeprom_bin_attr); 799 &ds2781_user_eeprom_bin_attr);
794 if (ret) { 800 if (ret) {
795 dev_err(dev_info->dev, 801 dev_err(dev_info->dev,
@@ -800,12 +806,12 @@ static int ds2781_battery_probe(struct platform_device *pdev)
800 return 0; 806 return 0;
801 807
802fail_remove_bin_file: 808fail_remove_bin_file:
803 sysfs_remove_bin_file(&dev_info->bat.dev->kobj, 809 sysfs_remove_bin_file(&dev_info->bat->dev.kobj,
804 &ds2781_param_eeprom_bin_attr); 810 &ds2781_param_eeprom_bin_attr);
805fail_remove_group: 811fail_remove_group:
806 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group); 812 sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
807fail_unregister: 813fail_unregister:
808 power_supply_unregister(&dev_info->bat); 814 power_supply_unregister(dev_info->bat);
809fail: 815fail:
810 return ret; 816 return ret;
811} 817}
@@ -814,10 +820,13 @@ static int ds2781_battery_remove(struct platform_device *pdev)
814{ 820{
815 struct ds2781_device_info *dev_info = platform_get_drvdata(pdev); 821 struct ds2781_device_info *dev_info = platform_get_drvdata(pdev);
816 822
817 /* remove attributes */ 823 /*
818 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2781_attr_group); 824 * Remove attributes before unregistering power supply
825 * because 'bat' will be freed on power_supply_unregister() call.
826 */
827 sysfs_remove_group(&dev_info->bat->dev.kobj, &ds2781_attr_group);
819 828
820 power_supply_unregister(&dev_info->bat); 829 power_supply_unregister(dev_info->bat);
821 830
822 return 0; 831 return 0;
823} 832}
diff --git a/drivers/power/ds2782_battery.c b/drivers/power/ds2782_battery.c
index 2dcb96a83cee..ed4d756d21e4 100644
--- a/drivers/power/ds2782_battery.c
+++ b/drivers/power/ds2782_battery.c
@@ -53,11 +53,12 @@ struct ds278x_battery_ops {
53 int (*get_battery_capacity)(struct ds278x_info *info, int *capacity); 53 int (*get_battery_capacity)(struct ds278x_info *info, int *capacity);
54}; 54};
55 55
56#define to_ds278x_info(x) container_of(x, struct ds278x_info, battery) 56#define to_ds278x_info(x) power_supply_get_drvdata(x)
57 57
58struct ds278x_info { 58struct ds278x_info {
59 struct i2c_client *client; 59 struct i2c_client *client;
60 struct power_supply battery; 60 struct power_supply *battery;
61 struct power_supply_desc battery_desc;
61 struct ds278x_battery_ops *ops; 62 struct ds278x_battery_ops *ops;
62 struct delayed_work bat_work; 63 struct delayed_work bat_work;
63 int id; 64 int id;
@@ -285,7 +286,7 @@ static void ds278x_bat_update(struct ds278x_info *info)
285 ds278x_get_status(info, &info->status); 286 ds278x_get_status(info, &info->status);
286 287
287 if ((old_status != info->status) || (old_capacity != info->capacity)) 288 if ((old_status != info->status) || (old_capacity != info->capacity))
288 power_supply_changed(&info->battery); 289 power_supply_changed(info->battery);
289} 290}
290 291
291static void ds278x_bat_work(struct work_struct *work) 292static void ds278x_bat_work(struct work_struct *work)
@@ -306,7 +307,7 @@ static enum power_supply_property ds278x_battery_props[] = {
306 POWER_SUPPLY_PROP_TEMP, 307 POWER_SUPPLY_PROP_TEMP,
307}; 308};
308 309
309static void ds278x_power_supply_init(struct power_supply *battery) 310static void ds278x_power_supply_init(struct power_supply_desc *battery)
310{ 311{
311 battery->type = POWER_SUPPLY_TYPE_BATTERY; 312 battery->type = POWER_SUPPLY_TYPE_BATTERY;
312 battery->properties = ds278x_battery_props; 313 battery->properties = ds278x_battery_props;
@@ -319,8 +320,8 @@ static int ds278x_battery_remove(struct i2c_client *client)
319{ 320{
320 struct ds278x_info *info = i2c_get_clientdata(client); 321 struct ds278x_info *info = i2c_get_clientdata(client);
321 322
322 power_supply_unregister(&info->battery); 323 power_supply_unregister(info->battery);
323 kfree(info->battery.name); 324 kfree(info->battery_desc.name);
324 325
325 mutex_lock(&battery_lock); 326 mutex_lock(&battery_lock);
326 idr_remove(&battery_id, info->id); 327 idr_remove(&battery_id, info->id);
@@ -377,6 +378,7 @@ static int ds278x_battery_probe(struct i2c_client *client,
377 const struct i2c_device_id *id) 378 const struct i2c_device_id *id)
378{ 379{
379 struct ds278x_platform_data *pdata = client->dev.platform_data; 380 struct ds278x_platform_data *pdata = client->dev.platform_data;
381 struct power_supply_config psy_cfg = {};
380 struct ds278x_info *info; 382 struct ds278x_info *info;
381 int ret; 383 int ret;
382 int num; 384 int num;
@@ -404,8 +406,9 @@ static int ds278x_battery_probe(struct i2c_client *client,
404 goto fail_info; 406 goto fail_info;
405 } 407 }
406 408
407 info->battery.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num); 409 info->battery_desc.name = kasprintf(GFP_KERNEL, "%s-%d",
408 if (!info->battery.name) { 410 client->name, num);
411 if (!info->battery_desc.name) {
409 ret = -ENOMEM; 412 ret = -ENOMEM;
410 goto fail_name; 413 goto fail_name;
411 } 414 }
@@ -417,16 +420,19 @@ static int ds278x_battery_probe(struct i2c_client *client,
417 info->client = client; 420 info->client = client;
418 info->id = num; 421 info->id = num;
419 info->ops = &ds278x_ops[id->driver_data]; 422 info->ops = &ds278x_ops[id->driver_data];
420 ds278x_power_supply_init(&info->battery); 423 ds278x_power_supply_init(&info->battery_desc);
424 psy_cfg.drv_data = info;
421 425
422 info->capacity = 100; 426 info->capacity = 100;
423 info->status = POWER_SUPPLY_STATUS_FULL; 427 info->status = POWER_SUPPLY_STATUS_FULL;
424 428
425 INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work); 429 INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work);
426 430
427 ret = power_supply_register(&client->dev, &info->battery, NULL); 431 info->battery = power_supply_register(&client->dev,
428 if (ret) { 432 &info->battery_desc, &psy_cfg);
433 if (IS_ERR(info->battery)) {
429 dev_err(&client->dev, "failed to register battery\n"); 434 dev_err(&client->dev, "failed to register battery\n");
435 ret = PTR_ERR(info->battery);
430 goto fail_register; 436 goto fail_register;
431 } else { 437 } else {
432 schedule_delayed_work(&info->bat_work, DS278x_DELAY); 438 schedule_delayed_work(&info->bat_work, DS278x_DELAY);
@@ -435,7 +441,7 @@ static int ds278x_battery_probe(struct i2c_client *client,
435 return 0; 441 return 0;
436 442
437fail_register: 443fail_register:
438 kfree(info->battery.name); 444 kfree(info->battery_desc.name);
439fail_name: 445fail_name:
440 kfree(info); 446 kfree(info);
441fail_info: 447fail_info:
diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
index 4575955de7c5..fedc5818fab7 100644
--- a/drivers/power/generic-adc-battery.c
+++ b/drivers/power/generic-adc-battery.c
@@ -44,7 +44,8 @@ static const char *const gab_chan_name[] = {
44}; 44};
45 45
46struct gab { 46struct gab {
47 struct power_supply psy; 47 struct power_supply *psy;
48 struct power_supply_desc psy_desc;
48 struct iio_channel *channel[GAB_MAX_CHAN_TYPE]; 49 struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
49 struct gab_platform_data *pdata; 50 struct gab_platform_data *pdata;
50 struct delayed_work bat_work; 51 struct delayed_work bat_work;
@@ -55,7 +56,7 @@ struct gab {
55 56
56static struct gab *to_generic_bat(struct power_supply *psy) 57static struct gab *to_generic_bat(struct power_supply *psy)
57{ 58{
58 return container_of(psy, struct gab, psy); 59 return power_supply_get_drvdata(psy);
59} 60}
60 61
61static void gab_ext_power_changed(struct power_supply *psy) 62static void gab_ext_power_changed(struct power_supply *psy)
@@ -151,7 +152,7 @@ static int gab_get_property(struct power_supply *psy,
151 152
152 adc_bat = to_generic_bat(psy); 153 adc_bat = to_generic_bat(psy);
153 if (!adc_bat) { 154 if (!adc_bat) {
154 dev_err(psy->dev, "no battery infos ?!\n"); 155 dev_err(&psy->dev, "no battery infos ?!\n");
155 return -EINVAL; 156 return -EINVAL;
156 } 157 }
157 pdata = adc_bat->pdata; 158 pdata = adc_bat->pdata;
@@ -210,7 +211,7 @@ static void gab_work(struct work_struct *work)
210 pdata = adc_bat->pdata; 211 pdata = adc_bat->pdata;
211 status = adc_bat->status; 212 status = adc_bat->status;
212 213
213 is_plugged = power_supply_am_i_supplied(&adc_bat->psy); 214 is_plugged = power_supply_am_i_supplied(adc_bat->psy);
214 adc_bat->cable_plugged = is_plugged; 215 adc_bat->cable_plugged = is_plugged;
215 216
216 if (!is_plugged) 217 if (!is_plugged)
@@ -221,7 +222,7 @@ static void gab_work(struct work_struct *work)
221 adc_bat->status = POWER_SUPPLY_STATUS_CHARGING; 222 adc_bat->status = POWER_SUPPLY_STATUS_CHARGING;
222 223
223 if (status != adc_bat->status) 224 if (status != adc_bat->status)
224 power_supply_changed(&adc_bat->psy); 225 power_supply_changed(adc_bat->psy);
225} 226}
226 227
227static irqreturn_t gab_charged(int irq, void *dev_id) 228static irqreturn_t gab_charged(int irq, void *dev_id)
@@ -239,7 +240,8 @@ static irqreturn_t gab_charged(int irq, void *dev_id)
239static int gab_probe(struct platform_device *pdev) 240static int gab_probe(struct platform_device *pdev)
240{ 241{
241 struct gab *adc_bat; 242 struct gab *adc_bat;
242 struct power_supply *psy; 243 struct power_supply_desc *psy_desc;
244 struct power_supply_config psy_cfg = {};
243 struct gab_platform_data *pdata = pdev->dev.platform_data; 245 struct gab_platform_data *pdata = pdev->dev.platform_data;
244 enum power_supply_property *properties; 246 enum power_supply_property *properties;
245 int ret = 0; 247 int ret = 0;
@@ -252,32 +254,34 @@ static int gab_probe(struct platform_device *pdev)
252 return -ENOMEM; 254 return -ENOMEM;
253 } 255 }
254 256
255 psy = &adc_bat->psy; 257 psy_cfg.drv_data = adc_bat;
256 psy->name = pdata->battery_info.name; 258 psy_desc = &adc_bat->psy_desc;
259 psy_desc->name = pdata->battery_info.name;
257 260
258 /* bootup default values for the battery */ 261 /* bootup default values for the battery */
259 adc_bat->cable_plugged = false; 262 adc_bat->cable_plugged = false;
260 adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING; 263 adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
261 psy->type = POWER_SUPPLY_TYPE_BATTERY; 264 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
262 psy->get_property = gab_get_property; 265 psy_desc->get_property = gab_get_property;
263 psy->external_power_changed = gab_ext_power_changed; 266 psy_desc->external_power_changed = gab_ext_power_changed;
264 adc_bat->pdata = pdata; 267 adc_bat->pdata = pdata;
265 268
266 /* 269 /*
267 * copying the static properties and allocating extra memory for holding 270 * copying the static properties and allocating extra memory for holding
268 * the extra configurable properties received from platform data. 271 * the extra configurable properties received from platform data.
269 */ 272 */
270 psy->properties = kcalloc(ARRAY_SIZE(gab_props) + 273 psy_desc->properties = kcalloc(ARRAY_SIZE(gab_props) +
271 ARRAY_SIZE(gab_chan_name), 274 ARRAY_SIZE(gab_chan_name),
272 sizeof(*psy->properties), GFP_KERNEL); 275 sizeof(*psy_desc->properties),
273 if (!psy->properties) { 276 GFP_KERNEL);
277 if (!psy_desc->properties) {
274 ret = -ENOMEM; 278 ret = -ENOMEM;
275 goto first_mem_fail; 279 goto first_mem_fail;
276 } 280 }
277 281
278 memcpy(psy->properties, gab_props, sizeof(gab_props)); 282 memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
279 properties = (enum power_supply_property *) 283 properties = (enum power_supply_property *)
280 ((char *)psy->properties + sizeof(gab_props)); 284 ((char *)psy_desc->properties + sizeof(gab_props));
281 285
282 /* 286 /*
283 * getting channel from iio and copying the battery properties 287 * getting channel from iio and copying the battery properties
@@ -291,7 +295,7 @@ static int gab_probe(struct platform_device *pdev)
291 adc_bat->channel[chan] = NULL; 295 adc_bat->channel[chan] = NULL;
292 } else { 296 } else {
293 /* copying properties for supported channels only */ 297 /* copying properties for supported channels only */
294 memcpy(properties + sizeof(*(psy->properties)) * index, 298 memcpy(properties + sizeof(*(psy_desc->properties)) * index,
295 &gab_dyn_props[chan], 299 &gab_dyn_props[chan],
296 sizeof(gab_dyn_props[chan])); 300 sizeof(gab_dyn_props[chan]));
297 index++; 301 index++;
@@ -310,11 +314,13 @@ static int gab_probe(struct platform_device *pdev)
310 * as come channels may be not be supported by the device.So 314 * as come channels may be not be supported by the device.So
311 * we need to take care of that. 315 * we need to take care of that.
312 */ 316 */
313 psy->num_properties = ARRAY_SIZE(gab_props) + index; 317 psy_desc->num_properties = ARRAY_SIZE(gab_props) + index;
314 318
315 ret = power_supply_register(&pdev->dev, psy, NULL); 319 adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
316 if (ret) 320 if (IS_ERR(adc_bat->psy)) {
321 ret = PTR_ERR(adc_bat->psy);
317 goto err_reg_fail; 322 goto err_reg_fail;
323 }
318 324
319 INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work); 325 INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
320 326
@@ -342,14 +348,14 @@ static int gab_probe(struct platform_device *pdev)
342err_gpio: 348err_gpio:
343 gpio_free(pdata->gpio_charge_finished); 349 gpio_free(pdata->gpio_charge_finished);
344gpio_req_fail: 350gpio_req_fail:
345 power_supply_unregister(psy); 351 power_supply_unregister(adc_bat->psy);
346err_reg_fail: 352err_reg_fail:
347 for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { 353 for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
348 if (adc_bat->channel[chan]) 354 if (adc_bat->channel[chan])
349 iio_channel_release(adc_bat->channel[chan]); 355 iio_channel_release(adc_bat->channel[chan]);
350 } 356 }
351second_mem_fail: 357second_mem_fail:
352 kfree(psy->properties); 358 kfree(psy_desc->properties);
353first_mem_fail: 359first_mem_fail:
354 return ret; 360 return ret;
355} 361}
@@ -360,7 +366,7 @@ static int gab_remove(struct platform_device *pdev)
360 struct gab *adc_bat = platform_get_drvdata(pdev); 366 struct gab *adc_bat = platform_get_drvdata(pdev);
361 struct gab_platform_data *pdata = adc_bat->pdata; 367 struct gab_platform_data *pdata = adc_bat->pdata;
362 368
363 power_supply_unregister(&adc_bat->psy); 369 power_supply_unregister(adc_bat->psy);
364 370
365 if (gpio_is_valid(pdata->gpio_charge_finished)) { 371 if (gpio_is_valid(pdata->gpio_charge_finished)) {
366 free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat); 372 free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat);
@@ -372,7 +378,7 @@ static int gab_remove(struct platform_device *pdev)
372 iio_channel_release(adc_bat->channel[chan]); 378 iio_channel_release(adc_bat->channel[chan]);
373 } 379 }
374 380
375 kfree(adc_bat->psy.properties); 381 kfree(adc_bat->psy_desc.properties);
376 cancel_delayed_work(&adc_bat->bat_work); 382 cancel_delayed_work(&adc_bat->bat_work);
377 return 0; 383 return 0;
378} 384}
diff --git a/drivers/power/goldfish_battery.c b/drivers/power/goldfish_battery.c
index 61d437f8cf76..a50bb988c69a 100644
--- a/drivers/power/goldfish_battery.c
+++ b/drivers/power/goldfish_battery.c
@@ -30,8 +30,8 @@ struct goldfish_battery_data {
30 int irq; 30 int irq;
31 spinlock_t lock; 31 spinlock_t lock;
32 32
33 struct power_supply battery; 33 struct power_supply *battery;
34 struct power_supply ac; 34 struct power_supply *ac;
35}; 35};
36 36
37#define GOLDFISH_BATTERY_READ(data, addr) \ 37#define GOLDFISH_BATTERY_READ(data, addr) \
@@ -67,8 +67,7 @@ static int goldfish_ac_get_property(struct power_supply *psy,
67 enum power_supply_property psp, 67 enum power_supply_property psp,
68 union power_supply_propval *val) 68 union power_supply_propval *val)
69{ 69{
70 struct goldfish_battery_data *data = container_of(psy, 70 struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
71 struct goldfish_battery_data, ac);
72 int ret = 0; 71 int ret = 0;
73 72
74 switch (psp) { 73 switch (psp) {
@@ -86,8 +85,7 @@ static int goldfish_battery_get_property(struct power_supply *psy,
86 enum power_supply_property psp, 85 enum power_supply_property psp,
87 union power_supply_propval *val) 86 union power_supply_propval *val)
88{ 87{
89 struct goldfish_battery_data *data = container_of(psy, 88 struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
90 struct goldfish_battery_data, battery);
91 int ret = 0; 89 int ret = 0;
92 90
93 switch (psp) { 91 switch (psp) {
@@ -139,20 +137,36 @@ static irqreturn_t goldfish_battery_interrupt(int irq, void *dev_id)
139 status &= BATTERY_INT_MASK; 137 status &= BATTERY_INT_MASK;
140 138
141 if (status & BATTERY_STATUS_CHANGED) 139 if (status & BATTERY_STATUS_CHANGED)
142 power_supply_changed(&data->battery); 140 power_supply_changed(data->battery);
143 if (status & AC_STATUS_CHANGED) 141 if (status & AC_STATUS_CHANGED)
144 power_supply_changed(&data->ac); 142 power_supply_changed(data->ac);
145 143
146 spin_unlock_irqrestore(&data->lock, irq_flags); 144 spin_unlock_irqrestore(&data->lock, irq_flags);
147 return status ? IRQ_HANDLED : IRQ_NONE; 145 return status ? IRQ_HANDLED : IRQ_NONE;
148} 146}
149 147
148static const struct power_supply_desc battery_desc = {
149 .properties = goldfish_battery_props,
150 .num_properties = ARRAY_SIZE(goldfish_battery_props),
151 .get_property = goldfish_battery_get_property,
152 .name = "battery",
153 .type = POWER_SUPPLY_TYPE_BATTERY,
154};
155
156static const struct power_supply_desc ac_desc = {
157 .properties = goldfish_ac_props,
158 .num_properties = ARRAY_SIZE(goldfish_ac_props),
159 .get_property = goldfish_ac_get_property,
160 .name = "ac",
161 .type = POWER_SUPPLY_TYPE_MAINS,
162};
150 163
151static int goldfish_battery_probe(struct platform_device *pdev) 164static int goldfish_battery_probe(struct platform_device *pdev)
152{ 165{
153 int ret; 166 int ret;
154 struct resource *r; 167 struct resource *r;
155 struct goldfish_battery_data *data; 168 struct goldfish_battery_data *data;
169 struct power_supply_config psy_cfg = {};
156 170
157 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 171 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
158 if (data == NULL) 172 if (data == NULL)
@@ -160,18 +174,6 @@ static int goldfish_battery_probe(struct platform_device *pdev)
160 174
161 spin_lock_init(&data->lock); 175 spin_lock_init(&data->lock);
162 176
163 data->battery.properties = goldfish_battery_props;
164 data->battery.num_properties = ARRAY_SIZE(goldfish_battery_props);
165 data->battery.get_property = goldfish_battery_get_property;
166 data->battery.name = "battery";
167 data->battery.type = POWER_SUPPLY_TYPE_BATTERY;
168
169 data->ac.properties = goldfish_ac_props;
170 data->ac.num_properties = ARRAY_SIZE(goldfish_ac_props);
171 data->ac.get_property = goldfish_ac_get_property;
172 data->ac.name = "ac";
173 data->ac.type = POWER_SUPPLY_TYPE_MAINS;
174
175 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 177 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
176 if (r == NULL) { 178 if (r == NULL) {
177 dev_err(&pdev->dev, "platform_get_resource failed\n"); 179 dev_err(&pdev->dev, "platform_get_resource failed\n");
@@ -195,14 +197,17 @@ static int goldfish_battery_probe(struct platform_device *pdev)
195 if (ret) 197 if (ret)
196 return ret; 198 return ret;
197 199
198 ret = power_supply_register(&pdev->dev, &data->ac, NULL); 200 psy_cfg.drv_data = data;
199 if (ret)
200 return ret;
201 201
202 ret = power_supply_register(&pdev->dev, &data->battery, NULL); 202 data->ac = power_supply_register(&pdev->dev, &ac_desc, &psy_cfg);
203 if (ret) { 203 if (IS_ERR(data->ac))
204 power_supply_unregister(&data->ac); 204 return PTR_ERR(data->ac);
205 return ret; 205
206 data->battery = power_supply_register(&pdev->dev, &battery_desc,
207 &psy_cfg);
208 if (IS_ERR(data->battery)) {
209 power_supply_unregister(data->ac);
210 return PTR_ERR(data->battery);
206 } 211 }
207 212
208 platform_set_drvdata(pdev, data); 213 platform_set_drvdata(pdev, data);
@@ -216,8 +221,8 @@ static int goldfish_battery_remove(struct platform_device *pdev)
216{ 221{
217 struct goldfish_battery_data *data = platform_get_drvdata(pdev); 222 struct goldfish_battery_data *data = platform_get_drvdata(pdev);
218 223
219 power_supply_unregister(&data->battery); 224 power_supply_unregister(data->battery);
220 power_supply_unregister(&data->ac); 225 power_supply_unregister(data->ac);
221 battery_data = NULL; 226 battery_data = NULL;
222 return 0; 227 return 0;
223} 228}
diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
index 47a9e2bd94d9..c5869b1941ac 100644
--- a/drivers/power/gpio-charger.c
+++ b/drivers/power/gpio-charger.c
@@ -32,7 +32,8 @@ struct gpio_charger {
32 unsigned int irq; 32 unsigned int irq;
33 bool wakeup_enabled; 33 bool wakeup_enabled;
34 34
35 struct power_supply charger; 35 struct power_supply *charger;
36 struct power_supply_desc charger_desc;
36}; 37};
37 38
38static irqreturn_t gpio_charger_irq(int irq, void *devid) 39static irqreturn_t gpio_charger_irq(int irq, void *devid)
@@ -46,7 +47,7 @@ static irqreturn_t gpio_charger_irq(int irq, void *devid)
46 47
47static inline struct gpio_charger *psy_to_gpio_charger(struct power_supply *psy) 48static inline struct gpio_charger *psy_to_gpio_charger(struct power_supply *psy)
48{ 49{
49 return container_of(psy, struct gpio_charger, charger); 50 return power_supply_get_drvdata(psy);
50} 51}
51 52
52static int gpio_charger_get_property(struct power_supply *psy, 53static int gpio_charger_get_property(struct power_supply *psy,
@@ -129,7 +130,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
129 const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data; 130 const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data;
130 struct power_supply_config psy_cfg = {}; 131 struct power_supply_config psy_cfg = {};
131 struct gpio_charger *gpio_charger; 132 struct gpio_charger *gpio_charger;
132 struct power_supply *charger; 133 struct power_supply_desc *charger_desc;
133 int ret; 134 int ret;
134 int irq; 135 int irq;
135 136
@@ -155,17 +156,18 @@ static int gpio_charger_probe(struct platform_device *pdev)
155 return -ENOMEM; 156 return -ENOMEM;
156 } 157 }
157 158
158 charger = &gpio_charger->charger; 159 charger_desc = &gpio_charger->charger_desc;
159 160
160 charger->name = pdata->name ? pdata->name : "gpio-charger"; 161 charger_desc->name = pdata->name ? pdata->name : "gpio-charger";
161 charger->type = pdata->type; 162 charger_desc->type = pdata->type;
162 charger->properties = gpio_charger_properties; 163 charger_desc->properties = gpio_charger_properties;
163 charger->num_properties = ARRAY_SIZE(gpio_charger_properties); 164 charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties);
164 charger->get_property = gpio_charger_get_property; 165 charger_desc->get_property = gpio_charger_get_property;
165 166
166 psy_cfg.supplied_to = pdata->supplied_to; 167 psy_cfg.supplied_to = pdata->supplied_to;
167 psy_cfg.num_supplicants = pdata->num_supplicants; 168 psy_cfg.num_supplicants = pdata->num_supplicants;
168 psy_cfg.of_node = pdev->dev.of_node; 169 psy_cfg.of_node = pdev->dev.of_node;
170 psy_cfg.drv_data = gpio_charger;
169 171
170 ret = gpio_request(pdata->gpio, dev_name(&pdev->dev)); 172 ret = gpio_request(pdata->gpio, dev_name(&pdev->dev));
171 if (ret) { 173 if (ret) {
@@ -180,8 +182,10 @@ static int gpio_charger_probe(struct platform_device *pdev)
180 182
181 gpio_charger->pdata = pdata; 183 gpio_charger->pdata = pdata;
182 184
183 ret = power_supply_register(&pdev->dev, charger, &psy_cfg); 185 gpio_charger->charger = power_supply_register(&pdev->dev,
184 if (ret < 0) { 186 charger_desc, &psy_cfg);
187 if (IS_ERR(gpio_charger->charger)) {
188 ret = PTR_ERR(gpio_charger->charger);
185 dev_err(&pdev->dev, "Failed to register power supply: %d\n", 189 dev_err(&pdev->dev, "Failed to register power supply: %d\n",
186 ret); 190 ret);
187 goto err_gpio_free; 191 goto err_gpio_free;
@@ -191,7 +195,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
191 if (irq > 0) { 195 if (irq > 0) {
192 ret = request_any_context_irq(irq, gpio_charger_irq, 196 ret = request_any_context_irq(irq, gpio_charger_irq,
193 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 197 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
194 dev_name(&pdev->dev), charger); 198 dev_name(&pdev->dev), gpio_charger->charger);
195 if (ret < 0) 199 if (ret < 0)
196 dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret); 200 dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret);
197 else 201 else
@@ -215,9 +219,9 @@ static int gpio_charger_remove(struct platform_device *pdev)
215 struct gpio_charger *gpio_charger = platform_get_drvdata(pdev); 219 struct gpio_charger *gpio_charger = platform_get_drvdata(pdev);
216 220
217 if (gpio_charger->irq) 221 if (gpio_charger->irq)
218 free_irq(gpio_charger->irq, &gpio_charger->charger); 222 free_irq(gpio_charger->irq, gpio_charger->charger);
219 223
220 power_supply_unregister(&gpio_charger->charger); 224 power_supply_unregister(gpio_charger->charger);
221 225
222 gpio_free(gpio_charger->pdata->gpio); 226 gpio_free(gpio_charger->pdata->gpio);
223 227
@@ -243,7 +247,7 @@ static int gpio_charger_resume(struct device *dev)
243 247
244 if (device_may_wakeup(dev) && gpio_charger->wakeup_enabled) 248 if (device_may_wakeup(dev) && gpio_charger->wakeup_enabled)
245 disable_irq_wake(gpio_charger->irq); 249 disable_irq_wake(gpio_charger->irq);
246 power_supply_changed(&gpio_charger->charger); 250 power_supply_changed(gpio_charger->charger);
247 251
248 return 0; 252 return 0;
249} 253}
diff --git a/drivers/power/intel_mid_battery.c b/drivers/power/intel_mid_battery.c
index 8a149657cd71..9fa4acc107ca 100644
--- a/drivers/power/intel_mid_battery.c
+++ b/drivers/power/intel_mid_battery.c
@@ -107,8 +107,8 @@ struct pmic_power_module_info {
107 unsigned int batt_prev_charge_full; /* in mAS */ 107 unsigned int batt_prev_charge_full; /* in mAS */
108 unsigned int batt_charge_rate; /* in units per second */ 108 unsigned int batt_charge_rate; /* in units per second */
109 109
110 struct power_supply usb; 110 struct power_supply *usb;
111 struct power_supply batt; 111 struct power_supply *batt;
112 int irq; /* GPE_ID or IRQ# */ 112 int irq; /* GPE_ID or IRQ# */
113 struct workqueue_struct *monitor_wqueue; 113 struct workqueue_struct *monitor_wqueue;
114 struct delayed_work monitor_battery; 114 struct delayed_work monitor_battery;
@@ -404,8 +404,7 @@ static int pmic_usb_get_property(struct power_supply *psy,
404 enum power_supply_property psp, 404 enum power_supply_property psp,
405 union power_supply_propval *val) 405 union power_supply_propval *val)
406{ 406{
407 struct pmic_power_module_info *pbi = container_of(psy, 407 struct pmic_power_module_info *pbi = power_supply_get_drvdata(psy);
408 struct pmic_power_module_info, usb);
409 408
410 /* update pmic_power_module_info members */ 409 /* update pmic_power_module_info members */
411 pmic_battery_read_status(pbi); 410 pmic_battery_read_status(pbi);
@@ -444,8 +443,7 @@ static int pmic_battery_get_property(struct power_supply *psy,
444 enum power_supply_property psp, 443 enum power_supply_property psp,
445 union power_supply_propval *val) 444 union power_supply_propval *val)
446{ 445{
447 struct pmic_power_module_info *pbi = container_of(psy, 446 struct pmic_power_module_info *pbi = power_supply_get_drvdata(psy);
448 struct pmic_power_module_info, batt);
449 447
450 /* update pmic_power_module_info members */ 448 /* update pmic_power_module_info members */
451 pmic_battery_read_status(pbi); 449 pmic_battery_read_status(pbi);
@@ -640,6 +638,25 @@ static void pmic_battery_handle_intrpt(struct work_struct *work)
640 __func__); 638 __func__);
641} 639}
642 640
641/*
642 * Description of power supplies
643 */
644static const struct power_supply_desc pmic_usb_desc = {
645 .name = "pmic-usb",
646 .type = POWER_SUPPLY_TYPE_USB,
647 .properties = pmic_usb_props,
648 .num_properties = ARRAY_SIZE(pmic_usb_props),
649 .get_property = pmic_usb_get_property,
650};
651
652static const struct power_supply_desc pmic_batt_desc = {
653 .name = "pmic-batt",
654 .type = POWER_SUPPLY_TYPE_BATTERY,
655 .properties = pmic_battery_props,
656 .num_properties = ARRAY_SIZE(pmic_battery_props),
657 .get_property = pmic_battery_get_property,
658};
659
643/** 660/**
644 * pmic_battery_probe - pmic battery initialize 661 * pmic_battery_probe - pmic battery initialize
645 * @irq: pmic battery device irq 662 * @irq: pmic battery device irq
@@ -653,6 +670,7 @@ static int probe(int irq, struct device *dev)
653{ 670{
654 int retval = 0; 671 int retval = 0;
655 struct pmic_power_module_info *pbi; 672 struct pmic_power_module_info *pbi;
673 struct power_supply_config psy_cfg = {};
656 674
657 dev_dbg(dev, "pmic-battery: found pmic battery device\n"); 675 dev_dbg(dev, "pmic-battery: found pmic battery device\n");
658 676
@@ -666,6 +684,7 @@ static int probe(int irq, struct device *dev)
666 pbi->dev = dev; 684 pbi->dev = dev;
667 pbi->irq = irq; 685 pbi->irq = irq;
668 dev_set_drvdata(dev, pbi); 686 dev_set_drvdata(dev, pbi);
687 psy_cfg.drv_data = pbi;
669 688
670 /* initialize all required framework before enabling interrupts */ 689 /* initialize all required framework before enabling interrupts */
671 INIT_WORK(&pbi->handler, pmic_battery_handle_intrpt); 690 INIT_WORK(&pbi->handler, pmic_battery_handle_intrpt);
@@ -687,16 +706,12 @@ static int probe(int irq, struct device *dev)
687 } 706 }
688 707
689 /* register pmic-batt with power supply subsystem */ 708 /* register pmic-batt with power supply subsystem */
690 pbi->batt.name = "pmic-batt"; 709 pbi->batt = power_supply_register(dev, &pmic_usb_desc, &psy_cfg);
691 pbi->batt.type = POWER_SUPPLY_TYPE_BATTERY; 710 if (IS_ERR(pbi->batt)) {
692 pbi->batt.properties = pmic_battery_props;
693 pbi->batt.num_properties = ARRAY_SIZE(pmic_battery_props);
694 pbi->batt.get_property = pmic_battery_get_property;
695 retval = power_supply_register(dev, &pbi->batt, NULL);
696 if (retval) {
697 dev_err(dev, 711 dev_err(dev,
698 "%s(): failed to register pmic battery device with power supply subsystem\n", 712 "%s(): failed to register pmic battery device with power supply subsystem\n",
699 __func__); 713 __func__);
714 retval = PTR_ERR(pbi->batt);
700 goto power_reg_failed; 715 goto power_reg_failed;
701 } 716 }
702 717
@@ -707,16 +722,12 @@ static int probe(int irq, struct device *dev)
707 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 1); 722 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 1);
708 723
709 /* register pmic-usb with power supply subsystem */ 724 /* register pmic-usb with power supply subsystem */
710 pbi->usb.name = "pmic-usb"; 725 pbi->usb = power_supply_register(dev, &pmic_batt_desc, &psy_cfg);
711 pbi->usb.type = POWER_SUPPLY_TYPE_USB; 726 if (IS_ERR(pbi->usb)) {
712 pbi->usb.properties = pmic_usb_props;
713 pbi->usb.num_properties = ARRAY_SIZE(pmic_usb_props);
714 pbi->usb.get_property = pmic_usb_get_property;
715 retval = power_supply_register(dev, &pbi->usb, NULL);
716 if (retval) {
717 dev_err(dev, 727 dev_err(dev,
718 "%s(): failed to register pmic usb device with power supply subsystem\n", 728 "%s(): failed to register pmic usb device with power supply subsystem\n",
719 __func__); 729 __func__);
730 retval = PTR_ERR(pbi->usb);
720 goto power_reg_failed_1; 731 goto power_reg_failed_1;
721 } 732 }
722 733
@@ -728,7 +739,7 @@ static int probe(int irq, struct device *dev)
728 return retval; 739 return retval;
729 740
730power_reg_failed_1: 741power_reg_failed_1:
731 power_supply_unregister(&pbi->batt); 742 power_supply_unregister(pbi->batt);
732power_reg_failed: 743power_reg_failed:
733 cancel_delayed_work_sync(&pbi->monitor_battery); 744 cancel_delayed_work_sync(&pbi->monitor_battery);
734requestirq_failed: 745requestirq_failed:
@@ -762,8 +773,8 @@ static int platform_pmic_battery_remove(struct platform_device *pdev)
762 cancel_delayed_work_sync(&pbi->monitor_battery); 773 cancel_delayed_work_sync(&pbi->monitor_battery);
763 destroy_workqueue(pbi->monitor_wqueue); 774 destroy_workqueue(pbi->monitor_wqueue);
764 775
765 power_supply_unregister(&pbi->usb); 776 power_supply_unregister(pbi->usb);
766 power_supply_unregister(&pbi->batt); 777 power_supply_unregister(pbi->batt);
767 778
768 cancel_work_sync(&pbi->handler); 779 cancel_work_sync(&pbi->handler);
769 kfree(pbi); 780 kfree(pbi);
diff --git a/drivers/power/ipaq_micro_battery.c b/drivers/power/ipaq_micro_battery.c
index 842e7e2e1cb5..f03014ea1dc4 100644
--- a/drivers/power/ipaq_micro_battery.c
+++ b/drivers/power/ipaq_micro_battery.c
@@ -93,7 +93,7 @@ static void micro_battery_work(struct work_struct *work)
93 93
94static int get_capacity(struct power_supply *b) 94static int get_capacity(struct power_supply *b)
95{ 95{
96 struct micro_battery *mb = dev_get_drvdata(b->dev->parent); 96 struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
97 97
98 switch (mb->flag & 0x07) { 98 switch (mb->flag & 0x07) {
99 case MICRO_BATT_STATUS_HIGH: 99 case MICRO_BATT_STATUS_HIGH:
@@ -113,7 +113,7 @@ static int get_capacity(struct power_supply *b)
113 113
114static int get_status(struct power_supply *b) 114static int get_status(struct power_supply *b)
115{ 115{
116 struct micro_battery *mb = dev_get_drvdata(b->dev->parent); 116 struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
117 117
118 if (mb->flag == MICRO_BATT_STATUS_UNKNOWN) 118 if (mb->flag == MICRO_BATT_STATUS_UNKNOWN)
119 return POWER_SUPPLY_STATUS_UNKNOWN; 119 return POWER_SUPPLY_STATUS_UNKNOWN;
@@ -132,7 +132,7 @@ static int micro_batt_get_property(struct power_supply *b,
132 enum power_supply_property psp, 132 enum power_supply_property psp,
133 union power_supply_propval *val) 133 union power_supply_propval *val)
134{ 134{
135 struct micro_battery *mb = dev_get_drvdata(b->dev->parent); 135 struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
136 136
137 switch (psp) { 137 switch (psp) {
138 case POWER_SUPPLY_PROP_TECHNOLOGY: 138 case POWER_SUPPLY_PROP_TECHNOLOGY:
@@ -180,7 +180,7 @@ static int micro_ac_get_property(struct power_supply *b,
180 enum power_supply_property psp, 180 enum power_supply_property psp,
181 union power_supply_propval *val) 181 union power_supply_propval *val)
182{ 182{
183 struct micro_battery *mb = dev_get_drvdata(b->dev->parent); 183 struct micro_battery *mb = dev_get_drvdata(b->dev.parent);
184 184
185 switch (psp) { 185 switch (psp) {
186 case POWER_SUPPLY_PROP_ONLINE: 186 case POWER_SUPPLY_PROP_ONLINE:
@@ -202,7 +202,7 @@ static enum power_supply_property micro_batt_power_props[] = {
202 POWER_SUPPLY_PROP_VOLTAGE_NOW, 202 POWER_SUPPLY_PROP_VOLTAGE_NOW,
203}; 203};
204 204
205static struct power_supply micro_batt_power = { 205static const struct power_supply_desc micro_batt_power_desc = {
206 .name = "main-battery", 206 .name = "main-battery",
207 .type = POWER_SUPPLY_TYPE_BATTERY, 207 .type = POWER_SUPPLY_TYPE_BATTERY,
208 .properties = micro_batt_power_props, 208 .properties = micro_batt_power_props,
@@ -215,7 +215,7 @@ static enum power_supply_property micro_ac_power_props[] = {
215 POWER_SUPPLY_PROP_ONLINE, 215 POWER_SUPPLY_PROP_ONLINE,
216}; 216};
217 217
218static struct power_supply micro_ac_power = { 218static const struct power_supply_desc micro_ac_power_desc = {
219 .name = "ac", 219 .name = "ac",
220 .type = POWER_SUPPLY_TYPE_MAINS, 220 .type = POWER_SUPPLY_TYPE_MAINS,
221 .properties = micro_ac_power_props, 221 .properties = micro_ac_power_props,
@@ -223,6 +223,8 @@ static struct power_supply micro_ac_power = {
223 .get_property = micro_ac_get_property, 223 .get_property = micro_ac_get_property,
224}; 224};
225 225
226static struct power_supply *micro_batt_power, *micro_ac_power;
227
226static int micro_batt_probe(struct platform_device *pdev) 228static int micro_batt_probe(struct platform_device *pdev)
227{ 229{
228 struct micro_battery *mb; 230 struct micro_battery *mb;
@@ -241,19 +243,25 @@ static int micro_batt_probe(struct platform_device *pdev)
241 platform_set_drvdata(pdev, mb); 243 platform_set_drvdata(pdev, mb);
242 queue_delayed_work(mb->wq, &mb->update, 1); 244 queue_delayed_work(mb->wq, &mb->update, 1);
243 245
244 ret = power_supply_register(&pdev->dev, &micro_batt_power, NULL); 246 micro_batt_power = power_supply_register(&pdev->dev,
245 if (ret < 0) 247 &micro_batt_power_desc, NULL);
248 if (IS_ERR(micro_batt_power)) {
249 ret = PTR_ERR(micro_batt_power);
246 goto batt_err; 250 goto batt_err;
251 }
247 252
248 ret = power_supply_register(&pdev->dev, &micro_ac_power, NULL); 253 micro_ac_power = power_supply_register(&pdev->dev,
249 if (ret < 0) 254 &micro_ac_power_desc, NULL);
255 if (IS_ERR(micro_ac_power)) {
256 ret = PTR_ERR(micro_ac_power);
250 goto ac_err; 257 goto ac_err;
258 }
251 259
252 dev_info(&pdev->dev, "iPAQ micro battery driver\n"); 260 dev_info(&pdev->dev, "iPAQ micro battery driver\n");
253 return 0; 261 return 0;
254 262
255ac_err: 263ac_err:
256 power_supply_unregister(&micro_ac_power); 264 power_supply_unregister(micro_ac_power);
257batt_err: 265batt_err:
258 cancel_delayed_work_sync(&mb->update); 266 cancel_delayed_work_sync(&mb->update);
259 destroy_workqueue(mb->wq); 267 destroy_workqueue(mb->wq);
@@ -265,8 +273,8 @@ static int micro_batt_remove(struct platform_device *pdev)
265{ 273{
266 struct micro_battery *mb = platform_get_drvdata(pdev); 274 struct micro_battery *mb = platform_get_drvdata(pdev);
267 275
268 power_supply_unregister(&micro_ac_power); 276 power_supply_unregister(micro_ac_power);
269 power_supply_unregister(&micro_batt_power); 277 power_supply_unregister(micro_batt_power);
270 cancel_delayed_work_sync(&mb->update); 278 cancel_delayed_work_sync(&mb->update);
271 destroy_workqueue(mb->wq); 279 destroy_workqueue(mb->wq);
272 280
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index 5521178bdc08..f2a7d970388f 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -57,11 +57,12 @@ static u16 isp170x_id[] = {
57}; 57};
58 58
59struct isp1704_charger { 59struct isp1704_charger {
60 struct device *dev; 60 struct device *dev;
61 struct power_supply psy; 61 struct power_supply *psy;
62 struct usb_phy *phy; 62 struct power_supply_desc psy_desc;
63 struct notifier_block nb; 63 struct usb_phy *phy;
64 struct work_struct work; 64 struct notifier_block nb;
65 struct work_struct work;
65 66
66 /* properties */ 67 /* properties */
67 char model[8]; 68 char model[8];
@@ -259,10 +260,10 @@ static void isp1704_charger_work(struct work_struct *data)
259 260
260 /* detect wall charger */ 261 /* detect wall charger */
261 if (isp1704_charger_detect_dcp(isp)) { 262 if (isp1704_charger_detect_dcp(isp)) {
262 isp->psy.type = POWER_SUPPLY_TYPE_USB_DCP; 263 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_DCP;
263 isp->current_max = 1800; 264 isp->current_max = 1800;
264 } else { 265 } else {
265 isp->psy.type = POWER_SUPPLY_TYPE_USB; 266 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
266 isp->current_max = 500; 267 isp->current_max = 500;
267 } 268 }
268 269
@@ -271,7 +272,7 @@ static void isp1704_charger_work(struct work_struct *data)
271 usb_gadget_connect(isp->phy->otg->gadget); 272 usb_gadget_connect(isp->phy->otg->gadget);
272 } 273 }
273 274
274 if (isp->psy.type != POWER_SUPPLY_TYPE_USB_DCP) { 275 if (isp->psy_desc.type != POWER_SUPPLY_TYPE_USB_DCP) {
275 /* 276 /*
276 * Only 500mA here or high speed chirp 277 * Only 500mA here or high speed chirp
277 * handshaking may break 278 * handshaking may break
@@ -280,14 +281,14 @@ static void isp1704_charger_work(struct work_struct *data)
280 isp->current_max = 500; 281 isp->current_max = 500;
281 282
282 if (isp->current_max > 100) 283 if (isp->current_max > 100)
283 isp->psy.type = POWER_SUPPLY_TYPE_USB_CDP; 284 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_CDP;
284 } 285 }
285 break; 286 break;
286 case USB_EVENT_NONE: 287 case USB_EVENT_NONE:
287 isp->online = false; 288 isp->online = false;
288 isp->present = 0; 289 isp->present = 0;
289 isp->current_max = 0; 290 isp->current_max = 0;
290 isp->psy.type = POWER_SUPPLY_TYPE_USB; 291 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
291 292
292 /* 293 /*
293 * Disable data pullups. We need to prevent the controller from 294 * Disable data pullups. We need to prevent the controller from
@@ -306,7 +307,7 @@ static void isp1704_charger_work(struct work_struct *data)
306 goto out; 307 goto out;
307 } 308 }
308 309
309 power_supply_changed(&isp->psy); 310 power_supply_changed(isp->psy);
310out: 311out:
311 mutex_unlock(&lock); 312 mutex_unlock(&lock);
312} 313}
@@ -326,8 +327,7 @@ static int isp1704_charger_get_property(struct power_supply *psy,
326 enum power_supply_property psp, 327 enum power_supply_property psp,
327 union power_supply_propval *val) 328 union power_supply_propval *val)
328{ 329{
329 struct isp1704_charger *isp = 330 struct isp1704_charger *isp = power_supply_get_drvdata(psy);
330 container_of(psy, struct isp1704_charger, psy);
331 331
332 switch (psp) { 332 switch (psp) {
333 case POWER_SUPPLY_PROP_PRESENT: 333 case POWER_SUPPLY_PROP_PRESENT:
@@ -403,6 +403,7 @@ static int isp1704_charger_probe(struct platform_device *pdev)
403{ 403{
404 struct isp1704_charger *isp; 404 struct isp1704_charger *isp;
405 int ret = -ENODEV; 405 int ret = -ENODEV;
406 struct power_supply_config psy_cfg = {};
406 407
407 struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev); 408 struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev);
408 struct device_node *np = pdev->dev.of_node; 409 struct device_node *np = pdev->dev.of_node;
@@ -454,15 +455,19 @@ static int isp1704_charger_probe(struct platform_device *pdev)
454 if (ret < 0) 455 if (ret < 0)
455 goto fail1; 456 goto fail1;
456 457
457 isp->psy.name = "isp1704"; 458 isp->psy_desc.name = "isp1704";
458 isp->psy.type = POWER_SUPPLY_TYPE_USB; 459 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB;
459 isp->psy.properties = power_props; 460 isp->psy_desc.properties = power_props;
460 isp->psy.num_properties = ARRAY_SIZE(power_props); 461 isp->psy_desc.num_properties = ARRAY_SIZE(power_props);
461 isp->psy.get_property = isp1704_charger_get_property; 462 isp->psy_desc.get_property = isp1704_charger_get_property;
462 463
463 ret = power_supply_register(isp->dev, &isp->psy, NULL); 464 psy_cfg.drv_data = isp;
464 if (ret) 465
466 isp->psy = power_supply_register(isp->dev, &isp->psy_desc, &psy_cfg);
467 if (IS_ERR(isp->psy)) {
468 ret = PTR_ERR(isp->psy);
465 goto fail1; 469 goto fail1;
470 }
466 471
467 /* 472 /*
468 * REVISIT: using work in order to allow the usb notifications to be 473 * 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)
498 503
499 return 0; 504 return 0;
500fail2: 505fail2:
501 power_supply_unregister(&isp->psy); 506 power_supply_unregister(isp->psy);
502fail1: 507fail1:
503 isp1704_charger_set_power(isp, 0); 508 isp1704_charger_set_power(isp, 0);
504fail0: 509fail0:
@@ -512,7 +517,7 @@ static int isp1704_charger_remove(struct platform_device *pdev)
512 struct isp1704_charger *isp = platform_get_drvdata(pdev); 517 struct isp1704_charger *isp = platform_get_drvdata(pdev);
513 518
514 usb_unregister_notifier(isp->phy, &isp->nb); 519 usb_unregister_notifier(isp->phy, &isp->nb);
515 power_supply_unregister(&isp->psy); 520 power_supply_unregister(isp->psy);
516 isp1704_charger_set_power(isp, 0); 521 isp1704_charger_set_power(isp, 0);
517 522
518 return 0; 523 return 0;
diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c
index 0444434e1927..abdfc21ec13f 100644
--- a/drivers/power/jz4740-battery.c
+++ b/drivers/power/jz4740-battery.c
@@ -46,7 +46,8 @@ struct jz_battery {
46 46
47 struct completion read_completion; 47 struct completion read_completion;
48 48
49 struct power_supply battery; 49 struct power_supply *battery;
50 struct power_supply_desc battery_desc;
50 struct delayed_work work; 51 struct delayed_work work;
51 52
52 struct mutex lock; 53 struct mutex lock;
@@ -54,7 +55,7 @@ struct jz_battery {
54 55
55static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) 56static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy)
56{ 57{
57 return container_of(psy, struct jz_battery, battery); 58 return power_supply_get_drvdata(psy);
58} 59}
59 60
60static irqreturn_t jz_battery_irq_handler(int irq, void *devid) 61static irqreturn_t jz_battery_irq_handler(int irq, void *devid)
@@ -213,7 +214,7 @@ static void jz_battery_update(struct jz_battery *jz_battery)
213 } 214 }
214 215
215 if (has_changed) 216 if (has_changed)
216 power_supply_changed(&jz_battery->battery); 217 power_supply_changed(jz_battery->battery);
217} 218}
218 219
219static enum power_supply_property jz_battery_properties[] = { 220static enum power_supply_property jz_battery_properties[] = {
@@ -242,8 +243,9 @@ static int jz_battery_probe(struct platform_device *pdev)
242{ 243{
243 int ret = 0; 244 int ret = 0;
244 struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data; 245 struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data;
246 struct power_supply_config psy_cfg = {};
245 struct jz_battery *jz_battery; 247 struct jz_battery *jz_battery;
246 struct power_supply *battery; 248 struct power_supply_desc *battery_desc;
247 struct resource *mem; 249 struct resource *mem;
248 250
249 if (!pdata) { 251 if (!pdata) {
@@ -271,14 +273,17 @@ static int jz_battery_probe(struct platform_device *pdev)
271 if (IS_ERR(jz_battery->base)) 273 if (IS_ERR(jz_battery->base))
272 return PTR_ERR(jz_battery->base); 274 return PTR_ERR(jz_battery->base);
273 275
274 battery = &jz_battery->battery; 276 battery_desc = &jz_battery->battery_desc;
275 battery->name = pdata->info.name; 277 battery_desc->name = pdata->info.name;
276 battery->type = POWER_SUPPLY_TYPE_BATTERY; 278 battery_desc->type = POWER_SUPPLY_TYPE_BATTERY;
277 battery->properties = jz_battery_properties; 279 battery_desc->properties = jz_battery_properties;
278 battery->num_properties = ARRAY_SIZE(jz_battery_properties); 280 battery_desc->num_properties = ARRAY_SIZE(jz_battery_properties);
279 battery->get_property = jz_battery_get_property; 281 battery_desc->get_property = jz_battery_get_property;
280 battery->external_power_changed = jz_battery_external_power_changed; 282 battery_desc->external_power_changed =
281 battery->use_for_apm = 1; 283 jz_battery_external_power_changed;
284 battery_desc->use_for_apm = 1;
285
286 psy_cfg.drv_data = jz_battery;
282 287
283 jz_battery->pdata = pdata; 288 jz_battery->pdata = pdata;
284 jz_battery->pdev = pdev; 289 jz_battery->pdev = pdev;
@@ -330,9 +335,11 @@ static int jz_battery_probe(struct platform_device *pdev)
330 else 335 else
331 jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0); 336 jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0);
332 337
333 ret = power_supply_register(&pdev->dev, &jz_battery->battery, NULL); 338 jz_battery->battery = power_supply_register(&pdev->dev, battery_desc,
334 if (ret) { 339 &psy_cfg);
340 if (IS_ERR(jz_battery->battery)) {
335 dev_err(&pdev->dev, "power supply battery register failed.\n"); 341 dev_err(&pdev->dev, "power supply battery register failed.\n");
342 ret = PTR_ERR(jz_battery->battery);
336 goto err_free_charge_irq; 343 goto err_free_charge_irq;
337 } 344 }
338 345
@@ -364,7 +371,7 @@ static int jz_battery_remove(struct platform_device *pdev)
364 gpio_free(jz_battery->pdata->gpio_charge); 371 gpio_free(jz_battery->pdata->gpio_charge);
365 } 372 }
366 373
367 power_supply_unregister(&jz_battery->battery); 374 power_supply_unregister(jz_battery->battery);
368 375
369 free_irq(jz_battery->irq, jz_battery); 376 free_irq(jz_battery->irq, jz_battery);
370 377
diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c
index 1f71af7a3811..7e741f1d3cd5 100644
--- a/drivers/power/lp8727_charger.c
+++ b/drivers/power/lp8727_charger.c
@@ -80,9 +80,9 @@ enum lp8727_die_temp {
80}; 80};
81 81
82struct lp8727_psy { 82struct lp8727_psy {
83 struct power_supply ac; 83 struct power_supply *ac;
84 struct power_supply usb; 84 struct power_supply *usb;
85 struct power_supply batt; 85 struct power_supply *batt;
86}; 86};
87 87
88struct lp8727_chg { 88struct lp8727_chg {
@@ -242,9 +242,9 @@ static void lp8727_delayed_func(struct work_struct *_work)
242 lp8727_id_detection(pchg, idno, vbus); 242 lp8727_id_detection(pchg, idno, vbus);
243 lp8727_enable_chgdet(pchg); 243 lp8727_enable_chgdet(pchg);
244 244
245 power_supply_changed(&pchg->psy->ac); 245 power_supply_changed(pchg->psy->ac);
246 power_supply_changed(&pchg->psy->usb); 246 power_supply_changed(pchg->psy->usb);
247 power_supply_changed(&pchg->psy->batt); 247 power_supply_changed(pchg->psy->batt);
248} 248}
249 249
250static irqreturn_t lp8727_isr_func(int irq, void *ptr) 250static irqreturn_t lp8727_isr_func(int irq, void *ptr)
@@ -311,12 +311,12 @@ static int lp8727_charger_get_property(struct power_supply *psy,
311 enum power_supply_property psp, 311 enum power_supply_property psp,
312 union power_supply_propval *val) 312 union power_supply_propval *val)
313{ 313{
314 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent); 314 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent);
315 315
316 if (psp != POWER_SUPPLY_PROP_ONLINE) 316 if (psp != POWER_SUPPLY_PROP_ONLINE)
317 return -EINVAL; 317 return -EINVAL;
318 318
319 val->intval = lp8727_is_charger_attached(psy->name, pchg->devid); 319 val->intval = lp8727_is_charger_attached(psy->desc->name, pchg->devid);
320 320
321 return 0; 321 return 0;
322} 322}
@@ -337,14 +337,14 @@ static int lp8727_battery_get_property(struct power_supply *psy,
337 enum power_supply_property psp, 337 enum power_supply_property psp,
338 union power_supply_propval *val) 338 union power_supply_propval *val)
339{ 339{
340 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent); 340 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent);
341 struct lp8727_platform_data *pdata = pchg->pdata; 341 struct lp8727_platform_data *pdata = pchg->pdata;
342 enum lp8727_die_temp temp; 342 enum lp8727_die_temp temp;
343 u8 read; 343 u8 read;
344 344
345 switch (psp) { 345 switch (psp) {
346 case POWER_SUPPLY_PROP_STATUS: 346 case POWER_SUPPLY_PROP_STATUS:
347 if (!lp8727_is_charger_attached(psy->name, pchg->devid)) { 347 if (!lp8727_is_charger_attached(psy->desc->name, pchg->devid)) {
348 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 348 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
349 return 0; 349 return 0;
350 } 350 }
@@ -400,13 +400,13 @@ static int lp8727_battery_get_property(struct power_supply *psy,
400 400
401static void lp8727_charger_changed(struct power_supply *psy) 401static void lp8727_charger_changed(struct power_supply *psy)
402{ 402{
403 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent); 403 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev.parent);
404 u8 eoc_level; 404 u8 eoc_level;
405 u8 ichg; 405 u8 ichg;
406 u8 val; 406 u8 val;
407 407
408 /* skip if no charger exists */ 408 /* skip if no charger exists */
409 if (!lp8727_is_charger_attached(psy->name, pchg->devid)) 409 if (!lp8727_is_charger_attached(psy->desc->name, pchg->devid))
410 return; 410 return;
411 411
412 /* update charging parameters */ 412 /* update charging parameters */
@@ -418,6 +418,31 @@ static void lp8727_charger_changed(struct power_supply *psy)
418 } 418 }
419} 419}
420 420
421static const struct power_supply_desc lp8727_ac_desc = {
422 .name = "ac",
423 .type = POWER_SUPPLY_TYPE_MAINS,
424 .properties = lp8727_charger_prop,
425 .num_properties = ARRAY_SIZE(lp8727_charger_prop),
426 .get_property = lp8727_charger_get_property,
427};
428
429static const struct power_supply_desc lp8727_usb_desc = {
430 .name = "usb",
431 .type = POWER_SUPPLY_TYPE_USB,
432 .properties = lp8727_charger_prop,
433 .num_properties = ARRAY_SIZE(lp8727_charger_prop),
434 .get_property = lp8727_charger_get_property,
435};
436
437static const struct power_supply_desc lp8727_batt_desc = {
438 .name = "main_batt",
439 .type = POWER_SUPPLY_TYPE_BATTERY,
440 .properties = lp8727_battery_prop,
441 .num_properties = ARRAY_SIZE(lp8727_battery_prop),
442 .get_property = lp8727_battery_get_property,
443 .external_power_changed = lp8727_charger_changed,
444};
445
421static int lp8727_register_psy(struct lp8727_chg *pchg) 446static int lp8727_register_psy(struct lp8727_chg *pchg)
422{ 447{
423 struct power_supply_config psy_cfg = {}; /* Only for ac and usb */ 448 struct power_supply_config psy_cfg = {}; /* Only for ac and usb */
@@ -432,40 +457,25 @@ static int lp8727_register_psy(struct lp8727_chg *pchg)
432 psy_cfg.supplied_to = battery_supplied_to; 457 psy_cfg.supplied_to = battery_supplied_to;
433 psy_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to); 458 psy_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to);
434 459
435 psy->ac.name = "ac"; 460 psy->ac = power_supply_register(pchg->dev, &lp8727_ac_desc, &psy_cfg);
436 psy->ac.type = POWER_SUPPLY_TYPE_MAINS; 461 if (IS_ERR(psy->ac))
437 psy->ac.properties = lp8727_charger_prop;
438 psy->ac.num_properties = ARRAY_SIZE(lp8727_charger_prop);
439 psy->ac.get_property = lp8727_charger_get_property;
440
441 if (power_supply_register(pchg->dev, &psy->ac, &psy_cfg))
442 goto err_psy_ac; 462 goto err_psy_ac;
443 463
444 psy->usb.name = "usb"; 464 psy->usb = power_supply_register(pchg->dev, &lp8727_usb_desc,
445 psy->usb.type = POWER_SUPPLY_TYPE_USB; 465 &psy_cfg);
446 psy->usb.properties = lp8727_charger_prop; 466 if (IS_ERR(psy->usb))
447 psy->usb.num_properties = ARRAY_SIZE(lp8727_charger_prop);
448 psy->usb.get_property = lp8727_charger_get_property;
449
450 if (power_supply_register(pchg->dev, &psy->usb, &psy_cfg))
451 goto err_psy_usb; 467 goto err_psy_usb;
452 468
453 psy->batt.name = "main_batt"; 469 psy->batt = power_supply_register(pchg->dev, &lp8727_batt_desc, NULL);
454 psy->batt.type = POWER_SUPPLY_TYPE_BATTERY; 470 if (IS_ERR(psy->batt))
455 psy->batt.properties = lp8727_battery_prop;
456 psy->batt.num_properties = ARRAY_SIZE(lp8727_battery_prop);
457 psy->batt.get_property = lp8727_battery_get_property;
458 psy->batt.external_power_changed = lp8727_charger_changed;
459
460 if (power_supply_register(pchg->dev, &psy->batt, NULL))
461 goto err_psy_batt; 471 goto err_psy_batt;
462 472
463 return 0; 473 return 0;
464 474
465err_psy_batt: 475err_psy_batt:
466 power_supply_unregister(&psy->usb); 476 power_supply_unregister(psy->usb);
467err_psy_usb: 477err_psy_usb:
468 power_supply_unregister(&psy->ac); 478 power_supply_unregister(psy->ac);
469err_psy_ac: 479err_psy_ac:
470 return -EPERM; 480 return -EPERM;
471} 481}
@@ -477,9 +487,9 @@ static void lp8727_unregister_psy(struct lp8727_chg *pchg)
477 if (!psy) 487 if (!psy)
478 return; 488 return;
479 489
480 power_supply_unregister(&psy->ac); 490 power_supply_unregister(psy->ac);
481 power_supply_unregister(&psy->usb); 491 power_supply_unregister(psy->usb);
482 power_supply_unregister(&psy->batt); 492 power_supply_unregister(psy->batt);
483} 493}
484 494
485#ifdef CONFIG_OF 495#ifdef CONFIG_OF
diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
index 8e4d228519c1..f5a48fd68b01 100644
--- a/drivers/power/lp8788-charger.c
+++ b/drivers/power/lp8788-charger.c
@@ -105,8 +105,8 @@ struct lp8788_chg_irq {
105 */ 105 */
106struct lp8788_charger { 106struct lp8788_charger {
107 struct lp8788 *lp; 107 struct lp8788 *lp;
108 struct power_supply charger; 108 struct power_supply *charger;
109 struct power_supply battery; 109 struct power_supply *battery;
110 struct work_struct charger_work; 110 struct work_struct charger_work;
111 struct iio_channel *chan[LP8788_NUM_CHG_ADC]; 111 struct iio_channel *chan[LP8788_NUM_CHG_ADC];
112 struct lp8788_chg_irq irqs[LP8788_MAX_CHG_IRQS]; 112 struct lp8788_chg_irq irqs[LP8788_MAX_CHG_IRQS];
@@ -148,7 +148,7 @@ static int lp8788_charger_get_property(struct power_supply *psy,
148 enum power_supply_property psp, 148 enum power_supply_property psp,
149 union power_supply_propval *val) 149 union power_supply_propval *val)
150{ 150{
151 struct lp8788_charger *pchg = dev_get_drvdata(psy->dev->parent); 151 struct lp8788_charger *pchg = dev_get_drvdata(psy->dev.parent);
152 u8 read; 152 u8 read;
153 153
154 switch (psp) { 154 switch (psp) {
@@ -337,7 +337,7 @@ static int lp8788_battery_get_property(struct power_supply *psy,
337 enum power_supply_property psp, 337 enum power_supply_property psp,
338 union power_supply_propval *val) 338 union power_supply_propval *val)
339{ 339{
340 struct lp8788_charger *pchg = dev_get_drvdata(psy->dev->parent); 340 struct lp8788_charger *pchg = dev_get_drvdata(psy->dev.parent);
341 341
342 switch (psp) { 342 switch (psp) {
343 case POWER_SUPPLY_PROP_STATUS: 343 case POWER_SUPPLY_PROP_STATUS:
@@ -397,31 +397,40 @@ static int lp8788_update_charger_params(struct platform_device *pdev,
397 return 0; 397 return 0;
398} 398}
399 399
400static const struct power_supply_desc lp8788_psy_charger_desc = {
401 .name = LP8788_CHARGER_NAME,
402 .type = POWER_SUPPLY_TYPE_MAINS,
403 .properties = lp8788_charger_prop,
404 .num_properties = ARRAY_SIZE(lp8788_charger_prop),
405 .get_property = lp8788_charger_get_property,
406};
407
408static const struct power_supply_desc lp8788_psy_battery_desc = {
409 .name = LP8788_BATTERY_NAME,
410 .type = POWER_SUPPLY_TYPE_BATTERY,
411 .properties = lp8788_battery_prop,
412 .num_properties = ARRAY_SIZE(lp8788_battery_prop),
413 .get_property = lp8788_battery_get_property,
414};
415
400static int lp8788_psy_register(struct platform_device *pdev, 416static int lp8788_psy_register(struct platform_device *pdev,
401 struct lp8788_charger *pchg) 417 struct lp8788_charger *pchg)
402{ 418{
403 struct power_supply_config charger_cfg = {}; 419 struct power_supply_config charger_cfg = {};
404 420
405 pchg->charger.name = LP8788_CHARGER_NAME;
406 pchg->charger.type = POWER_SUPPLY_TYPE_MAINS;
407 pchg->charger.properties = lp8788_charger_prop;
408 pchg->charger.num_properties = ARRAY_SIZE(lp8788_charger_prop);
409 pchg->charger.get_property = lp8788_charger_get_property;
410
411 charger_cfg.supplied_to = battery_supplied_to; 421 charger_cfg.supplied_to = battery_supplied_to;
412 charger_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to); 422 charger_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to);
413 423
414 if (power_supply_register(&pdev->dev, &pchg->charger, &charger_cfg)) 424 pchg->charger = power_supply_register(&pdev->dev,
425 &lp8788_psy_charger_desc,
426 &charger_cfg);
427 if (IS_ERR(pchg->charger))
415 return -EPERM; 428 return -EPERM;
416 429
417 pchg->battery.name = LP8788_BATTERY_NAME; 430 pchg->battery = power_supply_register(&pdev->dev,
418 pchg->battery.type = POWER_SUPPLY_TYPE_BATTERY; 431 &lp8788_psy_battery_desc, NULL);
419 pchg->battery.properties = lp8788_battery_prop; 432 if (IS_ERR(pchg->battery)) {
420 pchg->battery.num_properties = ARRAY_SIZE(lp8788_battery_prop); 433 power_supply_unregister(pchg->charger);
421 pchg->battery.get_property = lp8788_battery_get_property;
422
423 if (power_supply_register(&pdev->dev, &pchg->battery, NULL)) {
424 power_supply_unregister(&pchg->charger);
425 return -EPERM; 434 return -EPERM;
426 } 435 }
427 436
@@ -430,8 +439,8 @@ static int lp8788_psy_register(struct platform_device *pdev,
430 439
431static void lp8788_psy_unregister(struct lp8788_charger *pchg) 440static void lp8788_psy_unregister(struct lp8788_charger *pchg)
432{ 441{
433 power_supply_unregister(&pchg->battery); 442 power_supply_unregister(pchg->battery);
434 power_supply_unregister(&pchg->charger); 443 power_supply_unregister(pchg->charger);
435} 444}
436 445
437static void lp8788_charger_event(struct work_struct *work) 446static void lp8788_charger_event(struct work_struct *work)
@@ -475,8 +484,8 @@ static irqreturn_t lp8788_charger_irq_thread(int virq, void *ptr)
475 case LP8788_INT_EOC: 484 case LP8788_INT_EOC:
476 case LP8788_INT_BATT_LOW: 485 case LP8788_INT_BATT_LOW:
477 case LP8788_INT_NO_BATT: 486 case LP8788_INT_NO_BATT:
478 power_supply_changed(&pchg->charger); 487 power_supply_changed(pchg->charger);
479 power_supply_changed(&pchg->battery); 488 power_supply_changed(pchg->battery);
480 break; 489 break;
481 default: 490 default:
482 break; 491 break;
diff --git a/drivers/power/ltc2941-battery-gauge.c b/drivers/power/ltc2941-battery-gauge.c
index 9bc545393ef8..daeb0860736c 100644
--- a/drivers/power/ltc2941-battery-gauge.c
+++ b/drivers/power/ltc2941-battery-gauge.c
@@ -59,7 +59,8 @@ enum ltc294x_reg {
59 59
60struct ltc294x_info { 60struct ltc294x_info {
61 struct i2c_client *client; /* I2C Client pointer */ 61 struct i2c_client *client; /* I2C Client pointer */
62 struct power_supply supply; /* Supply pointer */ 62 struct power_supply *supply; /* Supply pointer */
63 struct power_supply_desc supply_desc; /* Supply description */
63 struct delayed_work work; /* Work scheduler */ 64 struct delayed_work work; /* Work scheduler */
64 int num_regs; /* Number of registers (chip type) */ 65 int num_regs; /* Number of registers (chip type) */
65 int id; /* Identifier of ltc294x chip */ 66 int id; /* Identifier of ltc294x chip */
@@ -294,8 +295,7 @@ static int ltc294x_get_property(struct power_supply *psy,
294 enum power_supply_property prop, 295 enum power_supply_property prop,
295 union power_supply_propval *val) 296 union power_supply_propval *val)
296{ 297{
297 struct ltc294x_info *info = 298 struct ltc294x_info *info = power_supply_get_drvdata(psy);
298 container_of(psy, struct ltc294x_info, supply);
299 299
300 switch (prop) { 300 switch (prop) {
301 case POWER_SUPPLY_PROP_CHARGE_NOW: 301 case POWER_SUPPLY_PROP_CHARGE_NOW:
@@ -317,8 +317,7 @@ static int ltc294x_set_property(struct power_supply *psy,
317 enum power_supply_property psp, 317 enum power_supply_property psp,
318 const union power_supply_propval *val) 318 const union power_supply_propval *val)
319{ 319{
320 struct ltc294x_info *info = 320 struct ltc294x_info *info = power_supply_get_drvdata(psy);
321 container_of(psy, struct ltc294x_info, supply);
322 321
323 switch (psp) { 322 switch (psp) {
324 case POWER_SUPPLY_PROP_CHARGE_NOW: 323 case POWER_SUPPLY_PROP_CHARGE_NOW:
@@ -345,7 +344,7 @@ static void ltc294x_update(struct ltc294x_info *info)
345 344
346 if (charge != info->charge) { 345 if (charge != info->charge) {
347 info->charge = charge; 346 info->charge = charge;
348 power_supply_changed(&info->supply); 347 power_supply_changed(info->supply);
349 } 348 }
350} 349}
351 350
@@ -371,8 +370,8 @@ static int ltc294x_i2c_remove(struct i2c_client *client)
371 struct ltc294x_info *info = i2c_get_clientdata(client); 370 struct ltc294x_info *info = i2c_get_clientdata(client);
372 371
373 cancel_delayed_work(&info->work); 372 cancel_delayed_work(&info->work);
374 power_supply_unregister(&info->supply); 373 power_supply_unregister(info->supply);
375 kfree(info->supply.name); 374 kfree(info->supply_desc.name);
376 mutex_lock(&ltc294x_lock); 375 mutex_lock(&ltc294x_lock);
377 idr_remove(&ltc294x_id, info->id); 376 idr_remove(&ltc294x_id, info->id);
378 mutex_unlock(&ltc294x_lock); 377 mutex_unlock(&ltc294x_lock);
@@ -382,6 +381,7 @@ static int ltc294x_i2c_remove(struct i2c_client *client)
382static int ltc294x_i2c_probe(struct i2c_client *client, 381static int ltc294x_i2c_probe(struct i2c_client *client,
383 const struct i2c_device_id *id) 382 const struct i2c_device_id *id)
384{ 383{
384 struct power_supply_config psy_cfg = {};
385 struct ltc294x_info *info; 385 struct ltc294x_info *info;
386 int ret; 386 int ret;
387 int num; 387 int num;
@@ -406,8 +406,9 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
406 i2c_set_clientdata(client, info); 406 i2c_set_clientdata(client, info);
407 407
408 info->num_regs = id->driver_data; 408 info->num_regs = id->driver_data;
409 info->supply.name = kasprintf(GFP_KERNEL, "%s-%d", client->name, num); 409 info->supply_desc.name = kasprintf(GFP_KERNEL, "%s-%d", client->name,
410 if (!info->supply.name) { 410 num);
411 if (!info->supply_desc.name) {
411 ret = -ENOMEM; 412 ret = -ENOMEM;
412 goto fail_name; 413 goto fail_name;
413 } 414 }
@@ -446,24 +447,26 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
446 447
447 info->client = client; 448 info->client = client;
448 info->id = num; 449 info->id = num;
449 info->supply.type = POWER_SUPPLY_TYPE_BATTERY; 450 info->supply_desc.type = POWER_SUPPLY_TYPE_BATTERY;
450 info->supply.properties = ltc294x_properties; 451 info->supply_desc.properties = ltc294x_properties;
451 if (info->num_regs >= LTC294X_REG_TEMPERATURE_LSB) 452 if (info->num_regs >= LTC294X_REG_TEMPERATURE_LSB)
452 info->supply.num_properties = 453 info->supply_desc.num_properties =
453 ARRAY_SIZE(ltc294x_properties); 454 ARRAY_SIZE(ltc294x_properties);
454 else if (info->num_regs >= LTC294X_REG_CURRENT_LSB) 455 else if (info->num_regs >= LTC294X_REG_CURRENT_LSB)
455 info->supply.num_properties = 456 info->supply_desc.num_properties =
456 ARRAY_SIZE(ltc294x_properties) - 1; 457 ARRAY_SIZE(ltc294x_properties) - 1;
457 else if (info->num_regs >= LTC294X_REG_VOLTAGE_LSB) 458 else if (info->num_regs >= LTC294X_REG_VOLTAGE_LSB)
458 info->supply.num_properties = 459 info->supply_desc.num_properties =
459 ARRAY_SIZE(ltc294x_properties) - 2; 460 ARRAY_SIZE(ltc294x_properties) - 2;
460 else 461 else
461 info->supply.num_properties = 462 info->supply_desc.num_properties =
462 ARRAY_SIZE(ltc294x_properties) - 3; 463 ARRAY_SIZE(ltc294x_properties) - 3;
463 info->supply.get_property = ltc294x_get_property; 464 info->supply_desc.get_property = ltc294x_get_property;
464 info->supply.set_property = ltc294x_set_property; 465 info->supply_desc.set_property = ltc294x_set_property;
465 info->supply.property_is_writeable = ltc294x_property_is_writeable; 466 info->supply_desc.property_is_writeable = ltc294x_property_is_writeable;
466 info->supply.external_power_changed = NULL; 467 info->supply_desc.external_power_changed = NULL;
468
469 psy_cfg.drv_data = info;
467 470
468 INIT_DELAYED_WORK(&info->work, ltc294x_work); 471 INIT_DELAYED_WORK(&info->work, ltc294x_work);
469 472
@@ -473,9 +476,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
473 goto fail_comm; 476 goto fail_comm;
474 } 477 }
475 478
476 ret = power_supply_register(&client->dev, &info->supply, NULL); 479 info->supply = power_supply_register(&client->dev, &info->supply_desc,
477 if (ret) { 480 &psy_cfg);
481 if (IS_ERR(info->supply)) {
478 dev_err(&client->dev, "failed to register ltc2941\n"); 482 dev_err(&client->dev, "failed to register ltc2941\n");
483 ret = PTR_ERR(info->supply);
479 goto fail_register; 484 goto fail_register;
480 } else { 485 } else {
481 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ); 486 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
@@ -484,7 +489,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
484 return 0; 489 return 0;
485 490
486fail_register: 491fail_register:
487 kfree(info->supply.name); 492 kfree(info->supply_desc.name);
488fail_comm: 493fail_comm:
489fail_name: 494fail_name:
490fail_info: 495fail_info:
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index c5f2a535c81a..a36bcaf62dd4 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -22,9 +22,9 @@
22#include <linux/mfd/max14577.h> 22#include <linux/mfd/max14577.h>
23 23
24struct max14577_charger { 24struct max14577_charger {
25 struct device *dev; 25 struct device *dev;
26 struct max14577 *max14577; 26 struct max14577 *max14577;
27 struct power_supply charger; 27 struct power_supply *charger;
28 28
29 struct max14577_charger_platform_data *pdata; 29 struct max14577_charger_platform_data *pdata;
30}; 30};
@@ -421,9 +421,7 @@ static int max14577_charger_get_property(struct power_supply *psy,
421 enum power_supply_property psp, 421 enum power_supply_property psp,
422 union power_supply_propval *val) 422 union power_supply_propval *val)
423{ 423{
424 struct max14577_charger *chg = container_of(psy, 424 struct max14577_charger *chg = power_supply_get_drvdata(psy);
425 struct max14577_charger,
426 charger);
427 int ret = 0; 425 int ret = 0;
428 426
429 switch (psp) { 427 switch (psp) {
@@ -456,6 +454,14 @@ static int max14577_charger_get_property(struct power_supply *psy,
456 return ret; 454 return ret;
457} 455}
458 456
457static const struct power_supply_desc max14577_charger_desc = {
458 .name = "max14577-charger",
459 .type = POWER_SUPPLY_TYPE_BATTERY,
460 .properties = max14577_charger_props,
461 .num_properties = ARRAY_SIZE(max14577_charger_props),
462 .get_property = max14577_charger_get_property,
463};
464
459#ifdef CONFIG_OF 465#ifdef CONFIG_OF
460static struct max14577_charger_platform_data *max14577_charger_dt_init( 466static struct max14577_charger_platform_data *max14577_charger_dt_init(
461 struct platform_device *pdev) 467 struct platform_device *pdev)
@@ -563,6 +569,7 @@ static DEVICE_ATTR(fast_charge_timer, S_IRUGO | S_IWUSR,
563static int max14577_charger_probe(struct platform_device *pdev) 569static int max14577_charger_probe(struct platform_device *pdev)
564{ 570{
565 struct max14577_charger *chg; 571 struct max14577_charger *chg;
572 struct power_supply_config psy_cfg = {};
566 struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); 573 struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
567 int ret; 574 int ret;
568 575
@@ -582,21 +589,18 @@ static int max14577_charger_probe(struct platform_device *pdev)
582 if (ret) 589 if (ret)
583 return ret; 590 return ret;
584 591
585 chg->charger.name = "max14577-charger",
586 chg->charger.type = POWER_SUPPLY_TYPE_BATTERY,
587 chg->charger.properties = max14577_charger_props,
588 chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props),
589 chg->charger.get_property = max14577_charger_get_property,
590
591 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); 592 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer);
592 if (ret) { 593 if (ret) {
593 dev_err(&pdev->dev, "failed: create sysfs entry\n"); 594 dev_err(&pdev->dev, "failed: create sysfs entry\n");
594 return ret; 595 return ret;
595 } 596 }
596 597
597 ret = power_supply_register(&pdev->dev, &chg->charger, NULL); 598 psy_cfg.drv_data = chg;
598 if (ret) { 599 chg->charger = power_supply_register(&pdev->dev, &max14577_charger_desc,
600 &psy_cfg);
601 if (IS_ERR(chg->charger)) {
599 dev_err(&pdev->dev, "failed: power supply register\n"); 602 dev_err(&pdev->dev, "failed: power supply register\n");
603 ret = PTR_ERR(chg->charger);
600 goto err; 604 goto err;
601 } 605 }
602 606
@@ -617,7 +621,7 @@ static int max14577_charger_remove(struct platform_device *pdev)
617 struct max14577_charger *chg = platform_get_drvdata(pdev); 621 struct max14577_charger *chg = platform_get_drvdata(pdev);
618 622
619 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); 623 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
620 power_supply_unregister(&chg->charger); 624 power_supply_unregister(chg->charger);
621 625
622 return 0; 626 return 0;
623} 627}
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index d36b2f6c2053..8689c80202b5 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -40,7 +40,7 @@
40struct max17040_chip { 40struct max17040_chip {
41 struct i2c_client *client; 41 struct i2c_client *client;
42 struct delayed_work work; 42 struct delayed_work work;
43 struct power_supply battery; 43 struct power_supply *battery;
44 struct max17040_platform_data *pdata; 44 struct max17040_platform_data *pdata;
45 45
46 /* State Of Connect */ 46 /* State Of Connect */
@@ -57,8 +57,7 @@ static int max17040_get_property(struct power_supply *psy,
57 enum power_supply_property psp, 57 enum power_supply_property psp,
58 union power_supply_propval *val) 58 union power_supply_propval *val)
59{ 59{
60 struct max17040_chip *chip = container_of(psy, 60 struct max17040_chip *chip = power_supply_get_drvdata(psy);
61 struct max17040_chip, battery);
62 61
63 switch (psp) { 62 switch (psp) {
64 case POWER_SUPPLY_PROP_STATUS: 63 case POWER_SUPPLY_PROP_STATUS:
@@ -199,12 +198,20 @@ static enum power_supply_property max17040_battery_props[] = {
199 POWER_SUPPLY_PROP_CAPACITY, 198 POWER_SUPPLY_PROP_CAPACITY,
200}; 199};
201 200
201static const struct power_supply_desc max17040_battery_desc = {
202 .name = "battery",
203 .type = POWER_SUPPLY_TYPE_BATTERY,
204 .get_property = max17040_get_property,
205 .properties = max17040_battery_props,
206 .num_properties = ARRAY_SIZE(max17040_battery_props),
207};
208
202static int max17040_probe(struct i2c_client *client, 209static int max17040_probe(struct i2c_client *client,
203 const struct i2c_device_id *id) 210 const struct i2c_device_id *id)
204{ 211{
205 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 212 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
213 struct power_supply_config psy_cfg = {};
206 struct max17040_chip *chip; 214 struct max17040_chip *chip;
207 int ret;
208 215
209 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 216 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
210 return -EIO; 217 return -EIO;
@@ -217,17 +224,13 @@ static int max17040_probe(struct i2c_client *client,
217 chip->pdata = client->dev.platform_data; 224 chip->pdata = client->dev.platform_data;
218 225
219 i2c_set_clientdata(client, chip); 226 i2c_set_clientdata(client, chip);
227 psy_cfg.drv_data = chip;
220 228
221 chip->battery.name = "battery"; 229 chip->battery = power_supply_register(&client->dev,
222 chip->battery.type = POWER_SUPPLY_TYPE_BATTERY; 230 &max17040_battery_desc, &psy_cfg);
223 chip->battery.get_property = max17040_get_property; 231 if (IS_ERR(chip->battery)) {
224 chip->battery.properties = max17040_battery_props;
225 chip->battery.num_properties = ARRAY_SIZE(max17040_battery_props);
226
227 ret = power_supply_register(&client->dev, &chip->battery, NULL);
228 if (ret) {
229 dev_err(&client->dev, "failed: power supply register\n"); 232 dev_err(&client->dev, "failed: power supply register\n");
230 return ret; 233 return PTR_ERR(chip->battery);
231 } 234 }
232 235
233 max17040_reset(client); 236 max17040_reset(client);
@@ -244,7 +247,7 @@ static int max17040_remove(struct i2c_client *client)
244{ 247{
245 struct max17040_chip *chip = i2c_get_clientdata(client); 248 struct max17040_chip *chip = i2c_get_clientdata(client);
246 249
247 power_supply_unregister(&chip->battery); 250 power_supply_unregister(chip->battery);
248 cancel_delayed_work(&chip->work); 251 cancel_delayed_work(&chip->work);
249 return 0; 252 return 0;
250} 253}
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index b1ebbc3b8640..e5645ea6f9d8 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -69,7 +69,7 @@
69struct max17042_chip { 69struct max17042_chip {
70 struct i2c_client *client; 70 struct i2c_client *client;
71 struct regmap *regmap; 71 struct regmap *regmap;
72 struct power_supply battery; 72 struct power_supply *battery;
73 enum max170xx_chip_type chip_type; 73 enum max170xx_chip_type chip_type;
74 struct max17042_platform_data *pdata; 74 struct max17042_platform_data *pdata;
75 struct work_struct work; 75 struct work_struct work;
@@ -96,8 +96,7 @@ static int max17042_get_property(struct power_supply *psy,
96 enum power_supply_property psp, 96 enum power_supply_property psp,
97 union power_supply_propval *val) 97 union power_supply_propval *val)
98{ 98{
99 struct max17042_chip *chip = container_of(psy, 99 struct max17042_chip *chip = power_supply_get_drvdata(psy);
100 struct max17042_chip, battery);
101 struct regmap *map = chip->regmap; 100 struct regmap *map = chip->regmap;
102 int ret; 101 int ret;
103 u32 data; 102 u32 data;
@@ -602,7 +601,7 @@ static irqreturn_t max17042_thread_handler(int id, void *dev)
602 max17042_set_soc_threshold(chip, 1); 601 max17042_set_soc_threshold(chip, 1);
603 } 602 }
604 603
605 power_supply_changed(&chip->battery); 604 power_supply_changed(chip->battery);
606 return IRQ_HANDLED; 605 return IRQ_HANDLED;
607} 606}
608 607
@@ -662,10 +661,28 @@ static const struct regmap_config max17042_regmap_config = {
662 .val_format_endian = REGMAP_ENDIAN_NATIVE, 661 .val_format_endian = REGMAP_ENDIAN_NATIVE,
663}; 662};
664 663
664static const struct power_supply_desc max17042_psy_desc = {
665 .name = "max170xx_battery",
666 .type = POWER_SUPPLY_TYPE_BATTERY,
667 .get_property = max17042_get_property,
668 .properties = max17042_battery_props,
669 .num_properties = ARRAY_SIZE(max17042_battery_props),
670};
671
672static const struct power_supply_desc max17042_no_current_sense_psy_desc = {
673 .name = "max170xx_battery",
674 .type = POWER_SUPPLY_TYPE_BATTERY,
675 .get_property = max17042_get_property,
676 .properties = max17042_battery_props,
677 .num_properties = ARRAY_SIZE(max17042_battery_props) - 2,
678};
679
665static int max17042_probe(struct i2c_client *client, 680static int max17042_probe(struct i2c_client *client,
666 const struct i2c_device_id *id) 681 const struct i2c_device_id *id)
667{ 682{
668 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 683 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
684 const struct power_supply_desc *max17042_desc = &max17042_psy_desc;
685 struct power_supply_config psy_cfg = {};
669 struct max17042_chip *chip; 686 struct max17042_chip *chip;
670 int ret; 687 int ret;
671 int i; 688 int i;
@@ -692,6 +709,7 @@ static int max17042_probe(struct i2c_client *client,
692 } 709 }
693 710
694 i2c_set_clientdata(client, chip); 711 i2c_set_clientdata(client, chip);
712 psy_cfg.drv_data = chip;
695 713
696 regmap_read(chip->regmap, MAX17042_DevName, &val); 714 regmap_read(chip->regmap, MAX17042_DevName, &val);
697 if (val == MAX17042_IC_VERSION) { 715 if (val == MAX17042_IC_VERSION) {
@@ -705,16 +723,10 @@ static int max17042_probe(struct i2c_client *client,
705 return -EIO; 723 return -EIO;
706 } 724 }
707 725
708 chip->battery.name = "max170xx_battery";
709 chip->battery.type = POWER_SUPPLY_TYPE_BATTERY;
710 chip->battery.get_property = max17042_get_property;
711 chip->battery.properties = max17042_battery_props;
712 chip->battery.num_properties = ARRAY_SIZE(max17042_battery_props);
713
714 /* When current is not measured, 726 /* When current is not measured,
715 * CURRENT_NOW and CURRENT_AVG properties should be invisible. */ 727 * CURRENT_NOW and CURRENT_AVG properties should be invisible. */
716 if (!chip->pdata->enable_current_sense) 728 if (!chip->pdata->enable_current_sense)
717 chip->battery.num_properties -= 2; 729 max17042_desc = &max17042_no_current_sense_psy_desc;
718 730
719 if (chip->pdata->r_sns == 0) 731 if (chip->pdata->r_sns == 0)
720 chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; 732 chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
@@ -731,17 +743,18 @@ static int max17042_probe(struct i2c_client *client,
731 regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); 743 regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007);
732 } 744 }
733 745
734 ret = power_supply_register(&client->dev, &chip->battery, NULL); 746 chip->battery = power_supply_register(&client->dev, max17042_desc,
735 if (ret) { 747 &psy_cfg);
748 if (IS_ERR(chip->battery)) {
736 dev_err(&client->dev, "failed: power supply register\n"); 749 dev_err(&client->dev, "failed: power supply register\n");
737 return ret; 750 return PTR_ERR(chip->battery);
738 } 751 }
739 752
740 if (client->irq) { 753 if (client->irq) {
741 ret = request_threaded_irq(client->irq, NULL, 754 ret = request_threaded_irq(client->irq, NULL,
742 max17042_thread_handler, 755 max17042_thread_handler,
743 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 756 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
744 chip->battery.name, chip); 757 chip->battery->desc->name, chip);
745 if (!ret) { 758 if (!ret) {
746 regmap_update_bits(chip->regmap, MAX17042_CONFIG, 759 regmap_update_bits(chip->regmap, MAX17042_CONFIG,
747 CONFIG_ALRT_BIT_ENBL, 760 CONFIG_ALRT_BIT_ENBL,
@@ -771,7 +784,7 @@ static int max17042_remove(struct i2c_client *client)
771 784
772 if (client->irq) 785 if (client->irq)
773 free_irq(client->irq, chip); 786 free_irq(client->irq, chip);
774 power_supply_unregister(&chip->battery); 787 power_supply_unregister(chip->battery);
775 return 0; 788 return 0;
776} 789}
777 790
diff --git a/drivers/power/max77693_charger.c b/drivers/power/max77693_charger.c
index 86ea0231175c..754879eb59f6 100644
--- a/drivers/power/max77693_charger.c
+++ b/drivers/power/max77693_charger.c
@@ -22,14 +22,14 @@
22#include <linux/mfd/max77693.h> 22#include <linux/mfd/max77693.h>
23#include <linux/mfd/max77693-private.h> 23#include <linux/mfd/max77693-private.h>
24 24
25static const char *max77693_charger_name = "max77693-charger"; 25#define MAX77693_CHARGER_NAME "max77693-charger"
26static const char *max77693_charger_model = "MAX77693"; 26static const char *max77693_charger_model = "MAX77693";
27static const char *max77693_charger_manufacturer = "Maxim Integrated"; 27static const char *max77693_charger_manufacturer = "Maxim Integrated";
28 28
29struct max77693_charger { 29struct max77693_charger {
30 struct device *dev; 30 struct device *dev;
31 struct max77693_dev *max77693; 31 struct max77693_dev *max77693;
32 struct power_supply charger; 32 struct power_supply *charger;
33 33
34 u32 constant_volt; 34 u32 constant_volt;
35 u32 min_system_volt; 35 u32 min_system_volt;
@@ -220,9 +220,7 @@ static int max77693_charger_get_property(struct power_supply *psy,
220 enum power_supply_property psp, 220 enum power_supply_property psp,
221 union power_supply_propval *val) 221 union power_supply_propval *val)
222{ 222{
223 struct max77693_charger *chg = container_of(psy, 223 struct max77693_charger *chg = power_supply_get_drvdata(psy);
224 struct max77693_charger,
225 charger);
226 struct regmap *regmap = chg->max77693->regmap; 224 struct regmap *regmap = chg->max77693->regmap;
227 int ret = 0; 225 int ret = 0;
228 226
@@ -255,6 +253,14 @@ static int max77693_charger_get_property(struct power_supply *psy,
255 return ret; 253 return ret;
256} 254}
257 255
256static const struct power_supply_desc max77693_charger_desc = {
257 .name = MAX77693_CHARGER_NAME,
258 .type = POWER_SUPPLY_TYPE_BATTERY,
259 .properties = max77693_charger_props,
260 .num_properties = ARRAY_SIZE(max77693_charger_props),
261 .get_property = max77693_charger_get_property,
262};
263
258static ssize_t device_attr_store(struct device *dev, 264static ssize_t device_attr_store(struct device *dev,
259 struct device_attribute *attr, const char *buf, size_t count, 265 struct device_attribute *attr, const char *buf, size_t count,
260 int (*fn)(struct max77693_charger *, unsigned long)) 266 int (*fn)(struct max77693_charger *, unsigned long))
@@ -670,6 +676,7 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
670static int max77693_charger_probe(struct platform_device *pdev) 676static int max77693_charger_probe(struct platform_device *pdev)
671{ 677{
672 struct max77693_charger *chg; 678 struct max77693_charger *chg;
679 struct power_supply_config psy_cfg = {};
673 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); 680 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
674 int ret; 681 int ret;
675 682
@@ -689,11 +696,7 @@ static int max77693_charger_probe(struct platform_device *pdev)
689 if (ret) 696 if (ret)
690 return ret; 697 return ret;
691 698
692 chg->charger.name = max77693_charger_name; 699 psy_cfg.drv_data = chg;
693 chg->charger.type = POWER_SUPPLY_TYPE_BATTERY;
694 chg->charger.properties = max77693_charger_props;
695 chg->charger.num_properties = ARRAY_SIZE(max77693_charger_props);
696 chg->charger.get_property = max77693_charger_get_property;
697 700
698 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); 701 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer);
699 if (ret) { 702 if (ret) {
@@ -714,9 +717,12 @@ static int max77693_charger_probe(struct platform_device *pdev)
714 goto err; 717 goto err;
715 } 718 }
716 719
717 ret = power_supply_register(&pdev->dev, &chg->charger, NULL); 720 chg->charger = power_supply_register(&pdev->dev,
718 if (ret) { 721 &max77693_charger_desc,
722 &psy_cfg);
723 if (IS_ERR(chg->charger)) {
719 dev_err(&pdev->dev, "failed: power supply register\n"); 724 dev_err(&pdev->dev, "failed: power supply register\n");
725 ret = PTR_ERR(chg->charger);
720 goto err; 726 goto err;
721 } 727 }
722 728
@@ -738,7 +744,7 @@ static int max77693_charger_remove(struct platform_device *pdev)
738 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); 744 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current);
739 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); 745 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
740 746
741 power_supply_unregister(&chg->charger); 747 power_supply_unregister(chg->charger);
742 748
743 return 0; 749 return 0;
744} 750}
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c
index 2f769faa85f6..bf2b4b3a7cae 100644
--- a/drivers/power/max8903_charger.c
+++ b/drivers/power/max8903_charger.c
@@ -31,7 +31,8 @@
31struct max8903_data { 31struct max8903_data {
32 struct max8903_pdata pdata; 32 struct max8903_pdata pdata;
33 struct device *dev; 33 struct device *dev;
34 struct power_supply psy; 34 struct power_supply *psy;
35 struct power_supply_desc psy_desc;
35 bool fault; 36 bool fault;
36 bool usb_in; 37 bool usb_in;
37 bool ta_in; 38 bool ta_in;
@@ -47,8 +48,7 @@ static int max8903_get_property(struct power_supply *psy,
47 enum power_supply_property psp, 48 enum power_supply_property psp,
48 union power_supply_propval *val) 49 union power_supply_propval *val)
49{ 50{
50 struct max8903_data *data = container_of(psy, 51 struct max8903_data *data = power_supply_get_drvdata(psy);
51 struct max8903_data, psy);
52 52
53 switch (psp) { 53 switch (psp) {
54 case POWER_SUPPLY_PROP_STATUS: 54 case POWER_SUPPLY_PROP_STATUS:
@@ -104,17 +104,17 @@ static irqreturn_t max8903_dcin(int irq, void *_data)
104 dev_dbg(data->dev, "TA(DC-IN) Charger %s.\n", ta_in ? 104 dev_dbg(data->dev, "TA(DC-IN) Charger %s.\n", ta_in ?
105 "Connected" : "Disconnected"); 105 "Connected" : "Disconnected");
106 106
107 old_type = data->psy.type; 107 old_type = data->psy_desc.type;
108 108
109 if (data->ta_in) 109 if (data->ta_in)
110 data->psy.type = POWER_SUPPLY_TYPE_MAINS; 110 data->psy_desc.type = POWER_SUPPLY_TYPE_MAINS;
111 else if (data->usb_in) 111 else if (data->usb_in)
112 data->psy.type = POWER_SUPPLY_TYPE_USB; 112 data->psy_desc.type = POWER_SUPPLY_TYPE_USB;
113 else 113 else
114 data->psy.type = POWER_SUPPLY_TYPE_BATTERY; 114 data->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY;
115 115
116 if (old_type != data->psy.type) 116 if (old_type != data->psy_desc.type)
117 power_supply_changed(&data->psy); 117 power_supply_changed(data->psy);
118 118
119 return IRQ_HANDLED; 119 return IRQ_HANDLED;
120} 120}
@@ -143,17 +143,17 @@ static irqreturn_t max8903_usbin(int irq, void *_data)
143 dev_dbg(data->dev, "USB Charger %s.\n", usb_in ? 143 dev_dbg(data->dev, "USB Charger %s.\n", usb_in ?
144 "Connected" : "Disconnected"); 144 "Connected" : "Disconnected");
145 145
146 old_type = data->psy.type; 146 old_type = data->psy_desc.type;
147 147
148 if (data->ta_in) 148 if (data->ta_in)
149 data->psy.type = POWER_SUPPLY_TYPE_MAINS; 149 data->psy_desc.type = POWER_SUPPLY_TYPE_MAINS;
150 else if (data->usb_in) 150 else if (data->usb_in)
151 data->psy.type = POWER_SUPPLY_TYPE_USB; 151 data->psy_desc.type = POWER_SUPPLY_TYPE_USB;
152 else 152 else
153 data->psy.type = POWER_SUPPLY_TYPE_BATTERY; 153 data->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY;
154 154
155 if (old_type != data->psy.type) 155 if (old_type != data->psy_desc.type)
156 power_supply_changed(&data->psy); 156 power_supply_changed(data->psy);
157 157
158 return IRQ_HANDLED; 158 return IRQ_HANDLED;
159} 159}
@@ -184,6 +184,7 @@ static int max8903_probe(struct platform_device *pdev)
184 struct max8903_data *data; 184 struct max8903_data *data;
185 struct device *dev = &pdev->dev; 185 struct device *dev = &pdev->dev;
186 struct max8903_pdata *pdata = pdev->dev.platform_data; 186 struct max8903_pdata *pdata = pdev->dev.platform_data;
187 struct power_supply_config psy_cfg = {};
187 int ret = 0; 188 int ret = 0;
188 int gpio; 189 int gpio;
189 int ta_in = 0; 190 int ta_in = 0;
@@ -280,17 +281,20 @@ static int max8903_probe(struct platform_device *pdev)
280 data->ta_in = ta_in; 281 data->ta_in = ta_in;
281 data->usb_in = usb_in; 282 data->usb_in = usb_in;
282 283
283 data->psy.name = "max8903_charger"; 284 data->psy_desc.name = "max8903_charger";
284 data->psy.type = (ta_in) ? POWER_SUPPLY_TYPE_MAINS : 285 data->psy_desc.type = (ta_in) ? POWER_SUPPLY_TYPE_MAINS :
285 ((usb_in) ? POWER_SUPPLY_TYPE_USB : 286 ((usb_in) ? POWER_SUPPLY_TYPE_USB :
286 POWER_SUPPLY_TYPE_BATTERY); 287 POWER_SUPPLY_TYPE_BATTERY);
287 data->psy.get_property = max8903_get_property; 288 data->psy_desc.get_property = max8903_get_property;
288 data->psy.properties = max8903_charger_props; 289 data->psy_desc.properties = max8903_charger_props;
289 data->psy.num_properties = ARRAY_SIZE(max8903_charger_props); 290 data->psy_desc.num_properties = ARRAY_SIZE(max8903_charger_props);
290 291
291 ret = power_supply_register(dev, &data->psy, NULL); 292 psy_cfg.drv_data = data;
292 if (ret) { 293
294 data->psy = power_supply_register(dev, &data->psy_desc, &psy_cfg);
295 if (IS_ERR(data->psy)) {
293 dev_err(dev, "failed: power supply register.\n"); 296 dev_err(dev, "failed: power supply register.\n");
297 ret = PTR_ERR(data->psy);
294 goto err; 298 goto err;
295 } 299 }
296 300
@@ -339,7 +343,7 @@ err_dc_irq:
339 if (pdata->dc_valid) 343 if (pdata->dc_valid)
340 free_irq(gpio_to_irq(pdata->dok), data); 344 free_irq(gpio_to_irq(pdata->dok), data);
341err_psy: 345err_psy:
342 power_supply_unregister(&data->psy); 346 power_supply_unregister(data->psy);
343err: 347err:
344 return ret; 348 return ret;
345} 349}
@@ -357,7 +361,7 @@ static int max8903_remove(struct platform_device *pdev)
357 free_irq(gpio_to_irq(pdata->uok), data); 361 free_irq(gpio_to_irq(pdata->uok), data);
358 if (pdata->dc_valid) 362 if (pdata->dc_valid)
359 free_irq(gpio_to_irq(pdata->dok), data); 363 free_irq(gpio_to_irq(pdata->dok), data);
360 power_supply_unregister(&data->psy); 364 power_supply_unregister(data->psy);
361 } 365 }
362 366
363 return 0; 367 return 0;
diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index 71c087e3feaf..57eb5c2bfc21 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -68,9 +68,9 @@ struct max8925_power_info {
68 struct i2c_client *gpm; 68 struct i2c_client *gpm;
69 struct i2c_client *adc; 69 struct i2c_client *adc;
70 70
71 struct power_supply ac; 71 struct power_supply *ac;
72 struct power_supply usb; 72 struct power_supply *usb;
73 struct power_supply battery; 73 struct power_supply *battery;
74 int irq_base; 74 int irq_base;
75 unsigned ac_online:1; 75 unsigned ac_online:1;
76 unsigned usb_online:1; 76 unsigned usb_online:1;
@@ -196,7 +196,7 @@ static int max8925_ac_get_prop(struct power_supply *psy,
196 enum power_supply_property psp, 196 enum power_supply_property psp,
197 union power_supply_propval *val) 197 union power_supply_propval *val)
198{ 198{
199 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); 199 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent);
200 int ret = 0; 200 int ret = 0;
201 201
202 switch (psp) { 202 switch (psp) {
@@ -230,7 +230,7 @@ static int max8925_usb_get_prop(struct power_supply *psy,
230 enum power_supply_property psp, 230 enum power_supply_property psp,
231 union power_supply_propval *val) 231 union power_supply_propval *val)
232{ 232{
233 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); 233 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent);
234 int ret = 0; 234 int ret = 0;
235 235
236 switch (psp) { 236 switch (psp) {
@@ -264,7 +264,7 @@ static int max8925_bat_get_prop(struct power_supply *psy,
264 enum power_supply_property psp, 264 enum power_supply_property psp,
265 union power_supply_propval *val) 265 union power_supply_propval *val)
266{ 266{
267 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); 267 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent);
268 int ret = 0; 268 int ret = 0;
269 269
270 switch (psp) { 270 switch (psp) {
@@ -347,6 +347,30 @@ static enum power_supply_property max8925_battery_props[] = {
347 POWER_SUPPLY_PROP_STATUS, 347 POWER_SUPPLY_PROP_STATUS,
348}; 348};
349 349
350static const struct power_supply_desc ac_desc = {
351 .name = "max8925-ac",
352 .type = POWER_SUPPLY_TYPE_MAINS,
353 .properties = max8925_ac_props,
354 .num_properties = ARRAY_SIZE(max8925_ac_props),
355 .get_property = max8925_ac_get_prop,
356};
357
358static const struct power_supply_desc usb_desc = {
359 .name = "max8925-usb",
360 .type = POWER_SUPPLY_TYPE_USB,
361 .properties = max8925_usb_props,
362 .num_properties = ARRAY_SIZE(max8925_usb_props),
363 .get_property = max8925_usb_get_prop,
364};
365
366static const struct power_supply_desc battery_desc = {
367 .name = "max8925-battery",
368 .type = POWER_SUPPLY_TYPE_BATTERY,
369 .properties = max8925_battery_props,
370 .num_properties = ARRAY_SIZE(max8925_battery_props),
371 .get_property = max8925_bat_get_prop,
372};
373
350#define REQUEST_IRQ(_irq, _name) \ 374#define REQUEST_IRQ(_irq, _name) \
351do { \ 375do { \
352 ret = request_threaded_irq(chip->irq_base + _irq, NULL, \ 376 ret = request_threaded_irq(chip->irq_base + _irq, NULL, \
@@ -506,36 +530,26 @@ static int max8925_power_probe(struct platform_device *pdev)
506 psy_cfg.supplied_to = pdata->supplied_to; 530 psy_cfg.supplied_to = pdata->supplied_to;
507 psy_cfg.num_supplicants = pdata->num_supplicants; 531 psy_cfg.num_supplicants = pdata->num_supplicants;
508 532
509 info->ac.name = "max8925-ac"; 533 info->ac = power_supply_register(&pdev->dev, &ac_desc, &psy_cfg);
510 info->ac.type = POWER_SUPPLY_TYPE_MAINS; 534 if (IS_ERR(info->ac)) {
511 info->ac.properties = max8925_ac_props; 535 ret = PTR_ERR(info->ac);
512 info->ac.num_properties = ARRAY_SIZE(max8925_ac_props);
513 info->ac.get_property = max8925_ac_get_prop;
514 ret = power_supply_register(&pdev->dev, &info->ac, &psy_cfg);
515 if (ret)
516 goto out; 536 goto out;
517 info->ac.dev->parent = &pdev->dev; 537 }
518 538 info->ac->dev.parent = &pdev->dev;
519 info->usb.name = "max8925-usb";
520 info->usb.type = POWER_SUPPLY_TYPE_USB;
521 info->usb.properties = max8925_usb_props;
522 info->usb.num_properties = ARRAY_SIZE(max8925_usb_props);
523 info->usb.get_property = max8925_usb_get_prop;
524 539
525 ret = power_supply_register(&pdev->dev, &info->usb, &psy_cfg); 540 info->usb = power_supply_register(&pdev->dev, &usb_desc, &psy_cfg);
526 if (ret) 541 if (IS_ERR(info->usb)) {
542 ret = PTR_ERR(info->usb);
527 goto out_usb; 543 goto out_usb;
528 info->usb.dev->parent = &pdev->dev; 544 }
529 545 info->usb->dev.parent = &pdev->dev;
530 info->battery.name = "max8925-battery"; 546
531 info->battery.type = POWER_SUPPLY_TYPE_BATTERY; 547 info->battery = power_supply_register(&pdev->dev, &battery_desc, NULL);
532 info->battery.properties = max8925_battery_props; 548 if (IS_ERR(info->battery)) {
533 info->battery.num_properties = ARRAY_SIZE(max8925_battery_props); 549 ret = PTR_ERR(info->battery);
534 info->battery.get_property = max8925_bat_get_prop;
535 ret = power_supply_register(&pdev->dev, &info->battery, NULL);
536 if (ret)
537 goto out_battery; 550 goto out_battery;
538 info->battery.dev->parent = &pdev->dev; 551 }
552 info->battery->dev.parent = &pdev->dev;
539 553
540 info->batt_detect = pdata->batt_detect; 554 info->batt_detect = pdata->batt_detect;
541 info->topoff_threshold = pdata->topoff_threshold; 555 info->topoff_threshold = pdata->topoff_threshold;
@@ -547,9 +561,9 @@ static int max8925_power_probe(struct platform_device *pdev)
547 max8925_init_charger(chip, info); 561 max8925_init_charger(chip, info);
548 return 0; 562 return 0;
549out_battery: 563out_battery:
550 power_supply_unregister(&info->battery); 564 power_supply_unregister(info->battery);
551out_usb: 565out_usb:
552 power_supply_unregister(&info->ac); 566 power_supply_unregister(info->ac);
553out: 567out:
554 return ret; 568 return ret;
555} 569}
@@ -559,9 +573,9 @@ static int max8925_power_remove(struct platform_device *pdev)
559 struct max8925_power_info *info = platform_get_drvdata(pdev); 573 struct max8925_power_info *info = platform_get_drvdata(pdev);
560 574
561 if (info) { 575 if (info) {
562 power_supply_unregister(&info->ac); 576 power_supply_unregister(info->ac);
563 power_supply_unregister(&info->usb); 577 power_supply_unregister(info->usb);
564 power_supply_unregister(&info->battery); 578 power_supply_unregister(info->battery);
565 max8925_deinit_charger(info); 579 max8925_deinit_charger(info);
566 } 580 }
567 return 0; 581 return 0;
diff --git a/drivers/power/max8997_charger.c b/drivers/power/max8997_charger.c
index a9f4d506eb44..0b2eab571528 100644
--- a/drivers/power/max8997_charger.c
+++ b/drivers/power/max8997_charger.c
@@ -30,7 +30,7 @@
30struct charger_data { 30struct charger_data {
31 struct device *dev; 31 struct device *dev;
32 struct max8997_dev *iodev; 32 struct max8997_dev *iodev;
33 struct power_supply battery; 33 struct power_supply *battery;
34}; 34};
35 35
36static enum power_supply_property max8997_battery_props[] = { 36static enum power_supply_property max8997_battery_props[] = {
@@ -44,8 +44,7 @@ static int max8997_battery_get_property(struct power_supply *psy,
44 enum power_supply_property psp, 44 enum power_supply_property psp,
45 union power_supply_propval *val) 45 union power_supply_propval *val)
46{ 46{
47 struct charger_data *charger = container_of(psy, 47 struct charger_data *charger = power_supply_get_drvdata(psy);
48 struct charger_data, battery);
49 struct i2c_client *i2c = charger->iodev->i2c; 48 struct i2c_client *i2c = charger->iodev->i2c;
50 int ret; 49 int ret;
51 u8 reg; 50 u8 reg;
@@ -86,12 +85,21 @@ static int max8997_battery_get_property(struct power_supply *psy,
86 return 0; 85 return 0;
87} 86}
88 87
88static const struct power_supply_desc max8997_battery_desc = {
89 .name = "max8997_pmic",
90 .type = POWER_SUPPLY_TYPE_BATTERY,
91 .get_property = max8997_battery_get_property,
92 .properties = max8997_battery_props,
93 .num_properties = ARRAY_SIZE(max8997_battery_props),
94};
95
89static int max8997_battery_probe(struct platform_device *pdev) 96static int max8997_battery_probe(struct platform_device *pdev)
90{ 97{
91 int ret = 0; 98 int ret = 0;
92 struct charger_data *charger; 99 struct charger_data *charger;
93 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 100 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
94 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); 101 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev);
102 struct power_supply_config psy_cfg = {};
95 103
96 if (!pdata) 104 if (!pdata)
97 return -EINVAL; 105 return -EINVAL;
@@ -147,19 +155,18 @@ static int max8997_battery_probe(struct platform_device *pdev)
147 155
148 platform_set_drvdata(pdev, charger); 156 platform_set_drvdata(pdev, charger);
149 157
150 charger->battery.name = "max8997_pmic";
151 charger->battery.type = POWER_SUPPLY_TYPE_BATTERY;
152 charger->battery.get_property = max8997_battery_get_property;
153 charger->battery.properties = max8997_battery_props;
154 charger->battery.num_properties = ARRAY_SIZE(max8997_battery_props);
155 158
156 charger->dev = &pdev->dev; 159 charger->dev = &pdev->dev;
157 charger->iodev = iodev; 160 charger->iodev = iodev;
158 161
159 ret = power_supply_register(&pdev->dev, &charger->battery, NULL); 162 psy_cfg.drv_data = charger;
160 if (ret) { 163
164 charger->battery = power_supply_register(&pdev->dev,
165 &max8997_battery_desc,
166 &psy_cfg);
167 if (IS_ERR(charger->battery)) {
161 dev_err(&pdev->dev, "failed: power supply register\n"); 168 dev_err(&pdev->dev, "failed: power supply register\n");
162 return ret; 169 return PTR_ERR(charger->battery);
163 } 170 }
164 171
165 return 0; 172 return 0;
@@ -169,7 +176,7 @@ static int max8997_battery_remove(struct platform_device *pdev)
169{ 176{
170 struct charger_data *charger = platform_get_drvdata(pdev); 177 struct charger_data *charger = platform_get_drvdata(pdev);
171 178
172 power_supply_unregister(&charger->battery); 179 power_supply_unregister(charger->battery);
173 return 0; 180 return 0;
174} 181}
175 182
diff --git a/drivers/power/max8998_charger.c b/drivers/power/max8998_charger.c
index 9ee72314b3d0..47448d4bc6cd 100644
--- a/drivers/power/max8998_charger.c
+++ b/drivers/power/max8998_charger.c
@@ -30,7 +30,7 @@
30struct max8998_battery_data { 30struct max8998_battery_data {
31 struct device *dev; 31 struct device *dev;
32 struct max8998_dev *iodev; 32 struct max8998_dev *iodev;
33 struct power_supply battery; 33 struct power_supply *battery;
34}; 34};
35 35
36static enum power_supply_property max8998_battery_props[] = { 36static enum power_supply_property max8998_battery_props[] = {
@@ -43,8 +43,7 @@ static int max8998_battery_get_property(struct power_supply *psy,
43 enum power_supply_property psp, 43 enum power_supply_property psp,
44 union power_supply_propval *val) 44 union power_supply_propval *val)
45{ 45{
46 struct max8998_battery_data *max8998 = container_of(psy, 46 struct max8998_battery_data *max8998 = power_supply_get_drvdata(psy);
47 struct max8998_battery_data, battery);
48 struct i2c_client *i2c = max8998->iodev->i2c; 47 struct i2c_client *i2c = max8998->iodev->i2c;
49 int ret; 48 int ret;
50 u8 reg; 49 u8 reg;
@@ -75,10 +74,19 @@ static int max8998_battery_get_property(struct power_supply *psy,
75 return 0; 74 return 0;
76} 75}
77 76
77static const struct power_supply_desc max8998_battery_desc = {
78 .name = "max8998_pmic",
79 .type = POWER_SUPPLY_TYPE_BATTERY,
80 .get_property = max8998_battery_get_property,
81 .properties = max8998_battery_props,
82 .num_properties = ARRAY_SIZE(max8998_battery_props),
83};
84
78static int max8998_battery_probe(struct platform_device *pdev) 85static int max8998_battery_probe(struct platform_device *pdev)
79{ 86{
80 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); 87 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
81 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); 88 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
89 struct power_supply_config psy_cfg = {};
82 struct max8998_battery_data *max8998; 90 struct max8998_battery_data *max8998;
83 struct i2c_client *i2c; 91 struct i2c_client *i2c;
84 int ret = 0; 92 int ret = 0;
@@ -161,15 +169,15 @@ static int max8998_battery_probe(struct platform_device *pdev)
161 goto err; 169 goto err;
162 } 170 }
163 171
164 max8998->battery.name = "max8998_pmic"; 172 psy_cfg.drv_data = max8998;
165 max8998->battery.type = POWER_SUPPLY_TYPE_BATTERY;
166 max8998->battery.get_property = max8998_battery_get_property;
167 max8998->battery.properties = max8998_battery_props;
168 max8998->battery.num_properties = ARRAY_SIZE(max8998_battery_props);
169 173
170 ret = power_supply_register(max8998->dev, &max8998->battery, NULL); 174 max8998->battery = power_supply_register(max8998->dev,
171 if (ret) { 175 &max8998_battery_desc,
172 dev_err(max8998->dev, "failed: power supply register\n"); 176 &psy_cfg);
177 if (IS_ERR(max8998->battery)) {
178 ret = PTR_ERR(max8998->battery);
179 dev_err(max8998->dev, "failed: power supply register: %d\n",
180 ret);
173 goto err; 181 goto err;
174 } 182 }
175 183
@@ -182,7 +190,7 @@ static int max8998_battery_remove(struct platform_device *pdev)
182{ 190{
183 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev); 191 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev);
184 192
185 power_supply_unregister(&max8998->battery); 193 power_supply_unregister(max8998->battery);
186 194
187 return 0; 195 return 0;
188} 196}
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 1340a1a75325..a944338a39de 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -81,7 +81,7 @@ static enum power_supply_property olpc_ac_props[] = {
81 POWER_SUPPLY_PROP_ONLINE, 81 POWER_SUPPLY_PROP_ONLINE,
82}; 82};
83 83
84static struct power_supply olpc_ac = { 84static const struct power_supply_desc olpc_ac_desc = {
85 .name = "olpc-ac", 85 .name = "olpc-ac",
86 .type = POWER_SUPPLY_TYPE_MAINS, 86 .type = POWER_SUPPLY_TYPE_MAINS,
87 .properties = olpc_ac_props, 87 .properties = olpc_ac_props,
@@ -89,6 +89,8 @@ static struct power_supply olpc_ac = {
89 .get_property = olpc_ac_get_prop, 89 .get_property = olpc_ac_get_prop,
90}; 90};
91 91
92static struct power_supply *olpc_ac;
93
92static char bat_serial[17]; /* Ick */ 94static char bat_serial[17]; /* Ick */
93 95
94static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte) 96static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte)
@@ -574,21 +576,23 @@ static struct device_attribute olpc_bat_error = {
574 * Initialisation 576 * Initialisation
575 *********************************************************************/ 577 *********************************************************************/
576 578
577static struct power_supply olpc_bat = { 579static struct power_supply_desc olpc_bat_desc = {
578 .name = "olpc-battery", 580 .name = "olpc-battery",
579 .get_property = olpc_bat_get_property, 581 .get_property = olpc_bat_get_property,
580 .use_for_apm = 1, 582 .use_for_apm = 1,
581}; 583};
582 584
585static struct power_supply *olpc_bat;
586
583static int olpc_battery_suspend(struct platform_device *pdev, 587static int olpc_battery_suspend(struct platform_device *pdev,
584 pm_message_t state) 588 pm_message_t state)
585{ 589{
586 if (device_may_wakeup(olpc_ac.dev)) 590 if (device_may_wakeup(&olpc_ac->dev))
587 olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR); 591 olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
588 else 592 else
589 olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR); 593 olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
590 594
591 if (device_may_wakeup(olpc_bat.dev)) 595 if (device_may_wakeup(&olpc_bat->dev))
592 olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC 596 olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
593 | EC_SCI_SRC_BATERR); 597 | EC_SCI_SRC_BATERR);
594 else 598 else
@@ -619,52 +623,54 @@ static int olpc_battery_probe(struct platform_device *pdev)
619 623
620 /* Ignore the status. It doesn't actually matter */ 624 /* Ignore the status. It doesn't actually matter */
621 625
622 ret = power_supply_register(&pdev->dev, &olpc_ac, NULL); 626 olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
623 if (ret) 627 if (IS_ERR(olpc_ac))
624 return ret; 628 return PTR_ERR(olpc_ac);
625 629
626 if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */ 630 if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
627 olpc_bat.properties = olpc_xo15_bat_props; 631 olpc_bat_desc.properties = olpc_xo15_bat_props;
628 olpc_bat.num_properties = ARRAY_SIZE(olpc_xo15_bat_props); 632 olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo15_bat_props);
629 } else { /* XO-1 */ 633 } else { /* XO-1 */
630 olpc_bat.properties = olpc_xo1_bat_props; 634 olpc_bat_desc.properties = olpc_xo1_bat_props;
631 olpc_bat.num_properties = ARRAY_SIZE(olpc_xo1_bat_props); 635 olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
632 } 636 }
633 637
634 ret = power_supply_register(&pdev->dev, &olpc_bat, NULL); 638 olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
635 if (ret) 639 if (IS_ERR(olpc_bat)) {
640 ret = PTR_ERR(olpc_bat);
636 goto battery_failed; 641 goto battery_failed;
642 }
637 643
638 ret = device_create_bin_file(olpc_bat.dev, &olpc_bat_eeprom); 644 ret = device_create_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
639 if (ret) 645 if (ret)
640 goto eeprom_failed; 646 goto eeprom_failed;
641 647
642 ret = device_create_file(olpc_bat.dev, &olpc_bat_error); 648 ret = device_create_file(&olpc_bat->dev, &olpc_bat_error);
643 if (ret) 649 if (ret)
644 goto error_failed; 650 goto error_failed;
645 651
646 if (olpc_ec_wakeup_available()) { 652 if (olpc_ec_wakeup_available()) {
647 device_set_wakeup_capable(olpc_ac.dev, true); 653 device_set_wakeup_capable(&olpc_ac->dev, true);
648 device_set_wakeup_capable(olpc_bat.dev, true); 654 device_set_wakeup_capable(&olpc_bat->dev, true);
649 } 655 }
650 656
651 return 0; 657 return 0;
652 658
653error_failed: 659error_failed:
654 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); 660 device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
655eeprom_failed: 661eeprom_failed:
656 power_supply_unregister(&olpc_bat); 662 power_supply_unregister(olpc_bat);
657battery_failed: 663battery_failed:
658 power_supply_unregister(&olpc_ac); 664 power_supply_unregister(olpc_ac);
659 return ret; 665 return ret;
660} 666}
661 667
662static int olpc_battery_remove(struct platform_device *pdev) 668static int olpc_battery_remove(struct platform_device *pdev)
663{ 669{
664 device_remove_file(olpc_bat.dev, &olpc_bat_error); 670 device_remove_file(&olpc_bat->dev, &olpc_bat_error);
665 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); 671 device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
666 power_supply_unregister(&olpc_bat); 672 power_supply_unregister(olpc_bat);
667 power_supply_unregister(&olpc_ac); 673 power_supply_unregister(olpc_ac);
668 return 0; 674 return 0;
669} 675}
670 676
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index 88fe7db2afcf..d05597b4e40f 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -33,9 +33,9 @@ struct pcf50633_mbc {
33 int adapter_online; 33 int adapter_online;
34 int usb_online; 34 int usb_online;
35 35
36 struct power_supply usb; 36 struct power_supply *usb;
37 struct power_supply adapter; 37 struct power_supply *adapter;
38 struct power_supply ac; 38 struct power_supply *ac;
39}; 39};
40 40
41int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma) 41int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
@@ -104,7 +104,7 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
104 PCF50633_MBCC1_CHGENA, PCF50633_MBCC1_CHGENA); 104 PCF50633_MBCC1_CHGENA, PCF50633_MBCC1_CHGENA);
105 } 105 }
106 106
107 power_supply_changed(&mbc->usb); 107 power_supply_changed(mbc->usb);
108 108
109 return ret; 109 return ret;
110} 110}
@@ -278,9 +278,9 @@ pcf50633_mbc_irq_handler(int irq, void *data)
278 else if (irq == PCF50633_IRQ_ADPREM) 278 else if (irq == PCF50633_IRQ_ADPREM)
279 mbc->adapter_online = 0; 279 mbc->adapter_online = 0;
280 280
281 power_supply_changed(&mbc->ac); 281 power_supply_changed(mbc->ac);
282 power_supply_changed(&mbc->usb); 282 power_supply_changed(mbc->usb);
283 power_supply_changed(&mbc->adapter); 283 power_supply_changed(mbc->adapter);
284 284
285 if (mbc->pcf->pdata->mbc_event_callback) 285 if (mbc->pcf->pdata->mbc_event_callback)
286 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq); 286 mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
@@ -290,8 +290,7 @@ static int adapter_get_property(struct power_supply *psy,
290 enum power_supply_property psp, 290 enum power_supply_property psp,
291 union power_supply_propval *val) 291 union power_supply_propval *val)
292{ 292{
293 struct pcf50633_mbc *mbc = container_of(psy, 293 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
294 struct pcf50633_mbc, adapter);
295 int ret = 0; 294 int ret = 0;
296 295
297 switch (psp) { 296 switch (psp) {
@@ -309,7 +308,7 @@ static int usb_get_property(struct power_supply *psy,
309 enum power_supply_property psp, 308 enum power_supply_property psp,
310 union power_supply_propval *val) 309 union power_supply_propval *val)
311{ 310{
312 struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); 311 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
313 int ret = 0; 312 int ret = 0;
314 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & 313 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
315 PCF50633_MBCC7_USB_MASK; 314 PCF50633_MBCC7_USB_MASK;
@@ -330,7 +329,7 @@ static int ac_get_property(struct power_supply *psy,
330 enum power_supply_property psp, 329 enum power_supply_property psp,
331 union power_supply_propval *val) 330 union power_supply_propval *val)
332{ 331{
333 struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, ac); 332 struct pcf50633_mbc *mbc = power_supply_get_drvdata(psy);
334 int ret = 0; 333 int ret = 0;
335 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & 334 u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) &
336 PCF50633_MBCC7_USB_MASK; 335 PCF50633_MBCC7_USB_MASK;
@@ -366,6 +365,30 @@ static const u8 mbc_irq_handlers[] = {
366 PCF50633_IRQ_LOWBAT, 365 PCF50633_IRQ_LOWBAT,
367}; 366};
368 367
368static const struct power_supply_desc pcf50633_mbc_adapter_desc = {
369 .name = "adapter",
370 .type = POWER_SUPPLY_TYPE_MAINS,
371 .properties = power_props,
372 .num_properties = ARRAY_SIZE(power_props),
373 .get_property = &adapter_get_property,
374};
375
376static const struct power_supply_desc pcf50633_mbc_usb_desc = {
377 .name = "usb",
378 .type = POWER_SUPPLY_TYPE_USB,
379 .properties = power_props,
380 .num_properties = ARRAY_SIZE(power_props),
381 .get_property = usb_get_property,
382};
383
384static const struct power_supply_desc pcf50633_mbc_ac_desc = {
385 .name = "ac",
386 .type = POWER_SUPPLY_TYPE_MAINS,
387 .properties = power_props,
388 .num_properties = ARRAY_SIZE(power_props),
389 .get_property = ac_get_property,
390};
391
369static int pcf50633_mbc_probe(struct platform_device *pdev) 392static int pcf50633_mbc_probe(struct platform_device *pdev)
370{ 393{
371 struct power_supply_config psy_cfg = {}; 394 struct power_supply_config psy_cfg = {};
@@ -388,44 +411,34 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
388 411
389 psy_cfg.supplied_to = mbc->pcf->pdata->batteries; 412 psy_cfg.supplied_to = mbc->pcf->pdata->batteries;
390 psy_cfg.num_supplicants = mbc->pcf->pdata->num_batteries; 413 psy_cfg.num_supplicants = mbc->pcf->pdata->num_batteries;
414 psy_cfg.drv_data = mbc;
391 415
392 /* Create power supplies */ 416 /* Create power supplies */
393 mbc->adapter.name = "adapter"; 417 mbc->adapter = power_supply_register(&pdev->dev,
394 mbc->adapter.type = POWER_SUPPLY_TYPE_MAINS; 418 &pcf50633_mbc_adapter_desc,
395 mbc->adapter.properties = power_props; 419 &psy_cfg);
396 mbc->adapter.num_properties = ARRAY_SIZE(power_props); 420 if (IS_ERR(mbc->adapter)) {
397 mbc->adapter.get_property = &adapter_get_property;
398
399 mbc->usb.name = "usb";
400 mbc->usb.type = POWER_SUPPLY_TYPE_USB;
401 mbc->usb.properties = power_props;
402 mbc->usb.num_properties = ARRAY_SIZE(power_props);
403 mbc->usb.get_property = usb_get_property;
404
405 mbc->ac.name = "ac";
406 mbc->ac.type = POWER_SUPPLY_TYPE_MAINS;
407 mbc->ac.properties = power_props;
408 mbc->ac.num_properties = ARRAY_SIZE(power_props);
409 mbc->ac.get_property = ac_get_property;
410
411 ret = power_supply_register(&pdev->dev, &mbc->adapter, &psy_cfg);
412 if (ret) {
413 dev_err(mbc->pcf->dev, "failed to register adapter\n"); 421 dev_err(mbc->pcf->dev, "failed to register adapter\n");
422 ret = PTR_ERR(mbc->adapter);
414 return ret; 423 return ret;
415 } 424 }
416 425
417 ret = power_supply_register(&pdev->dev, &mbc->usb, &psy_cfg); 426 mbc->usb = power_supply_register(&pdev->dev, &pcf50633_mbc_usb_desc,
418 if (ret) { 427 &psy_cfg);
428 if (IS_ERR(mbc->usb)) {
419 dev_err(mbc->pcf->dev, "failed to register usb\n"); 429 dev_err(mbc->pcf->dev, "failed to register usb\n");
420 power_supply_unregister(&mbc->adapter); 430 power_supply_unregister(mbc->adapter);
431 ret = PTR_ERR(mbc->usb);
421 return ret; 432 return ret;
422 } 433 }
423 434
424 ret = power_supply_register(&pdev->dev, &mbc->ac, &psy_cfg); 435 mbc->ac = power_supply_register(&pdev->dev, &pcf50633_mbc_ac_desc,
425 if (ret) { 436 &psy_cfg);
437 if (IS_ERR(mbc->ac)) {
426 dev_err(mbc->pcf->dev, "failed to register ac\n"); 438 dev_err(mbc->pcf->dev, "failed to register ac\n");
427 power_supply_unregister(&mbc->adapter); 439 power_supply_unregister(mbc->adapter);
428 power_supply_unregister(&mbc->usb); 440 power_supply_unregister(mbc->usb);
441 ret = PTR_ERR(mbc->ac);
429 return ret; 442 return ret;
430 } 443 }
431 444
@@ -452,9 +465,9 @@ static int pcf50633_mbc_remove(struct platform_device *pdev)
452 pcf50633_free_irq(mbc->pcf, mbc_irq_handlers[i]); 465 pcf50633_free_irq(mbc->pcf, mbc_irq_handlers[i]);
453 466
454 sysfs_remove_group(&pdev->dev.kobj, &mbc_attr_group); 467 sysfs_remove_group(&pdev->dev.kobj, &mbc_attr_group);
455 power_supply_unregister(&mbc->usb); 468 power_supply_unregister(mbc->usb);
456 power_supply_unregister(&mbc->adapter); 469 power_supply_unregister(mbc->adapter);
457 power_supply_unregister(&mbc->ac); 470 power_supply_unregister(mbc->ac);
458 471
459 return 0; 472 return 0;
460} 473}
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index fd55fad1d0db..dfe1ee89f7c7 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -34,6 +34,7 @@ static struct timer_list charger_timer;
34static struct timer_list supply_timer; 34static struct timer_list supply_timer;
35static struct timer_list polling_timer; 35static struct timer_list polling_timer;
36static int polling; 36static int polling;
37static struct power_supply *pda_psy_ac, *pda_psy_usb;
37 38
38#if IS_ENABLED(CONFIG_USB_PHY) 39#if IS_ENABLED(CONFIG_USB_PHY)
39static struct usb_phy *transceiver; 40static struct usb_phy *transceiver;
@@ -58,7 +59,7 @@ static int pda_power_get_property(struct power_supply *psy,
58{ 59{
59 switch (psp) { 60 switch (psp) {
60 case POWER_SUPPLY_PROP_ONLINE: 61 case POWER_SUPPLY_PROP_ONLINE:
61 if (psy->type == POWER_SUPPLY_TYPE_MAINS) 62 if (psy->desc->type == POWER_SUPPLY_TYPE_MAINS)
62 val->intval = pdata->is_ac_online ? 63 val->intval = pdata->is_ac_online ?
63 pdata->is_ac_online() : 0; 64 pdata->is_ac_online() : 0;
64 else 65 else
@@ -80,7 +81,7 @@ static char *pda_power_supplied_to[] = {
80 "backup-battery", 81 "backup-battery",
81}; 82};
82 83
83static struct power_supply pda_psy_ac = { 84static const struct power_supply_desc pda_psy_ac_desc = {
84 .name = "ac", 85 .name = "ac",
85 .type = POWER_SUPPLY_TYPE_MAINS, 86 .type = POWER_SUPPLY_TYPE_MAINS,
86 .properties = pda_power_props, 87 .properties = pda_power_props,
@@ -88,7 +89,7 @@ static struct power_supply pda_psy_ac = {
88 .get_property = pda_power_get_property, 89 .get_property = pda_power_get_property,
89}; 90};
90 91
91static struct power_supply pda_psy_usb = { 92static const struct power_supply_desc pda_psy_usb_desc = {
92 .name = "usb", 93 .name = "usb",
93 .type = POWER_SUPPLY_TYPE_USB, 94 .type = POWER_SUPPLY_TYPE_USB,
94 .properties = pda_power_props, 95 .properties = pda_power_props,
@@ -143,12 +144,12 @@ static void supply_timer_func(unsigned long unused)
143{ 144{
144 if (ac_status == PDA_PSY_TO_CHANGE) { 145 if (ac_status == PDA_PSY_TO_CHANGE) {
145 ac_status = new_ac_status; 146 ac_status = new_ac_status;
146 power_supply_changed(&pda_psy_ac); 147 power_supply_changed(pda_psy_ac);
147 } 148 }
148 149
149 if (usb_status == PDA_PSY_TO_CHANGE) { 150 if (usb_status == PDA_PSY_TO_CHANGE) {
150 usb_status = new_usb_status; 151 usb_status = new_usb_status;
151 power_supply_changed(&pda_psy_usb); 152 power_supply_changed(pda_psy_usb);
152 } 153 }
153} 154}
154 155
@@ -172,9 +173,9 @@ static void charger_timer_func(unsigned long unused)
172 173
173static irqreturn_t power_changed_isr(int irq, void *power_supply) 174static irqreturn_t power_changed_isr(int irq, void *power_supply)
174{ 175{
175 if (power_supply == &pda_psy_ac) 176 if (power_supply == pda_psy_ac)
176 ac_status = PDA_PSY_TO_CHANGE; 177 ac_status = PDA_PSY_TO_CHANGE;
177 else if (power_supply == &pda_psy_usb) 178 else if (power_supply == pda_psy_usb)
178 usb_status = PDA_PSY_TO_CHANGE; 179 usb_status = PDA_PSY_TO_CHANGE;
179 else 180 else
180 return IRQ_NONE; 181 return IRQ_NONE;
@@ -324,17 +325,19 @@ static int pda_power_probe(struct platform_device *pdev)
324#endif 325#endif
325 326
326 if (pdata->is_ac_online) { 327 if (pdata->is_ac_online) {
327 ret = power_supply_register(&pdev->dev, &pda_psy_ac, &psy_cfg); 328 pda_psy_ac = power_supply_register(&pdev->dev,
328 if (ret) { 329 &pda_psy_ac_desc, &psy_cfg);
330 if (IS_ERR(pda_psy_ac)) {
329 dev_err(dev, "failed to register %s power supply\n", 331 dev_err(dev, "failed to register %s power supply\n",
330 pda_psy_ac.name); 332 pda_psy_ac_desc.name);
333 ret = PTR_ERR(pda_psy_ac);
331 goto ac_supply_failed; 334 goto ac_supply_failed;
332 } 335 }
333 336
334 if (ac_irq) { 337 if (ac_irq) {
335 ret = request_irq(ac_irq->start, power_changed_isr, 338 ret = request_irq(ac_irq->start, power_changed_isr,
336 get_irq_flags(ac_irq), ac_irq->name, 339 get_irq_flags(ac_irq), ac_irq->name,
337 &pda_psy_ac); 340 pda_psy_ac);
338 if (ret) { 341 if (ret) {
339 dev_err(dev, "request ac irq failed\n"); 342 dev_err(dev, "request ac irq failed\n");
340 goto ac_irq_failed; 343 goto ac_irq_failed;
@@ -345,17 +348,20 @@ static int pda_power_probe(struct platform_device *pdev)
345 } 348 }
346 349
347 if (pdata->is_usb_online) { 350 if (pdata->is_usb_online) {
348 ret = power_supply_register(&pdev->dev, &pda_psy_usb, &psy_cfg); 351 pda_psy_usb = power_supply_register(&pdev->dev,
349 if (ret) { 352 &pda_psy_usb_desc,
353 &psy_cfg);
354 if (IS_ERR(pda_psy_usb)) {
350 dev_err(dev, "failed to register %s power supply\n", 355 dev_err(dev, "failed to register %s power supply\n",
351 pda_psy_usb.name); 356 pda_psy_usb_desc.name);
357 ret = PTR_ERR(pda_psy_usb);
352 goto usb_supply_failed; 358 goto usb_supply_failed;
353 } 359 }
354 360
355 if (usb_irq) { 361 if (usb_irq) {
356 ret = request_irq(usb_irq->start, power_changed_isr, 362 ret = request_irq(usb_irq->start, power_changed_isr,
357 get_irq_flags(usb_irq), 363 get_irq_flags(usb_irq),
358 usb_irq->name, &pda_psy_usb); 364 usb_irq->name, pda_psy_usb);
359 if (ret) { 365 if (ret) {
360 dev_err(dev, "request usb irq failed\n"); 366 dev_err(dev, "request usb irq failed\n");
361 goto usb_irq_failed; 367 goto usb_irq_failed;
@@ -392,21 +398,21 @@ static int pda_power_probe(struct platform_device *pdev)
392#if IS_ENABLED(CONFIG_USB_PHY) 398#if IS_ENABLED(CONFIG_USB_PHY)
393otg_reg_notifier_failed: 399otg_reg_notifier_failed:
394 if (pdata->is_usb_online && usb_irq) 400 if (pdata->is_usb_online && usb_irq)
395 free_irq(usb_irq->start, &pda_psy_usb); 401 free_irq(usb_irq->start, pda_psy_usb);
396#endif 402#endif
397usb_irq_failed: 403usb_irq_failed:
398 if (pdata->is_usb_online) 404 if (pdata->is_usb_online)
399 power_supply_unregister(&pda_psy_usb); 405 power_supply_unregister(pda_psy_usb);
400usb_supply_failed: 406usb_supply_failed:
401 if (pdata->is_ac_online && ac_irq) 407 if (pdata->is_ac_online && ac_irq)
402 free_irq(ac_irq->start, &pda_psy_ac); 408 free_irq(ac_irq->start, pda_psy_ac);
403#if IS_ENABLED(CONFIG_USB_PHY) 409#if IS_ENABLED(CONFIG_USB_PHY)
404 if (!IS_ERR_OR_NULL(transceiver)) 410 if (!IS_ERR_OR_NULL(transceiver))
405 usb_put_phy(transceiver); 411 usb_put_phy(transceiver);
406#endif 412#endif
407ac_irq_failed: 413ac_irq_failed:
408 if (pdata->is_ac_online) 414 if (pdata->is_ac_online)
409 power_supply_unregister(&pda_psy_ac); 415 power_supply_unregister(pda_psy_ac);
410ac_supply_failed: 416ac_supply_failed:
411 if (ac_draw) { 417 if (ac_draw) {
412 regulator_put(ac_draw); 418 regulator_put(ac_draw);
@@ -422,9 +428,9 @@ wrongid:
422static int pda_power_remove(struct platform_device *pdev) 428static int pda_power_remove(struct platform_device *pdev)
423{ 429{
424 if (pdata->is_usb_online && usb_irq) 430 if (pdata->is_usb_online && usb_irq)
425 free_irq(usb_irq->start, &pda_psy_usb); 431 free_irq(usb_irq->start, pda_psy_usb);
426 if (pdata->is_ac_online && ac_irq) 432 if (pdata->is_ac_online && ac_irq)
427 free_irq(ac_irq->start, &pda_psy_ac); 433 free_irq(ac_irq->start, pda_psy_ac);
428 434
429 if (polling) 435 if (polling)
430 del_timer_sync(&polling_timer); 436 del_timer_sync(&polling_timer);
@@ -432,9 +438,9 @@ static int pda_power_remove(struct platform_device *pdev)
432 del_timer_sync(&supply_timer); 438 del_timer_sync(&supply_timer);
433 439
434 if (pdata->is_usb_online) 440 if (pdata->is_usb_online)
435 power_supply_unregister(&pda_psy_usb); 441 power_supply_unregister(pda_psy_usb);
436 if (pdata->is_ac_online) 442 if (pdata->is_ac_online)
437 power_supply_unregister(&pda_psy_ac); 443 power_supply_unregister(pda_psy_ac);
438#if IS_ENABLED(CONFIG_USB_PHY) 444#if IS_ENABLED(CONFIG_USB_PHY)
439 if (!IS_ERR_OR_NULL(transceiver)) 445 if (!IS_ERR_OR_NULL(transceiver))
440 usb_put_phy(transceiver); 446 usb_put_phy(transceiver);
diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c
index d2e88e473238..cc0893ffbf7e 100644
--- a/drivers/power/pm2301_charger.c
+++ b/drivers/power/pm2301_charger.c
@@ -216,7 +216,7 @@ static int pm2xxx_charger_ovv_mngt(struct pm2xxx_charger *pm2, int val)
216{ 216{
217 dev_err(pm2->dev, "Overvoltage detected\n"); 217 dev_err(pm2->dev, "Overvoltage detected\n");
218 pm2->flags.ovv = true; 218 pm2->flags.ovv = true;
219 power_supply_changed(&pm2->ac_chg.psy); 219 power_supply_changed(pm2->ac_chg.psy);
220 220
221 /* Schedule a new HW failure check */ 221 /* Schedule a new HW failure check */
222 queue_delayed_work(pm2->charger_wq, &pm2->check_hw_failure_work, 0); 222 queue_delayed_work(pm2->charger_wq, &pm2->check_hw_failure_work, 0);
@@ -229,7 +229,7 @@ static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val)
229 dev_dbg(pm2->dev , "20 minutes watchdog expired\n"); 229 dev_dbg(pm2->dev , "20 minutes watchdog expired\n");
230 230
231 pm2->ac.wd_expired = true; 231 pm2->ac.wd_expired = true;
232 power_supply_changed(&pm2->ac_chg.psy); 232 power_supply_changed(pm2->ac_chg.psy);
233 233
234 return 0; 234 return 0;
235} 235}
@@ -573,7 +573,7 @@ static int pm2xxx_charger_update_charger_current(struct ux500_charger *charger,
573 struct pm2xxx_charger *pm2; 573 struct pm2xxx_charger *pm2;
574 u8 val; 574 u8 val;
575 575
576 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS) 576 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)
577 pm2 = to_pm2xxx_charger_ac_device_info(charger); 577 pm2 = to_pm2xxx_charger_ac_device_info(charger);
578 else 578 else
579 return -ENXIO; 579 return -ENXIO;
@@ -816,7 +816,7 @@ static int pm2xxx_charger_ac_en(struct ux500_charger *charger,
816 816
817 dev_dbg(pm2->dev, "PM2301: " "Disabled AC charging\n"); 817 dev_dbg(pm2->dev, "PM2301: " "Disabled AC charging\n");
818 } 818 }
819 power_supply_changed(&pm2->ac_chg.psy); 819 power_supply_changed(pm2->ac_chg.psy);
820 820
821error_occured: 821error_occured:
822 return ret; 822 return ret;
@@ -827,7 +827,7 @@ static int pm2xxx_charger_watchdog_kick(struct ux500_charger *charger)
827 int ret; 827 int ret;
828 struct pm2xxx_charger *pm2; 828 struct pm2xxx_charger *pm2;
829 829
830 if (charger->psy.type == POWER_SUPPLY_TYPE_MAINS) 830 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS)
831 pm2 = to_pm2xxx_charger_ac_device_info(charger); 831 pm2 = to_pm2xxx_charger_ac_device_info(charger);
832 else 832 else
833 return -ENXIO; 833 return -ENXIO;
@@ -845,8 +845,8 @@ static void pm2xxx_charger_ac_work(struct work_struct *work)
845 struct pm2xxx_charger, ac_work); 845 struct pm2xxx_charger, ac_work);
846 846
847 847
848 power_supply_changed(&pm2->ac_chg.psy); 848 power_supply_changed(pm2->ac_chg.psy);
849 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present"); 849 sysfs_notify(&pm2->ac_chg.psy->dev.kobj, NULL, "present");
850}; 850};
851 851
852static void pm2xxx_charger_check_hw_failure_work(struct work_struct *work) 852static void pm2xxx_charger_check_hw_failure_work(struct work_struct *work)
@@ -862,7 +862,7 @@ static void pm2xxx_charger_check_hw_failure_work(struct work_struct *work)
862 if (!(reg_value & (PM2XXX_INT4_S_ITVPWR1OVV | 862 if (!(reg_value & (PM2XXX_INT4_S_ITVPWR1OVV |
863 PM2XXX_INT4_S_ITVPWR2OVV))) { 863 PM2XXX_INT4_S_ITVPWR2OVV))) {
864 pm2->flags.ovv = false; 864 pm2->flags.ovv = false;
865 power_supply_changed(&pm2->ac_chg.psy); 865 power_supply_changed(pm2->ac_chg.psy);
866 } 866 }
867 } 867 }
868 868
@@ -895,7 +895,7 @@ static void pm2xxx_charger_check_main_thermal_prot_work(
895 | PM2XXX_INT5_S_ITTHERMALSHUTDOWNFALL)) 895 | PM2XXX_INT5_S_ITTHERMALSHUTDOWNFALL))
896 pm2->flags.main_thermal_prot = false; 896 pm2->flags.main_thermal_prot = false;
897 897
898 power_supply_changed(&pm2->ac_chg.psy); 898 power_supply_changed(pm2->ac_chg.psy);
899} 899}
900 900
901static struct pm2xxx_interrupts pm2xxx_int = { 901static struct pm2xxx_interrupts pm2xxx_int = {
@@ -1043,11 +1043,11 @@ static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
1043 1043
1044 /* AC supply */ 1044 /* AC supply */
1045 /* power_supply base class */ 1045 /* power_supply base class */
1046 pm2->ac_chg.psy.name = pm2->pdata->label; 1046 pm2->ac_chg_desc.name = pm2->pdata->label;
1047 pm2->ac_chg.psy.type = POWER_SUPPLY_TYPE_MAINS; 1047 pm2->ac_chg_desc.type = POWER_SUPPLY_TYPE_MAINS;
1048 pm2->ac_chg.psy.properties = pm2xxx_charger_ac_props; 1048 pm2->ac_chg_desc.properties = pm2xxx_charger_ac_props;
1049 pm2->ac_chg.psy.num_properties = ARRAY_SIZE(pm2xxx_charger_ac_props); 1049 pm2->ac_chg_desc.num_properties = ARRAY_SIZE(pm2xxx_charger_ac_props);
1050 pm2->ac_chg.psy.get_property = pm2xxx_charger_ac_get_property; 1050 pm2->ac_chg_desc.get_property = pm2xxx_charger_ac_get_property;
1051 1051
1052 psy_cfg.supplied_to = pm2->pdata->supplied_to; 1052 psy_cfg.supplied_to = pm2->pdata->supplied_to;
1053 psy_cfg.num_supplicants = pm2->pdata->num_supplicants; 1053 psy_cfg.num_supplicants = pm2->pdata->num_supplicants;
@@ -1095,9 +1095,11 @@ static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
1095 } 1095 }
1096 1096
1097 /* Register AC charger class */ 1097 /* Register AC charger class */
1098 ret = power_supply_register(pm2->dev, &pm2->ac_chg.psy, &psy_cfg); 1098 pm2->ac_chg.psy = power_supply_register(pm2->dev, &pm2->ac_chg_desc,
1099 if (ret) { 1099 &psy_cfg);
1100 if (IS_ERR(pm2->ac_chg.psy)) {
1100 dev_err(pm2->dev, "failed to register AC charger\n"); 1101 dev_err(pm2->dev, "failed to register AC charger\n");
1102 ret = PTR_ERR(pm2->ac_chg.psy);
1101 goto free_regulator; 1103 goto free_regulator;
1102 } 1104 }
1103 1105
@@ -1169,8 +1171,8 @@ static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
1169 ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON, 1171 ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
1170 AB8500_MAIN_CH_DET); 1172 AB8500_MAIN_CH_DET);
1171 pm2->ac_conn = true; 1173 pm2->ac_conn = true;
1172 power_supply_changed(&pm2->ac_chg.psy); 1174 power_supply_changed(pm2->ac_chg.psy);
1173 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present"); 1175 sysfs_notify(&pm2->ac_chg.psy->dev.kobj, NULL, "present");
1174 } 1176 }
1175 1177
1176 return 0; 1178 return 0;
@@ -1185,7 +1187,7 @@ unregister_pm2xxx_interrupt:
1185 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2); 1187 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2);
1186unregister_pm2xxx_charger: 1188unregister_pm2xxx_charger:
1187 /* unregister power supply */ 1189 /* unregister power supply */
1188 power_supply_unregister(&pm2->ac_chg.psy); 1190 power_supply_unregister(pm2->ac_chg.psy);
1189free_regulator: 1191free_regulator:
1190 /* disable the regulator */ 1192 /* disable the regulator */
1191 regulator_put(pm2->regu); 1193 regulator_put(pm2->regu);
@@ -1220,7 +1222,7 @@ static int pm2xxx_wall_charger_remove(struct i2c_client *i2c_client)
1220 /* disable the regulator */ 1222 /* disable the regulator */
1221 regulator_put(pm2->regu); 1223 regulator_put(pm2->regu);
1222 1224
1223 power_supply_unregister(&pm2->ac_chg.psy); 1225 power_supply_unregister(pm2->ac_chg.psy);
1224 1226
1225 if (gpio_is_valid(pm2->lpn_pin)) 1227 if (gpio_is_valid(pm2->lpn_pin))
1226 gpio_free(pm2->lpn_pin); 1228 gpio_free(pm2->lpn_pin);
diff --git a/drivers/power/pm2301_charger.h b/drivers/power/pm2301_charger.h
index 8ce3cc0195df..24181cf9717b 100644
--- a/drivers/power/pm2301_charger.h
+++ b/drivers/power/pm2301_charger.h
@@ -486,6 +486,7 @@ struct pm2xxx_charger {
486 struct work_struct check_main_thermal_prot_work; 486 struct work_struct check_main_thermal_prot_work;
487 struct delayed_work check_hw_failure_work; 487 struct delayed_work check_hw_failure_work;
488 struct ux500_charger ac_chg; 488 struct ux500_charger ac_chg;
489 struct power_supply_desc ac_chg_desc;
489 struct pm2xxx_charger_event_flags flags; 490 struct pm2xxx_charger_event_flags flags;
490}; 491};
491 492
diff --git a/drivers/power/pmu_battery.c b/drivers/power/pmu_battery.c
index fb026f19aa4a..9c8d5253812c 100644
--- a/drivers/power/pmu_battery.c
+++ b/drivers/power/pmu_battery.c
@@ -17,13 +17,14 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18 18
19static struct pmu_battery_dev { 19static struct pmu_battery_dev {
20 struct power_supply bat; 20 struct power_supply *bat;
21 struct power_supply_desc bat_desc;
21 struct pmu_battery_info *pbi; 22 struct pmu_battery_info *pbi;
22 char name[16]; 23 char name[16];
23 int propval; 24 int propval;
24} *pbats[PMU_MAX_BATTERIES]; 25} *pbats[PMU_MAX_BATTERIES];
25 26
26#define to_pmu_battery_dev(x) container_of(x, struct pmu_battery_dev, bat) 27#define to_pmu_battery_dev(x) power_supply_get_drvdata(x)
27 28
28/********************************************************************* 29/*********************************************************************
29 * Power 30 * Power
@@ -49,7 +50,7 @@ static enum power_supply_property pmu_ac_props[] = {
49 POWER_SUPPLY_PROP_ONLINE, 50 POWER_SUPPLY_PROP_ONLINE,
50}; 51};
51 52
52static struct power_supply pmu_ac = { 53static const struct power_supply_desc pmu_ac_desc = {
53 .name = "pmu-ac", 54 .name = "pmu-ac",
54 .type = POWER_SUPPLY_TYPE_MAINS, 55 .type = POWER_SUPPLY_TYPE_MAINS,
55 .properties = pmu_ac_props, 56 .properties = pmu_ac_props,
@@ -57,6 +58,8 @@ static struct power_supply pmu_ac = {
57 .get_property = pmu_get_ac_prop, 58 .get_property = pmu_get_ac_prop,
58}; 59};
59 60
61static struct power_supply *pmu_ac;
62
60/********************************************************************* 63/*********************************************************************
61 * Battery properties 64 * Battery properties
62 *********************************************************************/ 65 *********************************************************************/
@@ -142,7 +145,7 @@ static struct platform_device *bat_pdev;
142 145
143static int __init pmu_bat_init(void) 146static int __init pmu_bat_init(void)
144{ 147{
145 int ret; 148 int ret = 0;
146 int i; 149 int i;
147 150
148 bat_pdev = platform_device_register_simple("pmu-battery", 151 bat_pdev = platform_device_register_simple("pmu-battery",
@@ -152,25 +155,32 @@ static int __init pmu_bat_init(void)
152 goto pdev_register_failed; 155 goto pdev_register_failed;
153 } 156 }
154 157
155 ret = power_supply_register(&bat_pdev->dev, &pmu_ac, NULL); 158 pmu_ac = power_supply_register(&bat_pdev->dev, &pmu_ac_desc, NULL);
156 if (ret) 159 if (IS_ERR(pmu_ac)) {
160 ret = PTR_ERR(pmu_ac);
157 goto ac_register_failed; 161 goto ac_register_failed;
162 }
158 163
159 for (i = 0; i < pmu_battery_count; i++) { 164 for (i = 0; i < pmu_battery_count; i++) {
165 struct power_supply_config psy_cfg = {};
160 struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat), 166 struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat),
161 GFP_KERNEL); 167 GFP_KERNEL);
162 if (!pbat) 168 if (!pbat)
163 break; 169 break;
164 170
165 sprintf(pbat->name, "PMU_battery_%d", i); 171 sprintf(pbat->name, "PMU_battery_%d", i);
166 pbat->bat.name = pbat->name; 172 pbat->bat_desc.name = pbat->name;
167 pbat->bat.properties = pmu_bat_props; 173 pbat->bat_desc.properties = pmu_bat_props;
168 pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props); 174 pbat->bat_desc.num_properties = ARRAY_SIZE(pmu_bat_props);
169 pbat->bat.get_property = pmu_bat_get_property; 175 pbat->bat_desc.get_property = pmu_bat_get_property;
170 pbat->pbi = &pmu_batteries[i]; 176 pbat->pbi = &pmu_batteries[i];
177 psy_cfg.drv_data = pbat;
171 178
172 ret = power_supply_register(&bat_pdev->dev, &pbat->bat, NULL); 179 pbat->bat = power_supply_register(&bat_pdev->dev,
173 if (ret) { 180 &pbat->bat_desc,
181 &psy_cfg);
182 if (IS_ERR(pbat->bat)) {
183 ret = PTR_ERR(pbat->bat);
174 kfree(pbat); 184 kfree(pbat);
175 goto battery_register_failed; 185 goto battery_register_failed;
176 } 186 }
@@ -183,10 +193,10 @@ battery_register_failed:
183 while (i--) { 193 while (i--) {
184 if (!pbats[i]) 194 if (!pbats[i])
185 continue; 195 continue;
186 power_supply_unregister(&pbats[i]->bat); 196 power_supply_unregister(pbats[i]->bat);
187 kfree(pbats[i]); 197 kfree(pbats[i]);
188 } 198 }
189 power_supply_unregister(&pmu_ac); 199 power_supply_unregister(pmu_ac);
190ac_register_failed: 200ac_register_failed:
191 platform_device_unregister(bat_pdev); 201 platform_device_unregister(bat_pdev);
192pdev_register_failed: 202pdev_register_failed:
@@ -201,10 +211,10 @@ static void __exit pmu_bat_exit(void)
201 for (i = 0; i < PMU_MAX_BATTERIES; i++) { 211 for (i = 0; i < PMU_MAX_BATTERIES; i++) {
202 if (!pbats[i]) 212 if (!pbats[i])
203 continue; 213 continue;
204 power_supply_unregister(&pbats[i]->bat); 214 power_supply_unregister(pbats[i]->bat);
205 kfree(pbats[i]); 215 kfree(pbats[i]);
206 } 216 }
207 power_supply_unregister(&pmu_ac); 217 power_supply_unregister(pmu_ac);
208 platform_device_unregister(bat_pdev); 218 platform_device_unregister(bat_pdev);
209} 219}
210 220
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 583dece8845b..e51405b176c8 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -40,16 +40,16 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,
40 40
41 /* Support both supplied_to and supplied_from modes */ 41 /* Support both supplied_to and supplied_from modes */
42 if (supply->supplied_from) { 42 if (supply->supplied_from) {
43 if (!supplier->name) 43 if (!supplier->desc->name)
44 return false; 44 return false;
45 for (i = 0; i < supply->num_supplies; i++) 45 for (i = 0; i < supply->num_supplies; i++)
46 if (!strcmp(supplier->name, supply->supplied_from[i])) 46 if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
47 return true; 47 return true;
48 } else { 48 } else {
49 if (!supply->name) 49 if (!supply->desc->name)
50 return false; 50 return false;
51 for (i = 0; i < supplier->num_supplicants; i++) 51 for (i = 0; i < supplier->num_supplicants; i++)
52 if (!strcmp(supplier->supplied_to[i], supply->name)) 52 if (!strcmp(supplier->supplied_to[i], supply->desc->name))
53 return true; 53 return true;
54 } 54 }
55 55
@@ -62,8 +62,8 @@ static int __power_supply_changed_work(struct device *dev, void *data)
62 struct power_supply *pst = dev_get_drvdata(dev); 62 struct power_supply *pst = dev_get_drvdata(dev);
63 63
64 if (__power_supply_is_supplied_by(psy, pst)) { 64 if (__power_supply_is_supplied_by(psy, pst)) {
65 if (pst->external_power_changed) 65 if (pst->desc->external_power_changed)
66 pst->external_power_changed(pst); 66 pst->desc->external_power_changed(pst);
67 } 67 }
68 68
69 return 0; 69 return 0;
@@ -75,7 +75,7 @@ static void power_supply_changed_work(struct work_struct *work)
75 struct power_supply *psy = container_of(work, struct power_supply, 75 struct power_supply *psy = container_of(work, struct power_supply,
76 changed_work); 76 changed_work);
77 77
78 dev_dbg(psy->dev, "%s\n", __func__); 78 dev_dbg(&psy->dev, "%s\n", __func__);
79 79
80 spin_lock_irqsave(&psy->changed_lock, flags); 80 spin_lock_irqsave(&psy->changed_lock, flags);
81 /* 81 /*
@@ -93,7 +93,7 @@ static void power_supply_changed_work(struct work_struct *work)
93 power_supply_update_leds(psy); 93 power_supply_update_leds(psy);
94 atomic_notifier_call_chain(&power_supply_notifier, 94 atomic_notifier_call_chain(&power_supply_notifier,
95 PSY_EVENT_PROP_CHANGED, psy); 95 PSY_EVENT_PROP_CHANGED, psy);
96 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); 96 kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
97 spin_lock_irqsave(&psy->changed_lock, flags); 97 spin_lock_irqsave(&psy->changed_lock, flags);
98 } 98 }
99 99
@@ -103,7 +103,7 @@ static void power_supply_changed_work(struct work_struct *work)
103 * to true. 103 * to true.
104 */ 104 */
105 if (likely(!psy->changed)) 105 if (likely(!psy->changed))
106 pm_relax(psy->dev); 106 pm_relax(&psy->dev);
107 spin_unlock_irqrestore(&psy->changed_lock, flags); 107 spin_unlock_irqrestore(&psy->changed_lock, flags);
108} 108}
109 109
@@ -111,11 +111,11 @@ void power_supply_changed(struct power_supply *psy)
111{ 111{
112 unsigned long flags; 112 unsigned long flags;
113 113
114 dev_dbg(psy->dev, "%s\n", __func__); 114 dev_dbg(&psy->dev, "%s\n", __func__);
115 115
116 spin_lock_irqsave(&psy->changed_lock, flags); 116 spin_lock_irqsave(&psy->changed_lock, flags);
117 psy->changed = true; 117 psy->changed = true;
118 pm_stay_awake(psy->dev); 118 pm_stay_awake(&psy->dev);
119 spin_unlock_irqrestore(&psy->changed_lock, flags); 119 spin_unlock_irqrestore(&psy->changed_lock, flags);
120 schedule_work(&psy->changed_work); 120 schedule_work(&psy->changed_work);
121} 121}
@@ -138,9 +138,9 @@ static int __power_supply_populate_supplied_from(struct device *dev,
138 break; 138 break;
139 139
140 if (np == epsy->of_node) { 140 if (np == epsy->of_node) {
141 dev_info(psy->dev, "%s: Found supply : %s\n", 141 dev_info(&psy->dev, "%s: Found supply : %s\n",
142 psy->name, epsy->name); 142 psy->desc->name, epsy->desc->name);
143 psy->supplied_from[i-1] = (char *)epsy->name; 143 psy->supplied_from[i-1] = (char *)epsy->desc->name;
144 psy->num_supplies++; 144 psy->num_supplies++;
145 of_node_put(np); 145 of_node_put(np);
146 break; 146 break;
@@ -158,7 +158,7 @@ static int power_supply_populate_supplied_from(struct power_supply *psy)
158 error = class_for_each_device(power_supply_class, NULL, psy, 158 error = class_for_each_device(power_supply_class, NULL, psy,
159 __power_supply_populate_supplied_from); 159 __power_supply_populate_supplied_from);
160 160
161 dev_dbg(psy->dev, "%s %d\n", __func__, error); 161 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
162 162
163 return error; 163 return error;
164} 164}
@@ -220,7 +220,7 @@ static int power_supply_check_supplies(struct power_supply *psy)
220 of_node_put(np); 220 of_node_put(np);
221 221
222 if (ret) { 222 if (ret) {
223 dev_dbg(psy->dev, "Failed to find supply!\n"); 223 dev_dbg(&psy->dev, "Failed to find supply!\n");
224 return ret; 224 return ret;
225 } 225 }
226 } while (np); 226 } while (np);
@@ -230,17 +230,18 @@ static int power_supply_check_supplies(struct power_supply *psy)
230 return 0; 230 return 0;
231 231
232 /* All supplies found, allocate char ** array for filling */ 232 /* All supplies found, allocate char ** array for filling */
233 psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from), 233 psy->supplied_from = devm_kzalloc(&psy->dev, sizeof(psy->supplied_from),
234 GFP_KERNEL); 234 GFP_KERNEL);
235 if (!psy->supplied_from) { 235 if (!psy->supplied_from) {
236 dev_err(psy->dev, "Couldn't allocate memory for supply list\n"); 236 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
237 return -ENOMEM; 237 return -ENOMEM;
238 } 238 }
239 239
240 *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1), 240 *psy->supplied_from = devm_kzalloc(&psy->dev,
241 sizeof(char *) * (cnt - 1),
241 GFP_KERNEL); 242 GFP_KERNEL);
242 if (!*psy->supplied_from) { 243 if (!*psy->supplied_from) {
243 dev_err(psy->dev, "Couldn't allocate memory for supply list\n"); 244 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
244 return -ENOMEM; 245 return -ENOMEM;
245 } 246 }
246 247
@@ -260,7 +261,8 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data)
260 struct power_supply *epsy = dev_get_drvdata(dev); 261 struct power_supply *epsy = dev_get_drvdata(dev);
261 262
262 if (__power_supply_is_supplied_by(epsy, psy)) 263 if (__power_supply_is_supplied_by(epsy, psy))
263 if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) 264 if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
265 &ret))
264 return ret.intval; 266 return ret.intval;
265 267
266 return 0; 268 return 0;
@@ -273,7 +275,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
273 error = class_for_each_device(power_supply_class, NULL, psy, 275 error = class_for_each_device(power_supply_class, NULL, psy,
274 __power_supply_am_i_supplied); 276 __power_supply_am_i_supplied);
275 277
276 dev_dbg(psy->dev, "%s %d\n", __func__, error); 278 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
277 279
278 return error; 280 return error;
279} 281}
@@ -286,8 +288,9 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data)
286 unsigned int *count = data; 288 unsigned int *count = data;
287 289
288 (*count)++; 290 (*count)++;
289 if (psy->type != POWER_SUPPLY_TYPE_BATTERY) 291 if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
290 if (!psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) 292 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
293 &ret))
291 return ret.intval; 294 return ret.intval;
292 295
293 return 0; 296 return 0;
@@ -315,9 +318,9 @@ EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
315int power_supply_set_battery_charged(struct power_supply *psy) 318int power_supply_set_battery_charged(struct power_supply *psy)
316{ 319{
317 if (atomic_read(&psy->use_cnt) >= 0 && 320 if (atomic_read(&psy->use_cnt) >= 0 &&
318 psy->type == POWER_SUPPLY_TYPE_BATTERY && 321 psy->desc->type == POWER_SUPPLY_TYPE_BATTERY &&
319 psy->set_charged) { 322 psy->desc->set_charged) {
320 psy->set_charged(psy); 323 psy->desc->set_charged(psy);
321 return 0; 324 return 0;
322 } 325 }
323 326
@@ -330,7 +333,7 @@ static int power_supply_match_device_by_name(struct device *dev, const void *dat
330 const char *name = data; 333 const char *name = data;
331 struct power_supply *psy = dev_get_drvdata(dev); 334 struct power_supply *psy = dev_get_drvdata(dev);
332 335
333 return strcmp(psy->name, name) == 0; 336 return strcmp(psy->desc->name, name) == 0;
334} 337}
335 338
336struct power_supply *power_supply_get_by_name(const char *name) 339struct power_supply *power_supply_get_by_name(const char *name)
@@ -375,7 +378,7 @@ int power_supply_get_property(struct power_supply *psy,
375 if (atomic_read(&psy->use_cnt) <= 0) 378 if (atomic_read(&psy->use_cnt) <= 0)
376 return -ENODEV; 379 return -ENODEV;
377 380
378 return psy->get_property(psy, psp, val); 381 return psy->desc->get_property(psy, psp, val);
379} 382}
380EXPORT_SYMBOL_GPL(power_supply_get_property); 383EXPORT_SYMBOL_GPL(power_supply_get_property);
381 384
@@ -383,42 +386,45 @@ int power_supply_set_property(struct power_supply *psy,
383 enum power_supply_property psp, 386 enum power_supply_property psp,
384 const union power_supply_propval *val) 387 const union power_supply_propval *val)
385{ 388{
386 if (atomic_read(&psy->use_cnt) <= 0 || !psy->set_property) 389 if (atomic_read(&psy->use_cnt) <= 0 || !psy->desc->set_property)
387 return -ENODEV; 390 return -ENODEV;
388 391
389 return psy->set_property(psy, psp, val); 392 return psy->desc->set_property(psy, psp, val);
390} 393}
391EXPORT_SYMBOL_GPL(power_supply_set_property); 394EXPORT_SYMBOL_GPL(power_supply_set_property);
392 395
393int power_supply_property_is_writeable(struct power_supply *psy, 396int power_supply_property_is_writeable(struct power_supply *psy,
394 enum power_supply_property psp) 397 enum power_supply_property psp)
395{ 398{
396 if (atomic_read(&psy->use_cnt) <= 0 || !psy->property_is_writeable) 399 if (atomic_read(&psy->use_cnt) <= 0 ||
400 !psy->desc->property_is_writeable)
397 return -ENODEV; 401 return -ENODEV;
398 402
399 return psy->property_is_writeable(psy, psp); 403 return psy->desc->property_is_writeable(psy, psp);
400} 404}
401EXPORT_SYMBOL_GPL(power_supply_property_is_writeable); 405EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
402 406
403void power_supply_external_power_changed(struct power_supply *psy) 407void power_supply_external_power_changed(struct power_supply *psy)
404{ 408{
405 if (atomic_read(&psy->use_cnt) <= 0 || !psy->external_power_changed) 409 if (atomic_read(&psy->use_cnt) <= 0 ||
410 !psy->desc->external_power_changed)
406 return; 411 return;
407 412
408 psy->external_power_changed(psy); 413 psy->desc->external_power_changed(psy);
409} 414}
410EXPORT_SYMBOL_GPL(power_supply_external_power_changed); 415EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
411 416
412int power_supply_powers(struct power_supply *psy, struct device *dev) 417int power_supply_powers(struct power_supply *psy, struct device *dev)
413{ 418{
414 return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); 419 return sysfs_create_link(&psy->dev.kobj, &dev->kobj, "powers");
415} 420}
416EXPORT_SYMBOL_GPL(power_supply_powers); 421EXPORT_SYMBOL_GPL(power_supply_powers);
417 422
418static void power_supply_dev_release(struct device *dev) 423static void power_supply_dev_release(struct device *dev)
419{ 424{
425 struct power_supply *psy = container_of(dev, struct power_supply, dev);
420 pr_debug("device: '%s': %s\n", dev_name(dev), __func__); 426 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
421 kfree(dev); 427 kfree(psy);
422} 428}
423 429
424int power_supply_reg_notifier(struct notifier_block *nb) 430int power_supply_reg_notifier(struct notifier_block *nb)
@@ -443,7 +449,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
443 449
444 WARN_ON(tzd == NULL); 450 WARN_ON(tzd == NULL);
445 psy = tzd->devdata; 451 psy = tzd->devdata;
446 ret = psy->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val); 452 ret = psy->desc->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
447 453
448 /* Convert tenths of degree Celsius to milli degree Celsius. */ 454 /* Convert tenths of degree Celsius to milli degree Celsius. */
449 if (!ret) 455 if (!ret)
@@ -460,14 +466,14 @@ static int psy_register_thermal(struct power_supply *psy)
460{ 466{
461 int i; 467 int i;
462 468
463 if (psy->no_thermal) 469 if (psy->desc->no_thermal)
464 return 0; 470 return 0;
465 471
466 /* Register battery zone device psy reports temperature */ 472 /* Register battery zone device psy reports temperature */
467 for (i = 0; i < psy->num_properties; i++) { 473 for (i = 0; i < psy->desc->num_properties; i++) {
468 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { 474 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
469 psy->tzd = thermal_zone_device_register(psy->name, 0, 0, 475 psy->tzd = thermal_zone_device_register(psy->desc->name,
470 psy, &psy_tzd_ops, NULL, 0, 0); 476 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
471 return PTR_ERR_OR_ZERO(psy->tzd); 477 return PTR_ERR_OR_ZERO(psy->tzd);
472 } 478 }
473 } 479 }
@@ -490,7 +496,7 @@ static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
490 int ret; 496 int ret;
491 497
492 psy = tcd->devdata; 498 psy = tcd->devdata;
493 ret = psy->get_property(psy, 499 ret = psy->desc->get_property(psy,
494 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val); 500 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
495 if (!ret) 501 if (!ret)
496 *state = val.intval; 502 *state = val.intval;
@@ -506,7 +512,7 @@ static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
506 int ret; 512 int ret;
507 513
508 psy = tcd->devdata; 514 psy = tcd->devdata;
509 ret = psy->get_property(psy, 515 ret = psy->desc->get_property(psy,
510 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val); 516 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
511 if (!ret) 517 if (!ret)
512 *state = val.intval; 518 *state = val.intval;
@@ -523,7 +529,7 @@ static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
523 529
524 psy = tcd->devdata; 530 psy = tcd->devdata;
525 val.intval = state; 531 val.intval = state;
526 ret = psy->set_property(psy, 532 ret = psy->desc->set_property(psy,
527 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val); 533 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
528 534
529 return ret; 535 return ret;
@@ -540,11 +546,11 @@ static int psy_register_cooler(struct power_supply *psy)
540 int i; 546 int i;
541 547
542 /* Register for cooling device if psy can control charging */ 548 /* Register for cooling device if psy can control charging */
543 for (i = 0; i < psy->num_properties; i++) { 549 for (i = 0; i < psy->desc->num_properties; i++) {
544 if (psy->properties[i] == 550 if (psy->desc->properties[i] ==
545 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) { 551 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
546 psy->tcd = thermal_cooling_device_register( 552 psy->tcd = thermal_cooling_device_register(
547 (char *)psy->name, 553 (char *)psy->desc->name,
548 psy, &psy_tcd_ops); 554 psy, &psy_tcd_ops);
549 return PTR_ERR_OR_ZERO(psy->tcd); 555 return PTR_ERR_OR_ZERO(psy->tcd);
550 } 556 }
@@ -578,17 +584,21 @@ static void psy_unregister_cooler(struct power_supply *psy)
578} 584}
579#endif 585#endif
580 586
581static int __power_supply_register(struct device *parent, 587static struct power_supply *__must_check
582 struct power_supply *psy, 588__power_supply_register(struct device *parent,
589 const struct power_supply_desc *desc,
583 const struct power_supply_config *cfg, 590 const struct power_supply_config *cfg,
584 bool ws) 591 bool ws)
585{ 592{
586 struct device *dev; 593 struct device *dev;
594 struct power_supply *psy;
587 int rc; 595 int rc;
588 596
589 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 597 psy = kzalloc(sizeof(*psy), GFP_KERNEL);
590 if (!dev) 598 if (!psy)
591 return -ENOMEM; 599 return ERR_PTR(-ENOMEM);
600
601 dev = &psy->dev;
592 602
593 device_initialize(dev); 603 device_initialize(dev);
594 604
@@ -597,7 +607,7 @@ static int __power_supply_register(struct device *parent,
597 dev->parent = parent; 607 dev->parent = parent;
598 dev->release = power_supply_dev_release; 608 dev->release = power_supply_dev_release;
599 dev_set_drvdata(dev, psy); 609 dev_set_drvdata(dev, psy);
600 psy->dev = dev; 610 psy->desc = desc;
601 atomic_inc(&psy->use_cnt); 611 atomic_inc(&psy->use_cnt);
602 if (cfg) { 612 if (cfg) {
603 psy->drv_data = cfg->drv_data; 613 psy->drv_data = cfg->drv_data;
@@ -606,7 +616,7 @@ static int __power_supply_register(struct device *parent,
606 psy->num_supplicants = cfg->num_supplicants; 616 psy->num_supplicants = cfg->num_supplicants;
607 } 617 }
608 618
609 rc = dev_set_name(dev, "%s", psy->name); 619 rc = dev_set_name(dev, "%s", desc->name);
610 if (rc) 620 if (rc)
611 goto dev_set_name_failed; 621 goto dev_set_name_failed;
612 622
@@ -641,7 +651,7 @@ static int __power_supply_register(struct device *parent,
641 651
642 power_supply_changed(psy); 652 power_supply_changed(psy);
643 653
644 return 0; 654 return psy;
645 655
646create_triggers_failed: 656create_triggers_failed:
647 psy_unregister_cooler(psy); 657 psy_unregister_cooler(psy);
@@ -654,20 +664,49 @@ wakeup_init_failed:
654check_supplies_failed: 664check_supplies_failed:
655dev_set_name_failed: 665dev_set_name_failed:
656 put_device(dev); 666 put_device(dev);
657 return rc; 667 return ERR_PTR(rc);
658} 668}
659 669
660int power_supply_register(struct device *parent, struct power_supply *psy, 670/**
671 * power_supply_register() - Register new power supply
672 * @parent: Device to be a parent of power supply's device
673 * @desc: Description of power supply, must be valid through whole
674 * lifetime of this power supply
675 * @cfg: Run-time specific configuration accessed during registering,
676 * may be NULL
677 *
678 * Return: A pointer to newly allocated power_supply on success
679 * or ERR_PTR otherwise.
680 * Use power_supply_unregister() on returned power_supply pointer to release
681 * resources.
682 */
683struct power_supply *__must_check power_supply_register(struct device *parent,
684 const struct power_supply_desc *desc,
661 const struct power_supply_config *cfg) 685 const struct power_supply_config *cfg)
662{ 686{
663 return __power_supply_register(parent, psy, cfg, true); 687 return __power_supply_register(parent, desc, cfg, true);
664} 688}
665EXPORT_SYMBOL_GPL(power_supply_register); 689EXPORT_SYMBOL_GPL(power_supply_register);
666 690
667int power_supply_register_no_ws(struct device *parent, struct power_supply *psy, 691/**
692 * power_supply_register() - Register new non-waking-source power supply
693 * @parent: Device to be a parent of power supply's device
694 * @desc: Description of power supply, must be valid through whole
695 * lifetime of this power supply
696 * @cfg: Run-time specific configuration accessed during registering,
697 * may be NULL
698 *
699 * Return: A pointer to newly allocated power_supply on success
700 * or ERR_PTR otherwise.
701 * Use power_supply_unregister() on returned power_supply pointer to release
702 * resources.
703 */
704struct power_supply *__must_check
705power_supply_register_no_ws(struct device *parent,
706 const struct power_supply_desc *desc,
668 const struct power_supply_config *cfg) 707 const struct power_supply_config *cfg)
669{ 708{
670 return __power_supply_register(parent, psy, cfg, false); 709 return __power_supply_register(parent, desc, cfg, false);
671} 710}
672EXPORT_SYMBOL_GPL(power_supply_register_no_ws); 711EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
673 712
@@ -678,56 +717,93 @@ static void devm_power_supply_release(struct device *dev, void *res)
678 power_supply_unregister(*psy); 717 power_supply_unregister(*psy);
679} 718}
680 719
681int devm_power_supply_register(struct device *parent, struct power_supply *psy, 720/**
721 * power_supply_register() - Register managed power supply
722 * @parent: Device to be a parent of power supply's device
723 * @desc: Description of power supply, must be valid through whole
724 * lifetime of this power supply
725 * @cfg: Run-time specific configuration accessed during registering,
726 * may be NULL
727 *
728 * Return: A pointer to newly allocated power_supply on success
729 * or ERR_PTR otherwise.
730 * The returned power_supply pointer will be automatically unregistered
731 * on driver detach.
732 */
733struct power_supply *__must_check
734devm_power_supply_register(struct device *parent,
735 const struct power_supply_desc *desc,
682 const struct power_supply_config *cfg) 736 const struct power_supply_config *cfg)
683{ 737{
684 struct power_supply **ptr = devres_alloc(devm_power_supply_release, 738 struct power_supply **ptr, *psy;
685 sizeof(*ptr), GFP_KERNEL); 739
686 int ret; 740 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
687 741
688 if (!ptr) 742 if (!ptr)
689 return -ENOMEM; 743 return ERR_PTR(-ENOMEM);
690 ret = __power_supply_register(parent, psy, cfg, true); 744 psy = __power_supply_register(parent, desc, cfg, true);
691 if (ret < 0) 745 if (IS_ERR(psy)) {
692 devres_free(ptr); 746 devres_free(ptr);
693 else { 747 } else {
694 *ptr = psy; 748 *ptr = psy;
695 devres_add(parent, ptr); 749 devres_add(parent, ptr);
696 } 750 }
697 return ret; 751 return psy;
698} 752}
699EXPORT_SYMBOL_GPL(devm_power_supply_register); 753EXPORT_SYMBOL_GPL(devm_power_supply_register);
700 754
701int devm_power_supply_register_no_ws(struct device *parent, struct power_supply *psy, 755/**
756 * power_supply_register() - Register managed non-waking-source power supply
757 * @parent: Device to be a parent of power supply's device
758 * @desc: Description of power supply, must be valid through whole
759 * lifetime of this power supply
760 * @cfg: Run-time specific configuration accessed during registering,
761 * may be NULL
762 *
763 * Return: A pointer to newly allocated power_supply on success
764 * or ERR_PTR otherwise.
765 * The returned power_supply pointer will be automatically unregistered
766 * on driver detach.
767 */
768struct power_supply *__must_check
769devm_power_supply_register_no_ws(struct device *parent,
770 const struct power_supply_desc *desc,
702 const struct power_supply_config *cfg) 771 const struct power_supply_config *cfg)
703{ 772{
704 struct power_supply **ptr = devres_alloc(devm_power_supply_release, 773 struct power_supply **ptr, *psy;
705 sizeof(*ptr), GFP_KERNEL); 774
706 int ret; 775 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
707 776
708 if (!ptr) 777 if (!ptr)
709 return -ENOMEM; 778 return ERR_PTR(-ENOMEM);
710 ret = __power_supply_register(parent, psy, cfg, false); 779 psy = __power_supply_register(parent, desc, cfg, false);
711 if (ret < 0) 780 if (IS_ERR(psy)) {
712 devres_free(ptr); 781 devres_free(ptr);
713 else { 782 } else {
714 *ptr = psy; 783 *ptr = psy;
715 devres_add(parent, ptr); 784 devres_add(parent, ptr);
716 } 785 }
717 return ret; 786 return psy;
718} 787}
719EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws); 788EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
720 789
790/**
791 * power_supply_unregister() - Remove this power supply from system
792 * @psy: Pointer to power supply to unregister
793 *
794 * Remove this power supply from the system. The resources of power supply
795 * will be freed here or on last power_supply_put() call.
796 */
721void power_supply_unregister(struct power_supply *psy) 797void power_supply_unregister(struct power_supply *psy)
722{ 798{
723 WARN_ON(atomic_dec_return(&psy->use_cnt)); 799 WARN_ON(atomic_dec_return(&psy->use_cnt));
724 cancel_work_sync(&psy->changed_work); 800 cancel_work_sync(&psy->changed_work);
725 sysfs_remove_link(&psy->dev->kobj, "powers"); 801 sysfs_remove_link(&psy->dev.kobj, "powers");
726 power_supply_remove_triggers(psy); 802 power_supply_remove_triggers(psy);
727 psy_unregister_cooler(psy); 803 psy_unregister_cooler(psy);
728 psy_unregister_thermal(psy); 804 psy_unregister_thermal(psy);
729 device_init_wakeup(psy->dev, false); 805 device_init_wakeup(&psy->dev, false);
730 device_unregister(psy->dev); 806 device_unregister(&psy->dev);
731} 807}
732EXPORT_SYMBOL_GPL(power_supply_unregister); 808EXPORT_SYMBOL_GPL(power_supply_unregister);
733 809
diff --git a/drivers/power/power_supply_leds.c b/drivers/power/power_supply_leds.c
index effa093c37b0..2d41a43fc81a 100644
--- a/drivers/power/power_supply_leds.c
+++ b/drivers/power/power_supply_leds.c
@@ -25,10 +25,10 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
25 unsigned long delay_on = 0; 25 unsigned long delay_on = 0;
26 unsigned long delay_off = 0; 26 unsigned long delay_off = 0;
27 27
28 if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status)) 28 if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
29 return; 29 return;
30 30
31 dev_dbg(psy->dev, "%s %d\n", __func__, status.intval); 31 dev_dbg(&psy->dev, "%s %d\n", __func__, status.intval);
32 32
33 switch (status.intval) { 33 switch (status.intval) {
34 case POWER_SUPPLY_STATUS_FULL: 34 case POWER_SUPPLY_STATUS_FULL:
@@ -58,21 +58,21 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
58static int power_supply_create_bat_triggers(struct power_supply *psy) 58static int power_supply_create_bat_triggers(struct power_supply *psy)
59{ 59{
60 psy->charging_full_trig_name = kasprintf(GFP_KERNEL, 60 psy->charging_full_trig_name = kasprintf(GFP_KERNEL,
61 "%s-charging-or-full", psy->name); 61 "%s-charging-or-full", psy->desc->name);
62 if (!psy->charging_full_trig_name) 62 if (!psy->charging_full_trig_name)
63 goto charging_full_failed; 63 goto charging_full_failed;
64 64
65 psy->charging_trig_name = kasprintf(GFP_KERNEL, 65 psy->charging_trig_name = kasprintf(GFP_KERNEL,
66 "%s-charging", psy->name); 66 "%s-charging", psy->desc->name);
67 if (!psy->charging_trig_name) 67 if (!psy->charging_trig_name)
68 goto charging_failed; 68 goto charging_failed;
69 69
70 psy->full_trig_name = kasprintf(GFP_KERNEL, "%s-full", psy->name); 70 psy->full_trig_name = kasprintf(GFP_KERNEL, "%s-full", psy->desc->name);
71 if (!psy->full_trig_name) 71 if (!psy->full_trig_name)
72 goto full_failed; 72 goto full_failed;
73 73
74 psy->charging_blink_full_solid_trig_name = kasprintf(GFP_KERNEL, 74 psy->charging_blink_full_solid_trig_name = kasprintf(GFP_KERNEL,
75 "%s-charging-blink-full-solid", psy->name); 75 "%s-charging-blink-full-solid", psy->desc->name);
76 if (!psy->charging_blink_full_solid_trig_name) 76 if (!psy->charging_blink_full_solid_trig_name)
77 goto charging_blink_full_solid_failed; 77 goto charging_blink_full_solid_failed;
78 78
@@ -115,10 +115,10 @@ static void power_supply_update_gen_leds(struct power_supply *psy)
115{ 115{
116 union power_supply_propval online; 116 union power_supply_propval online;
117 117
118 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online)) 118 if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
119 return; 119 return;
120 120
121 dev_dbg(psy->dev, "%s %d\n", __func__, online.intval); 121 dev_dbg(&psy->dev, "%s %d\n", __func__, online.intval);
122 122
123 if (online.intval) 123 if (online.intval)
124 led_trigger_event(psy->online_trig, LED_FULL); 124 led_trigger_event(psy->online_trig, LED_FULL);
@@ -128,7 +128,8 @@ static void power_supply_update_gen_leds(struct power_supply *psy)
128 128
129static int power_supply_create_gen_triggers(struct power_supply *psy) 129static int power_supply_create_gen_triggers(struct power_supply *psy)
130{ 130{
131 psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name); 131 psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online",
132 psy->desc->name);
132 if (!psy->online_trig_name) 133 if (!psy->online_trig_name)
133 return -ENOMEM; 134 return -ENOMEM;
134 135
@@ -147,7 +148,7 @@ static void power_supply_remove_gen_triggers(struct power_supply *psy)
147 148
148void power_supply_update_leds(struct power_supply *psy) 149void power_supply_update_leds(struct power_supply *psy)
149{ 150{
150 if (psy->type == POWER_SUPPLY_TYPE_BATTERY) 151 if (psy->desc->type == POWER_SUPPLY_TYPE_BATTERY)
151 power_supply_update_bat_leds(psy); 152 power_supply_update_bat_leds(psy);
152 else 153 else
153 power_supply_update_gen_leds(psy); 154 power_supply_update_gen_leds(psy);
@@ -155,14 +156,14 @@ void power_supply_update_leds(struct power_supply *psy)
155 156
156int power_supply_create_triggers(struct power_supply *psy) 157int power_supply_create_triggers(struct power_supply *psy)
157{ 158{
158 if (psy->type == POWER_SUPPLY_TYPE_BATTERY) 159 if (psy->desc->type == POWER_SUPPLY_TYPE_BATTERY)
159 return power_supply_create_bat_triggers(psy); 160 return power_supply_create_bat_triggers(psy);
160 return power_supply_create_gen_triggers(psy); 161 return power_supply_create_gen_triggers(psy);
161} 162}
162 163
163void power_supply_remove_triggers(struct power_supply *psy) 164void power_supply_remove_triggers(struct power_supply *psy)
164{ 165{
165 if (psy->type == POWER_SUPPLY_TYPE_BATTERY) 166 if (psy->desc->type == POWER_SUPPLY_TYPE_BATTERY)
166 power_supply_remove_bat_triggers(psy); 167 power_supply_remove_bat_triggers(psy);
167 else 168 else
168 power_supply_remove_gen_triggers(psy); 169 power_supply_remove_gen_triggers(psy);
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index f817aab80813..9134e3d2d95e 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -74,7 +74,7 @@ static ssize_t power_supply_show_property(struct device *dev,
74 union power_supply_propval value; 74 union power_supply_propval value;
75 75
76 if (off == POWER_SUPPLY_PROP_TYPE) { 76 if (off == POWER_SUPPLY_PROP_TYPE) {
77 value.intval = psy->type; 77 value.intval = psy->desc->type;
78 } else { 78 } else {
79 ret = power_supply_get_property(psy, off, &value); 79 ret = power_supply_get_property(psy, off, &value);
80 80
@@ -125,7 +125,7 @@ static ssize_t power_supply_store_property(struct device *dev,
125 125
126 value.intval = long_val; 126 value.intval = long_val;
127 127
128 ret = power_supply_set_property(psy, off, &value); 128 ret = psy->desc->set_property(psy, off, &value);
129 if (ret < 0) 129 if (ret < 0)
130 return ret; 130 return ret;
131 131
@@ -218,11 +218,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
218 if (attrno == POWER_SUPPLY_PROP_TYPE) 218 if (attrno == POWER_SUPPLY_PROP_TYPE)
219 return mode; 219 return mode;
220 220
221 for (i = 0; i < psy->num_properties; i++) { 221 for (i = 0; i < psy->desc->num_properties; i++) {
222 int property = psy->properties[i]; 222 int property = psy->desc->properties[i];
223 223
224 if (property == attrno) { 224 if (property == attrno) {
225 if (psy->property_is_writeable && 225 if (psy->desc->property_is_writeable &&
226 power_supply_property_is_writeable(psy, property) > 0) 226 power_supply_property_is_writeable(psy, property) > 0)
227 mode |= S_IWUSR; 227 mode |= S_IWUSR;
228 228
@@ -279,14 +279,14 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
279 279
280 dev_dbg(dev, "uevent\n"); 280 dev_dbg(dev, "uevent\n");
281 281
282 if (!psy || !psy->dev) { 282 if (!psy || !psy->desc) {
283 dev_dbg(dev, "No power supply yet\n"); 283 dev_dbg(dev, "No power supply yet\n");
284 return ret; 284 return ret;
285 } 285 }
286 286
287 dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->name); 287 dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->desc->name);
288 288
289 ret = add_uevent_var(env, "POWER_SUPPLY_NAME=%s", psy->name); 289 ret = add_uevent_var(env, "POWER_SUPPLY_NAME=%s", psy->desc->name);
290 if (ret) 290 if (ret)
291 return ret; 291 return ret;
292 292
@@ -294,11 +294,11 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
294 if (!prop_buf) 294 if (!prop_buf)
295 return -ENOMEM; 295 return -ENOMEM;
296 296
297 for (j = 0; j < psy->num_properties; j++) { 297 for (j = 0; j < psy->desc->num_properties; j++) {
298 struct device_attribute *attr; 298 struct device_attribute *attr;
299 char *line; 299 char *line;
300 300
301 attr = &power_supply_attrs[psy->properties[j]]; 301 attr = &power_supply_attrs[psy->desc->properties[j]];
302 302
303 ret = power_supply_show_property(dev, attr, prop_buf); 303 ret = power_supply_show_property(dev, attr, prop_buf);
304 if (ret == -ENODEV || ret == -ENODATA) { 304 if (ret == -ENODEV || ret == -ENODATA) {
diff --git a/drivers/power/rt5033_battery.c b/drivers/power/rt5033_battery.c
index 8cf000baaf36..a7a6877b4e16 100644
--- a/drivers/power/rt5033_battery.c
+++ b/drivers/power/rt5033_battery.c
@@ -72,8 +72,7 @@ static int rt5033_battery_get_property(struct power_supply *psy,
72 enum power_supply_property psp, 72 enum power_supply_property psp,
73 union power_supply_propval *val) 73 union power_supply_propval *val)
74{ 74{
75 struct rt5033_battery *battery = container_of(psy, 75 struct rt5033_battery *battery = power_supply_get_drvdata(psy);
76 struct rt5033_battery, psy);
77 76
78 switch (psp) { 77 switch (psp) {
79 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 78 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
@@ -108,10 +107,19 @@ static const struct regmap_config rt5033_battery_regmap_config = {
108 .max_register = RT5033_FUEL_REG_END, 107 .max_register = RT5033_FUEL_REG_END,
109}; 108};
110 109
110static const struct power_supply_desc rt5033_battery_desc = {
111 .name = "rt5033-battery",
112 .type = POWER_SUPPLY_TYPE_BATTERY,
113 .get_property = rt5033_battery_get_property,
114 .properties = rt5033_battery_props,
115 .num_properties = ARRAY_SIZE(rt5033_battery_props),
116};
117
111static int rt5033_battery_probe(struct i2c_client *client, 118static int rt5033_battery_probe(struct i2c_client *client,
112 const struct i2c_device_id *id) 119 const struct i2c_device_id *id)
113{ 120{
114 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 121 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
122 struct power_supply_config psy_cfg = {};
115 struct rt5033_battery *battery; 123 struct rt5033_battery *battery;
116 u32 ret; 124 u32 ret;
117 125
@@ -131,16 +139,13 @@ static int rt5033_battery_probe(struct i2c_client *client,
131 } 139 }
132 140
133 i2c_set_clientdata(client, battery); 141 i2c_set_clientdata(client, battery);
142 psy_cfg.drv_data = battery;
134 143
135 battery->psy.name = "rt5033-battery"; 144 battery->psy = power_supply_register(&client->dev,
136 battery->psy.type = POWER_SUPPLY_TYPE_BATTERY; 145 &rt5033_battery_desc, &psy_cfg);
137 battery->psy.get_property = rt5033_battery_get_property; 146 if (IS_ERR(battery->psy)) {
138 battery->psy.properties = rt5033_battery_props;
139 battery->psy.num_properties = ARRAY_SIZE(rt5033_battery_props);
140
141 ret = power_supply_register(&client->dev, &battery->psy, NULL);
142 if (ret) {
143 dev_err(&client->dev, "Failed to register power supply\n"); 147 dev_err(&client->dev, "Failed to register power supply\n");
148 ret = PTR_ERR(battery->psy);
144 return ret; 149 return ret;
145 } 150 }
146 151
@@ -151,7 +156,7 @@ static int rt5033_battery_remove(struct i2c_client *client)
151{ 156{
152 struct rt5033_battery *battery = i2c_get_clientdata(client); 157 struct rt5033_battery *battery = i2c_get_clientdata(client);
153 158
154 power_supply_unregister(&battery->psy); 159 power_supply_unregister(battery->psy);
155 160
156 return 0; 161 return 0;
157} 162}
diff --git a/drivers/power/rx51_battery.c b/drivers/power/rx51_battery.c
index 804f60c7b715..ac6206951d58 100644
--- a/drivers/power/rx51_battery.c
+++ b/drivers/power/rx51_battery.c
@@ -29,7 +29,8 @@
29 29
30struct rx51_device_info { 30struct rx51_device_info {
31 struct device *dev; 31 struct device *dev;
32 struct power_supply bat; 32 struct power_supply *bat;
33 struct power_supply_desc bat_desc;
33 struct iio_channel *channel_temp; 34 struct iio_channel *channel_temp;
34 struct iio_channel *channel_bsi; 35 struct iio_channel *channel_bsi;
35 struct iio_channel *channel_vbat; 36 struct iio_channel *channel_vbat;
@@ -161,8 +162,7 @@ static int rx51_battery_get_property(struct power_supply *psy,
161 enum power_supply_property psp, 162 enum power_supply_property psp,
162 union power_supply_propval *val) 163 union power_supply_propval *val)
163{ 164{
164 struct rx51_device_info *di = container_of((psy), 165 struct rx51_device_info *di = power_supply_get_drvdata(psy);
165 struct rx51_device_info, bat);
166 166
167 switch (psp) { 167 switch (psp) {
168 case POWER_SUPPLY_PROP_TECHNOLOGY: 168 case POWER_SUPPLY_PROP_TECHNOLOGY:
@@ -204,6 +204,7 @@ static enum power_supply_property rx51_battery_props[] = {
204 204
205static int rx51_battery_probe(struct platform_device *pdev) 205static int rx51_battery_probe(struct platform_device *pdev)
206{ 206{
207 struct power_supply_config psy_cfg = {};
207 struct rx51_device_info *di; 208 struct rx51_device_info *di;
208 int ret; 209 int ret;
209 210
@@ -214,11 +215,13 @@ static int rx51_battery_probe(struct platform_device *pdev)
214 platform_set_drvdata(pdev, di); 215 platform_set_drvdata(pdev, di);
215 216
216 di->dev = &pdev->dev; 217 di->dev = &pdev->dev;
217 di->bat.name = dev_name(&pdev->dev); 218 di->bat_desc.name = dev_name(&pdev->dev);
218 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 219 di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
219 di->bat.properties = rx51_battery_props; 220 di->bat_desc.properties = rx51_battery_props;
220 di->bat.num_properties = ARRAY_SIZE(rx51_battery_props); 221 di->bat_desc.num_properties = ARRAY_SIZE(rx51_battery_props);
221 di->bat.get_property = rx51_battery_get_property; 222 di->bat_desc.get_property = rx51_battery_get_property;
223
224 psy_cfg.drv_data = di;
222 225
223 di->channel_temp = iio_channel_get(di->dev, "temp"); 226 di->channel_temp = iio_channel_get(di->dev, "temp");
224 if (IS_ERR(di->channel_temp)) { 227 if (IS_ERR(di->channel_temp)) {
@@ -238,9 +241,11 @@ static int rx51_battery_probe(struct platform_device *pdev)
238 goto error_channel_bsi; 241 goto error_channel_bsi;
239 } 242 }
240 243
241 ret = power_supply_register(di->dev, &di->bat, NULL); 244 di->bat = power_supply_register(di->dev, &di->bat_desc, &psy_cfg);
242 if (ret) 245 if (IS_ERR(di->bat)) {
246 ret = PTR_ERR(di->bat);
243 goto error_channel_vbat; 247 goto error_channel_vbat;
248 }
244 249
245 return 0; 250 return 0;
246 251
@@ -259,7 +264,7 @@ static int rx51_battery_remove(struct platform_device *pdev)
259{ 264{
260 struct rx51_device_info *di = platform_get_drvdata(pdev); 265 struct rx51_device_info *di = platform_get_drvdata(pdev);
261 266
262 power_supply_unregister(&di->bat); 267 power_supply_unregister(di->bat);
263 268
264 iio_channel_release(di->channel_vbat); 269 iio_channel_release(di->channel_vbat);
265 iio_channel_release(di->channel_bsi); 270 iio_channel_release(di->channel_bsi);
diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
index b6ff213373dd..0ffe5cd3abf6 100644
--- a/drivers/power/s3c_adc_battery.c
+++ b/drivers/power/s3c_adc_battery.c
@@ -28,7 +28,7 @@
28#define JITTER_DELAY 500 /* ms */ 28#define JITTER_DELAY 500 /* ms */
29 29
30struct s3c_adc_bat { 30struct s3c_adc_bat {
31 struct power_supply psy; 31 struct power_supply *psy;
32 struct s3c_adc_client *client; 32 struct s3c_adc_client *client;
33 struct s3c_adc_bat_pdata *pdata; 33 struct s3c_adc_bat_pdata *pdata;
34 int volt_value; 34 int volt_value;
@@ -73,10 +73,10 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
73 enum power_supply_property psp, 73 enum power_supply_property psp,
74 union power_supply_propval *val) 74 union power_supply_propval *val)
75{ 75{
76 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy); 76 struct s3c_adc_bat *bat = power_supply_get_drvdata(psy);
77 77
78 if (!bat) { 78 if (!bat) {
79 dev_err(psy->dev, "%s: no battery infos ?!\n", __func__); 79 dev_err(&psy->dev, "%s: no battery infos ?!\n", __func__);
80 return -EINVAL; 80 return -EINVAL;
81 } 81 }
82 82
@@ -105,17 +105,17 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
105 } 105 }
106} 106}
107 107
108static struct s3c_adc_bat backup_bat = { 108static const struct power_supply_desc backup_bat_desc = {
109 .psy = { 109 .name = "backup-battery",
110 .name = "backup-battery", 110 .type = POWER_SUPPLY_TYPE_BATTERY,
111 .type = POWER_SUPPLY_TYPE_BATTERY, 111 .properties = s3c_adc_backup_bat_props,
112 .properties = s3c_adc_backup_bat_props, 112 .num_properties = ARRAY_SIZE(s3c_adc_backup_bat_props),
113 .num_properties = ARRAY_SIZE(s3c_adc_backup_bat_props), 113 .get_property = s3c_adc_backup_bat_get_property,
114 .get_property = s3c_adc_backup_bat_get_property, 114 .use_for_apm = 1,
115 .use_for_apm = 1,
116 },
117}; 115};
118 116
117static struct s3c_adc_bat backup_bat;
118
119static enum power_supply_property s3c_adc_main_bat_props[] = { 119static enum power_supply_property s3c_adc_main_bat_props[] = {
120 POWER_SUPPLY_PROP_STATUS, 120 POWER_SUPPLY_PROP_STATUS,
121 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 121 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
@@ -141,7 +141,7 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
141 enum power_supply_property psp, 141 enum power_supply_property psp,
142 union power_supply_propval *val) 142 union power_supply_propval *val)
143{ 143{
144 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy); 144 struct s3c_adc_bat *bat = power_supply_get_drvdata(psy);
145 145
146 int new_level; 146 int new_level;
147 int full_volt; 147 int full_volt;
@@ -149,7 +149,7 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
149 unsigned int lut_size; 149 unsigned int lut_size;
150 150
151 if (!bat) { 151 if (!bat) {
152 dev_err(psy->dev, "no battery infos ?!\n"); 152 dev_err(&psy->dev, "no battery infos ?!\n");
153 return -EINVAL; 153 return -EINVAL;
154 } 154 }
155 155
@@ -232,18 +232,18 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
232 } 232 }
233} 233}
234 234
235static struct s3c_adc_bat main_bat = { 235static const struct power_supply_desc main_bat_desc = {
236 .psy = { 236 .name = "main-battery",
237 .name = "main-battery", 237 .type = POWER_SUPPLY_TYPE_BATTERY,
238 .type = POWER_SUPPLY_TYPE_BATTERY, 238 .properties = s3c_adc_main_bat_props,
239 .properties = s3c_adc_main_bat_props, 239 .num_properties = ARRAY_SIZE(s3c_adc_main_bat_props),
240 .num_properties = ARRAY_SIZE(s3c_adc_main_bat_props), 240 .get_property = s3c_adc_bat_get_property,
241 .get_property = s3c_adc_bat_get_property, 241 .external_power_changed = s3c_adc_bat_ext_power_changed,
242 .external_power_changed = s3c_adc_bat_ext_power_changed, 242 .use_for_apm = 1,
243 .use_for_apm = 1,
244 },
245}; 243};
246 244
245static struct s3c_adc_bat main_bat;
246
247static void s3c_adc_bat_work(struct work_struct *work) 247static void s3c_adc_bat_work(struct work_struct *work)
248{ 248{
249 struct s3c_adc_bat *bat = &main_bat; 249 struct s3c_adc_bat *bat = &main_bat;
@@ -251,7 +251,7 @@ static void s3c_adc_bat_work(struct work_struct *work)
251 int is_plugged; 251 int is_plugged;
252 static int was_plugged; 252 static int was_plugged;
253 253
254 is_plugged = power_supply_am_i_supplied(&bat->psy); 254 is_plugged = power_supply_am_i_supplied(bat->psy);
255 bat->cable_plugged = is_plugged; 255 bat->cable_plugged = is_plugged;
256 if (is_plugged != was_plugged) { 256 if (is_plugged != was_plugged) {
257 was_plugged = is_plugged; 257 was_plugged = is_plugged;
@@ -279,7 +279,7 @@ static void s3c_adc_bat_work(struct work_struct *work)
279 } 279 }
280 } 280 }
281 281
282 power_supply_changed(&bat->psy); 282 power_supply_changed(bat->psy);
283} 283}
284 284
285static irqreturn_t s3c_adc_bat_charged(int irq, void *dev_id) 285static irqreturn_t s3c_adc_bat_charged(int irq, void *dev_id)
@@ -310,16 +310,25 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)
310 main_bat.cable_plugged = 0; 310 main_bat.cable_plugged = 0;
311 main_bat.status = POWER_SUPPLY_STATUS_DISCHARGING; 311 main_bat.status = POWER_SUPPLY_STATUS_DISCHARGING;
312 312
313 ret = power_supply_register(&pdev->dev, &main_bat.psy, NULL); 313 main_bat.psy = power_supply_register(&pdev->dev, &main_bat_desc, NULL);
314 if (ret) 314 if (IS_ERR(main_bat.psy)) {
315 ret = PTR_ERR(main_bat.psy);
315 goto err_reg_main; 316 goto err_reg_main;
317 }
316 if (pdata->backup_volt_mult) { 318 if (pdata->backup_volt_mult) {
319 const struct power_supply_config psy_cfg
320 = { .drv_data = &backup_bat, };
321
317 backup_bat.client = client; 322 backup_bat.client = client;
318 backup_bat.pdata = pdev->dev.platform_data; 323 backup_bat.pdata = pdev->dev.platform_data;
319 backup_bat.volt_value = -1; 324 backup_bat.volt_value = -1;
320 ret = power_supply_register(&pdev->dev, &backup_bat.psy, NULL); 325 backup_bat.psy = power_supply_register(&pdev->dev,
321 if (ret) 326 &backup_bat_desc,
327 &psy_cfg);
328 if (IS_ERR(backup_bat.psy)) {
329 ret = PTR_ERR(backup_bat.psy);
322 goto err_reg_backup; 330 goto err_reg_backup;
331 }
323 } 332 }
324 333
325 INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work); 334 INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work);
@@ -360,9 +369,9 @@ err_irq:
360 gpio_free(pdata->gpio_charge_finished); 369 gpio_free(pdata->gpio_charge_finished);
361err_gpio: 370err_gpio:
362 if (pdata->backup_volt_mult) 371 if (pdata->backup_volt_mult)
363 power_supply_unregister(&backup_bat.psy); 372 power_supply_unregister(backup_bat.psy);
364err_reg_backup: 373err_reg_backup:
365 power_supply_unregister(&main_bat.psy); 374 power_supply_unregister(main_bat.psy);
366err_reg_main: 375err_reg_main:
367 return ret; 376 return ret;
368} 377}
@@ -372,9 +381,9 @@ static int s3c_adc_bat_remove(struct platform_device *pdev)
372 struct s3c_adc_client *client = platform_get_drvdata(pdev); 381 struct s3c_adc_client *client = platform_get_drvdata(pdev);
373 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data; 382 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
374 383
375 power_supply_unregister(&main_bat.psy); 384 power_supply_unregister(main_bat.psy);
376 if (pdata->backup_volt_mult) 385 if (pdata->backup_volt_mult)
377 power_supply_unregister(&backup_bat.psy); 386 power_supply_unregister(backup_bat.psy);
378 387
379 s3c_adc_release(client); 388 s3c_adc_release(client);
380 389
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 879f1448fc4a..de1178659d4b 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -156,7 +156,7 @@ static enum power_supply_property sbs_properties[] = {
156 156
157struct sbs_info { 157struct sbs_info {
158 struct i2c_client *client; 158 struct i2c_client *client;
159 struct power_supply power_supply; 159 struct power_supply *power_supply;
160 struct sbs_platform_data *pdata; 160 struct sbs_platform_data *pdata;
161 bool is_present; 161 bool is_present;
162 bool gpio_detect; 162 bool gpio_detect;
@@ -391,7 +391,7 @@ static int sbs_get_battery_property(struct i2c_client *client,
391 chip->last_state = val->intval; 391 chip->last_state = val->intval;
392 else if (chip->last_state != val->intval) { 392 else if (chip->last_state != val->intval) {
393 cancel_delayed_work_sync(&chip->work); 393 cancel_delayed_work_sync(&chip->work);
394 power_supply_changed(&chip->power_supply); 394 power_supply_changed(chip->power_supply);
395 chip->poll_time = 0; 395 chip->poll_time = 0;
396 } 396 }
397 } else { 397 } else {
@@ -556,8 +556,7 @@ static int sbs_get_property(struct power_supply *psy,
556 union power_supply_propval *val) 556 union power_supply_propval *val)
557{ 557{
558 int ret = 0; 558 int ret = 0;
559 struct sbs_info *chip = container_of(psy, 559 struct sbs_info *chip = power_supply_get_drvdata(psy);
560 struct sbs_info, power_supply);
561 struct i2c_client *client = chip->client; 560 struct i2c_client *client = chip->client;
562 561
563 switch (psp) { 562 switch (psp) {
@@ -638,7 +637,7 @@ static int sbs_get_property(struct power_supply *psy,
638 if (!chip->gpio_detect && 637 if (!chip->gpio_detect &&
639 chip->is_present != (ret >= 0)) { 638 chip->is_present != (ret >= 0)) {
640 chip->is_present = (ret >= 0); 639 chip->is_present = (ret >= 0);
641 power_supply_changed(&chip->power_supply); 640 power_supply_changed(chip->power_supply);
642 } 641 }
643 642
644done: 643done:
@@ -671,9 +670,7 @@ static irqreturn_t sbs_irq(int irq, void *devid)
671 670
672static void sbs_external_power_changed(struct power_supply *psy) 671static void sbs_external_power_changed(struct power_supply *psy)
673{ 672{
674 struct sbs_info *chip; 673 struct sbs_info *chip = power_supply_get_drvdata(psy);
675
676 chip = container_of(psy, struct sbs_info, power_supply);
677 674
678 if (chip->ignore_changes > 0) { 675 if (chip->ignore_changes > 0) {
679 chip->ignore_changes--; 676 chip->ignore_changes--;
@@ -712,7 +709,7 @@ static void sbs_delayed_work(struct work_struct *work)
712 709
713 if (chip->last_state != ret) { 710 if (chip->last_state != ret) {
714 chip->poll_time = 0; 711 chip->poll_time = 0;
715 power_supply_changed(&chip->power_supply); 712 power_supply_changed(chip->power_supply);
716 return; 713 return;
717 } 714 }
718 if (chip->poll_time > 0) { 715 if (chip->poll_time > 0) {
@@ -796,43 +793,48 @@ static struct sbs_platform_data *sbs_of_populate_pdata(
796} 793}
797#endif 794#endif
798 795
796static const struct power_supply_desc sbs_default_desc = {
797 .type = POWER_SUPPLY_TYPE_BATTERY,
798 .properties = sbs_properties,
799 .num_properties = ARRAY_SIZE(sbs_properties),
800 .get_property = sbs_get_property,
801 .external_power_changed = sbs_external_power_changed,
802};
803
799static int sbs_probe(struct i2c_client *client, 804static int sbs_probe(struct i2c_client *client,
800 const struct i2c_device_id *id) 805 const struct i2c_device_id *id)
801{ 806{
802 struct sbs_info *chip; 807 struct sbs_info *chip;
808 struct power_supply_desc *sbs_desc;
803 struct sbs_platform_data *pdata = client->dev.platform_data; 809 struct sbs_platform_data *pdata = client->dev.platform_data;
804 struct power_supply_config psy_cfg = {}; 810 struct power_supply_config psy_cfg = {};
805 int rc; 811 int rc;
806 int irq; 812 int irq;
807 char *name;
808 813
809 name = kasprintf(GFP_KERNEL, "sbs-%s", dev_name(&client->dev)); 814 sbs_desc = devm_kmemdup(&client->dev, &sbs_default_desc,
810 if (!name) { 815 sizeof(*sbs_desc), GFP_KERNEL);
811 dev_err(&client->dev, "Failed to allocate device name\n"); 816 if (!sbs_desc)
817 return -ENOMEM;
818
819 sbs_desc->name = devm_kasprintf(&client->dev, GFP_KERNEL, "sbs-%s",
820 dev_name(&client->dev));
821 if (!sbs_desc->name)
812 return -ENOMEM; 822 return -ENOMEM;
813 }
814 823
815 chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL); 824 chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL);
816 if (!chip) { 825 if (!chip)
817 rc = -ENOMEM; 826 return -ENOMEM;
818 goto exit_free_name;
819 }
820 827
821 chip->client = client; 828 chip->client = client;
822 chip->enable_detection = false; 829 chip->enable_detection = false;
823 chip->gpio_detect = false; 830 chip->gpio_detect = false;
824 chip->power_supply.name = name;
825 chip->power_supply.type = POWER_SUPPLY_TYPE_BATTERY;
826 chip->power_supply.properties = sbs_properties;
827 chip->power_supply.num_properties = ARRAY_SIZE(sbs_properties);
828 chip->power_supply.get_property = sbs_get_property;
829 psy_cfg.of_node = client->dev.of_node; 831 psy_cfg.of_node = client->dev.of_node;
832 psy_cfg.drv_data = chip;
830 /* ignore first notification of external change, it is generated 833 /* ignore first notification of external change, it is generated
831 * from the power_supply_register call back 834 * from the power_supply_register call back
832 */ 835 */
833 chip->ignore_changes = 1; 836 chip->ignore_changes = 1;
834 chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN; 837 chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
835 chip->power_supply.external_power_changed = sbs_external_power_changed;
836 838
837 pdata = sbs_of_populate_pdata(client); 839 pdata = sbs_of_populate_pdata(client);
838 840
@@ -871,7 +873,7 @@ static int sbs_probe(struct i2c_client *client,
871 873
872 rc = request_irq(irq, sbs_irq, 874 rc = request_irq(irq, sbs_irq,
873 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 875 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
874 dev_name(&client->dev), &chip->power_supply); 876 dev_name(&client->dev), chip->power_supply);
875 if (rc) { 877 if (rc) {
876 dev_warn(&client->dev, "Failed to request irq: %d\n", rc); 878 dev_warn(&client->dev, "Failed to request irq: %d\n", rc);
877 gpio_free(pdata->battery_detect); 879 gpio_free(pdata->battery_detect);
@@ -893,11 +895,12 @@ skip_gpio:
893 goto exit_psupply; 895 goto exit_psupply;
894 } 896 }
895 897
896 rc = power_supply_register(&client->dev, &chip->power_supply, 898 chip->power_supply = power_supply_register(&client->dev, sbs_desc,
897 &psy_cfg); 899 &psy_cfg);
898 if (rc) { 900 if (IS_ERR(chip->power_supply)) {
899 dev_err(&client->dev, 901 dev_err(&client->dev,
900 "%s: Failed to register power supply\n", __func__); 902 "%s: Failed to register power supply\n", __func__);
903 rc = PTR_ERR(chip->power_supply);
901 goto exit_psupply; 904 goto exit_psupply;
902 } 905 }
903 906
@@ -912,15 +915,12 @@ skip_gpio:
912 915
913exit_psupply: 916exit_psupply:
914 if (chip->irq) 917 if (chip->irq)
915 free_irq(chip->irq, &chip->power_supply); 918 free_irq(chip->irq, chip->power_supply);
916 if (chip->gpio_detect) 919 if (chip->gpio_detect)
917 gpio_free(pdata->battery_detect); 920 gpio_free(pdata->battery_detect);
918 921
919 kfree(chip); 922 kfree(chip);
920 923
921exit_free_name:
922 kfree(name);
923
924 return rc; 924 return rc;
925} 925}
926 926
@@ -929,15 +929,14 @@ static int sbs_remove(struct i2c_client *client)
929 struct sbs_info *chip = i2c_get_clientdata(client); 929 struct sbs_info *chip = i2c_get_clientdata(client);
930 930
931 if (chip->irq) 931 if (chip->irq)
932 free_irq(chip->irq, &chip->power_supply); 932 free_irq(chip->irq, chip->power_supply);
933 if (chip->gpio_detect) 933 if (chip->gpio_detect)
934 gpio_free(chip->pdata->battery_detect); 934 gpio_free(chip->pdata->battery_detect);
935 935
936 power_supply_unregister(&chip->power_supply); 936 power_supply_unregister(chip->power_supply);
937 937
938 cancel_delayed_work_sync(&chip->work); 938 cancel_delayed_work_sync(&chip->work);
939 939
940 kfree(chip->power_supply.name);
941 kfree(chip); 940 kfree(chip);
942 chip = NULL; 941 chip = NULL;
943 942
diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
index 4396a1ffeb1a..0b60a0b5878b 100644
--- a/drivers/power/smb347-charger.c
+++ b/drivers/power/smb347-charger.c
@@ -139,9 +139,9 @@ struct smb347_charger {
139 struct mutex lock; 139 struct mutex lock;
140 struct device *dev; 140 struct device *dev;
141 struct regmap *regmap; 141 struct regmap *regmap;
142 struct power_supply mains; 142 struct power_supply *mains;
143 struct power_supply usb; 143 struct power_supply *usb;
144 struct power_supply battery; 144 struct power_supply *battery;
145 bool mains_online; 145 bool mains_online;
146 bool usb_online; 146 bool usb_online;
147 bool charging_enabled; 147 bool charging_enabled;
@@ -741,7 +741,7 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
741 */ 741 */
742 if (stat_c & STAT_C_CHARGER_ERROR) { 742 if (stat_c & STAT_C_CHARGER_ERROR) {
743 dev_err(smb->dev, "charging stopped due to charger error\n"); 743 dev_err(smb->dev, "charging stopped due to charger error\n");
744 power_supply_changed(&smb->battery); 744 power_supply_changed(smb->battery);
745 handled = true; 745 handled = true;
746 } 746 }
747 747
@@ -752,7 +752,7 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
752 */ 752 */
753 if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ)) { 753 if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ)) {
754 if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) 754 if (irqstat_c & IRQSTAT_C_TERMINATION_STAT)
755 power_supply_changed(&smb->battery); 755 power_supply_changed(smb->battery);
756 dev_dbg(smb->dev, "going to HW maintenance mode\n"); 756 dev_dbg(smb->dev, "going to HW maintenance mode\n");
757 handled = true; 757 handled = true;
758 } 758 }
@@ -766,7 +766,7 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
766 766
767 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT) 767 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT)
768 dev_warn(smb->dev, "charging stopped due to timeout\n"); 768 dev_warn(smb->dev, "charging stopped due to timeout\n");
769 power_supply_changed(&smb->battery); 769 power_supply_changed(smb->battery);
770 handled = true; 770 handled = true;
771 } 771 }
772 772
@@ -778,9 +778,9 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
778 if (smb347_update_ps_status(smb) > 0) { 778 if (smb347_update_ps_status(smb) > 0) {
779 smb347_start_stop_charging(smb); 779 smb347_start_stop_charging(smb);
780 if (smb->pdata->use_mains) 780 if (smb->pdata->use_mains)
781 power_supply_changed(&smb->mains); 781 power_supply_changed(smb->mains);
782 if (smb->pdata->use_usb) 782 if (smb->pdata->use_usb)
783 power_supply_changed(&smb->usb); 783 power_supply_changed(smb->usb);
784 } 784 }
785 handled = true; 785 handled = true;
786 } 786 }
@@ -935,8 +935,7 @@ static int smb347_mains_get_property(struct power_supply *psy,
935 enum power_supply_property prop, 935 enum power_supply_property prop,
936 union power_supply_propval *val) 936 union power_supply_propval *val)
937{ 937{
938 struct smb347_charger *smb = 938 struct smb347_charger *smb = power_supply_get_drvdata(psy);
939 container_of(psy, struct smb347_charger, mains);
940 int ret; 939 int ret;
941 940
942 switch (prop) { 941 switch (prop) {
@@ -977,8 +976,7 @@ static int smb347_usb_get_property(struct power_supply *psy,
977 enum power_supply_property prop, 976 enum power_supply_property prop,
978 union power_supply_propval *val) 977 union power_supply_propval *val)
979{ 978{
980 struct smb347_charger *smb = 979 struct smb347_charger *smb = power_supply_get_drvdata(psy);
981 container_of(psy, struct smb347_charger, usb);
982 int ret; 980 int ret;
983 981
984 switch (prop) { 982 switch (prop) {
@@ -1064,8 +1062,7 @@ static int smb347_battery_get_property(struct power_supply *psy,
1064 enum power_supply_property prop, 1062 enum power_supply_property prop,
1065 union power_supply_propval *val) 1063 union power_supply_propval *val)
1066{ 1064{
1067 struct smb347_charger *smb = 1065 struct smb347_charger *smb = power_supply_get_drvdata(psy);
1068 container_of(psy, struct smb347_charger, battery);
1069 const struct smb347_charger_platform_data *pdata = smb->pdata; 1066 const struct smb347_charger_platform_data *pdata = smb->pdata;
1070 int ret; 1067 int ret;
1071 1068
@@ -1189,12 +1186,36 @@ static const struct regmap_config smb347_regmap = {
1189 .readable_reg = smb347_readable_reg, 1186 .readable_reg = smb347_readable_reg,
1190}; 1187};
1191 1188
1189static const struct power_supply_desc smb347_mains_desc = {
1190 .name = "smb347-mains",
1191 .type = POWER_SUPPLY_TYPE_MAINS,
1192 .get_property = smb347_mains_get_property,
1193 .properties = smb347_mains_properties,
1194 .num_properties = ARRAY_SIZE(smb347_mains_properties),
1195};
1196
1197static const struct power_supply_desc smb347_usb_desc = {
1198 .name = "smb347-usb",
1199 .type = POWER_SUPPLY_TYPE_USB,
1200 .get_property = smb347_usb_get_property,
1201 .properties = smb347_usb_properties,
1202 .num_properties = ARRAY_SIZE(smb347_usb_properties),
1203};
1204
1205static const struct power_supply_desc smb347_battery_desc = {
1206 .name = "smb347-battery",
1207 .type = POWER_SUPPLY_TYPE_BATTERY,
1208 .get_property = smb347_battery_get_property,
1209 .properties = smb347_battery_properties,
1210 .num_properties = ARRAY_SIZE(smb347_battery_properties),
1211};
1212
1192static int smb347_probe(struct i2c_client *client, 1213static int smb347_probe(struct i2c_client *client,
1193 const struct i2c_device_id *id) 1214 const struct i2c_device_id *id)
1194{ 1215{
1195 static char *battery[] = { "smb347-battery" }; 1216 static char *battery[] = { "smb347-battery" };
1196 const struct smb347_charger_platform_data *pdata; 1217 const struct smb347_charger_platform_data *pdata;
1197 struct power_supply_config psy_cfg = {}; /* Only for mains and usb */ 1218 struct power_supply_config mains_usb_cfg = {}, battery_cfg = {};
1198 struct device *dev = &client->dev; 1219 struct device *dev = &client->dev;
1199 struct smb347_charger *smb; 1220 struct smb347_charger *smb;
1200 int ret; 1221 int ret;
@@ -1224,47 +1245,35 @@ static int smb347_probe(struct i2c_client *client,
1224 if (ret < 0) 1245 if (ret < 0)
1225 return ret; 1246 return ret;
1226 1247
1227 psy_cfg.supplied_to = battery; 1248 mains_usb_cfg.supplied_to = battery;
1228 psy_cfg.num_supplicants = ARRAY_SIZE(battery); 1249 mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery);
1250 mains_usb_cfg.drv_data = smb;
1229 if (smb->pdata->use_mains) { 1251 if (smb->pdata->use_mains) {
1230 smb->mains.name = "smb347-mains"; 1252 smb->mains = power_supply_register(dev, &smb347_mains_desc,
1231 smb->mains.type = POWER_SUPPLY_TYPE_MAINS; 1253 &mains_usb_cfg);
1232 smb->mains.get_property = smb347_mains_get_property; 1254 if (IS_ERR(smb->mains))
1233 smb->mains.properties = smb347_mains_properties; 1255 return PTR_ERR(smb->mains);
1234 smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
1235 ret = power_supply_register(dev, &smb->mains, &psy_cfg);
1236 if (ret < 0)
1237 return ret;
1238 } 1256 }
1239 1257
1240 if (smb->pdata->use_usb) { 1258 if (smb->pdata->use_usb) {
1241 smb->usb.name = "smb347-usb"; 1259 smb->usb = power_supply_register(dev, &smb347_usb_desc,
1242 smb->usb.type = POWER_SUPPLY_TYPE_USB; 1260 &mains_usb_cfg);
1243 smb->usb.get_property = smb347_usb_get_property; 1261 if (IS_ERR(smb->usb)) {
1244 smb->usb.properties = smb347_usb_properties;
1245 smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
1246 ret = power_supply_register(dev, &smb->usb, &psy_cfg);
1247 if (ret < 0) {
1248 if (smb->pdata->use_mains) 1262 if (smb->pdata->use_mains)
1249 power_supply_unregister(&smb->mains); 1263 power_supply_unregister(smb->mains);
1250 return ret; 1264 return PTR_ERR(smb->usb);
1251 } 1265 }
1252 } 1266 }
1253 1267
1254 smb->battery.name = "smb347-battery"; 1268 battery_cfg.drv_data = smb;
1255 smb->battery.type = POWER_SUPPLY_TYPE_BATTERY; 1269 smb->battery = power_supply_register(dev, &smb347_battery_desc,
1256 smb->battery.get_property = smb347_battery_get_property; 1270 &battery_cfg);
1257 smb->battery.properties = smb347_battery_properties; 1271 if (IS_ERR(smb->battery)) {
1258 smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties);
1259
1260
1261 ret = power_supply_register(dev, &smb->battery, NULL);
1262 if (ret < 0) {
1263 if (smb->pdata->use_usb) 1272 if (smb->pdata->use_usb)
1264 power_supply_unregister(&smb->usb); 1273 power_supply_unregister(smb->usb);
1265 if (smb->pdata->use_mains) 1274 if (smb->pdata->use_mains)
1266 power_supply_unregister(&smb->mains); 1275 power_supply_unregister(smb->mains);
1267 return ret; 1276 return PTR_ERR(smb->battery);
1268 } 1277 }
1269 1278
1270 /* 1279 /*
@@ -1294,11 +1303,11 @@ static int smb347_remove(struct i2c_client *client)
1294 gpio_free(smb->pdata->irq_gpio); 1303 gpio_free(smb->pdata->irq_gpio);
1295 } 1304 }
1296 1305
1297 power_supply_unregister(&smb->battery); 1306 power_supply_unregister(smb->battery);
1298 if (smb->pdata->use_usb) 1307 if (smb->pdata->use_usb)
1299 power_supply_unregister(&smb->usb); 1308 power_supply_unregister(smb->usb);
1300 if (smb->pdata->use_mains) 1309 if (smb->pdata->use_mains)
1301 power_supply_unregister(&smb->mains); 1310 power_supply_unregister(smb->mains);
1302 return 0; 1311 return 0;
1303} 1312}
1304 1313
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c
index f6c92d1d7811..f986e0cca7ac 100644
--- a/drivers/power/test_power.c
+++ b/drivers/power/test_power.c
@@ -153,7 +153,9 @@ static char *test_power_ac_supplied_to[] = {
153 "test_battery", 153 "test_battery",
154}; 154};
155 155
156static struct power_supply test_power_supplies[] = { 156static struct power_supply *test_power_supplies[TEST_POWER_NUM];
157
158static const struct power_supply_desc test_power_desc[] = {
157 [TEST_AC] = { 159 [TEST_AC] = {
158 .name = "test_ac", 160 .name = "test_ac",
159 .type = POWER_SUPPLY_TYPE_MAINS, 161 .type = POWER_SUPPLY_TYPE_MAINS,
@@ -200,11 +202,13 @@ static int __init test_power_init(void)
200 BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_configs)); 202 BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_configs));
201 203
202 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) { 204 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
203 ret = power_supply_register(NULL, &test_power_supplies[i], 205 test_power_supplies[i] = power_supply_register(NULL,
206 &test_power_desc[i],
204 &test_power_configs[i]); 207 &test_power_configs[i]);
205 if (ret) { 208 if (IS_ERR(test_power_supplies[i])) {
206 pr_err("%s: failed to register %s\n", __func__, 209 pr_err("%s: failed to register %s\n", __func__,
207 test_power_supplies[i].name); 210 test_power_desc[i].name);
211 ret = PTR_ERR(test_power_supplies[i]);
208 goto failed; 212 goto failed;
209 } 213 }
210 } 214 }
@@ -213,7 +217,7 @@ static int __init test_power_init(void)
213 return 0; 217 return 0;
214failed: 218failed:
215 while (--i >= 0) 219 while (--i >= 0)
216 power_supply_unregister(&test_power_supplies[i]); 220 power_supply_unregister(test_power_supplies[i]);
217 return ret; 221 return ret;
218} 222}
219module_init(test_power_init); 223module_init(test_power_init);
@@ -227,13 +231,13 @@ static void __exit test_power_exit(void)
227 usb_online = 0; 231 usb_online = 0;
228 battery_status = POWER_SUPPLY_STATUS_DISCHARGING; 232 battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
229 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) 233 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
230 power_supply_changed(&test_power_supplies[i]); 234 power_supply_changed(test_power_supplies[i]);
231 pr_info("%s: 'changed' event sent, sleeping for 10 seconds...\n", 235 pr_info("%s: 'changed' event sent, sleeping for 10 seconds...\n",
232 __func__); 236 __func__);
233 ssleep(10); 237 ssleep(10);
234 238
235 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) 239 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
236 power_supply_unregister(&test_power_supplies[i]); 240 power_supply_unregister(test_power_supplies[i]);
237 241
238 module_initialized = false; 242 module_initialized = false;
239} 243}
@@ -331,7 +335,7 @@ static inline void signal_power_supply_changed(struct power_supply *psy)
331static int param_set_ac_online(const char *key, const struct kernel_param *kp) 335static int param_set_ac_online(const char *key, const struct kernel_param *kp)
332{ 336{
333 ac_online = map_get_value(map_ac_online, key, ac_online); 337 ac_online = map_get_value(map_ac_online, key, ac_online);
334 signal_power_supply_changed(&test_power_supplies[TEST_AC]); 338 signal_power_supply_changed(test_power_supplies[TEST_AC]);
335 return 0; 339 return 0;
336} 340}
337 341
@@ -344,7 +348,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
344static int param_set_usb_online(const char *key, const struct kernel_param *kp) 348static int param_set_usb_online(const char *key, const struct kernel_param *kp)
345{ 349{
346 usb_online = map_get_value(map_ac_online, key, usb_online); 350 usb_online = map_get_value(map_ac_online, key, usb_online);
347 signal_power_supply_changed(&test_power_supplies[TEST_USB]); 351 signal_power_supply_changed(test_power_supplies[TEST_USB]);
348 return 0; 352 return 0;
349} 353}
350 354
@@ -358,7 +362,7 @@ static int param_set_battery_status(const char *key,
358 const struct kernel_param *kp) 362 const struct kernel_param *kp)
359{ 363{
360 battery_status = map_get_value(map_status, key, battery_status); 364 battery_status = map_get_value(map_status, key, battery_status);
361 signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); 365 signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
362 return 0; 366 return 0;
363} 367}
364 368
@@ -372,7 +376,7 @@ static int param_set_battery_health(const char *key,
372 const struct kernel_param *kp) 376 const struct kernel_param *kp)
373{ 377{
374 battery_health = map_get_value(map_health, key, battery_health); 378 battery_health = map_get_value(map_health, key, battery_health);
375 signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); 379 signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
376 return 0; 380 return 0;
377} 381}
378 382
@@ -386,7 +390,7 @@ static int param_set_battery_present(const char *key,
386 const struct kernel_param *kp) 390 const struct kernel_param *kp)
387{ 391{
388 battery_present = map_get_value(map_present, key, battery_present); 392 battery_present = map_get_value(map_present, key, battery_present);
389 signal_power_supply_changed(&test_power_supplies[TEST_AC]); 393 signal_power_supply_changed(test_power_supplies[TEST_AC]);
390 return 0; 394 return 0;
391} 395}
392 396
@@ -402,7 +406,7 @@ static int param_set_battery_technology(const char *key,
402{ 406{
403 battery_technology = map_get_value(map_technology, key, 407 battery_technology = map_get_value(map_technology, key,
404 battery_technology); 408 battery_technology);
405 signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); 409 signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
406 return 0; 410 return 0;
407} 411}
408 412
@@ -423,7 +427,7 @@ static int param_set_battery_capacity(const char *key,
423 return -EINVAL; 427 return -EINVAL;
424 428
425 battery_capacity = tmp; 429 battery_capacity = tmp;
426 signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); 430 signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
427 return 0; 431 return 0;
428} 432}
429 433
@@ -438,7 +442,7 @@ static int param_set_battery_voltage(const char *key,
438 return -EINVAL; 442 return -EINVAL;
439 443
440 battery_voltage = tmp; 444 battery_voltage = tmp;
441 signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); 445 signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
442 return 0; 446 return 0;
443} 447}
444 448
diff --git a/drivers/power/tosa_battery.c b/drivers/power/tosa_battery.c
index 895e4b4dfcf6..6e88c1b37945 100644
--- a/drivers/power/tosa_battery.c
+++ b/drivers/power/tosa_battery.c
@@ -26,7 +26,7 @@ static struct work_struct bat_work;
26 26
27struct tosa_bat { 27struct tosa_bat {
28 int status; 28 int status;
29 struct power_supply psy; 29 struct power_supply *psy;
30 int full_chrg; 30 int full_chrg;
31 31
32 struct mutex work_lock; /* protects data */ 32 struct mutex work_lock; /* protects data */
@@ -61,7 +61,7 @@ static unsigned long tosa_read_bat(struct tosa_bat *bat)
61 mutex_lock(&bat_lock); 61 mutex_lock(&bat_lock);
62 gpio_set_value(bat->gpio_bat, 1); 62 gpio_set_value(bat->gpio_bat, 1);
63 msleep(5); 63 msleep(5);
64 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy.dev->parent), 64 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent),
65 bat->adc_bat); 65 bat->adc_bat);
66 gpio_set_value(bat->gpio_bat, 0); 66 gpio_set_value(bat->gpio_bat, 0);
67 mutex_unlock(&bat_lock); 67 mutex_unlock(&bat_lock);
@@ -81,7 +81,7 @@ static unsigned long tosa_read_temp(struct tosa_bat *bat)
81 mutex_lock(&bat_lock); 81 mutex_lock(&bat_lock);
82 gpio_set_value(bat->gpio_temp, 1); 82 gpio_set_value(bat->gpio_temp, 1);
83 msleep(5); 83 msleep(5);
84 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy.dev->parent), 84 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent),
85 bat->adc_temp); 85 bat->adc_temp);
86 gpio_set_value(bat->gpio_temp, 0); 86 gpio_set_value(bat->gpio_temp, 0);
87 mutex_unlock(&bat_lock); 87 mutex_unlock(&bat_lock);
@@ -96,7 +96,7 @@ static int tosa_bat_get_property(struct power_supply *psy,
96 union power_supply_propval *val) 96 union power_supply_propval *val)
97{ 97{
98 int ret = 0; 98 int ret = 0;
99 struct tosa_bat *bat = container_of(psy, struct tosa_bat, psy); 99 struct tosa_bat *bat = power_supply_get_drvdata(psy);
100 100
101 if (bat->is_present && !bat->is_present(bat) 101 if (bat->is_present && !bat->is_present(bat)
102 && psp != POWER_SUPPLY_PROP_PRESENT) { 102 && psp != POWER_SUPPLY_PROP_PRESENT) {
@@ -158,14 +158,14 @@ static irqreturn_t tosa_bat_gpio_isr(int irq, void *data)
158static void tosa_bat_update(struct tosa_bat *bat) 158static void tosa_bat_update(struct tosa_bat *bat)
159{ 159{
160 int old; 160 int old;
161 struct power_supply *psy = &bat->psy; 161 struct power_supply *psy = bat->psy;
162 162
163 mutex_lock(&bat->work_lock); 163 mutex_lock(&bat->work_lock);
164 164
165 old = bat->status; 165 old = bat->status;
166 166
167 if (bat->is_present && !bat->is_present(bat)) { 167 if (bat->is_present && !bat->is_present(bat)) {
168 printk(KERN_NOTICE "%s not present\n", psy->name); 168 printk(KERN_NOTICE "%s not present\n", psy->desc->name);
169 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; 169 bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
170 bat->full_chrg = -1; 170 bat->full_chrg = -1;
171 } else if (power_supply_am_i_supplied(psy)) { 171 } else if (power_supply_am_i_supplied(psy)) {
@@ -222,18 +222,38 @@ static enum power_supply_property tosa_bat_bu_props[] = {
222 POWER_SUPPLY_PROP_PRESENT, 222 POWER_SUPPLY_PROP_PRESENT,
223}; 223};
224 224
225static const struct power_supply_desc tosa_bat_main_desc = {
226 .name = "main-battery",
227 .type = POWER_SUPPLY_TYPE_BATTERY,
228 .properties = tosa_bat_main_props,
229 .num_properties = ARRAY_SIZE(tosa_bat_main_props),
230 .get_property = tosa_bat_get_property,
231 .external_power_changed = tosa_bat_external_power_changed,
232 .use_for_apm = 1,
233};
234
235static const struct power_supply_desc tosa_bat_jacket_desc = {
236 .name = "jacket-battery",
237 .type = POWER_SUPPLY_TYPE_BATTERY,
238 .properties = tosa_bat_main_props,
239 .num_properties = ARRAY_SIZE(tosa_bat_main_props),
240 .get_property = tosa_bat_get_property,
241 .external_power_changed = tosa_bat_external_power_changed,
242};
243
244static const struct power_supply_desc tosa_bat_bu_desc = {
245 .name = "backup-battery",
246 .type = POWER_SUPPLY_TYPE_BATTERY,
247 .properties = tosa_bat_bu_props,
248 .num_properties = ARRAY_SIZE(tosa_bat_bu_props),
249 .get_property = tosa_bat_get_property,
250 .external_power_changed = tosa_bat_external_power_changed,
251};
252
225static struct tosa_bat tosa_bat_main = { 253static struct tosa_bat tosa_bat_main = {
226 .status = POWER_SUPPLY_STATUS_DISCHARGING, 254 .status = POWER_SUPPLY_STATUS_DISCHARGING,
227 .full_chrg = -1, 255 .full_chrg = -1,
228 .psy = { 256 .psy = NULL,
229 .name = "main-battery",
230 .type = POWER_SUPPLY_TYPE_BATTERY,
231 .properties = tosa_bat_main_props,
232 .num_properties = ARRAY_SIZE(tosa_bat_main_props),
233 .get_property = tosa_bat_get_property,
234 .external_power_changed = tosa_bat_external_power_changed,
235 .use_for_apm = 1,
236 },
237 257
238 .gpio_full = TOSA_GPIO_BAT0_CRG, 258 .gpio_full = TOSA_GPIO_BAT0_CRG,
239 .gpio_charge_off = TOSA_GPIO_CHARGE_OFF, 259 .gpio_charge_off = TOSA_GPIO_CHARGE_OFF,
@@ -254,14 +274,7 @@ static struct tosa_bat tosa_bat_main = {
254static struct tosa_bat tosa_bat_jacket = { 274static struct tosa_bat tosa_bat_jacket = {
255 .status = POWER_SUPPLY_STATUS_DISCHARGING, 275 .status = POWER_SUPPLY_STATUS_DISCHARGING,
256 .full_chrg = -1, 276 .full_chrg = -1,
257 .psy = { 277 .psy = NULL,
258 .name = "jacket-battery",
259 .type = POWER_SUPPLY_TYPE_BATTERY,
260 .properties = tosa_bat_main_props,
261 .num_properties = ARRAY_SIZE(tosa_bat_main_props),
262 .get_property = tosa_bat_get_property,
263 .external_power_changed = tosa_bat_external_power_changed,
264 },
265 278
266 .is_present = tosa_jacket_bat_is_present, 279 .is_present = tosa_jacket_bat_is_present,
267 .gpio_full = TOSA_GPIO_BAT1_CRG, 280 .gpio_full = TOSA_GPIO_BAT1_CRG,
@@ -283,15 +296,7 @@ static struct tosa_bat tosa_bat_jacket = {
283static struct tosa_bat tosa_bat_bu = { 296static struct tosa_bat tosa_bat_bu = {
284 .status = POWER_SUPPLY_STATUS_UNKNOWN, 297 .status = POWER_SUPPLY_STATUS_UNKNOWN,
285 .full_chrg = -1, 298 .full_chrg = -1,
286 299 .psy = NULL,
287 .psy = {
288 .name = "backup-battery",
289 .type = POWER_SUPPLY_TYPE_BATTERY,
290 .properties = tosa_bat_bu_props,
291 .num_properties = ARRAY_SIZE(tosa_bat_bu_props),
292 .get_property = tosa_bat_get_property,
293 .external_power_changed = tosa_bat_external_power_changed,
294 },
295 300
296 .gpio_full = -1, 301 .gpio_full = -1,
297 .gpio_charge_off = -1, 302 .gpio_charge_off = -1,
@@ -345,6 +350,9 @@ static int tosa_bat_resume(struct platform_device *dev)
345static int tosa_bat_probe(struct platform_device *dev) 350static int tosa_bat_probe(struct platform_device *dev)
346{ 351{
347 int ret; 352 int ret;
353 struct power_supply_config main_psy_cfg = {},
354 jacket_psy_cfg = {},
355 bu_psy_cfg = {};
348 356
349 if (!machine_is_tosa()) 357 if (!machine_is_tosa())
350 return -ENODEV; 358 return -ENODEV;
@@ -358,15 +366,31 @@ static int tosa_bat_probe(struct platform_device *dev)
358 366
359 INIT_WORK(&bat_work, tosa_bat_work); 367 INIT_WORK(&bat_work, tosa_bat_work);
360 368
361 ret = power_supply_register(&dev->dev, &tosa_bat_main.psy, NULL); 369 main_psy_cfg.drv_data = &tosa_bat_main;
362 if (ret) 370 tosa_bat_main.psy = power_supply_register(&dev->dev,
371 &tosa_bat_main_desc,
372 &main_psy_cfg);
373 if (IS_ERR(tosa_bat_main.psy)) {
374 ret = PTR_ERR(tosa_bat_main.psy);
363 goto err_psy_reg_main; 375 goto err_psy_reg_main;
364 ret = power_supply_register(&dev->dev, &tosa_bat_jacket.psy, NULL); 376 }
365 if (ret) 377
378 jacket_psy_cfg.drv_data = &tosa_bat_jacket;
379 tosa_bat_jacket.psy = power_supply_register(&dev->dev,
380 &tosa_bat_jacket_desc,
381 &jacket_psy_cfg);
382 if (IS_ERR(tosa_bat_jacket.psy)) {
383 ret = PTR_ERR(tosa_bat_jacket.psy);
366 goto err_psy_reg_jacket; 384 goto err_psy_reg_jacket;
367 ret = power_supply_register(&dev->dev, &tosa_bat_bu.psy, NULL); 385 }
368 if (ret) 386
387 bu_psy_cfg.drv_data = &tosa_bat_bu;
388 tosa_bat_bu.psy = power_supply_register(&dev->dev, &tosa_bat_bu_desc,
389 &bu_psy_cfg);
390 if (IS_ERR(tosa_bat_bu.psy)) {
391 ret = PTR_ERR(tosa_bat_bu.psy);
369 goto err_psy_reg_bu; 392 goto err_psy_reg_bu;
393 }
370 394
371 ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), 395 ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG),
372 tosa_bat_gpio_isr, 396 tosa_bat_gpio_isr,
@@ -395,11 +419,11 @@ static int tosa_bat_probe(struct platform_device *dev)
395err_req_jacket: 419err_req_jacket:
396 free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main); 420 free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main);
397err_req_main: 421err_req_main:
398 power_supply_unregister(&tosa_bat_bu.psy); 422 power_supply_unregister(tosa_bat_bu.psy);
399err_psy_reg_bu: 423err_psy_reg_bu:
400 power_supply_unregister(&tosa_bat_jacket.psy); 424 power_supply_unregister(tosa_bat_jacket.psy);
401err_psy_reg_jacket: 425err_psy_reg_jacket:
402 power_supply_unregister(&tosa_bat_main.psy); 426 power_supply_unregister(tosa_bat_main.psy);
403err_psy_reg_main: 427err_psy_reg_main:
404 428
405 /* see comment in tosa_bat_remove */ 429 /* see comment in tosa_bat_remove */
@@ -415,9 +439,9 @@ static int tosa_bat_remove(struct platform_device *dev)
415 free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket); 439 free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket);
416 free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main); 440 free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main);
417 441
418 power_supply_unregister(&tosa_bat_bu.psy); 442 power_supply_unregister(tosa_bat_bu.psy);
419 power_supply_unregister(&tosa_bat_jacket.psy); 443 power_supply_unregister(tosa_bat_jacket.psy);
420 power_supply_unregister(&tosa_bat_main.psy); 444 power_supply_unregister(tosa_bat_main.psy);
421 445
422 /* 446 /*
423 * Now cancel the bat_work. We won't get any more schedules, 447 * Now cancel the bat_work. We won't get any more schedules,
diff --git a/drivers/power/tps65090-charger.c b/drivers/power/tps65090-charger.c
index 9872c901bd70..dcf9a3ca53d5 100644
--- a/drivers/power/tps65090-charger.c
+++ b/drivers/power/tps65090-charger.c
@@ -43,7 +43,7 @@ struct tps65090_charger {
43 int irq; 43 int irq;
44 struct task_struct *poll_task; 44 struct task_struct *poll_task;
45 bool passive_mode; 45 bool passive_mode;
46 struct power_supply ac; 46 struct power_supply *ac;
47 struct tps65090_platform_data *pdata; 47 struct tps65090_platform_data *pdata;
48}; 48};
49 49
@@ -135,8 +135,7 @@ static int tps65090_ac_get_property(struct power_supply *psy,
135 enum power_supply_property psp, 135 enum power_supply_property psp,
136 union power_supply_propval *val) 136 union power_supply_propval *val)
137{ 137{
138 struct tps65090_charger *charger = container_of(psy, 138 struct tps65090_charger *charger = power_supply_get_drvdata(psy);
139 struct tps65090_charger, ac);
140 139
141 if (psp == POWER_SUPPLY_PROP_ONLINE) { 140 if (psp == POWER_SUPPLY_PROP_ONLINE) {
142 val->intval = charger->ac_online; 141 val->intval = charger->ac_online;
@@ -190,7 +189,7 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
190 } 189 }
191 190
192 if (charger->prev_ac_online != charger->ac_online) 191 if (charger->prev_ac_online != charger->ac_online)
193 power_supply_changed(&charger->ac); 192 power_supply_changed(charger->ac);
194 193
195 return IRQ_HANDLED; 194 return IRQ_HANDLED;
196} 195}
@@ -229,6 +228,14 @@ static int tps65090_charger_poll_task(void *data)
229 return 0; 228 return 0;
230} 229}
231 230
231static const struct power_supply_desc tps65090_charger_desc = {
232 .name = "tps65090-ac",
233 .type = POWER_SUPPLY_TYPE_MAINS,
234 .get_property = tps65090_ac_get_property,
235 .properties = tps65090_ac_props,
236 .num_properties = ARRAY_SIZE(tps65090_ac_props),
237};
238
232static int tps65090_charger_probe(struct platform_device *pdev) 239static int tps65090_charger_probe(struct platform_device *pdev)
233{ 240{
234 struct tps65090_charger *cdata; 241 struct tps65090_charger *cdata;
@@ -260,20 +267,16 @@ static int tps65090_charger_probe(struct platform_device *pdev)
260 cdata->dev = &pdev->dev; 267 cdata->dev = &pdev->dev;
261 cdata->pdata = pdata; 268 cdata->pdata = pdata;
262 269
263 cdata->ac.name = "tps65090-ac";
264 cdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
265 cdata->ac.get_property = tps65090_ac_get_property;
266 cdata->ac.properties = tps65090_ac_props;
267 cdata->ac.num_properties = ARRAY_SIZE(tps65090_ac_props);
268
269 psy_cfg.supplied_to = pdata->supplied_to; 270 psy_cfg.supplied_to = pdata->supplied_to;
270 psy_cfg.num_supplicants = pdata->num_supplicants; 271 psy_cfg.num_supplicants = pdata->num_supplicants;
271 psy_cfg.of_node = pdev->dev.of_node; 272 psy_cfg.of_node = pdev->dev.of_node;
273 psy_cfg.drv_data = cdata;
272 274
273 ret = power_supply_register(&pdev->dev, &cdata->ac, &psy_cfg); 275 cdata->ac = power_supply_register(&pdev->dev, &tps65090_charger_desc,
274 if (ret) { 276 &psy_cfg);
277 if (IS_ERR(cdata->ac)) {
275 dev_err(&pdev->dev, "failed: power supply register\n"); 278 dev_err(&pdev->dev, "failed: power supply register\n");
276 return ret; 279 return PTR_ERR(cdata->ac);
277 } 280 }
278 281
279 irq = platform_get_irq(pdev, 0); 282 irq = platform_get_irq(pdev, 0);
@@ -303,7 +306,7 @@ static int tps65090_charger_probe(struct platform_device *pdev)
303 goto fail_unregister_supply; 306 goto fail_unregister_supply;
304 } 307 }
305 cdata->ac_online = 1; 308 cdata->ac_online = 1;
306 power_supply_changed(&cdata->ac); 309 power_supply_changed(cdata->ac);
307 } 310 }
308 311
309 if (irq != -ENXIO) { 312 if (irq != -ENXIO) {
@@ -330,7 +333,7 @@ static int tps65090_charger_probe(struct platform_device *pdev)
330 return 0; 333 return 0;
331 334
332fail_unregister_supply: 335fail_unregister_supply:
333 power_supply_unregister(&cdata->ac); 336 power_supply_unregister(cdata->ac);
334 337
335 return ret; 338 return ret;
336} 339}
@@ -341,7 +344,7 @@ static int tps65090_charger_remove(struct platform_device *pdev)
341 344
342 if (cdata->irq == -ENXIO) 345 if (cdata->irq == -ENXIO)
343 kthread_stop(cdata->poll_task); 346 kthread_stop(cdata->poll_task);
344 power_supply_unregister(&cdata->ac); 347 power_supply_unregister(cdata->ac);
345 348
346 return 0; 349 return 0;
347} 350}
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 156f30e64a75..02a522cb7753 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -87,8 +87,8 @@ MODULE_PARM_DESC(allow_usb, "Allow USB charge drawing default current");
87 87
88struct twl4030_bci { 88struct twl4030_bci {
89 struct device *dev; 89 struct device *dev;
90 struct power_supply ac; 90 struct power_supply *ac;
91 struct power_supply usb; 91 struct power_supply *usb;
92 struct usb_phy *transceiver; 92 struct usb_phy *transceiver;
93 struct notifier_block usb_nb; 93 struct notifier_block usb_nb;
94 struct work_struct work; 94 struct work_struct work;
@@ -318,8 +318,8 @@ static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
318 struct twl4030_bci *bci = arg; 318 struct twl4030_bci *bci = arg;
319 319
320 dev_dbg(bci->dev, "CHG_PRES irq\n"); 320 dev_dbg(bci->dev, "CHG_PRES irq\n");
321 power_supply_changed(&bci->ac); 321 power_supply_changed(bci->ac);
322 power_supply_changed(&bci->usb); 322 power_supply_changed(bci->usb);
323 323
324 return IRQ_HANDLED; 324 return IRQ_HANDLED;
325} 325}
@@ -347,8 +347,8 @@ static irqreturn_t twl4030_bci_interrupt(int irq, void *arg)
347 347
348 if (irqs1 & (TWL4030_ICHGLOW | TWL4030_ICHGEOC)) { 348 if (irqs1 & (TWL4030_ICHGLOW | TWL4030_ICHGEOC)) {
349 /* charger state change, inform the core */ 349 /* charger state change, inform the core */
350 power_supply_changed(&bci->ac); 350 power_supply_changed(bci->ac);
351 power_supply_changed(&bci->usb); 351 power_supply_changed(bci->usb);
352 } 352 }
353 353
354 /* various monitoring events, for now we just log them here */ 354 /* various monitoring events, for now we just log them here */
@@ -463,7 +463,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
463 enum power_supply_property psp, 463 enum power_supply_property psp,
464 union power_supply_propval *val) 464 union power_supply_propval *val)
465{ 465{
466 struct twl4030_bci *bci = dev_get_drvdata(psy->dev->parent); 466 struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent);
467 int is_charging; 467 int is_charging;
468 int state; 468 int state;
469 int ret; 469 int ret;
@@ -472,7 +472,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
472 if (state < 0) 472 if (state < 0)
473 return state; 473 return state;
474 474
475 if (psy->type == POWER_SUPPLY_TYPE_USB) 475 if (psy->desc->type == POWER_SUPPLY_TYPE_USB)
476 is_charging = state & TWL4030_MSTATEC_USB; 476 is_charging = state & TWL4030_MSTATEC_USB;
477 else 477 else
478 is_charging = state & TWL4030_MSTATEC_AC; 478 is_charging = state & TWL4030_MSTATEC_AC;
@@ -488,7 +488,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
488 /* charging must be active for meaningful result */ 488 /* charging must be active for meaningful result */
489 if (!is_charging) 489 if (!is_charging)
490 return -ENODATA; 490 return -ENODATA;
491 if (psy->type == POWER_SUPPLY_TYPE_USB) { 491 if (psy->desc->type == POWER_SUPPLY_TYPE_USB) {
492 ret = twl4030bci_read_adc_val(TWL4030_BCIVBUS); 492 ret = twl4030bci_read_adc_val(TWL4030_BCIVBUS);
493 if (ret < 0) 493 if (ret < 0)
494 return ret; 494 return ret;
@@ -558,6 +558,22 @@ twl4030_bci_parse_dt(struct device *dev)
558} 558}
559#endif 559#endif
560 560
561static const struct power_supply_desc twl4030_bci_ac_desc = {
562 .name = "twl4030_ac",
563 .type = POWER_SUPPLY_TYPE_MAINS,
564 .properties = twl4030_charger_props,
565 .num_properties = ARRAY_SIZE(twl4030_charger_props),
566 .get_property = twl4030_bci_get_property,
567};
568
569static const struct power_supply_desc twl4030_bci_usb_desc = {
570 .name = "twl4030_usb",
571 .type = POWER_SUPPLY_TYPE_USB,
572 .properties = twl4030_charger_props,
573 .num_properties = ARRAY_SIZE(twl4030_charger_props),
574 .get_property = twl4030_bci_get_property,
575};
576
561static int __init twl4030_bci_probe(struct platform_device *pdev) 577static int __init twl4030_bci_probe(struct platform_device *pdev)
562{ 578{
563 struct twl4030_bci *bci; 579 struct twl4030_bci *bci;
@@ -584,28 +600,21 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
584 } 600 }
585 601
586 platform_set_drvdata(pdev, bci); 602 platform_set_drvdata(pdev, bci);
587 bci->ac.name = "twl4030_ac";
588 bci->ac.type = POWER_SUPPLY_TYPE_MAINS;
589 bci->ac.properties = twl4030_charger_props;
590 bci->ac.num_properties = ARRAY_SIZE(twl4030_charger_props);
591 bci->ac.get_property = twl4030_bci_get_property;
592 603
593 ret = power_supply_register(&pdev->dev, &bci->ac, NULL); 604 bci->ac = power_supply_register(&pdev->dev, &twl4030_bci_ac_desc,
594 if (ret) { 605 NULL);
606 if (IS_ERR(bci->ac)) {
607 ret = PTR_ERR(bci->ac);
595 dev_err(&pdev->dev, "failed to register ac: %d\n", ret); 608 dev_err(&pdev->dev, "failed to register ac: %d\n", ret);
596 goto fail_register_ac; 609 goto fail_register_ac;
597 } 610 }
598 611
599 bci->usb.name = "twl4030_usb";
600 bci->usb.type = POWER_SUPPLY_TYPE_USB;
601 bci->usb.properties = twl4030_charger_props;
602 bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
603 bci->usb.get_property = twl4030_bci_get_property;
604
605 bci->usb_reg = regulator_get(bci->dev, "bci3v1"); 612 bci->usb_reg = regulator_get(bci->dev, "bci3v1");
606 613
607 ret = power_supply_register(&pdev->dev, &bci->usb, NULL); 614 bci->usb = power_supply_register(&pdev->dev, &twl4030_bci_usb_desc,
608 if (ret) { 615 NULL);
616 if (IS_ERR(bci->usb)) {
617 ret = PTR_ERR(bci->usb);
609 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); 618 dev_err(&pdev->dev, "failed to register usb: %d\n", ret);
610 goto fail_register_usb; 619 goto fail_register_usb;
611 } 620 }
@@ -670,9 +679,9 @@ fail_unmask_interrupts:
670fail_bci_irq: 679fail_bci_irq:
671 free_irq(bci->irq_chg, bci); 680 free_irq(bci->irq_chg, bci);
672fail_chg_irq: 681fail_chg_irq:
673 power_supply_unregister(&bci->usb); 682 power_supply_unregister(bci->usb);
674fail_register_usb: 683fail_register_usb:
675 power_supply_unregister(&bci->ac); 684 power_supply_unregister(bci->ac);
676fail_register_ac: 685fail_register_ac:
677fail_no_battery: 686fail_no_battery:
678 kfree(bci); 687 kfree(bci);
@@ -700,8 +709,8 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
700 } 709 }
701 free_irq(bci->irq_bci, bci); 710 free_irq(bci->irq_bci, bci);
702 free_irq(bci->irq_chg, bci); 711 free_irq(bci->irq_chg, bci);
703 power_supply_unregister(&bci->usb); 712 power_supply_unregister(bci->usb);
704 power_supply_unregister(&bci->ac); 713 power_supply_unregister(bci->ac);
705 kfree(bci); 714 kfree(bci);
706 715
707 return 0; 716 return 0;
diff --git a/drivers/power/twl4030_madc_battery.c b/drivers/power/twl4030_madc_battery.c
index d065460c1cb3..36d3a0e229fa 100644
--- a/drivers/power/twl4030_madc_battery.c
+++ b/drivers/power/twl4030_madc_battery.c
@@ -21,7 +21,7 @@
21#include <linux/power/twl4030_madc_battery.h> 21#include <linux/power/twl4030_madc_battery.h>
22 22
23struct twl4030_madc_battery { 23struct twl4030_madc_battery {
24 struct power_supply psy; 24 struct power_supply *psy;
25 struct twl4030_madc_bat_platform_data *pdata; 25 struct twl4030_madc_bat_platform_data *pdata;
26}; 26};
27 27
@@ -113,8 +113,7 @@ static int twl4030_madc_bat_get_property(struct power_supply *psy,
113 enum power_supply_property psp, 113 enum power_supply_property psp,
114 union power_supply_propval *val) 114 union power_supply_propval *val)
115{ 115{
116 struct twl4030_madc_battery *bat = container_of(psy, 116 struct twl4030_madc_battery *bat = power_supply_get_drvdata(psy);
117 struct twl4030_madc_battery, psy);
118 117
119 switch (psp) { 118 switch (psp) {
120 case POWER_SUPPLY_PROP_STATUS: 119 case POWER_SUPPLY_PROP_STATUS:
@@ -176,12 +175,19 @@ static int twl4030_madc_bat_get_property(struct power_supply *psy,
176 175
177static void twl4030_madc_bat_ext_changed(struct power_supply *psy) 176static void twl4030_madc_bat_ext_changed(struct power_supply *psy)
178{ 177{
179 struct twl4030_madc_battery *bat = container_of(psy, 178 power_supply_changed(psy);
180 struct twl4030_madc_battery, psy);
181
182 power_supply_changed(&bat->psy);
183} 179}
184 180
181static const struct power_supply_desc twl4030_madc_bat_desc = {
182 .name = "twl4030_battery",
183 .type = POWER_SUPPLY_TYPE_BATTERY,
184 .properties = twl4030_madc_bat_props,
185 .num_properties = ARRAY_SIZE(twl4030_madc_bat_props),
186 .get_property = twl4030_madc_bat_get_property,
187 .external_power_changed = twl4030_madc_bat_ext_changed,
188
189};
190
185static int twl4030_cmp(const void *a, const void *b) 191static int twl4030_cmp(const void *a, const void *b)
186{ 192{
187 return ((struct twl4030_madc_bat_calibration *)b)->voltage - 193 return ((struct twl4030_madc_bat_calibration *)b)->voltage -
@@ -192,21 +198,13 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
192{ 198{
193 struct twl4030_madc_battery *twl4030_madc_bat; 199 struct twl4030_madc_battery *twl4030_madc_bat;
194 struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data; 200 struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;
201 struct power_supply_config psy_cfg = {};
195 int ret = 0; 202 int ret = 0;
196 203
197 twl4030_madc_bat = kzalloc(sizeof(*twl4030_madc_bat), GFP_KERNEL); 204 twl4030_madc_bat = kzalloc(sizeof(*twl4030_madc_bat), GFP_KERNEL);
198 if (!twl4030_madc_bat) 205 if (!twl4030_madc_bat)
199 return -ENOMEM; 206 return -ENOMEM;
200 207
201 twl4030_madc_bat->psy.name = "twl4030_battery";
202 twl4030_madc_bat->psy.type = POWER_SUPPLY_TYPE_BATTERY;
203 twl4030_madc_bat->psy.properties = twl4030_madc_bat_props;
204 twl4030_madc_bat->psy.num_properties =
205 ARRAY_SIZE(twl4030_madc_bat_props);
206 twl4030_madc_bat->psy.get_property = twl4030_madc_bat_get_property;
207 twl4030_madc_bat->psy.external_power_changed =
208 twl4030_madc_bat_ext_changed;
209
210 /* sort charging and discharging calibration data */ 208 /* sort charging and discharging calibration data */
211 sort(pdata->charging, pdata->charging_size, 209 sort(pdata->charging, pdata->charging_size,
212 sizeof(struct twl4030_madc_bat_calibration), 210 sizeof(struct twl4030_madc_bat_calibration),
@@ -217,9 +215,14 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
217 215
218 twl4030_madc_bat->pdata = pdata; 216 twl4030_madc_bat->pdata = pdata;
219 platform_set_drvdata(pdev, twl4030_madc_bat); 217 platform_set_drvdata(pdev, twl4030_madc_bat);
220 ret = power_supply_register(&pdev->dev, &twl4030_madc_bat->psy, NULL); 218 psy_cfg.drv_data = twl4030_madc_bat;
221 if (ret < 0) 219 twl4030_madc_bat->psy = power_supply_register(&pdev->dev,
220 &twl4030_madc_bat_desc,
221 &psy_cfg);
222 if (IS_ERR(twl4030_madc_bat->psy)) {
223 ret = PTR_ERR(twl4030_madc_bat->psy);
222 kfree(twl4030_madc_bat); 224 kfree(twl4030_madc_bat);
225 }
223 226
224 return ret; 227 return ret;
225} 228}
@@ -228,7 +231,7 @@ static int twl4030_madc_battery_remove(struct platform_device *pdev)
228{ 231{
229 struct twl4030_madc_battery *bat = platform_get_drvdata(pdev); 232 struct twl4030_madc_battery *bat = platform_get_drvdata(pdev);
230 233
231 power_supply_unregister(&bat->psy); 234 power_supply_unregister(bat->psy);
232 kfree(bat); 235 kfree(bat);
233 236
234 return 0; 237 return 0;
diff --git a/drivers/power/wm831x_backup.c b/drivers/power/wm831x_backup.c
index 60ae871148b0..2e33109ca8c7 100644
--- a/drivers/power/wm831x_backup.c
+++ b/drivers/power/wm831x_backup.c
@@ -21,7 +21,8 @@
21 21
22struct wm831x_backup { 22struct wm831x_backup {
23 struct wm831x *wm831x; 23 struct wm831x *wm831x;
24 struct power_supply backup; 24 struct power_supply *backup;
25 struct power_supply_desc backup_desc;
25 char name[20]; 26 char name[20];
26}; 27};
27 28
@@ -115,7 +116,7 @@ static int wm831x_backup_get_prop(struct power_supply *psy,
115 enum power_supply_property psp, 116 enum power_supply_property psp,
116 union power_supply_propval *val) 117 union power_supply_propval *val)
117{ 118{
118 struct wm831x_backup *devdata = dev_get_drvdata(psy->dev->parent); 119 struct wm831x_backup *devdata = dev_get_drvdata(psy->dev.parent);
119 struct wm831x *wm831x = devdata->wm831x; 120 struct wm831x *wm831x = devdata->wm831x;
120 int ret = 0; 121 int ret = 0;
121 122
@@ -166,8 +167,6 @@ static int wm831x_backup_probe(struct platform_device *pdev)
166 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 167 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
167 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data; 168 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
168 struct wm831x_backup *devdata; 169 struct wm831x_backup *devdata;
169 struct power_supply *backup;
170 int ret;
171 170
172 devdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_backup), 171 devdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_backup),
173 GFP_KERNEL); 172 GFP_KERNEL);
@@ -177,8 +176,6 @@ static int wm831x_backup_probe(struct platform_device *pdev)
177 devdata->wm831x = wm831x; 176 devdata->wm831x = wm831x;
178 platform_set_drvdata(pdev, devdata); 177 platform_set_drvdata(pdev, devdata);
179 178
180 backup = &devdata->backup;
181
182 /* We ignore configuration failures since we can still read 179 /* We ignore configuration failures since we can still read
183 * back the status without enabling the charger (which may 180 * back the status without enabling the charger (which may
184 * already be enabled anyway). 181 * already be enabled anyway).
@@ -192,21 +189,22 @@ static int wm831x_backup_probe(struct platform_device *pdev)
192 snprintf(devdata->name, sizeof(devdata->name), 189 snprintf(devdata->name, sizeof(devdata->name),
193 "wm831x-backup"); 190 "wm831x-backup");
194 191
195 backup->name = devdata->name; 192 devdata->backup_desc.name = devdata->name;
196 backup->type = POWER_SUPPLY_TYPE_BATTERY; 193 devdata->backup_desc.type = POWER_SUPPLY_TYPE_BATTERY;
197 backup->properties = wm831x_backup_props; 194 devdata->backup_desc.properties = wm831x_backup_props;
198 backup->num_properties = ARRAY_SIZE(wm831x_backup_props); 195 devdata->backup_desc.num_properties = ARRAY_SIZE(wm831x_backup_props);
199 backup->get_property = wm831x_backup_get_prop; 196 devdata->backup_desc.get_property = wm831x_backup_get_prop;
200 ret = power_supply_register(&pdev->dev, backup, NULL); 197 devdata->backup = power_supply_register(&pdev->dev,
198 &devdata->backup_desc, NULL);
201 199
202 return ret; 200 return PTR_ERR_OR_ZERO(devdata->backup);
203} 201}
204 202
205static int wm831x_backup_remove(struct platform_device *pdev) 203static int wm831x_backup_remove(struct platform_device *pdev)
206{ 204{
207 struct wm831x_backup *devdata = platform_get_drvdata(pdev); 205 struct wm831x_backup *devdata = platform_get_drvdata(pdev);
208 206
209 power_supply_unregister(&devdata->backup); 207 power_supply_unregister(devdata->backup);
210 208
211 return 0; 209 return 0;
212} 210}
diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c
index a132aae6225d..0161bdabd5a3 100644
--- a/drivers/power/wm831x_power.c
+++ b/drivers/power/wm831x_power.c
@@ -21,9 +21,12 @@
21 21
22struct wm831x_power { 22struct wm831x_power {
23 struct wm831x *wm831x; 23 struct wm831x *wm831x;
24 struct power_supply wall; 24 struct power_supply *wall;
25 struct power_supply usb; 25 struct power_supply *usb;
26 struct power_supply battery; 26 struct power_supply *battery;
27 struct power_supply_desc wall_desc;
28 struct power_supply_desc usb_desc;
29 struct power_supply_desc battery_desc;
27 char wall_name[20]; 30 char wall_name[20];
28 char usb_name[20]; 31 char usb_name[20];
29 char battery_name[20]; 32 char battery_name[20];
@@ -67,7 +70,7 @@ static int wm831x_wall_get_prop(struct power_supply *psy,
67 enum power_supply_property psp, 70 enum power_supply_property psp,
68 union power_supply_propval *val) 71 union power_supply_propval *val)
69{ 72{
70 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent); 73 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev.parent);
71 struct wm831x *wm831x = wm831x_power->wm831x; 74 struct wm831x *wm831x = wm831x_power->wm831x;
72 int ret = 0; 75 int ret = 0;
73 76
@@ -98,7 +101,7 @@ static int wm831x_usb_get_prop(struct power_supply *psy,
98 enum power_supply_property psp, 101 enum power_supply_property psp,
99 union power_supply_propval *val) 102 union power_supply_propval *val)
100{ 103{
101 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent); 104 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev.parent);
102 struct wm831x *wm831x = wm831x_power->wm831x; 105 struct wm831x *wm831x = wm831x_power->wm831x;
103 int ret = 0; 106 int ret = 0;
104 107
@@ -393,7 +396,7 @@ static int wm831x_bat_get_prop(struct power_supply *psy,
393 enum power_supply_property psp, 396 enum power_supply_property psp,
394 union power_supply_propval *val) 397 union power_supply_propval *val)
395{ 398{
396 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent); 399 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev.parent);
397 struct wm831x *wm831x = wm831x_power->wm831x; 400 struct wm831x *wm831x = wm831x_power->wm831x;
398 int ret = 0; 401 int ret = 0;
399 402
@@ -451,7 +454,7 @@ static irqreturn_t wm831x_bat_irq(int irq, void *data)
451 /* The battery charger is autonomous so we don't need to do 454 /* The battery charger is autonomous so we don't need to do
452 * anything except kick user space */ 455 * anything except kick user space */
453 if (wm831x_power->have_battery) 456 if (wm831x_power->have_battery)
454 power_supply_changed(&wm831x_power->battery); 457 power_supply_changed(wm831x_power->battery);
455 458
456 return IRQ_HANDLED; 459 return IRQ_HANDLED;
457} 460}
@@ -482,9 +485,9 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
482 485
483 /* Just notify for everything - little harm in overnotifying. */ 486 /* Just notify for everything - little harm in overnotifying. */
484 if (wm831x_power->have_battery) 487 if (wm831x_power->have_battery)
485 power_supply_changed(&wm831x_power->battery); 488 power_supply_changed(wm831x_power->battery);
486 power_supply_changed(&wm831x_power->usb); 489 power_supply_changed(wm831x_power->usb);
487 power_supply_changed(&wm831x_power->wall); 490 power_supply_changed(wm831x_power->wall);
488 491
489 return IRQ_HANDLED; 492 return IRQ_HANDLED;
490} 493}
@@ -494,9 +497,6 @@ static int wm831x_power_probe(struct platform_device *pdev)
494 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 497 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
495 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data; 498 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
496 struct wm831x_power *power; 499 struct wm831x_power *power;
497 struct power_supply *usb;
498 struct power_supply *battery;
499 struct power_supply *wall;
500 int ret, irq, i; 500 int ret, irq, i;
501 501
502 power = kzalloc(sizeof(struct wm831x_power), GFP_KERNEL); 502 power = kzalloc(sizeof(struct wm831x_power), GFP_KERNEL);
@@ -506,10 +506,6 @@ static int wm831x_power_probe(struct platform_device *pdev)
506 power->wm831x = wm831x; 506 power->wm831x = wm831x;
507 platform_set_drvdata(pdev, power); 507 platform_set_drvdata(pdev, power);
508 508
509 usb = &power->usb;
510 battery = &power->battery;
511 wall = &power->wall;
512
513 if (wm831x_pdata && wm831x_pdata->wm831x_num) { 509 if (wm831x_pdata && wm831x_pdata->wm831x_num) {
514 snprintf(power->wall_name, sizeof(power->wall_name), 510 snprintf(power->wall_name, sizeof(power->wall_name),
515 "wm831x-wall.%d", wm831x_pdata->wm831x_num); 511 "wm831x-wall.%d", wm831x_pdata->wm831x_num);
@@ -531,23 +527,28 @@ static int wm831x_power_probe(struct platform_device *pdev)
531 */ 527 */
532 wm831x_config_battery(wm831x); 528 wm831x_config_battery(wm831x);
533 529
534 wall->name = power->wall_name; 530 power->wall_desc.name = power->wall_name;
535 wall->type = POWER_SUPPLY_TYPE_MAINS; 531 power->wall_desc.type = POWER_SUPPLY_TYPE_MAINS;
536 wall->properties = wm831x_wall_props; 532 power->wall_desc.properties = wm831x_wall_props;
537 wall->num_properties = ARRAY_SIZE(wm831x_wall_props); 533 power->wall_desc.num_properties = ARRAY_SIZE(wm831x_wall_props);
538 wall->get_property = wm831x_wall_get_prop; 534 power->wall_desc.get_property = wm831x_wall_get_prop;
539 ret = power_supply_register(&pdev->dev, wall, NULL); 535 power->wall = power_supply_register(&pdev->dev, &power->wall_desc,
540 if (ret) 536 NULL);
537 if (IS_ERR(power->wall)) {
538 ret = PTR_ERR(power->wall);
541 goto err_kmalloc; 539 goto err_kmalloc;
540 }
542 541
543 usb->name = power->usb_name, 542 power->usb_desc.name = power->usb_name,
544 usb->type = POWER_SUPPLY_TYPE_USB; 543 power->usb_desc.type = POWER_SUPPLY_TYPE_USB;
545 usb->properties = wm831x_usb_props; 544 power->usb_desc.properties = wm831x_usb_props;
546 usb->num_properties = ARRAY_SIZE(wm831x_usb_props); 545 power->usb_desc.num_properties = ARRAY_SIZE(wm831x_usb_props);
547 usb->get_property = wm831x_usb_get_prop; 546 power->usb_desc.get_property = wm831x_usb_get_prop;
548 ret = power_supply_register(&pdev->dev, usb, NULL); 547 power->usb = power_supply_register(&pdev->dev, &power->usb_desc, NULL);
549 if (ret) 548 if (IS_ERR(power->usb)) {
549 ret = PTR_ERR(power->usb);
550 goto err_wall; 550 goto err_wall;
551 }
551 552
552 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_CONTROL_1); 553 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_CONTROL_1);
553 if (ret < 0) 554 if (ret < 0)
@@ -555,14 +556,18 @@ static int wm831x_power_probe(struct platform_device *pdev)
555 power->have_battery = ret & WM831X_CHG_ENA; 556 power->have_battery = ret & WM831X_CHG_ENA;
556 557
557 if (power->have_battery) { 558 if (power->have_battery) {
558 battery->name = power->battery_name; 559 power->battery_desc.name = power->battery_name;
559 battery->properties = wm831x_bat_props; 560 power->battery_desc.properties = wm831x_bat_props;
560 battery->num_properties = ARRAY_SIZE(wm831x_bat_props); 561 power->battery_desc.num_properties = ARRAY_SIZE(wm831x_bat_props);
561 battery->get_property = wm831x_bat_get_prop; 562 power->battery_desc.get_property = wm831x_bat_get_prop;
562 battery->use_for_apm = 1; 563 power->battery_desc.use_for_apm = 1;
563 ret = power_supply_register(&pdev->dev, battery, NULL); 564 power->battery = power_supply_register(&pdev->dev,
564 if (ret) 565 &power->battery_desc,
565 goto err_usb; 566 NULL);
567 if (IS_ERR(power->battery)) {
568 ret = PTR_ERR(power->battery);
569 goto err_usb;
570 }
566 } 571 }
567 572
568 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "SYSLO")); 573 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "SYSLO"));
@@ -615,11 +620,11 @@ err_syslo:
615 free_irq(irq, power); 620 free_irq(irq, power);
616err_battery: 621err_battery:
617 if (power->have_battery) 622 if (power->have_battery)
618 power_supply_unregister(battery); 623 power_supply_unregister(power->battery);
619err_usb: 624err_usb:
620 power_supply_unregister(usb); 625 power_supply_unregister(power->usb);
621err_wall: 626err_wall:
622 power_supply_unregister(wall); 627 power_supply_unregister(power->wall);
623err_kmalloc: 628err_kmalloc:
624 kfree(power); 629 kfree(power);
625 return ret; 630 return ret;
@@ -645,9 +650,9 @@ static int wm831x_power_remove(struct platform_device *pdev)
645 free_irq(irq, wm831x_power); 650 free_irq(irq, wm831x_power);
646 651
647 if (wm831x_power->have_battery) 652 if (wm831x_power->have_battery)
648 power_supply_unregister(&wm831x_power->battery); 653 power_supply_unregister(wm831x_power->battery);
649 power_supply_unregister(&wm831x_power->wall); 654 power_supply_unregister(wm831x_power->wall);
650 power_supply_unregister(&wm831x_power->usb); 655 power_supply_unregister(wm831x_power->usb);
651 kfree(wm831x_power); 656 kfree(wm831x_power);
652 return 0; 657 return 0;
653} 658}
diff --git a/drivers/power/wm8350_power.c b/drivers/power/wm8350_power.c
index 261ceca561d5..5c5880664e09 100644
--- a/drivers/power/wm8350_power.c
+++ b/drivers/power/wm8350_power.c
@@ -196,14 +196,14 @@ static irqreturn_t wm8350_charger_handler(int irq, void *data)
196 break; 196 break;
197 case WM8350_IRQ_CHG_TO: 197 case WM8350_IRQ_CHG_TO:
198 dev_err(wm8350->dev, "charger timeout\n"); 198 dev_err(wm8350->dev, "charger timeout\n");
199 power_supply_changed(&power->battery); 199 power_supply_changed(power->battery);
200 break; 200 break;
201 201
202 case WM8350_IRQ_CHG_BAT_HOT: 202 case WM8350_IRQ_CHG_BAT_HOT:
203 case WM8350_IRQ_CHG_BAT_COLD: 203 case WM8350_IRQ_CHG_BAT_COLD:
204 case WM8350_IRQ_CHG_START: 204 case WM8350_IRQ_CHG_START:
205 case WM8350_IRQ_CHG_END: 205 case WM8350_IRQ_CHG_END:
206 power_supply_changed(&power->battery); 206 power_supply_changed(power->battery);
207 break; 207 break;
208 208
209 case WM8350_IRQ_CHG_FAST_RDY: 209 case WM8350_IRQ_CHG_FAST_RDY:
@@ -231,9 +231,9 @@ static irqreturn_t wm8350_charger_handler(int irq, void *data)
231 case WM8350_IRQ_EXT_WALL_FB: 231 case WM8350_IRQ_EXT_WALL_FB:
232 wm8350_charger_config(wm8350, policy); 232 wm8350_charger_config(wm8350, policy);
233 case WM8350_IRQ_EXT_BAT_FB: /* Fall through */ 233 case WM8350_IRQ_EXT_BAT_FB: /* Fall through */
234 power_supply_changed(&power->battery); 234 power_supply_changed(power->battery);
235 power_supply_changed(&power->usb); 235 power_supply_changed(power->usb);
236 power_supply_changed(&power->ac); 236 power_supply_changed(power->ac);
237 break; 237 break;
238 238
239 default: 239 default:
@@ -250,7 +250,7 @@ static int wm8350_ac_get_prop(struct power_supply *psy,
250 enum power_supply_property psp, 250 enum power_supply_property psp,
251 union power_supply_propval *val) 251 union power_supply_propval *val)
252{ 252{
253 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); 253 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent);
254 int ret = 0; 254 int ret = 0;
255 255
256 switch (psp) { 256 switch (psp) {
@@ -280,7 +280,7 @@ static int wm8350_usb_get_prop(struct power_supply *psy,
280 enum power_supply_property psp, 280 enum power_supply_property psp,
281 union power_supply_propval *val) 281 union power_supply_propval *val)
282{ 282{
283 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); 283 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent);
284 int ret = 0; 284 int ret = 0;
285 285
286 switch (psp) { 286 switch (psp) {
@@ -346,7 +346,7 @@ static int wm8350_bat_get_property(struct power_supply *psy,
346 enum power_supply_property psp, 346 enum power_supply_property psp,
347 union power_supply_propval *val) 347 union power_supply_propval *val)
348{ 348{
349 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); 349 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent);
350 int ret = 0; 350 int ret = 0;
351 351
352 switch (psp) { 352 switch (psp) {
@@ -382,6 +382,30 @@ static enum power_supply_property wm8350_bat_props[] = {
382 POWER_SUPPLY_PROP_CHARGE_TYPE, 382 POWER_SUPPLY_PROP_CHARGE_TYPE,
383}; 383};
384 384
385static const struct power_supply_desc wm8350_ac_desc = {
386 .name = "wm8350-ac",
387 .type = POWER_SUPPLY_TYPE_MAINS,
388 .properties = wm8350_ac_props,
389 .num_properties = ARRAY_SIZE(wm8350_ac_props),
390 .get_property = wm8350_ac_get_prop,
391};
392
393static const struct power_supply_desc wm8350_battery_desc = {
394 .name = "wm8350-battery",
395 .properties = wm8350_bat_props,
396 .num_properties = ARRAY_SIZE(wm8350_bat_props),
397 .get_property = wm8350_bat_get_property,
398 .use_for_apm = 1,
399};
400
401static const struct power_supply_desc wm8350_usb_desc = {
402 .name = "wm8350-usb",
403 .type = POWER_SUPPLY_TYPE_USB,
404 .properties = wm8350_usb_props,
405 .num_properties = ARRAY_SIZE(wm8350_usb_props),
406 .get_property = wm8350_usb_get_prop,
407};
408
385/********************************************************************* 409/*********************************************************************
386 * Initialisation 410 * Initialisation
387 *********************************************************************/ 411 *********************************************************************/
@@ -447,37 +471,24 @@ static int wm8350_power_probe(struct platform_device *pdev)
447 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 471 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
448 struct wm8350_power *power = &wm8350->power; 472 struct wm8350_power *power = &wm8350->power;
449 struct wm8350_charger_policy *policy = power->policy; 473 struct wm8350_charger_policy *policy = power->policy;
450 struct power_supply *usb = &power->usb;
451 struct power_supply *battery = &power->battery;
452 struct power_supply *ac = &power->ac;
453 int ret; 474 int ret;
454 475
455 ac->name = "wm8350-ac"; 476 power->ac = power_supply_register(&pdev->dev, &wm8350_ac_desc, NULL);
456 ac->type = POWER_SUPPLY_TYPE_MAINS; 477 if (IS_ERR(power->ac))
457 ac->properties = wm8350_ac_props; 478 return PTR_ERR(power->ac);
458 ac->num_properties = ARRAY_SIZE(wm8350_ac_props); 479
459 ac->get_property = wm8350_ac_get_prop; 480 power->battery = power_supply_register(&pdev->dev, &wm8350_battery_desc,
460 ret = power_supply_register(&pdev->dev, ac, NULL); 481 NULL);
461 if (ret) 482 if (IS_ERR(power->battery)) {
462 return ret; 483 ret = PTR_ERR(power->battery);
463
464 battery->name = "wm8350-battery";
465 battery->properties = wm8350_bat_props;
466 battery->num_properties = ARRAY_SIZE(wm8350_bat_props);
467 battery->get_property = wm8350_bat_get_property;
468 battery->use_for_apm = 1;
469 ret = power_supply_register(&pdev->dev, battery, NULL);
470 if (ret)
471 goto battery_failed; 484 goto battery_failed;
485 }
472 486
473 usb->name = "wm8350-usb", 487 power->usb = power_supply_register(&pdev->dev, &wm8350_usb_desc, NULL);
474 usb->type = POWER_SUPPLY_TYPE_USB; 488 if (IS_ERR(power->usb)) {
475 usb->properties = wm8350_usb_props; 489 ret = PTR_ERR(power->usb);
476 usb->num_properties = ARRAY_SIZE(wm8350_usb_props);
477 usb->get_property = wm8350_usb_get_prop;
478 ret = power_supply_register(&pdev->dev, usb, NULL);
479 if (ret)
480 goto usb_failed; 490 goto usb_failed;
491 }
481 492
482 ret = device_create_file(&pdev->dev, &dev_attr_charger_state); 493 ret = device_create_file(&pdev->dev, &dev_attr_charger_state);
483 if (ret < 0) 494 if (ret < 0)
@@ -494,9 +505,9 @@ static int wm8350_power_probe(struct platform_device *pdev)
494 return ret; 505 return ret;
495 506
496usb_failed: 507usb_failed:
497 power_supply_unregister(battery); 508 power_supply_unregister(power->battery);
498battery_failed: 509battery_failed:
499 power_supply_unregister(ac); 510 power_supply_unregister(power->ac);
500 511
501 return ret; 512 return ret;
502} 513}
@@ -508,9 +519,9 @@ static int wm8350_power_remove(struct platform_device *pdev)
508 519
509 free_charger_irq(wm8350); 520 free_charger_irq(wm8350);
510 device_remove_file(&pdev->dev, &dev_attr_charger_state); 521 device_remove_file(&pdev->dev, &dev_attr_charger_state);
511 power_supply_unregister(&power->battery); 522 power_supply_unregister(power->battery);
512 power_supply_unregister(&power->ac); 523 power_supply_unregister(power->ac);
513 power_supply_unregister(&power->usb); 524 power_supply_unregister(power->usb);
514 return 0; 525 return 0;
515} 526}
516 527
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index e81e917bd9d0..c2f09ed35050 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -32,20 +32,20 @@ static enum power_supply_property *prop;
32 32
33static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) 33static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
34{ 34{
35 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; 35 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
36 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; 36 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
37 37
38 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent), 38 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
39 pdata->batt_aux) * pdata->batt_mult / 39 pdata->batt_aux) * pdata->batt_mult /
40 pdata->batt_div; 40 pdata->batt_div;
41} 41}
42 42
43static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) 43static unsigned long wm97xx_read_temp(struct power_supply *bat_ps)
44{ 44{
45 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; 45 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
46 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; 46 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
47 47
48 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent), 48 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
49 pdata->temp_aux) * pdata->temp_mult / 49 pdata->temp_aux) * pdata->temp_mult /
50 pdata->temp_div; 50 pdata->temp_div;
51} 51}
@@ -54,7 +54,7 @@ static int wm97xx_bat_get_property(struct power_supply *bat_ps,
54 enum power_supply_property psp, 54 enum power_supply_property psp,
55 union power_supply_propval *val) 55 union power_supply_propval *val)
56{ 56{
57 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; 57 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
58 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; 58 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
59 59
60 switch (psp) { 60 switch (psp) {
@@ -105,7 +105,7 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps)
105static void wm97xx_bat_update(struct power_supply *bat_ps) 105static void wm97xx_bat_update(struct power_supply *bat_ps)
106{ 106{
107 int old_status = bat_status; 107 int old_status = bat_status;
108 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data; 108 struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data;
109 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata; 109 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
110 110
111 mutex_lock(&work_lock); 111 mutex_lock(&work_lock);
@@ -117,7 +117,7 @@ static void wm97xx_bat_update(struct power_supply *bat_ps)
117 POWER_SUPPLY_STATUS_UNKNOWN; 117 POWER_SUPPLY_STATUS_UNKNOWN;
118 118
119 if (old_status != bat_status) { 119 if (old_status != bat_status) {
120 pr_debug("%s: %i -> %i\n", bat_ps->name, old_status, 120 pr_debug("%s: %i -> %i\n", bat_ps->desc->name, old_status,
121 bat_status); 121 bat_status);
122 power_supply_changed(bat_ps); 122 power_supply_changed(bat_ps);
123 } 123 }
@@ -125,7 +125,8 @@ static void wm97xx_bat_update(struct power_supply *bat_ps)
125 mutex_unlock(&work_lock); 125 mutex_unlock(&work_lock);
126} 126}
127 127
128static struct power_supply bat_ps = { 128static struct power_supply *bat_psy;
129static struct power_supply_desc bat_psy_desc = {
129 .type = POWER_SUPPLY_TYPE_BATTERY, 130 .type = POWER_SUPPLY_TYPE_BATTERY,
130 .get_property = wm97xx_bat_get_property, 131 .get_property = wm97xx_bat_get_property,
131 .external_power_changed = wm97xx_bat_external_power_changed, 132 .external_power_changed = wm97xx_bat_external_power_changed,
@@ -134,7 +135,7 @@ static struct power_supply bat_ps = {
134 135
135static void wm97xx_bat_work(struct work_struct *work) 136static void wm97xx_bat_work(struct work_struct *work)
136{ 137{
137 wm97xx_bat_update(&bat_ps); 138 wm97xx_bat_update(bat_psy);
138} 139}
139 140
140static irqreturn_t wm97xx_chrg_irq(int irq, void *data) 141static irqreturn_t wm97xx_chrg_irq(int irq, void *data)
@@ -237,18 +238,20 @@ static int wm97xx_bat_probe(struct platform_device *dev)
237 dev_info(&dev->dev, "Please consider setting proper battery " 238 dev_info(&dev->dev, "Please consider setting proper battery "
238 "name in platform definition file, falling " 239 "name in platform definition file, falling "
239 "back to name \"wm97xx-batt\"\n"); 240 "back to name \"wm97xx-batt\"\n");
240 bat_ps.name = "wm97xx-batt"; 241 bat_psy_desc.name = "wm97xx-batt";
241 } else 242 } else
242 bat_ps.name = pdata->batt_name; 243 bat_psy_desc.name = pdata->batt_name;
243 244
244 bat_ps.properties = prop; 245 bat_psy_desc.properties = prop;
245 bat_ps.num_properties = props; 246 bat_psy_desc.num_properties = props;
246 247
247 ret = power_supply_register(&dev->dev, &bat_ps, NULL); 248 bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, NULL);
248 if (!ret) 249 if (!IS_ERR(bat_psy)) {
249 schedule_work(&bat_work); 250 schedule_work(&bat_work);
250 else 251 } else {
252 ret = PTR_ERR(bat_psy);
251 goto err4; 253 goto err4;
254 }
252 255
253 return 0; 256 return 0;
254err4: 257err4:
@@ -273,7 +276,7 @@ static int wm97xx_bat_remove(struct platform_device *dev)
273 gpio_free(pdata->charge_gpio); 276 gpio_free(pdata->charge_gpio);
274 } 277 }
275 cancel_work_sync(&bat_work); 278 cancel_work_sync(&bat_work);
276 power_supply_unregister(&bat_ps); 279 power_supply_unregister(bat_psy);
277 kfree(prop); 280 kfree(prop);
278 return 0; 281 return 0;
279} 282}
diff --git a/drivers/power/z2_battery.c b/drivers/power/z2_battery.c
index df22364212dd..b201e3facf73 100644
--- a/drivers/power/z2_battery.c
+++ b/drivers/power/z2_battery.c
@@ -21,12 +21,13 @@
21#define Z2_DEFAULT_NAME "Z2" 21#define Z2_DEFAULT_NAME "Z2"
22 22
23struct z2_charger { 23struct z2_charger {
24 struct z2_battery_info *info; 24 struct z2_battery_info *info;
25 int bat_status; 25 int bat_status;
26 struct i2c_client *client; 26 struct i2c_client *client;
27 struct power_supply batt_ps; 27 struct power_supply *batt_ps;
28 struct mutex work_lock; 28 struct power_supply_desc batt_ps_desc;
29 struct work_struct bat_work; 29 struct mutex work_lock;
30 struct work_struct bat_work;
30}; 31};
31 32
32static unsigned long z2_read_bat(struct z2_charger *charger) 33static unsigned long z2_read_bat(struct z2_charger *charger)
@@ -44,8 +45,7 @@ static int z2_batt_get_property(struct power_supply *batt_ps,
44 enum power_supply_property psp, 45 enum power_supply_property psp,
45 union power_supply_propval *val) 46 union power_supply_propval *val)
46{ 47{
47 struct z2_charger *charger = container_of(batt_ps, struct z2_charger, 48 struct z2_charger *charger = power_supply_get_drvdata(batt_ps);
48 batt_ps);
49 struct z2_battery_info *info = charger->info; 49 struct z2_battery_info *info = charger->info;
50 50
51 switch (psp) { 51 switch (psp) {
@@ -85,8 +85,8 @@ static int z2_batt_get_property(struct power_supply *batt_ps,
85 85
86static void z2_batt_ext_power_changed(struct power_supply *batt_ps) 86static void z2_batt_ext_power_changed(struct power_supply *batt_ps)
87{ 87{
88 struct z2_charger *charger = container_of(batt_ps, struct z2_charger, 88 struct z2_charger *charger = power_supply_get_drvdata(batt_ps);
89 batt_ps); 89
90 schedule_work(&charger->bat_work); 90 schedule_work(&charger->bat_work);
91} 91}
92 92
@@ -106,9 +106,10 @@ static void z2_batt_update(struct z2_charger *charger)
106 POWER_SUPPLY_STATUS_UNKNOWN; 106 POWER_SUPPLY_STATUS_UNKNOWN;
107 107
108 if (old_status != charger->bat_status) { 108 if (old_status != charger->bat_status) {
109 pr_debug("%s: %i -> %i\n", charger->batt_ps.name, old_status, 109 pr_debug("%s: %i -> %i\n", charger->batt_ps->desc->name,
110 charger->bat_status); 110 old_status,
111 power_supply_changed(&charger->batt_ps); 111 charger->bat_status);
112 power_supply_changed(charger->batt_ps);
112 } 113 }
113 114
114 mutex_unlock(&charger->work_lock); 115 mutex_unlock(&charger->work_lock);
@@ -166,16 +167,17 @@ static int z2_batt_ps_init(struct z2_charger *charger, int props)
166 "Please consider setting proper battery " 167 "Please consider setting proper battery "
167 "name in platform definition file, falling " 168 "name in platform definition file, falling "
168 "back to name \" Z2_DEFAULT_NAME \"\n"); 169 "back to name \" Z2_DEFAULT_NAME \"\n");
169 charger->batt_ps.name = Z2_DEFAULT_NAME; 170 charger->batt_ps_desc.name = Z2_DEFAULT_NAME;
170 } else 171 } else
171 charger->batt_ps.name = info->batt_name; 172 charger->batt_ps_desc.name = info->batt_name;
172 173
173 charger->batt_ps.properties = prop; 174 charger->batt_ps_desc.properties = prop;
174 charger->batt_ps.num_properties = props; 175 charger->batt_ps_desc.num_properties = props;
175 charger->batt_ps.type = POWER_SUPPLY_TYPE_BATTERY; 176 charger->batt_ps_desc.type = POWER_SUPPLY_TYPE_BATTERY;
176 charger->batt_ps.get_property = z2_batt_get_property; 177 charger->batt_ps_desc.get_property = z2_batt_get_property;
177 charger->batt_ps.external_power_changed = z2_batt_ext_power_changed; 178 charger->batt_ps_desc.external_power_changed =
178 charger->batt_ps.use_for_apm = 1; 179 z2_batt_ext_power_changed;
180 charger->batt_ps_desc.use_for_apm = 1;
179 181
180 return 0; 182 return 0;
181} 183}
@@ -187,6 +189,7 @@ static int z2_batt_probe(struct i2c_client *client,
187 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */ 189 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */
188 struct z2_charger *charger; 190 struct z2_charger *charger;
189 struct z2_battery_info *info = client->dev.platform_data; 191 struct z2_battery_info *info = client->dev.platform_data;
192 struct power_supply_config psy_cfg = {};
190 193
191 if (info == NULL) { 194 if (info == NULL) {
192 dev_err(&client->dev, 195 dev_err(&client->dev,
@@ -203,6 +206,7 @@ static int z2_batt_probe(struct i2c_client *client,
203 charger->info = info; 206 charger->info = info;
204 charger->client = client; 207 charger->client = client;
205 i2c_set_clientdata(client, charger); 208 i2c_set_clientdata(client, charger);
209 psy_cfg.drv_data = charger;
206 210
207 mutex_init(&charger->work_lock); 211 mutex_init(&charger->work_lock);
208 212
@@ -230,16 +234,20 @@ static int z2_batt_probe(struct i2c_client *client,
230 234
231 INIT_WORK(&charger->bat_work, z2_batt_work); 235 INIT_WORK(&charger->bat_work, z2_batt_work);
232 236
233 ret = power_supply_register(&client->dev, &charger->batt_ps, NULL); 237 charger->batt_ps = power_supply_register(&client->dev,
234 if (ret) 238 &charger->batt_ps_desc,
239 &psy_cfg);
240 if (IS_ERR(charger->batt_ps)) {
241 ret = PTR_ERR(charger->batt_ps);
235 goto err4; 242 goto err4;
243 }
236 244
237 schedule_work(&charger->bat_work); 245 schedule_work(&charger->bat_work);
238 246
239 return 0; 247 return 0;
240 248
241err4: 249err4:
242 kfree(charger->batt_ps.properties); 250 kfree(charger->batt_ps_desc.properties);
243err3: 251err3:
244 if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) 252 if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio))
245 free_irq(gpio_to_irq(info->charge_gpio), charger); 253 free_irq(gpio_to_irq(info->charge_gpio), charger);
@@ -257,9 +265,9 @@ static int z2_batt_remove(struct i2c_client *client)
257 struct z2_battery_info *info = charger->info; 265 struct z2_battery_info *info = charger->info;
258 266
259 cancel_work_sync(&charger->bat_work); 267 cancel_work_sync(&charger->bat_work);
260 power_supply_unregister(&charger->batt_ps); 268 power_supply_unregister(charger->batt_ps);
261 269
262 kfree(charger->batt_ps.properties); 270 kfree(charger->batt_ps_desc.properties);
263 if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) { 271 if (info->charge_gpio >= 0 && gpio_is_valid(info->charge_gpio)) {
264 free_irq(gpio_to_irq(info->charge_gpio), charger); 272 free_irq(gpio_to_irq(info->charge_gpio), charger);
265 gpio_free(info->charge_gpio); 273 gpio_free(info->charge_gpio);
diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index 4bfa84672818..30b66c3c9b73 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -82,8 +82,8 @@ struct bat_response {
82 }; 82 };
83}; 83};
84 84
85static struct power_supply nvec_bat_psy; 85static struct power_supply *nvec_bat_psy;
86static struct power_supply nvec_psy; 86static struct power_supply *nvec_psy;
87 87
88static int nvec_power_notifier(struct notifier_block *nb, 88static int nvec_power_notifier(struct notifier_block *nb,
89 unsigned long event_type, void *data) 89 unsigned long event_type, void *data)
@@ -98,7 +98,7 @@ static int nvec_power_notifier(struct notifier_block *nb,
98 if (res->sub_type == 0) { 98 if (res->sub_type == 0) {
99 if (power->on != res->plu) { 99 if (power->on != res->plu) {
100 power->on = res->plu; 100 power->on = res->plu;
101 power_supply_changed(&nvec_psy); 101 power_supply_changed(nvec_psy);
102 } 102 }
103 return NOTIFY_STOP; 103 return NOTIFY_STOP;
104 } 104 }
@@ -167,7 +167,7 @@ static int nvec_power_bat_notifier(struct notifier_block *nb,
167 } 167 }
168 power->bat_cap = res->plc[1]; 168 power->bat_cap = res->plc[1];
169 if (status_changed) 169 if (status_changed)
170 power_supply_changed(&nvec_bat_psy); 170 power_supply_changed(nvec_bat_psy);
171 break; 171 break;
172 case VOLTAGE: 172 case VOLTAGE:
173 power->bat_voltage_now = res->plu * 1000; 173 power->bat_voltage_now = res->plu * 1000;
@@ -225,7 +225,7 @@ static int nvec_power_get_property(struct power_supply *psy,
225 enum power_supply_property psp, 225 enum power_supply_property psp,
226 union power_supply_propval *val) 226 union power_supply_propval *val)
227{ 227{
228 struct nvec_power *power = dev_get_drvdata(psy->dev->parent); 228 struct nvec_power *power = dev_get_drvdata(psy->dev.parent);
229 229
230 switch (psp) { 230 switch (psp) {
231 case POWER_SUPPLY_PROP_ONLINE: 231 case POWER_SUPPLY_PROP_ONLINE:
@@ -241,7 +241,7 @@ static int nvec_battery_get_property(struct power_supply *psy,
241 enum power_supply_property psp, 241 enum power_supply_property psp,
242 union power_supply_propval *val) 242 union power_supply_propval *val)
243{ 243{
244 struct nvec_power *power = dev_get_drvdata(psy->dev->parent); 244 struct nvec_power *power = dev_get_drvdata(psy->dev.parent);
245 245
246 switch (psp) { 246 switch (psp) {
247 case POWER_SUPPLY_PROP_STATUS: 247 case POWER_SUPPLY_PROP_STATUS:
@@ -323,7 +323,7 @@ static char *nvec_power_supplied_to[] = {
323 "battery", 323 "battery",
324}; 324};
325 325
326static struct power_supply nvec_bat_psy = { 326static const struct power_supply_desc nvec_bat_psy_desc = {
327 .name = "battery", 327 .name = "battery",
328 .type = POWER_SUPPLY_TYPE_BATTERY, 328 .type = POWER_SUPPLY_TYPE_BATTERY,
329 .properties = nvec_battery_props, 329 .properties = nvec_battery_props,
@@ -331,7 +331,7 @@ static struct power_supply nvec_bat_psy = {
331 .get_property = nvec_battery_get_property, 331 .get_property = nvec_battery_get_property,
332}; 332};
333 333
334static struct power_supply nvec_psy = { 334static const struct power_supply_desc nvec_psy_desc = {
335 .name = "ac", 335 .name = "ac",
336 .type = POWER_SUPPLY_TYPE_MAINS, 336 .type = POWER_SUPPLY_TYPE_MAINS,
337 .properties = nvec_power_props, 337 .properties = nvec_power_props,
@@ -371,7 +371,8 @@ static void nvec_power_poll(struct work_struct *work)
371 371
372static int nvec_power_probe(struct platform_device *pdev) 372static int nvec_power_probe(struct platform_device *pdev)
373{ 373{
374 struct power_supply *psy; 374 struct power_supply **psy;
375 const struct power_supply_desc *psy_desc;
375 struct nvec_power *power; 376 struct nvec_power *power;
376 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 377 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
377 struct power_supply_config psy_cfg = {}; 378 struct power_supply_config psy_cfg = {};
@@ -386,6 +387,7 @@ static int nvec_power_probe(struct platform_device *pdev)
386 switch (pdev->id) { 387 switch (pdev->id) {
387 case AC: 388 case AC:
388 psy = &nvec_psy; 389 psy = &nvec_psy;
390 psy_desc = &nvec_psy_desc;
389 psy_cfg.supplied_to = nvec_power_supplied_to; 391 psy_cfg.supplied_to = nvec_power_supplied_to;
390 psy_cfg.num_supplicants = ARRAY_SIZE(nvec_power_supplied_to); 392 psy_cfg.num_supplicants = ARRAY_SIZE(nvec_power_supplied_to);
391 393
@@ -396,6 +398,7 @@ static int nvec_power_probe(struct platform_device *pdev)
396 break; 398 break;
397 case BAT: 399 case BAT:
398 psy = &nvec_bat_psy; 400 psy = &nvec_bat_psy;
401 psy_desc = &nvec_bat_psy_desc;
399 402
400 power->notifier.notifier_call = nvec_power_bat_notifier; 403 power->notifier.notifier_call = nvec_power_bat_notifier;
401 break; 404 break;
@@ -408,7 +411,9 @@ static int nvec_power_probe(struct platform_device *pdev)
408 if (pdev->id == BAT) 411 if (pdev->id == BAT)
409 get_bat_mfg_data(power); 412 get_bat_mfg_data(power);
410 413
411 return power_supply_register(&pdev->dev, psy, &psy_cfg); 414 *psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
415
416 return PTR_ERR_OR_ZERO(*psy);
412} 417}
413 418
414static int nvec_power_remove(struct platform_device *pdev) 419static int nvec_power_remove(struct platform_device *pdev)
@@ -419,10 +424,10 @@ static int nvec_power_remove(struct platform_device *pdev)
419 nvec_unregister_notifier(power->nvec, &power->notifier); 424 nvec_unregister_notifier(power->nvec, &power->notifier);
420 switch (pdev->id) { 425 switch (pdev->id) {
421 case AC: 426 case AC:
422 power_supply_unregister(&nvec_psy); 427 power_supply_unregister(nvec_psy);
423 break; 428 break;
424 case BAT: 429 case BAT:
425 power_supply_unregister(&nvec_bat_psy); 430 power_supply_unregister(nvec_bat_psy);
426 } 431 }
427 432
428 return 0; 433 return 0;