Skip to content

Commit 942c1a9

Browse files
perdalenGuenter Roeck
authored andcommitted
hwmon: (max6642): Better chip detection schema
Improve detection of MAX6642 by reading non existing registers (0x04, 0x06 and 0xff). Reading those registers returns the previously read value. Signed-off-by: Per Dalen <per.dalen@appeartv.com> [guenter.roeck@ericsson.com: added second set of register reads] Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
1 parent bb9973e commit 942c1a9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/hwmon/max6642.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,29 @@ static int max6642_detect(struct i2c_client *client,
136136
if (man_id != 0x4D)
137137
return -ENODEV;
138138

139+
/* sanity check */
140+
if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D
141+
|| i2c_smbus_read_byte_data(client, 0x06) != 0x4D
142+
|| i2c_smbus_read_byte_data(client, 0xff) != 0x4D)
143+
return -ENODEV;
144+
139145
/*
140146
* We read the config and status register, the 4 lower bits in the
141147
* config register should be zero and bit 5, 3, 1 and 0 should be
142148
* zero in the status register.
143149
*/
144150
reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG);
151+
if ((reg_config & 0x0f) != 0x00)
152+
return -ENODEV;
153+
154+
/* in between, another round of sanity checks */
155+
if (i2c_smbus_read_byte_data(client, 0x04) != reg_config
156+
|| i2c_smbus_read_byte_data(client, 0x06) != reg_config
157+
|| i2c_smbus_read_byte_data(client, 0xff) != reg_config)
158+
return -ENODEV;
159+
145160
reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS);
146-
if (((reg_config & 0x0f) != 0x00) ||
147-
((reg_status & 0x2b) != 0x00))
161+
if ((reg_status & 0x2b) != 0x00)
148162
return -ENODEV;
149163

150164
strlcpy(info->type, "max6642", I2C_NAME_SIZE);

0 commit comments

Comments
 (0)