[lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature results
Jean Delvare
khali at linux-fr.org
Thu Jul 7 11:38:26 CEST 2011
On Tue, 5 Jul 2011 07:36:32 -0700, Guenter Roeck wrote:
> Negative temperatures were returned in degrees C instead of milli-Degrees C.
> Fix by multiplying with 1000.
>
> Signed-off-by: Guenter Roeck <guenter.roeck at ericsson.com>
> ---
> drivers/hwmon/lm95241.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
> index f2cfecf..d1bbdf8 100644
> --- a/drivers/hwmon/lm95241.c
> +++ b/drivers/hwmon/lm95241.c
> @@ -101,7 +101,7 @@ struct lm95241_data {
> static int TempFromReg(u8 val_h, u8 val_l)
> {
> if (val_h & 0x80)
> - return val_h - 0x100;
> + return (val_h - 0x100) * 1000;
> return val_h * 1000 + val_l * 1000 / 256;
> }
>
The fix is needed but is it sufficient? How comes that positive
temperatures would be returned with a sub-degree resolution and negative
ones with 1°C resolution only? I don't see any such limitation in the
datasheet.
Also, negative values are really only 2's complement format so a simple
cast should do (untested):
s16 val_hl = (val_h << 8) | val_l;
return val_hl * 1000 / 256;
--
Jean Delvare
More information about the lm-sensors
mailing list