]> Pileus Git - ~andy/linux/commitdiff
bq27x00_battery: Fix reporting battery temperature
authorPali Rohár <pali.rohar@gmail.com>
Sat, 2 Feb 2013 10:06:09 +0000 (11:06 +0100)
committerAnton Vorontsov <anton@enomsg.org>
Sun, 3 Feb 2013 03:44:08 +0000 (19:44 -0800)
Reported temperature can be also negative, so cache value in non negative
Kelvin degree.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
drivers/power/bq27x00_battery.c

index 7087d0d6a087bbb359535f076f5cf4649760202b..8ccf5d7d0add29c12c7830036b1881977ec3f188 100644 (file)
@@ -299,7 +299,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)
@@ -312,10 +312,8 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
                return temp;
        }
 
-       if (bq27xxx_is_chip_version_higher(di))
-               temp -= 2731;
-       else
-               temp = ((temp * 5) - 5463) / 2;
+       if (!bq27xxx_is_chip_version_higher(di))
+               temp = 5 * temp / 2;
 
        return temp;
 }
@@ -641,6 +639,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);