The odroid fan driver uses pulse width modulation (PWM) to control the speed of the fan, with the PWM duty cycle adjusted based on the temperature of the CPU. The driver has four speed settings, which it selects among based on three temperature settings. So, if the current CPU temp is below the lowest temperature setting it uses the first fan speed, if between the first and second temperature settings it uses the second fan speed, if between the second and third temperature settings it uses the third fan speed, and if greater than the third temperature setting it uses the fourth fan speed.
There are a number of settings in sysfs for the odroid-fan driver, on the XU4 this is under /sys/devices/odroid_fan.13, while on the XU3 it is /sys/devices/odroid_fan.14.
The settings are:
fan_mode: Auto or Manual (set to 1 for auto and 0 for manual, default Auto)
fan_speeds: Four space delimited fan speed percentage values, in ascending order. (default "1 51 71 91")
pwm_duty: Current setting of the PWM duty cycle (0-255, set dynamically)
pwm_enable: On or off (default on)
temp_levels: Three space delimited CPU Celcius temperature values, in ascending order (default "57 63 68")
There are two places to get the CPU temperature in sysfs, /sys/devices/10060000.tmu/temp and /sys/devices/virtual/thermal/thermal_zone0/temp. The first is readable only by root or a user in group root. It shows the temperatures of five sensors. The second is readable by all and gives a single temperature. In both cases, the temperatures are in milli-degrees Celsius (so divide by 1000 to get Celsius). The highest of the values in /sys/devices/10060000.tmu/temp is used to control the fan speed.
The fan speed settings are specified in percent, so should be in the range 0-100. The PWM duty cycle is specified in the range 0-255, and in automatic mode is calculated by multiplying the fan speed setting by 255 and dividing by 100. For example, in the default case, when the temperature hits 57 degrees it turns the fan on to 51%, which equals a PWM duty cycle of 51*255/100 = 130.
The fan-control script works by setting the fan_mode to manual and changing the pwm_duty to the desired value based on the temperature. The script has 9 fan levels defined as opposed to the 4 in the odroid-fan driver.
In order to configure the automatic mode for the fan, you can echo new settings to the fan_speeds and temp_levels settings. These settings will take effect immediately.
Here is an example to make the fan turn on to 20% at 50C, go up to 50% at 70C, and up to 95% at 80C on the Odroid XU4
Code: Select all
sudo echo "1 20 50 95" > /sys/devices/odroid_fan.13/fan_speeds
sudo echo "50 70 80" > /sys/devices/odroid_fan.13/temp_levels
Code: Select all
DRIVER=="odroid-fan", ACTION=="add", ATTR{fan_speeds}="1 20 50 95", ATTR{temp_levels}="50 70 80"