]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
LM75 bug fix for negative temperatures
authorLarry Johnson <lrj@acm.org>
Thu, 21 Feb 2008 18:58:16 +0000 (13:58 -0500)
committerWolfgang Denk <wd@denx.de>
Fri, 22 Feb 2008 15:33:09 +0000 (16:33 +0100)
When the LM75 temperature sensor measures a temperature below 0 C, the
current driver does not perform sign extension, so the result returned is
256 C too high.  This patch fixes the problem.

Signed-off-by: Larry Johnson <lrj@acm.org>
drivers/hwmon/lm75.c

index 63f3b7551e9be6a73abe6dd2f8a24fadc04db293..e29b29440f237aa537321bc388abce9c86014822 100644 (file)
@@ -179,7 +179,13 @@ int dtt_init (void)
 
 int dtt_get_temp(int sensor)
 {
-    return (dtt_read(sensor, DTT_READ_TEMP) / 256);
+    int const ret = dtt_read(sensor, DTT_READ_TEMP);
+
+    if (ret < 0) {
+       printf("DTT temperature read failed.\n");
+       return 0;
+    }
+    return (int)((int16_t) ret / 256);
 } /* dtt_get_temp() */
 
 #endif /* CONFIG_DTT_LM75 */