diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:55 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:55 -0500 |
commit | 3f8b845940c8344e88123bead66b5a871e6366df (patch) | |
tree | 74afb7c7057510c889041d2cfbab7cb38868b1e3 /drivers/hwmon/w83791d.c | |
parent | bab2bf44f80a5749fdf69f854247e912353142b2 (diff) |
hwmon: (w83791d) 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>
Acked-by: Marc Hulsman <m.hulsman@tudelft.nl>
Diffstat (limited to 'drivers/hwmon/w83791d.c')
-rw-r--r-- | drivers/hwmon/w83791d.c | 60 |
1 files changed, 18 insertions, 42 deletions
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 97851c5ba3a3..0410bf12c521 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -1270,56 +1270,32 @@ static int w83791d_detect(struct i2c_client *client, int kind, | |||
1270 | return -ENODEV; | 1270 | return -ENODEV; |
1271 | } | 1271 | } |
1272 | 1272 | ||
1273 | /* The w83791d may be stuck in some other bank than bank 0. This may | 1273 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) |
1274 | make reading other information impossible. Specify a force=... | 1274 | return -ENODEV; |
1275 | parameter, and the Winbond will be reset to the right bank. */ | 1275 | |
1276 | if (kind < 0) { | 1276 | val1 = w83791d_read(client, W83791D_REG_BANK); |
1277 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { | 1277 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
1278 | return -ENODEV; | 1278 | /* Check for Winbond ID if in bank 0 */ |
1279 | } | 1279 | if (!(val1 & 0x07)) { |
1280 | val1 = w83791d_read(client, W83791D_REG_BANK); | 1280 | if ((!(val1 & 0x80) && val2 != 0xa3) || |
1281 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 1281 | ( (val1 & 0x80) && val2 != 0x5c)) { |
1282 | /* Check for Winbond ID if in bank 0 */ | ||
1283 | if (!(val1 & 0x07)) { | ||
1284 | /* yes it is Bank0 */ | ||
1285 | if (((!(val1 & 0x80)) && (val2 != 0xa3)) || | ||
1286 | ((val1 & 0x80) && (val2 != 0x5c))) { | ||
1287 | return -ENODEV; | ||
1288 | } | ||
1289 | } | ||
1290 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR | ||
1291 | should match */ | ||
1292 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) { | ||
1293 | return -ENODEV; | 1282 | return -ENODEV; |
1294 | } | 1283 | } |
1295 | } | 1284 | } |
1285 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR | ||
1286 | should match */ | ||
1287 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) | ||
1288 | return -ENODEV; | ||
1296 | 1289 | ||
1297 | /* We either have a force parameter or we have reason to | 1290 | /* We want bank 0 and Vendor ID high byte */ |
1298 | believe it is a Winbond chip. Either way, we want bank 0 and | ||
1299 | Vendor ID high byte */ | ||
1300 | val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78; | 1291 | val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78; |
1301 | w83791d_write(client, W83791D_REG_BANK, val1 | 0x80); | 1292 | w83791d_write(client, W83791D_REG_BANK, val1 | 0x80); |
1302 | 1293 | ||
1303 | /* Verify it is a Winbond w83791d */ | 1294 | /* Verify it is a Winbond w83791d */ |
1304 | if (kind <= 0) { | 1295 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); |
1305 | /* get vendor ID */ | 1296 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); |
1306 | val2 = w83791d_read(client, W83791D_REG_CHIPMAN); | 1297 | if (val1 != 0x71 || val2 != 0x5c) |
1307 | if (val2 != 0x5c) { /* the vendor is NOT Winbond */ | 1298 | return -ENODEV; |
1308 | return -ENODEV; | ||
1309 | } | ||
1310 | val1 = w83791d_read(client, W83791D_REG_WCHIPID); | ||
1311 | if (val1 == 0x71) { | ||
1312 | kind = w83791d; | ||
1313 | } else { | ||
1314 | if (kind == 0) | ||
1315 | dev_warn(&adapter->dev, | ||
1316 | "w83791d: Ignoring 'force' parameter " | ||
1317 | "for unknown chip at adapter %d, " | ||
1318 | "address 0x%02x\n", | ||
1319 | i2c_adapter_id(adapter), address); | ||
1320 | return -ENODEV; | ||
1321 | } | ||
1322 | } | ||
1323 | 1299 | ||
1324 | strlcpy(info->type, "w83791d", I2C_NAME_SIZE); | 1300 | strlcpy(info->type, "w83791d", I2C_NAME_SIZE); |
1325 | 1301 | ||