diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-11-04 07:00:46 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-11-04 07:00:46 -0400 |
commit | 24d6e2a89a1ff0a035f163a83a2812a3192083b6 (patch) | |
tree | 9cd9206f65ae126d78ab428272ee8da62e41c4a8 /drivers/hwmon | |
parent | 746cdfbf01c0a30d59f6e1b6942d432658d7c7cd (diff) |
hwmon: (lm73) Make detection less problematic
Word reads can cause trouble with some I2C devices, so do as much
detection as we can using only byte reads, and only use a word read in
the end to confirm the positive match. Also properly handle read
errors.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Robert Casanova <robertcasanova@nanometrics.ca>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm73.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c index 29b9030d42c..24be17608fb 100644 --- a/drivers/hwmon/lm73.c +++ b/drivers/hwmon/lm73.c | |||
@@ -150,17 +150,31 @@ static int lm73_detect(struct i2c_client *new_client, | |||
150 | struct i2c_board_info *info) | 150 | struct i2c_board_info *info) |
151 | { | 151 | { |
152 | struct i2c_adapter *adapter = new_client->adapter; | 152 | struct i2c_adapter *adapter = new_client->adapter; |
153 | u16 id; | 153 | int id, ctrl, conf; |
154 | u8 ctrl; | ||
155 | 154 | ||
156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 155 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
157 | I2C_FUNC_SMBUS_WORD_DATA)) | 156 | I2C_FUNC_SMBUS_WORD_DATA)) |
158 | return -ENODEV; | 157 | return -ENODEV; |
159 | 158 | ||
159 | /* | ||
160 | * Do as much detection as possible with byte reads first, as word | ||
161 | * reads can confuse other devices. | ||
162 | */ | ||
163 | ctrl = i2c_smbus_read_byte_data(new_client, LM73_REG_CTRL); | ||
164 | if (ctrl < 0 || (ctrl & 0x10)) | ||
165 | return -ENODEV; | ||
166 | |||
167 | conf = i2c_smbus_read_byte_data(new_client, LM73_REG_CONF); | ||
168 | if (conf < 0 || (conf & 0x0c)) | ||
169 | return -ENODEV; | ||
170 | |||
171 | id = i2c_smbus_read_byte_data(new_client, LM73_REG_ID); | ||
172 | if (id < 0 || id != (LM73_ID & 0xff)) | ||
173 | return -ENODEV; | ||
174 | |||
160 | /* Check device ID */ | 175 | /* Check device ID */ |
161 | id = i2c_smbus_read_word_data(new_client, LM73_REG_ID); | 176 | id = i2c_smbus_read_word_data(new_client, LM73_REG_ID); |
162 | ctrl = i2c_smbus_read_byte_data(new_client, LM73_REG_CTRL); | 177 | if (id < 0 || id != LM73_ID) |
163 | if ((id != LM73_ID) || (ctrl & 0x10)) | ||
164 | return -ENODEV; | 178 | return -ENODEV; |
165 | 179 | ||
166 | strlcpy(info->type, "lm73", I2C_NAME_SIZE); | 180 | strlcpy(info->type, "lm73", I2C_NAME_SIZE); |