From: Pali Rohár Date: Sat, 2 Feb 2013 10:06:09 +0000 (+0100) Subject: bq27x00_battery: Fix reporting battery temperature X-Git-Tag: sz_161~85 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff_plain;h=c0c62d30af220d2f44d908fd9a60108b727ec2aa bq27x00_battery: Fix reporting battery temperature Reported temperature can be also negative, so cache value in non negative Kelvin degree. Signed-off-by: Pali Rohár Signed-off-by: Anton Vorontsov Conflicts: drivers/power/bq27x00_battery.c --- diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index 97c7cdeb488e..17a7389802ad 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c @@ -253,7 +253,7 @@ static int bq27x00_battery_read_energy(struct bq27x00_device_info *di) } /* - * Return the battery temperature in tenths of degree Celsius + * Return the battery temperature in tenths of degree Kelvin * Or < 0 if something fails. */ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di) @@ -266,10 +266,8 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di) return temp; } - if (di->chip == BQ27500) - temp -= 2731; - else - temp = ((temp * 5) - 5463) / 2; + if (di->chip != BQ27500) + temp = 5 * temp / 2; return temp; } @@ -541,6 +539,8 @@ static int bq27x00_battery_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_TEMP: ret = bq27x00_simple_value(di->cache.temperature, val); + if (ret == 0) + val->intval -= 2731; break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: ret = bq27x00_simple_value(di->cache.time_to_empty, val);