aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83781d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83781d.c')
-rw-r--r--drivers/hwmon/w83781d.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 93bd28639595..aeec5b1d81c9 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -159,7 +159,7 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
159#define W83781D_DEFAULT_BETA 3435 159#define W83781D_DEFAULT_BETA 3435
160 160
161/* Conversions */ 161/* Conversions */
162#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255) 162#define IN_TO_REG(val) clamp_val(((val) + 8) / 16, 0, 255)
163#define IN_FROM_REG(val) ((val) * 16) 163#define IN_FROM_REG(val) ((val) * 16)
164 164
165static inline u8 165static inline u8
@@ -167,8 +167,8 @@ FAN_TO_REG(long rpm, int div)
167{ 167{
168 if (rpm == 0) 168 if (rpm == 0)
169 return 255; 169 return 255;
170 rpm = SENSORS_LIMIT(rpm, 1, 1000000); 170 rpm = clamp_val(rpm, 1, 1000000);
171 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 171 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
172} 172}
173 173
174static inline long 174static inline long
@@ -181,7 +181,7 @@ FAN_FROM_REG(u8 val, int div)
181 return 1350000 / (val * div); 181 return 1350000 / (val * div);
182} 182}
183 183
184#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128) 184#define TEMP_TO_REG(val) clamp_val((val) / 1000, -127, 128)
185#define TEMP_FROM_REG(val) ((val) * 1000) 185#define TEMP_FROM_REG(val) ((val) * 1000)
186 186
187#define BEEP_MASK_FROM_REG(val, type) ((type) == as99127f ? \ 187#define BEEP_MASK_FROM_REG(val, type) ((type) == as99127f ? \
@@ -195,9 +195,8 @@ static inline u8
195DIV_TO_REG(long val, enum chips type) 195DIV_TO_REG(long val, enum chips type)
196{ 196{
197 int i; 197 int i;
198 val = SENSORS_LIMIT(val, 1, 198 val = clamp_val(val, 1,
199 ((type == w83781d 199 ((type == w83781d || type == as99127f) ? 8 : 128)) >> 1;
200 || type == as99127f) ? 8 : 128)) >> 1;
201 for (i = 0; i < 7; i++) { 200 for (i = 0; i < 7; i++) {
202 if (val == 0) 201 if (val == 0)
203 break; 202 break;
@@ -443,7 +442,7 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr,
443 err = kstrtoul(buf, 10, &val); 442 err = kstrtoul(buf, 10, &val);
444 if (err) 443 if (err)
445 return err; 444 return err;
446 data->vrm = SENSORS_LIMIT(val, 0, 255); 445 data->vrm = clamp_val(val, 0, 255);
447 446
448 return count; 447 return count;
449} 448}
@@ -730,7 +729,7 @@ store_pwm(struct device *dev, struct device_attribute *da, const char *buf,
730 return err; 729 return err;
731 730
732 mutex_lock(&data->update_lock); 731 mutex_lock(&data->update_lock);
733 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); 732 data->pwm[nr] = clamp_val(val, 0, 255);
734 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]); 733 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]);
735 mutex_unlock(&data->update_lock); 734 mutex_unlock(&data->update_lock);
736 return count; 735 return count;