Commit 815e1295 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: add possibility to use hysteresis to control fans' speed

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4a6d01ee
......@@ -662,4 +662,39 @@ config MONIT_DISABLE
Disable monit to prevent processes' restarts. It may be useful for
development.
menu "Fan speed control"
config FAN_HYSTERESIS
bool "Use hysteresis to control fan speed"
default n
help
Disable monit to prevent processes' restarts. It may be useful for
development.
config FAN_HYSTERESIS_T_DISABLE
int "Disable fans temperature"
default 60
range 0 80
depends on FAN_HYSTERESIS
help
Temperature at which fans are disabled when working in hysteresis mode.
config FAN_HYSTERESIS_T_ENABLE
int "Enable fans temperature"
default 65
range 0 80
depends on FAN_HYSTERESIS
help
Temperature at which fans are enabled when working in hysteresis mode.
Maximum allowed value is 80
config FAN_HYSTERESIS_PWM_VAL
int "Value of fans' PWM"
default 100
range 4 1000
depends on FAN_HYSTERESIS
help
PWM value used to drive fans. Range from 4 to 1000.
endmenu
endmenu
......@@ -707,6 +707,17 @@ value is changed by the web interface, proper action is taken.
re-spawns processes that have died. This option is useful mostly during
development.
@item CONFIG_FAN_HYSTERESIS
@itemx CONFIG_FAN_HYSTERESIS_T_DISABLE
@itemx CONFIG_FAN_HYSTERESIS_T_ENABLE
@itemx CONFIG_FAN_HYSTERESIS_PWM_VAL
Use hysteresis to control switch's fans. Enable fans with PWM value
@t{CONFIG_FAN_HYSTERESIS_PWM_VAL} when PLL's temperature exceeds
@t{CONFIG_FAN_HYSTERESIS_T_ENABLE}. Disable fans when temperature drops
below @t{CONFIG_FAN_HYSTERESIS_T_DISABLE}. These options are intended to
be used during development to reduce noise generated by switch.
@end table
@c ==========================================================================
......
......@@ -24,11 +24,13 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <libwr/wrs-msg.h>
#include <libwr/pio.h>
#include <libwr/fan.h>
#include <libwr/hal_shmem.h>
#include <libwr/config.h>
#include <at91_softpwm.h>
......@@ -49,6 +51,10 @@
static int is_cpu_pwn = 0;
static int enable_d0 = 0;
static int fan_hysteresis = 0;
static int fan_hysteresis_t_disable = 0;
static int fan_hysteresis_t_enable = 0;
static int fan_hysteresis_pwm_val = 0;
static i2c_fpga_reg_t fpga_sensors_bus_master = {
.base_address = FPGA_I2C_ADDRESS,
......@@ -204,6 +210,7 @@ static int shw_init_i2c_sensors(void)
int shw_init_fans(void)
{
uint32_t val = 0;
char *config_item;
//Set the type of PWM
if (shw_get_hw_ver() < 330)
......@@ -255,6 +262,42 @@ int shw_init_fans(void)
pi_init(&fan_pi);
/* check wether config fields exist, atoi has to have valid string */
config_item = libwr_cfg_get("FAN_HYSTERESIS");
if ((config_item) && !strcmp(config_item, "y")) {
fan_hysteresis = 1;
pr_info("enable fan hysteresis\n");
config_item = libwr_cfg_get("FAN_HYSTERESIS_T_ENABLE");
if (config_item) {
fan_hysteresis_t_enable = atoi(config_item);
/* don't allow fan_hysteresis_t_enable to be higher
* than 80 deg */
if (fan_hysteresis_t_enable >= 80)
fan_hysteresis_t_enable = 80;
}
config_item = libwr_cfg_get("FAN_HYSTERESIS_T_DISABLE");
if (config_item) {
fan_hysteresis_t_disable = atoi(config_item);
}
config_item = libwr_cfg_get("FAN_HYSTERESIS_PWM_VAL");
if (config_item) {
fan_hysteresis_pwm_val = atoi(config_item);
}
if (fan_hysteresis_pwm_val < 4) {
/* set minimum pwm value to 4 */
fan_hysteresis_pwm_val = 4;
}
pr_info("set temp enable to %d for fan hysteresis\n",
fan_hysteresis_t_enable);
pr_info("set temp disable to %d for fan hysteresis\n",
fan_hysteresis_t_disable);
pr_info("set pwm value to %d for fan hysteresis\n",
fan_hysteresis_pwm_val);
}
return 0;
}
......@@ -268,7 +311,21 @@ void shw_update_fans(struct hal_temp_sensors *sensors)
float t_cur = tmp100_read_temp(TEMP_SENSOR_ADDR_PLL);
float drive = pi_update(&fan_pi, t_cur - DESIRED_TEMPERATURE);
//pr_info("t=%f,pwm=%f\n",t_cur , drive);
shw_pwm_speed(0xFF, drive / 1000); //enable two and one
if (fan_hysteresis) {
if (t_cur < fan_hysteresis_t_disable) {
/* disable fans */
shw_pwm_speed(0xFF, 0);
}
if (t_cur > fan_hysteresis_t_enable) {
/* enable fans with given value */
shw_pwm_speed(0xFF,
((float) fan_hysteresis_pwm_val)/1000);
}
} else {
/* use PI controller for FANs speeds */
shw_pwm_speed(0xFF, drive / 1000);
}
/* update sensor values */
sensors->fpga = tmp100_read_reg(TEMP_SENSOR_ADDR_FPGA, 0, 2);
......
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