Re: [PATCH] bq27x00_battery: Fix reporting battery temperature

From: Pali RohÃr
Date: Wed Feb 06 2013 - 12:56:48 EST


On Sunday 03 February 2013 21:05:57 Anton Vorontsov wrote:
> On Sun, Feb 03, 2013 at 09:01:54PM +0100, Pali RohÃr wrote:
> > On Sunday 03 February 2013 04:44:51 Anton Vorontsov wrote:
> > > On Sat, Feb 02, 2013 at 11:06:09AM +0100, Pali RohÃr wrote:
> > > > Reported temperature can be also negative, so cache
> > > > value in non negative Kelvin degree.
> > > >
> > > > Signed-off-by: Pali RohÃr <pali.rohar@xxxxxxxxx>
> > > > ---
> > >
> > > Applied, thanks!
> >
> > Now I looked at bq27x00_battery and rx51_battery drivers and
> > I see that both drivers reporting temperature in different
> > units. bq27x00_battery in 1/10 ÂC and rx51_battery in 1/100
> > ÂC. What is correct degree for kernel power power supply
> > API? Maybe other kernel drivers have different units too...
> > Note that my above patch did not changed anything units,
> > only fixed reporting (possible) negative temperature.
>
> Per Documentation/power/power_supply_class.txt and
> power_supply.h:
>
> /*
> * All voltages, currents, charges, energies, time and
> temperatures in uV, * ÂA, ÂAh, ÂWh, seconds and tenths of
> degree Celsius unless otherwise * stated. It's driver's job
> to convert its raw values to units in which * this class
> operates.
> */
>
> Feel free to fix the offending drivers.
>
> Thanks,
>
> Anton

Ok, here is small patch which fixing it in bq27x00_battery driver.
Tested on Nokia N900 with patched 3.8-rc3 kernel.
bq27x00_battery reporting "POWER_SUPPLY_TEMP=2700"
and rx51_battery reporting "POWER_SUPPLY_TEMP=3590"

From 43a99615d6d7375770736303f1e000f3d85d75cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@xxxxxxxxx>
Date: Sun, 3 Feb 2013 22:06:20 +0100
Subject: [PATCH] bq27x00_battery: Report temperature in 1/100 degree Celsius
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Documentation/power/power_supply_class.txt say that temperature must be reported in tenths of degree
Celsius

Signed-off-by: Pali RohÃr <pali.rohar@xxxxxxxxx>
---
drivers/power/bq27x00_battery.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 5b077af..482755f 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -312,8 +312,10 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
return temp;
}

- if (!bq27xxx_is_chip_version_higher(di))
- temp = 5 * temp / 2;
+ if (bq27xxx_is_chip_version_higher(di))
+ temp *= 10;
+ else
+ temp *= 25;

return temp;
}
@@ -640,7 +642,7 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_TEMP:
ret = bq27x00_simple_value(di->cache.temperature, val);
if (ret == 0)
- val->intval -= 2731;
+ val->intval -= 27310;
break;
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
ret = bq27x00_simple_value(di->cache.time_to_empty, val);
--
1.7.10.4

--
Pali RohÃr
pali.rohar@xxxxxxxxx

Attachment: signature.asc
Description: This is a digitally signed message part.