Commit 3f8b8459 authored by Jean Delvare's avatar Jean Delvare

hwmon: (w83791d) Clean up detect function

As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarMarc Hulsman <m.hulsman@tudelft.nl>
parent bab2bf44
...@@ -1270,56 +1270,32 @@ static int w83791d_detect(struct i2c_client *client, int kind, ...@@ -1270,56 +1270,32 @@ static int w83791d_detect(struct i2c_client *client, int kind,
return -ENODEV; return -ENODEV;
} }
/* The w83791d may be stuck in some other bank than bank 0. This may if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80)
make reading other information impossible. Specify a force=... return -ENODEV;
parameter, and the Winbond will be reset to the right bank. */
if (kind < 0) { val1 = w83791d_read(client, W83791D_REG_BANK);
if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { val2 = w83791d_read(client, W83791D_REG_CHIPMAN);
return -ENODEV; /* Check for Winbond ID if in bank 0 */
} if (!(val1 & 0x07)) {
val1 = w83791d_read(client, W83791D_REG_BANK); if ((!(val1 & 0x80) && val2 != 0xa3) ||
val2 = w83791d_read(client, W83791D_REG_CHIPMAN); ( (val1 & 0x80) && val2 != 0x5c)) {
/* Check for Winbond ID if in bank 0 */
if (!(val1 & 0x07)) {
/* yes it is Bank0 */
if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
((val1 & 0x80) && (val2 != 0x5c))) {
return -ENODEV;
}
}
/* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR
should match */
if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) {
return -ENODEV; return -ENODEV;
} }
} }
/* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR
should match */
if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address)
return -ENODEV;
/* We either have a force parameter or we have reason to /* We want bank 0 and Vendor ID high byte */
believe it is a Winbond chip. Either way, we want bank 0 and
Vendor ID high byte */
val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78; val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78;
w83791d_write(client, W83791D_REG_BANK, val1 | 0x80); w83791d_write(client, W83791D_REG_BANK, val1 | 0x80);
/* Verify it is a Winbond w83791d */ /* Verify it is a Winbond w83791d */
if (kind <= 0) { val1 = w83791d_read(client, W83791D_REG_WCHIPID);
/* get vendor ID */ val2 = w83791d_read(client, W83791D_REG_CHIPMAN);
val2 = w83791d_read(client, W83791D_REG_CHIPMAN); if (val1 != 0x71 || val2 != 0x5c)
if (val2 != 0x5c) { /* the vendor is NOT Winbond */ return -ENODEV;
return -ENODEV;
}
val1 = w83791d_read(client, W83791D_REG_WCHIPID);
if (val1 == 0x71) {
kind = w83791d;
} else {
if (kind == 0)
dev_warn(&adapter->dev,
"w83791d: Ignoring 'force' parameter "
"for unknown chip at adapter %d, "
"address 0x%02x\n",
i2c_adapter_id(adapter), address);
return -ENODEV;
}
}
strlcpy(info->type, "w83791d", I2C_NAME_SIZE); strlcpy(info->type, "w83791d", I2C_NAME_SIZE);
......
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