aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-03-21 12:59:36 -0400
committerJean Delvare <khali@endymion.delvare>2011-03-21 12:59:36 -0400
commite76f67b5babc65cd620d395a1fd231409808df90 (patch)
treea5af03c47fd02f83e1a35f75a4efaf1a1f6fe5b6 /drivers
parent05e82fe40faee8499b4e3ba12fddaaf013d84203 (diff)
hwmon: (lm75) Speed up detection
Make the LM75/LM75A device detection faster: * Don't read the current temperature value when we don't use it. * Check for unused bits in the configuration register as soon as we have read its value. * Don't use word reads, not all devices support this, and some which don't misbehave when you try. * Check for cycling register values every 40 register addresses instead of every 8, it's 5 times faster and just as efficient. Some of these improvements come straight from the user-space sensors-detect script, so both detection routines are in line now. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Len Sorensen <lsorense@csclub.uwaterloo.ca> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/lm75.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 638dd0586e3f..ef902d5d06ab 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -240,7 +240,7 @@ static int lm75_detect(struct i2c_client *new_client,
240{ 240{
241 struct i2c_adapter *adapter = new_client->adapter; 241 struct i2c_adapter *adapter = new_client->adapter;
242 int i; 242 int i;
243 int cur, conf, hyst, os; 243 int conf, hyst, os;
244 bool is_lm75a = 0; 244 bool is_lm75a = 0;
245 245
246 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 246 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
@@ -261,8 +261,10 @@ static int lm75_detect(struct i2c_client *new_client,
261 register 7, and unused registers return 0xff rather than the 261 register 7, and unused registers return 0xff rather than the
262 last read value. */ 262 last read value. */
263 263
264 cur = i2c_smbus_read_word_data(new_client, 0); 264 /* Unused bits */
265 conf = i2c_smbus_read_byte_data(new_client, 1); 265 conf = i2c_smbus_read_byte_data(new_client, 1);
266 if (conf & 0xe0)
267 return -ENODEV;
266 268
267 /* First check for LM75A */ 269 /* First check for LM75A */
268 if (i2c_smbus_read_byte_data(new_client, 7) == LM75A_ID) { 270 if (i2c_smbus_read_byte_data(new_client, 7) == LM75A_ID) {
@@ -273,33 +275,29 @@ static int lm75_detect(struct i2c_client *new_client,
273 || i2c_smbus_read_byte_data(new_client, 6) != 0xff) 275 || i2c_smbus_read_byte_data(new_client, 6) != 0xff)
274 return -ENODEV; 276 return -ENODEV;
275 is_lm75a = 1; 277 is_lm75a = 1;
276 hyst = i2c_smbus_read_word_data(new_client, 2); 278 hyst = i2c_smbus_read_byte_data(new_client, 2);
277 os = i2c_smbus_read_word_data(new_client, 3); 279 os = i2c_smbus_read_byte_data(new_client, 3);
278 } else { /* Traditional style LM75 detection */ 280 } else { /* Traditional style LM75 detection */
279 /* Unused addresses */ 281 /* Unused addresses */
280 hyst = i2c_smbus_read_word_data(new_client, 2); 282 hyst = i2c_smbus_read_byte_data(new_client, 2);
281 if (i2c_smbus_read_word_data(new_client, 4) != hyst 283 if (i2c_smbus_read_byte_data(new_client, 4) != hyst
282 || i2c_smbus_read_word_data(new_client, 5) != hyst 284 || i2c_smbus_read_byte_data(new_client, 5) != hyst
283 || i2c_smbus_read_word_data(new_client, 6) != hyst 285 || i2c_smbus_read_byte_data(new_client, 6) != hyst
284 || i2c_smbus_read_word_data(new_client, 7) != hyst) 286 || i2c_smbus_read_byte_data(new_client, 7) != hyst)
285 return -ENODEV; 287 return -ENODEV;
286 os = i2c_smbus_read_word_data(new_client, 3); 288 os = i2c_smbus_read_byte_data(new_client, 3);
287 if (i2c_smbus_read_word_data(new_client, 4) != os 289 if (i2c_smbus_read_byte_data(new_client, 4) != os
288 || i2c_smbus_read_word_data(new_client, 5) != os 290 || i2c_smbus_read_byte_data(new_client, 5) != os
289 || i2c_smbus_read_word_data(new_client, 6) != os 291 || i2c_smbus_read_byte_data(new_client, 6) != os
290 || i2c_smbus_read_word_data(new_client, 7) != os) 292 || i2c_smbus_read_byte_data(new_client, 7) != os)
291 return -ENODEV; 293 return -ENODEV;
292 } 294 }
293 295
294 /* Unused bits */
295 if (conf & 0xe0)
296 return -ENODEV;
297
298 /* Addresses cycling */ 296 /* Addresses cycling */
299 for (i = 8; i < 0xff; i += 8) { 297 for (i = 8; i <= 248; i += 40) {
300 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf 298 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
301 || i2c_smbus_read_word_data(new_client, i + 2) != hyst 299 || i2c_smbus_read_byte_data(new_client, i + 2) != hyst
302 || i2c_smbus_read_word_data(new_client, i + 3) != os) 300 || i2c_smbus_read_byte_data(new_client, i + 3) != os)
303 return -ENODEV; 301 return -ENODEV;
304 if (is_lm75a && i2c_smbus_read_byte_data(new_client, i + 7) 302 if (is_lm75a && i2c_smbus_read_byte_data(new_client, i + 7)
305 != LM75A_ID) 303 != LM75A_ID)