dect
/
linux-2.6
Archived
13
0
Fork 0

hwmon: (lm85) 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>
This commit is contained in:
Jean Delvare 2009-12-09 20:35:53 +01:00
parent b57dc3940a
commit d42a2eb5ad
1 changed files with 63 additions and 90 deletions

View File

@ -5,7 +5,7 @@
Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org>
Chip details at <http://www.national.com/ds/LM/LM85.pdf> Chip details at <http://www.national.com/ds/LM/LM85.pdf>
@ -1162,107 +1162,80 @@ static int lm85_detect(struct i2c_client *client, int kind,
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int address = client->addr; int address = client->addr;
const char *type_name; const char *type_name;
int company, verstep;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */ /* We need to be able to do byte I/O */
return -ENODEV; return -ENODEV;
} }
/* If auto-detecting, determine the chip type */ /* Determine the chip type */
if (kind < 0) { company = lm85_read_value(client, LM85_REG_COMPANY);
int company = lm85_read_value(client, LM85_REG_COMPANY); verstep = lm85_read_value(client, LM85_REG_VERSTEP);
int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
dev_dbg(&adapter->dev, "Detecting device at 0x%02x with " dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
"COMPANY: 0x%02x and VERSTEP: 0x%02x\n", "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
address, company, verstep); address, company, verstep);
/* All supported chips have the version in common */ /* All supported chips have the version in common */
if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC && if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
(verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) { (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
dev_dbg(&adapter->dev, "Autodetection failed: " dev_dbg(&adapter->dev,
"unsupported version\n"); "Autodetection failed: unsupported version\n");
return -ENODEV; return -ENODEV;
}
type_name = "lm85";
/* Now, refine the detection */
if (company == LM85_COMPANY_NATIONAL) {
switch (verstep) {
case LM85_VERSTEP_LM85C:
type_name = "lm85c";
break;
case LM85_VERSTEP_LM85B:
type_name = "lm85b";
break;
case LM85_VERSTEP_LM96000_1:
case LM85_VERSTEP_LM96000_2:
/* Check for Winbond WPCD377I */
if (lm85_is_fake(client)) {
dev_dbg(&adapter->dev,
"Found Winbond WPCD377I, ignoring\n");
return -ENODEV;
}
break;
} }
kind = any_chip; } else if (company == LM85_COMPANY_ANALOG_DEV) {
switch (verstep) {
/* Now, refine the detection */ case LM85_VERSTEP_ADM1027:
if (company == LM85_COMPANY_NATIONAL) { type_name = "adm1027";
switch (verstep) { break;
case LM85_VERSTEP_LM85C: case LM85_VERSTEP_ADT7463:
kind = lm85c; case LM85_VERSTEP_ADT7463C:
break; type_name = "adt7463";
case LM85_VERSTEP_LM85B: break;
kind = lm85b; case LM85_VERSTEP_ADT7468_1:
break; case LM85_VERSTEP_ADT7468_2:
case LM85_VERSTEP_LM96000_1: type_name = "adt7468";
case LM85_VERSTEP_LM96000_2: break;
/* Check for Winbond WPCD377I */
if (lm85_is_fake(client)) {
dev_dbg(&adapter->dev,
"Found Winbond WPCD377I, "
"ignoring\n");
return -ENODEV;
}
break;
}
} else if (company == LM85_COMPANY_ANALOG_DEV) {
switch (verstep) {
case LM85_VERSTEP_ADM1027:
kind = adm1027;
break;
case LM85_VERSTEP_ADT7463:
case LM85_VERSTEP_ADT7463C:
kind = adt7463;
break;
case LM85_VERSTEP_ADT7468_1:
case LM85_VERSTEP_ADT7468_2:
kind = adt7468;
break;
}
} else if (company == LM85_COMPANY_SMSC) {
switch (verstep) {
case LM85_VERSTEP_EMC6D100_A0:
case LM85_VERSTEP_EMC6D100_A1:
/* Note: we can't tell a '100 from a '101 */
kind = emc6d100;
break;
case LM85_VERSTEP_EMC6D102:
kind = emc6d102;
break;
}
} else {
dev_dbg(&adapter->dev, "Autodetection failed: "
"unknown vendor\n");
return -ENODEV;
} }
} else if (company == LM85_COMPANY_SMSC) {
switch (verstep) {
case LM85_VERSTEP_EMC6D100_A0:
case LM85_VERSTEP_EMC6D100_A1:
/* Note: we can't tell a '100 from a '101 */
type_name = "emc6d100";
break;
case LM85_VERSTEP_EMC6D102:
type_name = "emc6d102";
break;
}
} else {
dev_dbg(&adapter->dev,
"Autodetection failed: unknown vendor\n");
return -ENODEV;
} }
switch (kind) {
case lm85b:
type_name = "lm85b";
break;
case lm85c:
type_name = "lm85c";
break;
case adm1027:
type_name = "adm1027";
break;
case adt7463:
type_name = "adt7463";
break;
case adt7468:
type_name = "adt7468";
break;
case emc6d100:
type_name = "emc6d100";
break;
case emc6d102:
type_name = "emc6d102";
break;
default:
type_name = "lm85";
}
strlcpy(info->type, type_name, I2C_NAME_SIZE); strlcpy(info->type, type_name, I2C_NAME_SIZE);
return 0; return 0;