提交 52df6440 编写于 作者: J Jean Delvare

hwmon: Clean up detect functions

As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by: NJean Delvare <khali@linux-fr.org>
Acked-by: NCorentin Labbe <corentin.labbe@geomatys.fr>
Cc: "Mark M. Hoffman" <mhoffman@lightlink.com>
Cc: Juerg Haefliger <juergh@gmail.com>
Cc: Riku Voipio <riku.voipio@iki.fi>
Acked-by: N"Hans J. Koch" <hjk@linutronix.de>
Cc: Rudolf Marek <r.marek@assembler.cz>
上级 a1fa4cdc
...@@ -1672,35 +1672,26 @@ static int adm1026_detect(struct i2c_client *client, int kind, ...@@ -1672,35 +1672,26 @@ static int adm1026_detect(struct i2c_client *client, int kind,
i2c_adapter_id(client->adapter), client->addr, i2c_adapter_id(client->adapter), client->addr,
company, verstep); company, verstep);
/* If auto-detecting, Determine the chip type. */ /* Determine the chip type. */
if (kind <= 0) { dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n",
dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x " i2c_adapter_id(adapter), address);
"...\n", i2c_adapter_id(adapter), address); if (company == ADM1026_COMPANY_ANALOG_DEV
if (company == ADM1026_COMPANY_ANALOG_DEV && verstep == ADM1026_VERSTEP_ADM1026) {
&& verstep == ADM1026_VERSTEP_ADM1026) { /* Analog Devices ADM1026 */
kind = adm1026; } else if (company == ADM1026_COMPANY_ANALOG_DEV
} else if (company == ADM1026_COMPANY_ANALOG_DEV && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
&& (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { dev_err(&adapter->dev, "Unrecognized stepping "
dev_err(&adapter->dev, "Unrecognized stepping " "0x%02x. Defaulting to ADM1026.\n", verstep);
"0x%02x. Defaulting to ADM1026.\n", verstep); } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
kind = adm1026; dev_err(&adapter->dev, "Found version/stepping "
} else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { "0x%02x. Assuming generic ADM1026.\n",
dev_err(&adapter->dev, "Found version/stepping " verstep);
"0x%02x. Assuming generic ADM1026.\n", } else {
verstep); dev_dbg(&adapter->dev, "Autodetection failed\n");
kind = any_chip; /* Not an ADM1026... */
} else { return -ENODEV;
dev_dbg(&adapter->dev, "Autodetection failed\n");
/* Not an ADM1026 ... */
if (kind == 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
return -ENODEV;
}
} }
strlcpy(info->type, "adm1026", I2C_NAME_SIZE); strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -301,59 +301,36 @@ static int adm1029_detect(struct i2c_client *client, int kind, ...@@ -301,59 +301,36 @@ static int adm1029_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
u8 man_id, chip_id, temp_devices_installed, nb_fan_support;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
/* Now we do the detection and identification. A negative kind
* means that the driver was loaded with no force parameter
* (default), so we must both detect and identify the chip
* (actually there is only one possible kind of chip for now, adm1029).
* A zero kind means that the driver was loaded with the force
* parameter, the detection step shall be skipped. A positive kind
* means that the driver was loaded with the force parameter and a
* given kind of chip is requested, so both the detection and the
* identification steps are skipped. */
/* Default to an adm1029 if forced */
if (kind == 0)
kind = adm1029;
/* ADM1029 doesn't have CHIP ID, check just MAN ID /* ADM1029 doesn't have CHIP ID, check just MAN ID
* For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
* ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
* documented * documented
*/ */
if (kind <= 0) { /* identification */ man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
u8 man_id, chip_id, temp_devices_installed, nb_fan_support; chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
temp_devices_installed = i2c_smbus_read_byte_data(client,
man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
temp_devices_installed = i2c_smbus_read_byte_data(client,
ADM1029_REG_TEMP_DEVICES_INSTALLED); ADM1029_REG_TEMP_DEVICES_INSTALLED);
nb_fan_support = i2c_smbus_read_byte_data(client, nb_fan_support = i2c_smbus_read_byte_data(client,
ADM1029_REG_NB_FAN_SUPPORT); ADM1029_REG_NB_FAN_SUPPORT);
/* 0x41 is Analog Devices */ /* 0x41 is Analog Devices */
if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01 if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01
&& nb_fan_support == 0x03) { || nb_fan_support != 0x03)
if ((chip_id & 0xF0) == 0x00) { return -ENODEV;
kind = adm1029;
} else {
/* There are no "official" CHIP ID, so actually
* we use Major/Minor revision for that */
printk(KERN_INFO
"adm1029: Unknown major revision %x, "
"please let us know\n", chip_id);
}
}
if (kind <= 0) { /* identification failed */ if ((chip_id & 0xF0) != 0x00) {
pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " /* There are no "official" CHIP ID, so actually
"chip_id=0x%02X)\n", man_id, chip_id); * we use Major/Minor revision for that */
return -ENODEV; pr_info("adm1029: Unknown major revision %x, "
} "please let us know\n", chip_id);
return -ENODEV;
} }
strlcpy(info->type, "adm1029", I2C_NAME_SIZE); strlcpy(info->type, "adm1029", I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -817,31 +817,19 @@ static int adm1031_detect(struct i2c_client *client, int kind, ...@@ -817,31 +817,19 @@ static int adm1031_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
const char *name = ""; const char *name;
int id, co;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind < 0) { id = i2c_smbus_read_byte_data(client, 0x3d);
int id, co; co = i2c_smbus_read_byte_data(client, 0x3e);
id = i2c_smbus_read_byte_data(client, 0x3d);
co = i2c_smbus_read_byte_data(client, 0x3e);
if (!((id == 0x31 || id == 0x30) && co == 0x41)) if (!((id == 0x31 || id == 0x30) && co == 0x41))
return -ENODEV; return -ENODEV;
kind = (id == 0x30) ? adm1030 : adm1031; name = (id == 0x30) ? "adm1030" : "adm1031";
}
if (kind <= 0)
kind = adm1031;
/* Given the detected chip type, set the chip name and the
* auto fan control helper table. */
if (kind == adm1030) {
name = "adm1030";
} else if (kind == adm1031) {
name = "adm1031";
}
strlcpy(info->type, name, I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -556,51 +556,34 @@ static int adm9240_detect(struct i2c_client *new_client, int kind, ...@@ -556,51 +556,34 @@ static int adm9240_detect(struct i2c_client *new_client, int kind,
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind == 0) { /* verify chip: reg address should match i2c address */
kind = adm9240; if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
} != address) {
dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n",
if (kind < 0) { address);
return -ENODEV;
/* verify chip: reg address should match i2c address */
if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
!= address) {
dev_err(&adapter->dev, "detect fail: address match, "
"0x%02x\n", address);
return -ENODEV;
}
/* check known chip manufacturer */
man_id = i2c_smbus_read_byte_data(new_client,
ADM9240_REG_MAN_ID);
if (man_id == 0x23) {
kind = adm9240;
} else if (man_id == 0xda) {
kind = ds1780;
} else if (man_id == 0x01) {
kind = lm81;
} else {
dev_err(&adapter->dev, "detect fail: unknown manuf, "
"0x%02x\n", man_id);
return -ENODEV;
}
/* successful detect, print chip info */
die_rev = i2c_smbus_read_byte_data(new_client,
ADM9240_REG_DIE_REV);
dev_info(&adapter->dev, "found %s revision %u\n",
man_id == 0x23 ? "ADM9240" :
man_id == 0xda ? "DS1780" : "LM81", die_rev);
} }
/* either forced or detected chip kind */ /* check known chip manufacturer */
if (kind == adm9240) { man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID);
if (man_id == 0x23) {
name = "adm9240"; name = "adm9240";
} else if (kind == ds1780) { } else if (man_id == 0xda) {
name = "ds1780"; name = "ds1780";
} else if (kind == lm81) { } else if (man_id == 0x01) {
name = "lm81"; name = "lm81";
} else {
dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n",
man_id);
return -ENODEV;
} }
/* successful detect, print chip info */
die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV);
dev_info(&adapter->dev, "found %s revision %u\n",
man_id == 0x23 ? "ADM9240" :
man_id == 0xda ? "DS1780" : "LM81", die_rev);
strlcpy(info->type, name, I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -191,6 +191,7 @@ static int ads7828_detect(struct i2c_client *client, int kind, ...@@ -191,6 +191,7 @@ static int ads7828_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int ch;
/* Check we have a valid client */ /* Check we have a valid client */
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
...@@ -202,20 +203,17 @@ static int ads7828_detect(struct i2c_client *client, int kind, ...@@ -202,20 +203,17 @@ static int ads7828_detect(struct i2c_client *client, int kind,
- Read from the 8 channel addresses - Read from the 8 channel addresses
- Check the top 4 bits of each result are not set (12 data bits) - Check the top 4 bits of each result are not set (12 data bits)
*/ */
if (kind < 0) { for (ch = 0; ch < ADS7828_NCH; ch++) {
int ch; u16 in_data;
for (ch = 0; ch < ADS7828_NCH; ch++) { u8 cmd = channel_cmd_byte(ch);
u16 in_data; in_data = ads7828_read_value(client, cmd);
u8 cmd = channel_cmd_byte(ch); if (in_data & 0xF000) {
in_data = ads7828_read_value(client, cmd); pr_debug("%s : Doesn't look like an ads7828 device\n",
if (in_data & 0xF000) { __func__);
printk(KERN_DEBUG return -ENODEV;
"%s : Doesn't look like an ads7828 device\n",
__func__);
return -ENODEV;
}
} }
} }
strlcpy(info->type, "ads7828", I2C_NAME_SIZE); strlcpy(info->type, "ads7828", I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -1906,27 +1906,22 @@ static int adt7462_detect(struct i2c_client *client, int kind, ...@@ -1906,27 +1906,22 @@ static int adt7462_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int vendor, device, revision;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind <= 0) { vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
int vendor, device, revision; if (vendor != ADT7462_VENDOR)
return -ENODEV;
vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
if (vendor != ADT7462_VENDOR)
return -ENODEV;
device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE);
if (device != ADT7462_DEVICE) if (device != ADT7462_DEVICE)
return -ENODEV; return -ENODEV;
revision = i2c_smbus_read_byte_data(client, revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION);
ADT7462_REG_REVISION); if (revision != ADT7462_REVISION)
if (revision != ADT7462_REVISION) return -ENODEV;
return -ENODEV;
} else
dev_dbg(&adapter->dev, "detection forced\n");
strlcpy(info->type, "adt7462", I2C_NAME_SIZE); strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
......
...@@ -1229,27 +1229,22 @@ static int adt7470_detect(struct i2c_client *client, int kind, ...@@ -1229,27 +1229,22 @@ static int adt7470_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int vendor, device, revision;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind <= 0) { vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
int vendor, device, revision; if (vendor != ADT7470_VENDOR)
return -ENODEV;
vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
if (vendor != ADT7470_VENDOR)
return -ENODEV;
device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE);
if (device != ADT7470_DEVICE) if (device != ADT7470_DEVICE)
return -ENODEV; return -ENODEV;
revision = i2c_smbus_read_byte_data(client, revision = i2c_smbus_read_byte_data(client, ADT7470_REG_REVISION);
ADT7470_REG_REVISION); if (revision != ADT7470_REVISION)
if (revision != ADT7470_REVISION) return -ENODEV;
return -ENODEV;
} else
dev_dbg(&adapter->dev, "detection forced\n");
strlcpy(info->type, "adt7470", I2C_NAME_SIZE); strlcpy(info->type, "adt7470", I2C_NAME_SIZE);
......
...@@ -1090,27 +1090,22 @@ static int adt7473_detect(struct i2c_client *client, int kind, ...@@ -1090,27 +1090,22 @@ static int adt7473_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int vendor, device, revision;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind <= 0) { vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
int vendor, device, revision; if (vendor != ADT7473_VENDOR)
return -ENODEV;
vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
if (vendor != ADT7473_VENDOR)
return -ENODEV;
device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE);
if (device != ADT7473_DEVICE) if (device != ADT7473_DEVICE)
return -ENODEV; return -ENODEV;
revision = i2c_smbus_read_byte_data(client, revision = i2c_smbus_read_byte_data(client, ADT7473_REG_REVISION);
ADT7473_REG_REVISION); if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69)
if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) return -ENODEV;
return -ENODEV;
} else
dev_dbg(&adapter->dev, "detection forced\n");
strlcpy(info->type, "adt7473", I2C_NAME_SIZE); strlcpy(info->type, "adt7473", I2C_NAME_SIZE);
......
...@@ -974,14 +974,12 @@ static int adt7475_detect(struct i2c_client *client, int kind, ...@@ -974,14 +974,12 @@ static int adt7475_detect(struct i2c_client *client, int kind,
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind <= 0) { if (adt7475_read(REG_VENDID) != 0x41 ||
if (adt7475_read(REG_VENDID) != 0x41 || adt7475_read(REG_DEVID) != 0x75) {
adt7475_read(REG_DEVID) != 0x75) { dev_err(&adapter->dev,
dev_err(&adapter->dev, "Couldn't detect a adt7475 part at 0x%02x\n",
"Couldn't detect a adt7475 part at 0x%02x\n", (unsigned int)client->addr);
(unsigned int)client->addr); return -ENODEV;
return -ENODEV;
}
} }
strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE); strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE);
......
...@@ -701,6 +701,7 @@ static int asb100_detect(struct i2c_client *client, int kind, ...@@ -701,6 +701,7 @@ static int asb100_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int val1, val2;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
pr_debug("asb100.o: detect failed, " pr_debug("asb100.o: detect failed, "
...@@ -708,50 +709,30 @@ static int asb100_detect(struct i2c_client *client, int kind, ...@@ -708,50 +709,30 @@ static int asb100_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
} }
/* The chip may be stuck in some other bank than bank 0. This may val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK);
make reading other information impossible. Specify a force=... or val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
force_*=... parameter, and the chip will be reset to the right
bank. */
if (kind < 0) {
int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK);
int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
/* If we're in bank 0 */
if ((!(val1 & 0x07)) &&
/* Check for ASB100 ID (low byte) */
(((!(val1 & 0x80)) && (val2 != 0x94)) ||
/* Check for ASB100 ID (high byte ) */
((val1 & 0x80) && (val2 != 0x06)))) {
pr_debug("asb100.o: detect failed, "
"bad chip id 0x%02x!\n", val2);
return -ENODEV;
}
} /* kind < 0 */ /* If we're in bank 0 */
if ((!(val1 & 0x07)) &&
/* Check for ASB100 ID (low byte) */
(((!(val1 & 0x80)) && (val2 != 0x94)) ||
/* Check for ASB100 ID (high byte ) */
((val1 & 0x80) && (val2 != 0x06)))) {
pr_debug("asb100: detect failed, bad chip id 0x%02x!\n", val2);
return -ENODEV;
}
/* We have either had a force parameter, or we have already detected /* Put it now into bank 0 and Vendor ID High Byte */
Winbond. Put it now into bank 0 and Vendor ID High Byte */
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, i2c_smbus_write_byte_data(client, ASB100_REG_BANK,
(i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78)
| 0x80); | 0x80);
/* Determine the chip type. */ /* Determine the chip type. */
if (kind <= 0) { val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID);
int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
if (val1 != 0x31 || val2 != 0x06)
if ((val1 == 0x31) && (val2 == 0x06)) return -ENODEV;
kind = asb100;
else {
if (kind == 0)
dev_warn(&adapter->dev, "ignoring "
"'force' parameter for unknown chip "
"at adapter %d, address 0x%02x.\n",
i2c_adapter_id(adapter), client->addr);
return -ENODEV;
}
}
strlcpy(info->type, "asb100", I2C_NAME_SIZE); strlcpy(info->type, "asb100", I2C_NAME_SIZE);
......
...@@ -2220,33 +2220,23 @@ static int dme1737_i2c_detect(struct i2c_client *client, int kind, ...@@ -2220,33 +2220,23 @@ static int dme1737_i2c_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
} }
/* A negative kind means that the driver was loaded with no force company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
* parameter (default), so we must identify the chip. */ verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
if (kind < 0) {
company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
if (company == DME1737_COMPANY_SMSC &&
(verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
kind = dme1737;
} else if (company == DME1737_COMPANY_SMSC &&
verstep == SCH5027_VERSTEP) {
kind = sch5027;
} else {
return -ENODEV;
}
}
if (kind == sch5027) { if (company == DME1737_COMPANY_SMSC &&
verstep == SCH5027_VERSTEP) {
name = "sch5027"; name = "sch5027";
} else {
kind = dme1737; } else if (company == DME1737_COMPANY_SMSC &&
(verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
name = "dme1737"; name = "dme1737";
} else {
return -ENODEV;
} }
dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
kind == sch5027 ? "SCH5027" : "DME1737", client->addr, verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737",
verstep); client->addr, verstep);
strlcpy(info->type, name, I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -237,20 +237,16 @@ static int ds1621_detect(struct i2c_client *client, int kind, ...@@ -237,20 +237,16 @@ static int ds1621_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
/* Now, we do the remaining detection. It is lousy. */ /* Now, we do the remaining detection. It is lousy. */
if (kind < 0) { /* The NVB bit should be low if no EEPROM write has been requested
/* The NVB bit should be low if no EEPROM write has been during the latest 10ms, which is highly improbable in our case. */
requested during the latest 10ms, which is highly conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
improbable in our case. */ if (conf < 0 || conf & DS1621_REG_CONFIG_NVB)
conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); return -ENODEV;
if (conf < 0 || conf & DS1621_REG_CONFIG_NVB) /* The 7 lowest bits of a temperature should always be 0. */
for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) {
temp = i2c_smbus_read_word_data(client, DS1621_REG_TEMP[i]);
if (temp < 0 || (temp & 0x7f00))
return -ENODEV; return -ENODEV;
/* The 7 lowest bits of a temperature should always be 0. */
for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) {
temp = i2c_smbus_read_word_data(client,
DS1621_REG_TEMP[i]);
if (temp < 0 || (temp & 0x7f00))
return -ENODEV;
}
} }
strlcpy(info->type, "ds1621", I2C_NAME_SIZE); strlcpy(info->type, "ds1621", I2C_NAME_SIZE);
......
...@@ -681,30 +681,20 @@ static int f75375_detect(struct i2c_client *client, int kind, ...@@ -681,30 +681,20 @@ static int f75375_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
u8 version = 0; u16 vendid, chipid;
const char *name = ""; u8 version;
const char *name;
if (kind < 0) {
u16 vendid = f75375_read16(client, F75375_REG_VENDOR);
u16 chipid = f75375_read16(client, F75375_CHIP_ID);
version = f75375_read8(client, F75375_REG_VERSION);
if (chipid == 0x0306 && vendid == 0x1934) {
kind = f75375;
} else if (chipid == 0x0204 && vendid == 0x1934) {
kind = f75373;
} else {
dev_err(&adapter->dev,
"failed,%02X,%02X,%02X\n",
chipid, version, vendid);
return -ENODEV;
}
}
if (kind == f75375) { vendid = f75375_read16(client, F75375_REG_VENDOR);
chipid = f75375_read16(client, F75375_CHIP_ID);
if (chipid == 0x0306 && vendid == 0x1934)
name = "f75375"; name = "f75375";
} else if (kind == f75373) { else if (chipid == 0x0204 && vendid == 0x1934)
name = "f75373"; name = "f75373";
} else
return -ENODEV;
version = f75375_read8(client, F75375_REG_VERSION);
dev_info(&adapter->dev, "found %s version: %02X\n", name, version); dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
strlcpy(info->type, name, I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
......
...@@ -1000,43 +1000,38 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy) ...@@ -1000,43 +1000,38 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
} }
} }
static int fschmd_detect(struct i2c_client *client, int kind, static int fschmd_detect(struct i2c_client *client, int _kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
enum chips kind;
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
char id[4];
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
/* Detect & Identify the chip */ /* Detect & Identify the chip */
if (kind <= 0) { id[0] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_0);
char id[4]; id[1] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_1);
id[2] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_2);
id[0] = i2c_smbus_read_byte_data(client, id[3] = '\0';
FSCHMD_REG_IDENT_0);
id[1] = i2c_smbus_read_byte_data(client, if (!strcmp(id, "PEG"))
FSCHMD_REG_IDENT_1); kind = fscpos;
id[2] = i2c_smbus_read_byte_data(client, else if (!strcmp(id, "HER"))
FSCHMD_REG_IDENT_2); kind = fscher;
id[3] = '\0'; else if (!strcmp(id, "SCY"))
kind = fscscy;
if (!strcmp(id, "PEG")) else if (!strcmp(id, "HRC"))
kind = fscpos; kind = fschrc;
else if (!strcmp(id, "HER")) else if (!strcmp(id, "HMD"))
kind = fscher; kind = fschmd;
else if (!strcmp(id, "SCY")) else if (!strcmp(id, "HDS"))
kind = fscscy; kind = fschds;
else if (!strcmp(id, "HRC")) else if (!strcmp(id, "SYL"))
kind = fschrc; kind = fscsyl;
else if (!strcmp(id, "HMD")) else
kind = fschmd; return -ENODEV;
else if (!strcmp(id, "HDS"))
kind = fschds;
else if (!strcmp(id, "SYL"))
kind = fscsyl;
else
return -ENODEV;
}
strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE);
......
...@@ -488,36 +488,21 @@ static int gl518_detect(struct i2c_client *client, int kind, ...@@ -488,36 +488,21 @@ static int gl518_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int i; int rev;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA)) I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV; return -ENODEV;
/* Now, we do the remaining detection. */ /* Now, we do the remaining detection. */
if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
if (kind < 0) { || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) return -ENODEV;
|| (gl518_read_value(client, GL518_REG_CONF) & 0x80))
return -ENODEV;
}
/* Determine the chip type. */ /* Determine the chip type. */
if (kind <= 0) { rev = gl518_read_value(client, GL518_REG_REVISION);
i = gl518_read_value(client, GL518_REG_REVISION); if (rev != 0x00 && rev != 0x80)
if (i == 0x00) { return -ENODEV;
kind = gl518sm_r00;
} else if (i == 0x80) {
kind = gl518sm_r80;
} else {
if (kind <= 0)
dev_info(&adapter->dev,
"Ignoring 'force' parameter for unknown "
"chip at adapter %d, address 0x%02x\n",
i2c_adapter_id(adapter), client->addr);
return -ENODEV;
}
}
strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); strlcpy(info->type, "gl518sm", I2C_NAME_SIZE);
......
...@@ -691,13 +691,11 @@ static int gl520_detect(struct i2c_client *client, int kind, ...@@ -691,13 +691,11 @@ static int gl520_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
/* Determine the chip type. */ /* Determine the chip type. */
if (kind < 0) { if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) || ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { dev_dbg(&client->dev, "Unknown chip type, skipping\n");
dev_dbg(&client->dev, "Unknown chip type, skipping\n"); return -ENODEV;
return -ENODEV;
}
} }
strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
......
...@@ -427,40 +427,34 @@ static int lm63_detect(struct i2c_client *new_client, int kind, ...@@ -427,40 +427,34 @@ static int lm63_detect(struct i2c_client *new_client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = new_client->adapter;
u8 man_id, chip_id, reg_config1, reg_config2;
u8 reg_alert_status, reg_alert_mask;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
if (kind < 0) { /* must identify */ man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID);
u8 man_id, chip_id, reg_config1, reg_config2; chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID);
u8 reg_alert_status, reg_alert_mask;
reg_config1 = i2c_smbus_read_byte_data(new_client,
man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CONFIG1);
LM63_REG_MAN_ID); reg_config2 = i2c_smbus_read_byte_data(new_client,
chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CONFIG2);
LM63_REG_CHIP_ID); reg_alert_status = i2c_smbus_read_byte_data(new_client,
reg_config1 = i2c_smbus_read_byte_data(new_client, LM63_REG_ALERT_STATUS);
LM63_REG_CONFIG1); reg_alert_mask = i2c_smbus_read_byte_data(new_client,
reg_config2 = i2c_smbus_read_byte_data(new_client, LM63_REG_ALERT_MASK);
LM63_REG_CONFIG2);
reg_alert_status = i2c_smbus_read_byte_data(new_client, if (man_id != 0x01 /* National Semiconductor */
LM63_REG_ALERT_STATUS); || chip_id != 0x41 /* LM63 */
reg_alert_mask = i2c_smbus_read_byte_data(new_client, || (reg_config1 & 0x18) != 0x00
LM63_REG_ALERT_MASK); || (reg_config2 & 0xF8) != 0x00
|| (reg_alert_status & 0x20) != 0x00
if (man_id == 0x01 /* National Semiconductor */ || (reg_alert_mask & 0xA4) != 0xA4) {
&& chip_id == 0x41 /* LM63 */ dev_dbg(&adapter->dev,
&& (reg_config1 & 0x18) == 0x00 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
&& (reg_config2 & 0xF8) == 0x00 man_id, chip_id);
&& (reg_alert_status & 0x20) == 0x00 return -ENODEV;
&& (reg_alert_mask & 0xA4) == 0xA4) {
kind = lm63;
} else { /* failed */
dev_dbg(&adapter->dev, "Unsupported chip "
"(man_id=0x%02X, chip_id=0x%02X).\n",
man_id, chip_id);
return -ENODEV;
}
} }
strlcpy(info->type, "lm63", I2C_NAME_SIZE); strlcpy(info->type, "lm63", I2C_NAME_SIZE);
......
...@@ -239,6 +239,7 @@ static int lm75_detect(struct i2c_client *new_client, int kind, ...@@ -239,6 +239,7 @@ static int lm75_detect(struct i2c_client *new_client, int kind,
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = new_client->adapter;
int i; int i;
int cur, conf, hyst, os;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA)) I2C_FUNC_SMBUS_WORD_DATA))
...@@ -251,40 +252,35 @@ static int lm75_detect(struct i2c_client *new_client, int kind, ...@@ -251,40 +252,35 @@ static int lm75_detect(struct i2c_client *new_client, int kind,
The cycling+unused addresses combination is not tested, The cycling+unused addresses combination is not tested,
since it would significantly slow the detection down and would since it would significantly slow the detection down and would
hardly add any value. */ hardly add any value. */
if (kind < 0) {
int cur, conf, hyst, os;
/* Unused addresses */
cur = i2c_smbus_read_word_data(new_client, 0);
conf = i2c_smbus_read_byte_data(new_client, 1);
hyst = i2c_smbus_read_word_data(new_client, 2);
if (i2c_smbus_read_word_data(new_client, 4) != hyst
|| i2c_smbus_read_word_data(new_client, 5) != hyst
|| i2c_smbus_read_word_data(new_client, 6) != hyst
|| i2c_smbus_read_word_data(new_client, 7) != hyst)
return -ENODEV;
os = i2c_smbus_read_word_data(new_client, 3);
if (i2c_smbus_read_word_data(new_client, 4) != os
|| i2c_smbus_read_word_data(new_client, 5) != os
|| i2c_smbus_read_word_data(new_client, 6) != os
|| i2c_smbus_read_word_data(new_client, 7) != os)
return -ENODEV;
/* Unused bits */ /* Unused addresses */
if (conf & 0xe0) cur = i2c_smbus_read_word_data(new_client, 0);
return -ENODEV; conf = i2c_smbus_read_byte_data(new_client, 1);
hyst = i2c_smbus_read_word_data(new_client, 2);
if (i2c_smbus_read_word_data(new_client, 4) != hyst
|| i2c_smbus_read_word_data(new_client, 5) != hyst
|| i2c_smbus_read_word_data(new_client, 6) != hyst
|| i2c_smbus_read_word_data(new_client, 7) != hyst)
return -ENODEV;
os = i2c_smbus_read_word_data(new_client, 3);
if (i2c_smbus_read_word_data(new_client, 4) != os
|| i2c_smbus_read_word_data(new_client, 5) != os
|| i2c_smbus_read_word_data(new_client, 6) != os
|| i2c_smbus_read_word_data(new_client, 7) != os)
return -ENODEV;
/* Addresses cycling */ /* Unused bits */
for (i = 8; i < 0xff; i += 8) if (conf & 0xe0)
if (i2c_smbus_read_byte_data(new_client, i + 1) != conf return -ENODEV;
|| i2c_smbus_read_word_data(new_client, i + 2) != hyst
|| i2c_smbus_read_word_data(new_client, i + 3) != os) /* Addresses cycling */
return -ENODEV; for (i = 8; i < 0xff; i += 8) {
if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
|| i2c_smbus_read_word_data(new_client, i + 2) != hyst
|| i2c_smbus_read_word_data(new_client, i + 3) != os)
return -ENODEV;
} }
/* NOTE: we treat "force=..." and "force_lm75=..." the same.
* Only new-style driver binding distinguishes chip types.
*/
strlcpy(info->type, "lm75", I2C_NAME_SIZE); strlcpy(info->type, "lm75", I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -576,52 +576,34 @@ static int lm78_i2c_detect(struct i2c_client *client, int kind, ...@@ -576,52 +576,34 @@ static int lm78_i2c_detect(struct i2c_client *client, int kind,
if (isa) if (isa)
mutex_lock(&isa->update_lock); mutex_lock(&isa->update_lock);
if (kind < 0) { if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80)
if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80) || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) != address)
|| i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) goto err_nodev;
!= address)
goto err_nodev; /* Explicitly prevent the misdetection of Winbond chips */
i = i2c_smbus_read_byte_data(client, 0x4f);
/* Explicitly prevent the misdetection of Winbond chips */ if (i == 0xa3 || i == 0x5c)
i = i2c_smbus_read_byte_data(client, 0x4f); goto err_nodev;
if (i == 0xa3 || i == 0x5c)
goto err_nodev;
}
/* Determine the chip type. */ /* Determine the chip type. */
if (kind <= 0) { i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID);
i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID); if (i == 0x00 || i == 0x20 /* LM78 */
if (i == 0x00 || i == 0x20 /* LM78 */ || i == 0x40) /* LM78-J */
|| i == 0x40) /* LM78-J */ client_name = "lm78";
kind = lm78; else if ((i & 0xfe) == 0xc0)
else if ((i & 0xfe) == 0xc0) client_name = "lm79";
kind = lm79; else
else { goto err_nodev;
if (kind == 0)
dev_warn(&adapter->dev, "Ignoring 'force' "
"parameter for unknown chip at "
"adapter %d, address 0x%02x\n",
i2c_adapter_id(adapter), address);
goto err_nodev;
}
if (lm78_alias_detect(client, i)) { if (lm78_alias_detect(client, i)) {
dev_dbg(&adapter->dev, "Device at 0x%02x appears to " dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
"be the same as ISA device\n", address); "be the same as ISA device\n", address);
goto err_nodev; goto err_nodev;
}
} }
if (isa) if (isa)
mutex_unlock(&isa->update_lock); mutex_unlock(&isa->update_lock);
switch (kind) {
case lm79:
client_name = "lm79";
break;
default:
client_name = "lm78";
}
strlcpy(info->type, client_name, I2C_NAME_SIZE); strlcpy(info->type, client_name, I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -666,37 +666,32 @@ static int lm87_detect(struct i2c_client *new_client, int kind, ...@@ -666,37 +666,32 @@ static int lm87_detect(struct i2c_client *new_client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = new_client->adapter;
static const char *names[] = { "lm87", "adm1024" }; const char *name;
u8 cid, rev;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
/* Default to an LM87 if forced */ if (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)
if (kind == 0) return -ENODEV;
kind = lm87;
/* Now, we do the remaining detection. */ /* Now, we do the remaining detection. */
if (kind < 0) { cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID);
u8 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); rev = lm87_read_value(new_client, LM87_REG_REVISION);
u8 rev = lm87_read_value(new_client, LM87_REG_REVISION);
if (cid == 0x02 /* National Semiconductor */
if (cid == 0x02 /* National Semiconductor */ && (rev >= 0x01 && rev <= 0x08))
&& (rev >= 0x01 && rev <= 0x08)) name = "lm87";
kind = lm87; else if (cid == 0x41 /* Analog Devices */
else if (cid == 0x41 /* Analog Devices */ && (rev & 0xf0) == 0x10)
&& (rev & 0xf0) == 0x10) name = "adm1024";
kind = adm1024; else {
dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n",
if (kind < 0 new_client->addr);
|| (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { return -ENODEV;
dev_dbg(&adapter->dev,
"LM87 detection failed at 0x%02x.\n",
new_client->addr);
return -ENODEV;
}
} }
strlcpy(info->type, names[kind - 1], I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
return 0; return 0;
} }
......
...@@ -323,31 +323,22 @@ static int lm92_detect(struct i2c_client *new_client, int kind, ...@@ -323,31 +323,22 @@ static int lm92_detect(struct i2c_client *new_client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = new_client->adapter;
u8 config;
u16 man_id;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA)) | I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV; return -ENODEV;
/* A negative kind means that the driver was loaded with no force config = i2c_smbus_read_byte_data(new_client, LM92_REG_CONFIG);
parameter (default), so we must identify the chip. */ man_id = i2c_smbus_read_word_data(new_client, LM92_REG_MAN_ID);
if (kind < 0) {
u8 config = i2c_smbus_read_byte_data(new_client, if ((config & 0xe0) == 0x00 && man_id == 0x0180)
LM92_REG_CONFIG); pr_info("lm92: Found National Semiconductor LM92 chip\n");
u16 man_id = i2c_smbus_read_word_data(new_client, else if (max6635_check(new_client))
LM92_REG_MAN_ID); pr_info("lm92: Found Maxim MAX6635 chip\n");
else
if ((config & 0xe0) == 0x00 return -ENODEV;
&& man_id == 0x0180) {
pr_info("lm92: Found National Semiconductor LM92 chip\n");
kind = lm92;
} else
if (max6635_check(new_client)) {
pr_info("lm92: Found Maxim MAX6635 chip\n");
kind = lm92; /* No separate prefix */
}
else
return -ENODEV;
}
strlcpy(info->type, "lm92", I2C_NAME_SIZE); strlcpy(info->type, "lm92", I2C_NAME_SIZE);
......
...@@ -2505,34 +2505,24 @@ static int lm93_detect(struct i2c_client *client, int kind, ...@@ -2505,34 +2505,24 @@ static int lm93_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int mfr, ver;
if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN))
return -ENODEV; return -ENODEV;
/* detection */ /* detection */
if (kind < 0) { mfr = lm93_read_byte(client, LM93_REG_MFR_ID);
int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); if (mfr != 0x01) {
dev_dbg(&adapter->dev,
if (mfr != 0x01) { "detect failed, bad manufacturer id 0x%02x!\n", mfr);
dev_dbg(&adapter->dev,"detect failed, " return -ENODEV;
"bad manufacturer id 0x%02x!\n", mfr);
return -ENODEV;
}
} }
if (kind <= 0) { ver = lm93_read_byte(client, LM93_REG_VER);
int ver = lm93_read_byte(client, LM93_REG_VER); if (ver != LM93_MFR_ID && ver != LM93_MFR_ID_PROTOTYPE) {
dev_dbg(&adapter->dev,
if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { "detect failed, bad version id 0x%02x!\n", ver);
kind = lm93; return -ENODEV;
} else {
dev_dbg(&adapter->dev,"detect failed, "
"bad version id 0x%02x!\n", ver);
if (kind == 0)
dev_dbg(&adapter->dev,
"(ignored 'force' parameter)\n");
return -ENODEV;
}
} }
strlcpy(info->type, "lm93", I2C_NAME_SIZE); strlcpy(info->type, "lm93", I2C_NAME_SIZE);
......
...@@ -315,51 +315,23 @@ static int lm95241_detect(struct i2c_client *new_client, int kind, ...@@ -315,51 +315,23 @@ static int lm95241_detect(struct i2c_client *new_client, int kind,
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = new_client->adapter;
int address = new_client->addr; int address = new_client->addr;
const char *name = ""; const char *name;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
/* if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
* Now we do the remaining detection. A negative kind means that == MANUFACTURER_ID)
* the driver was loaded with no force parameter (default), so we && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
* must both detect and identify the chip. A zero kind means that >= DEFAULT_REVISION)) {
* the driver was loaded with the force parameter, the detection name = "lm95241";
* step shall be skipped. A positive kind means that the driver } else {
* was loaded with the force parameter and a given kind of chip is dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n",
* requested, so both the detection and the identification steps address);
* are skipped. return -ENODEV;
*/
if (kind < 0) { /* detection */
if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
!= MANUFACTURER_ID)
|| (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
< DEFAULT_REVISION)) {
dev_dbg(&adapter->dev,
"LM95241 detection failed at 0x%02x.\n",
address);
return -ENODEV;
}
}
if (kind <= 0) { /* identification */
if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
== MANUFACTURER_ID)
&& (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
>= DEFAULT_REVISION)) {
kind = lm95241;
if (kind <= 0) { /* identification failed */
dev_info(&adapter->dev, "Unsupported chip\n");
return -ENODEV;
}
}
} }
/* Fill the i2c board info */ /* Fill the i2c board info */
if (kind == lm95241)
name = "lm95241";
strlcpy(info->type, name, I2C_NAME_SIZE); strlcpy(info->type, name, I2C_NAME_SIZE);
return 0; return 0;
} }
......
...@@ -226,58 +226,34 @@ static const struct attribute_group max1619_group = { ...@@ -226,58 +226,34 @@ static const struct attribute_group max1619_group = {
*/ */
/* Return 0 if detection is successful, -ENODEV otherwise */ /* Return 0 if detection is successful, -ENODEV otherwise */
static int max1619_detect(struct i2c_client *new_client, int kind, static int max1619_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = new_client->adapter; struct i2c_adapter *adapter = client->adapter;
u8 reg_config=0, reg_convrate=0, reg_status=0; u8 reg_config, reg_convrate, reg_status, man_id, chip_id;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
/* /* detection */
* Now we do the remaining detection. A negative kind means that reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG);
* the driver was loaded with no force parameter (default), so we reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONVRATE);
* must both detect and identify the chip. A zero kind means that reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_R_STATUS);
* the driver was loaded with the force parameter, the detection if ((reg_config & 0x03) != 0x00
* step shall be skipped. A positive kind means that the driver || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) {
* was loaded with the force parameter and a given kind of chip is dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n",
* requested, so both the detection and the identification steps client->addr);
* are skipped. return -ENODEV;
*/
if (kind < 0) { /* detection */
reg_config = i2c_smbus_read_byte_data(new_client,
MAX1619_REG_R_CONFIG);
reg_convrate = i2c_smbus_read_byte_data(new_client,
MAX1619_REG_R_CONVRATE);
reg_status = i2c_smbus_read_byte_data(new_client,
MAX1619_REG_R_STATUS);
if ((reg_config & 0x03) != 0x00
|| reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) {
dev_dbg(&adapter->dev,
"MAX1619 detection failed at 0x%02x.\n",
new_client->addr);
return -ENODEV;
}
} }
if (kind <= 0) { /* identification */ /* identification */
u8 man_id, chip_id; man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_MAN_ID);
chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CHIP_ID);
man_id = i2c_smbus_read_byte_data(new_client, if (man_id != 0x4D || chip_id != 0x04) {
MAX1619_REG_R_MAN_ID); dev_info(&adapter->dev,
chip_id = i2c_smbus_read_byte_data(new_client, "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n",
MAX1619_REG_R_CHIP_ID); man_id, chip_id);
return -ENODEV;
if ((man_id == 0x4D) && (chip_id == 0x04))
kind = max1619;
if (kind <= 0) { /* identification failed */
dev_info(&adapter->dev,
"Unsupported chip (man_id=0x%02X, "
"chip_id=0x%02X).\n", man_id, chip_id);
return -ENODEV;
}
} }
strlcpy(info->type, "max1619", I2C_NAME_SIZE); strlcpy(info->type, "max1619", I2C_NAME_SIZE);
......
...@@ -534,7 +534,7 @@ static int max6650_detect(struct i2c_client *client, int kind, ...@@ -534,7 +534,7 @@ static int max6650_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;
dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); dev_dbg(&adapter->dev, "max6650_detect called\n");
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support "
...@@ -542,23 +542,7 @@ static int max6650_detect(struct i2c_client *client, int kind, ...@@ -542,23 +542,7 @@ static int max6650_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
} }
/* if (((i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
* Now we do the remaining detection. A negative kind means that
* the driver was loaded with no force parameter (default), so we
* must both detect and identify the chip (actually there is only
* one possible kind of chip for now, max6650). A zero kind means that
* the driver was loaded with the force parameter, the detection
* step shall be skipped. A positive kind means that the driver
* was loaded with the force parameter and a given kind of chip is
* requested, so both the detection and the identification steps
* are skipped.
*
* Currently I can find no way to distinguish between a MAX6650 and
* a MAX6651. This driver has only been tried on the former.
*/
if ((kind < 0) &&
( (i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0) ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0)
||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0) ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0)
||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0) ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0)
......
...@@ -491,24 +491,22 @@ static int smsc47m192_detect(struct i2c_client *client, int kind, ...@@ -491,24 +491,22 @@ static int smsc47m192_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
/* Detection criteria from sensors_detect script */ /* Detection criteria from sensors_detect script */
if (kind < 0) { version = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VERSION);
if (i2c_smbus_read_byte_data(client, if (i2c_smbus_read_byte_data(client,
SMSC47M192_REG_COMPANY_ID) == 0x55 SMSC47M192_REG_COMPANY_ID) == 0x55
&& ((version = i2c_smbus_read_byte_data(client, && (version & 0xf0) == 0x20
SMSC47M192_REG_VERSION)) & 0xf0) == 0x20 && (i2c_smbus_read_byte_data(client,
&& (i2c_smbus_read_byte_data(client,
SMSC47M192_REG_VID) & 0x70) == 0x00 SMSC47M192_REG_VID) & 0x70) == 0x00
&& (i2c_smbus_read_byte_data(client, && (i2c_smbus_read_byte_data(client,
SMSC47M192_REG_VID4) & 0xfe) == 0x80) { SMSC47M192_REG_VID4) & 0xfe) == 0x80) {
dev_info(&adapter->dev, dev_info(&adapter->dev,
"found SMSC47M192 or compatible, " "found SMSC47M192 or compatible, "
"version 2, stepping A%d\n", version & 0x0f); "version 2, stepping A%d\n", version & 0x0f);
} else { } else {
dev_dbg(&adapter->dev, dev_dbg(&adapter->dev,
"SMSC47M192 detection failed at 0x%02x\n", "SMSC47M192 detection failed at 0x%02x\n",
client->addr); client->addr);
return -ENODEV; return -ENODEV;
}
} }
strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE);
......
...@@ -289,7 +289,6 @@ static int thmc50_detect(struct i2c_client *client, int kind, ...@@ -289,7 +289,6 @@ static int thmc50_detect(struct i2c_client *client, int kind,
unsigned revision; unsigned revision;
unsigned config; unsigned config;
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int err = 0;
const char *type_name; const char *type_name;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
...@@ -301,31 +300,13 @@ static int thmc50_detect(struct i2c_client *client, int kind, ...@@ -301,31 +300,13 @@ static int thmc50_detect(struct i2c_client *client, int kind,
pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n",
client->addr, i2c_adapter_id(client->adapter)); client->addr, i2c_adapter_id(client->adapter));
/* Now, we do the remaining detection. */
company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID); company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID);
revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE); revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE);
config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
if (revision < 0xc0 || (config & 0x10))
return -ENODEV;
if (kind == 0) if (company == 0x41) {
kind = thmc50;
else if (kind < 0) {
err = -ENODEV;
if (revision >= 0xc0 && ((config & 0x10) == 0)) {
if (company == 0x49) {
kind = thmc50;
err = 0;
} else if (company == 0x41) {
kind = adm1022;
err = 0;
}
}
}
if (err == -ENODEV) {
pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
return err;
}
if (kind == adm1022) {
int id = i2c_adapter_id(client->adapter); int id = i2c_adapter_id(client->adapter);
int i; int i;
...@@ -340,9 +321,13 @@ static int thmc50_detect(struct i2c_client *client, int kind, ...@@ -340,9 +321,13 @@ static int thmc50_detect(struct i2c_client *client, int kind,
config); config);
break; break;
} }
} else { } else if (company == 0x49) {
type_name = "thmc50"; type_name = "thmc50";
} else {
pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
return -ENODEV;
} }
pr_debug("thmc50: Detected %s (version %x, revision %x)\n", pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
type_name, (revision >> 4) - 0xc, revision & 0xf); type_name, (revision >> 4) - 0xc, revision & 0xf);
......
...@@ -1164,7 +1164,7 @@ w83793_detect_subclients(struct i2c_client *client) ...@@ -1164,7 +1164,7 @@ w83793_detect_subclients(struct i2c_client *client)
static int w83793_detect(struct i2c_client *client, int kind, static int w83793_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
u8 tmp, bank; u8 tmp, bank, chip_id;
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
unsigned short address = client->addr; unsigned short address = client->addr;
...@@ -1174,44 +1174,27 @@ static int w83793_detect(struct i2c_client *client, int kind, ...@@ -1174,44 +1174,27 @@ static int w83793_detect(struct i2c_client *client, int kind,
bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
if (kind < 0) { tmp = bank & 0x80 ? 0x5c : 0xa3;
tmp = bank & 0x80 ? 0x5c : 0xa3; /* Check Winbond vendor ID */
/* Check Winbond vendor ID */ if (tmp != i2c_smbus_read_byte_data(client, W83793_REG_VENDORID)) {
if (tmp != i2c_smbus_read_byte_data(client, pr_debug("w83793: Detection failed at check vendor id\n");
W83793_REG_VENDORID)) { return -ENODEV;
pr_debug("w83793: Detection failed at check "
"vendor id\n");
return -ENODEV;
}
/* If Winbond chip, address of chip and W83793_REG_I2C_ADDR
should match */
if ((bank & 0x07) == 0
&& i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
(address << 1)) {
pr_debug("w83793: Detection failed at check "
"i2c addr\n");
return -ENODEV;
}
} }
/* We have either had a force parameter, or we have already detected the /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR
Winbond. Determine the chip type now */ should match */
if ((bank & 0x07) == 0
if (kind <= 0) { && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
if (0x7b == i2c_smbus_read_byte_data(client, (address << 1)) {
W83793_REG_CHIPID)) { pr_debug("w83793: Detection failed at check i2c addr\n");
kind = w83793; return -ENODEV;
} else {
if (kind == 0)
dev_warn(&adapter->dev, "w83793: Ignoring "
"'force' parameter for unknown chip "
"at address 0x%02x\n", address);
return -ENODEV;
}
} }
/* Determine the chip type now */
chip_id = i2c_smbus_read_byte_data(client, W83793_REG_CHIPID);
if (chip_id != 0x7b)
return -ENODEV;
strlcpy(info->type, "w83793", I2C_NAME_SIZE); strlcpy(info->type, "w83793", I2C_NAME_SIZE);
return 0; return 0;
......
...@@ -590,53 +590,31 @@ w83l786ng_detect(struct i2c_client *client, int kind, ...@@ -590,53 +590,31 @@ w83l786ng_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info) struct i2c_board_info *info)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
u16 man_id;
u8 chip_id;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
return -ENODEV; return -ENODEV;
} }
/* /* Detection */
* Now we do the remaining detection. A negative kind means that if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) {
* the driver was loaded with no force parameter (default), so we dev_dbg(&adapter->dev, "W83L786NG detection failed at 0x%02x\n",
* must both detect and identify the chip (actually there is only client->addr);
* one possible kind of chip for now, W83L786NG). A zero kind means return -ENODEV;
* that the driver was loaded with the force parameter, the detection
* step shall be skipped. A positive kind means that the driver
* was loaded with the force parameter and a given kind of chip is
* requested, so both the detection and the identification steps
* are skipped.
*/
if (kind < 0) { /* detection */
if (((w83l786ng_read_value(client,
W83L786NG_REG_CONFIG) & 0x80) != 0x00)) {
dev_dbg(&adapter->dev,
"W83L786NG detection failed at 0x%02x.\n",
client->addr);
return -ENODEV;
}
} }
if (kind <= 0) { /* identification */ /* Identification */
u16 man_id; man_id = (w83l786ng_read_value(client, W83L786NG_REG_MAN_ID1) << 8) +
u8 chip_id; w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
man_id = (w83l786ng_read_value(client,
W83L786NG_REG_MAN_ID1) << 8) +
w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
if (man_id == 0x5CA3) { /* Winbond */
if (chip_id == 0x80) { /* W83L786NG */
kind = w83l786ng;
}
}
if (kind <= 0) { /* identification failed */ if (man_id != 0x5CA3 || /* Winbond */
dev_info(&adapter->dev, chip_id != 0x80) { /* W83L786NG */
"Unsupported chip (man_id=0x%04X, " dev_dbg(&adapter->dev,
"chip_id=0x%02X).\n", man_id, chip_id); "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
return -ENODEV; man_id, chip_id);
} return -ENODEV;
} }
strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册