diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:56 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:56 -0500 |
commit | 2de1875a5894794b42fce3833cddf4eac55831de (patch) | |
tree | 3ef1865a45346904b796e4f9042858526b1873f9 /drivers/hwmon | |
parent | 3f8b845940c8344e88123bead66b5a871e6366df (diff) |
hwmon: (w83792d) 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')
-rw-r--r-- | drivers/hwmon/w83792d.c | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 2be16194ddf3..38978851333f 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -1273,58 +1273,33 @@ w83792d_detect(struct i2c_client *client, int kind, struct i2c_board_info *info) | |||
1273 | return -ENODEV; | 1273 | return -ENODEV; |
1274 | } | 1274 | } |
1275 | 1275 | ||
1276 | /* The w83792d may be stuck in some other bank than bank 0. This may | 1276 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) |
1277 | make reading other information impossible. Specify a force=... or | 1277 | return -ENODEV; |
1278 | force_*=... parameter, and the Winbond will be reset to the right | 1278 | |
1279 | bank. */ | 1279 | val1 = w83792d_read_value(client, W83792D_REG_BANK); |
1280 | if (kind < 0) { | 1280 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
1281 | if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { | 1281 | /* Check for Winbond ID if in bank 0 */ |
1282 | return -ENODEV; | 1282 | if (!(val1 & 0x07)) { /* is Bank0 */ |
1283 | } | 1283 | if ((!(val1 & 0x80) && val2 != 0xa3) || |
1284 | val1 = w83792d_read_value(client, W83792D_REG_BANK); | 1284 | ( (val1 & 0x80) && val2 != 0x5c)) |
1285 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | ||
1286 | /* Check for Winbond ID if in bank 0 */ | ||
1287 | if (!(val1 & 0x07)) { /* is Bank0 */ | ||
1288 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | ||
1289 | ((val1 & 0x80) && (val2 != 0x5c))) { | ||
1290 | return -ENODEV; | ||
1291 | } | ||
1292 | } | ||
1293 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR | ||
1294 | should match */ | ||
1295 | if (w83792d_read_value(client, | ||
1296 | W83792D_REG_I2C_ADDR) != address) { | ||
1297 | return -ENODEV; | 1285 | return -ENODEV; |
1298 | } | ||
1299 | } | 1286 | } |
1287 | /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR | ||
1288 | should match */ | ||
1289 | if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address) | ||
1290 | return -ENODEV; | ||
1300 | 1291 | ||
1301 | /* We have either had a force parameter, or we have already detected the | 1292 | /* Put it now into bank 0 and Vendor ID High Byte */ |
1302 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ | ||
1303 | w83792d_write_value(client, | 1293 | w83792d_write_value(client, |
1304 | W83792D_REG_BANK, | 1294 | W83792D_REG_BANK, |
1305 | (w83792d_read_value(client, | 1295 | (w83792d_read_value(client, |
1306 | W83792D_REG_BANK) & 0x78) | 0x80); | 1296 | W83792D_REG_BANK) & 0x78) | 0x80); |
1307 | 1297 | ||
1308 | /* Determine the chip type. */ | 1298 | /* Determine the chip type. */ |
1309 | if (kind <= 0) { | 1299 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); |
1310 | /* get vendor ID */ | 1300 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); |
1311 | val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); | 1301 | if (val1 != 0x7a || val2 != 0x5c) |
1312 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1302 | return -ENODEV; |
1313 | return -ENODEV; | ||
1314 | } | ||
1315 | val1 = w83792d_read_value(client, W83792D_REG_WCHIPID); | ||
1316 | if (val1 == 0x7a) { | ||
1317 | kind = w83792d; | ||
1318 | } else { | ||
1319 | if (kind == 0) | ||
1320 | dev_warn(&adapter->dev, | ||
1321 | "w83792d: Ignoring 'force' parameter for" | ||
1322 | " unknown chip at adapter %d, address" | ||
1323 | " 0x%02x\n", i2c_adapter_id(adapter), | ||
1324 | address); | ||
1325 | return -ENODEV; | ||
1326 | } | ||
1327 | } | ||
1328 | 1303 | ||
1329 | strlcpy(info->type, "w83792d", I2C_NAME_SIZE); | 1304 | strlcpy(info->type, "w83792d", I2C_NAME_SIZE); |
1330 | 1305 | ||