[BPI-R4] CPU fan setup

Yes thats the same i have and it is working with my latest patches for dts. Daniel will add them to openwrt too.

1 Like

PWM is working now? Sweet.

Pwm was basicly already working,but we missed a patch for the fan socket in dts and enabling pwm itself.

2 Likes

I’m rusty on Device Tree. I think the current R4’s DTS is quite wrong about trip points and cooling mapping. The fan won’t work as expected.

Perhaps that’s the reason one user above tried to do it himself in Linux user space ? Akin to run a program on Windows eating CPU cycles to manage fan speed.

If I read the current DTS correctly, here are current fan speed & trip point setup:

fan level: 0 - duty cycle 0%, 1 - 30%, 2 - 50%, 3 100%

Trip points: low - 40C, med - 85C, high - 115C, hot - 120C, critical - 125C

trip point to fan level mapping: low <> 1 1, med <> 2 2, hot <> 3 3

I see four main issues:

  1. 40C is too low a temperature to start the fan and potentially associated noise. Router chips can tolerate lot higher temperature.
  2. Once the fan triggered it will never stop, even if temperature drops below 40C.
  3. No “passive” trip point. Note I think “passive” is not what the author thinks i.e. heat dissipation by heatsink. A “passive” trip point in DTS is cooling by adjusting CPU freq.
  4. CPU freq won’t throttle when overheat as a “passive” mapping is missing.

I haven’t got R4 yet and no chance to try. My recommended trip points:

Trip points: low - 65C, med - 70C, high - 80C, hot - 95C (define this trip point as “passive”), critical - 125C

And the trip points to fan level mapping should be:

low <> 0 1, med <> 1 2, high <> 2 3, hot <> 3 3

Add the missing mapping for ‘hot’ that linking to CPU OPPs for “passive” cooling

With these changes, the behaviour will be:

  • 65C or below: fan not spin
  • 70C or below: 0% to 30% duty cycle
  • 80C or below: 30% to 50% duty cycle
  • 95C or below: 50% to 100% full blast; additionally use CPU throttle to reduce heat
  • 125C: system auto reboot (I believe it’s hard wired inside the SoC).

Reference to Device Tree: https://www.kernel.org/doc/Documentation/devicetree/bindings/thermal/thermal.txt

2 Likes

I have not changed temperatures for fan yet, so i see them as some test values…especially the lowest one…40 is a bit low and reached fast after bootup. I would say 60 or 55 would be a good choice.

I have not done tests for cpu-freq yet because i’m no expert here,but i saw driver change.

@dangowrt what do you think? Any tests with cpufreq yet?

Autoreboot is set in thermal driver (lvts) with a security space like on other SoCs…afair at 115°C

1 Like

Going to play on it once I got my hands on R4 hardware. Sounds fun and hopefully will have something useful coming out of it.

I saw following patch in openwrt.git shortlog:

mediatek: fix PWM fan on BPi-R4

I rebuilt the snapshot, but unfortunately the fan still always spinning. I’m using:

cat /sys/class/thermal/thermal_zone0/temp

to read the temperature and

echo 47000 > /sys/class/thermal/thermal_zone0/trip_point_2_temp

to write the temp threshold. When I read the status:

cat /sys/class/thermal/cooling_device0/cur_state

it is reporting 0 (fun off), but fun is still spinning.

Have you looked what trip_point2 is? Afaik you have to change trip_point 4 or 3 as these are the lowest trips

Hi Frank, I did not know about ne two more trip points. Thanks However I set in thermal_zone_0:

trip_point 0 to 80000
trip_point 1 to 70000
trip_point 2 to 56000
trip_point 3 to 55000
trip_point 4 to 54000

temperature of thermal_zone_0 is 33122 and fan still spinning. Status of “cooling device 0” still 0 off but spinning. Seems trip points not working or I’m doing something wrong. Also set trip point 4 to 30000 and the status went to 1 (fan on) So it seems the status 0 is not interrupting the power on fan plug.

Yes thats what i have expected…whats wrong here?

Why should it do that? Thermal trips handling fan nothing else yet…maybe we get passive (cpu trotteling) cooling working.

The emergency shotdown is hardcoded in lvts driver at 115°C

In BPI-R3 the trip point_2 was the threshold for the fan to spin or not. When temeperature more than the theshold it was spinning when under the threshold the fan was not spinning. In BPI-R4 always spinning at the same maximum speed. May be I do not understand how PWM works… Changing the rotation speed according to the various trip points? A mistery for me… :smile: Frank clarify how should work.

Create a shell command file and write these into shell command file:

if [ -d /sys/devices/pwm-fan ]; then
FAN_CTRL=/sys/devices/pwm-fan/hwmon/hwmon0/pwm1
elif [ -d /sys/devices/platform/pwm-fan ]; then
FAN_CTRL=/sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1
else
exit 0
fi

run this shell file:

chmod +x yourFileName.sh && ./yourFileName.sh

finally use this command:

echo 180 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1

Hello i have used echo 180 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1 then my fan go up. after a few seconds its go back to 80. its look like a fancontrol is active. is the fan controlled by the driver or by a linux programm? and can i change the settings?

BTW: If you’re curious about that open-top case: That’s a parametric OpenSCAD 3D-printable case I’m working on. I’ll post it here (and Github) when it’s done (still haven’t coded the front plate yet). When it’s done you’ll be able to specify how much space you want above/below the board, whether and where you want antenna holes, whether or not to include various mounting options, etc. Neat feature: I made it so you can feel/press the WPS and Reset buttons via little flexure tabs/buttons (no need to get a needle hehe) :+1:

A very old comment I just stumbled across, but did you ever get the case finished or still have the files for however far you got on it you’d share?

BPI R4 over-temperature reboot will slow down the fan speed, I recommend writing

echo 180 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/pwm1

script to the /etc/rc.local file

I am using the Banana Pi Ubuntu 24.04 for this board and looking for a way to control the CPU heat sink fan speed.

FWIW, I came across a shell script in the BPI-R4 doc, scroll down to Heat sink in the link below:

CPU heat sink fan control

Caveat: you may have to change some of the filenames in the script, based on what the kernel creates:

# ls -l /sys/class/pwm/pwmchip0/
device/    export     npwm       power/     subsystem/ uevent     unexport

Hope this helps :vulcan_salute:t4: