diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-11-04 07:00:47 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-11-04 07:00:47 -0400 |
commit | b2589ab02b46ea4a80b30a90fc2fe8eed957e86a (patch) | |
tree | 716e89b006bdf17ff4c4859f3f2cf523ff18701a /drivers/hwmon/lm90.c | |
parent | 8dc089d68b125179b1c97e75d29623472d99c68b (diff) |
hwmon: (lm90) Make code more readable
Clean up the code to make it more readable:
* Remove reg_ and new_ prefixes from variable names, they made the
names longer, causing extra line breaks, while not adding much
value.
* Introduce struct device dev* = &client->dev in two functions, to
avoid repeating client->dev everywhere in these functions.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r-- | drivers/hwmon/lm90.c | 143 |
1 files changed, 69 insertions, 74 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 60b3e3030277..615bc4f4e530 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -1105,39 +1105,37 @@ static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec); | |||
1105 | */ | 1105 | */ |
1106 | 1106 | ||
1107 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 1107 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1108 | static int lm90_detect(struct i2c_client *new_client, | 1108 | static int lm90_detect(struct i2c_client *client, |
1109 | struct i2c_board_info *info) | 1109 | struct i2c_board_info *info) |
1110 | { | 1110 | { |
1111 | struct i2c_adapter *adapter = new_client->adapter; | 1111 | struct i2c_adapter *adapter = client->adapter; |
1112 | int address = new_client->addr; | 1112 | int address = client->addr; |
1113 | const char *name = NULL; | 1113 | const char *name = NULL; |
1114 | int man_id, chip_id, reg_config1, reg_config2, reg_convrate; | 1114 | int man_id, chip_id, config1, config2, 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; |
1118 | 1118 | ||
1119 | /* detection and identification */ | 1119 | /* detection and identification */ |
1120 | man_id = i2c_smbus_read_byte_data(new_client, LM90_REG_R_MAN_ID); | 1120 | man_id = i2c_smbus_read_byte_data(client, LM90_REG_R_MAN_ID); |
1121 | chip_id = i2c_smbus_read_byte_data(new_client, LM90_REG_R_CHIP_ID); | 1121 | chip_id = i2c_smbus_read_byte_data(client, LM90_REG_R_CHIP_ID); |
1122 | reg_config1 = i2c_smbus_read_byte_data(new_client, LM90_REG_R_CONFIG1); | 1122 | config1 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1); |
1123 | reg_convrate = i2c_smbus_read_byte_data(new_client, | 1123 | convrate = i2c_smbus_read_byte_data(client, LM90_REG_R_CONVRATE); |
1124 | LM90_REG_R_CONVRATE); | 1124 | if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0) |
1125 | if (man_id < 0 || chip_id < 0 || reg_config1 < 0 || reg_convrate < 0) | ||
1126 | return -ENODEV; | 1125 | return -ENODEV; |
1127 | 1126 | ||
1128 | if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { | 1127 | if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { |
1129 | reg_config2 = i2c_smbus_read_byte_data(new_client, | 1128 | config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2); |
1130 | LM90_REG_R_CONFIG2); | 1129 | if (config2 < 0) |
1131 | if (reg_config2 < 0) | ||
1132 | return -ENODEV; | 1130 | return -ENODEV; |
1133 | } else | 1131 | } else |
1134 | reg_config2 = 0; /* Make compiler happy */ | 1132 | config2 = 0; /* Make compiler happy */ |
1135 | 1133 | ||
1136 | if ((address == 0x4C || address == 0x4D) | 1134 | if ((address == 0x4C || address == 0x4D) |
1137 | && man_id == 0x01) { /* National Semiconductor */ | 1135 | && man_id == 0x01) { /* National Semiconductor */ |
1138 | if ((reg_config1 & 0x2A) == 0x00 | 1136 | if ((config1 & 0x2A) == 0x00 |
1139 | && (reg_config2 & 0xF8) == 0x00 | 1137 | && (config2 & 0xF8) == 0x00 |
1140 | && reg_convrate <= 0x09) { | 1138 | && convrate <= 0x09) { |
1141 | if (address == 0x4C | 1139 | if (address == 0x4C |
1142 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ | 1140 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ |
1143 | name = "lm90"; | 1141 | name = "lm90"; |
@@ -1161,8 +1159,8 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1161 | if ((address == 0x4C || address == 0x4D) | 1159 | if ((address == 0x4C || address == 0x4D) |
1162 | && man_id == 0x41) { /* Analog Devices */ | 1160 | && man_id == 0x41) { /* Analog Devices */ |
1163 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ | 1161 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ |
1164 | && (reg_config1 & 0x3F) == 0x00 | 1162 | && (config1 & 0x3F) == 0x00 |
1165 | && reg_convrate <= 0x0A) { | 1163 | && convrate <= 0x0A) { |
1166 | name = "adm1032"; | 1164 | name = "adm1032"; |
1167 | /* The ADM1032 supports PEC, but only if combined | 1165 | /* The ADM1032 supports PEC, but only if combined |
1168 | transactions are not used. */ | 1166 | transactions are not used. */ |
@@ -1171,18 +1169,18 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1171 | info->flags |= I2C_CLIENT_PEC; | 1169 | info->flags |= I2C_CLIENT_PEC; |
1172 | } else | 1170 | } else |
1173 | if (chip_id == 0x51 /* ADT7461 */ | 1171 | if (chip_id == 0x51 /* ADT7461 */ |
1174 | && (reg_config1 & 0x1B) == 0x00 | 1172 | && (config1 & 0x1B) == 0x00 |
1175 | && reg_convrate <= 0x0A) { | 1173 | && convrate <= 0x0A) { |
1176 | name = "adt7461"; | 1174 | name = "adt7461"; |
1177 | } else | 1175 | } else |
1178 | if (chip_id == 0x57 /* ADT7461A, NCT1008 */ | 1176 | if (chip_id == 0x57 /* ADT7461A, NCT1008 */ |
1179 | && (reg_config1 & 0x1B) == 0x00 | 1177 | && (config1 & 0x1B) == 0x00 |
1180 | && reg_convrate <= 0x0A) { | 1178 | && convrate <= 0x0A) { |
1181 | name = "adt7461a"; | 1179 | name = "adt7461a"; |
1182 | } | 1180 | } |
1183 | } else | 1181 | } else |
1184 | if (man_id == 0x4D) { /* Maxim */ | 1182 | if (man_id == 0x4D) { /* Maxim */ |
1185 | int reg_emerg, reg_emerg2, reg_status2; | 1183 | int emerg, emerg2, status2; |
1186 | 1184 | ||
1187 | /* | 1185 | /* |
1188 | * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read | 1186 | * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read |
@@ -1190,16 +1188,15 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1190 | * exists, both readings will reflect the same value. Otherwise, | 1188 | * exists, both readings will reflect the same value. Otherwise, |
1191 | * the readings will be different. | 1189 | * the readings will be different. |
1192 | */ | 1190 | */ |
1193 | reg_emerg = i2c_smbus_read_byte_data(new_client, | 1191 | emerg = i2c_smbus_read_byte_data(client, |
1194 | MAX6659_REG_R_REMOTE_EMERG); | 1192 | MAX6659_REG_R_REMOTE_EMERG); |
1195 | man_id = i2c_smbus_read_byte_data(new_client, | 1193 | man_id = i2c_smbus_read_byte_data(client, |
1196 | LM90_REG_R_MAN_ID); | 1194 | LM90_REG_R_MAN_ID); |
1197 | reg_emerg2 = i2c_smbus_read_byte_data(new_client, | 1195 | emerg2 = i2c_smbus_read_byte_data(client, |
1198 | MAX6659_REG_R_REMOTE_EMERG); | 1196 | MAX6659_REG_R_REMOTE_EMERG); |
1199 | reg_status2 = i2c_smbus_read_byte_data(new_client, | 1197 | status2 = i2c_smbus_read_byte_data(client, |
1200 | MAX6696_REG_R_STATUS2); | 1198 | MAX6696_REG_R_STATUS2); |
1201 | if (reg_emerg < 0 || man_id < 0 || reg_emerg2 < 0 | 1199 | if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0) |
1202 | || reg_status2 < 0) | ||
1203 | return -ENODEV; | 1200 | return -ENODEV; |
1204 | 1201 | ||
1205 | /* | 1202 | /* |
@@ -1217,8 +1214,8 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1217 | */ | 1214 | */ |
1218 | if (chip_id == man_id | 1215 | if (chip_id == man_id |
1219 | && (address == 0x4C || address == 0x4D || address == 0x4E) | 1216 | && (address == 0x4C || address == 0x4D || address == 0x4E) |
1220 | && (reg_config1 & 0x1F) == (man_id & 0x0F) | 1217 | && (config1 & 0x1F) == (man_id & 0x0F) |
1221 | && reg_convrate <= 0x09) { | 1218 | && convrate <= 0x09) { |
1222 | if (address == 0x4C) | 1219 | if (address == 0x4C) |
1223 | name = "max6657"; | 1220 | name = "max6657"; |
1224 | else | 1221 | else |
@@ -1236,10 +1233,10 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1236 | * one of those registers exists. | 1233 | * one of those registers exists. |
1237 | */ | 1234 | */ |
1238 | if (chip_id == 0x01 | 1235 | if (chip_id == 0x01 |
1239 | && (reg_config1 & 0x10) == 0x00 | 1236 | && (config1 & 0x10) == 0x00 |
1240 | && (reg_status2 & 0x01) == 0x00 | 1237 | && (status2 & 0x01) == 0x00 |
1241 | && reg_emerg == reg_emerg2 | 1238 | && emerg == emerg2 |
1242 | && reg_convrate <= 0x07) { | 1239 | && convrate <= 0x07) { |
1243 | name = "max6696"; | 1240 | name = "max6696"; |
1244 | } else | 1241 | } else |
1245 | /* | 1242 | /* |
@@ -1249,8 +1246,8 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1249 | * second to last bit of config1 (software reset). | 1246 | * second to last bit of config1 (software reset). |
1250 | */ | 1247 | */ |
1251 | if (chip_id == 0x01 | 1248 | if (chip_id == 0x01 |
1252 | && (reg_config1 & 0x03) == 0x00 | 1249 | && (config1 & 0x03) == 0x00 |
1253 | && reg_convrate <= 0x07) { | 1250 | && convrate <= 0x07) { |
1254 | name = "max6680"; | 1251 | name = "max6680"; |
1255 | } else | 1252 | } else |
1256 | /* | 1253 | /* |
@@ -1259,21 +1256,21 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1259 | * register are unused and should return zero when read. | 1256 | * register are unused and should return zero when read. |
1260 | */ | 1257 | */ |
1261 | if (chip_id == 0x59 | 1258 | if (chip_id == 0x59 |
1262 | && (reg_config1 & 0x3f) == 0x00 | 1259 | && (config1 & 0x3f) == 0x00 |
1263 | && reg_convrate <= 0x07) { | 1260 | && convrate <= 0x07) { |
1264 | name = "max6646"; | 1261 | name = "max6646"; |
1265 | } | 1262 | } |
1266 | } else | 1263 | } else |
1267 | if (address == 0x4C | 1264 | if (address == 0x4C |
1268 | && man_id == 0x5C) { /* Winbond/Nuvoton */ | 1265 | && man_id == 0x5C) { /* Winbond/Nuvoton */ |
1269 | if ((reg_config1 & 0x2A) == 0x00 | 1266 | if ((config1 & 0x2A) == 0x00 |
1270 | && (reg_config2 & 0xF8) == 0x00) { | 1267 | && (config2 & 0xF8) == 0x00) { |
1271 | if (chip_id == 0x01 /* W83L771W/G */ | 1268 | if (chip_id == 0x01 /* W83L771W/G */ |
1272 | && reg_convrate <= 0x09) { | 1269 | && convrate <= 0x09) { |
1273 | name = "w83l771"; | 1270 | name = "w83l771"; |
1274 | } else | 1271 | } else |
1275 | if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ | 1272 | if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ |
1276 | && reg_convrate <= 0x08) { | 1273 | && convrate <= 0x08) { |
1277 | name = "w83l771"; | 1274 | name = "w83l771"; |
1278 | } | 1275 | } |
1279 | } | 1276 | } |
@@ -1281,9 +1278,9 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1281 | if (address >= 0x48 && address <= 0x4F | 1278 | if (address >= 0x48 && address <= 0x4F |
1282 | && man_id == 0xA1) { /* NXP Semiconductor/Philips */ | 1279 | && man_id == 0xA1) { /* NXP Semiconductor/Philips */ |
1283 | if (chip_id == 0x00 | 1280 | if (chip_id == 0x00 |
1284 | && (reg_config1 & 0x2A) == 0x00 | 1281 | && (config1 & 0x2A) == 0x00 |
1285 | && (reg_config2 & 0xFE) == 0x00 | 1282 | && (config2 & 0xFE) == 0x00 |
1286 | && reg_convrate <= 0x09) { | 1283 | && convrate <= 0x09) { |
1287 | name = "sa56004"; | 1284 | name = "sa56004"; |
1288 | } | 1285 | } |
1289 | } | 1286 | } |
@@ -1302,19 +1299,18 @@ static int lm90_detect(struct i2c_client *new_client, | |||
1302 | 1299 | ||
1303 | static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) | 1300 | static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) |
1304 | { | 1301 | { |
1302 | struct device *dev = &client->dev; | ||
1303 | |||
1305 | if (data->flags & LM90_HAVE_TEMP3) | 1304 | if (data->flags & LM90_HAVE_TEMP3) |
1306 | sysfs_remove_group(&client->dev.kobj, &lm90_temp3_group); | 1305 | sysfs_remove_group(&dev->kobj, &lm90_temp3_group); |
1307 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) | 1306 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) |
1308 | sysfs_remove_group(&client->dev.kobj, | 1307 | sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group); |
1309 | &lm90_emergency_alarm_group); | ||
1310 | if (data->flags & LM90_HAVE_EMERGENCY) | 1308 | if (data->flags & LM90_HAVE_EMERGENCY) |
1311 | sysfs_remove_group(&client->dev.kobj, | 1309 | sysfs_remove_group(&dev->kobj, &lm90_emergency_group); |
1312 | &lm90_emergency_group); | ||
1313 | if (data->flags & LM90_HAVE_OFFSET) | 1310 | if (data->flags & LM90_HAVE_OFFSET) |
1314 | device_remove_file(&client->dev, | 1311 | device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr); |
1315 | &sensor_dev_attr_temp2_offset.dev_attr); | 1312 | device_remove_file(dev, &dev_attr_pec); |
1316 | device_remove_file(&client->dev, &dev_attr_pec); | 1313 | sysfs_remove_group(&dev->kobj, &lm90_group); |
1317 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | ||
1318 | } | 1314 | } |
1319 | 1315 | ||
1320 | static void lm90_init_client(struct i2c_client *client) | 1316 | static void lm90_init_client(struct i2c_client *client) |
@@ -1363,10 +1359,11 @@ static void lm90_init_client(struct i2c_client *client) | |||
1363 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | 1359 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
1364 | } | 1360 | } |
1365 | 1361 | ||
1366 | static int lm90_probe(struct i2c_client *new_client, | 1362 | static int lm90_probe(struct i2c_client *client, |
1367 | const struct i2c_device_id *id) | 1363 | const struct i2c_device_id *id) |
1368 | { | 1364 | { |
1369 | struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent); | 1365 | struct device *dev = &client->dev; |
1366 | struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); | ||
1370 | struct lm90_data *data; | 1367 | struct lm90_data *data; |
1371 | int err; | 1368 | int err; |
1372 | 1369 | ||
@@ -1375,14 +1372,14 @@ static int lm90_probe(struct i2c_client *new_client, | |||
1375 | err = -ENOMEM; | 1372 | err = -ENOMEM; |
1376 | goto exit; | 1373 | goto exit; |
1377 | } | 1374 | } |
1378 | i2c_set_clientdata(new_client, data); | 1375 | i2c_set_clientdata(client, data); |
1379 | mutex_init(&data->update_lock); | 1376 | mutex_init(&data->update_lock); |
1380 | 1377 | ||
1381 | /* Set the device type */ | 1378 | /* Set the device type */ |
1382 | data->kind = id->driver_data; | 1379 | data->kind = id->driver_data; |
1383 | if (data->kind == adm1032) { | 1380 | if (data->kind == adm1032) { |
1384 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 1381 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
1385 | new_client->flags &= ~I2C_CLIENT_PEC; | 1382 | client->flags &= ~I2C_CLIENT_PEC; |
1386 | } | 1383 | } |
1387 | 1384 | ||
1388 | /* Different devices have different alarm bits triggering the | 1385 | /* Different devices have different alarm bits triggering the |
@@ -1397,43 +1394,41 @@ static int lm90_probe(struct i2c_client *new_client, | |||
1397 | data->max_convrate = lm90_params[data->kind].max_convrate; | 1394 | data->max_convrate = lm90_params[data->kind].max_convrate; |
1398 | 1395 | ||
1399 | /* Initialize the LM90 chip */ | 1396 | /* Initialize the LM90 chip */ |
1400 | lm90_init_client(new_client); | 1397 | lm90_init_client(client); |
1401 | 1398 | ||
1402 | /* Register sysfs hooks */ | 1399 | /* Register sysfs hooks */ |
1403 | err = sysfs_create_group(&new_client->dev.kobj, &lm90_group); | 1400 | err = sysfs_create_group(&dev->kobj, &lm90_group); |
1404 | if (err) | 1401 | if (err) |
1405 | goto exit_free; | 1402 | goto exit_free; |
1406 | if (new_client->flags & I2C_CLIENT_PEC) { | 1403 | if (client->flags & I2C_CLIENT_PEC) { |
1407 | err = device_create_file(&new_client->dev, &dev_attr_pec); | 1404 | err = device_create_file(dev, &dev_attr_pec); |
1408 | if (err) | 1405 | if (err) |
1409 | goto exit_remove_files; | 1406 | goto exit_remove_files; |
1410 | } | 1407 | } |
1411 | if (data->flags & LM90_HAVE_OFFSET) { | 1408 | if (data->flags & LM90_HAVE_OFFSET) { |
1412 | err = device_create_file(&new_client->dev, | 1409 | err = device_create_file(dev, |
1413 | &sensor_dev_attr_temp2_offset.dev_attr); | 1410 | &sensor_dev_attr_temp2_offset.dev_attr); |
1414 | if (err) | 1411 | if (err) |
1415 | goto exit_remove_files; | 1412 | goto exit_remove_files; |
1416 | } | 1413 | } |
1417 | if (data->flags & LM90_HAVE_EMERGENCY) { | 1414 | if (data->flags & LM90_HAVE_EMERGENCY) { |
1418 | err = sysfs_create_group(&new_client->dev.kobj, | 1415 | err = sysfs_create_group(&dev->kobj, &lm90_emergency_group); |
1419 | &lm90_emergency_group); | ||
1420 | if (err) | 1416 | if (err) |
1421 | goto exit_remove_files; | 1417 | goto exit_remove_files; |
1422 | } | 1418 | } |
1423 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { | 1419 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { |
1424 | err = sysfs_create_group(&new_client->dev.kobj, | 1420 | err = sysfs_create_group(&dev->kobj, |
1425 | &lm90_emergency_alarm_group); | 1421 | &lm90_emergency_alarm_group); |
1426 | if (err) | 1422 | if (err) |
1427 | goto exit_remove_files; | 1423 | goto exit_remove_files; |
1428 | } | 1424 | } |
1429 | if (data->flags & LM90_HAVE_TEMP3) { | 1425 | if (data->flags & LM90_HAVE_TEMP3) { |
1430 | err = sysfs_create_group(&new_client->dev.kobj, | 1426 | err = sysfs_create_group(&dev->kobj, &lm90_temp3_group); |
1431 | &lm90_temp3_group); | ||
1432 | if (err) | 1427 | if (err) |
1433 | goto exit_remove_files; | 1428 | goto exit_remove_files; |
1434 | } | 1429 | } |
1435 | 1430 | ||
1436 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 1431 | data->hwmon_dev = hwmon_device_register(dev); |
1437 | if (IS_ERR(data->hwmon_dev)) { | 1432 | if (IS_ERR(data->hwmon_dev)) { |
1438 | err = PTR_ERR(data->hwmon_dev); | 1433 | err = PTR_ERR(data->hwmon_dev); |
1439 | goto exit_remove_files; | 1434 | goto exit_remove_files; |
@@ -1442,7 +1437,7 @@ static int lm90_probe(struct i2c_client *new_client, | |||
1442 | return 0; | 1437 | return 0; |
1443 | 1438 | ||
1444 | exit_remove_files: | 1439 | exit_remove_files: |
1445 | lm90_remove_files(new_client, data); | 1440 | lm90_remove_files(client, data); |
1446 | exit_free: | 1441 | exit_free: |
1447 | kfree(data); | 1442 | kfree(data); |
1448 | exit: | 1443 | exit: |