Skip to contentSkip to conversation

MAX6642 chip detection and other stuff

lm-sensors Applied Guenter Roeck 3 participants 9 messages May 28, 2011 – Jun 4, 2011 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

Hi all,

I finally got MAX6642 samples, so I am able to play around with the chip.

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

While testing the chip, I found another little problem: the fault attribute is named temp_fault. That will have to be renamed to temp2_fault, first because it reflects a fault with the external diode and second to match the ABI. We will need a separate patch to fix this problem.

Here is the output of i2cdump for the MAX6642 (with open/unconnected external sensor).

root@groeck-desktop:/home/groeck# i2cdump -y 5 0x48
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 18 ff 84 10 10 46 46 78 78 78 78 78 78 78 78 78    ?.???FFxxxxxxxxx
10: c0 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    ?@@@@@@@@@@@@@@@
20: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
30: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
40: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
50: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
60: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
70: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
80: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
90: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
a0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
b0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
c0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
d0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
e0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
f0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 4d 4d    @@@@@@@@@@@@@@MM
root@groeck-desktop:/home/groeck# modprobe max6642
root@groeck-desktop:/home/groeck# sensors
max6642-i2c-5-48
Adapter: i2c-devantech-iss at bus 001 device 007
temp1:        +24.0°C  (high = +70.0°C)
temp2:          FAULT  (high = +120.0°C)

Thanks,
Guenter

From 197b9b4fb23c372de6d08afad4a0ebd72cfaadc6 Mon Sep 17 00:00:00 2001
From: Guenter Roeck <[email protected]>
Date: Fri, 27 May 2011 21:39:59 -0700
Subject: [PATCH] hwmon: (max6642) Improve chip detection

---
 drivers/hwmon/max6642.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)
drivers/hwmon/max6642.c +18 -17
index 872155e..160853c 100644
@@ -64,14 +64,6 @@ static const unsigned short normal_i2c[] = {
 #define MAX6642_REG_W_REMOTE_HIGH	0x0D
 
 /*
- * Registers for detection tests. These registers are not present and,
- * when read, will only return the last valid register read.
- */
-#define MAX6642_REG_R_DUMMY_1          0x04
-#define MAX6642_REG_R_DUMMY_2          0x06
-#define MAX6642_REG_R_DUMMY_3          0xFF
-
-/*
  * Conversions
  */
 
@@ -134,7 +126,7 @@ static int max6642_detect(struct i2c_client *client,
 			  struct i2c_board_info *info)
 {
 	struct i2c_adapter *adapter = client->adapter;
-	u8 reg_config, reg_status, man_id, dummy_reg;
+	u8 reg_config, reg_status, man_id;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -ENODEV;
@@ -145,16 +137,13 @@ static int max6642_detect(struct i2c_client *client,
 		return -ENODEV;
 
 	/* sanity check */
-	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_1);
-	if (dummy_reg != 0x4D)
+	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D)
 		return -ENODEV;
 
-	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_2);
-	if (dummy_reg != 0x4D)
+	if (i2c_smbus_read_byte_data(client, 0x06) != 0x4D)
 		return -ENODEV;
 
-	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_3);
-	if (dummy_reg != 0x4D)
+	if (i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
 		return -ENODEV;
 
 	/*
@@ -163,9 +152,21 @@ static int max6642_detect(struct i2c_client *client,
 	 * zero in the status register.
 	 */
 	reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG);
+	if ((reg_config & 0x0f) != 0x00)
+		return -ENODEV;
+
+	/* in between, another round of sanity checks */
+	if (i2c_smbus_read_byte_data(client, 0x04) != reg_config)
+		return -ENODEV;
+
+	if (i2c_smbus_read_byte_data(client, 0x06) != reg_config)
+		return -ENODEV;
+
+	if (i2c_smbus_read_byte_data(client, 0xff) != reg_config)
+		return -ENODEV;
+
 	reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS);
