diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-10-20 03:13:31 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-10-24 14:09:48 -0400 |
commit | c5794cfac09a585945e1632451900594db19393b (patch) | |
tree | 64a01f41edbcbbcbb8c22f271c02a57c538fbf04 /drivers/hwmon/w83627ehf.c | |
parent | 17296feb3c666d0fee3e659e9b5d668ff7a02549 (diff) |
hwmon: (w83627ehf) Better fix for negative temperature values
It is more efficient to left-align 8-bit temperature values, so that
8-bit and 9-bit temperature values can be handled exactly the same way
in the rest of the code.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/w83627ehf.c')
-rw-r--r-- | drivers/hwmon/w83627ehf.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index a26830dfea7e..98aab4bea342 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
@@ -388,23 +388,6 @@ div_from_reg(u8 reg) | |||
388 | return 1 << reg; | 388 | return 1 << reg; |
389 | } | 389 | } |
390 | 390 | ||
391 | static inline int | ||
392 | temp_from_reg(u16 reg, s16 regval) | ||
393 | { | ||
394 | if (is_word_sized(reg)) | ||
395 | return LM75_TEMP_FROM_REG(regval); | ||
396 | return ((s8)regval) * 1000; | ||
397 | } | ||
398 | |||
399 | static inline u16 | ||
400 | temp_to_reg(u16 reg, long temp) | ||
401 | { | ||
402 | if (is_word_sized(reg)) | ||
403 | return LM75_TEMP_TO_REG(temp); | ||
404 | return (s8)DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, -127000, 128000), | ||
405 | 1000); | ||
406 | } | ||
407 | |||
408 | /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ | 391 | /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ |
409 | 392 | ||
410 | static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; | 393 | static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; |
@@ -561,6 +544,26 @@ static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, | |||
561 | return 0; | 544 | return 0; |
562 | } | 545 | } |
563 | 546 | ||
547 | /* We left-align 8-bit temperature values to make the code simpler */ | ||
548 | static u16 w83627ehf_read_temp(struct w83627ehf_data *data, u16 reg) | ||
549 | { | ||
550 | u16 res; | ||
551 | |||
552 | res = w83627ehf_read_value(data, reg); | ||
553 | if (!is_word_sized(reg)) | ||
554 | res <<= 8; | ||
555 | |||
556 | return res; | ||
557 | } | ||
558 | |||
559 | static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, | ||
560 | u16 value) | ||
561 | { | ||
562 | if (!is_word_sized(reg)) | ||
563 | value >>= 8; | ||
564 | return w83627ehf_write_value(data, reg, value); | ||
565 | } | ||
566 | |||
564 | /* This function assumes that the caller holds data->update_lock */ | 567 | /* This function assumes that the caller holds data->update_lock */ |
565 | static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr) | 568 | static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr) |
566 | { | 569 | { |
@@ -862,15 +865,15 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
862 | for (i = 0; i < NUM_REG_TEMP; i++) { | 865 | for (i = 0; i < NUM_REG_TEMP; i++) { |
863 | if (!(data->have_temp & (1 << i))) | 866 | if (!(data->have_temp & (1 << i))) |
864 | continue; | 867 | continue; |
865 | data->temp[i] = w83627ehf_read_value(data, | 868 | data->temp[i] = w83627ehf_read_temp(data, |
866 | data->reg_temp[i]); | 869 | data->reg_temp[i]); |
867 | if (data->reg_temp_over[i]) | 870 | if (data->reg_temp_over[i]) |
868 | data->temp_max[i] | 871 | data->temp_max[i] |
869 | = w83627ehf_read_value(data, | 872 | = w83627ehf_read_temp(data, |
870 | data->reg_temp_over[i]); | 873 | data->reg_temp_over[i]); |
871 | if (data->reg_temp_hyst[i]) | 874 | if (data->reg_temp_hyst[i]) |
872 | data->temp_max_hyst[i] | 875 | data->temp_max_hyst[i] |
873 | = w83627ehf_read_value(data, | 876 | = w83627ehf_read_temp(data, |
874 | data->reg_temp_hyst[i]); | 877 | data->reg_temp_hyst[i]); |
875 | } | 878 | } |
876 | 879 | ||
@@ -1166,8 +1169,7 @@ show_##reg(struct device *dev, struct device_attribute *attr, \ | |||
1166 | struct sensor_device_attribute *sensor_attr = \ | 1169 | struct sensor_device_attribute *sensor_attr = \ |
1167 | to_sensor_dev_attr(attr); \ | 1170 | to_sensor_dev_attr(attr); \ |
1168 | int nr = sensor_attr->index; \ | 1171 | int nr = sensor_attr->index; \ |
1169 | return sprintf(buf, "%d\n", \ | 1172 | return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \ |
1170 | temp_from_reg(data->addr[nr], data->reg[nr])); \ | ||
1171 | } | 1173 | } |
1172 | show_temp_reg(reg_temp, temp); | 1174 | show_temp_reg(reg_temp, temp); |
1173 | show_temp_reg(reg_temp_over, temp_max); | 1175 | show_temp_reg(reg_temp_over, temp_max); |
@@ -1188,9 +1190,8 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ | |||
1188 | if (err < 0) \ | 1190 | if (err < 0) \ |
1189 | return err; \ | 1191 | return err; \ |
1190 | mutex_lock(&data->update_lock); \ | 1192 | mutex_lock(&data->update_lock); \ |
1191 | data->reg[nr] = temp_to_reg(data->addr[nr], val); \ | 1193 | data->reg[nr] = LM75_TEMP_TO_REG(val); \ |
1192 | w83627ehf_write_value(data, data->addr[nr], \ | 1194 | w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \ |
1193 | data->reg[nr]); \ | ||
1194 | mutex_unlock(&data->update_lock); \ | 1195 | mutex_unlock(&data->update_lock); \ |
1195 | return count; \ | 1196 | return count; \ |
1196 | } | 1197 | } |