diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2011-10-31 20:43:03 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2011-11-25 14:57:14 -0500 |
commit | b68f6216c5f53698379603209d3168766449fdab (patch) | |
tree | da4a07c26d78ee7d7f309c6328d93fb5f551499f /drivers/power | |
parent | e7a5f6d55991fb3b3214f435681ee2db96320395 (diff) |
bq27x00_battery: Do not cache current_now value for bq27000 batery
* This prevent reporting old current_now value for bq27000
* Also ask for current flags, to make sure that current_now
will be reported with correct signature
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/bq27x00_battery.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index bb16f5b7e167..d238144d1e81 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c | |||
@@ -80,8 +80,6 @@ struct bq27x00_reg_cache { | |||
80 | int cycle_count; | 80 | int cycle_count; |
81 | int capacity; | 81 | int capacity; |
82 | int flags; | 82 | int flags; |
83 | |||
84 | int current_now; | ||
85 | }; | 83 | }; |
86 | 84 | ||
87 | struct bq27x00_device_info { | 85 | struct bq27x00_device_info { |
@@ -270,17 +268,12 @@ static void bq27x00_update(struct bq27x00_device_info *di) | |||
270 | cache.charge_full = bq27x00_battery_read_lmd(di); | 268 | cache.charge_full = bq27x00_battery_read_lmd(di); |
271 | cache.cycle_count = bq27x00_battery_read_cyct(di); | 269 | cache.cycle_count = bq27x00_battery_read_cyct(di); |
272 | 270 | ||
273 | if (!is_bq27500) | ||
274 | cache.current_now = bq27x00_read(di, BQ27x00_REG_AI, false); | ||
275 | |||
276 | /* We only have to read charge design full once */ | 271 | /* We only have to read charge design full once */ |
277 | if (di->charge_design_full <= 0) | 272 | if (di->charge_design_full <= 0) |
278 | di->charge_design_full = bq27x00_battery_read_ilmd(di); | 273 | di->charge_design_full = bq27x00_battery_read_ilmd(di); |
279 | } | 274 | } |
280 | 275 | ||
281 | /* Ignore current_now which is a snapshot of the current battery state | 276 | if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) { |
282 | * and is likely to be different even between two consecutive reads */ | ||
283 | if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) { | ||
284 | di->cache = cache; | 277 | di->cache = cache; |
285 | power_supply_changed(&di->bat); | 278 | power_supply_changed(&di->bat); |
286 | } | 279 | } |
@@ -330,12 +323,9 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di, | |||
330 | union power_supply_propval *val) | 323 | union power_supply_propval *val) |
331 | { | 324 | { |
332 | int curr; | 325 | int curr; |
326 | int flags; | ||
333 | 327 | ||
334 | if (di->chip == BQ27500) | 328 | curr = bq27x00_read(di, BQ27x00_REG_AI, false); |
335 | curr = bq27x00_read(di, BQ27x00_REG_AI, false); | ||
336 | else | ||
337 | curr = di->cache.current_now; | ||
338 | |||
339 | if (curr < 0) | 329 | if (curr < 0) |
340 | return curr; | 330 | return curr; |
341 | 331 | ||
@@ -343,7 +333,8 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di, | |||
343 | /* bq27500 returns signed value */ | 333 | /* bq27500 returns signed value */ |
344 | val->intval = (int)((s16)curr) * 1000; | 334 | val->intval = (int)((s16)curr) * 1000; |
345 | } else { | 335 | } else { |
346 | if (di->cache.flags & BQ27000_FLAG_CHGS) { | 336 | flags = bq27x00_read(di, BQ27x00_REG_FLAGS, false); |
337 | if (flags & BQ27000_FLAG_CHGS) { | ||
347 | dev_dbg(di->dev, "negative current!\n"); | 338 | dev_dbg(di->dev, "negative current!\n"); |
348 | curr = -curr; | 339 | curr = -curr; |
349 | } | 340 | } |