-	if (((reg_config & 0x0f) != 0x00) ||
-	    ((reg_status & 0x2b) != 0x00))
+	if ((reg_status & 0x2b) != 0x00)
 		return -ENODEV;
 
 	strlcpy(info->type, "max6642", I2C_NAME_SIZE);
Signature · 1 line
1.7.3.1

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

#1 lore raw

Hi Guenter,

Quoted 2 lines · Guenter Roeck

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

Looks good, pretty much what I had in mind. But I think you could make the code even more compact:

	/* sanity check */
	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
		return -ENODEV;
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

Hi Jean,

Quoted 6 lines · Jean Delvare

Hi Guenter,

Quoted 2 lines · Guenter Roeck

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

Quoted 9 lines

Looks good, pretty much what I had in mind. But I think you could make the code even more compact:

	/* sanity check */
	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
		return -ENODEV;

Yes, you are right. I didn't do it to avoid a checkpatch warning, but forgot that I don't use a variable anymore.

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 and Jean,

Sorry for the delay. Much stuff at work...
Here's (Jean's ;) patch.

BR
Per

Quoted 18 lines · Guenter Roeck

Hi Jean,

Quoted 6 lines · Jean Delvare

Hi Guenter,

Quoted 2 lines · Guenter Roeck

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

Quoted 9 lines

Looks good, pretty much what I had in mind. But I think you could make the code even more compact:

	/* sanity check */
	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
		return -ENODEV;
Quoted 4 lines

Yes, you are right. I didn't do it to avoid a checkpatch warning, but forgot that I don't use a variable anymore.

Guenter

Improve the detection of MAX6642 by reading non exciting registers (0x04, 0x06 and 0xff). The value of those registers should be the same as the last valid resister read.

---

