aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/bq27x00_battery.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2011-10-31 20:43:07 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2011-11-25 14:59:38 -0500
commitd149e98e02c84fe1e81aa7f6b91a667d796b2c6e (patch)
tree67be8d86b75f02a7191ba7ec4eec70e356bf221a /drivers/power/bq27x00_battery.c
parenta8f6bd23cc73a54b9182cf8be102739e01ea874a (diff)
bq27x00_battery: Cache temperature value in converted unit
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.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index e9aeb533a1f0..a22124ab1e3b 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -248,6 +248,28 @@ static int bq27x00_battery_read_energy(struct bq27x00_device_info *di)
248} 248}
249 249
250/* 250/*
251 * Return the battery temperature in tenths of degree Celsius
252 * Or < 0 if something fails.
253 */
254static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
255{
256 int temp;
257
258 temp = bq27x00_read(di, BQ27x00_REG_TEMP, false);
259 if (temp < 0) {
260 dev_err(di->dev, "error reading temperature\n");
261 return temp;
262 }
263
264 if (di->chip == BQ27500)
265 temp -= 2731;
266 else
267 temp = ((temp * 5) - 5463) / 2;
268
269 return temp;
270}
271
272/*
251 * Return the battery Cycle count total 273 * Return the battery Cycle count total
252 * Or < 0 if something fails. 274 * Or < 0 if something fails.
253 */ 275 */
@@ -304,7 +326,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
304 cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF); 326 cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
305 cache.charge_full = bq27x00_battery_read_lmd(di); 327 cache.charge_full = bq27x00_battery_read_lmd(di);
306 } 328 }
307 cache.temperature = bq27x00_read(di, BQ27x00_REG_TEMP, false); 329 cache.temperature = bq27x00_battery_read_temperature(di);
308 cache.cycle_count = bq27x00_battery_read_cyct(di); 330 cache.cycle_count = bq27x00_battery_read_cyct(di);
309 331
310 /* We only have to read charge design full once */ 332 /* We only have to read charge design full once */
@@ -334,25 +356,6 @@ static void bq27x00_battery_poll(struct work_struct *work)
334 } 356 }
335} 357}
336 358
337
338/*
339 * Return the battery temperature in tenths of degree Celsius
340 * Or < 0 if something fails.
341 */
342static int bq27x00_battery_temperature(struct bq27x00_device_info *di,
343 union power_supply_propval *val)
344{
345 if (di->cache.temperature < 0)
346 return di->cache.temperature;
347
348 if (di->chip == BQ27500)
349 val->intval = di->cache.temperature - 2731;
350 else
351 val->intval = ((di->cache.temperature * 5) - 5463) / 2;
352
353 return 0;
354}
355
356/* 359/*
357 * Return the battery average current in µA 360 * Return the battery average current in µA
358 * Note that current can be negative signed as well 361 * Note that current can be negative signed as well
@@ -511,7 +514,7 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
511 ret = bq27x00_battery_capacity_level(di, val); 514 ret = bq27x00_battery_capacity_level(di, val);
512 break; 515 break;
513 case POWER_SUPPLY_PROP_TEMP: 516 case POWER_SUPPLY_PROP_TEMP:
514 ret = bq27x00_battery_temperature(di, val); 517 ret = bq27x00_simple_value(di->cache.temperature, val);
515 break; 518 break;
516 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: 519 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
517 ret = bq27x00_simple_value(di->cache.time_to_empty, val); 520 ret = bq27x00_simple_value(di->cache.time_to_empty, val);