Skip to contentSkip to conversation

lm75: Fix lm75a detection

PATCH In review Laurent Pinchart 2 participants 4 messages Apr 16, 2008 – Apr 18, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lm75: Fix lm75a detection

Philips LM75A temperature sensors don't pass the current detection check as they return 0xffff when reading unimplemented registers instead of the last read value. This patch modifies device detection to accept 0xffff as valid values when reading registers 0x04-0x07.

---
 drivers/hwmon/lm75.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
drivers/hwmon/lm75.c +13 -12
index 115f409..d7a22a5 100644
@@ -159,28 +159,29 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
 	/* Now, we do the remaining detection. There is no identification-
 	   dedicated register so we have to rely on several tricks:
 	   unused bits, registers cycling over 8-address boundaries,
-	   addresses 0x04-0x07 returning the last read value.
+	   addresses 0x04-0x07 returning the last read value (LM75) or
+	   0xffff (Philips LM75A).
 	   The cycling+unused addresses combination is not tested,
 	   since it would significantly slow the detection down and would
 	   hardly add any value. */
 	if (kind < 0) {
-		int cur, conf, hyst, os;
+		int cur, conf, hyst, os, na;
 
 		/* Unused addresses */
 		cur = i2c_smbus_read_word_data(new_client, 0);
 		conf = i2c_smbus_read_byte_data(new_client, 1);
 		hyst = i2c_smbus_read_word_data(new_client, 2);
-		if (i2c_smbus_read_word_data(new_client, 4) != hyst
-		 || i2c_smbus_read_word_data(new_client, 5) != hyst
-		 || i2c_smbus_read_word_data(new_client, 6) != hyst
-		 || i2c_smbus_read_word_data(new_client, 7) != hyst)
-		 	goto exit_free;
+		for (i = 4; i < 8; ++i) {
+			na = i2c_smbus_read_word_data(new_client, i);
+			if (na != hyst && na != 0xffff)
+				goto exit_free;
+		}
 		os = i2c_smbus_read_word_data(new_client, 3);
-		if (i2c_smbus_read_word_data(new_client, 4) != os
-		 || i2c_smbus_read_word_data(new_client, 5) != os
-		 || i2c_smbus_read_word_data(new_client, 6) != os
-		 || i2c_smbus_read_word_data(new_client, 7) != os)
-		 	goto exit_free;
+		for (i = 4; i < 8; ++i) {
+			na = i2c_smbus_read_word_data(new_client, i);
+			if (na != os && na != 0xffff)
+				goto exit_free;
+		}
 
 		/* Unused bits */
 		if (conf & 0xe0)
Signature · 17 lines
1.5.0

-- 
Laurent Pinchart
CSE Semaphore Belgium

Chaussee de Bruxelles, 732A
B-1410 Waterloo
Belgium

T +32 (2) 387 42 59
F +32 (2) 387 42 75

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

Hello Laurent,

Quoted 4 lines · Laurent Pinchart

Philips LM75A temperature sensors don't pass the current detection check as they return 0xffff when reading unimplemented registers instead of the last read value. This patch modifies device detection to accept 0xffff as valid values when reading registers 0x04-0x07.

In fact almost no LM75 clone mimics the original behavior perfectly so they all need to be forced with a module parameter at the moment. I have always been reluctant to update the detection code to support them all, as this would weaken it to a point where about any device at any of the 8 supported I2C addresses would be picked.

May I ask on which system you have the Philips LM75A chip? If that's an embedded system where you will end up using the new-style lm75 driver, then I'd rather focus on getting this new-style driver ready, instead of updating the detection code.

I'm reviewing your patch still, in case we finally decide to apply it:

Quoted 11 lines
---
 drivers/hwmon/lm75.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
drivers/hwmon/lm75.c +0 -0
index 115f409..d7a22a5 100644

drivers/hwmon/lm75.c static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) · line 163

Quoted 6 lines
drivers/hwmon/lm75.c +2 -1
@@ -159,28 +159,29 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
 	/* Now, we do the remaining detection. There is no identification-
 	   dedicated register so we have to rely on several tricks:
 	   unused bits, registers cycling over 8-address boundaries,
-	   addresses 0x04-0x07 returning the last read value.
+	   addresses 0x04-0x07 returning the last read value (LM75) or
+	   0xffff (Philips LM75A).

Does the chip really return 0xffff or is the SMBus read returning an error which in turn is converted to 0xffff? i2cdump w should tell.

Quoted 11 lines
drivers/hwmon/lm75.c +1 -1
 	   The cycling+unused addresses combination is not tested,
 	   since it would significantly slow the detection down and would
 	   hardly add any value. */
 	if (kind < 0) {
-		int cur, conf, hyst, os;
+		int cur, conf, hyst, os, na;
 
 		/* Unused addresses */
 		cur = i2c_smbus_read_word_data(new_client, 0);
 		conf = i2c_smbus_read_byte_data(new_client, 1);
 		hyst = i2c_smbus_read_word_data(new_client, 2);

drivers/hwmon/lm75.c static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) · line 178

