Skip to contentSkip to conversation

hwmon: (adm1021) Strengthen chip detection for LM84 and MAX1617

PATCH Superseded Guenter Roeck 2 participants 6 messages Jun 5, 2013 – Jun 6, 2013 Hardware monitoring

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (adm1021) Strengthen chip detection for LM84 and MAX1617

On a system with both MAX1617A and JC42 sensors, JC42 sensors can be misdetected as LM84. Strengthen detection sufficiently enough to avoid this misdetection at least in some cases. Code follows example in sensors-detect script.

---
Still pretty weak detection. Any suggestions for improvements are welcome.

 drivers/hwmon/adm1021.c |   36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
drivers/hwmon/adm1021.c +29 -7
index 7e76922..8b342b8 100644
@@ -344,13 +344,35 @@ static int adm1021_detect(struct i2c_client *client,
 		type_name = "gl523sm";
 	else if (man_id = 0x54)
 		type_name = "mc1066";
-	/* LM84 Mfr ID in a different place, and it has more unused bits */
-	else if (conv_rate = 0x00
-		 && (config & 0x7F) = 0x00
-		 && (status & 0xAB) = 0x00)
-		type_name = "lm84";
-	else
-		type_name = "max1617";
+	else {
+		int lte, rte, lhi, rhi, llo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		lte = i2c_smbus_read_byte_data(client, 0x00);
+		rte = i2c_smbus_read_byte_data(client, 0x01);
+		lhi = i2c_smbus_read_byte_data(client, 0x05);
+		rhi = i2c_smbus_read_byte_data(client, 0x07);
+		llo = i2c_smbus_read_byte_data(client, 0x06);
+
+		if (lte = rte && lte = lhi && lte = rhi && lte = llo)
+			return -ENODEV;
+		if ((lte & 0x80) || (rte & 0x80) || (lhi & 0x80)
+		    || (rhi & 0x80))
+			return -ENODEV;
+
+		/*
+		 * LM84 Mfr ID is in a different place,
+		 * and it has more unused bits.
+		 */
+		if (conv_rate = 0x00
+		    && (config & 0x7F) = 0x00
+		    && (status & 0xAB) = 0x00) {
+			type_name = "lm84";
+		} else {
+			type_name = "max1617";
+		}
+	}
 
 	pr_debug("Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);
Signature · 7 lines
1.7.9.7


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

Hi Guenter,

Quoted 3 lines · Guenter Roeck

On a system with both MAX1617A and JC42 sensors, JC42 sensors can be misdetected as LM84. Strengthen detection sufficiently enough to avoid this misdetection at least in some cases. Code follows example in sensors-detect script.

Good idea.

Quoted 3 lines

---
Still pretty weak detection. Any suggestions for improvements are welcome.

As I was comparing the code in sensors-detect with the detection code in the adm1021 driver, I noticed another difference. In sensors-detect, the ADM1021 is identified with ($rev & 0xf0) = 0x00, while this check doesn't exist in adm1021_detect(). I think it should be added to avoid other false positives.

Detection of the MAX1617 is weak by nature, I don't think there's much
we can do about it. Even the extra checks you picked from
sensors-detect are only heuristics and could theoretically lead to
missed detections. But I think the only alternative is to drop
detection of these chips altogether - which I'd rather avoid. Missed detections can always be fixed

Quoted 19 lines
 drivers/hwmon/adm1021.c |   36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
drivers/hwmon/adm1021.c +0 -7
index 7e76922..8b342b8 100644
@@ -344,13 +344,35 @@ static int adm1021_detect(struct i2c_client *client,
 		type_name = "gl523sm";
 	else if (man_id = 0x54)
 		type_name = "mc1066";
-	/* LM84 Mfr ID in a different place, and it has more unused bits */
-	else if (conv_rate = 0x00
-		 && (config & 0x7F) = 0x00
-		 && (status & 0xAB) = 0x00)
-		type_name = "lm84";
-	else
-		type_name = "max1617";

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 356

Quoted 10 lines
drivers/hwmon/adm1021.c +10 -0
+	else {
+		int lte, rte, lhi, rhi, llo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		lte = i2c_smbus_read_byte_data(client, 0x00);
+		rte = i2c_smbus_read_byte_data(client, 0x01);
+		lhi = i2c_smbus_read_byte_data(client, 0x05);
+		rhi = i2c_smbus_read_byte_data(client, 0x07);
+		llo = i2c_smbus_read_byte_data(client, 0x06);

The sensors-detect code also reads rlo from 0x08, why don't you? I think we should have the exact same detection logic in sensors-detect and the adm1021 driver. If you are worried by performance then you can swap the order of the tests and check for negative temperatures first, that can be done one or two registers at a time.

Also these registers have a name in the adm1021 driver, you could use these names to improve code readability?

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 362

Quoted 6 lines
drivers/hwmon/adm1021.c +6 -0
+
+		if (lte = rte && lte = lhi && lte = rhi && lte = llo)
+			return -ENODEV;
+		if ((lte & 0x80) || (rte & 0x80) || (lhi & 0x80)
+		    || (rhi & 0x80))
+			return -ENODEV;

The sensors-detect code has nice comments explaining the tests, please include them here too.

You have omitted on set of tests: low limits over high limits. Is this on purpose? If you think this test is bad then it should be removed from sensors-detect. If not, please add it to adm1021_detect().

Quoted 6 lines
drivers/hwmon/adm1021.c +6 -0
+
+		/*
+		 * LM84 Mfr ID is in a different place,
+		 * and it has more unused bits.
+		 */
+		if (conv_rate = 0x00

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 378

Quoted 10 lines
drivers/hwmon/adm1021.c +7 -0
+		    && (config & 0x7F) = 0x00
+		    && (status & 0xAB) = 0x00) {
+			type_name = "lm84";
+		} else {
+			type_name = "max1617";
+		}
+	}
 
 	pr_debug("Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);

Last note: sensors-detect claims that these tests are missing from the adm1021 driver. As you are adding them now, that comment should be removed or updated.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#2 lore raw
In reply to Guenter Roeck

Hi Jean,

Quoted 9 lines · Jean Delvare

Hi Guenter,

Quoted 3 lines · Guenter Roeck

On a system with both MAX1617A and JC42 sensors, JC42 sensors can be misdetected as LM84. Strengthen detection sufficiently enough to avoid this misdetection at least in some cases. Code follows example in sensors-detect script.

Good idea.

Necessary. One of our systems hits that condition.

Quoted 10 lines
Quoted 3 lines

---
Still pretty weak detection. Any suggestions for improvements are welcome.

As I was comparing the code in sensors-detect with the detection code in the adm1021 driver, I noticed another difference. In sensors-detect, the ADM1021 is identified with ($rev & 0xf0) = 0x00, while this check doesn't exist in adm1021_detect(). I think it should be added to avoid other false positives.

I'll have another look and add it as well.

Quoted 6 lines

Detection of the MAX1617 is weak by nature, I don't think there's much
we can do about it. Even the extra checks you picked from
sensors-detect are only heuristics and could theoretically lead to
missed detections. But I think the only alternative is to drop
detection of these chips altogether - which I'd rather avoid. Missed detections can always be fixed

Yes, I agree. I requested samples for MAX1617 and LM84; once I get them I'll try to improve detection a bit more.

Quoted 27 lines
Quoted 27 lines
 drivers/hwmon/adm1021.c |   36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
drivers/hwmon/adm1021.c +8 -7
index 7e76922..8b342b8 100644
@@ -344,13 +344,35 @@ static int adm1021_detect(struct i2c_client *client,
 		type_name = "gl523sm";
 	else if (man_id = 0x54)
 		type_name = "mc1066";
-	/* LM84 Mfr ID in a different place, and it has more unused bits */
-	else if (conv_rate = 0x00
-		 && (config & 0x7F) = 0x00
-		 && (status & 0xAB) = 0x00)
-		type_name = "lm84";
-	else
-		type_name = "max1617";
+	else {
+		int lte, rte, lhi, rhi, llo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		lte = i2c_smbus_read_byte_data(client, 0x00);
+		rte = i2c_smbus_read_byte_data(client, 0x01);
+		lhi = i2c_smbus_read_byte_data(client, 0x05);
Quoted 9 lines

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 356

Quoted 2 lines
drivers/hwmon/adm1021.c +2 -0
+		rhi = i2c_smbus_read_byte_data(client, 0x07);
+		llo = i2c_smbus_read_byte_data(client, 0x06);

The sensors-detect code also reads rlo from 0x08, why don't you? I think we should have the exact same detection logic in sensors-detect and the adm1021 driver. If you are worried by performance then you can swap the order of the tests and check for negative temperatures first, that can be done one or two registers at a time.

More because I don't know what the LM84 returns when reading it, as it is a write-only register there. Any idea what LM84 returns ? Or I can wait until I get the samples.

Quoted 3 lines

Also these registers have a name in the adm1021 driver, you could use these names to improve code readability?

ok.

Quoted 10 lines

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 362

Quoted 6 lines
drivers/hwmon/adm1021.c +6 -0
+
+		if (lte = rte && lte = lhi && lte = rhi && lte = llo)
+			return -ENODEV;
+		if ((lte & 0x80) || (rte & 0x80) || (lhi & 0x80)
+		    || (rhi & 0x80))
+			return -ENODEV;

The sensors-detect code has nice comments explaining the tests, please include them here too.

ok.

Quoted 2 lines

You have omitted on set of tests: low limits over high limits. Is this on purpose? If you think this test is bad then it should be removed

Me being lazy.

Quoted 2 lines

from sensors-detect. If not, please add it to adm1021_detect().

Sure, can do.

Quoted 14 lines
Quoted 14 lines
drivers/hwmon/adm1021.c +13 -0
+
+		/*
+		 * LM84 Mfr ID is in a different place,
+		 * and it has more unused bits.
+		 */
+		if (conv_rate = 0x00
+		    && (config & 0x7F) = 0x00
+		    && (status & 0xAB) = 0x00) {
+			type_name = "lm84";
+		} else {
+			type_name = "max1617";
+		}
+	}
 
Quoted 7 lines

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 378

Quoted 2 lines
drivers/hwmon/adm1021.c +0 -0
 	pr_debug("Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);

Last note: sensors-detect claims that these tests are missing from the adm1021 driver. As you are adding them now, that comment should be removed or updated.

Makes sense. Will do once the tests are in.

Would it be useful to add word reads when checking LM84 and MAX1617 ? Those would help detecting chips with word size registers in the checked register locations.

Thanks,
Guenter

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

#3 lore raw
In reply to Guenter Roeck

Hi Guenter,

Quoted 9 lines · Guenter Roeck
Quoted 5 lines · Jean Delvare

Detection of the MAX1617 is weak by nature, I don't think there's much
we can do about it. Even the extra checks you picked from
sensors-detect are only heuristics and could theoretically lead to
missed detections. But I think the only alternative is to drop
detection of these chips altogether - which I'd rather avoid. Missed detections can always be fixed

Yes, I agree. I requested samples for MAX1617 and LM84; once I get them I'll try to improve detection a bit more.

I have just sent you two MAX1617 dumps. I don't have any for the LM84, unfortunately.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/hwmon/adm1021.c +8 -0
+	else {
+		int lte, rte, lhi, rhi, llo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		lte = i2c_smbus_read_byte_data(client, 0x00);
+		rte = i2c_smbus_read_byte_data(client, 0x01);
+		lhi = i2c_smbus_read_byte_data(client, 0x05);
Quoted 8 lines

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 356

Quoted 2 lines
drivers/hwmon/adm1021.c +2 -0
+		rhi = i2c_smbus_read_byte_data(client, 0x07);
+		llo = i2c_smbus_read_byte_data(client, 0x06);

The sensors-detect code also reads rlo from 0x08, why don't you? I think we should have the exact same detection logic in sensors-detect and the adm1021 driver. If you are worried by performance then you can swap the order of the tests and check for negative temperatures first, that can be done one or two registers at a time.

Quoted 3 lines

More because I don't know what the LM84 returns when reading it, as it is a write-only register there. Any idea what LM84 returns ? Or I can wait until I get the samples.

Write-only? The LM84 datasheet I have here says there is no register at 0x08 at all. It says the same for 0x06, BTW, which you are reading from nevertheless.

I have no idea what the LM84 returns for these, but as long as this doesn't crash the chip, this is irrelevant as far as detection is concerned. We read from these to find out if we have a reason to believe the chip being probed is _not_ an LM84 nor MAX1617.

Note that the LM84 also doesn't have registers at 0xFE and 0xFF, still the detection function reads from these, apparently without trouble.

As far as I can see the driver is unconditionally reading from registers 0x06 and 0x08 in adm1021_update_device() and exposing the temp1_min and temp2_min in sysfs. That would be a bug for the LM84, right?

Quoted 4 lines

(...)
Would it be useful to add word reads when checking LM84 and MAX1617 ? Those would help detecting chips with word size registers in the checked register locations.

I would avoid word reads, they can have nasty effects on some chips. And the chips supported by the adm1021 driver don't even need word reads so you have no guarantee that the underlying I2C/SMBUS controller driver supports that.

I don't think it would help anyway, as different chips will react differently to word reads, regardless of whether they are supposed to support them or not. Some will return twice the same byte, some will return the byte from the following register as the MSB, some will always return an MSB of 0 and some will simply fail, more or less gracefully. I can't see what kind of conclusion you would be able to draw.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#4 lore raw
In reply to Guenter Roeck

Hi Jean,

Quoted 10 lines · Jean Delvare

Hi Guenter,

Quoted 7 lines · Guenter Roeck
Quoted 5 lines · Jean Delvare

Detection of the MAX1617 is weak by nature, I don't think there's much
we can do about it. Even the extra checks you picked from
sensors-detect are only heuristics and could theoretically lead to
missed detections. But I think the only alternative is to drop
detection of these chips altogether - which I'd rather avoid. Missed detections can always be fixed

Quoted 6 lines
Quoted 2 lines

Yes, I agree. I requested samples for MAX1617 and LM84; once I get them I'll try to improve detection a bit more.

I have just sent you two MAX1617 dumps. I don't have any for the LM84, unfortunately.

Thanks, that helps.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

drivers/hwmon/adm1021.c static int adm1021_detect(struct i2c_client *client, · line 356

Quoted 10 lines
drivers/hwmon/adm1021.c +10 -0
+	else {
+		int lte, rte, lhi, rhi, llo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		lte = i2c_smbus_read_byte_data(client, 0x00);
+		rte = i2c_smbus_read_byte_data(client, 0x01);
+		lhi = i2c_smbus_read_byte_data(client, 0x05);
+		rhi = i2c_smbus_read_byte_data(client, 0x07);
+		llo = i2c_smbus_read_byte_data(client, 0x06);

The sensors-detect code also reads rlo from 0x08, why don't you? I think we should have the exact same detection logic in sensors-detect and the adm1021 driver. If you are worried by performance then you can swap the order of the tests and check for negative temperatures first, that can be done one or two registers at a time.

Quoted 8 lines
Quoted 3 lines

More because I don't know what the LM84 returns when reading it, as it is a write-only register there. Any idea what LM84 returns ? Or I can wait until I get the samples.

Write-only? The LM84 datasheet I have here says there is no register at 0x08 at all. It says the same for 0x06, BTW, which you are reading from nevertheless.

Me talking nonsense. That was register 0x09 and MAX1617. I need more sleep :(.

Quoted 8 lines

I have no idea what the LM84 returns for these, but as long as this doesn't crash the chip, this is irrelevant as far as detection is concerned. We read from these to find out if we have a reason to believe the chip being probed is _not_ an LM84 nor MAX1617.

Note that the LM84 also doesn't have registers at 0xFE and 0xFF, still the detection function reads from these, apparently without trouble.

We don't really check if the reads return an error, though.

Quoted 5 lines

As far as I can see the driver is unconditionally reading from registers 0x06 and 0x08 in adm1021_update_device() and exposing the temp1_min and temp2_min in sysfs. That would be a bug for the LM84, right?

Yes. Maybe I'll fix it after I get samples.

Quoted 10 lines
Quoted 4 lines

(...)
Would it be useful to add word reads when checking LM84 and MAX1617 ? Those would help detecting chips with word size registers in the checked register locations.

I would avoid word reads, they can have nasty effects on some chips. And the chips supported by the adm1021 driver don't even need word reads so you have no guarantee that the underlying I2C/SMBUS controller driver supports that.

Ok.

Would it be acceptable to check if reading 0xfe and 0xff return an error ? That would help weeding out some chips (the JC42 chips on our board return an error when reading register 0x08, for example).

Thanks,
Guenter

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

#5 lore raw
In reply to Guenter Roeck
Quoted 9 lines · Guenter Roeck
Quoted 2 lines · Jean Delvare

Note that the LM84 also doesn't have registers at 0xFE and 0xFF, still the detection function reads from these, apparently without trouble.

We don't really check if the reads return an error, though. (...)
Would it be acceptable to check if reading 0xfe and 0xff return an error ? That would help weeding out some chips (the JC42 chips on our board return an error when reading register 0x08, for example).

We should definitely check for error on all SMBus calls in the detect function.

Signature · 6 lines
Jean Delvare

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