diff options
author | Darrick J. Wong <djwong@us.ibm.com> | 2009-01-06 17:41:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 18:59:18 -0500 |
commit | 8f8c1fb0c829278b889588da211a5a557518b06c (patch) | |
tree | 551ad7728438ec885de76db4c7c776f88589a219 /drivers/hwmon | |
parent | 57b9c6d9c5074a06fda770a7f009d655593e0e29 (diff) |
adt74{62, 70, 73}: Use DIV_ROUND_CLOSEST for rounded division
Modify some hwmon drivers to use DIV_ROUND_CLOSEST instead of bloating
source with (naughty) macros.
Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/adt7462.c | 14 | ||||
-rw-r--r-- | drivers/hwmon/adt7470.c | 8 | ||||
-rw-r--r-- | drivers/hwmon/adt7473.c | 10 |
3 files changed, 13 insertions, 19 deletions
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index 66107b4dc12a..1852f27bac51 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c | |||
@@ -204,8 +204,6 @@ I2C_CLIENT_INSMOD_1(adt7462); | |||
204 | #define MASK_AND_SHIFT(value, prefix) \ | 204 | #define MASK_AND_SHIFT(value, prefix) \ |
205 | (((value) & prefix##_MASK) >> prefix##_SHIFT) | 205 | (((value) & prefix##_MASK) >> prefix##_SHIFT) |
206 | 206 | ||
207 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
208 | |||
209 | struct adt7462_data { | 207 | struct adt7462_data { |
210 | struct device *hwmon_dev; | 208 | struct device *hwmon_dev; |
211 | struct attribute_group attrs; | 209 | struct attribute_group attrs; |
@@ -840,7 +838,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
840 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | 838 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) |
841 | return -EINVAL; | 839 | return -EINVAL; |
842 | 840 | ||
843 | temp = ROUND_DIV(temp, 1000) + 64; | 841 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
844 | temp = SENSORS_LIMIT(temp, 0, 255); | 842 | temp = SENSORS_LIMIT(temp, 0, 255); |
845 | 843 | ||
846 | mutex_lock(&data->lock); | 844 | mutex_lock(&data->lock); |
@@ -878,7 +876,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
878 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | 876 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) |
879 | return -EINVAL; | 877 | return -EINVAL; |
880 | 878 | ||
881 | temp = ROUND_DIV(temp, 1000) + 64; | 879 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
882 | temp = SENSORS_LIMIT(temp, 0, 255); | 880 | temp = SENSORS_LIMIT(temp, 0, 255); |
883 | 881 | ||
884 | mutex_lock(&data->lock); | 882 | mutex_lock(&data->lock); |
@@ -943,7 +941,7 @@ static ssize_t set_volt_max(struct device *dev, | |||
943 | return -EINVAL; | 941 | return -EINVAL; |
944 | 942 | ||
945 | temp *= 1000; /* convert mV to uV */ | 943 | temp *= 1000; /* convert mV to uV */ |
946 | temp = ROUND_DIV(temp, x); | 944 | temp = DIV_ROUND_CLOSEST(temp, x); |
947 | temp = SENSORS_LIMIT(temp, 0, 255); | 945 | temp = SENSORS_LIMIT(temp, 0, 255); |
948 | 946 | ||
949 | mutex_lock(&data->lock); | 947 | mutex_lock(&data->lock); |
@@ -985,7 +983,7 @@ static ssize_t set_volt_min(struct device *dev, | |||
985 | return -EINVAL; | 983 | return -EINVAL; |
986 | 984 | ||
987 | temp *= 1000; /* convert mV to uV */ | 985 | temp *= 1000; /* convert mV to uV */ |
988 | temp = ROUND_DIV(temp, x); | 986 | temp = DIV_ROUND_CLOSEST(temp, x); |
989 | temp = SENSORS_LIMIT(temp, 0, 255); | 987 | temp = SENSORS_LIMIT(temp, 0, 255); |
990 | 988 | ||
991 | mutex_lock(&data->lock); | 989 | mutex_lock(&data->lock); |
@@ -1250,7 +1248,7 @@ static ssize_t set_pwm_hyst(struct device *dev, | |||
1250 | if (strict_strtol(buf, 10, &temp)) | 1248 | if (strict_strtol(buf, 10, &temp)) |
1251 | return -EINVAL; | 1249 | return -EINVAL; |
1252 | 1250 | ||
1253 | temp = ROUND_DIV(temp, 1000); | 1251 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
1254 | temp = SENSORS_LIMIT(temp, 0, 15); | 1252 | temp = SENSORS_LIMIT(temp, 0, 15); |
1255 | 1253 | ||
1256 | /* package things up */ | 1254 | /* package things up */ |
@@ -1337,7 +1335,7 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
1337 | if (strict_strtol(buf, 10, &temp)) | 1335 | if (strict_strtol(buf, 10, &temp)) |
1338 | return -EINVAL; | 1336 | return -EINVAL; |
1339 | 1337 | ||
1340 | temp = ROUND_DIV(temp, 1000) + 64; | 1338 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
1341 | temp = SENSORS_LIMIT(temp, 0, 255); | 1339 | temp = SENSORS_LIMIT(temp, 0, 255); |
1342 | 1340 | ||
1343 | mutex_lock(&data->lock); | 1341 | mutex_lock(&data->lock); |
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 1311a595147e..da6c9306ca5f 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -137,8 +137,6 @@ I2C_CLIENT_INSMOD_1(adt7470); | |||
137 | #define FAN_PERIOD_INVALID 65535 | 137 | #define FAN_PERIOD_INVALID 65535 |
138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
139 | 139 | ||
140 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
141 | |||
142 | struct adt7470_data { | 140 | struct adt7470_data { |
143 | struct device *hwmon_dev; | 141 | struct device *hwmon_dev; |
144 | struct attribute_group attrs; | 142 | struct attribute_group attrs; |
@@ -360,7 +358,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
360 | if (strict_strtol(buf, 10, &temp)) | 358 | if (strict_strtol(buf, 10, &temp)) |
361 | return -EINVAL; | 359 | return -EINVAL; |
362 | 360 | ||
363 | temp = ROUND_DIV(temp, 1000); | 361 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
364 | temp = SENSORS_LIMIT(temp, 0, 255); | 362 | temp = SENSORS_LIMIT(temp, 0, 255); |
365 | 363 | ||
366 | mutex_lock(&data->lock); | 364 | mutex_lock(&data->lock); |
@@ -394,7 +392,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
394 | if (strict_strtol(buf, 10, &temp)) | 392 | if (strict_strtol(buf, 10, &temp)) |
395 | return -EINVAL; | 393 | return -EINVAL; |
396 | 394 | ||
397 | temp = ROUND_DIV(temp, 1000); | 395 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
398 | temp = SENSORS_LIMIT(temp, 0, 255); | 396 | temp = SENSORS_LIMIT(temp, 0, 255); |
399 | 397 | ||
400 | mutex_lock(&data->lock); | 398 | mutex_lock(&data->lock); |
@@ -671,7 +669,7 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
671 | if (strict_strtol(buf, 10, &temp)) | 669 | if (strict_strtol(buf, 10, &temp)) |
672 | return -EINVAL; | 670 | return -EINVAL; |
673 | 671 | ||
674 | temp = ROUND_DIV(temp, 1000); | 672 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
675 | temp = SENSORS_LIMIT(temp, 0, 255); | 673 | temp = SENSORS_LIMIT(temp, 0, 255); |
676 | 674 | ||
677 | mutex_lock(&data->lock); | 675 | mutex_lock(&data->lock); |
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index 18aa30866a6c..0a6ce2367b42 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
@@ -129,8 +129,6 @@ I2C_CLIENT_INSMOD_1(adt7473); | |||
129 | #define FAN_PERIOD_INVALID 65535 | 129 | #define FAN_PERIOD_INVALID 65535 |
130 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 130 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
131 | 131 | ||
132 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
133 | |||
134 | struct adt7473_data { | 132 | struct adt7473_data { |
135 | struct device *hwmon_dev; | 133 | struct device *hwmon_dev; |
136 | struct attribute_group attrs; | 134 | struct attribute_group attrs; |
@@ -459,7 +457,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
459 | if (strict_strtol(buf, 10, &temp)) | 457 | if (strict_strtol(buf, 10, &temp)) |
460 | return -EINVAL; | 458 | return -EINVAL; |
461 | 459 | ||
462 | temp = ROUND_DIV(temp, 1000); | 460 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
463 | temp = encode_temp(data->temp_twos_complement, temp); | 461 | temp = encode_temp(data->temp_twos_complement, temp); |
464 | 462 | ||
465 | mutex_lock(&data->lock); | 463 | mutex_lock(&data->lock); |
@@ -495,7 +493,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
495 | if (strict_strtol(buf, 10, &temp)) | 493 | if (strict_strtol(buf, 10, &temp)) |
496 | return -EINVAL; | 494 | return -EINVAL; |
497 | 495 | ||
498 | temp = ROUND_DIV(temp, 1000); | 496 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
499 | temp = encode_temp(data->temp_twos_complement, temp); | 497 | temp = encode_temp(data->temp_twos_complement, temp); |
500 | 498 | ||
501 | mutex_lock(&data->lock); | 499 | mutex_lock(&data->lock); |
@@ -720,7 +718,7 @@ static ssize_t set_temp_tmax(struct device *dev, | |||
720 | if (strict_strtol(buf, 10, &temp)) | 718 | if (strict_strtol(buf, 10, &temp)) |
721 | return -EINVAL; | 719 | return -EINVAL; |
722 | 720 | ||
723 | temp = ROUND_DIV(temp, 1000); | 721 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
724 | temp = encode_temp(data->temp_twos_complement, temp); | 722 | temp = encode_temp(data->temp_twos_complement, temp); |
725 | 723 | ||
726 | mutex_lock(&data->lock); | 724 | mutex_lock(&data->lock); |
@@ -756,7 +754,7 @@ static ssize_t set_temp_tmin(struct device *dev, | |||
756 | if (strict_strtol(buf, 10, &temp)) | 754 | if (strict_strtol(buf, 10, &temp)) |
757 | return -EINVAL; | 755 | return -EINVAL; |
758 | 756 | ||
759 | temp = ROUND_DIV(temp, 1000); | 757 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
760 | temp = encode_temp(data->temp_twos_complement, temp); | 758 | temp = encode_temp(data->temp_twos_complement, temp); |
761 | 759 | ||
762 | mutex_lock(&data->lock); | 760 | mutex_lock(&data->lock); |