Received: from eggs.gnu.org ([2001:4830:134:3::10]:51551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUjUP-0006v9-Tm for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUjUA-0006Hr-1a for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:29 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49326 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUjU9-0006HX-Rt for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:13 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 31 Mar 2014 23:10:59 +0200 Message-Id: <1396300262-10430-14-git-send-email-afaerber@suse.de> In-Reply-To: <1396300262-10430-1-git-send-email-afaerber@suse.de> References: <1396300262-10430-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Paolo Bonzini Right now, the temperature property must be written in milli-celsius, but it reads back the value in 8.8 fixed point. Fix this by letting the property read back the original value (possibly rounded). Also simplify the code that does the conversion. Before: (QEMU) qom-set path=3D/machine/peripheral/sensor property=3Dtemperatu= re value=3D20000 {u'return': {}} (QEMU) qom-get path=3Dsensor property=3Dtemperature {u'return': 5120} After: (QEMU) qom-set path=3D/machine/peripheral/sensor property=3Dtemperatu= re value=3D20000 {u'return': {}} (QEMU) qom-get path=3Dsensor property=3Dtemperature {u'return': 20000} Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- hw/misc/tmp105.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index 155e03d..63aa3d6 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -56,12 +56,14 @@ static void tmp105_get_temperature(Object *obj, Visit= or *v, void *opaque, const char *name, Error **errp) { TMP105State *s =3D TMP105(obj); - int64_t value =3D s->temperature; + int64_t value =3D s->temperature * 1000 / 256; =20 visit_type_int(v, &value, name, errp); } =20 -/* Units are 0.001 centigrades relative to 0 C. */ +/* Units are 0.001 centigrades relative to 0 C. s->temperature is 8.8 + * fixed point, so units are 1/256 centigrades. A simple ratio will do. + */ static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque= , const char *name, Error **errp) { @@ -78,7 +80,7 @@ static void tmp105_set_temperature(Object *obj, Visitor= *v, void *opaque, return; } =20 - s->temperature =3D ((int16_t) (temp * 0x800 / 128000)) << 4; + s->temperature =3D (int16_t) (temp * 256 / 1000); =20 tmp105_alarm_update(s); } --=20 1.8.4.5