Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a844c14 authored by Guenter Roeck's avatar Guenter Roeck
Browse files

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: default avatarGuenter Roeck <linux@roeck-us.net>
Acked-by: default avatarGeorge Joseph <george.joseph@fairview5.com>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
parent 142c0901
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ static ssize_t set_max_min(struct device *dev,
	if (ret < 0)
		return ret;

	temp = SENSORS_LIMIT(temp, -40000, 85000);
	temp = clamp_val(temp, -40000, 85000);
	temp = (temp + (temp < 0 ? -500 : 500)) / 1000;

	mutex_lock(&data->lock);
+2 −2
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ static ssize_t set_temp_max(struct device *dev,
	temp /= 1000;

	mutex_lock(&data->update_lock);
	data->temp_max[index] = SENSORS_LIMIT(temp, -128, 127);
	data->temp_max[index] = clamp_val(temp, -128, 127);
	if (!read_only)
		i2c_smbus_write_byte_data(client, ADM1021_REG_TOS_W(index),
					  data->temp_max[index]);
@@ -218,7 +218,7 @@ static ssize_t set_temp_min(struct device *dev,
	temp /= 1000;

	mutex_lock(&data->update_lock);
	data->temp_min[index] = SENSORS_LIMIT(temp, -128, 127);
	data->temp_min[index] = clamp_val(temp, -128, 127);
	if (!read_only)
		i2c_smbus_write_byte_data(client, ADM1021_REG_THYST_W(index),
					  data->temp_min[index]);
+8 −8
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
	};
#define NEG12_OFFSET  16000
#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n, val)  (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\
#define INS_TO_REG(n, val)  (clamp_val(SCALE(val, adm1026_scaling[n], 192),\
	0, 255))
#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))

@@ -207,7 +207,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
 *      22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
 */
#define FAN_TO_REG(val, div)  ((val) <= 0 ? 0xff : \
				SENSORS_LIMIT(1350000 / ((val) * (div)), \
				clamp_val(1350000 / ((val) * (div)), \
					      1, 254))
#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
				1350000 / ((val) * (div)))
@@ -215,14 +215,14 @@ static int adm1026_scaling[] = { /* .001 Volts */
#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)

/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
#define TEMP_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
					/ 1000, -127, 127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
#define OFFSET_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
					  / 1000, -127, 127))
#define OFFSET_FROM_REG(val) ((val) * 1000)

#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
#define PWM_TO_REG(val) (clamp_val(val, 0, 255))
#define PWM_FROM_REG(val) (val)

#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
@@ -233,7 +233,7 @@ static int adm1026_scaling[] = { /* .001 Volts */
 *   indicates that the DAC could be used to drive the fans, but in our
 *   example board (Arima HDAMA) it isn't connected to the fans at all.
 */
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255))
#define DAC_TO_REG(val) (clamp_val(((((val) * 255) + 500) / 2500), 0, 255))
#define DAC_FROM_REG(val) (((val) * 2500) / 255)

/*
@@ -933,7 +933,7 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
		return;

	new_min = data->fan_min[fan] * old_div / new_div;
	new_min = SENSORS_LIMIT(new_min, 1, 254);
	new_min = clamp_val(new_min, 1, 254);
	data->fan_min[fan] = new_min;
	adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
@@ -1527,7 +1527,7 @@ static ssize_t set_auto_pwm_min(struct device *dev,
		return err;

	mutex_lock(&data->update_lock);
	data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255);
	data->pwm1.auto_pwm_min = clamp_val(val, 0, 255);
	if (data->pwm1.enable == 2) { /* apply immediately */
		data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
			PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+6 −6
Original line number Diff line number Diff line
@@ -162,13 +162,13 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value)
static int FAN_TO_REG(int reg, int div)
{
	int tmp;
	tmp = FAN_FROM_REG(SENSORS_LIMIT(reg, 0, 65535), div);
	tmp = FAN_FROM_REG(clamp_val(reg, 0, 65535), div);
	return tmp > 255 ? 255 : tmp;
}

#define FAN_DIV_FROM_REG(reg)		(1<<(((reg)&0xc0)>>6))

#define PWM_TO_REG(val)			(SENSORS_LIMIT((val), 0, 255) >> 4)
#define PWM_TO_REG(val)			(clamp_val((val), 0, 255) >> 4)
#define PWM_FROM_REG(val)		((val) << 4)

#define FAN_CHAN_FROM_REG(reg)		(((reg) >> 5) & 7)
@@ -675,7 +675,7 @@ static ssize_t set_temp_offset(struct device *dev,
	if (ret)
		return ret;

	val = SENSORS_LIMIT(val, -15000, 15000);
	val = clamp_val(val, -15000, 15000);
	mutex_lock(&data->update_lock);
	data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val);
	adm1031_write_value(client, ADM1031_REG_TEMP_OFFSET(nr),
@@ -696,7 +696,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
	if (ret)
		return ret;

	val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
	val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875);
	mutex_lock(&data->update_lock);
	data->temp_min[nr] = TEMP_TO_REG(val);
	adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
@@ -717,7 +717,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
	if (ret)
		return ret;

	val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
	val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875);
	mutex_lock(&data->update_lock);
	data->temp_max[nr] = TEMP_TO_REG(val);
	adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
@@ -738,7 +738,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
	if (ret)
		return ret;

	val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
	val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875);
	mutex_lock(&data->update_lock);
	data->temp_crit[nr] = TEMP_TO_REG(val);
	adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
+3 −3
Original line number Diff line number Diff line
@@ -98,13 +98,13 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n)

static inline u8 IN_TO_REG(unsigned long val, int n)
{
	return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
	return clamp_val(SCALE(val, 192, nom_mv[n]), 0, 255);
}

/* temperature range: -40..125, 127 disables temperature alarm */
static inline s8 TEMP_TO_REG(long val)
{
	return SENSORS_LIMIT(SCALE(val, 1, 1000), -40, 127);
	return clamp_val(SCALE(val, 1, 1000), -40, 127);
}

/* two fans, each with low fan speed limit */
@@ -122,7 +122,7 @@ static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)
/* analog out 0..1250mV */
static inline u8 AOUT_TO_REG(unsigned long val)
{
	return SENSORS_LIMIT(SCALE(val, 255, 1250), 0, 255);
	return clamp_val(SCALE(val, 255, 1250), 0, 255);
}

static inline unsigned int AOUT_FROM_REG(u8 reg)
Loading