diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:52 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:52 -0500 |
commit | b57dc3940a70a2c2460b628567a3cc76efe725f2 (patch) | |
tree | 23c38b6dcfbaeb1ee5f8d4a0fe99811cf391c753 /drivers/hwmon/lm83.c | |
parent | 747d9bedc3d1e42900bf2bb1669f46e4fd0c8957 (diff) |
hwmon: (lm83) 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/hwmon/lm83.c')
-rw-r--r-- | drivers/hwmon/lm83.c | 81 |
1 files changed, 26 insertions, 55 deletions
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index e59e2d1f080c..08b03e6ed0b7 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm83.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | 3 | * monitoring |
4 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is | 6 | * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is |
7 | * a sensor chip made by National Semiconductor. It reports up to four | 7 | * a sensor chip made by National Semiconductor. It reports up to four |
@@ -295,69 +295,40 @@ static int lm83_detect(struct i2c_client *new_client, int kind, | |||
295 | struct i2c_board_info *info) | 295 | struct i2c_board_info *info) |
296 | { | 296 | { |
297 | struct i2c_adapter *adapter = new_client->adapter; | 297 | struct i2c_adapter *adapter = new_client->adapter; |
298 | const char *name = ""; | 298 | const char *name; |
299 | u8 man_id, chip_id; | ||
299 | 300 | ||
300 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 301 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
301 | return -ENODEV; | 302 | return -ENODEV; |
302 | 303 | ||
303 | /* Now we do the detection and identification. A negative kind | 304 | /* Detection */ |
304 | * means that the driver was loaded with no force parameter | 305 | if ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1) & 0xA8) || |
305 | * (default), so we must both detect and identify the chip | 306 | (i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2) & 0x48) || |
306 | * (actually there is only one possible kind of chip for now, LM83). | 307 | (i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) & 0x41)) { |
307 | * A zero kind means that the driver was loaded with the force | 308 | dev_dbg(&adapter->dev, "LM83 detection failed at 0x%02x\n", |
308 | * parameter, the detection step shall be skipped. A positive kind | 309 | new_client->addr); |
309 | * means that the driver was loaded with the force parameter and a | 310 | return -ENODEV; |
310 | * given kind of chip is requested, so both the detection and the | ||
311 | * identification steps are skipped. */ | ||
312 | |||
313 | /* Default to an LM83 if forced */ | ||
314 | if (kind == 0) | ||
315 | kind = lm83; | ||
316 | |||
317 | if (kind < 0) { /* detection */ | ||
318 | if (((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1) | ||
319 | & 0xA8) != 0x00) || | ||
320 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2) | ||
321 | & 0x48) != 0x00) || | ||
322 | ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) | ||
323 | & 0x41) != 0x00)) { | ||
324 | dev_dbg(&adapter->dev, | ||
325 | "LM83 detection failed at 0x%02x.\n", | ||
326 | new_client->addr); | ||
327 | return -ENODEV; | ||
328 | } | ||
329 | } | 311 | } |
330 | 312 | ||
331 | if (kind <= 0) { /* identification */ | 313 | /* Identification */ |
332 | u8 man_id, chip_id; | 314 | man_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_MAN_ID); |
333 | 315 | if (man_id != 0x01) /* National Semiconductor */ | |
334 | man_id = i2c_smbus_read_byte_data(new_client, | 316 | return -ENODEV; |
335 | LM83_REG_R_MAN_ID); | ||
336 | chip_id = i2c_smbus_read_byte_data(new_client, | ||
337 | LM83_REG_R_CHIP_ID); | ||
338 | |||
339 | if (man_id == 0x01) { /* National Semiconductor */ | ||
340 | if (chip_id == 0x03) { | ||
341 | kind = lm83; | ||
342 | } else | ||
343 | if (chip_id == 0x01) { | ||
344 | kind = lm82; | ||
345 | } | ||
346 | } | ||
347 | |||
348 | if (kind <= 0) { /* identification failed */ | ||
349 | dev_info(&adapter->dev, | ||
350 | "Unsupported chip (man_id=0x%02X, " | ||
351 | "chip_id=0x%02X).\n", man_id, chip_id); | ||
352 | return -ENODEV; | ||
353 | } | ||
354 | } | ||
355 | 317 | ||
356 | if (kind == lm83) { | 318 | chip_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_CHIP_ID); |
319 | switch (chip_id) { | ||
320 | case 0x03: | ||
357 | name = "lm83"; | 321 | name = "lm83"; |
358 | } else | 322 | break; |
359 | if (kind == lm82) { | 323 | case 0x01: |
360 | name = "lm82"; | 324 | name = "lm82"; |
325 | break; | ||
326 | default: | ||
327 | /* identification failed */ | ||
328 | dev_info(&adapter->dev, | ||
329 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", | ||
330 | man_id, chip_id); | ||
331 | return -ENODEV; | ||
361 | } | 332 | } |
362 | 333 | ||
363 | strlcpy(info->type, name, I2C_NAME_SIZE); | 334 | strlcpy(info->type, name, I2C_NAME_SIZE); |