diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-07-24 14:37:05 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-07-28 23:16:36 -0400 |
commit | f90be42fb383f39aa814b8e14de138da8973e5c1 (patch) | |
tree | c32c4a3d2d1c07e11cdb605c682af1a00e731634 /drivers/hwmon | |
parent | 6d101c588f0fe08ef00f16c1a93762dd5d563df7 (diff) |
hwmon: (lm90) Refactor reading of config2 register
Several vendors implement a second configuration register, which we
check during device detection. Refactor the code to avoid duplication.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Stijn Devriendt <sdevrien@cisco.com>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm90.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 7c6a3df36d86..90ddb8774210 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -1111,7 +1111,7 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1111 | struct i2c_adapter *adapter = new_client->adapter; | 1111 | struct i2c_adapter *adapter = new_client->adapter; |
1112 | int address = new_client->addr; | 1112 | int address = new_client->addr; |
1113 | const char *name = NULL; | 1113 | const char *name = NULL; |
1114 | int man_id, chip_id, reg_config1, reg_convrate; | 1114 | int man_id, chip_id, reg_config1, reg_config2, reg_convrate; |
1115 | 1115 | ||
1116 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1116 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1117 | return -ENODEV; | 1117 | return -ENODEV; |
@@ -1127,15 +1127,16 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1127 | LM90_REG_R_CONVRATE)) < 0) | 1127 | LM90_REG_R_CONVRATE)) < 0) |
1128 | return -ENODEV; | 1128 | return -ENODEV; |
1129 | 1129 | ||
1130 | if ((address == 0x4C || address == 0x4D) | 1130 | if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { |
1131 | && man_id == 0x01) { /* National Semiconductor */ | ||
1132 | int reg_config2; | ||
1133 | |||
1134 | reg_config2 = i2c_smbus_read_byte_data(new_client, | 1131 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
1135 | LM90_REG_R_CONFIG2); | 1132 | LM90_REG_R_CONFIG2); |
1136 | if (reg_config2 < 0) | 1133 | if (reg_config2 < 0) |
1137 | return -ENODEV; | 1134 | return -ENODEV; |
1135 | } else | ||
1136 | reg_config2 = 0; /* Make compiler happy */ | ||
1138 | 1137 | ||
1138 | if ((address == 0x4C || address == 0x4D) | ||
1139 | && man_id == 0x01) { /* National Semiconductor */ | ||
1139 | if ((reg_config1 & 0x2A) == 0x00 | 1140 | if ((reg_config1 & 0x2A) == 0x00 |
1140 | && (reg_config2 & 0xF8) == 0x00 | 1141 | && (reg_config2 & 0xF8) == 0x00 |
1141 | && reg_convrate <= 0x09) { | 1142 | && reg_convrate <= 0x09) { |
@@ -1264,13 +1265,6 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1264 | } else | 1265 | } else |
1265 | if (address == 0x4C | 1266 | if (address == 0x4C |
1266 | && man_id == 0x5C) { /* Winbond/Nuvoton */ | 1267 | && man_id == 0x5C) { /* Winbond/Nuvoton */ |
1267 | int reg_config2; | ||
1268 | |||
1269 | reg_config2 = i2c_smbus_read_byte_data(new_client, | ||
1270 | LM90_REG_R_CONFIG2); | ||
1271 | if (reg_config2 < 0) | ||
1272 | return -ENODEV; | ||
1273 | |||
1274 | if ((reg_config1 & 0x2A) == 0x00 | 1268 | if ((reg_config1 & 0x2A) == 0x00 |
1275 | && (reg_config2 & 0xF8) == 0x00) { | 1269 | && (reg_config2 & 0xF8) == 0x00) { |
1276 | if (chip_id == 0x01 /* W83L771W/G */ | 1270 | if (chip_id == 0x01 /* W83L771W/G */ |
@@ -1285,13 +1279,6 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1285 | } else | 1279 | } else |
1286 | if (address >= 0x48 && address <= 0x4F | 1280 | if (address >= 0x48 && address <= 0x4F |
1287 | && man_id == 0xA1) { /* NXP Semiconductor/Philips */ | 1281 | && man_id == 0xA1) { /* NXP Semiconductor/Philips */ |
1288 | int reg_config2; | ||
1289 | |||
1290 | reg_config2 = i2c_smbus_read_byte_data(new_client, | ||
1291 | LM90_REG_R_CONFIG2); | ||
1292 | if (reg_config2 < 0) | ||
1293 | return -ENODEV; | ||
1294 | |||
1295 | if (chip_id == 0x00 | 1282 | if (chip_id == 0x00 |
1296 | && (reg_config1 & 0x2A) == 0x00 | 1283 | && (reg_config1 & 0x2A) == 0x00 |
1297 | && (reg_config2 & 0xFE) == 0x00 | 1284 | && (reg_config2 & 0xFE) == 0x00 |