# Pi 5 fan control: the rp1fan driver

<span class="badge badge-ok">works</span> Version 0.1.0, Pi 5 Model B only. Tested on FreeBSD 15.0-RELEASE; on 15.1-RELEASE-p7 it builds, attaches at boot and the sysctls read correctly. Source: [spagu/freebsd-rpi-fan](https://github.com/spagu/freebsd-rpi-fan).

This driver started on 29 November 2026, the day the Pi 5 on the desk got too hot while its fan sat still. The bootloader only switches the fan on above 85 °C, and nothing in FreeBSD switches it on after that.

## How it works

The fan connector is driven by channel 3 of the RP1 chip's PWM1 block on GPIO45 (with inverted polarity), and its tachometer is on GPIO29. Once a second the driver reads the SoC temperature from the AVS monitor and picks a speed. It needs no device tree, so it works on UEFI/ACPI boot. It only attaches when the SMBIOS product name is `Raspberry Pi 5 Model B` and the RP1 chip ID reads `0x20001927`.

If the sensor reading is invalid, or the module is unloaded, the fan runs at full speed. Failing loud beats failing hot.

## Install

<ol class="steps">
<li>

Build and install:

```sh
make module                                    # builds driver/rp1fan.ko
sudo install -m 555 driver/rp1fan.ko /boot/modules/
```

</li>
<li>

Load it now and at every boot:

```sh
sudo sysrc kld_list+=rp1fan
sudo kldload rp1fan
```

</li>
<li>

Check `dmesg`. The expected line:

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

</li>
</ol>

The Makefile also has `make load`, `make status` and `make unload`.

## Fan curve

| SoC temperature | Level | Speed (0 to 255) | Measured |
|---|---|---|---|
| below 50 °C | 0 | 0 (off) | |
| from 50 °C | 1 | 75 | 3574 rpm |
| from 60 °C | 2 | 125 | 5995 rpm |
| from 67.5 °C | 3 | 175 | |
| from 75 °C | 4 | 250 | 9649 rpm at 255 |

Hysteresis is 5 °C, so the fan does not hunt between two levels.

## Sysctls

Read-only, under `hw.rp1fan`: `temp` (milli-degrees C), `state`, `speed`, `rpm`, `sensor_ok`, `invalid_reads`.

Writable:

| Sysctl | Default | Meaning |
|---|---|---|
| `trip0` to `trip3` | 50000 / 60000 / 67500 / 75000 | Temperature thresholds in milli-degrees |
| `speed0` to `speed3` | 75 / 125 / 175 / 250 | PWM speed for each level |
| `hyst` | 5000 | Hysteresis |
| `manual` | -1 | -1 follows the temperature, 0 to 255 fixes the speed |

For a fan that never stops: `sysctl hw.rp1fan.trip0=0`. Settings meant to persist go in `/etc/sysctl.conf`. Before loading, `kenv` can set `hw.rp1fan.rp1_base` (default `0x1f00000000`) and `hw.rp1fan.force`.