Quoted 10 lines
drivers/hwmon/lm75.c +5 -5
-		if (i2c_smbus_read_word_data(new_client, 4) != hyst
-		 || i2c_smbus_read_word_data(new_client, 5) != hyst
-		 || i2c_smbus_read_word_data(new_client, 6) != hyst
-		 || i2c_smbus_read_word_data(new_client, 7) != hyst)
-		 	goto exit_free;
+		for (i = 4; i < 8; ++i) {
+			na = i2c_smbus_read_word_data(new_client, i);
+			if (na != hyst && na != 0xffff)
+				goto exit_free;
+		}

This will accept all combinations of hyst and 0xffff, while ideally only "all hyst" or "all 0xffff" should be accepted, for more robustness.

drivers/hwmon/lm75.c static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) · line 184

Quoted 11 lines
drivers/hwmon/lm75.c +5 -5
 		os = i2c_smbus_read_word_data(new_client, 3);
-		if (i2c_smbus_read_word_data(new_client, 4) != os
-		 || i2c_smbus_read_word_data(new_client, 5) != os
-		 || i2c_smbus_read_word_data(new_client, 6) != os
-		 || i2c_smbus_read_word_data(new_client, 7) != os)
-		 	goto exit_free;
+		for (i = 4; i < 8; ++i) {
+			na = i2c_smbus_read_word_data(new_client, i);
+			if (na != os && na != 0xffff)
+				goto exit_free;
+		}

Note that this second loop only makes sense if the hyst value was returned in the first loop. If 0xffff was returned then the second loop will certainly return 0xffff again so there's no point in testing it again.

Quoted 3 lines
drivers/hwmon/lm75.c +0 -0
 		/* Unused bits */
 		if (conf & 0xe0)
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 Laurent Pinchart

Hi Jean,

Quoted 14 lines · Jean Delvare

Hello Laurent,

Quoted 4 lines · Laurent Pinchart

Philips LM75A temperature sensors don't pass the current detection check as they return 0xffff when reading unimplemented registers instead of the last read value. This patch modifies device detection to accept 0xffff as valid values when reading registers 0x04-0x07.

In fact almost no LM75 clone mimics the original behavior perfectly so they all need to be forced with a module parameter at the moment. I have always been reluctant to update the detection code to support them all, as this would weaken it to a point where about any device at any of the 8 supported I2C addresses would be picked.

Quoted 4 lines

May I ask on which system you have the Philips LM75A chip? If that's an embedded system where you will end up using the new-style lm75 driver, then I'd rather focus on getting this new-style driver ready, instead of updating the detection code.

This is indeed an embedded system. I'm fine with focussing on getting the new-style driver ready.

Do you have more comments on David's patches ? He mentionned receiving no feedback on his smbalert# patch.

Best regards,

Signature · 9 lines
Laurent Pinchart
CSE Semaphore Belgium

Chaussee de Bruxelles, 732A
B-1410 Waterloo
Belgium

T +32 (2) 387 42 59
F +32 (2) 387 42 75

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

#3 lore raw
In reply to Laurent Pinchart
Quoted 22 lines · Laurent Pinchart

Hi Jean,

Quoted 14 lines · Jean Delvare

Hello Laurent,

Quoted 4 lines · Laurent Pinchart

Philips LM75A temperature sensors don't pass the current detection check as they return 0xffff when reading unimplemented registers instead of the last read value. This patch modifies device detection to accept 0xffff as valid values when reading registers 0x04-0x07.

In fact almost no LM75 clone mimics the original behavior perfectly so they all need to be forced with a module parameter at the moment. I have always been reluctant to update the detection code to support them all, as this would weaken it to a point where about any device at any of the 8 supported I2C addresses would be picked.

Quoted 4 lines

May I ask on which system you have the Philips LM75A chip? If that's an embedded system where you will end up using the new-style lm75 driver, then I'd rather focus on getting this new-style driver ready, instead of updating the detection code.

Quoted 5 lines

This is indeed an embedded system. I'm fine with focussing on getting the new-style driver ready.

Do you have more comments on David's patches ? He mentionned receiving no feedback on his smbalert# patch.

I didn't look at the updated patchset David sent 2 days ago yet. But anyway, smbalert# support is unrelated to converting the lm75 driver to new-style. What should get reviewed and integrated quickly are the 2 first patches of the set. Please test them, and if you have time, please review them. I don't know when I will have the time for that.

Signature · 6 lines
Jean Delvare

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