aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-28 14:31:47 -0400
committerJean Delvare <khali@endymion.delvare>2010-10-28 14:31:47 -0400
commitdd127f5ccd7c61eb7ee215120a7809eb67c1ed7f (patch)
tree9be7c4c8f1b35526c5b8357e25ccb5e8e99eaff9 /drivers/hwmon
parenta0ce402fb006bd694436be8c8522fbe5e6823ac1 (diff)
hwmon: (w83795) Properly handle negative temperatures
The temperature registers hold regular 2's complement values, no need to add any arithmetics. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/w83795.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 5ce276b6752..f4b7cb45ebc 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -295,7 +295,7 @@ static inline long temp_from_reg(s8 reg)
295 295
296static inline s8 temp_to_reg(long val, s8 min, s8 max) 296static inline s8 temp_to_reg(long val, s8 min, s8 max)
297{ 297{
298 return SENSORS_LIMIT((val < 0 ? -val : val) / 1000, min, max); 298 return SENSORS_LIMIT(val / 1000, min, max);
299} 299}
300 300
301static const u16 pwm_freq_cksel0[16] = { 301static const u16 pwm_freq_cksel0[16] = {
@@ -364,7 +364,7 @@ struct w83795_data {
364 u16 fan_min[14]; /* Register value combine */ 364 u16 fan_min[14]; /* Register value combine */
365 365
366 u8 has_temp; /* Enable monitor temp6-1 or not */ 366 u8 has_temp; /* Enable monitor temp6-1 or not */
367 u8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ 367 s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */
368 u8 temp_read_vrlsb[6]; 368 u8 temp_read_vrlsb[6];
369 u8 temp_mode; /* bit 0: TR mode, bit 1: TD mode */ 369 u8 temp_mode; /* bit 0: TR mode, bit 1: TD mode */
370 u8 temp_src[3]; /* Register value */ 370 u8 temp_src[3]; /* Register value */
@@ -373,9 +373,9 @@ struct w83795_data {
373 * bit 0: =1 enable, =0 disable, 373 * bit 0: =1 enable, =0 disable,
374 * bit 1: =1 AMD SB-TSI, =0 Intel PECI */ 374 * bit 1: =1 AMD SB-TSI, =0 Intel PECI */
375 u8 has_dts; /* Enable monitor DTS temp */ 375 u8 has_dts; /* Enable monitor DTS temp */
376 u8 dts[8]; /* Register value */ 376 s8 dts[8]; /* Register value */
377 u8 dts_read_vrlsb[8]; /* Register value */ 377 u8 dts_read_vrlsb[8]; /* Register value */
378 u8 dts_ext[4]; /* Register value */ 378 s8 dts_ext[4]; /* Register value */
379 379
380 u8 has_pwm; /* 795g supports 8 pwm, 795adg only supports 2, 380 u8 has_pwm; /* 795g supports 8 pwm, 795adg only supports 2,
381 * no config register, only affected by chip 381 * no config register, only affected by chip
@@ -1170,13 +1170,11 @@ show_temp(struct device *dev, struct device_attribute *attr, char *buf)
1170 int nr = sensor_attr->nr; 1170 int nr = sensor_attr->nr;
1171 int index = sensor_attr->index; 1171 int index = sensor_attr->index;
1172 struct w83795_data *data = w83795_update_device(dev); 1172 struct w83795_data *data = w83795_update_device(dev);
1173 long temp = temp_from_reg(data->temp[index][nr] & 0x7f); 1173 long temp = temp_from_reg(data->temp[index][nr]);
1174 1174
1175 if (TEMP_READ == nr) 1175 if (TEMP_READ == nr)
1176 temp += ((data->temp_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03) 1176 temp += ((data->temp_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03)
1177 * 250; 1177 * 250;
1178 if (data->temp[index][nr] & 0x80)
1179 temp = -temp;
1180 return sprintf(buf, "%ld\n", temp); 1178 return sprintf(buf, "%ld\n", temp);
1181} 1179}
1182 1180
@@ -1235,11 +1233,9 @@ show_dts(struct device *dev, struct device_attribute *attr, char *buf)
1235 to_sensor_dev_attr_2(attr); 1233 to_sensor_dev_attr_2(attr);
1236 int index = sensor_attr->index; 1234 int index = sensor_attr->index;
1237 struct w83795_data *data = w83795_update_device(dev); 1235 struct w83795_data *data = w83795_update_device(dev);
1238 long temp = temp_from_reg(data->dts[index] & 0x7f); 1236 long temp = temp_from_reg(data->dts[index]);
1239 1237
1240 temp += ((data->dts_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03) * 250; 1238 temp += ((data->dts_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03) * 250;
1241 if (data->dts[index] & 0x80)
1242 temp = -temp;
1243 return sprintf(buf, "%ld\n", temp); 1239 return sprintf(buf, "%ld\n", temp);
1244} 1240}
1245 1241
@@ -1251,10 +1247,8 @@ show_dts_ext(struct device *dev, struct device_attribute *attr, char *buf)
1251 int nr = sensor_attr->nr; 1247 int nr = sensor_attr->nr;
1252 struct i2c_client *client = to_i2c_client(dev); 1248 struct i2c_client *client = to_i2c_client(dev);
1253 struct w83795_data *data = i2c_get_clientdata(client); 1249 struct w83795_data *data = i2c_get_clientdata(client);
1254 long temp = temp_from_reg(data->dts_ext[nr] & 0x7f); 1250 long temp = temp_from_reg(data->dts_ext[nr]);
1255 1251
1256 if (data->dts_ext[nr] & 0x80)
1257 temp = -temp;
1258 return sprintf(buf, "%ld\n", temp); 1252 return sprintf(buf, "%ld\n", temp);
1259} 1253}
1260 1254