Commit 69fc1feb authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

hwmon: (lm85) Rework the device detection

Rework the device detection to make it clearer and faster in the
general case (when a known device is found.)
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarHerbert Poetzl <herbert@13thfloor.at>
parent dbee3562
...@@ -1106,7 +1106,6 @@ static void lm85_init_client(struct i2c_client *client) ...@@ -1106,7 +1106,6 @@ static void lm85_init_client(struct i2c_client *client)
static int lm85_detect(struct i2c_adapter *adapter, int address, static int lm85_detect(struct i2c_adapter *adapter, int address,
int kind) int kind)
{ {
int company, verstep;
struct i2c_client *client; struct i2c_client *client;
struct lm85_data *data; struct lm85_data *data;
int err = 0; int err = 0;
...@@ -1117,10 +1116,6 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -1117,10 +1116,6 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
goto ERROR0; goto ERROR0;
} }
/* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet.
But it allows us to access lm85_{read,write}_value. */
if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) { if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR0; goto ERROR0;
...@@ -1132,75 +1127,57 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -1132,75 +1127,57 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
client->adapter = adapter; client->adapter = adapter;
client->driver = &lm85_driver; client->driver = &lm85_driver;
/* Now, we do the remaining detection. */ /* If auto-detecting, 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 %d,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",
i2c_adapter_id(client->adapter), client->addr, address, company, verstep);
company, verstep);
/* All supported chips have the version in common */
/* If auto-detecting, Determine the chip type. */ if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
if (kind <= 0) { dev_dbg(&adapter->dev, "Autodetection failed: "
dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", "unsupported version\n");
i2c_adapter_id(adapter), address); goto ERROR1;
if (company == LM85_COMPANY_NATIONAL }
&& verstep == LM85_VERSTEP_LM85C) { kind = any_chip;
kind = lm85c;
} else if (company == LM85_COMPANY_NATIONAL /* Now, refine the detection */
&& verstep == LM85_VERSTEP_LM85B) { if (company == LM85_COMPANY_NATIONAL) {
kind = lm85b; switch (verstep) {
} else if (company == LM85_COMPANY_NATIONAL case LM85_VERSTEP_LM85C:
&& (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { kind = lm85c;
dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" break;
" Defaulting to LM85.\n", verstep); case LM85_VERSTEP_LM85B:
kind = any_chip; kind = lm85b;
} else if (company == LM85_COMPANY_ANALOG_DEV break;
&& verstep == LM85_VERSTEP_ADM1027) { }
kind = adm1027; } else if (company == LM85_COMPANY_ANALOG_DEV) {
} else if (company == LM85_COMPANY_ANALOG_DEV switch (verstep) {
&& (verstep == LM85_VERSTEP_ADT7463 case LM85_VERSTEP_ADM1027:
|| verstep == LM85_VERSTEP_ADT7463C)) { kind = adm1027;
kind = adt7463; break;
} else if (company == LM85_COMPANY_ANALOG_DEV case LM85_VERSTEP_ADT7463:
&& (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { case LM85_VERSTEP_ADT7463C:
dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" kind = adt7463;
" Defaulting to Generic LM85.\n", verstep); break;
kind = any_chip;
} else if (company == LM85_COMPANY_SMSC
&& (verstep == LM85_VERSTEP_EMC6D100_A0
|| verstep == LM85_VERSTEP_EMC6D100_A1)) {
/* Unfortunately, we can't tell a '100 from a '101
* from the registers. Since a '101 is a '100
* in a package with fewer pins and therefore no
* 3.3V, 1.5V or 1.8V inputs, perhaps if those
* inputs read 0, then it's a '101.
*/
kind = emc6d100;
} else if (company == LM85_COMPANY_SMSC
&& verstep == LM85_VERSTEP_EMC6D102) {
kind = emc6d102;
} else if (company == LM85_COMPANY_SMSC
&& (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
" Defaulting to Generic LM85.\n", verstep);
kind = any_chip;
} else if (kind == any_chip
&& (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
/* Leave kind as "any_chip" */
} else {
dev_dbg(&adapter->dev, "Autodetection failed\n");
/* Not an LM85... */
if (kind == any_chip) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic LM85 Version 6 not"
" found at %d,0x%02x. Try force_lm85c.\n",
i2c_adapter_id(adapter), address);
} }
err = 0; } 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");
goto ERROR1; goto ERROR1;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment