Commit e76f67b5babc65cd620d395a1fd231409808df90

Authored by Jean Delvare
Committed by Jean Delvare
1 parent 05e82fe40f

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>

Showing 1 changed file with 19 additions and 21 deletions Side-by-side Diff

drivers/hwmon/lm75.c
... ... @@ -240,7 +240,7 @@
240 240 {
241 241 struct i2c_adapter *adapter = new_client->adapter;
242 242 int i;
243   - int cur, conf, hyst, os;
  243 + int conf, hyst, os;
244 244 bool is_lm75a = 0;
245 245  
246 246 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
247 247  
... ... @@ -261,8 +261,10 @@
261 261 register 7, and unused registers return 0xff rather than the
262 262 last read value. */
263 263  
264   - cur = i2c_smbus_read_word_data(new_client, 0);
  264 + /* Unused bits */
265 265 conf = i2c_smbus_read_byte_data(new_client, 1);
  266 + if (conf & 0xe0)
  267 + return -ENODEV;
266 268  
267 269 /* First check for LM75A */
268 270 if (i2c_smbus_read_byte_data(new_client, 7) == LM75A_ID) {
269 271  
270 272  
271 273  
272 274  
273 275  
... ... @@ -273,33 +275,29 @@
273 275 || i2c_smbus_read_byte_data(new_client, 6) != 0xff)
274 276 return -ENODEV;
275 277 is_lm75a = 1;
276   - hyst = i2c_smbus_read_word_data(new_client, 2);
277   - os = i2c_smbus_read_word_data(new_client, 3);
  278 + hyst = i2c_smbus_read_byte_data(new_client, 2);
  279 + os = i2c_smbus_read_byte_data(new_client, 3);
278 280 } else { /* Traditional style LM75 detection */
279 281 /* Unused addresses */
280   - hyst = i2c_smbus_read_word_data(new_client, 2);
281   - if (i2c_smbus_read_word_data(new_client, 4) != hyst
282   - || i2c_smbus_read_word_data(new_client, 5) != hyst
283   - || i2c_smbus_read_word_data(new_client, 6) != hyst
284   - || i2c_smbus_read_word_data(new_client, 7) != hyst)
  282 + hyst = i2c_smbus_read_byte_data(new_client, 2);
  283 + if (i2c_smbus_read_byte_data(new_client, 4) != hyst
  284 + || i2c_smbus_read_byte_data(new_client, 5) != hyst
  285 + || i2c_smbus_read_byte_data(new_client, 6) != hyst
  286 + || i2c_smbus_read_byte_data(new_client, 7) != hyst)
285 287 return -ENODEV;
286   - os = i2c_smbus_read_word_data(new_client, 3);
287   - if (i2c_smbus_read_word_data(new_client, 4) != os
288   - || i2c_smbus_read_word_data(new_client, 5) != os
289   - || i2c_smbus_read_word_data(new_client, 6) != os
290   - || i2c_smbus_read_word_data(new_client, 7) != os)
  288 + os = i2c_smbus_read_byte_data(new_client, 3);
  289 + if (i2c_smbus_read_byte_data(new_client, 4) != os
  290 + || i2c_smbus_read_byte_data(new_client, 5) != os
  291 + || i2c_smbus_read_byte_data(new_client, 6) != os
  292 + || i2c_smbus_read_byte_data(new_client, 7) != os)
291 293 return -ENODEV;
292 294 }
293 295  
294   - /* Unused bits */
295   - if (conf & 0xe0)
296   - return -ENODEV;
297   -
298 296 /* Addresses cycling */
299   - for (i = 8; i < 0xff; i += 8) {
  297 + for (i = 8; i <= 248; i += 40) {
300 298 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
301   - || i2c_smbus_read_word_data(new_client, i + 2) != hyst
302   - || i2c_smbus_read_word_data(new_client, i + 3) != os)
  299 + || i2c_smbus_read_byte_data(new_client, i + 2) != hyst
  300 + || i2c_smbus_read_byte_data(new_client, i + 3) != os)
303 301 return -ENODEV;
304 302 if (is_lm75a && i2c_smbus_read_byte_data(new_client, i + 7)
305 303 != LM75A_ID)