drivers/hwmon/max6642.c +6 -0
index 0f9fc40..4fb0564 100644
@@ -136,6 +136,12 @@ static int max6642_detect(struct i2c_client *client,
 	if (man_id != 0x4D)
 		return -ENODEV;
 
+	/* sanity check */
+	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
+	    || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
+	    || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
+		return -ENODEV;
+
 	/*
 	 * We read the config and status register, the 4 lower bits in the
 	 * config register should be zero and bit 5, 3, 1 and 0 should be

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

#4 lore raw
In reply to Guenter Roeck

Hi,

Thanks for finding this error. I have attached the patch you requested.

BR
Per

Quoted 40 lines · Guenter Roeck

Hi all,

I finally got MAX6642 samples, so I am able to play around with the chip.

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

While testing the chip, I found another little problem: the fault attribute is named temp_fault. That will have to be renamed to temp2_fault, first because it reflects a fault with the external diode and second to match the ABI. We will need a separate patch to fix this problem.

Here is the output of i2cdump for the MAX6642 (with open/unconnected external sensor).

root@groeck-desktop:/home/groeck# i2cdump -y 5 0x48
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 18 ff 84 10 10 46 46 78 78 78 78 78 78 78 78 78    ?.???FFxxxxxxxxx
10: c0 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    ?@@@@@@@@@@@@@@@
20: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
30: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
40: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
50: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
60: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
70: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
80: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
90: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
a0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
b0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
c0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
d0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
e0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40    @@@@@@@@@@@@@@@@
f0: 40 40 40 40 40 40 40 40 40 40 40 40 40 40 4d 4d    @@@@@@@@@@@@@@MM
root@groeck-desktop:/home/groeck# modprobe max6642
root@groeck-desktop:/home/groeck# sensors
max6642-i2c-5-48
Adapter: i2c-devantech-iss at bus 001 device 007
temp1:        +24.0°C  (high = +70.0°C)
temp2:          FAULT  (high = +120.0°C)
Quoted 2 lines

Thanks,
Guenter

BUG: The temp_fault is wrong, it should be temp2_fault insteedd. 

Guenter: "While testing the chip, I found another little problem: the fault attribute is named temp_fault. That will have to be renamed to temp2_fault, first because it reflects a fault with the external diode and second to match the ABI." Thanks Guenter for finding the bug.

---

drivers/hwmon/max6642.c +2 -2
index 0f9fc40..0f30e1b 100644
@@ -246,7 +246,7 @@ static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
 			    set_temp_max, 0, MAX6642_REG_W_LOCAL_HIGH);
 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
 			    set_temp_max, 1, MAX6642_REG_W_REMOTE_HIGH);
-static SENSOR_DEVICE_ATTR(temp_fault, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
 
@@ -256,7 +256,7 @@ static struct attribute *max6642_attributes[] = {
 	&sensor_dev_attr_temp1_max.dev_attr.attr,
 	&sensor_dev_attr_temp2_max.dev_attr.attr,
 
-	&sensor_dev_attr_temp_fault.dev_attr.attr,
+	&sensor_dev_attr_temp2_fault.dev_attr.attr,
 	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
 	&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
 	NULL

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

#6 lore raw
In reply to Guenter Roeck

Hi Per,

Quoted 8 lines · Per Dalén

Hi Guenter and Jean,

Sorry for the delay. Much stuff at work...
Here's (Jean's ;) patch.

BR
Per

[ ... ]

Quoted 11 lines

Improve the detection of MAX6642 by reading non exciting registers (0x04, 0x06 and 0xff). The value of those registers should be the same as the last valid resister read.

---

drivers/hwmon/max6642.c +0 -0
index 0f9fc40..4fb0564 100644
@@ -136,6 +136,12 @@ static int max6642_detect(struct i2c_client *client,
 	if (man_id != 0x4D)
 		return -ENODEV;

drivers/hwmon/max6642.c static int max6642_detect(struct i2c_client *client, · line 147

Quoted 10 lines
drivers/hwmon/max6642.c +6 -0
 
+	/* sanity check */
+	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
+	    || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
+	    || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
+		return -ENODEV;
+
 	/*
 	 * We read the config and status register, the 4 lower bits in the
 	 * config register should be zero and bit 5, 3, 1 and 0 should be

Looks good, only the second part of my suggested changes got lost.

        reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG);

+ if ((reg_config & 0x0f) != 0x00)
+ return -ENODEV;
+
+ /* in between, another round of sanity checks */
+ if (i2c_smbus_read_byte_data(client, 0x04) != reg_config

+	    || i2c_smbus_read_byte_data(client, 0x06) != reg_config
+	    || i2c_smbus_read_byte_data(client, 0xff) != reg_config)

+ return -ENODEV;
+

Please add those, and we should be ready to go.

Thanks,
Guenter

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

#8 lore raw
In reply to Guenter Roeck

Hi Per,

Quoted 30 lines · Per Dalén

Hi Guenter and Jean,

Sorry for the delay. Much stuff at work...
Here's (Jean's ;) patch.

BR
Per

Quoted 21 lines · Guenter Roeck

Hi Jean,

Quoted 6 lines · Jean Delvare

Hi Guenter,

Quoted 2 lines · Guenter Roeck

The attached patch (on top of Per's most recent patch) works quite nicely. Per, maybe you can just merge it with your patch and resubmit it.

Quoted 9 lines

Looks good, pretty much what I had in mind. But I think you could make the code even more compact:

	/* sanity check */
	if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0x06) != 0x4D
	 || i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
		return -ENODEV;

Yes, you are right. I didn't do it to avoid a checkpatch warning, but forgot that I don't use a variable anymore.

Quoted 6 lines
Quoted 1 line

Guenter

Improve the detection of MAX6642 by reading non exciting registers (0x04, 0x06 and 0xff). The value of those registers should be the same as the last valid resister read.

I want to send this off to Linus with my next set of patches, so I added the second set of checks myself. No need to resubmit.

Thanks,
Guenter

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