diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2011-10-31 20:43:06 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2011-11-25 14:58:47 -0500 |
commit | a8f6bd23cc73a54b9182cf8be102739e01ea874a (patch) | |
tree | 1901f17ffd9a7537d734555e496a599ca60bd300 /drivers/power/bq27x00_battery.c | |
parent | 4b226c2cf04eb373369d298fa00181b0eec71233 (diff) |
bq27x00_battery: Cache energy property
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/bq27x00_battery.c')
-rw-r--r-- | drivers/power/bq27x00_battery.c | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index 6c8dfdb169a1..e9aeb533a1f0 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c | |||
@@ -84,6 +84,7 @@ struct bq27x00_reg_cache { | |||
84 | int charge_full; | 84 | int charge_full; |
85 | int cycle_count; | 85 | int cycle_count; |
86 | int capacity; | 86 | int capacity; |
87 | int energy; | ||
87 | int flags; | 88 | int flags; |
88 | }; | 89 | }; |
89 | 90 | ||
@@ -225,6 +226,28 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di) | |||
225 | } | 226 | } |
226 | 227 | ||
227 | /* | 228 | /* |
229 | * Return the battery Available energy in µWh | ||
230 | * Or < 0 if something fails. | ||
231 | */ | ||
232 | static int bq27x00_battery_read_energy(struct bq27x00_device_info *di) | ||
233 | { | ||
234 | int ae; | ||
235 | |||
236 | ae = bq27x00_read(di, BQ27x00_REG_AE, false); | ||
237 | if (ae < 0) { | ||
238 | dev_err(di->dev, "error reading available energy\n"); | ||
239 | return ae; | ||
240 | } | ||
241 | |||
242 | if (di->chip == BQ27500) | ||
243 | ae *= 1000; | ||
244 | else | ||
245 | ae = ae * 29200 / BQ27000_RS; | ||
246 | |||
247 | return ae; | ||
248 | } | ||
249 | |||
250 | /* | ||
228 | * Return the battery Cycle count total | 251 | * Return the battery Cycle count total |
229 | * Or < 0 if something fails. | 252 | * Or < 0 if something fails. |
230 | */ | 253 | */ |
@@ -268,12 +291,14 @@ static void bq27x00_update(struct bq27x00_device_info *di) | |||
268 | if (cache.flags >= 0) { | 291 | if (cache.flags >= 0) { |
269 | if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) { | 292 | if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) { |
270 | cache.capacity = -ENODATA; | 293 | cache.capacity = -ENODATA; |
294 | cache.energy = -ENODATA; | ||
271 | cache.time_to_empty = -ENODATA; | 295 | cache.time_to_empty = -ENODATA; |
272 | cache.time_to_empty_avg = -ENODATA; | 296 | cache.time_to_empty_avg = -ENODATA; |
273 | cache.time_to_full = -ENODATA; | 297 | cache.time_to_full = -ENODATA; |
274 | cache.charge_full = -ENODATA; | 298 | cache.charge_full = -ENODATA; |
275 | } else { | 299 | } else { |
276 | cache.capacity = bq27x00_battery_read_rsoc(di); | 300 | cache.capacity = bq27x00_battery_read_rsoc(di); |
301 | cache.energy = bq27x00_battery_read_energy(di); | ||
277 | cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE); | 302 | cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE); |
278 | cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP); | 303 | cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP); |
279 | cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF); | 304 | cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF); |
@@ -435,32 +460,6 @@ static int bq27x00_battery_voltage(struct bq27x00_device_info *di, | |||
435 | return 0; | 460 | return 0; |
436 | } | 461 | } |
437 | 462 | ||
438 | /* | ||
439 | * Return the battery Available energy in µWh | ||
440 | * Or < 0 if something fails. | ||
441 | */ | ||
442 | static int bq27x00_battery_energy(struct bq27x00_device_info *di, | ||
443 | union power_supply_propval *val) | ||
444 | { | ||
445 | int ae; | ||
446 | |||
447 | ae = bq27x00_read(di, BQ27x00_REG_AE, false); | ||
448 | if (ae < 0) { | ||
449 | dev_err(di->dev, "error reading available energy\n"); | ||
450 | return ae; | ||
451 | } | ||
452 | |||
453 | if (di->chip == BQ27500) | ||
454 | ae *= 1000; | ||
455 | else | ||
456 | ae = ae * 29200 / BQ27000_RS; | ||
457 | |||
458 | val->intval = ae; | ||
459 | |||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | |||
464 | static int bq27x00_simple_value(int value, | 463 | static int bq27x00_simple_value(int value, |
465 | union power_supply_propval *val) | 464 | union power_supply_propval *val) |
466 | { | 465 | { |
@@ -539,7 +538,7 @@ static int bq27x00_battery_get_property(struct power_supply *psy, | |||
539 | ret = bq27x00_simple_value(di->cache.cycle_count, val); | 538 | ret = bq27x00_simple_value(di->cache.cycle_count, val); |
540 | break; | 539 | break; |
541 | case POWER_SUPPLY_PROP_ENERGY_NOW: | 540 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
542 | ret = bq27x00_battery_energy(di, val); | 541 | ret = bq27x00_simple_value(di->cache.energy, val); |
543 | break; | 542 | break; |
544 | default: | 543 | default: |
545 | return -EINVAL; | 544 | return -EINVAL; |