All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: peter maydell <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, Alex Horn <alex.horn@cs.ox.ac.uk>
Subject: Re: [Qemu-devel] [PATCH] tmp105: read temperature in milli-celsius
Date: Mon, 17 Feb 2014 07:13:40 -0500 (EST)	[thread overview]
Message-ID: <1032488099.4610216.1392639220673.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <5301FBAB.6060705@suse.de>


> > @@ -78,7 +80,7 @@ static void tmp105_set_temperature(Object *obj, Visitor
> > *v, void *opaque,
> >          return;
> >      }
> >  
> > -    s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4;
> > +    s->temperature = (int16_t) (temp * 256 / 1000);
> 
> Did you check whether those magic 4 bits shift were for some other
> purpose such as flags possibly? CC'ing Alex Horn.

>From the data sheet, the temperature register is 9-12 bits, depending
on the configuration.  So the low 4 bits will always read back as zero.
However, they are already masked away when reading the temperature in
tmp105_read:

        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
                (0xf0 << ((~s->config >> 5) & 3));              /* R */

The equivalence of the formula can be proved as follows:

   ((int16_t) (temp * 0x800 / 128000)) << 4
          = (int16_t) (temp * 0x8000 / 128000) & ~15
          = (int16_t) (temp * (0x100 * 0x80) / (1000 * 0x80)) & ~15
          = (int16_t) (temp * 0x100 / 1000) & ~15

and the AND can be removed as mentioned above.

> Since we do have a tmp105-test, we should also add a regression test for
> the getter bug.

Yeah, if only tmp105-test already tested the setter. :)

Paolo

  reply	other threads:[~2014-02-17 12:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-17 10:57 [Qemu-devel] [PATCH] tmp105: read temperature in milli-celsius Paolo Bonzini
2014-02-17 12:08 ` Andreas Färber
2014-02-17 12:13   ` Paolo Bonzini [this message]
2014-03-24 10:09   ` Paolo Bonzini

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=1032488099.4610216.1392639220673.JavaMail.zimbra@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=alex.horn@cs.ox.ac.uk \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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.