diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-13 12:30:09 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:26 -0400 |
commit | 688a3174a2a0426a898dc641226249fa0df9e922 (patch) | |
tree | 3f2481978d307e6463af1ca15363cba594b4ddc8 /drivers | |
parent | 9028ff8e3dd207375d2459079f728322671069ac (diff) |
hwmon: (lm80) Normalize all temperature values to 16 bit
Normalize all stored temperature values to 16 bit to simplify
temperature calculations.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/lm80.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 8e9a0b1dc437..fe980d64dc05 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -86,13 +86,9 @@ static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div) | |||
86 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 86 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
87 | (val) == 255 ? 0 : 1350000/((div) * (val))) | 87 | (val) == 255 ? 0 : 1350000/((div) * (val))) |
88 | 88 | ||
89 | #define TEMP_FROM_REG(temp) ((temp) * 125 / 32) | 89 | #define TEMP_FROM_REG(reg) ((reg) * 125 / 32) |
90 | 90 | #define TEMP_TO_REG(temp) (DIV_ROUND_CLOSEST(clamp_val((temp), \ | |
91 | #define TEMP_LIMIT_FROM_REG(val) (((val) > 0x80 ? \ | 91 | -128000, 127000), 1000) << 8) |
92 | (val) - 0x100 : (val)) * 1000) | ||
93 | |||
94 | #define TEMP_LIMIT_TO_REG(val) clamp_val((val) < 0 ? \ | ||
95 | ((val) - 500) / 1000 : ((val) + 500) / 1000, 0, 255) | ||
96 | 92 | ||
97 | #define DIV_FROM_REG(val) (1 << (val)) | 93 | #define DIV_FROM_REG(val) (1 << (val)) |
98 | 94 | ||
@@ -114,10 +110,10 @@ struct lm80_data { | |||
114 | u8 fan_min[2]; /* Register value */ | 110 | u8 fan_min[2]; /* Register value */ |
115 | u8 fan_div[2]; /* Register encoding, shifted right */ | 111 | u8 fan_div[2]; /* Register encoding, shifted right */ |
116 | s16 temp; /* Register values */ | 112 | s16 temp; /* Register values */ |
117 | u8 temp_hot_max; /* Register value */ | 113 | s16 temp_hot_max; /* Register value, left shifted */ |
118 | u8 temp_hot_hyst; /* Register value */ | 114 | s16 temp_hot_hyst; /* Register value, left shifted */ |
119 | u8 temp_os_max; /* Register value */ | 115 | s16 temp_os_max; /* Register value, left shifted */ |
120 | u8 temp_os_hyst; /* Register value */ | 116 | s16 temp_os_hyst; /* Register value, left shifted */ |
121 | u16 alarms; /* Register encoding, combined */ | 117 | u16 alarms; /* Register encoding, combined */ |
122 | }; | 118 | }; |
123 | 119 | ||
@@ -308,7 +304,7 @@ static ssize_t show_temp_##suffix(struct device *dev, \ | |||
308 | struct lm80_data *data = lm80_update_device(dev); \ | 304 | struct lm80_data *data = lm80_update_device(dev); \ |
309 | if (IS_ERR(data)) \ | 305 | if (IS_ERR(data)) \ |
310 | return PTR_ERR(data); \ | 306 | return PTR_ERR(data); \ |
311 | return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \ | 307 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ |
312 | } | 308 | } |
313 | show_temp(hot_max, temp_hot_max); | 309 | show_temp(hot_max, temp_hot_max); |
314 | show_temp(hot_hyst, temp_hot_hyst); | 310 | show_temp(hot_hyst, temp_hot_hyst); |
@@ -327,8 +323,8 @@ static ssize_t set_temp_##suffix(struct device *dev, \ | |||
327 | return err; \ | 323 | return err; \ |
328 | \ | 324 | \ |
329 | mutex_lock(&data->update_lock); \ | 325 | mutex_lock(&data->update_lock); \ |
330 | data->value = TEMP_LIMIT_TO_REG(val); \ | 326 | data->value = TEMP_TO_REG(val); \ |
331 | lm80_write_value(client, reg, data->value); \ | 327 | lm80_write_value(client, reg, data->value >> 8); \ |
332 | mutex_unlock(&data->update_lock); \ | 328 | mutex_unlock(&data->update_lock); \ |
333 | return count; \ | 329 | return count; \ |
334 | } | 330 | } |
@@ -639,22 +635,22 @@ static struct lm80_data *lm80_update_device(struct device *dev) | |||
639 | rv = lm80_read_value(client, LM80_REG_TEMP_OS_MAX); | 635 | rv = lm80_read_value(client, LM80_REG_TEMP_OS_MAX); |
640 | if (rv < 0) | 636 | if (rv < 0) |
641 | goto abort; | 637 | goto abort; |
642 | data->temp_os_max = rv; | 638 | data->temp_os_max = rv << 8; |
643 | 639 | ||
644 | rv = lm80_read_value(client, LM80_REG_TEMP_OS_HYST); | 640 | rv = lm80_read_value(client, LM80_REG_TEMP_OS_HYST); |
645 | if (rv < 0) | 641 | if (rv < 0) |
646 | goto abort; | 642 | goto abort; |
647 | data->temp_os_hyst = rv; | 643 | data->temp_os_hyst = rv << 8; |
648 | 644 | ||
649 | rv = lm80_read_value(client, LM80_REG_TEMP_HOT_MAX); | 645 | rv = lm80_read_value(client, LM80_REG_TEMP_HOT_MAX); |
650 | if (rv < 0) | 646 | if (rv < 0) |
651 | goto abort; | 647 | goto abort; |
652 | data->temp_hot_max = rv; | 648 | data->temp_hot_max = rv << 8; |
653 | 649 | ||
654 | rv = lm80_read_value(client, LM80_REG_TEMP_HOT_HYST); | 650 | rv = lm80_read_value(client, LM80_REG_TEMP_HOT_HYST); |
655 | if (rv < 0) | 651 | if (rv < 0) |
656 | goto abort; | 652 | goto abort; |
657 | data->temp_hot_hyst = rv; | 653 | data->temp_hot_hyst = rv << 8; |
658 | 654 | ||
659 | rv = lm80_read_value(client, LM80_REG_FANDIV); | 655 | rv = lm80_read_value(client, LM80_REG_FANDIV); |
660 | if (rv < 0) | 656 | if (rv < 0) |