aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/Kconfig11
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/bq27x00_battery.c177
-rw-r--r--drivers/power/da9030_battery.c2
-rw-r--r--drivers/power/max8925_power.c534
-rw-r--r--drivers/power/power_supply_sysfs.c1
-rw-r--r--drivers/power/wm8350_power.c26
-rw-r--r--drivers/power/wm97xx_battery.c4
8 files changed, 694 insertions, 62 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index d4b3d67f0548..faaa9b4d0d07 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 MAX8925_POWER
33 tristate "MAX8925 battery charger support"
34 depends on MFD_MAX8925
35 help
36 Say Y here to enable support for the battery charger in the Maxim
37 MAX8925 PMIC.
38
32config WM831X_BACKUP 39config WM831X_BACKUP
33 tristate "WM831X backup battery charger support" 40 tristate "WM831X backup battery charger support"
34 depends on MFD_WM831X 41 depends on MFD_WM831X
@@ -98,10 +105,10 @@ config BATTERY_WM97XX
98 Say Y to enable support for battery measured by WM97xx aux port. 105 Say Y to enable support for battery measured by WM97xx aux port.
99 106
100config BATTERY_BQ27x00 107config BATTERY_BQ27x00
101 tristate "BQ27200 battery driver" 108 tristate "BQ27x00 battery driver"
102 depends on I2C 109 depends on I2C
103 help 110 help
104 Say Y here to enable support for batteries with BQ27200(I2C) chip. 111 Say Y here to enable support for batteries with BQ27x00 (I2C) chips.
105 112
106config BATTERY_DA9030 113config BATTERY_DA9030
107 tristate "DA9030 battery driver" 114 tristate "DA9030 battery driver"
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 573597c683b4..a2ba7c85c97a 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_MAX8925_POWER) += max8925_power.o
19obj-$(CONFIG_WM831X_BACKUP) += wm831x_backup.o 20obj-$(CONFIG_WM831X_BACKUP) += wm831x_backup.o
20obj-$(CONFIG_WM831X_POWER) += wm831x_power.o 21obj-$(CONFIG_WM831X_POWER) += wm831x_power.o
21obj-$(CONFIG_WM8350_POWER) += wm8350_power.o 22obj-$(CONFIG_WM8350_POWER) += wm8350_power.o
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 62bb98124e26..bece33ed873c 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -26,13 +26,22 @@
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <asm/unaligned.h> 27#include <asm/unaligned.h>
28 28
29#define DRIVER_VERSION "1.0.0" 29#define DRIVER_VERSION "1.1.0"
30 30
31#define BQ27x00_REG_TEMP 0x06 31#define BQ27x00_REG_TEMP 0x06
32#define BQ27x00_REG_VOLT 0x08 32#define BQ27x00_REG_VOLT 0x08
33#define BQ27x00_REG_RSOC 0x0B /* Relative State-of-Charge */
34#define BQ27x00_REG_AI 0x14 33#define BQ27x00_REG_AI 0x14
35#define BQ27x00_REG_FLAGS 0x0A 34#define BQ27x00_REG_FLAGS 0x0A
35#define BQ27x00_REG_TTE 0x16
36#define BQ27x00_REG_TTF 0x18
37#define BQ27x00_REG_TTECP 0x26
38
39#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
40#define BQ27000_FLAG_CHGS BIT(7)
41
42#define BQ27500_REG_SOC 0x2c
43#define BQ27500_FLAG_DSC BIT(0)
44#define BQ27500_FLAG_FC BIT(9)
36 45
37/* If the system has several batteries we need a different name for each 46/* If the system has several batteries we need a different name for each
38 * of them... 47 * of them...
@@ -46,25 +55,28 @@ struct bq27x00_access_methods {
46 struct bq27x00_device_info *di); 55 struct bq27x00_device_info *di);
47}; 56};
48 57
58enum bq27x00_chip { BQ27000, BQ27500 };
59
49struct bq27x00_device_info { 60struct bq27x00_device_info {
50 struct device *dev; 61 struct device *dev;
51 int id; 62 int id;
52 int voltage_uV;
53 int current_uA;
54 int temp_C;
55 int charge_rsoc;
56 struct bq27x00_access_methods *bus; 63 struct bq27x00_access_methods *bus;
57 struct power_supply bat; 64 struct power_supply bat;
65 enum bq27x00_chip chip;
58 66
59 struct i2c_client *client; 67 struct i2c_client *client;
60}; 68};
61 69
62static enum power_supply_property bq27x00_battery_props[] = { 70static enum power_supply_property bq27x00_battery_props[] = {
71 POWER_SUPPLY_PROP_STATUS,
63 POWER_SUPPLY_PROP_PRESENT, 72 POWER_SUPPLY_PROP_PRESENT,
64 POWER_SUPPLY_PROP_VOLTAGE_NOW, 73 POWER_SUPPLY_PROP_VOLTAGE_NOW,
65 POWER_SUPPLY_PROP_CURRENT_NOW, 74 POWER_SUPPLY_PROP_CURRENT_NOW,
66 POWER_SUPPLY_PROP_CAPACITY, 75 POWER_SUPPLY_PROP_CAPACITY,
67 POWER_SUPPLY_PROP_TEMP, 76 POWER_SUPPLY_PROP_TEMP,
77 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
78 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
79 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
68}; 80};
69 81
70/* 82/*
@@ -74,16 +86,11 @@ static enum power_supply_property bq27x00_battery_props[] = {
74static int bq27x00_read(u8 reg, int *rt_value, int b_single, 86static int bq27x00_read(u8 reg, int *rt_value, int b_single,
75 struct bq27x00_device_info *di) 87 struct bq27x00_device_info *di)
76{ 88{
77 int ret; 89 return di->bus->read(reg, rt_value, b_single, di);
78
79 ret = di->bus->read(reg, rt_value, b_single, di);
80 *rt_value = be16_to_cpu(*rt_value);
81
82 return ret;
83} 90}
84 91
85/* 92/*
86 * Return the battery temperature in Celsius degrees 93 * Return the battery temperature in tenths of degree Celsius
87 * Or < 0 if something fails. 94 * Or < 0 if something fails.
88 */ 95 */
89static int bq27x00_battery_temperature(struct bq27x00_device_info *di) 96static int bq27x00_battery_temperature(struct bq27x00_device_info *di)
@@ -97,7 +104,10 @@ static int bq27x00_battery_temperature(struct bq27x00_device_info *di)
97 return ret; 104 return ret;
98 } 105 }
99 106
100 return (temp >> 2) - 273; 107 if (di->chip == BQ27500)
108 return temp - 2731;
109 else
110 return ((temp >> 2) - 273) * 10;
101} 111}
102 112
103/* 113/*
@@ -115,7 +125,7 @@ static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
115 return ret; 125 return ret;
116 } 126 }
117 127
118 return volt; 128 return volt * 1000;
119} 129}
120 130
121/* 131/*
@@ -134,16 +144,23 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di)
134 dev_err(di->dev, "error reading current\n"); 144 dev_err(di->dev, "error reading current\n");
135 return 0; 145 return 0;
136 } 146 }
137 ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di); 147
138 if (ret < 0) { 148 if (di->chip == BQ27500) {
139 dev_err(di->dev, "error reading flags\n"); 149 /* bq27500 returns signed value */
140 return 0; 150 curr = (int)(s16)curr;
141 } 151 } else {
142 if ((flags & (1 << 7)) != 0) { 152 ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
143 dev_dbg(di->dev, "negative current!\n"); 153 if (ret < 0) {
144 return -curr; 154 dev_err(di->dev, "error reading flags\n");
155 return 0;
156 }
157 if (flags & BQ27000_FLAG_CHGS) {
158 dev_dbg(di->dev, "negative current!\n");
159 curr = -curr;
160 }
145 } 161 }
146 return curr; 162
163 return curr * 1000;
147} 164}
148 165
149/* 166/*
@@ -155,13 +172,70 @@ static int bq27x00_battery_rsoc(struct bq27x00_device_info *di)
155 int ret; 172 int ret;
156 int rsoc = 0; 173 int rsoc = 0;
157 174
158 ret = bq27x00_read(BQ27x00_REG_RSOC, &rsoc, 1, di); 175 if (di->chip == BQ27500)
176 ret = bq27x00_read(BQ27500_REG_SOC, &rsoc, 0, di);
177 else
178 ret = bq27x00_read(BQ27000_REG_RSOC, &rsoc, 1, di);
159 if (ret) { 179 if (ret) {
160 dev_err(di->dev, "error reading relative State-of-Charge\n"); 180 dev_err(di->dev, "error reading relative State-of-Charge\n");
161 return ret; 181 return ret;
162 } 182 }
163 183
164 return rsoc >> 8; 184 return rsoc;
185}
186
187static int bq27x00_battery_status(struct bq27x00_device_info *di,
188 union power_supply_propval *val)
189{
190 int flags = 0;
191 int status;
192 int ret;
193
194 ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
195 if (ret < 0) {
196 dev_err(di->dev, "error reading flags\n");
197 return ret;
198 }
199
200 if (di->chip == BQ27500) {
201 if (flags & BQ27500_FLAG_FC)
202 status = POWER_SUPPLY_STATUS_FULL;
203 else if (flags & BQ27500_FLAG_DSC)
204 status = POWER_SUPPLY_STATUS_DISCHARGING;
205 else
206 status = POWER_SUPPLY_STATUS_CHARGING;
207 } else {
208 if (flags & BQ27000_FLAG_CHGS)
209 status = POWER_SUPPLY_STATUS_CHARGING;
210 else
211 status = POWER_SUPPLY_STATUS_DISCHARGING;
212 }
213
214 val->intval = status;
215 return 0;
216}
217
218/*
219 * Read a time register.
220 * Return < 0 if something fails.
221 */
222static int bq27x00_battery_time(struct bq27x00_device_info *di, int reg,
223 union power_supply_propval *val)
224{
225 int tval = 0;
226 int ret;
227
228 ret = bq27x00_read(reg, &tval, 0, di);
229 if (ret) {
230 dev_err(di->dev, "error reading register %02x\n", reg);
231 return ret;
232 }
233
234 if (tval == 65535)
235 return -ENODATA;
236
237 val->intval = tval * 60;
238 return 0;
165} 239}
166 240
167#define to_bq27x00_device_info(x) container_of((x), \ 241#define to_bq27x00_device_info(x) container_of((x), \
@@ -171,9 +245,13 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
171 enum power_supply_property psp, 245 enum power_supply_property psp,
172 union power_supply_propval *val) 246 union power_supply_propval *val)
173{ 247{
248 int ret = 0;
174 struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 249 struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
175 250
176 switch (psp) { 251 switch (psp) {
252 case POWER_SUPPLY_PROP_STATUS:
253 ret = bq27x00_battery_status(di, val);
254 break;
177 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 255 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
178 case POWER_SUPPLY_PROP_PRESENT: 256 case POWER_SUPPLY_PROP_PRESENT:
179 val->intval = bq27x00_battery_voltage(di); 257 val->intval = bq27x00_battery_voltage(di);
@@ -189,11 +267,20 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
189 case POWER_SUPPLY_PROP_TEMP: 267 case POWER_SUPPLY_PROP_TEMP:
190 val->intval = bq27x00_battery_temperature(di); 268 val->intval = bq27x00_battery_temperature(di);
191 break; 269 break;
270 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
271 ret = bq27x00_battery_time(di, BQ27x00_REG_TTE, val);
272 break;
273 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
274 ret = bq27x00_battery_time(di, BQ27x00_REG_TTECP, val);
275 break;
276 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
277 ret = bq27x00_battery_time(di, BQ27x00_REG_TTF, val);
278 break;
192 default: 279 default:
193 return -EINVAL; 280 return -EINVAL;
194 } 281 }
195 282
196 return 0; 283 return ret;
197} 284}
198 285
199static void bq27x00_powersupply_init(struct bq27x00_device_info *di) 286static void bq27x00_powersupply_init(struct bq27x00_device_info *di)
@@ -206,10 +293,10 @@ static void bq27x00_powersupply_init(struct bq27x00_device_info *di)
206} 293}
207 294
208/* 295/*
209 * BQ27200 specific code 296 * i2c specific code
210 */ 297 */
211 298
212static int bq27200_read(u8 reg, int *rt_value, int b_single, 299static int bq27x00_read_i2c(u8 reg, int *rt_value, int b_single,
213 struct bq27x00_device_info *di) 300 struct bq27x00_device_info *di)
214{ 301{
215 struct i2c_client *client = di->client; 302 struct i2c_client *client = di->client;
@@ -238,7 +325,7 @@ static int bq27200_read(u8 reg, int *rt_value, int b_single,
238 err = i2c_transfer(client->adapter, msg, 1); 325 err = i2c_transfer(client->adapter, msg, 1);
239 if (err >= 0) { 326 if (err >= 0) {
240 if (!b_single) 327 if (!b_single)
241 *rt_value = get_unaligned_be16(data); 328 *rt_value = get_unaligned_le16(data);
242 else 329 else
243 *rt_value = data[0]; 330 *rt_value = data[0];
244 331
@@ -248,7 +335,7 @@ static int bq27200_read(u8 reg, int *rt_value, int b_single,
248 return err; 335 return err;
249} 336}
250 337
251static int bq27200_battery_probe(struct i2c_client *client, 338static int bq27x00_battery_probe(struct i2c_client *client,
252 const struct i2c_device_id *id) 339 const struct i2c_device_id *id)
253{ 340{
254 char *name; 341 char *name;
@@ -267,7 +354,7 @@ static int bq27200_battery_probe(struct i2c_client *client,
267 if (retval < 0) 354 if (retval < 0)
268 return retval; 355 return retval;
269 356
270 name = kasprintf(GFP_KERNEL, "bq27200-%d", num); 357 name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
271 if (!name) { 358 if (!name) {
272 dev_err(&client->dev, "failed to allocate device name\n"); 359 dev_err(&client->dev, "failed to allocate device name\n");
273 retval = -ENOMEM; 360 retval = -ENOMEM;
@@ -281,6 +368,7 @@ static int bq27200_battery_probe(struct i2c_client *client,
281 goto batt_failed_2; 368 goto batt_failed_2;
282 } 369 }
283 di->id = num; 370 di->id = num;
371 di->chip = id->driver_data;
284 372
285 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 373 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
286 if (!bus) { 374 if (!bus) {
@@ -293,7 +381,7 @@ static int bq27200_battery_probe(struct i2c_client *client,
293 i2c_set_clientdata(client, di); 381 i2c_set_clientdata(client, di);
294 di->dev = &client->dev; 382 di->dev = &client->dev;
295 di->bat.name = name; 383 di->bat.name = name;
296 bus->read = &bq27200_read; 384 bus->read = &bq27x00_read_i2c;
297 di->bus = bus; 385 di->bus = bus;
298 di->client = client; 386 di->client = client;
299 387
@@ -323,7 +411,7 @@ batt_failed_1:
323 return retval; 411 return retval;
324} 412}
325 413
326static int bq27200_battery_remove(struct i2c_client *client) 414static int bq27x00_battery_remove(struct i2c_client *client)
327{ 415{
328 struct bq27x00_device_info *di = i2c_get_clientdata(client); 416 struct bq27x00_device_info *di = i2c_get_clientdata(client);
329 417
@@ -344,27 +432,28 @@ static int bq27200_battery_remove(struct i2c_client *client)
344 * Module stuff 432 * Module stuff
345 */ 433 */
346 434
347static const struct i2c_device_id bq27200_id[] = { 435static const struct i2c_device_id bq27x00_id[] = {
348 { "bq27200", 0 }, 436 { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
437 { "bq27500", BQ27500 },
349 {}, 438 {},
350}; 439};
351 440
352static struct i2c_driver bq27200_battery_driver = { 441static struct i2c_driver bq27x00_battery_driver = {
353 .driver = { 442 .driver = {
354 .name = "bq27200-battery", 443 .name = "bq27x00-battery",
355 }, 444 },
356 .probe = bq27200_battery_probe, 445 .probe = bq27x00_battery_probe,
357 .remove = bq27200_battery_remove, 446 .remove = bq27x00_battery_remove,
358 .id_table = bq27200_id, 447 .id_table = bq27x00_id,
359}; 448};
360 449
361static int __init bq27x00_battery_init(void) 450static int __init bq27x00_battery_init(void)
362{ 451{
363 int ret; 452 int ret;
364 453
365 ret = i2c_add_driver(&bq27200_battery_driver); 454 ret = i2c_add_driver(&bq27x00_battery_driver);
366 if (ret) 455 if (ret)
367 printk(KERN_ERR "Unable to register BQ27200 driver\n"); 456 printk(KERN_ERR "Unable to register BQ27x00 driver\n");
368 457
369 return ret; 458 return ret;
370} 459}
@@ -372,7 +461,7 @@ module_init(bq27x00_battery_init);
372 461
373static void __exit bq27x00_battery_exit(void) 462static void __exit bq27x00_battery_exit(void)
374{ 463{
375 i2c_del_driver(&bq27200_battery_driver); 464 i2c_del_driver(&bq27x00_battery_driver);
376} 465}
377module_exit(bq27x00_battery_exit); 466module_exit(bq27x00_battery_exit);
378 467
diff --git a/drivers/power/da9030_battery.c b/drivers/power/da9030_battery.c
index 3364198134a1..a2e71f7b27fb 100644
--- a/drivers/power/da9030_battery.c
+++ b/drivers/power/da9030_battery.c
@@ -509,7 +509,7 @@ static int da9030_battery_probe(struct platform_device *pdev)
509 509
510 charger->master = pdev->dev.parent; 510 charger->master = pdev->dev.parent;
511 511
512 /* 10 seconds between monotor runs unless platfrom defines other 512 /* 10 seconds between monitor runs unless platform defines other
513 interval */ 513 interval */
514 charger->interval = msecs_to_jiffies( 514 charger->interval = msecs_to_jiffies(
515 (pdata->batmon_interval ? : 10) * 1000); 515 (pdata->batmon_interval ? : 10) * 1000);
diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
new file mode 100644
index 000000000000..a1b4410544d7
--- /dev/null
+++ b/drivers/power/max8925_power.c
@@ -0,0 +1,534 @@
1/*
2 * Battery driver for Maxim MAX8925
3 *
4 * Copyright (c) 2009-2010 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <linux/power_supply.h>
18#include <linux/mfd/max8925.h>
19
20/* registers in GPM */
21#define MAX8925_OUT5VEN 0x54
22#define MAX8925_OUT3VEN 0x58
23#define MAX8925_CHG_CNTL1 0x7c
24
25/* bits definition */
26#define MAX8925_CHG_STAT_VSYSLOW (1 << 0)
27#define MAX8925_CHG_STAT_MODE_MASK (3 << 2)
28#define MAX8925_CHG_STAT_EN_MASK (1 << 4)
29#define MAX8925_CHG_MBDET (1 << 1)
30#define MAX8925_CHG_AC_RANGE_MASK (3 << 6)
31
32/* registers in ADC */
33#define MAX8925_ADC_RES_CNFG1 0x06
34#define MAX8925_ADC_AVG_CNFG1 0x07
35#define MAX8925_ADC_ACQ_CNFG1 0x08
36#define MAX8925_ADC_ACQ_CNFG2 0x09
37/* 2 bytes registers in below. MSB is 1st, LSB is 2nd. */
38#define MAX8925_ADC_AUX2 0x62
39#define MAX8925_ADC_VCHG 0x64
40#define MAX8925_ADC_VBBATT 0x66
41#define MAX8925_ADC_VMBATT 0x68
42#define MAX8925_ADC_ISNS 0x6a
43#define MAX8925_ADC_THM 0x6c
44#define MAX8925_ADC_TDIE 0x6e
45#define MAX8925_CMD_AUX2 0xc8
46#define MAX8925_CMD_VCHG 0xd0
47#define MAX8925_CMD_VBBATT 0xd8
48#define MAX8925_CMD_VMBATT 0xe0
49#define MAX8925_CMD_ISNS 0xe8
50#define MAX8925_CMD_THM 0xf0
51#define MAX8925_CMD_TDIE 0xf8
52
53enum {
54 MEASURE_AUX2,
55 MEASURE_VCHG,
56 MEASURE_VBBATT,
57 MEASURE_VMBATT,
58 MEASURE_ISNS,
59 MEASURE_THM,
60 MEASURE_TDIE,
61 MEASURE_MAX,
62};
63
64struct max8925_power_info {
65 struct max8925_chip *chip;
66 struct i2c_client *gpm;
67 struct i2c_client *adc;
68
69 struct power_supply ac;
70 struct power_supply usb;
71 struct power_supply battery;
72 int irq_base;
73 unsigned ac_online:1;
74 unsigned usb_online:1;
75 unsigned bat_online:1;
76 unsigned chg_mode:2;
77 unsigned batt_detect:1; /* detecing MB by ID pin */
78 unsigned topoff_threshold:2;
79 unsigned fast_charge:3;
80
81 int (*set_charger) (int);
82};
83
84static int __set_charger(struct max8925_power_info *info, int enable)
85{
86 struct max8925_chip *chip = info->chip;
87 if (enable) {
88 /* enable charger in platform */
89 if (info->set_charger)
90 info->set_charger(1);
91 /* enable charger */
92 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 0);
93 } else {
94 /* disable charge */
95 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 1 << 7);
96 if (info->set_charger)
97 info->set_charger(0);
98 }
99 dev_dbg(chip->dev, "%s\n", (enable) ? "Enable charger"
100 : "Disable charger");
101 return 0;
102}
103
104static irqreturn_t max8925_charger_handler(int irq, void *data)
105{
106 struct max8925_power_info *info = (struct max8925_power_info *)data;
107 struct max8925_chip *chip = info->chip;
108
109 switch (irq - chip->irq_base) {
110 case MAX8925_IRQ_VCHG_DC_R:
111 info->ac_online = 1;
112 __set_charger(info, 1);
113 dev_dbg(chip->dev, "Adapter inserted\n");
114 break;
115 case MAX8925_IRQ_VCHG_DC_F:
116 info->ac_online = 0;
117 __set_charger(info, 0);
118 dev_dbg(chip->dev, "Adapter is removal\n");
119 break;
120 case MAX8925_IRQ_VCHG_USB_R:
121 info->usb_online = 1;
122 __set_charger(info, 1);
123 dev_dbg(chip->dev, "USB inserted\n");
124 break;
125 case MAX8925_IRQ_VCHG_USB_F:
126 info->usb_online = 0;
127 __set_charger(info, 0);
128 dev_dbg(chip->dev, "USB is removal\n");
129 break;
130 case MAX8925_IRQ_VCHG_THM_OK_F:
131 /* Battery is not ready yet */
132 dev_dbg(chip->dev, "Battery temperature is out of range\n");
133 case MAX8925_IRQ_VCHG_DC_OVP:
134 dev_dbg(chip->dev, "Error detection\n");
135 __set_charger(info, 0);
136 break;
137 case MAX8925_IRQ_VCHG_THM_OK_R:
138 /* Battery is ready now */
139 dev_dbg(chip->dev, "Battery temperature is in range\n");
140 break;
141 case MAX8925_IRQ_VCHG_SYSLOW_R:
142 /* VSYS is low */
143 dev_info(chip->dev, "Sys power is too low\n");
144 break;
145 case MAX8925_IRQ_VCHG_SYSLOW_F:
146 dev_dbg(chip->dev, "Sys power is above low threshold\n");
147 break;
148 case MAX8925_IRQ_VCHG_DONE:
149 __set_charger(info, 0);
150 dev_dbg(chip->dev, "Charging is done\n");
151 break;
152 case MAX8925_IRQ_VCHG_TOPOFF:
153 dev_dbg(chip->dev, "Charging in top-off mode\n");
154 break;
155 case MAX8925_IRQ_VCHG_TMR_FAULT:
156 __set_charger(info, 0);
157 dev_dbg(chip->dev, "Safe timer is expired\n");
158 break;
159 case MAX8925_IRQ_VCHG_RST:
160 __set_charger(info, 0);
161 dev_dbg(chip->dev, "Charger is reset\n");
162 break;
163 }
164 return IRQ_HANDLED;
165}
166
167static int start_measure(struct max8925_power_info *info, int type)
168{
169 unsigned char buf[2] = {0, 0};
170 int meas_reg = 0, ret;
171
172 switch (type) {
173 case MEASURE_VCHG:
174 meas_reg = MAX8925_ADC_VCHG;
175 break;
176 case MEASURE_VBBATT:
177 meas_reg = MAX8925_ADC_VBBATT;
178 break;
179 case MEASURE_VMBATT:
180 meas_reg = MAX8925_ADC_VMBATT;
181 break;
182 case MEASURE_ISNS:
183 meas_reg = MAX8925_ADC_ISNS;
184 break;
185 default:
186 return -EINVAL;
187 }
188
189 max8925_bulk_read(info->adc, meas_reg, 2, buf);
190 ret = (buf[0] << 4) | (buf[1] >> 4);
191
192 return ret;
193}
194
195static int max8925_ac_get_prop(struct power_supply *psy,
196 enum power_supply_property psp,
197 union power_supply_propval *val)
198{
199 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
200 int ret = 0;
201
202 switch (psp) {
203 case POWER_SUPPLY_PROP_ONLINE:
204 val->intval = info->ac_online;
205 break;
206 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
207 if (info->ac_online) {
208 ret = start_measure(info, MEASURE_VCHG);
209 if (ret >= 0) {
210 val->intval = ret << 1; /* unit is mV */
211 goto out;
212 }
213 }
214 ret = -ENODATA;
215 break;
216 default:
217 ret = -ENODEV;
218 break;
219 }
220out:
221 return ret;
222}
223
224static enum power_supply_property max8925_ac_props[] = {
225 POWER_SUPPLY_PROP_ONLINE,
226 POWER_SUPPLY_PROP_VOLTAGE_NOW,
227};
228
229static int max8925_usb_get_prop(struct power_supply *psy,
230 enum power_supply_property psp,
231 union power_supply_propval *val)
232{
233 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
234 int ret = 0;
235
236 switch (psp) {
237 case POWER_SUPPLY_PROP_ONLINE:
238 val->intval = info->usb_online;
239 break;
240 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
241 if (info->usb_online) {
242 ret = start_measure(info, MEASURE_VCHG);
243 if (ret >= 0) {
244 val->intval = ret << 1; /* unit is mV */
245 goto out;
246 }
247 }
248 ret = -ENODATA;
249 break;
250 default:
251 ret = -ENODEV;
252 break;
253 }
254out:
255 return ret;
256}
257
258static enum power_supply_property max8925_usb_props[] = {
259 POWER_SUPPLY_PROP_ONLINE,
260 POWER_SUPPLY_PROP_VOLTAGE_NOW,
261};
262
263static int max8925_bat_get_prop(struct power_supply *psy,
264 enum power_supply_property psp,
265 union power_supply_propval *val)
266{
267 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
268 long long int tmp = 0;
269 int ret = 0;
270
271 switch (psp) {
272 case POWER_SUPPLY_PROP_ONLINE:
273 val->intval = info->bat_online;
274 break;
275 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
276 if (info->bat_online) {
277 ret = start_measure(info, MEASURE_VMBATT);
278 if (ret >= 0) {
279 val->intval = ret << 1; /* unit is mV */
280 ret = 0;
281 break;
282 }
283 }
284 ret = -ENODATA;
285 break;
286 case POWER_SUPPLY_PROP_CURRENT_NOW:
287 if (info->bat_online) {
288 ret = start_measure(info, MEASURE_ISNS);
289 if (ret >= 0) {
290 tmp = (long long int)ret * 6250 / 4096 - 3125;
291 ret = (int)tmp;
292 val->intval = 0;
293 if (ret > 0)
294 val->intval = ret; /* unit is mA */
295 ret = 0;
296 break;
297 }
298 }
299 ret = -ENODATA;
300 break;
301 case POWER_SUPPLY_PROP_CHARGE_TYPE:
302 if (!info->bat_online) {
303 ret = -ENODATA;
304 break;
305 }
306 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS);
307 ret = (ret & MAX8925_CHG_STAT_MODE_MASK) >> 2;
308 switch (ret) {
309 case 1:
310 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
311 break;
312 case 0:
313 case 2:
314 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
315 break;
316 case 3:
317 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
318 break;
319 }
320 ret = 0;
321 break;
322 case POWER_SUPPLY_PROP_STATUS:
323 if (!info->bat_online) {
324 ret = -ENODATA;
325 break;
326 }
327 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS);
328 if (info->usb_online || info->ac_online) {
329 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
330 if (ret & MAX8925_CHG_STAT_EN_MASK)
331 val->intval = POWER_SUPPLY_STATUS_CHARGING;
332 } else
333 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
334 ret = 0;
335 break;
336 default:
337 ret = -ENODEV;
338 break;
339 }
340 return ret;
341}
342
343static enum power_supply_property max8925_battery_props[] = {
344 POWER_SUPPLY_PROP_ONLINE,
345 POWER_SUPPLY_PROP_VOLTAGE_NOW,
346 POWER_SUPPLY_PROP_CURRENT_NOW,
347 POWER_SUPPLY_PROP_CHARGE_TYPE,
348 POWER_SUPPLY_PROP_STATUS,
349};
350
351#define REQUEST_IRQ(_irq, _name) \
352do { \
353 ret = request_threaded_irq(chip->irq_base + _irq, NULL, \
354 max8925_charger_handler, \
355 IRQF_ONESHOT, _name, info); \
356 if (ret) \
357 dev_err(chip->dev, "Failed to request IRQ #%d: %d\n", \
358 _irq, ret); \
359} while (0)
360
361static __devinit int max8925_init_charger(struct max8925_chip *chip,
362 struct max8925_power_info *info)
363{
364 int ret;
365
366 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_OVP, "ac-ovp");
367 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_F, "ac-remove");
368 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_R, "ac-insert");
369 REQUEST_IRQ(MAX8925_IRQ_VCHG_USB_OVP, "usb-ovp");
370 REQUEST_IRQ(MAX8925_IRQ_VCHG_USB_F, "usb-remove");
371 REQUEST_IRQ(MAX8925_IRQ_VCHG_USB_R, "usb-insert");
372 REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_R, "batt-temp-in-range");
373 REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_F, "batt-temp-out-range");
374 REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_F, "vsys-high");
375 REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_R, "vsys-low");
376 REQUEST_IRQ(MAX8925_IRQ_VCHG_RST, "charger-reset");
377 REQUEST_IRQ(MAX8925_IRQ_VCHG_DONE, "charger-done");
378 REQUEST_IRQ(MAX8925_IRQ_VCHG_TOPOFF, "charger-topoff");
379 REQUEST_IRQ(MAX8925_IRQ_VCHG_TMR_FAULT, "charger-timer-expire");
380
381 info->ac_online = 0;
382 info->usb_online = 0;
383 info->bat_online = 0;
384 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS);
385 if (ret >= 0) {
386 /*
387 * If battery detection is enabled, ID pin of battery is
388 * connected to MBDET pin of MAX8925. It could be used to
389 * detect battery presence.
390 * Otherwise, we have to assume that battery is always on.
391 */
392 if (info->batt_detect)
393 info->bat_online = (ret & MAX8925_CHG_MBDET) ? 0 : 1;
394 else
395 info->bat_online = 1;
396 if (ret & MAX8925_CHG_AC_RANGE_MASK)
397 info->ac_online = 1;
398 else
399 info->ac_online = 0;
400 }
401 /* disable charge */
402 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 1 << 7);
403 /* set charging current in charge topoff mode */
404 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 3 << 5,
405 info->topoff_threshold << 5);
406 /* set charing current in fast charge mode */
407 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 7, info->fast_charge);
408
409 return 0;
410}
411
412static __devexit int max8925_deinit_charger(struct max8925_power_info *info)
413{
414 struct max8925_chip *chip = info->chip;
415 int irq;
416
417 irq = chip->irq_base + MAX8925_IRQ_VCHG_DC_OVP;
418 for (; irq <= chip->irq_base + MAX8925_IRQ_VCHG_TMR_FAULT; irq++)
419 free_irq(irq, info);
420
421 return 0;
422}
423
424static __devinit int max8925_power_probe(struct platform_device *pdev)
425{
426 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
427 struct max8925_platform_data *max8925_pdata;
428 struct max8925_power_pdata *pdata = NULL;
429 struct max8925_power_info *info;
430 int ret;
431
432 if (pdev->dev.parent->platform_data) {
433 max8925_pdata = pdev->dev.parent->platform_data;
434 pdata = max8925_pdata->power;
435 }
436
437 if (!pdata) {
438 dev_err(&pdev->dev, "platform data isn't assigned to "
439 "power supply\n");
440 return -EINVAL;
441 }
442
443 info = kzalloc(sizeof(struct max8925_power_info), GFP_KERNEL);
444 if (!info)
445 return -ENOMEM;
446 info->chip = chip;
447 info->gpm = chip->i2c;
448 info->adc = chip->adc;
449
450 info->ac.name = "max8925-ac";
451 info->ac.type = POWER_SUPPLY_TYPE_MAINS;
452 info->ac.properties = max8925_ac_props;
453 info->ac.num_properties = ARRAY_SIZE(max8925_ac_props);
454 info->ac.get_property = max8925_ac_get_prop;
455 ret = power_supply_register(&pdev->dev, &info->ac);
456 if (ret)
457 goto out;
458 info->ac.dev->parent = &pdev->dev;
459
460 info->usb.name = "max8925-usb";
461 info->usb.type = POWER_SUPPLY_TYPE_USB;
462 info->usb.properties = max8925_usb_props;
463 info->usb.num_properties = ARRAY_SIZE(max8925_usb_props);
464 info->usb.get_property = max8925_usb_get_prop;
465 ret = power_supply_register(&pdev->dev, &info->usb);
466 if (ret)
467 goto out_usb;
468 info->usb.dev->parent = &pdev->dev;
469
470 info->battery.name = "max8925-battery";
471 info->battery.type = POWER_SUPPLY_TYPE_BATTERY;
472 info->battery.properties = max8925_battery_props;
473 info->battery.num_properties = ARRAY_SIZE(max8925_battery_props);
474 info->battery.get_property = max8925_bat_get_prop;
475 ret = power_supply_register(&pdev->dev, &info->battery);
476 if (ret)
477 goto out_battery;
478 info->battery.dev->parent = &pdev->dev;
479
480 info->batt_detect = pdata->batt_detect;
481 info->topoff_threshold = pdata->topoff_threshold;
482 info->fast_charge = pdata->fast_charge;
483 info->set_charger = pdata->set_charger;
484 dev_set_drvdata(&pdev->dev, info);
485 platform_set_drvdata(pdev, info);
486
487 max8925_init_charger(chip, info);
488 return 0;
489out_battery:
490 power_supply_unregister(&info->battery);
491out_usb:
492 power_supply_unregister(&info->ac);
493out:
494 kfree(info);
495 return ret;
496}
497
498static __devexit int max8925_power_remove(struct platform_device *pdev)
499{
500 struct max8925_power_info *info = platform_get_drvdata(pdev);
501
502 if (info) {
503 power_supply_unregister(&info->ac);
504 power_supply_unregister(&info->usb);
505 power_supply_unregister(&info->battery);
506 max8925_deinit_charger(info);
507 kfree(info);
508 }
509 return 0;
510}
511
512static struct platform_driver max8925_power_driver = {
513 .probe = max8925_power_probe,
514 .remove = __devexit_p(max8925_power_remove),
515 .driver = {
516 .name = "max8925-power",
517 },
518};
519
520static int __init max8925_power_init(void)
521{
522 return platform_driver_register(&max8925_power_driver);
523}
524module_init(max8925_power_init);
525
526static void __exit max8925_power_exit(void)
527{
528 platform_driver_unregister(&max8925_power_driver);
529}
530module_exit(max8925_power_exit);
531
532MODULE_LICENSE("GPL");
533MODULE_DESCRIPTION("Power supply driver for MAX8925");
534MODULE_ALIAS("platform:max8925-power");
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index c790e0c77d4b..ff05e6189768 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -99,6 +99,7 @@ static struct device_attribute power_supply_attrs[] = {
99 POWER_SUPPLY_ATTR(present), 99 POWER_SUPPLY_ATTR(present),
100 POWER_SUPPLY_ATTR(online), 100 POWER_SUPPLY_ATTR(online),
101 POWER_SUPPLY_ATTR(technology), 101 POWER_SUPPLY_ATTR(technology),
102 POWER_SUPPLY_ATTR(cycle_count),
102 POWER_SUPPLY_ATTR(voltage_max), 103 POWER_SUPPLY_ATTR(voltage_max),
103 POWER_SUPPLY_ATTR(voltage_min), 104 POWER_SUPPLY_ATTR(voltage_min),
104 POWER_SUPPLY_ATTR(voltage_max_design), 105 POWER_SUPPLY_ATTR(voltage_max_design),
diff --git a/drivers/power/wm8350_power.c b/drivers/power/wm8350_power.c
index ad4f071e1287..0693902d6151 100644
--- a/drivers/power/wm8350_power.c
+++ b/drivers/power/wm8350_power.c
@@ -190,7 +190,7 @@ static irqreturn_t wm8350_charger_handler(int irq, void *data)
190 struct wm8350_power *power = &wm8350->power; 190 struct wm8350_power *power = &wm8350->power;
191 struct wm8350_charger_policy *policy = power->policy; 191 struct wm8350_charger_policy *policy = power->policy;
192 192
193 switch (irq) { 193 switch (irq - wm8350->irq_base) {
194 case WM8350_IRQ_CHG_BAT_FAIL: 194 case WM8350_IRQ_CHG_BAT_FAIL:
195 dev_err(wm8350->dev, "battery failed\n"); 195 dev_err(wm8350->dev, "battery failed\n");
196 break; 196 break;
@@ -428,18 +428,18 @@ static void wm8350_init_charger(struct wm8350 *wm8350)
428 428
429static void free_charger_irq(struct wm8350 *wm8350) 429static void free_charger_irq(struct wm8350 *wm8350)
430{ 430{
431 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT); 431 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, wm8350);
432 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD); 432 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, wm8350);
433 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL); 433 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, wm8350);
434 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO); 434 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350);
435 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END); 435 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350);
436 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START); 436 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350);
437 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9); 437 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350);
438 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1); 438 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350);
439 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85); 439 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350);
440 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB); 440 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB, wm8350);
441 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB); 441 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, wm8350);
442 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_BAT_FB); 442 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, wm8350);
443} 443}
444 444
445static __devinit int wm8350_power_probe(struct platform_device *pdev) 445static __devinit int wm8350_power_probe(struct platform_device *pdev)
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index 6ea3cb5837c7..23eed356a854 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -26,7 +26,7 @@
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; 29static struct mutex work_lock;
30static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; 30static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
31static struct wm97xx_batt_info *gpdata; 31static struct wm97xx_batt_info *gpdata;
32static enum power_supply_property *prop; 32static enum power_supply_property *prop;
@@ -203,7 +203,7 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
203 goto err2; 203 goto err2;
204 ret = request_irq(gpio_to_irq(pdata->charge_gpio), 204 ret = request_irq(gpio_to_irq(pdata->charge_gpio),
205 wm97xx_chrg_irq, IRQF_DISABLED, 205 wm97xx_chrg_irq, IRQF_DISABLED,
206 "AC Detect", 0); 206 "AC Detect", dev);
207 if (ret) 207 if (ret)
208 goto err2; 208 goto err2;
209 props++; /* POWER_SUPPLY_PROP_STATUS */ 209 props++; /* POWER_SUPPLY_PROP_STATUS */