* [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature
@ 2011-07-05 14:36 Guenter Roeck
2011-07-07 9:38 ` Jean Delvare
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Guenter Roeck @ 2011-07-05 14:36 UTC (permalink / raw)
To: lm-sensors
Negative temperatures were returned in degrees C instead of milli-Degrees C.
Fix by multiplying with 1000.
Signed-off-by: Guenter Roeck <guenter.roeck@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;
}
--
1.7.3.1
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature
2011-07-05 14:36 [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature Guenter Roeck
@ 2011-07-07 9:38 ` Jean Delvare
2011-07-07 14:34 ` Guenter Roeck
2011-07-07 17:59 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Jean Delvare @ 2011-07-07 9:38 UTC (permalink / raw)
To: lm-sensors
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@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
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature
2011-07-05 14:36 [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature Guenter Roeck
2011-07-07 9:38 ` Jean Delvare
@ 2011-07-07 14:34 ` Guenter Roeck
2011-07-07 17:59 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2011-07-07 14:34 UTC (permalink / raw)
To: lm-sensors
On Thu, Jul 07, 2011 at 05:38:26AM -0400, Jean Delvare wrote:
> 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@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.
>
Saw that too late. Good question.
> 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;
>
Should be. I'll try to test it with the LM95231.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature
2011-07-05 14:36 [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature Guenter Roeck
2011-07-07 9:38 ` Jean Delvare
2011-07-07 14:34 ` Guenter Roeck
@ 2011-07-07 17:59 ` Guenter Roeck
2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2011-07-07 17:59 UTC (permalink / raw)
To: lm-sensors
On Thu, 2011-07-07 at 05:38 -0400, Jean Delvare wrote:
> 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@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;
>
Actually, it is getting more complicated than that. Like the LM95245,
the LM95241 supports both unsigned and signed temperature formats, and
the driver configures unsigned mode when loaded - meaning there are
actually no negative temperature values to report by default. I'll have
to change the code to take the chip configuration into account when
doing a conversion, similar to the LM95245 code.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-07 17:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-05 14:36 [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature Guenter Roeck
2011-07-07 9:38 ` Jean Delvare
2011-07-07 14:34 ` Guenter Roeck
2011-07-07 17:59 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.