All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <guenter.roeck@ericsson.com>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] hwmon: (lm95241) Fix negative temperature
Date: Thu, 07 Jul 2011 14:34:12 +0000	[thread overview]
Message-ID: <20110707143412.GA11236@ericsson.com> (raw)
In-Reply-To: <1309876592-24015-1-git-send-email-guenter.roeck@ericsson.com>

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

  parent reply	other threads:[~2011-07-07 14:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-07-07 17:59 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110707143412.GA11236@ericsson.com \
    --to=guenter.roeck@ericsson.com \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.