Commit bc27490f authored by Hans de Goede's avatar Hans de Goede Committed by Jean Delvare

hwmon: (f71882fg) Cleanup fan and temp hyst functions

Simplify fan and temp hyst. handling by treating the registers as an array of
nibbles instead of using switch cases. Also unify the way hysts are handled
between temp and fans, the temp code was storing the actual per temp hyst
values in 4 u8's, where as the fan code was storing actual register values.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent ce0bfa5e
...@@ -68,8 +68,7 @@ ...@@ -68,8 +68,7 @@
#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr)) #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
#define F71882FG_REG_TEMP_STATUS 0x62 #define F71882FG_REG_TEMP_STATUS 0x62
#define F71882FG_REG_TEMP_BEEP 0x63 #define F71882FG_REG_TEMP_BEEP 0x63
#define F71882FG_REG_TEMP_HYST1 0x6C #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
#define F71882FG_REG_TEMP_HYST23 0x6D
#define F71882FG_REG_TEMP_TYPE 0x6B #define F71882FG_REG_TEMP_TYPE 0x6B
#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
...@@ -77,8 +76,7 @@ ...@@ -77,8 +76,7 @@
#define F71882FG_REG_PWM_TYPE 0x94 #define F71882FG_REG_PWM_TYPE 0x94
#define F71882FG_REG_PWM_ENABLE 0x96 #define F71882FG_REG_PWM_ENABLE 0x96
#define F71882FG_REG_FAN_HYST0 0x98 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
#define F71882FG_REG_FAN_HYST1 0x99
#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm))) #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm))) #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
...@@ -144,7 +142,7 @@ struct f71882fg_data { ...@@ -144,7 +142,7 @@ struct f71882fg_data {
u8 temp[4]; u8 temp[4];
u8 temp_ovt[4]; u8 temp_ovt[4];
u8 temp_high[4]; u8 temp_high[4];
u8 temp_hyst[4]; u8 temp_hyst[2]; /* 2 hysts stored per reg */
u8 temp_type[4]; u8 temp_type[4];
u8 temp_status; u8 temp_status;
u8 temp_beep; u8 temp_beep;
...@@ -688,13 +686,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev) ...@@ -688,13 +686,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
F71882FG_REG_TEMP_HIGH(nr)); F71882FG_REG_TEMP_HIGH(nr));
} }
/* Have to hardcode hyst*/ /* hyst */
data->temp_hyst[1] = f71882fg_read8(data, data->temp_hyst[0] =
F71882FG_REG_TEMP_HYST1) >> 4; f71882fg_read8(data, F71882FG_REG_TEMP_HYST(0));
/* Hyst temps 2 & 3 stored in same register */ data->temp_hyst[1] =
reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); f71882fg_read8(data, F71882FG_REG_TEMP_HYST(1));
data->temp_hyst[2] = reg & 0x0F;
data->temp_hyst[3] = reg >> 4;
/* Have to hardcode type, because temp1 is special */ /* Have to hardcode type, because temp1 is special */
reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE); reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
...@@ -715,10 +711,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev) ...@@ -715,10 +711,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
data->pwm_enable = f71882fg_read8(data, data->pwm_enable = f71882fg_read8(data,
F71882FG_REG_PWM_ENABLE); F71882FG_REG_PWM_ENABLE);
data->pwm_auto_point_hyst[0] = f71882fg_read8(data, data->pwm_auto_point_hyst[0] =
F71882FG_REG_FAN_HYST0); f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
data->pwm_auto_point_hyst[1] = f71882fg_read8(data, data->pwm_auto_point_hyst[1] =
F71882FG_REG_FAN_HYST1); f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
for (nr = 0; nr < nr_fans; nr++) { for (nr = 0; nr < nr_fans; nr++) {
data->pwm_auto_point_mapping[nr] = data->pwm_auto_point_mapping[nr] =
f71882fg_read8(data, f71882fg_read8(data,
...@@ -1011,7 +1008,11 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute ...@@ -1011,7 +1008,11 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
int temp_max_hyst; int temp_max_hyst;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
temp_max_hyst = (data->temp_high[nr] - data->temp_hyst[nr]) * 1000; if (nr & 1)
temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
else
temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return sprintf(buf, "%d\n", temp_max_hyst); return sprintf(buf, "%d\n", temp_max_hyst);
...@@ -1033,26 +1034,15 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute ...@@ -1033,26 +1034,15 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
val = SENSORS_LIMIT(val, data->temp_high[nr] - 15, val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
data->temp_high[nr]); data->temp_high[nr]);
val = data->temp_high[nr] - val; val = data->temp_high[nr] - val;
data->temp_hyst[nr] = val;
/* convert value to register contents */ /* convert value to register contents */
switch (nr) { reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
case 1: if (nr & 1)
reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST1); reg = (reg & 0x0f) | (val << 4);
reg = (reg & 0x0f) | (val << 4); else
break; reg = (reg & 0xf0) | val;
case 2: f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); data->temp_hyst[nr / 2] = reg;
reg = (reg & 0xf0) | val;
break;
case 3:
reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23);
reg = (reg & 0x0f) | (val << 4);
break;
}
f71882fg_write8(data, (nr <= 1) ? F71882FG_REG_TEMP_HYST1 :
F71882FG_REG_TEMP_HYST23, reg);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return ret; return ret;
...@@ -1091,7 +1081,11 @@ static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute ...@@ -1091,7 +1081,11 @@ static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
int temp_crit_hyst; int temp_crit_hyst;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
temp_crit_hyst = (data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000; if (nr & 1)
temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
else
temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return sprintf(buf, "%d\n", temp_crit_hyst); return sprintf(buf, "%d\n", temp_crit_hyst);
...@@ -1320,20 +1314,10 @@ static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev, ...@@ -1320,20 +1314,10 @@ static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
int point = to_sensor_dev_attr_2(devattr)->nr; int point = to_sensor_dev_attr_2(devattr)->nr;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
switch (nr) { if (nr & 1)
case 0: result = data->pwm_auto_point_hyst[nr / 2] >> 4;
result = data->pwm_auto_point_hyst[0] & 0x0f; else
break; result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
case 1:
result = data->pwm_auto_point_hyst[0] >> 4;
break;
case 2:
result = data->pwm_auto_point_hyst[1] & 0x0f;
break;
case 3:
result = data->pwm_auto_point_hyst[1] >> 4;
break;
}
result = 1000 * (data->pwm_auto_point_temp[nr][point] - result); result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
...@@ -1348,6 +1332,7 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, ...@@ -1348,6 +1332,7 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
int nr = to_sensor_dev_attr_2(devattr)->index; int nr = to_sensor_dev_attr_2(devattr)->index;
int point = to_sensor_dev_attr_2(devattr)->nr; int point = to_sensor_dev_attr_2(devattr)->nr;
long val = simple_strtol(buf, NULL, 10) / 1000; long val = simple_strtol(buf, NULL, 10) / 1000;
u8 reg;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm_auto_point_temp[nr][point] = data->pwm_auto_point_temp[nr][point] =
...@@ -1356,34 +1341,14 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, ...@@ -1356,34 +1341,14 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
data->pwm_auto_point_temp[nr][point]); data->pwm_auto_point_temp[nr][point]);
val = data->pwm_auto_point_temp[nr][point] - val; val = data->pwm_auto_point_temp[nr][point] - val;
if (nr == 0 || nr == 1) { reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
data->pwm_auto_point_hyst[0] = if (nr & 1)
f71882fg_read8(data, F71882FG_REG_FAN_HYST0); reg = (reg & 0x0f) | (val << 4);
} else { else
data->pwm_auto_point_hyst[1] = reg = (reg & 0xf0) | val;
f71882fg_read8(data, F71882FG_REG_FAN_HYST1);
} f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
switch (nr) { data->pwm_auto_point_hyst[nr / 2] = reg;
case 0:
val = (data->pwm_auto_point_hyst[0] & 0xf0) | val;
break;
case 1:
val = (data->pwm_auto_point_hyst[0] & 0x0f) | (val << 4);
break;
case 2:
val = (data->pwm_auto_point_hyst[1] & 0xf0) | val;
break;
case 3:
val = (data->pwm_auto_point_hyst[1] & 0x0f) | (val << 4);
break;
}
if (nr == 0 || nr == 1) {
f71882fg_write8(data, F71882FG_REG_FAN_HYST0, val);
data->pwm_auto_point_hyst[0] = val;
} else {
f71882fg_write8(data, F71882FG_REG_FAN_HYST1, val);
data->pwm_auto_point_hyst[1] = val;
}
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment