Messages in this thread Patch in this message | | | From | Pali Rohár <> | Subject | Re: [PATCH] bq27x00_battery: Fix reporting battery temperature | Date | Wed, 6 Feb 2013 18:56:34 +0100 |
| |
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@gmail.com> > > > > --- > > > > > > 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@gmail.com> 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@gmail.com> --- 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@gmail.com [unhandled content-type:application/pgp-signature] | |