[BPI-R4] CPU fan setup

setup 1: at /BPI-R4-OPENWRT-V21.02/target/linux/mediatek/mt7988/base-files/etc/init.d/fanspeed if [ ! -d /sys/devices/platform/pwm-fan ]; then exit 0 fi

setup 2: at //home/jiang/BPI/BPI-R4-OPENWRT-V21.02/target/linux/mediatek/mt7988/base-files/sbin/fan-speed

USE this file and replace it fan-speed (5.7 KB)

Then rebuild

or edit and replace

setup 1: the file in /etc/init.d/fanspeed. find and edit it

setup 2 : replace fan-speed with my file in /sbin/

Where can we set these values before compiling?

example: /sys/class/thermal/thermal_zone0/trip_point_1_temp

I cannot for my life find that info, and it’s not in the notes and patches on getting the pwm working.

The trip-point temperatures are already set in mt7988a.dtsi so not part of the patches…

1 Like

Got it, thank you. Now to move on to other items on my list.

Where to buy this heatsink and fan for BPI-R4?

This looks like the r3 heatsink…i saw it on aliexpress but more expensive than r4 heatsink

Indeed apparently it’s the R3 heatsink, but hey if it works it doesn’t matter.

https://de.aliexpress.com/item/1005006544838058.html

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.