Skip to content

A Raspberry Pi 5 on FreeBSD, and a fan that would not turn

· 5 min read

Bottom line up front

Put the official fan on a Raspberry Pi 5, boot FreeBSD, and the fan stays still. Nothing is broken. FreeBSD has no driver for the part of the board that makes the fan turn.

We wrote one. rp1fan is a small kernel module that reads the CPU temperature once a second and sets the fan speed to match. It runs on FreeBSD 15.0 with the stock GENERIC kernel. The code is in spagu/freebsd-rpi-fan.

Why the fan does nothing

On older Raspberry Pi boards a fan was two wires on the 40-pin header: 5 volts and ground, spinning flat out for as long as the board had power. The Pi 5 has a dedicated four-pin FAN socket instead, tucked between the end of the header and the USB 2.0 ports. Two of the four pins carry power. The third tells the fan how fast to go, and the fourth lets the fan report how fast it is going.

The speed signal comes from RP1, the chip Raspberry Pi designed to run most of the board's ports. Somebody has to tell RP1 what speed to ask for. On Raspberry Pi OS the kernel does that. According to the bootloader's release notes, the firmware leaves the fan off until the operating system takes over, and steps in by itself only above 85 °C. FreeBSD never takes over, so the fan waits.

FreeBSD on this board also had no way to show the CPU temperature. There was no sysctl for it. You had a computer that could get hot, a fan that would not turn, and no thermometer.

What we tried first

There is a set of out-of-tree modules for the Pi 5 that includes a fan controller. We read its code before building anything. It maps hardware addresses and writes to them without checking which machine it is on, it accepts any number for a fan speed, and when the sensor gives no valid reading it reports 50 °C and carries on. The repository had been quiet for months. We kept three fixes for it as patches, and wrote our own module.

What rp1fan does

Once a second it reads the temperature sensor inside the processor and picks one of five levels:

TemperatureFan
below 50 °Cstopped
from 50 °Cslow
from 60 °Cmedium
from 67.5 °Cfast
from 75 °Cnearly full

Those are the thresholds Raspberry Pi documents for this fan. A level is left again 5 °C below the point where it started, so the fan does not flick on and off when the temperature sits right on a threshold.

It also covers the cases where something is off:

  • If the sensor stops giving valid readings, the fan goes to full speed and the kernel log says why.
  • If you unload the module, the fan is left at full speed. With nobody watching the temperature, a loud board is better than a hot one.
  • The module checks that it is on a Raspberry Pi 5 and that the RP1 chip answers with its identifier before it writes anything. On any other machine it refuses to load.
  • Every setting has a range, and a value outside it is refused.

On the board

The first load on the Pi 5:

rp1fan: RP1 at 0x1f00000000, 48.5 C, level 0, speed 0

Then the fan by hand, to see whether it listens. Speeds go from 0 to 255:

Speed asked forFan reported
2559649 RPM
1255995 RPM
753574 RPM
0stopped

After a restart the module came up by itself and the readings were there again.

Installing it

You need the kernel sources for your release in /usr/src. On the board:

make module
sudo install -m 555 driver/rp1fan.ko /boot/modules/
sudo sysrc kld_list+=rp1fan
sudo kldload rp1fan

After that, sysctl hw.rp1fan shows the temperature, the level, the speed and the fan's RPM:

hw.rp1fan.temp: 47950
hw.rp1fan.state: 0
hw.rp1fan.speed: 0
hw.rp1fan.rpm: 0

The temperature is in thousandths of a degree, so 47950 is 47.95 °C.

Two settings are worth knowing. If you would rather have the fan always turning a little, set the first threshold to zero:

sudo sysctl hw.rp1fan.trip0=0

And if you want one fixed speed whatever the temperature, hw.rp1fan.manual takes a number from 0 to 255. Set it to -1 to hand control back.

What has been tested

One Raspberry Pi 5 Model B on FreeBSD 15.0-RELEASE, started through UEFI firmware: build, load, every fan speed above, the range checks, unload and a restart. FreeBSD 15.1 is next on the list, and the README will say so when it is done.