diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-01-09 11:09:34 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-01-26 00:03:54 -0500 |
commit | 2a844c148e1f714ebf42cb96e1b172ce394c36c9 (patch) | |
tree | eb68eb8438f0470e7a81b022199abe5f6d866879 /drivers/hwmon/w83792d.c | |
parent | 142c090184ac7f9763c5d22509405da3486f9801 (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/w83792d.c')
-rw-r--r-- | drivers/hwmon/w83792d.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 301942d08453..5cb83ddf2cc6 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -235,8 +235,8 @@ FAN_TO_REG(long rpm, int div) | |||
235 | { | 235 | { |
236 | if (rpm == 0) | 236 | if (rpm == 0) |
237 | return 255; | 237 | return 255; |
238 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 238 | rpm = clamp_val(rpm, 1, 1000000); |
239 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 239 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
240 | } | 240 | } |
241 | 241 | ||
242 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 242 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
@@ -244,16 +244,15 @@ FAN_TO_REG(long rpm, int div) | |||
244 | 1350000 / ((val) * (div)))) | 244 | 1350000 / ((val) * (div)))) |
245 | 245 | ||
246 | /* for temp1 */ | 246 | /* for temp1 */ |
247 | #define TEMP1_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ | 247 | #define TEMP1_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \ |
248 | : (val)) / 1000, 0, 0xff)) | 248 | : (val)) / 1000, 0, 0xff)) |
249 | #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) | 249 | #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) |
250 | /* for temp2 and temp3, because they need additional resolution */ | 250 | /* for temp2 and temp3, because they need additional resolution */ |
251 | #define TEMP_ADD_FROM_REG(val1, val2) \ | 251 | #define TEMP_ADD_FROM_REG(val1, val2) \ |
252 | ((((val1) & 0x80 ? (val1)-0x100 \ | 252 | ((((val1) & 0x80 ? (val1)-0x100 \ |
253 | : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) | 253 | : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) |
254 | #define TEMP_ADD_TO_REG_HIGH(val) \ | 254 | #define TEMP_ADD_TO_REG_HIGH(val) \ |
255 | (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ | 255 | (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 : (val)) / 1000, 0, 0xff)) |
256 | : (val)) / 1000, 0, 0xff)) | ||
257 | #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) | 256 | #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) |
258 | 257 | ||
259 | #define DIV_FROM_REG(val) (1 << (val)) | 258 | #define DIV_FROM_REG(val) (1 << (val)) |
@@ -262,7 +261,7 @@ static inline u8 | |||
262 | DIV_TO_REG(long val) | 261 | DIV_TO_REG(long val) |
263 | { | 262 | { |
264 | int i; | 263 | int i; |
265 | val = SENSORS_LIMIT(val, 1, 128) >> 1; | 264 | val = clamp_val(val, 1, 128) >> 1; |
266 | for (i = 0; i < 7; i++) { | 265 | for (i = 0; i < 7; i++) { |
267 | if (val == 0) | 266 | if (val == 0) |
268 | break; | 267 | break; |
@@ -397,7 +396,7 @@ static ssize_t store_in_##reg(struct device *dev, \ | |||
397 | if (err) \ | 396 | if (err) \ |
398 | return err; \ | 397 | return err; \ |
399 | mutex_lock(&data->update_lock); \ | 398 | mutex_lock(&data->update_lock); \ |
400 | data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val) / 4, 0, 255); \ | 399 | data->in_##reg[nr] = clamp_val(IN_TO_REG(nr, val) / 4, 0, 255); \ |
401 | w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \ | 400 | w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \ |
402 | data->in_##reg[nr]); \ | 401 | data->in_##reg[nr]); \ |
403 | mutex_unlock(&data->update_lock); \ | 402 | mutex_unlock(&data->update_lock); \ |
@@ -645,7 +644,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
645 | err = kstrtoul(buf, 10, &val); | 644 | err = kstrtoul(buf, 10, &val); |
646 | if (err) | 645 | if (err) |
647 | return err; | 646 | return err; |
648 | val = SENSORS_LIMIT(val, 0, 255) >> 4; | 647 | val = clamp_val(val, 0, 255) >> 4; |
649 | 648 | ||
650 | mutex_lock(&data->update_lock); | 649 | mutex_lock(&data->update_lock); |
651 | val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; | 650 | val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; |
@@ -799,7 +798,7 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr, | |||
799 | mutex_lock(&data->update_lock); | 798 | mutex_lock(&data->update_lock); |
800 | target_mask = w83792d_read_value(client, | 799 | target_mask = w83792d_read_value(client, |
801 | W83792D_REG_THERMAL[nr]) & 0x80; | 800 | W83792D_REG_THERMAL[nr]) & 0x80; |
802 | data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); | 801 | data->thermal_cruise[nr] = clamp_val(target_tmp, 0, 255); |
803 | w83792d_write_value(client, W83792D_REG_THERMAL[nr], | 802 | w83792d_write_value(client, W83792D_REG_THERMAL[nr], |
804 | (data->thermal_cruise[nr]) | target_mask); | 803 | (data->thermal_cruise[nr]) | target_mask); |
805 | mutex_unlock(&data->update_lock); | 804 | mutex_unlock(&data->update_lock); |
@@ -837,7 +836,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
837 | mutex_lock(&data->update_lock); | 836 | mutex_lock(&data->update_lock); |
838 | tol_mask = w83792d_read_value(client, | 837 | tol_mask = w83792d_read_value(client, |
839 | W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); | 838 | W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); |
840 | tol_tmp = SENSORS_LIMIT(val, 0, 15); | 839 | tol_tmp = clamp_val(val, 0, 15); |
841 | tol_tmp &= 0x0f; | 840 | tol_tmp &= 0x0f; |
842 | data->tolerance[nr] = tol_tmp; | 841 | data->tolerance[nr] = tol_tmp; |
843 | if (nr == 1) | 842 | if (nr == 1) |
@@ -881,7 +880,7 @@ store_sf2_point(struct device *dev, struct device_attribute *attr, | |||
881 | return err; | 880 | return err; |
882 | 881 | ||
883 | mutex_lock(&data->update_lock); | 882 | mutex_lock(&data->update_lock); |
884 | data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); | 883 | data->sf2_points[index][nr] = clamp_val(val, 0, 127); |
885 | mask_tmp = w83792d_read_value(client, | 884 | mask_tmp = w83792d_read_value(client, |
886 | W83792D_REG_POINTS[index][nr]) & 0x80; | 885 | W83792D_REG_POINTS[index][nr]) & 0x80; |
887 | w83792d_write_value(client, W83792D_REG_POINTS[index][nr], | 886 | w83792d_write_value(client, W83792D_REG_POINTS[index][nr], |
@@ -923,7 +922,7 @@ store_sf2_level(struct device *dev, struct device_attribute *attr, | |||
923 | return err; | 922 | return err; |
924 | 923 | ||
925 | mutex_lock(&data->update_lock); | 924 | mutex_lock(&data->update_lock); |
926 | data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); | 925 | data->sf2_levels[index][nr] = clamp_val((val * 15) / 100, 0, 15); |
927 | mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) | 926 | mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) |
928 | & ((nr == 3) ? 0xf0 : 0x0f); | 927 | & ((nr == 3) ? 0xf0 : 0x0f); |
929 | if (nr == 3) | 928 | if (nr == 3) |