Open MichaIng opened 6 years ago
@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:
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 😞.
Some days ago i tested an I2C cooling had, works perfectly on Dietpi, just needed some finetuning to get it work.
Python or C based control settings.
https://github.com/YahboomTechnology/Raspberry-Pi-RGB-Cooling-HAT
Pinging @Rick847 here and #4454, with the idea to make this more generic, toggling a GPIO-attached fan based on CPU temperature, where no native PWM fan socket + kernel interface is available.
this one we have as well https://github.com/MichaIng/DietPi/issues/4003
True. Again very different (much simpler) to configure, but when we write such a script, why not adding every case of fan controls into it. But I think I'll add the RPi case fan to dietpi-config > Advanced Options earlier, as it is all together just a few lines of code, not comparable to the other solutions. Also while the others work OOTB, so can be live-controlled, for RPi fan changes via dtoverlay, a reboot is always required.
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.