From owner-svn-src-head@FreeBSD.ORG Tue Feb 17 20:08:41 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 81E1722B; Tue, 17 Feb 2015 20:08:41 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 537C9C6E; Tue, 17 Feb 2015 20:08:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1HK8fDQ007978; Tue, 17 Feb 2015 20:08:41 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1HK8fP4007977; Tue, 17 Feb 2015 20:08:41 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201502172008.t1HK8fP4007977@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Tue, 17 Feb 2015 20:08:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278917 - head/sys/dev/iicbus X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Feb 2015 20:08:41 -0000 Author: loos Date: Tue Feb 17 20:08:40 2015 New Revision: 278917 URL: https://svnweb.freebsd.org/changeset/base/278917 Log: Fix the display of negative temperatures. Fix the setting of TOS (overtemperature shutdown) and THYST (hysteresis temperature). Modified: head/sys/dev/iicbus/lm75.c Modified: head/sys/dev/iicbus/lm75.c ============================================================================== --- head/sys/dev/iicbus/lm75.c Tue Feb 17 19:53:41 2015 (r278916) +++ head/sys/dev/iicbus/lm75.c Tue Feb 17 20:08:40 2015 (r278917) @@ -51,6 +51,8 @@ __FBSDID("$FreeBSD$"); /* LM75 registers. */ #define LM75_TEMP 0x0 +#define LM75_TEMP_MASK 0xff80 +#define LM75A_TEMP_MASK 0xffe0 #define LM75_CONF 0x1 #define LM75_CONF_FSHIFT 3 #define LM75_CONF_FAULT 0x18 @@ -331,20 +333,24 @@ lm75_temp_read(struct lm75_softc *sc, ui { uint8_t buf8[2]; uint16_t buf; - int t; + int neg, t; if (lm75_read(sc->sc_dev, sc->sc_addr, reg, buf8, 2) < 0) return (-1); - - buf = (buf8[0] << 8) | (buf8[1] & 0xff); - + buf = (uint16_t)((buf8[0] << 8) | (buf8[1] & 0xff)); /* * LM75 has a 9 bit ADC with resolution of 0.5 C per bit. * LM75A has an 11 bit ADC with resolution of 0.125 C per bit. * Temperature is stored with two's complement. */ - if (buf & LM75_NEG_BIT) - buf = ~buf + 1; + neg = 0; + if (buf & LM75_NEG_BIT) { + if (sc->sc_hwtype == HWTYPE_LM75A) + buf = ~(buf & LM75A_TEMP_MASK) + 1; + else + buf = ~(buf & LM75_TEMP_MASK) + 1; + neg = 1; + } *temp = ((int16_t)buf >> 8) * 10; t = 0; if (sc->sc_hwtype == HWTYPE_LM75A) { @@ -357,7 +363,7 @@ lm75_temp_read(struct lm75_softc *sc, ui t += 500; t /= 100; *temp += t; - if (buf & LM75_NEG_BIT) + if (neg) *temp = -(*temp); *temp += TZ_ZEROC; @@ -370,6 +376,7 @@ lm75_temp_write(struct lm75_softc *sc, u uint8_t buf8[3]; uint16_t buf; + temp = (temp - TZ_ZEROC) / 10; if (temp > LM75_MAX_TEMP) temp = LM75_MAX_TEMP; if (temp < LM75_MIN_TEMP)