At least for Odroid XU4 this is quite easy:
For RPi there was some similarly easy way.
Would be nice to have it inside DietPi-Config where applicable/easy to accomplish.
@MichaIng You do know that the HC1 and HC2 do not have any connections for a fan?
@enwi
Good hint. Although the board itself seems to have, according to forum user.
As HC1/2 is the same board, thus we cannot estimate any difference, AFAIK, we can still add the option. Of course it does not have any effect if no fan is attached.
And theoretically you could attach one with some case modification ;) (?).
@MichaIng Yeah that's what I did. I am using a USB fan, that I've attached to the metal extrusion. But to not confuse anybody there is no other way of adding a fan to HC1/2.
I am working on it. At least for testing/debug reasons it contains more code than I planned 馃ぃ: https://github.com/Fourdee/DietPi/pull/1978
@enwi
Did the guide actually work as expected for you, something to take care about?
I have no Odroid to test, hope it is the same for all Odroids (whether they have native fan support by case or not).
I doubt that this is the same for all SBCs and x86_64. Rough research lead to many different methods, also based on how the fan is attached. My aim is to release it for Odroids (in case XU4/HC1/HC2 board) first and then add support for other hardware step by step.
@MichaIng
On the HC1 and HC2 you can mount a fan to the metal extrusion. The XU4 either comes with a fan mounted or with a larger heatsink. All other Odroids except C0 have a heatsink where you can probably attach a fan afaik.
@MichaIng You do know that the HC1 and HC2 do not have any connections for a fan?
Also with that I meant that there is no way you can connect any cable to the board to control the fan since it only has a connection for a serial interface and a battery. See this link.
@enwi
Many thanks for the infos.
Ah, so you do not control your fan in this case, leaving it at static (max) speed?
Just checked. Yeah, I thought XU4/HC1/HC2 are exactly the same, but the board layout/features are not.
XU4 comes with separate fan connector, HC1/2 do not. There is a similar connector, but that's the RTC backup battery 馃槈.
For other boards, there are USB fans offered. Needs check how/if they can be controlled.
For RPi there are several guides for using GPIO pins for fan control, but this needs a separate controller board then. We could add a default (software) interface and configuration for this to the script. But this needs someone who uses this setup and knows a bid how similar control (defined temperature limits, where the fan runs at defined speeds) can be achieved.
For general use, this turns out way more complicated then I though 馃ぃ. So far this then just works for XU4 natively. At least I hope that other boards with this fan connector work similar or identical. Especially for native PCs this could be also interesting.
However, is still fun to write this, using our most current coding knowledge and methods to create menus, error handling etc.
@MichaIng
That's correct, the fan has two speed settings that can be selected with a switch and it is running at the low setting, which is plenty to cool the HC1.
Testing:
[ OK ] DietPi-Set_CPU_fan | Root access verified.
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 47: /sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic:
/sys/devices/virtual/thermal/thermal_zone0/trip_point_0_temp: 100000
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 49: /sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed:
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 50: /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1:
[FAILED] DietPi-Set_CPU_fan | CPU fan control is not available on your device. Aborting...
root@DietPi:~# cat /sys/devices/platform/
ACPI0003:00/ INT33A1:00/ PNP0C14:00/ snd-soc-dummy/
ACPI000C:00/ microcode/ PNP0C14:01/ thinkpad_acpi/
alarmtimer/ pcspkr/ PNP0C14:02/ thinkpad_hwmon/
coretemp.0/ PNP0C0A:00/ PNP0C14:03/ uevent
efi-framebuffer.0/ PNP0C0C:00/ power/
efivars.0/ PNP0C0D:00/ regulatory.0/
i8042/ PNP0C0E:00/ serial8250/
root@DietPi:~# find /sys -name *fan*
/sys/kernel/debug/tracing/events/syscalls/sys_enter_fanotify_init
/sys/kernel/debug/tracing/events/syscalls/sys_exit_fanotify_init
/sys/kernel/debug/tracing/events/syscalls/sys_enter_fanotify_mark
/sys/kernel/debug/tracing/events/syscalls/sys_exit_fanotify_mark
/sys/devices/platform/thinkpad_hwmon/fan1_input
/sys/bus/platform/drivers/thinkpad_hwmon/fan_watchdog
/sys/module/thinkpad_acpi/parameters/fan_control
/sys/module/rcutree/parameters/rcu_fanout_exact
/sys/module/rcutree/parameters/rcu_fanout_leaf
Trail and error:
root@DietPi:~# echo 1 > /sys/bus/platform/drivers/thinkpad_hwmon/fan_watchdog
bash: echo: write error: Operation not permitted
root@DietPi:~# echo 1 > /sys/module/thinkpad_acpi/parameters/fan_control
bash: /sys/module/thinkpad_acpi/parameters/fan_control: Permission denied
root@DietPi:~# cat /proc/acpi/ibm/fan
status: enabled
speed: 0
level: auto
https://www.kernel.org/doc/Documentation/laptops/thinkpad-acpi.txt
The fan may be enabled or disabled with the following commands:
echo enable >/proc/acpi/ibm/fan
echo disable >/proc/acpi/ibm/fan
Placing a fan on level 0 is the same as disabling it. Enabling a fan
will try to place it in a safe level if it is too slow or disabled.
The fan level can be controlled with the command:
echo 'level <level>' > /proc/acpi/ibm/fan
root@DietPi:~# echo 'enable' > /proc/acpi/ibm/fan
bash: echo: write error: Invalid argument
root@DietPi:~# /DietPi/dietpi/func/dietpi-set_cpu_fan
[ OK ] DietPi-Set_CPU_fan | Root access verified.
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 47: /sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic:
/sys/devices/virtual/thermal/thermal_zone0/trip_point_0_temp: 80000
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 49: /sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/fan_speed:
/DietPi/dietpi/func/dietpi-set_cpu_fan: line 50: /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1: No such file or directory
/sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1:
[FAILED] DietPi-Set_CPU_fan | CPU fan control is not available on your device. Aborting...
root@DietPi:~# cat /sys/devices/platform/
alarmtimer/ nexell-ion@0/ regulatory.0/
board/ nexell-pcm/ snd-soc-dummy/
bt_bcm/ nx-v4l2/ sound/
c0000000.soc/ panel-friendlyelec/ spdif-out/
c0010000.oscillator/ pmu/ uevent
c0018000.onewire_pwm/ power/ wlan/
cpu/ psci/
gpio_keys/ reg-dummy/
root@DietPi:~# find /sys -name '*fan*'
/sys/kernel/slab/fanotify_event_info
/sys/module/rcutree/parameters/rcu_fanout_exact
/sys/module/rcutree/parameters/rcu_fanout_leaf
root@DietPi:~# find /sys -name '*pwm*'
/sys/bus/platform/devices/c0018000.onewire_pwm
/sys/bus/platform/devices/c0018000.pwm
/sys/bus/platform/drivers/pwm-backlight
/sys/bus/platform/drivers/samsung-pwm
/sys/bus/platform/drivers/samsung-pwm/c0018000.pwm
/sys/bus/platform/drivers/onewire_ts/c0018000.onewire_pwm
/sys/devices/platform/c0018000.onewire_pwm
/sys/devices/platform/c0000000.soc/c0018000.pwm
/sys/devices/platform/c0000000.soc/c0018000.pwm/pwm
/sys/devices/platform/c0000000.soc/c0018000.pwm/pwm/pwmchip0
/sys/devices/platform/c0000000.soc/c0018000.pwm/pwm/pwmchip0/npwm
/sys/class/pwm
/sys/class/pwm/pwmchip0
/sys/firmware/devicetree/base/soc/pwm@c0018000
/sys/firmware/devicetree/base/soc/pwm@c0018000/samsung,pwm-outputs
/sys/firmware/devicetree/base/soc/pwm@c0018000/#pwm-cells
/sys/firmware/devicetree/base/soc/pinctrl@C0010000/pwm0
/sys/firmware/devicetree/base/soc/pinctrl@C0010000/pwm1
/sys/firmware/devicetree/base/soc/pinctrl@C0010000/pwm2
/sys/firmware/devicetree/base/soc/pinctrl@C0010000/pwm3
/sys/firmware/devicetree/base/soc/clocks/pwm2@c00be000
/sys/firmware/devicetree/base/soc/clocks/pwm3@c00be000
/sys/firmware/devicetree/base/soc/clocks/pwm0@c00ba000
/sys/firmware/devicetree/base/soc/clocks/pwm1@c00ba000
/sys/firmware/devicetree/base/onewire_pwm
/sys/firmware/devicetree/base/onewire_pwm/pwms
/sys/kernel/debug/clk/pwm0
/sys/kernel/debug/clk/pwm1
/sys/kernel/debug/clk/pwm2
/sys/kernel/debug/clk/pwm3
/sys/kernel/debug/pwm
@Fourdee
Oh my god, every manufacturer has it's own fan interface it seems. Yours for IBM/Lenovo/ThinkPad I guess... 馃
What is inside there?
cat /sys/devices/platform/thinkpad_hwmon/fan1_input
cat /sys/module/thinkpad_acpi/parameters/fan_control
level: auto
I guess auto means temp controlled, but can we adjust this, somehow attach temp to fan speeds?
Okay was reading the link a bid. There are several interfaces on how to control the fan on IBM/Lenovo/ThinkPad. What is most similar to XU4 is the following:
Sysfs
Sysfs notes:
The sysfs interface follows the hwmon subsystem guidelines for the most
part, and the exception is the fan safety watchdog.
Writes to any of the sysfs attributes may return the EINVAL error if
that operation is not supported in a given ThinkPad or if the parameter
is out-of-bounds, and EPERM if it is forbidden. They may also return
EINTR (interrupted system call), and EIO (I/O error while trying to talk
to the firmware).
Features not yet implemented by the driver return ENOSYS.
hwmon device attribute pwm1_enable:
0: PWM offline (fan is set to full-speed mode)
1: Manual PWM control (use pwm1 to set fan level)
2: Hardware PWM control (EC "auto" mode)
3: reserved (Software PWM control, not implemented yet)
Modes 0 and 2 are not supported by all ThinkPads, and the
driver is not always able to detect this. If it does know a
mode is unsupported, it will return -EINVAL.
hwmon device attribute pwm1:
Fan level, scaled from the firmware values of 0-7 to the hwmon
scale of 0-255. 0 means fan stopped, 255 means highest normal
speed (level 7).
This attribute only commands the fan if pmw1_enable is set to 1
(manual PWM control).
hwmon device attribute fan1_input:
Fan tachometer reading, in RPM. May go stale on certain
ThinkPads while the EC transitions the PWM to offline mode,
which can take up to two minutes. May return rubbish on older
ThinkPads.
hwmon device attribute fan2_input:
Fan tachometer reading, in RPM, for the secondary fan.
Available only on some ThinkPads. If the secondary fan is
not installed, will always read 0.
hwmon driver attribute fan_watchdog:
Fan safety watchdog timer interval, in seconds. Minimum is
1 second, maximum is 120 seconds. 0 disables the watchdog.
To stop the fan: set pwm1 to zero, and pwm1_enable to 1.
To start the fan in a safe mode: set pwm1_enable to 2. If that fails
with EINVAL, try to set pwm1_enable to 1 and pwm1 to at least 128 (255
would be the safest choice, though).
Most importantly:
NOTE NOTE NOTE: fan control operations are disabled by default for
safety reasons. To enable them, the module parameter "fan_control=1"
must be given to thinkpad-acpi.
/sys/bus/platform/drivers/thinkpad_hwmon/pwm1_enable
set 0
for static full speed, 1
for manual PWM control, 2
for auto (thermal based) mode, which cannot be further controlled, at least according to the above info./sys/bus/platform/drivers/thinkpad_hwmon/pwm1
to set fan speed via values [0-255]
(same as on XU4) for manual PWM control mode./sys/devices/platform/thinkpad_hwmon/fan1_input
read current speed in RPM, could be interesting for some kind of live monitor, although I am not sure how to add this to a whiptail menu: background process that rewrites a certain part of the screen, but how to know this part, breaks interactive input etc?/sys/bus/platform/drivers/thinkpad_hwmon/fan_watchdog
, by default, after changing the above controls, will check after 120 seconds if the fan speed is safe and in case enables fan or rises fan speed, if I got it right? Thus if a static fan speed wants to be assured, a value of 0
needs to be given to disable the watchdog, other values define the amount of seconds, after which the watchdog checks fan speed against temperature again.The sysfs interface tries to blend in the generic Linux sysfs subsystems
and classes as much as possible. Since some of these subsystems are not
yet ready or stabilized, it is expected that this interface will change,
and any and all userspace programs must deal with it.
So we can hope, that for most x86_64 systems, the above interface is at least similar. I am thinking about installing DietPi on a separate partition/drive of my laptop 馃. HP Probook would be it.
@MichaIng
root@DietPi:~# cat /sys/devices/platform/thinkpad_hwmon/fan1_input
0
root@DietPi:~# cat /sys/module/thinkpad_acpi/parameters/fan_control
N
root@DietPi:~# echo 1 > /sys/module/thinkpad_acpi/parameters/fan_control
bash: /sys/module/thinkpad_acpi/parameters/fan_control: Permission denied
@Fourdee
Does this work?
echo 0 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1_enable
Fan slowly speeds up until full speed...
echo 1 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1_enable
echo 0 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1
Fan slowly speeds down until stop...
...possibly after some time, it speeds up again due to watchdog. In this case:
echo 0 > /sys/bus/platform/drivers/thinkpad_hwmon/fan_watchdog
echo 1 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1_enable
echo 0 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1
...should lead to fan stays off.
echo 2 > /sys/bus/platform/drivers/thinkpad_hwmon/pwm1_enable
Fan, depending on temperature, turns on and auto adjusts speed to temp/usage.
echo 1 > /sys/bus/platform/drivers/thinkpad_hwmon/fan_watchdog
Just to be failsafe, when enabling auto mode anyway.
Btw.:
I think before releasing this, it makes sense to do some more testing on Odroid XU4 (where the current implementation should work with) and add at least some more common x86_64 setups, which will quite take some time for research test and coding, since the fan control interfaces seem to be more different than expected.
As there are still other topics to test/tune/finish, move this to v6.14?
Or do an Odroid XU4-only release? (XU3 might be working as well)
@Fourdee
Let's move to v6.14.
This is no urgent thing and if release, it should be more than XU4-only 馃槈. Initial branch is still in place, so we can re-add it at any time.
Moved from own branch to main branch line .meta/
dir: https://github.com/Fourdee/DietPi/commit/2d9e9e3bd40daa15a10075490baedd4386bf7242
ROCKPro64 uses /sys/class/hwmon/hwmon3/
: https://dietpi.com/phpbb/viewtopic.php?p=26996#p26996
Not sure if there is a generic way to detect the correct tuneables, probably we need to implement it per-device 馃槥.