How to control FAN on Rockpro64?


mabs

Recommended Posts

Hi,

 

Is fan control still broken?

Linux rockpro64 5.7.15-rockchip64 #20.08 SMP PREEMPT Mon Aug 17 00:26:28 CEST 2020 aarch64 aarch64 aarch64 GNU/Linux
echo 255 > /sys/devices/platform/pwm-fan/hwmon/hwmon2/pwm1
echo 0 > /sys/devices/platform/pwm-fan/hwmon/hwmon2/pwm1

Commands line above work, but writing anything between (like 240, 200, etc.) does not.

I can hear noise imho coming from fan coils when I write 253 to pwm1, maybe it's pwm frequency too high/too low?

I checked two different 80x80mm fans, same result.

Fans start to spin connected to DC ~4V, so they should work for sure.

 

From kernel side there is pwm-fan module, but it can't take any parameters imho.

Every kernel version I checked comes with it's own values (lol), for. example:

https://github.com/ayufan-rock64/linux-kernel/pull/40/commits/5d9fbef9cfa01846dd0b4d66249df55c85fa344f

 

Link to post
Share on other sites
Want Armbian t-shirt or a cup?

@soerenderfor

I already tried tux3dv fan cotrol. Well, it isn't magic box :-)

What it does is to read from /sys/devices/virtual/thermal/thermal_zone*/temp and  write values from curve build from config f.e. 100..255 into /sys/devices/platform/pwm-fan/hwmon/hwmon*/pwm1.

All of this can be done manually.

It uses pwm-fan kernel module. If you unload this module there is no more /sys/devices/platform/pwm-fan/hwmon/hwmon* and fan stops.

 

Real problem here is lack of customization in this module. In 5.7.15 version there is hardcoded 50kHz pwm frequency - which simply won't work with all 2-wire fans.

Decent DC fans aren't simple motors, such fan has microcontroller which task is to deliver AC current in correct time to coils. Since there is no control with in 2-wire fan, 50% square pwm signal simply turns on/off whole circuit (at low frequency). All you can get at high frequency is fan working at full or zero speed.

Good solution would be to add paremeter to pwm-fan module for setting pwm-freqeuncy.

 

Meanwhile I searched alot and found solution for my fan :-)

 

rmmod pwm-fan
echo 0 > /sys/class/pwm/pwmchip1/export
echo 40 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo 100 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

What is does:

- remove useless kernel module and unlock pwmchip

- write to export creates subfolder to control pwm

- 40/100 - set frequency to 100Hz and duty_cycle to 40% (so we have low pwm frequency and square vawe fulfillment of 40%)

 

It works, fan speed can be controlled in much higher range, no more jet turbine dB level :-)

 

PS.

I used Sunon fans for test:

https://www.tme.eu/Document/b6f8c2a3813918913726d12d942d1b83/EE80151S1-A99.pdf

https://www.tme.eu/Document/d44c6feef6683af4934c9d10cdd59c2e/ME80201V1-A99.pdf

 

IMHO RockPro64 fan solution is bad desing. It should be programmable DC output for 2 wire, or 4-wire nice pwm like we have in PC.

Link to post
Share on other sites

@soerenderfor

 

 

echo 100 > /sys/class/pwm/pwmchip1/pwm0/period - this is 100% (at frequency of 100Hz)

echo 40 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle  - 40 here is 40% of 100

 

Period is cycle frequency, duty is percentage of this cycle filled with logical 1, here 12V, so at 100Hz cycle is 10ms, 4ms signal is 12V and 6ms its 0V

 

echo 500 > /sys/class/pwm/pwmchip1/pwm0/period - this is 100% (at frequency of 500Hz)

echo 250 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle  - 250 here is 50% of 500

 

main-qimg-6a0c03c88e95a195da651a1cc25b96

 

No problem :-)

 

Edited by Dunc4n1d4h0
Link to post
Share on other sites

The right way to use the fan would be to have a proper thermal setup (rk3399-rockpro64-tz.dts) in the devicetree. With this the kernel thermal system can handle the management.

This is a visualisation of a tmon log documenting the working of the thermal system:

Spoiler

tmon-log.thumb.png.56f144a87b98e60d9a13764a0b79a6a3.png

rk3399-rockpro64.dtb is a mainline dtb with rk3399-rockpro64-tz.dtbo applied via:

fdtoverlay --input rk3399-rockpro64.dtb --output rk3399-rockpro64.dtb rk3399-rockpro64-tz.dtbo

See if this is working for you by replacing your dtb and check with tmon.

Link to post
Share on other sites
9 hours ago, Dunc4n1d4h0 said:

For me problem here is hardcoded pwm frequency

There is nothing hardcoded, there is only a default value. And as one value does not fit them all, you have to set it to the value that fits your need. See rk3399-rockpro64-tz.dts for reference. Unfortunately you cannot apply this with mainline ftdoverlay because it does not support full path notion for a reference to another node. But with fdt_overlay.patch.txt applied it is working as expected.

Link to post
Share on other sites
8 hours ago, usual user said:

There is nothing hardcoded, there is only a default value. And as one value does not fit them all, you have to set it to the value that fits your need. See rk3399-rockpro64-tz.dts for reference. Unfortunately you cannot apply this with mainline ftdoverlay because it does not support full path notion for a reference to another node. But with fdt_overlay.patch.txt applied it is working as expected.

 

My bad, hardcoded default value.

Long time ago I used kernel module parameters. There are none in pwm-fan module.

Please, tell me how to change that to value that fits my needs? :-) (Other way that I use to write values to /sys/*)

 

Regards

Link to post
Share on other sites
13 hours ago, soerenderfor said:

can explain it in another way

ftdoverlay is a convenient way to apply an overlay staticly to a base dtb. You spare the DTC decompile - manually edit - DTC compile dance. Usually you write overlays with label refernces, but to be able to apply such an overlay, the base dtb has to be compiled with the @-option. This has significant impact on the size and distributions usually don't do this. When you write the overlay with full paths, it contains all the information to be applied to a base dtb that was not created with the @-option. The mainline ftdoverlay need the patch to be able to apply it.

 

13 hours ago, Dunc4n1d4h0 said:

Please, tell me how to change that to value that fits my needs

Edit the pwms property to any value you like as shown in the provided rk3399-rockpro64-tz.dts (50000 default changed to 10000).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...