aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627hf.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/w83627hf.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/w83627hf.c')
-rw-r--r--drivers/hwmon/w83627hf.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 81f486520cea..3b9ef2d23452 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -254,16 +254,15 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
254 * these macros are called: arguments may be evaluated more than once. 254 * these macros are called: arguments may be evaluated more than once.
255 * Fixing this is just not worth it. 255 * Fixing this is just not worth it.
256 */ 256 */
257#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 257#define IN_TO_REG(val) (clamp_val((((val) + 8) / 16), 0, 255))
258#define IN_FROM_REG(val) ((val) * 16) 258#define IN_FROM_REG(val) ((val) * 16)
259 259
260static inline u8 FAN_TO_REG(long rpm, int div) 260static inline u8 FAN_TO_REG(long rpm, int div)
261{ 261{
262 if (rpm == 0) 262 if (rpm == 0)
263 return 255; 263 return 255;
264 rpm = SENSORS_LIMIT(rpm, 1, 1000000); 264 rpm = clamp_val(rpm, 1, 1000000);
265 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 265 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
266 254);
267} 266}
268 267
269#define TEMP_MIN (-128000) 268#define TEMP_MIN (-128000)
@@ -275,9 +274,9 @@ static inline u8 FAN_TO_REG(long rpm, int div)
275 */ 274 */
276static u8 TEMP_TO_REG(long temp) 275static u8 TEMP_TO_REG(long temp)
277{ 276{
278 int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX); 277 int ntemp = clamp_val(temp, TEMP_MIN, TEMP_MAX);
279 ntemp += (ntemp<0 ? -500 : 500); 278 ntemp += (ntemp < 0 ? -500 : 500);
280 return (u8)(ntemp / 1000); 279 return (u8)(ntemp / 1000);
281} 280}
282 281
283static int TEMP_FROM_REG(u8 reg) 282static int TEMP_FROM_REG(u8 reg)
@@ -287,7 +286,7 @@ static int TEMP_FROM_REG(u8 reg)
287 286
288#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 287#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
289 288
290#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) 289#define PWM_TO_REG(val) (clamp_val((val), 0, 255))
291 290
292static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) 291static inline unsigned long pwm_freq_from_reg_627hf(u8 reg)
293{ 292{
@@ -342,7 +341,7 @@ static inline u8 pwm_freq_to_reg(unsigned long val)
342static inline u8 DIV_TO_REG(long val) 341static inline u8 DIV_TO_REG(long val)
343{ 342{
344 int i; 343 int i;
345 val = SENSORS_LIMIT(val, 1, 128) >> 1; 344 val = clamp_val(val, 1, 128) >> 1;
346 for (i = 0; i < 7; i++) { 345 for (i = 0; i < 7; i++) {
347 if (val == 0) 346 if (val == 0)
348 break; 347 break;
@@ -614,8 +613,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
614 613
615 /* use VRM9 calculation */ 614 /* use VRM9 calculation */
616 data->in_min[0] = 615 data->in_min[0] =
617 SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, 616 clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255);
618 255);
619 else 617 else
620 /* use VRM8 (standard) calculation */ 618 /* use VRM8 (standard) calculation */
621 data->in_min[0] = IN_TO_REG(val); 619 data->in_min[0] = IN_TO_REG(val);
@@ -644,8 +642,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
644 642
645 /* use VRM9 calculation */ 643 /* use VRM9 calculation */
646 data->in_max[0] = 644 data->in_max[0] =
647 SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, 645 clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255);
648 255);
649 else 646 else
650 /* use VRM8 (standard) calculation */ 647 /* use VRM8 (standard) calculation */
651 data->in_max[0] = IN_TO_REG(val); 648 data->in_max[0] = IN_TO_REG(val);