summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer Dalén <per.dalen@appeartv.com>2011-05-26 09:08:53 -0400
committerGuenter Roeck <guenter.roeck@ericsson.com>2011-06-04 10:34:28 -0700
commit942c1a927bf296fd64fd49f04c5a8f66bb14446b (patch)
tree58020f9137fd23755a918eca1ad0621109123a80
parentbb9973e4e73f43bd86698483d0c3f7a362ff94ce (diff)
downloadlinux-942c1a927bf296fd64fd49f04c5a8f66bb14446b.tar.bz2
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>
-rw-r--r--drivers/hwmon/max6642.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
index 0f30e1bb366f..e855d3b0bd1f 100644
--- a/drivers/hwmon/max6642.c
+++ b/drivers/hwmon/max6642.c
@@ -136,15 +136,29 @@ 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
* 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
+ || i2c_smbus_read_byte_data(client, 0x06) != reg_config
+ || 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);