Skip to contentSkip to conversation

hwmon: (lm95241) Fix negative temperature

PATCH Superseded Guenter Roeck 2 participants 4 messages Jul 5, 2011 – Jul 7, 2011 Hardware monitoring

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (lm95241) Fix negative temperature

Negative temperatures were returned in degrees C instead of milli-Degrees C. Fix by multiplying with 1000.

---
 drivers/hwmon/lm95241.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hwmon/lm95241.c +1 -1
index f2cfecf..d1bbdf8 100644
@@ -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;
 }
 
Signature · 7 lines
1.7.3.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 13 lines · Guenter Roeck

Negative temperatures were returned in degrees C instead of milli-Degrees C. Fix by multiplying with 1000.

---
 drivers/hwmon/lm95241.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hwmon/lm95241.c +0 -0
index f2cfecf..d1bbdf8 100644

drivers/hwmon/lm95241.c struct lm95241_data { · line 107

Quoted 8 lines
drivers/hwmon/lm95241.c +1 -1
@@ -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.

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;
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Guenter Roeck
Quoted 19 lines · Jean Delvare
Quoted 18 lines · Guenter Roeck

Negative temperatures were returned in degrees C instead of milli-Degrees C. Fix by multiplying with 1000.

---
 drivers/hwmon/lm95241.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hwmon/lm95241.c +1 -1
index f2cfecf..d1bbdf8 100644
@@ -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;
Quoted 9 lines

drivers/hwmon/lm95241.c struct lm95241_data { · line 107

Quoted 3 lines
drivers/hwmon/lm95241.c +0 -0
 	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.

Quoted 6 lines

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
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Guenter Roeck
Quoted 28 lines · Jean Delvare
Quoted 13 lines · Guenter Roeck

Negative temperatures were returned in degrees C instead of milli-Degrees C. Fix by multiplying with 1000.

---
 drivers/hwmon/lm95241.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hwmon/lm95241.c +0 -0
index f2cfecf..d1bbdf8 100644

drivers/hwmon/lm95241.c struct lm95241_data { · line 107

Quoted 8 lines
drivers/hwmon/lm95241.c +1 -1
@@ -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.

Quoted 6 lines

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;

Actually, it is getting more complicated than that. Like the LM95245, the LM95241 supports both unsigned and signed temperature formats, and the driver configures unsigned mode when loaded - meaning there are actually no negative temperature values to report by default. I'll have to change the code to take the chip configuration into account when doing a conversion, similar to the LM95245 code.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors