diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-10-28 14:31:48 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-28 14:31:48 -0400 |
commit | 39deb6993e7c22274c272c95013eef886f7004e8 (patch) | |
tree | 212af4c4e49ecf64174981c336ebd6ca15bcfb59 | |
parent | cd316df582925f3dab1ce5863651b3e260687035 (diff) |
hwmon: (w83795) Simplify temperature sensor type handling
All 3 temperature sensor type sysfs functions (show_temp_mode,
store_temp_mode and show_dts_mode) can be simplified. We don't
create these files when the correponding input isn't in temperature
monitoring mode, so there is no point in handling that case.
Likewise, we don't allow changing inputs from temperature to voltage,
so the code handling this case is dead and can be removed.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r-- | drivers/hwmon/w83795.c | 107 |
1 files changed, 24 insertions, 83 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index c8f62044ac19..07e8de58dcd4 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c | |||
@@ -66,23 +66,6 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); | |||
66 | #define W83795_REG_FANIN_CTRL2 0x07 | 66 | #define W83795_REG_FANIN_CTRL2 0x07 |
67 | #define W83795_REG_VMIGB_CTRL 0x08 | 67 | #define W83795_REG_VMIGB_CTRL 0x08 |
68 | 68 | ||
69 | #define TEMP_CTRL_DISABLE 0 | ||
70 | #define TEMP_CTRL_TD 1 | ||
71 | #define TEMP_CTRL_VSEN 2 | ||
72 | #define TEMP_CTRL_TR 3 | ||
73 | #define TEMP_CTRL_SHIFT 4 | ||
74 | #define TEMP_CTRL_HASIN_SHIFT 5 | ||
75 | /* temp mode may effect VSEN17-12 (in20-15) */ | ||
76 | static const u16 W83795_REG_TEMP_CTRL[][6] = { | ||
77 | /* Disable, TD, VSEN, TR, register shift value, has_in shift num */ | ||
78 | {0x00, 0x01, 0x02, 0x03, 0, 17}, /* TR1 */ | ||
79 | {0x00, 0x04, 0x08, 0x0C, 2, 18}, /* TR2 */ | ||
80 | {0x00, 0x10, 0x20, 0x30, 4, 19}, /* TR3 */ | ||
81 | {0x00, 0x40, 0x80, 0xC0, 6, 20}, /* TR4 */ | ||
82 | {0x00, 0x00, 0x02, 0x03, 0, 15}, /* TR5 */ | ||
83 | {0x00, 0x00, 0x08, 0x0C, 2, 16}, /* TR6 */ | ||
84 | }; | ||
85 | |||
86 | #define TEMP_READ 0 | 69 | #define TEMP_READ 0 |
87 | #define TEMP_CRIT 1 | 70 | #define TEMP_CRIT 1 |
88 | #define TEMP_CRIT_HYST 2 | 71 | #define TEMP_CRIT_HYST 2 |
@@ -359,7 +342,7 @@ struct w83795_data { | |||
359 | u8 has_temp; /* Enable monitor temp6-1 or not */ | 342 | u8 has_temp; /* Enable monitor temp6-1 or not */ |
360 | s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ | 343 | s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ |
361 | u8 temp_read_vrlsb[6]; | 344 | u8 temp_read_vrlsb[6]; |
362 | u8 temp_mode; /* bit 0: TR mode, bit 1: TD mode */ | 345 | u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */ |
363 | u8 temp_src[3]; /* Register value */ | 346 | u8 temp_src[3]; /* Register value */ |
364 | 347 | ||
365 | u8 enable_dts; /* Enable PECI and SB-TSI, | 348 | u8 enable_dts; /* Enable PECI and SB-TSI, |
@@ -509,13 +492,6 @@ static struct w83795_data *w83795_update_device(struct device *dev) | |||
509 | 492 | ||
510 | /* Update temperature */ | 493 | /* Update temperature */ |
511 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { | 494 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { |
512 | /* even stop monitor, register still keep value, just read out | ||
513 | * it */ | ||
514 | if (!(data->has_temp & (1 << i))) { | ||
515 | data->temp[i][TEMP_READ] = 0; | ||
516 | data->temp_read_vrlsb[i] = 0; | ||
517 | continue; | ||
518 | } | ||
519 | data->temp[i][TEMP_READ] = | 495 | data->temp[i][TEMP_READ] = |
520 | w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); | 496 | w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); |
521 | data->temp_read_vrlsb[i] = | 497 | data->temp_read_vrlsb[i] = |
@@ -1163,22 +1139,12 @@ show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf) | |||
1163 | { | 1139 | { |
1164 | struct i2c_client *client = to_i2c_client(dev); | 1140 | struct i2c_client *client = to_i2c_client(dev); |
1165 | struct w83795_data *data = i2c_get_clientdata(client); | 1141 | struct w83795_data *data = i2c_get_clientdata(client); |
1166 | struct sensor_device_attribute_2 *sensor_attr = | 1142 | int tmp; |
1167 | to_sensor_dev_attr_2(attr); | ||
1168 | int index = sensor_attr->index; | ||
1169 | u8 tmp; | ||
1170 | 1143 | ||
1171 | if (data->enable_dts == 0) | 1144 | if (data->enable_dts & 2) |
1172 | return sprintf(buf, "%d\n", 0); | 1145 | tmp = 5; |
1173 | 1146 | else | |
1174 | if ((data->has_dts >> index) & 0x01) { | 1147 | tmp = 6; |
1175 | if (data->enable_dts & 2) | ||
1176 | tmp = 5; | ||
1177 | else | ||
1178 | tmp = 6; | ||
1179 | } else { | ||
1180 | tmp = 0; | ||
1181 | } | ||
1182 | 1148 | ||
1183 | return sprintf(buf, "%d\n", tmp); | 1149 | return sprintf(buf, "%d\n", tmp); |
1184 | } | 1150 | } |
@@ -1231,14 +1197,6 @@ store_dts_ext(struct device *dev, struct device_attribute *attr, | |||
1231 | } | 1197 | } |
1232 | 1198 | ||
1233 | 1199 | ||
1234 | /* | ||
1235 | Type 3: Thermal diode | ||
1236 | Type 4: Thermistor | ||
1237 | |||
1238 | Temp5-6, default TR | ||
1239 | Temp1-4, default TD | ||
1240 | */ | ||
1241 | |||
1242 | static ssize_t | 1200 | static ssize_t |
1243 | show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) | 1201 | show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) |
1244 | { | 1202 | { |
@@ -1247,20 +1205,17 @@ show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) | |||
1247 | struct sensor_device_attribute_2 *sensor_attr = | 1205 | struct sensor_device_attribute_2 *sensor_attr = |
1248 | to_sensor_dev_attr_2(attr); | 1206 | to_sensor_dev_attr_2(attr); |
1249 | int index = sensor_attr->index; | 1207 | int index = sensor_attr->index; |
1250 | u8 tmp; | 1208 | int tmp; |
1251 | 1209 | ||
1252 | if (data->has_temp >> index & 0x01) { | 1210 | if (data->temp_mode & (1 << index)) |
1253 | if (data->temp_mode >> index & 0x01) | 1211 | tmp = 3; /* Thermal diode */ |
1254 | tmp = 3; | 1212 | else |
1255 | else | 1213 | tmp = 4; /* Thermistor */ |
1256 | tmp = 4; | ||
1257 | } else { | ||
1258 | tmp = 0; | ||
1259 | } | ||
1260 | 1214 | ||
1261 | return sprintf(buf, "%d\n", tmp); | 1215 | return sprintf(buf, "%d\n", tmp); |
1262 | } | 1216 | } |
1263 | 1217 | ||
1218 | /* Only for temp1-4 (temp5-6 can only be thermistor) */ | ||
1264 | static ssize_t | 1219 | static ssize_t |
1265 | store_temp_mode(struct device *dev, struct device_attribute *attr, | 1220 | store_temp_mode(struct device *dev, struct device_attribute *attr, |
1266 | const char *buf, size_t count) | 1221 | const char *buf, size_t count) |
@@ -1270,45 +1225,31 @@ store_temp_mode(struct device *dev, struct device_attribute *attr, | |||
1270 | struct sensor_device_attribute_2 *sensor_attr = | 1225 | struct sensor_device_attribute_2 *sensor_attr = |
1271 | to_sensor_dev_attr_2(attr); | 1226 | to_sensor_dev_attr_2(attr); |
1272 | int index = sensor_attr->index; | 1227 | int index = sensor_attr->index; |
1228 | int reg_shift; | ||
1273 | unsigned long val; | 1229 | unsigned long val; |
1274 | u8 tmp; | 1230 | u8 tmp; |
1275 | u32 mask; | ||
1276 | 1231 | ||
1277 | if (strict_strtoul(buf, 10, &val) < 0) | 1232 | if (strict_strtoul(buf, 10, &val) < 0) |
1278 | return -EINVAL; | 1233 | return -EINVAL; |
1279 | if ((val != 4) && (val != 3)) | 1234 | if ((val != 4) && (val != 3)) |
1280 | return -EINVAL; | 1235 | return -EINVAL; |
1281 | if ((index > 3) && (val == 3)) | ||
1282 | return -EINVAL; | ||
1283 | 1236 | ||
1284 | mutex_lock(&data->update_lock); | 1237 | mutex_lock(&data->update_lock); |
1285 | if (val == 3) { | 1238 | if (val == 3) { |
1286 | val = TEMP_CTRL_TD; | 1239 | /* Thermal diode */ |
1287 | data->has_temp |= 1 << index; | 1240 | val = 0x01; |
1288 | data->temp_mode |= 1 << index; | 1241 | data->temp_mode |= 1 << index; |
1289 | } else if (val == 4) { | 1242 | } else if (val == 4) { |
1290 | val = TEMP_CTRL_TR; | 1243 | /* Thermistor */ |
1291 | data->has_temp |= 1 << index; | 1244 | val = 0x03; |
1292 | tmp = 1 << index; | 1245 | data->temp_mode &= ~(1 << index); |
1293 | data->temp_mode &= ~tmp; | ||
1294 | } | 1246 | } |
1295 | 1247 | ||
1296 | if (index > 3) | 1248 | reg_shift = 2 * index; |
1297 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); | 1249 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); |
1298 | else | 1250 | tmp &= ~(0x03 << reg_shift); |
1299 | tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); | 1251 | tmp |= val << reg_shift; |
1300 | 1252 | w83795_write(client, W83795_REG_TEMP_CTRL2, tmp); | |
1301 | mask = 0x03 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_SHIFT]; | ||
1302 | tmp &= ~mask; | ||
1303 | tmp |= W83795_REG_TEMP_CTRL[index][val]; | ||
1304 | |||
1305 | mask = 1 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_HASIN_SHIFT]; | ||
1306 | data->has_in &= ~mask; | ||
1307 | |||
1308 | if (index > 3) | ||
1309 | w83795_write(client, W83795_REG_TEMP_CTRL1, tmp); | ||
1310 | else | ||
1311 | w83795_write(client, W83795_REG_TEMP_CTRL2, tmp); | ||
1312 | 1253 | ||
1313 | mutex_unlock(&data->update_lock); | 1254 | mutex_unlock(&data->update_lock); |
1314 | return count; | 1255 | return count; |
@@ -1506,7 +1447,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr, | |||
1506 | show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } | 1447 | show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } |
1507 | 1448 | ||
1508 | #define SENSOR_ATTR_TEMP(index) { \ | 1449 | #define SENSOR_ATTR_TEMP(index) { \ |
1509 | SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \ | 1450 | SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ |
1510 | show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ | 1451 | show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ |
1511 | SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ | 1452 | SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ |
1512 | NULL, TEMP_READ, index - 1), \ | 1453 | NULL, TEMP_READ, index - 1), \ |