aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/Kconfig7
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/ds2760_battery.c147
-rw-r--r--drivers/power/olpc_battery.c50
-rw-r--r--drivers/power/power_supply_core.c44
-rw-r--r--drivers/power/power_supply_sysfs.c12
-rw-r--r--drivers/power/wm831x_power.c779
-rw-r--r--drivers/power/wm8350_power.c22
-rw-r--r--drivers/power/wm97xx_battery.c79
9 files changed, 1089 insertions, 52 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index bdbc4f73fcdc..cea6cef27e89 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -29,6 +29,13 @@ config APM_POWER
29 Say Y here to enable support APM status emulation using 29 Say Y here to enable support APM status emulation using
30 battery class devices. 30 battery class devices.
31 31
32config WM831X_POWER
33 tristate "WM831X PMU support"
34 depends on MFD_WM831X
35 help
36 Say Y here to enable support for the power management unit
37 provided by Wolfson Microelectronics WM831x PMICs.
38
32config WM8350_POWER 39config WM8350_POWER
33 tristate "WM8350 PMU support" 40 tristate "WM8350 PMU support"
34 depends on MFD_WM8350 41 depends on MFD_WM8350
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 380d17c9ae29..b96f29d91c28 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_POWER_SUPPLY) += power_supply.o
16 16
17obj-$(CONFIG_PDA_POWER) += pda_power.o 17obj-$(CONFIG_PDA_POWER) += pda_power.o
18obj-$(CONFIG_APM_POWER) += apm_power.o 18obj-$(CONFIG_APM_POWER) += apm_power.o
19obj-$(CONFIG_WM831X_POWER) += wm831x_power.o
19obj-$(CONFIG_WM8350_POWER) += wm8350_power.o 20obj-$(CONFIG_WM8350_POWER) += wm8350_power.o
20 21
21obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o 22obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c
index 520b5c49ff30..6f1dba5a519d 100644
--- a/drivers/power/ds2760_battery.c
+++ b/drivers/power/ds2760_battery.c
@@ -56,6 +56,7 @@ struct ds2760_device_info {
56 struct device *w1_dev; 56 struct device *w1_dev;
57 struct workqueue_struct *monitor_wqueue; 57 struct workqueue_struct *monitor_wqueue;
58 struct delayed_work monitor_work; 58 struct delayed_work monitor_work;
59 struct delayed_work set_charged_work;
59}; 60};
60 61
61static unsigned int cache_time = 1000; 62static unsigned int cache_time = 1000;
@@ -66,6 +67,14 @@ static unsigned int pmod_enabled;
66module_param(pmod_enabled, bool, 0644); 67module_param(pmod_enabled, bool, 0644);
67MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit"); 68MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
68 69
70static unsigned int rated_capacity;
71module_param(rated_capacity, uint, 0644);
72MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
73
74static unsigned int current_accum;
75module_param(current_accum, uint, 0644);
76MODULE_PARM_DESC(current_accum, "current accumulator value");
77
69/* Some batteries have their rated capacity stored a N * 10 mAh, while 78/* Some batteries have their rated capacity stored a N * 10 mAh, while
70 * others use an index into this table. */ 79 * others use an index into this table. */
71static int rated_capacities[] = { 80static int rated_capacities[] = {
@@ -168,8 +177,13 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
168 di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 | 177 di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 |
169 di->raw[DS2760_ACTIVE_FULL + 1]; 178 di->raw[DS2760_ACTIVE_FULL + 1];
170 179
171 scale[0] = di->raw[DS2760_ACTIVE_FULL] << 8 | 180 /* If the full_active_uAh value is not given, fall back to the rated
172 di->raw[DS2760_ACTIVE_FULL + 1]; 181 * capacity. This is likely to happen when chips are not part of the
182 * battery pack and is therefore not bootstrapped. */
183 if (di->full_active_uAh == 0)
184 di->full_active_uAh = di->rated_capacity / 1000L;
185
186 scale[0] = di->full_active_uAh;
173 for (i = 1; i < 5; i++) 187 for (i = 1; i < 5; i++)
174 scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 2 + i]; 188 scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 2 + i];
175 189
@@ -197,15 +211,31 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
197 if (di->rem_capacity > 100) 211 if (di->rem_capacity > 100)
198 di->rem_capacity = 100; 212 di->rem_capacity = 100;
199 213
200 if (di->current_uA) 214 if (di->current_uA >= 100L)
201 di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 215 di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 36L)
202 3600L) / di->current_uA; 216 / (di->current_uA / 100L);
203 else 217 else
204 di->life_sec = 0; 218 di->life_sec = 0;
205 219
206 return 0; 220 return 0;
207} 221}
208 222
223static void ds2760_battery_set_current_accum(struct ds2760_device_info *di,
224 unsigned int acr_val)
225{
226 unsigned char acr[2];
227
228 /* acr is in units of 0.25 mAh */
229 acr_val *= 4L;
230 acr_val /= 1000;
231
232 acr[0] = acr_val >> 8;
233 acr[1] = acr_val & 0xff;
234
235 if (w1_ds2760_write(di->w1_dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2)
236 dev_warn(di->dev, "ACR write failed\n");
237}
238
209static void ds2760_battery_update_status(struct ds2760_device_info *di) 239static void ds2760_battery_update_status(struct ds2760_device_info *di)
210{ 240{
211 int old_charge_status = di->charge_status; 241 int old_charge_status = di->charge_status;
@@ -237,21 +267,9 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
237 if (di->full_counter < 2) { 267 if (di->full_counter < 2) {
238 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 268 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
239 } else { 269 } else {
240 unsigned char acr[2];
241 int acr_val;
242
243 /* acr is in units of 0.25 mAh */
244 acr_val = di->full_active_uAh * 4L / 1000;
245
246 acr[0] = acr_val >> 8;
247 acr[1] = acr_val & 0xff;
248
249 if (w1_ds2760_write(di->w1_dev, acr,
250 DS2760_CURRENT_ACCUM_MSB, 2) < 2)
251 dev_warn(di->dev,
252 "ACR reset failed\n");
253
254 di->charge_status = POWER_SUPPLY_STATUS_FULL; 270 di->charge_status = POWER_SUPPLY_STATUS_FULL;
271 ds2760_battery_set_current_accum(di,
272 di->full_active_uAh);
255 } 273 }
256 } 274 }
257 } else { 275 } else {
@@ -274,6 +292,17 @@ static void ds2760_battery_write_status(struct ds2760_device_info *di,
274 w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1); 292 w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
275} 293}
276 294
295static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
296 unsigned char rated_capacity)
297{
298 if (rated_capacity == di->raw[DS2760_RATED_CAPACITY])
299 return;
300
301 w1_ds2760_write(di->w1_dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
302 w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
303 w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
304}
305
277static void ds2760_battery_work(struct work_struct *work) 306static void ds2760_battery_work(struct work_struct *work)
278{ 307{
279 struct ds2760_device_info *di = container_of(work, 308 struct ds2760_device_info *di = container_of(work,
@@ -299,6 +328,52 @@ static void ds2760_battery_external_power_changed(struct power_supply *psy)
299 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10); 328 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10);
300} 329}
301 330
331
332static void ds2760_battery_set_charged_work(struct work_struct *work)
333{
334 char bias;
335 struct ds2760_device_info *di = container_of(work,
336 struct ds2760_device_info, set_charged_work.work);
337
338 dev_dbg(di->dev, "%s\n", __func__);
339
340 ds2760_battery_read_status(di);
341
342 /* When we get notified by external circuitry that the battery is
343 * considered fully charged now, we know that there is no current
344 * flow any more. However, the ds2760's internal current meter is
345 * too inaccurate to rely on - spec say something ~15% failure.
346 * Hence, we use the current offset bias register to compensate
347 * that error.
348 */
349
350 if (!power_supply_am_i_supplied(&di->bat))
351 return;
352
353 bias = (signed char) di->current_raw +
354 (signed char) di->raw[DS2760_CURRENT_OFFSET_BIAS];
355
356 dev_dbg(di->dev, "%s: bias = %d\n", __func__, bias);
357
358 w1_ds2760_write(di->w1_dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1);
359 w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
360 w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
361
362 /* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS
363 * value won't be read back by ds2760_battery_read_status() */
364 di->raw[DS2760_CURRENT_OFFSET_BIAS] = bias;
365}
366
367static void ds2760_battery_set_charged(struct power_supply *psy)
368{
369 struct ds2760_device_info *di = to_ds2760_device_info(psy);
370
371 /* postpone the actual work by 20 secs. This is for debouncing GPIO
372 * signals and to let the current value settle. See AN4188. */
373 cancel_delayed_work(&di->set_charged_work);
374 queue_delayed_work(di->monitor_wqueue, &di->set_charged_work, HZ * 20);
375}
376
302static int ds2760_battery_get_property(struct power_supply *psy, 377static int ds2760_battery_get_property(struct power_supply *psy,
303 enum power_supply_property psp, 378 enum power_supply_property psp,
304 union power_supply_propval *val) 379 union power_supply_propval *val)
@@ -337,6 +412,12 @@ static int ds2760_battery_get_property(struct power_supply *psy,
337 case POWER_SUPPLY_PROP_TEMP: 412 case POWER_SUPPLY_PROP_TEMP:
338 val->intval = di->temp_C; 413 val->intval = di->temp_C;
339 break; 414 break;
415 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
416 val->intval = di->life_sec;
417 break;
418 case POWER_SUPPLY_PROP_CAPACITY:
419 val->intval = di->rem_capacity;
420 break;
340 default: 421 default:
341 return -EINVAL; 422 return -EINVAL;
342 } 423 }
@@ -353,6 +434,8 @@ static enum power_supply_property ds2760_battery_props[] = {
353 POWER_SUPPLY_PROP_CHARGE_EMPTY, 434 POWER_SUPPLY_PROP_CHARGE_EMPTY,
354 POWER_SUPPLY_PROP_CHARGE_NOW, 435 POWER_SUPPLY_PROP_CHARGE_NOW,
355 POWER_SUPPLY_PROP_TEMP, 436 POWER_SUPPLY_PROP_TEMP,
437 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
438 POWER_SUPPLY_PROP_CAPACITY,
356}; 439};
357 440
358static int ds2760_battery_probe(struct platform_device *pdev) 441static int ds2760_battery_probe(struct platform_device *pdev)
@@ -376,17 +459,12 @@ static int ds2760_battery_probe(struct platform_device *pdev)
376 di->bat.properties = ds2760_battery_props; 459 di->bat.properties = ds2760_battery_props;
377 di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); 460 di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props);
378 di->bat.get_property = ds2760_battery_get_property; 461 di->bat.get_property = ds2760_battery_get_property;
462 di->bat.set_charged = ds2760_battery_set_charged;
379 di->bat.external_power_changed = 463 di->bat.external_power_changed =
380 ds2760_battery_external_power_changed; 464 ds2760_battery_external_power_changed;
381 465
382 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; 466 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
383 467
384 retval = power_supply_register(&pdev->dev, &di->bat);
385 if (retval) {
386 dev_err(di->dev, "failed to register battery\n");
387 goto batt_failed;
388 }
389
390 /* enable sleep mode feature */ 468 /* enable sleep mode feature */
391 ds2760_battery_read_status(di); 469 ds2760_battery_read_status(di);
392 status = di->raw[DS2760_STATUS_REG]; 470 status = di->raw[DS2760_STATUS_REG];
@@ -397,7 +475,24 @@ static int ds2760_battery_probe(struct platform_device *pdev)
397 475
398 ds2760_battery_write_status(di, status); 476 ds2760_battery_write_status(di, status);
399 477
478 /* set rated capacity from module param */
479 if (rated_capacity)
480 ds2760_battery_write_rated_capacity(di, rated_capacity);
481
482 /* set current accumulator if given as parameter.
483 * this should only be done for bootstrapping the value */
484 if (current_accum)
485 ds2760_battery_set_current_accum(di, current_accum);
486
487 retval = power_supply_register(&pdev->dev, &di->bat);
488 if (retval) {
489 dev_err(di->dev, "failed to register battery\n");
490 goto batt_failed;
491 }
492
400 INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work); 493 INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work);
494 INIT_DELAYED_WORK(&di->set_charged_work,
495 ds2760_battery_set_charged_work);
401 di->monitor_wqueue = create_singlethread_workqueue(dev_name(&pdev->dev)); 496 di->monitor_wqueue = create_singlethread_workqueue(dev_name(&pdev->dev));
402 if (!di->monitor_wqueue) { 497 if (!di->monitor_wqueue) {
403 retval = -ESRCH; 498 retval = -ESRCH;
@@ -422,6 +517,8 @@ static int ds2760_battery_remove(struct platform_device *pdev)
422 517
423 cancel_rearming_delayed_workqueue(di->monitor_wqueue, 518 cancel_rearming_delayed_workqueue(di->monitor_wqueue,
424 &di->monitor_work); 519 &di->monitor_work);
520 cancel_rearming_delayed_workqueue(di->monitor_wqueue,
521 &di->set_charged_work);
425 destroy_workqueue(di->monitor_wqueue); 522 destroy_workqueue(di->monitor_wqueue);
426 power_supply_unregister(&di->bat); 523 power_supply_unregister(&di->bat);
427 524
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 58e419299cd6..8fefe5a73558 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -10,7 +10,9 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/types.h>
13#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/device.h>
14#include <linux/platform_device.h> 16#include <linux/platform_device.h>
15#include <linux/power_supply.h> 17#include <linux/power_supply.h>
16#include <linux/jiffies.h> 18#include <linux/jiffies.h>
@@ -231,6 +233,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
231 if (ret) 233 if (ret)
232 return ret; 234 return ret;
233 break; 235 break;
236 case POWER_SUPPLY_PROP_CHARGE_TYPE:
237 if (ec_byte & BAT_STAT_TRICKLE)
238 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
239 else if (ec_byte & BAT_STAT_CHARGING)
240 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
241 else
242 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
243 break;
234 case POWER_SUPPLY_PROP_PRESENT: 244 case POWER_SUPPLY_PROP_PRESENT:
235 val->intval = !!(ec_byte & (BAT_STAT_PRESENT | 245 val->intval = !!(ec_byte & (BAT_STAT_PRESENT |
236 BAT_STAT_TRICKLE)); 246 BAT_STAT_TRICKLE));
@@ -276,6 +286,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
276 return ret; 286 return ret;
277 val->intval = ec_byte; 287 val->intval = ec_byte;
278 break; 288 break;
289 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
290 if (ec_byte & BAT_STAT_FULL)
291 val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
292 else if (ec_byte & BAT_STAT_LOW)
293 val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
294 else
295 val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
296 break;
279 case POWER_SUPPLY_PROP_TEMP: 297 case POWER_SUPPLY_PROP_TEMP:
280 ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2); 298 ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
281 if (ret) 299 if (ret)
@@ -315,12 +333,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
315 333
316static enum power_supply_property olpc_bat_props[] = { 334static enum power_supply_property olpc_bat_props[] = {
317 POWER_SUPPLY_PROP_STATUS, 335 POWER_SUPPLY_PROP_STATUS,
336 POWER_SUPPLY_PROP_CHARGE_TYPE,
318 POWER_SUPPLY_PROP_PRESENT, 337 POWER_SUPPLY_PROP_PRESENT,
319 POWER_SUPPLY_PROP_HEALTH, 338 POWER_SUPPLY_PROP_HEALTH,
320 POWER_SUPPLY_PROP_TECHNOLOGY, 339 POWER_SUPPLY_PROP_TECHNOLOGY,
321 POWER_SUPPLY_PROP_VOLTAGE_AVG, 340 POWER_SUPPLY_PROP_VOLTAGE_AVG,
322 POWER_SUPPLY_PROP_CURRENT_AVG, 341 POWER_SUPPLY_PROP_CURRENT_AVG,
323 POWER_SUPPLY_PROP_CAPACITY, 342 POWER_SUPPLY_PROP_CAPACITY,
343 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
324 POWER_SUPPLY_PROP_TEMP, 344 POWER_SUPPLY_PROP_TEMP,
325 POWER_SUPPLY_PROP_TEMP_AMBIENT, 345 POWER_SUPPLY_PROP_TEMP_AMBIENT,
326 POWER_SUPPLY_PROP_MANUFACTURER, 346 POWER_SUPPLY_PROP_MANUFACTURER,
@@ -370,6 +390,29 @@ static struct bin_attribute olpc_bat_eeprom = {
370 .read = olpc_bat_eeprom_read, 390 .read = olpc_bat_eeprom_read,
371}; 391};
372 392
393/* Allow userspace to see the specific error value pulled from the EC */
394
395static ssize_t olpc_bat_error_read(struct device *dev,
396 struct device_attribute *attr, char *buf)
397{
398 uint8_t ec_byte;
399 ssize_t ret;
400
401 ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
402 if (ret < 0)
403 return ret;
404
405 return sprintf(buf, "%d\n", ec_byte);
406}
407
408static struct device_attribute olpc_bat_error = {
409 .attr = {
410 .name = "error",
411 .mode = S_IRUGO,
412 },
413 .show = olpc_bat_error_read,
414};
415
373/********************************************************************* 416/*********************************************************************
374 * Initialisation 417 * Initialisation
375 *********************************************************************/ 418 *********************************************************************/
@@ -433,8 +476,14 @@ static int __init olpc_bat_init(void)
433 if (ret) 476 if (ret)
434 goto eeprom_failed; 477 goto eeprom_failed;
435 478
479 ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
480 if (ret)
481 goto error_failed;
482
436 goto success; 483 goto success;
437 484
485error_failed:
486 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
438eeprom_failed: 487eeprom_failed:
439 power_supply_unregister(&olpc_bat); 488 power_supply_unregister(&olpc_bat);
440battery_failed: 489battery_failed:
@@ -447,6 +496,7 @@ success:
447 496
448static void __exit olpc_bat_exit(void) 497static void __exit olpc_bat_exit(void)
449{ 498{
499 device_remove_file(olpc_bat.dev, &olpc_bat_error);
450 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom); 500 device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
451 power_supply_unregister(&olpc_bat); 501 power_supply_unregister(&olpc_bat);
452 power_supply_unregister(&olpc_ac); 502 power_supply_unregister(&olpc_ac);
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 5520040449c4..cce75b40b435 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -18,7 +18,9 @@
18#include <linux/power_supply.h> 18#include <linux/power_supply.h>
19#include "power_supply.h" 19#include "power_supply.h"
20 20
21/* exported for the APM Power driver, APM emulation */
21struct class *power_supply_class; 22struct class *power_supply_class;
23EXPORT_SYMBOL_GPL(power_supply_class);
22 24
23static int __power_supply_changed_work(struct device *dev, void *data) 25static int __power_supply_changed_work(struct device *dev, void *data)
24{ 26{
@@ -55,6 +57,7 @@ void power_supply_changed(struct power_supply *psy)
55 57
56 schedule_work(&psy->changed_work); 58 schedule_work(&psy->changed_work);
57} 59}
60EXPORT_SYMBOL_GPL(power_supply_changed);
58 61
59static int __power_supply_am_i_supplied(struct device *dev, void *data) 62static int __power_supply_am_i_supplied(struct device *dev, void *data)
60{ 63{
@@ -86,6 +89,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
86 89
87 return error; 90 return error;
88} 91}
92EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
89 93
90static int __power_supply_is_system_supplied(struct device *dev, void *data) 94static int __power_supply_is_system_supplied(struct device *dev, void *data)
91{ 95{
@@ -110,6 +114,35 @@ int power_supply_is_system_supplied(void)
110 114
111 return error; 115 return error;
112} 116}
117EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
118
119int power_supply_set_battery_charged(struct power_supply *psy)
120{
121 if (psy->type == POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) {
122 psy->set_charged(psy);
123 return 0;
124 }
125
126 return -EINVAL;
127}
128EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
129
130static int power_supply_match_device_by_name(struct device *dev, void *data)
131{
132 const char *name = data;
133 struct power_supply *psy = dev_get_drvdata(dev);
134
135 return strcmp(psy->name, name) == 0;
136}
137
138struct power_supply *power_supply_get_by_name(char *name)
139{
140 struct device *dev = class_find_device(power_supply_class, NULL, name,
141 power_supply_match_device_by_name);
142
143 return dev ? dev_get_drvdata(dev) : NULL;
144}
145EXPORT_SYMBOL_GPL(power_supply_get_by_name);
113 146
114int power_supply_register(struct device *parent, struct power_supply *psy) 147int power_supply_register(struct device *parent, struct power_supply *psy)
115{ 148{
@@ -144,6 +177,7 @@ dev_create_failed:
144success: 177success:
145 return rc; 178 return rc;
146} 179}
180EXPORT_SYMBOL_GPL(power_supply_register);
147 181
148void power_supply_unregister(struct power_supply *psy) 182void power_supply_unregister(struct power_supply *psy)
149{ 183{
@@ -152,6 +186,7 @@ void power_supply_unregister(struct power_supply *psy)
152 power_supply_remove_attrs(psy); 186 power_supply_remove_attrs(psy);
153 device_unregister(psy->dev); 187 device_unregister(psy->dev);
154} 188}
189EXPORT_SYMBOL_GPL(power_supply_unregister);
155 190
156static int __init power_supply_class_init(void) 191static int __init power_supply_class_init(void)
157{ 192{
@@ -170,15 +205,6 @@ static void __exit power_supply_class_exit(void)
170 class_destroy(power_supply_class); 205 class_destroy(power_supply_class);
171} 206}
172 207
173EXPORT_SYMBOL_GPL(power_supply_changed);
174EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
175EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
176EXPORT_SYMBOL_GPL(power_supply_register);
177EXPORT_SYMBOL_GPL(power_supply_unregister);
178
179/* exported for the APM Power driver, APM emulation */
180EXPORT_SYMBOL_GPL(power_supply_class);
181
182subsys_initcall(power_supply_class_init); 208subsys_initcall(power_supply_class_init);
183module_exit(power_supply_class_exit); 209module_exit(power_supply_class_exit);
184 210
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index da73591017f9..08144393d64b 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -43,6 +43,9 @@ static ssize_t power_supply_show_property(struct device *dev,
43 static char *status_text[] = { 43 static char *status_text[] = {
44 "Unknown", "Charging", "Discharging", "Not charging", "Full" 44 "Unknown", "Charging", "Discharging", "Not charging", "Full"
45 }; 45 };
46 static char *charge_type[] = {
47 "Unknown", "N/A", "Trickle", "Fast"
48 };
46 static char *health_text[] = { 49 static char *health_text[] = {
47 "Unknown", "Good", "Overheat", "Dead", "Over voltage", 50 "Unknown", "Good", "Overheat", "Dead", "Over voltage",
48 "Unspecified failure", "Cold", 51 "Unspecified failure", "Cold",
@@ -51,6 +54,9 @@ static ssize_t power_supply_show_property(struct device *dev,
51 "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", 54 "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd",
52 "LiMn" 55 "LiMn"
53 }; 56 };
57 static char *capacity_level_text[] = {
58 "Unknown", "Critical", "Low", "Normal", "High", "Full"
59 };
54 ssize_t ret; 60 ssize_t ret;
55 struct power_supply *psy = dev_get_drvdata(dev); 61 struct power_supply *psy = dev_get_drvdata(dev);
56 const ptrdiff_t off = attr - power_supply_attrs; 62 const ptrdiff_t off = attr - power_supply_attrs;
@@ -67,10 +73,14 @@ static ssize_t power_supply_show_property(struct device *dev,
67 73
68 if (off == POWER_SUPPLY_PROP_STATUS) 74 if (off == POWER_SUPPLY_PROP_STATUS)
69 return sprintf(buf, "%s\n", status_text[value.intval]); 75 return sprintf(buf, "%s\n", status_text[value.intval]);
76 else if (off == POWER_SUPPLY_PROP_CHARGE_TYPE)
77 return sprintf(buf, "%s\n", charge_type[value.intval]);
70 else if (off == POWER_SUPPLY_PROP_HEALTH) 78 else if (off == POWER_SUPPLY_PROP_HEALTH)
71 return sprintf(buf, "%s\n", health_text[value.intval]); 79 return sprintf(buf, "%s\n", health_text[value.intval]);
72 else if (off == POWER_SUPPLY_PROP_TECHNOLOGY) 80 else if (off == POWER_SUPPLY_PROP_TECHNOLOGY)
73 return sprintf(buf, "%s\n", technology_text[value.intval]); 81 return sprintf(buf, "%s\n", technology_text[value.intval]);
82 else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL)
83 return sprintf(buf, "%s\n", capacity_level_text[value.intval]);
74 else if (off >= POWER_SUPPLY_PROP_MODEL_NAME) 84 else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
75 return sprintf(buf, "%s\n", value.strval); 85 return sprintf(buf, "%s\n", value.strval);
76 86
@@ -81,6 +91,7 @@ static ssize_t power_supply_show_property(struct device *dev,
81static struct device_attribute power_supply_attrs[] = { 91static struct device_attribute power_supply_attrs[] = {
82 /* Properties of type `int' */ 92 /* Properties of type `int' */
83 POWER_SUPPLY_ATTR(status), 93 POWER_SUPPLY_ATTR(status),
94 POWER_SUPPLY_ATTR(charge_type),
84 POWER_SUPPLY_ATTR(health), 95 POWER_SUPPLY_ATTR(health),
85 POWER_SUPPLY_ATTR(present), 96 POWER_SUPPLY_ATTR(present),
86 POWER_SUPPLY_ATTR(online), 97 POWER_SUPPLY_ATTR(online),
@@ -109,6 +120,7 @@ static struct device_attribute power_supply_attrs[] = {
109 POWER_SUPPLY_ATTR(energy_now), 120 POWER_SUPPLY_ATTR(energy_now),
110 POWER_SUPPLY_ATTR(energy_avg), 121 POWER_SUPPLY_ATTR(energy_avg),
111 POWER_SUPPLY_ATTR(capacity), 122 POWER_SUPPLY_ATTR(capacity),
123 POWER_SUPPLY_ATTR(capacity_level),
112 POWER_SUPPLY_ATTR(temp), 124 POWER_SUPPLY_ATTR(temp),
113 POWER_SUPPLY_ATTR(temp_ambient), 125 POWER_SUPPLY_ATTR(temp_ambient),
114 POWER_SUPPLY_ATTR(time_to_empty_now), 126 POWER_SUPPLY_ATTR(time_to_empty_now),
diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c
new file mode 100644
index 000000000000..2a4c8b0b829c
--- /dev/null
+++ b/drivers/power/wm831x_power.c
@@ -0,0 +1,779 @@
1/*
2 * PMU driver for Wolfson Microelectronics wm831x PMICs
3 *
4 * Copyright 2009 Wolfson Microelectronics PLC.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/err.h>
13#include <linux/platform_device.h>
14#include <linux/power_supply.h>
15
16#include <linux/mfd/wm831x/core.h>
17#include <linux/mfd/wm831x/auxadc.h>
18#include <linux/mfd/wm831x/pmu.h>
19#include <linux/mfd/wm831x/pdata.h>
20
21struct wm831x_power {
22 struct wm831x *wm831x;
23 struct power_supply wall;
24 struct power_supply backup;
25 struct power_supply usb;
26 struct power_supply battery;
27};
28
29static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
30 union power_supply_propval *val)
31{
32 int ret;
33
34 ret = wm831x_reg_read(wm831x, WM831X_SYSTEM_STATUS);
35 if (ret < 0)
36 return ret;
37
38 if (ret & supply)
39 val->intval = 1;
40 else
41 val->intval = 0;
42
43 return 0;
44}
45
46static int wm831x_power_read_voltage(struct wm831x *wm831x,
47 enum wm831x_auxadc src,
48 union power_supply_propval *val)
49{
50 int ret;
51
52 ret = wm831x_auxadc_read_uv(wm831x, src);
53 if (ret >= 0)
54 val->intval = ret;
55
56 return ret;
57}
58
59/*********************************************************************
60 * WALL Power
61 *********************************************************************/
62static int wm831x_wall_get_prop(struct power_supply *psy,
63 enum power_supply_property psp,
64 union power_supply_propval *val)
65{
66 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent);
67 struct wm831x *wm831x = wm831x_power->wm831x;
68 int ret = 0;
69
70 switch (psp) {
71 case POWER_SUPPLY_PROP_ONLINE:
72 ret = wm831x_power_check_online(wm831x, WM831X_PWR_WALL, val);
73 break;
74 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
75 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_WALL, val);
76 break;
77 default:
78 ret = -EINVAL;
79 break;
80 }
81
82 return ret;
83}
84
85static enum power_supply_property wm831x_wall_props[] = {
86 POWER_SUPPLY_PROP_ONLINE,
87 POWER_SUPPLY_PROP_VOLTAGE_NOW,
88};
89
90/*********************************************************************
91 * USB Power
92 *********************************************************************/
93static int wm831x_usb_get_prop(struct power_supply *psy,
94 enum power_supply_property psp,
95 union power_supply_propval *val)
96{
97 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent);
98 struct wm831x *wm831x = wm831x_power->wm831x;
99 int ret = 0;
100
101 switch (psp) {
102 case POWER_SUPPLY_PROP_ONLINE:
103 ret = wm831x_power_check_online(wm831x, WM831X_PWR_USB, val);
104 break;
105 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
106 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_USB, val);
107 break;
108 default:
109 ret = -EINVAL;
110 break;
111 }
112
113 return ret;
114}
115
116static enum power_supply_property wm831x_usb_props[] = {
117 POWER_SUPPLY_PROP_ONLINE,
118 POWER_SUPPLY_PROP_VOLTAGE_NOW,
119};
120
121/*********************************************************************
122 * Battery properties
123 *********************************************************************/
124
125struct chg_map {
126 int val;
127 int reg_val;
128};
129
130static struct chg_map trickle_ilims[] = {
131 { 50, 0 << WM831X_CHG_TRKL_ILIM_SHIFT },
132 { 100, 1 << WM831X_CHG_TRKL_ILIM_SHIFT },
133 { 150, 2 << WM831X_CHG_TRKL_ILIM_SHIFT },
134 { 200, 3 << WM831X_CHG_TRKL_ILIM_SHIFT },
135};
136
137static struct chg_map vsels[] = {
138 { 4050, 0 << WM831X_CHG_VSEL_SHIFT },
139 { 4100, 1 << WM831X_CHG_VSEL_SHIFT },
140 { 4150, 2 << WM831X_CHG_VSEL_SHIFT },
141 { 4200, 3 << WM831X_CHG_VSEL_SHIFT },
142};
143
144static struct chg_map fast_ilims[] = {
145 { 0, 0 << WM831X_CHG_FAST_ILIM_SHIFT },
146 { 50, 1 << WM831X_CHG_FAST_ILIM_SHIFT },
147 { 100, 2 << WM831X_CHG_FAST_ILIM_SHIFT },
148 { 150, 3 << WM831X_CHG_FAST_ILIM_SHIFT },
149 { 200, 4 << WM831X_CHG_FAST_ILIM_SHIFT },
150 { 250, 5 << WM831X_CHG_FAST_ILIM_SHIFT },
151 { 300, 6 << WM831X_CHG_FAST_ILIM_SHIFT },
152 { 350, 7 << WM831X_CHG_FAST_ILIM_SHIFT },
153 { 400, 8 << WM831X_CHG_FAST_ILIM_SHIFT },
154 { 450, 9 << WM831X_CHG_FAST_ILIM_SHIFT },
155 { 500, 10 << WM831X_CHG_FAST_ILIM_SHIFT },
156 { 600, 11 << WM831X_CHG_FAST_ILIM_SHIFT },
157 { 700, 12 << WM831X_CHG_FAST_ILIM_SHIFT },
158 { 800, 13 << WM831X_CHG_FAST_ILIM_SHIFT },
159 { 900, 14 << WM831X_CHG_FAST_ILIM_SHIFT },
160 { 1000, 15 << WM831X_CHG_FAST_ILIM_SHIFT },
161};
162
163static struct chg_map eoc_iterms[] = {
164 { 20, 0 << WM831X_CHG_ITERM_SHIFT },
165 { 30, 1 << WM831X_CHG_ITERM_SHIFT },
166 { 40, 2 << WM831X_CHG_ITERM_SHIFT },
167 { 50, 3 << WM831X_CHG_ITERM_SHIFT },
168 { 60, 4 << WM831X_CHG_ITERM_SHIFT },
169 { 70, 5 << WM831X_CHG_ITERM_SHIFT },
170 { 80, 6 << WM831X_CHG_ITERM_SHIFT },
171 { 90, 7 << WM831X_CHG_ITERM_SHIFT },
172};
173
174static struct chg_map chg_times[] = {
175 { 60, 0 << WM831X_CHG_TIME_SHIFT },
176 { 90, 1 << WM831X_CHG_TIME_SHIFT },
177 { 120, 2 << WM831X_CHG_TIME_SHIFT },
178 { 150, 3 << WM831X_CHG_TIME_SHIFT },
179 { 180, 4 << WM831X_CHG_TIME_SHIFT },
180 { 210, 5 << WM831X_CHG_TIME_SHIFT },
181 { 240, 6 << WM831X_CHG_TIME_SHIFT },
182 { 270, 7 << WM831X_CHG_TIME_SHIFT },
183 { 300, 8 << WM831X_CHG_TIME_SHIFT },
184 { 330, 9 << WM831X_CHG_TIME_SHIFT },
185 { 360, 10 << WM831X_CHG_TIME_SHIFT },
186 { 390, 11 << WM831X_CHG_TIME_SHIFT },
187 { 420, 12 << WM831X_CHG_TIME_SHIFT },
188 { 450, 13 << WM831X_CHG_TIME_SHIFT },
189 { 480, 14 << WM831X_CHG_TIME_SHIFT },
190 { 510, 15 << WM831X_CHG_TIME_SHIFT },
191};
192
193static void wm831x_battey_apply_config(struct wm831x *wm831x,
194 struct chg_map *map, int count, int val,
195 int *reg, const char *name,
196 const char *units)
197{
198 int i;
199
200 for (i = 0; i < count; i++)
201 if (val == map[i].val)
202 break;
203 if (i == count) {
204 dev_err(wm831x->dev, "Invalid %s %d%s\n",
205 name, val, units);
206 } else {
207 *reg |= map[i].reg_val;
208 dev_dbg(wm831x->dev, "Set %s of %d%s\n", name, val, units);
209 }
210}
211
212static void wm831x_config_battery(struct wm831x *wm831x)
213{
214 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
215 struct wm831x_battery_pdata *pdata;
216 int ret, reg1, reg2;
217
218 if (!wm831x_pdata || !wm831x_pdata->battery) {
219 dev_warn(wm831x->dev,
220 "No battery charger configuration\n");
221 return;
222 }
223
224 pdata = wm831x_pdata->battery;
225
226 reg1 = 0;
227 reg2 = 0;
228
229 if (!pdata->enable) {
230 dev_info(wm831x->dev, "Battery charger disabled\n");
231 return;
232 }
233
234 reg1 |= WM831X_CHG_ENA;
235 if (pdata->off_mask)
236 reg2 |= WM831X_CHG_OFF_MSK;
237 if (pdata->fast_enable)
238 reg1 |= WM831X_CHG_FAST;
239
240 wm831x_battey_apply_config(wm831x, trickle_ilims,
241 ARRAY_SIZE(trickle_ilims),
242 pdata->trickle_ilim, &reg2,
243 "trickle charge current limit", "mA");
244
245 wm831x_battey_apply_config(wm831x, vsels, ARRAY_SIZE(vsels),
246 pdata->vsel, &reg2,
247 "target voltage", "mV");
248
249 wm831x_battey_apply_config(wm831x, fast_ilims, ARRAY_SIZE(fast_ilims),
250 pdata->fast_ilim, &reg2,
251 "fast charge current limit", "mA");
252
253 wm831x_battey_apply_config(wm831x, eoc_iterms, ARRAY_SIZE(eoc_iterms),
254 pdata->eoc_iterm, &reg1,
255 "end of charge current threshold", "mA");
256
257 wm831x_battey_apply_config(wm831x, chg_times, ARRAY_SIZE(chg_times),
258 pdata->timeout, &reg2,
259 "charger timeout", "min");
260
261 ret = wm831x_reg_unlock(wm831x);
262 if (ret != 0) {
263 dev_err(wm831x->dev, "Failed to unlock registers: %d\n", ret);
264 return;
265 }
266
267 ret = wm831x_set_bits(wm831x, WM831X_CHARGER_CONTROL_1,
268 WM831X_CHG_ENA_MASK |
269 WM831X_CHG_FAST_MASK |
270 WM831X_CHG_ITERM_MASK |
271 WM831X_CHG_ITERM_MASK,
272 reg1);
273 if (ret != 0)
274 dev_err(wm831x->dev, "Failed to set charger control 1: %d\n",
275 ret);
276
277 ret = wm831x_set_bits(wm831x, WM831X_CHARGER_CONTROL_2,
278 WM831X_CHG_OFF_MSK |
279 WM831X_CHG_TIME_MASK |
280 WM831X_CHG_FAST_ILIM_MASK |
281 WM831X_CHG_TRKL_ILIM_MASK |
282 WM831X_CHG_VSEL_MASK,
283 reg2);
284 if (ret != 0)
285 dev_err(wm831x->dev, "Failed to set charger control 2: %d\n",
286 ret);
287
288 wm831x_reg_lock(wm831x);
289}
290
291static int wm831x_bat_check_status(struct wm831x *wm831x, int *status)
292{
293 int ret;
294
295 ret = wm831x_reg_read(wm831x, WM831X_SYSTEM_STATUS);
296 if (ret < 0)
297 return ret;
298
299 if (ret & WM831X_PWR_SRC_BATT) {
300 *status = POWER_SUPPLY_STATUS_DISCHARGING;
301 return 0;
302 }
303
304 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_STATUS);
305 if (ret < 0)
306 return ret;
307
308 switch (ret & WM831X_CHG_STATE_MASK) {
309 case WM831X_CHG_STATE_OFF:
310 *status = POWER_SUPPLY_STATUS_NOT_CHARGING;
311 break;
312 case WM831X_CHG_STATE_TRICKLE:
313 case WM831X_CHG_STATE_FAST:
314 *status = POWER_SUPPLY_STATUS_CHARGING;
315 break;
316
317 default:
318 *status = POWER_SUPPLY_STATUS_UNKNOWN;
319 break;
320 }
321
322 return 0;
323}
324
325static int wm831x_bat_check_type(struct wm831x *wm831x, int *type)
326{
327 int ret;
328
329 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_STATUS);
330 if (ret < 0)
331 return ret;
332
333 switch (ret & WM831X_CHG_STATE_MASK) {
334 case WM831X_CHG_STATE_TRICKLE:
335 case WM831X_CHG_STATE_TRICKLE_OT:
336 *type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
337 break;
338 case WM831X_CHG_STATE_FAST:
339 case WM831X_CHG_STATE_FAST_OT:
340 *type = POWER_SUPPLY_CHARGE_TYPE_FAST;
341 break;
342 default:
343 *type = POWER_SUPPLY_CHARGE_TYPE_NONE;
344 break;
345 }
346
347 return 0;
348}
349
350static int wm831x_bat_check_health(struct wm831x *wm831x, int *health)
351{
352 int ret;
353
354 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_STATUS);
355 if (ret < 0)
356 return ret;
357
358 if (ret & WM831X_BATT_HOT_STS) {
359 *health = POWER_SUPPLY_HEALTH_OVERHEAT;
360 return 0;
361 }
362
363 if (ret & WM831X_BATT_COLD_STS) {
364 *health = POWER_SUPPLY_HEALTH_COLD;
365 return 0;
366 }
367
368 if (ret & WM831X_BATT_OV_STS) {
369 *health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
370 return 0;
371 }
372
373 switch (ret & WM831X_CHG_STATE_MASK) {
374 case WM831X_CHG_STATE_TRICKLE_OT:
375 case WM831X_CHG_STATE_FAST_OT:
376 *health = POWER_SUPPLY_HEALTH_OVERHEAT;
377 break;
378 case WM831X_CHG_STATE_DEFECTIVE:
379 *health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
380 break;
381 default:
382 *health = POWER_SUPPLY_HEALTH_GOOD;
383 break;
384 }
385
386 return 0;
387}
388
389static int wm831x_bat_get_prop(struct power_supply *psy,
390 enum power_supply_property psp,
391 union power_supply_propval *val)
392{
393 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent);
394 struct wm831x *wm831x = wm831x_power->wm831x;
395 int ret = 0;
396
397 switch (psp) {
398 case POWER_SUPPLY_PROP_STATUS:
399 ret = wm831x_bat_check_status(wm831x, &val->intval);
400 break;
401 case POWER_SUPPLY_PROP_ONLINE:
402 ret = wm831x_power_check_online(wm831x, WM831X_PWR_SRC_BATT,
403 val);
404 break;
405 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
406 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_BATT, val);
407 break;
408 case POWER_SUPPLY_PROP_HEALTH:
409 ret = wm831x_bat_check_health(wm831x, &val->intval);
410 break;
411 case POWER_SUPPLY_PROP_CHARGE_TYPE:
412 ret = wm831x_bat_check_type(wm831x, &val->intval);
413 break;
414 default:
415 ret = -EINVAL;
416 break;
417 }
418
419 return ret;
420}
421
422static enum power_supply_property wm831x_bat_props[] = {
423 POWER_SUPPLY_PROP_STATUS,
424 POWER_SUPPLY_PROP_ONLINE,
425 POWER_SUPPLY_PROP_VOLTAGE_NOW,
426 POWER_SUPPLY_PROP_HEALTH,
427 POWER_SUPPLY_PROP_CHARGE_TYPE,
428};
429
430static const char *wm831x_bat_irqs[] = {
431 "BATT HOT",
432 "BATT COLD",
433 "BATT FAIL",
434 "OV",
435 "END",
436 "TO",
437 "MODE",
438 "START",
439};
440
441static irqreturn_t wm831x_bat_irq(int irq, void *data)
442{
443 struct wm831x_power *wm831x_power = data;
444 struct wm831x *wm831x = wm831x_power->wm831x;
445
446 dev_dbg(wm831x->dev, "Battery status changed: %d\n", irq);
447
448 /* The battery charger is autonomous so we don't need to do
449 * anything except kick user space */
450 power_supply_changed(&wm831x_power->battery);
451
452 return IRQ_HANDLED;
453}
454
455
456/*********************************************************************
457 * Backup supply properties
458 *********************************************************************/
459
460static void wm831x_config_backup(struct wm831x *wm831x)
461{
462 struct wm831x_pdata *wm831x_pdata = wm831x->dev->platform_data;
463 struct wm831x_backup_pdata *pdata;
464 int ret, reg;
465
466 if (!wm831x_pdata || !wm831x_pdata->backup) {
467 dev_warn(wm831x->dev,
468 "No backup battery charger configuration\n");
469 return;
470 }
471
472 pdata = wm831x_pdata->backup;
473
474 reg = 0;
475
476 if (pdata->charger_enable)
477 reg |= WM831X_BKUP_CHG_ENA | WM831X_BKUP_BATT_DET_ENA;
478 if (pdata->no_constant_voltage)
479 reg |= WM831X_BKUP_CHG_MODE;
480
481 switch (pdata->vlim) {
482 case 2500:
483 break;
484 case 3100:
485 reg |= WM831X_BKUP_CHG_VLIM;
486 break;
487 default:
488 dev_err(wm831x->dev, "Invalid backup voltage limit %dmV\n",
489 pdata->vlim);
490 }
491
492 switch (pdata->ilim) {
493 case 100:
494 break;
495 case 200:
496 reg |= 1;
497 break;
498 case 300:
499 reg |= 2;
500 break;
501 case 400:
502 reg |= 3;
503 break;
504 default:
505 dev_err(wm831x->dev, "Invalid backup current limit %duA\n",
506 pdata->ilim);
507 }
508
509 ret = wm831x_reg_unlock(wm831x);
510 if (ret != 0) {
511 dev_err(wm831x->dev, "Failed to unlock registers: %d\n", ret);
512 return;
513 }
514
515 ret = wm831x_set_bits(wm831x, WM831X_BACKUP_CHARGER_CONTROL,
516 WM831X_BKUP_CHG_ENA_MASK |
517 WM831X_BKUP_CHG_MODE_MASK |
518 WM831X_BKUP_BATT_DET_ENA_MASK |
519 WM831X_BKUP_CHG_VLIM_MASK |
520 WM831X_BKUP_CHG_ILIM_MASK,
521 reg);
522 if (ret != 0)
523 dev_err(wm831x->dev,
524 "Failed to set backup charger config: %d\n", ret);
525
526 wm831x_reg_lock(wm831x);
527}
528
529static int wm831x_backup_get_prop(struct power_supply *psy,
530 enum power_supply_property psp,
531 union power_supply_propval *val)
532{
533 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev->parent);
534 struct wm831x *wm831x = wm831x_power->wm831x;
535 int ret = 0;
536
537 ret = wm831x_reg_read(wm831x, WM831X_BACKUP_CHARGER_CONTROL);
538 if (ret < 0)
539 return ret;
540
541 switch (psp) {
542 case POWER_SUPPLY_PROP_STATUS:
543 if (ret & WM831X_BKUP_CHG_STS)
544 val->intval = POWER_SUPPLY_STATUS_CHARGING;
545 else
546 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
547 break;
548
549 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
550 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_BKUP_BATT,
551 val);
552 break;
553
554 case POWER_SUPPLY_PROP_PRESENT:
555 if (ret & WM831X_BKUP_CHG_STS)
556 val->intval = 1;
557 else
558 val->intval = 0;
559 break;
560
561 default:
562 ret = -EINVAL;
563 break;
564 }
565
566 return ret;
567}
568
569static enum power_supply_property wm831x_backup_props[] = {
570 POWER_SUPPLY_PROP_STATUS,
571 POWER_SUPPLY_PROP_VOLTAGE_NOW,
572 POWER_SUPPLY_PROP_PRESENT,
573};
574
575/*********************************************************************
576 * Initialisation
577 *********************************************************************/
578
579static irqreturn_t wm831x_syslo_irq(int irq, void *data)
580{
581 struct wm831x_power *wm831x_power = data;
582 struct wm831x *wm831x = wm831x_power->wm831x;
583
584 /* Not much we can actually *do* but tell people for
585 * posterity, we're probably about to run out of power. */
586 dev_crit(wm831x->dev, "SYSVDD under voltage\n");
587
588 return IRQ_HANDLED;
589}
590
591static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
592{
593 struct wm831x_power *wm831x_power = data;
594 struct wm831x *wm831x = wm831x_power->wm831x;
595
596 dev_dbg(wm831x->dev, "Power source changed\n");
597
598 /* Just notify for everything - little harm in overnotifying.
599 * The backup battery is not a power source while the system
600 * is running so skip that.
601 */
602 power_supply_changed(&wm831x_power->battery);
603 power_supply_changed(&wm831x_power->usb);
604 power_supply_changed(&wm831x_power->wall);
605
606 return IRQ_HANDLED;
607}
608
609static __devinit int wm831x_power_probe(struct platform_device *pdev)
610{
611 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
612 struct wm831x_power *power;
613 struct power_supply *usb;
614 struct power_supply *battery;
615 struct power_supply *wall;
616 struct power_supply *backup;
617 int ret, irq, i;
618
619 power = kzalloc(sizeof(struct wm831x_power), GFP_KERNEL);
620 if (power == NULL)
621 return -ENOMEM;
622
623 power->wm831x = wm831x;
624 platform_set_drvdata(pdev, power);
625
626 usb = &power->usb;
627 battery = &power->battery;
628 wall = &power->wall;
629 backup = &power->backup;
630
631 /* We ignore configuration failures since we can still read back
632 * the status without enabling either of the chargers.
633 */
634 wm831x_config_battery(wm831x);
635 wm831x_config_backup(wm831x);
636
637 wall->name = "wm831x-wall";
638 wall->type = POWER_SUPPLY_TYPE_MAINS;
639 wall->properties = wm831x_wall_props;
640 wall->num_properties = ARRAY_SIZE(wm831x_wall_props);
641 wall->get_property = wm831x_wall_get_prop;
642 ret = power_supply_register(&pdev->dev, wall);
643 if (ret)
644 goto err_kmalloc;
645
646 battery->name = "wm831x-battery";
647 battery->properties = wm831x_bat_props;
648 battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
649 battery->get_property = wm831x_bat_get_prop;
650 battery->use_for_apm = 1;
651 ret = power_supply_register(&pdev->dev, battery);
652 if (ret)
653 goto err_wall;
654
655 usb->name = "wm831x-usb",
656 usb->type = POWER_SUPPLY_TYPE_USB;
657 usb->properties = wm831x_usb_props;
658 usb->num_properties = ARRAY_SIZE(wm831x_usb_props);
659 usb->get_property = wm831x_usb_get_prop;
660 ret = power_supply_register(&pdev->dev, usb);
661 if (ret)
662 goto err_battery;
663
664 backup->name = "wm831x-backup";
665 backup->type = POWER_SUPPLY_TYPE_BATTERY;
666 backup->properties = wm831x_backup_props;
667 backup->num_properties = ARRAY_SIZE(wm831x_backup_props);
668 backup->get_property = wm831x_backup_get_prop;
669 ret = power_supply_register(&pdev->dev, backup);
670 if (ret)
671 goto err_usb;
672
673 irq = platform_get_irq_byname(pdev, "SYSLO");
674 ret = wm831x_request_irq(wm831x, irq, wm831x_syslo_irq,
675 IRQF_TRIGGER_RISING, "SYSLO",
676 power);
677 if (ret != 0) {
678 dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n",
679 irq, ret);
680 goto err_backup;
681 }
682
683 irq = platform_get_irq_byname(pdev, "PWR SRC");
684 ret = wm831x_request_irq(wm831x, irq, wm831x_pwr_src_irq,
685 IRQF_TRIGGER_RISING, "Power source",
686 power);
687 if (ret != 0) {
688 dev_err(&pdev->dev, "Failed to request PWR SRC IRQ %d: %d\n",
689 irq, ret);
690 goto err_syslo;
691 }
692
693 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
694 irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
695 ret = wm831x_request_irq(wm831x, irq, wm831x_bat_irq,
696 IRQF_TRIGGER_RISING,
697 wm831x_bat_irqs[i],
698 power);
699 if (ret != 0) {
700 dev_err(&pdev->dev,
701 "Failed to request %s IRQ %d: %d\n",
702 wm831x_bat_irqs[i], irq, ret);
703 goto err_bat_irq;
704 }
705 }
706
707 return ret;
708
709err_bat_irq:
710 for (; i >= 0; i--) {
711 irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
712 wm831x_free_irq(wm831x, irq, power);
713 }
714 irq = platform_get_irq_byname(pdev, "PWR SRC");
715 wm831x_free_irq(wm831x, irq, power);
716err_syslo:
717 irq = platform_get_irq_byname(pdev, "SYSLO");
718 wm831x_free_irq(wm831x, irq, power);
719err_backup:
720 power_supply_unregister(backup);
721err_usb:
722 power_supply_unregister(usb);
723err_battery:
724 power_supply_unregister(battery);
725err_wall:
726 power_supply_unregister(wall);
727err_kmalloc:
728 kfree(power);
729 return ret;
730}
731
732static __devexit int wm831x_power_remove(struct platform_device *pdev)
733{
734 struct wm831x_power *wm831x_power = platform_get_drvdata(pdev);
735 struct wm831x *wm831x = wm831x_power->wm831x;
736 int irq, i;
737
738 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
739 irq = platform_get_irq_byname(pdev, wm831x_bat_irqs[i]);
740 wm831x_free_irq(wm831x, irq, wm831x_power);
741 }
742
743 irq = platform_get_irq_byname(pdev, "PWR SRC");
744 wm831x_free_irq(wm831x, irq, wm831x_power);
745
746 irq = platform_get_irq_byname(pdev, "SYSLO");
747 wm831x_free_irq(wm831x, irq, wm831x_power);
748
749 power_supply_unregister(&wm831x_power->backup);
750 power_supply_unregister(&wm831x_power->battery);
751 power_supply_unregister(&wm831x_power->wall);
752 power_supply_unregister(&wm831x_power->usb);
753 return 0;
754}
755
756static struct platform_driver wm831x_power_driver = {
757 .probe = wm831x_power_probe,
758 .remove = __devexit_p(wm831x_power_remove),
759 .driver = {
760 .name = "wm831x-power",
761 },
762};
763
764static int __init wm831x_power_init(void)
765{
766 return platform_driver_register(&wm831x_power_driver);
767}
768module_init(wm831x_power_init);
769
770static void __exit wm831x_power_exit(void)
771{
772 platform_driver_unregister(&wm831x_power_driver);
773}
774module_exit(wm831x_power_exit);
775
776MODULE_DESCRIPTION("Power supply driver for WM831x PMICs");
777MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
778MODULE_LICENSE("GPL");
779MODULE_ALIAS("platform:wm831x-power");
diff --git a/drivers/power/wm8350_power.c b/drivers/power/wm8350_power.c
index 1b16bf343f2f..28b0299c0043 100644
--- a/drivers/power/wm8350_power.c
+++ b/drivers/power/wm8350_power.c
@@ -321,6 +321,24 @@ static int wm8350_bat_check_health(struct wm8350 *wm8350)
321 return POWER_SUPPLY_HEALTH_GOOD; 321 return POWER_SUPPLY_HEALTH_GOOD;
322} 322}
323 323
324static int wm8350_bat_get_charge_type(struct wm8350 *wm8350)
325{
326 int state;
327
328 state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2) &
329 WM8350_CHG_STS_MASK;
330 switch (state) {
331 case WM8350_CHG_STS_OFF:
332 return POWER_SUPPLY_CHARGE_TYPE_NONE;
333 case WM8350_CHG_STS_TRICKLE:
334 return POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
335 case WM8350_CHG_STS_FAST:
336 return POWER_SUPPLY_CHARGE_TYPE_FAST;
337 default:
338 return POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
339 }
340}
341
324static int wm8350_bat_get_property(struct power_supply *psy, 342static int wm8350_bat_get_property(struct power_supply *psy,
325 enum power_supply_property psp, 343 enum power_supply_property psp,
326 union power_supply_propval *val) 344 union power_supply_propval *val)
@@ -342,6 +360,9 @@ static int wm8350_bat_get_property(struct power_supply *psy,
342 case POWER_SUPPLY_PROP_HEALTH: 360 case POWER_SUPPLY_PROP_HEALTH:
343 val->intval = wm8350_bat_check_health(wm8350); 361 val->intval = wm8350_bat_check_health(wm8350);
344 break; 362 break;
363 case POWER_SUPPLY_PROP_CHARGE_TYPE:
364 val->intval = wm8350_bat_get_charge_type(wm8350);
365 break;
345 default: 366 default:
346 ret = -EINVAL; 367 ret = -EINVAL;
347 break; 368 break;
@@ -355,6 +376,7 @@ static enum power_supply_property wm8350_bat_props[] = {
355 POWER_SUPPLY_PROP_ONLINE, 376 POWER_SUPPLY_PROP_ONLINE,
356 POWER_SUPPLY_PROP_VOLTAGE_NOW, 377 POWER_SUPPLY_PROP_VOLTAGE_NOW,
357 POWER_SUPPLY_PROP_HEALTH, 378 POWER_SUPPLY_PROP_HEALTH,
379 POWER_SUPPLY_PROP_CHARGE_TYPE,
358}; 380};
359 381
360/********************************************************************* 382/*********************************************************************
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index b787335a8419..f2bfd296dbae 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -22,17 +22,20 @@
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/wm97xx_batt.h> 25#include <linux/irq.h>
26 26
27static DEFINE_MUTEX(bat_lock); 27static DEFINE_MUTEX(bat_lock);
28static struct work_struct bat_work; 28static struct work_struct bat_work;
29struct mutex work_lock; 29struct mutex work_lock;
30static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; 30static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
31static struct wm97xx_batt_info *pdata; 31static struct wm97xx_batt_info *gpdata;
32static enum power_supply_property *prop; 32static enum power_supply_property *prop;
33 33
34static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) 34static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
35{ 35{
36 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data;
37 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
38
36 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent), 39 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent),
37 pdata->batt_aux) * pdata->batt_mult / 40 pdata->batt_aux) * pdata->batt_mult /
38 pdata->batt_div; 41 pdata->batt_div;
@@ -40,6 +43,9 @@ static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
40 43
41static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) 44static unsigned long wm97xx_read_temp(struct power_supply *bat_ps)
42{ 45{
46 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data;
47 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
48
43 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent), 49 return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev->parent),
44 pdata->temp_aux) * pdata->temp_mult / 50 pdata->temp_aux) * pdata->temp_mult /
45 pdata->temp_div; 51 pdata->temp_div;
@@ -49,6 +55,9 @@ static int wm97xx_bat_get_property(struct power_supply *bat_ps,
49 enum power_supply_property psp, 55 enum power_supply_property psp,
50 union power_supply_propval *val) 56 union power_supply_propval *val)
51{ 57{
58 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data;
59 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
60
52 switch (psp) { 61 switch (psp) {
53 case POWER_SUPPLY_PROP_STATUS: 62 case POWER_SUPPLY_PROP_STATUS:
54 val->intval = bat_status; 63 val->intval = bat_status;
@@ -97,6 +106,8 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps)
97static void wm97xx_bat_update(struct power_supply *bat_ps) 106static void wm97xx_bat_update(struct power_supply *bat_ps)
98{ 107{
99 int old_status = bat_status; 108 int old_status = bat_status;
109 struct wm97xx_pdata *wmdata = bat_ps->dev->parent->platform_data;
110 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
100 111
101 mutex_lock(&work_lock); 112 mutex_lock(&work_lock);
102 113
@@ -127,21 +138,29 @@ static void wm97xx_bat_work(struct work_struct *work)
127 wm97xx_bat_update(&bat_ps); 138 wm97xx_bat_update(&bat_ps);
128} 139}
129 140
141static irqreturn_t wm97xx_chrg_irq(int irq, void *data)
142{
143 schedule_work(&bat_work);
144 return IRQ_HANDLED;
145}
146
130#ifdef CONFIG_PM 147#ifdef CONFIG_PM
131static int wm97xx_bat_suspend(struct platform_device *dev, pm_message_t state) 148static int wm97xx_bat_suspend(struct device *dev)
132{ 149{
133 flush_scheduled_work(); 150 flush_scheduled_work();
134 return 0; 151 return 0;
135} 152}
136 153
137static int wm97xx_bat_resume(struct platform_device *dev) 154static int wm97xx_bat_resume(struct device *dev)
138{ 155{
139 schedule_work(&bat_work); 156 schedule_work(&bat_work);
140 return 0; 157 return 0;
141} 158}
142#else 159
143#define wm97xx_bat_suspend NULL 160static struct dev_pm_ops wm97xx_bat_pm_ops = {
144#define wm97xx_bat_resume NULL 161 .suspend = wm97xx_bat_suspend,
162 .resume = wm97xx_bat_resume,
163};
145#endif 164#endif
146 165
147static int __devinit wm97xx_bat_probe(struct platform_device *dev) 166static int __devinit wm97xx_bat_probe(struct platform_device *dev)
@@ -149,6 +168,15 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
149 int ret = 0; 168 int ret = 0;
150 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */ 169 int props = 1; /* POWER_SUPPLY_PROP_PRESENT */
151 int i = 0; 170 int i = 0;
171 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
172 struct wm97xx_batt_pdata *pdata;
173
174 if (gpdata) {
175 dev_err(&dev->dev, "Do not pass platform_data through "
176 "wm97xx_bat_set_pdata!\n");
177 return -EINVAL;
178 } else
179 pdata = wmdata->batt_pdata;
152 180
153 if (dev->id != -1) 181 if (dev->id != -1)
154 return -EINVAL; 182 return -EINVAL;
@@ -156,17 +184,22 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
156 mutex_init(&work_lock); 184 mutex_init(&work_lock);
157 185
158 if (!pdata) { 186 if (!pdata) {
159 dev_err(&dev->dev, "Please use wm97xx_bat_set_pdata\n"); 187 dev_err(&dev->dev, "No platform_data supplied\n");
160 return -EINVAL; 188 return -EINVAL;
161 } 189 }
162 190
163 if (pdata->charge_gpio >= 0 && gpio_is_valid(pdata->charge_gpio)) { 191 if (gpio_is_valid(pdata->charge_gpio)) {
164 ret = gpio_request(pdata->charge_gpio, "BATT CHRG"); 192 ret = gpio_request(pdata->charge_gpio, "BATT CHRG");
165 if (ret) 193 if (ret)
166 goto err; 194 goto err;
167 ret = gpio_direction_input(pdata->charge_gpio); 195 ret = gpio_direction_input(pdata->charge_gpio);
168 if (ret) 196 if (ret)
169 goto err2; 197 goto err2;
198 ret = request_irq(gpio_to_irq(pdata->charge_gpio),
199 wm97xx_chrg_irq, IRQF_DISABLED,
200 "AC Detect", 0);
201 if (ret)
202 goto err2;
170 props++; /* POWER_SUPPLY_PROP_STATUS */ 203 props++; /* POWER_SUPPLY_PROP_STATUS */
171 } 204 }
172 205
@@ -183,7 +216,7 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
183 216
184 prop = kzalloc(props * sizeof(*prop), GFP_KERNEL); 217 prop = kzalloc(props * sizeof(*prop), GFP_KERNEL);
185 if (!prop) 218 if (!prop)
186 goto err2; 219 goto err3;
187 220
188 prop[i++] = POWER_SUPPLY_PROP_PRESENT; 221 prop[i++] = POWER_SUPPLY_PROP_PRESENT;
189 if (pdata->charge_gpio >= 0) 222 if (pdata->charge_gpio >= 0)
@@ -216,21 +249,30 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
216 if (!ret) 249 if (!ret)
217 schedule_work(&bat_work); 250 schedule_work(&bat_work);
218 else 251 else
219 goto err3; 252 goto err4;
220 253
221 return 0; 254 return 0;
222err3: 255err4:
223 kfree(prop); 256 kfree(prop);
257err3:
258 if (gpio_is_valid(pdata->charge_gpio))
259 free_irq(gpio_to_irq(pdata->charge_gpio), dev);
224err2: 260err2:
225 gpio_free(pdata->charge_gpio); 261 if (gpio_is_valid(pdata->charge_gpio))
262 gpio_free(pdata->charge_gpio);
226err: 263err:
227 return ret; 264 return ret;
228} 265}
229 266
230static int __devexit wm97xx_bat_remove(struct platform_device *dev) 267static int __devexit wm97xx_bat_remove(struct platform_device *dev)
231{ 268{
232 if (pdata && pdata->charge_gpio && pdata->charge_gpio >= 0) 269 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
270 struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
271
272 if (pdata && gpio_is_valid(pdata->charge_gpio)) {
273 free_irq(gpio_to_irq(pdata->charge_gpio), dev);
233 gpio_free(pdata->charge_gpio); 274 gpio_free(pdata->charge_gpio);
275 }
234 flush_scheduled_work(); 276 flush_scheduled_work();
235 power_supply_unregister(&bat_ps); 277 power_supply_unregister(&bat_ps);
236 kfree(prop); 278 kfree(prop);
@@ -241,11 +283,12 @@ static struct platform_driver wm97xx_bat_driver = {
241 .driver = { 283 .driver = {
242 .name = "wm97xx-battery", 284 .name = "wm97xx-battery",
243 .owner = THIS_MODULE, 285 .owner = THIS_MODULE,
286#ifdef CONFIG_PM
287 .pm = &wm97xx_bat_pm_ops,
288#endif
244 }, 289 },
245 .probe = wm97xx_bat_probe, 290 .probe = wm97xx_bat_probe,
246 .remove = __devexit_p(wm97xx_bat_remove), 291 .remove = __devexit_p(wm97xx_bat_remove),
247 .suspend = wm97xx_bat_suspend,
248 .resume = wm97xx_bat_resume,
249}; 292};
250 293
251static int __init wm97xx_bat_init(void) 294static int __init wm97xx_bat_init(void)
@@ -258,9 +301,9 @@ static void __exit wm97xx_bat_exit(void)
258 platform_driver_unregister(&wm97xx_bat_driver); 301 platform_driver_unregister(&wm97xx_bat_driver);
259} 302}
260 303
261void __init wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) 304void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data)
262{ 305{
263 pdata = data; 306 gpdata = data;
264} 307}
265EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata); 308EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata);
266 309