aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/Kconfig4
-rw-r--r--drivers/power/bq27x00_battery.c177
-rw-r--r--drivers/power/da9030_battery.c2
-rw-r--r--drivers/power/wm97xx_battery.c4
4 files changed, 138 insertions, 49 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index d4b3d67f0548..bf1467213954 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -98,10 +98,10 @@ config BATTERY_WM97XX
98 Say Y to enable support for battery measured by WM97xx aux port. 98 Say Y to enable support for battery measured by WM97xx aux port.
99 99
100config BATTERY_BQ27x00 100config BATTERY_BQ27x00
101 tristate "BQ27200 battery driver" 101 tristate "BQ27x00 battery driver"
102 depends on I2C 102 depends on I2C
103 help 103 help
104 Say Y here to enable support for batteries with BQ27200(I2C) chip. 104 Say Y here to enable support for batteries with BQ27x00 (I2C) chips.
105 105
106config BATTERY_DA9030 106config BATTERY_DA9030
107 tristate "DA9030 battery driver" 107 tristate "DA9030 battery driver"
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/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 */