aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1026.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/adm1026.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/adm1026.c')
-rw-r--r--drivers/hwmon/adm1026.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 0f068e7297ee..ea09046e651d 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -197,7 +197,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
197 }; 197 };
198#define NEG12_OFFSET 16000 198#define NEG12_OFFSET 16000
199#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from)) 199#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
200#define INS_TO_REG(n, val) (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\ 200#define INS_TO_REG(n, val) (clamp_val(SCALE(val, adm1026_scaling[n], 192),\
201 0, 255)) 201 0, 255))
202#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) 202#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
203 203
@@ -207,7 +207,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
207 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 207 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
208 */ 208 */
209#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ 209#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
210 SENSORS_LIMIT(1350000 / ((val) * (div)), \ 210 clamp_val(1350000 / ((val) * (div)), \
211 1, 254)) 211 1, 254))
212#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \ 212#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
213 1350000 / ((val) * (div))) 213 1350000 / ((val) * (div)))
@@ -215,14 +215,14 @@ static int adm1026_scaling[] = { /* .001 Volts */
215#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) 215#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
216 216
217/* Temperature is reported in 1 degC increments */ 217/* Temperature is reported in 1 degC increments */
218#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ 218#define TEMP_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
219 / 1000, -127, 127)) 219 / 1000, -127, 127))
220#define TEMP_FROM_REG(val) ((val) * 1000) 220#define TEMP_FROM_REG(val) ((val) * 1000)
221#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ 221#define OFFSET_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
222 / 1000, -127, 127)) 222 / 1000, -127, 127))
223#define OFFSET_FROM_REG(val) ((val) * 1000) 223#define OFFSET_FROM_REG(val) ((val) * 1000)
224 224
225#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) 225#define PWM_TO_REG(val) (clamp_val(val, 0, 255))
226#define PWM_FROM_REG(val) (val) 226#define PWM_FROM_REG(val) (val)
227 227
228#define PWM_MIN_TO_REG(val) ((val) & 0xf0) 228#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
@@ -233,7 +233,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
233 * indicates that the DAC could be used to drive the fans, but in our 233 * indicates that the DAC could be used to drive the fans, but in our
234 * example board (Arima HDAMA) it isn't connected to the fans at all. 234 * example board (Arima HDAMA) it isn't connected to the fans at all.
235 */ 235 */
236#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255)) 236#define DAC_TO_REG(val) (clamp_val(((((val) * 255) + 500) / 2500), 0, 255))
237#define DAC_FROM_REG(val) (((val) * 2500) / 255) 237#define DAC_FROM_REG(val) (((val) * 2500) / 255)
238 238
239/* 239/*
@@ -933,7 +933,7 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
933 return; 933 return;
934 934
935 new_min = data->fan_min[fan] * old_div / new_div; 935 new_min = data->fan_min[fan] * old_div / new_div;
936 new_min = SENSORS_LIMIT(new_min, 1, 254); 936 new_min = clamp_val(new_min, 1, 254);
937 data->fan_min[fan] = new_min; 937 data->fan_min[fan] = new_min;
938 adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min); 938 adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
939} 939}
@@ -1527,7 +1527,7 @@ static ssize_t set_auto_pwm_min(struct device *dev,
1527 return err; 1527 return err;
1528 1528
1529 mutex_lock(&data->update_lock); 1529 mutex_lock(&data->update_lock);
1530 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); 1530 data->pwm1.auto_pwm_min = clamp_val(val, 0, 255);
1531 if (data->pwm1.enable == 2) { /* apply immediately */ 1531 if (data->pwm1.enable == 2) { /* apply immediately */
1532 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | 1532 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1533 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 1533 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));