aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83l786ng.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-01-09 11:09:34 -0500
committerGuenter Roeck <linux@roeck-us.net>2013-01-26 00:03:54 -0500
commit2a844c148e1f714ebf42cb96e1b172ce394c36c9 (patch)
treeeb68eb8438f0470e7a81b022199abe5f6d866879 /drivers/hwmon/w83l786ng.c
parent142c090184ac7f9763c5d22509405da3486f9801 (diff)
hwmon: Replace SENSORS_LIMIT with clamp_val
SENSORS_LIMIT and the generic clamp_val have the same functionality, and clamp_val is more efficient. This patch reduces text size by 9052 bytes and bss size by 11624 bytes for x86_64 builds. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: George Joseph <george.joseph@fairview5.com> Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/w83l786ng.c')
-rw-r--r--drivers/hwmon/w83l786ng.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index 79710bcac2f7..edb06cda5a68 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -86,8 +86,8 @@ FAN_TO_REG(long rpm, int div)
86{ 86{
87 if (rpm == 0) 87 if (rpm == 0)
88 return 255; 88 return 255;
89 rpm = SENSORS_LIMIT(rpm, 1, 1000000); 89 rpm = clamp_val(rpm, 1, 1000000);
90 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 90 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
91} 91}
92 92
93#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ 93#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
@@ -95,9 +95,8 @@ FAN_TO_REG(long rpm, int div)
95 1350000 / ((val) * (div)))) 95 1350000 / ((val) * (div))))
96 96
97/* for temp */ 97/* for temp */
98#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? \ 98#define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
99 (val) + 0x100 * 1000 \ 99 : (val)) / 1000, 0, 0xff))
100 : (val)) / 1000, 0, 0xff))
101#define TEMP_FROM_REG(val) (((val) & 0x80 ? \ 100#define TEMP_FROM_REG(val) (((val) & 0x80 ? \
102 (val) - 0x100 : (val)) * 1000) 101 (val) - 0x100 : (val)) * 1000)
103 102
@@ -106,7 +105,7 @@ FAN_TO_REG(long rpm, int div)
106 * in mV as would be measured on the chip input pin, need to just 105 * in mV as would be measured on the chip input pin, need to just
107 * multiply/divide by 8 to translate from/to register values. 106 * multiply/divide by 8 to translate from/to register values.
108 */ 107 */
109#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255)) 108#define IN_TO_REG(val) (clamp_val((((val) + 4) / 8), 0, 255))
110#define IN_FROM_REG(val) ((val) * 8) 109#define IN_FROM_REG(val) ((val) * 8)
111 110
112#define DIV_FROM_REG(val) (1 << (val)) 111#define DIV_FROM_REG(val) (1 << (val))
@@ -115,7 +114,7 @@ static inline u8
115DIV_TO_REG(long val) 114DIV_TO_REG(long val)
116{ 115{
117 int i; 116 int i;
118 val = SENSORS_LIMIT(val, 1, 128) >> 1; 117 val = clamp_val(val, 1, 128) >> 1;
119 for (i = 0; i < 7; i++) { 118 for (i = 0; i < 7; i++) {
120 if (val == 0) 119 if (val == 0)
121 break; 120 break;
@@ -481,7 +480,7 @@ store_pwm(struct device *dev, struct device_attribute *attr,
481 err = kstrtoul(buf, 10, &val); 480 err = kstrtoul(buf, 10, &val);
482 if (err) 481 if (err)
483 return err; 482 return err;
484 val = SENSORS_LIMIT(val, 0, 255); 483 val = clamp_val(val, 0, 255);
485 484
486 mutex_lock(&data->update_lock); 485 mutex_lock(&data->update_lock);
487 data->pwm[nr] = val; 486 data->pwm[nr] = val;
@@ -564,7 +563,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
564 mutex_lock(&data->update_lock); 563 mutex_lock(&data->update_lock);
565 tol_mask = w83l786ng_read_value(client, 564 tol_mask = w83l786ng_read_value(client,
566 W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0); 565 W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0);
567 tol_tmp = SENSORS_LIMIT(val, 0, 15); 566 tol_tmp = clamp_val(val, 0, 15);
568 tol_tmp &= 0x0f; 567 tol_tmp &= 0x0f;
569 data->tolerance[nr] = tol_tmp; 568 data->tolerance[nr] = tol_tmp;
570 if (nr == 1) 569 if (nr == 1)