aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2009-12-09 14:35:52 -0500
committerJean Delvare <khali@linux-fr.org>2009-12-09 14:35:52 -0500
commit747d9bedc3d1e42900bf2bb1669f46e4fd0c8957 (patch)
treebf6d50a0e6cd7089c52fee5f8e0f1e7fe4c48aae /drivers
parent9560672369098b021688421f45476ce0c8bc451b (diff)
hwmon: (lm77) Clean up detect function
As kind is now hard-coded to -1, there is room for code clean-ups. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/lm77.c80
1 files changed, 39 insertions, 41 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 866b401ab6e8..ac067fd19482 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -249,6 +249,7 @@ static int lm77_detect(struct i2c_client *new_client, int kind,
249 struct i2c_board_info *info) 249 struct i2c_board_info *info)
250{ 250{
251 struct i2c_adapter *adapter = new_client->adapter; 251 struct i2c_adapter *adapter = new_client->adapter;
252 int i, cur, conf, hyst, crit, min, max;
252 253
253 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 254 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
254 I2C_FUNC_SMBUS_WORD_DATA)) 255 I2C_FUNC_SMBUS_WORD_DATA))
@@ -265,51 +266,48 @@ static int lm77_detect(struct i2c_client *new_client, int kind,
265 4. registers cycling over 8-address boundaries 266 4. registers cycling over 8-address boundaries
266 267
267 Word-sized registers are high-byte first. */ 268 Word-sized registers are high-byte first. */
268 if (kind < 0) {
269 int i, cur, conf, hyst, crit, min, max;
270
271 /* addresses cycling */
272 cur = i2c_smbus_read_word_data(new_client, 0);
273 conf = i2c_smbus_read_byte_data(new_client, 1);
274 hyst = i2c_smbus_read_word_data(new_client, 2);
275 crit = i2c_smbus_read_word_data(new_client, 3);
276 min = i2c_smbus_read_word_data(new_client, 4);
277 max = i2c_smbus_read_word_data(new_client, 5);
278 for (i = 8; i <= 0xff; i += 8)
279 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
280 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
281 || i2c_smbus_read_word_data(new_client, i + 3) != crit
282 || i2c_smbus_read_word_data(new_client, i + 4) != min
283 || i2c_smbus_read_word_data(new_client, i + 5) != max)
284 return -ENODEV;
285
286 /* sign bits */
287 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
288 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
289 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
290 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
291 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
292 return -ENODEV;
293 269
294 /* unused bits */ 270 /* addresses cycling */
295 if (conf & 0xe0) 271 cur = i2c_smbus_read_word_data(new_client, 0);
272 conf = i2c_smbus_read_byte_data(new_client, 1);
273 hyst = i2c_smbus_read_word_data(new_client, 2);
274 crit = i2c_smbus_read_word_data(new_client, 3);
275 min = i2c_smbus_read_word_data(new_client, 4);
276 max = i2c_smbus_read_word_data(new_client, 5);
277 for (i = 8; i <= 0xff; i += 8) {
278 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
279 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
280 || i2c_smbus_read_word_data(new_client, i + 3) != crit
281 || i2c_smbus_read_word_data(new_client, i + 4) != min
282 || i2c_smbus_read_word_data(new_client, i + 5) != max)
296 return -ENODEV; 283 return -ENODEV;
284 }
297 285
298 /* 0x06 and 0x07 return the last read value */ 286 /* sign bits */
299 cur = i2c_smbus_read_word_data(new_client, 0); 287 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
300 if (i2c_smbus_read_word_data(new_client, 6) != cur 288 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
301 || i2c_smbus_read_word_data(new_client, 7) != cur) 289 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
302 return -ENODEV; 290 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
303 hyst = i2c_smbus_read_word_data(new_client, 2); 291 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
304 if (i2c_smbus_read_word_data(new_client, 6) != hyst 292 return -ENODEV;
305 || i2c_smbus_read_word_data(new_client, 7) != hyst)
306 return -ENODEV;
307 min = i2c_smbus_read_word_data(new_client, 4);
308 if (i2c_smbus_read_word_data(new_client, 6) != min
309 || i2c_smbus_read_word_data(new_client, 7) != min)
310 return -ENODEV;
311 293
312 } 294 /* unused bits */
295 if (conf & 0xe0)
296 return -ENODEV;
297
298 /* 0x06 and 0x07 return the last read value */
299 cur = i2c_smbus_read_word_data(new_client, 0);
300 if (i2c_smbus_read_word_data(new_client, 6) != cur
301 || i2c_smbus_read_word_data(new_client, 7) != cur)
302 return -ENODEV;
303 hyst = i2c_smbus_read_word_data(new_client, 2);
304 if (i2c_smbus_read_word_data(new_client, 6) != hyst
305 || i2c_smbus_read_word_data(new_client, 7) != hyst)
306 return -ENODEV;
307 min = i2c_smbus_read_word_data(new_client, 4);
308 if (i2c_smbus_read_word_data(new_client, 6) != min
309 || i2c_smbus_read_word_data(new_client, 7) != min)
310 return -ENODEV;
313 311
314 strlcpy(info->type, "lm77", I2C_NAME_SIZE); 312 strlcpy(info->type, "lm77", I2C_NAME_SIZE);
315 313