Raspberry pi 5 status

Turning the fan off doesn't appear to work except by unloading the driver.
Well, except that it doesn't work either. I can unload the rpi5 module, the bcm2712 module, but the fan just keeps on going. Only if I restart the Pi 5 does the fan stop (I load the modules manually for now).
 
Last edited:
One other thing:
- there is a bcm2712 kernel module which apparently does read the temperature sensor, and also control pwm.
- there is a rpi5 module, which implements the fan control

but rumors have it that on the Pi 5 the fan is controlled by the rp1 co-processor....
The code does contain the files rp1_pwm_driver.c and Makefile.thermal but if I try to compile it
Code:
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ make -f Makefile.thermal
Warning: Object directory not changed from original /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -ffile-prefix-map=/usr/src/sys=/usr/src/sys -ffile-prefix-map=/home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules=/usr/obj/usr/src/arm64.aarch64/sys/modules/FreeBSD15-RPi5-modules -fdebug-prefix-map=./machine=/usr/src/sys/arm64/include     -MD  -MF.depend.rpi5_cooling_fan_integrated.o -MTrpi5_cooling_fan_integrated.o -mgeneral-regs-only -ffixed-x18 -mno-outline-atomics -ffreestanding -fwrapv -fstack-protector -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length     -std=gnu99 -c rpi5_cooling_fan_integrated.c -o rpi5_cooling_fan_integrated.o
In file included from rpi5_cooling_fan_integrated.c:23:
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'BUS_READ_IVAR'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
   58 | PWMBUS_ACCESSOR(channel, CHANNEL, u_int)
      | ^
/usr/src/sys/dev/pwm/pwmbus.h:48:9: note: expanded from macro 'PWMBUS_ACCESSOR'
   48 |         return BUS_READ_IVAR(device_get_parent(dev), dev,               \
      |                ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'device_get_parent'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:48:23: note: expanded from macro 'PWMBUS_ACCESSOR'
   48 |         return BUS_READ_IVAR(device_get_parent(dev), dev,               \
      |                              ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'BUS_WRITE_IVAR'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:54:9: note: expanded from macro 'PWMBUS_ACCESSOR'
   54 |         return BUS_WRITE_IVAR(device_get_parent(dev), dev,              \
      |                ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'device_get_parent'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:54:24: note: expanded from macro 'PWMBUS_ACCESSOR'
   54 |         return BUS_WRITE_IVAR(device_get_parent(dev), dev,              \
      |                               ^
/usr/src/sys/dev/pwm/pwmbus.h:66:8: error: unknown type name 'driver_t'
   66 | extern driver_t   pwmbus_driver;
      |        ^
/usr/src/sys/dev/pwm/pwmbus.h:67:8: error: unknown type name 'driver_t'
   67 | extern driver_t   ofw_pwmbus_driver;
      |        ^
rpi5_cooling_fan_integrated.c:104:2: error: use of undeclared identifier 'FILE'
  104 |         FILE *fp;
      |         ^
rpi5_cooling_fan_integrated.c:104:8: error: use of undeclared identifier 'fp'
  104 |         FILE *fp;
      |               ^
rpi5_cooling_fan_integrated.c:206:11: error: call to undeclared function 'PWMBUS_CHANNEL_CONFIG'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  206 |                 error = PWMBUS_CHANNEL_CONFIG(cooling_fan.pwm_dev, 
      |                         ^
rpi5_cooling_fan_integrated.c:212:5: error: call to undeclared function 'PWMBUS_CHANNEL_ENABLE'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  212 |                                 PWMBUS_CHANNEL_ENABLE(cooling_fan.pwm_dev,
      |                                 ^
rpi5_cooling_fan_integrated.c:138:11: error: unused variable 'thresh' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                  ^~~~~~
rpi5_cooling_fan_integrated.c:138:19: error: unused variable 'hyst' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                          ^~~~
rpi5_cooling_fan_integrated.c:138:25: error: unused variable 'speed' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                                ^~~~~
rpi5_cooling_fan_integrated.c:500:4: error: call to undeclared function 'PWMBUS_CHANNEL_ENABLE'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  500 |                         PWMBUS_CHANNEL_ENABLE(cooling_fan.pwm_dev, 
      |                         ^
14 errors generated.
*** Error code 1

Stop.
make: stopped making "all" in /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules
I will submit issues on github.
 
One other thing:
- there is a bcm2712 kernel module which apparently does read the temperature sensor, and also control pwm.
- there is a rpi5 module, which implements the fan control

but rumors have it that on the Pi 5 the fan is controlled by the rp1 co-processor....
The code does contain the files rp1_pwm_driver.c and Makefile.thermal but if I try to compile it
Code:
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ make -f Makefile.thermal
Warning: Object directory not changed from original /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules
cc  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -include /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -ffile-prefix-map=/usr/src/sys=/usr/src/sys -ffile-prefix-map=/home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules=/usr/obj/usr/src/arm64.aarch64/sys/modules/FreeBSD15-RPi5-modules -fdebug-prefix-map=./machine=/usr/src/sys/arm64/include     -MD  -MF.depend.rpi5_cooling_fan_integrated.o -MTrpi5_cooling_fan_integrated.o -mgeneral-regs-only -ffixed-x18 -mno-outline-atomics -ffreestanding -fwrapv -fstack-protector -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length     -std=gnu99 -c rpi5_cooling_fan_integrated.c -o rpi5_cooling_fan_integrated.o
In file included from rpi5_cooling_fan_integrated.c:23:
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'BUS_READ_IVAR'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
   58 | PWMBUS_ACCESSOR(channel, CHANNEL, u_int)
      | ^
/usr/src/sys/dev/pwm/pwmbus.h:48:9: note: expanded from macro 'PWMBUS_ACCESSOR'
   48 |         return BUS_READ_IVAR(device_get_parent(dev), dev,               \
      |                ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'device_get_parent'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:48:23: note: expanded from macro 'PWMBUS_ACCESSOR'
   48 |         return BUS_READ_IVAR(device_get_parent(dev), dev,               \
      |                              ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'BUS_WRITE_IVAR'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:54:9: note: expanded from macro 'PWMBUS_ACCESSOR'
   54 |         return BUS_WRITE_IVAR(device_get_parent(dev), dev,              \
      |                ^
/usr/src/sys/dev/pwm/pwmbus.h:58:1: error: call to undeclared function 'device_get_parent'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
/usr/src/sys/dev/pwm/pwmbus.h:54:24: note: expanded from macro 'PWMBUS_ACCESSOR'
   54 |         return BUS_WRITE_IVAR(device_get_parent(dev), dev,              \
      |                               ^
/usr/src/sys/dev/pwm/pwmbus.h:66:8: error: unknown type name 'driver_t'
   66 | extern driver_t   pwmbus_driver;
      |        ^
/usr/src/sys/dev/pwm/pwmbus.h:67:8: error: unknown type name 'driver_t'
   67 | extern driver_t   ofw_pwmbus_driver;
      |        ^
rpi5_cooling_fan_integrated.c:104:2: error: use of undeclared identifier 'FILE'
  104 |         FILE *fp;
      |         ^
rpi5_cooling_fan_integrated.c:104:8: error: use of undeclared identifier 'fp'
  104 |         FILE *fp;
      |               ^
rpi5_cooling_fan_integrated.c:206:11: error: call to undeclared function 'PWMBUS_CHANNEL_CONFIG'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  206 |                 error = PWMBUS_CHANNEL_CONFIG(cooling_fan.pwm_dev,
      |                         ^
rpi5_cooling_fan_integrated.c:212:5: error: call to undeclared function 'PWMBUS_CHANNEL_ENABLE'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  212 |                                 PWMBUS_CHANNEL_ENABLE(cooling_fan.pwm_dev,
      |                                 ^
rpi5_cooling_fan_integrated.c:138:11: error: unused variable 'thresh' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                  ^~~~~~
rpi5_cooling_fan_integrated.c:138:19: error: unused variable 'hyst' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                          ^~~~
rpi5_cooling_fan_integrated.c:138:25: error: unused variable 'speed' [-Werror,-Wunused-variable]
  138 |         uint32_t thresh, hyst, speed;
      |                                ^~~~~
rpi5_cooling_fan_integrated.c:500:4: error: call to undeclared function 'PWMBUS_CHANNEL_ENABLE'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  500 |                         PWMBUS_CHANNEL_ENABLE(cooling_fan.pwm_dev,
      |                         ^
14 errors generated.
*** Error code 1

Stop.
make: stopped making "all" in /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules
I will submit issues on github.
These make targets are not really standalone. I want to refactor the mess Claude created with multiple makefiles, but .. priorities.

If you use the primary Makefile, it will build things in the correct order. I like correctly coded dependencies also, but I'm holding my nose here.

FWIW, this is a project where I'm also trying to learn and learn how to manage the limitations and gotchas of using AI. I'm learning Anthropic has a lot of bad stuff in their training corpus, and the "wisdom of crowds" isn't yet in the models they publish. Also the limits of a "Pro" subscription are inadequate for any real work. I'm just not in a position to 10x my donations to make this go faster, better.
 
Issue #1 - the temperature control doesn't work
Issue #2 - it should be possible to report / read the fan speed
Issue #3 - the fan doesn't stop when modules are unloaded

I'll try to put the details in the ticket, but I'm working on all 3 of these today.

1: this is due to the PWM fan speed control not working. The fan runs at max speed, and the PWM code isn't doing anything at the hardware level. This is in progress.
2: I have gotten the fan rpm working, but this required getting the GPIO stuff working because the fan ticks twice on a GPIO pin per revolution. This is done I think. Try "sysctl hw.rpi5.fan.rpm" if you can build the latest rev.
3: caused by #1

The PWM code doesn't set the delta/sigma registers on sysctl changes, but it should: in progress.
The PWM delta/sigma --> duty cycle needs to be inverted as the PWM hardware driver on the GPIO pins feeding the fan are pull-down and you have to invert the on/off time ratio in code to represent the kick the fan feels: in progress.

Check out the tools folder in the repo for test utility scripts.
 
High level lessons learned about the RPi5:
  • It will lock up if you run it without active cooling
  • The onboard fan control is a poorly undocumented part of the RP1, and it might be poorly implemented in hardware ;)
  • The thermal sensor is an open secret BCM2712 interface: the Linux code is the only open documentation. I guess we're lucky to have that. Thank the GPL lawyers.
  • The fan tachometer is wired to a GPIO pin.
  • Nothing can be simple: need to correctly interface the RP1 GPIO functions and also the BCM2712 GPU registers just to use the onboard fan as designed.
  • The idiosyncracies of the RP1 architecture might prevent using the existing GEM driver for the onboard GE NIC.
  • core dumps to a USB UFS volume are so slow I fear this device might not be a very good NAS platform without special hardware using the accessory PCIe bus. It was a mistake to do the development work on a 16GB RPi5 board. I should have treated this like an embedded device and set up a cross compiler or VM to to all the builds and just push the binaries to the device for testing.
 
https://github.com/narqo/freebsd-brcmfmac check the broadcom full mac wifi code to compare with your code. Thank you for this v0.01-ALPHA code contribution. I will test your code on RPI500 keyboard model. I am happy to see you solve these RPI5 problems for FreeBSD. It will be nice to have a single binary to download that has these features for a new to FreeBSD user to experience FreeBSD, like they would download Linux. The RPI5 has the ability to http: url download image and burn into microSD card or USB flash drive, Thank you again for this code.
 
Brave folk: please try this if you can.

Very cool. Finally a Raspberry Pi wifi driver for FreeBSD. I wonder how it compares to OpenBSD/NetBSD's offering.

You mentioned in the repo quite a lot of AI generation? How was the experience? Was it as straight forward as, here is some code for another platform, here are some shite docs, Go!
 
Brave folk: please try this if you can.

ok, tested the updated fan control now
Code:
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sudo sysctl hw.rpi5.fan.temp0=45000
hw.rpi5.fan.temp0: 50000 -> 45000
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.current_state
hw.rpi5.fan.current_state: 1
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.cpu_temp
hw.rpi5.fan.cpu_temp: 54000
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sudo sysctl hw.rpi5.fan.temp1=44000
hw.rpi5.fan.temp1: 60000 -> 44000
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.cpu_temp
hw.rpi5.fan.cpu_temp: 54000
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.current_state
hw.rpi5.fan.current_state: 2
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sudo sysctl hw.rpi5.fan.temp2=46000
hw.rpi5.fan.temp2: 67500 -> 46000
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.current_state
hw.rpi5.fan.current_state: 3
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sudo sysctl hw.rpi5.fan.temp0=50000 hw.rpi5.fan.temp1=60000 hw.rpi5.fan.temp2=67500
hw.rpi5.fan.temp0: 45000 -> 50000
hw.rpi5.fan.temp1: 44000 -> 60000
hw.rpi5.fan.temp2: 46000 -> 67500
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.current_state
hw.rpi5.fan.current_state: 1
tingo@devpi5:~/work/projects/FreeBSD/FreeBSD15-RPi5-modules $ sysctl hw.rpi5.fan.cpu_temp
hw.rpi5.fan.cpu_temp: 52350
it works - thank you.
 
Brave folk: please try this if you can.

I tested the ethernet now, but alas, while the bcm2712_pcie module loads, the rp1_eth module does not. Created issue 4.
details
Code:
root@devpi5:~ # kldload /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules/bcm2712_pcie.ko
root@devpi5:~ # kldstat
Id Refs Address                Size Name
 1   20 0xffff000000000000  1355268 kernel
 2    1 0xffff000001356000   41e528 zfs.ko
 3    1 0xffff000129600000    22000 mac_ntpd.ko
 6    2 0xffff000129622000    23000 bcm2712.ko
 7    1 0xffff000129645000    22000 rpi5.ko
 9    1 0xffff000129667000    22000 bcm2712_pcie.ko


root@devpi5:~ # kldload /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules/rp1_eth.ko
kldload: an error occurred while loading module /home/tingo/work/projects/FreeBSD/FreeBSD15-RPi5-modules/rp1_eth.ko. Please check dmesg(8) for more details.

root@devpi5:~ # tail -2 /var/log/messages
May 10 18:22:22 devpi5 kernel: rp1_eth: root compatible does not match Pi 5 (raspberrypi,5-model-b or raspberrypi,5-compute-module) — refusing attach
May 10 18:22:22 devpi5 kernel: module_register_init: MOD_LOAD (rp1_eth, 0xffff00012969c79c, 0) error 6
 
Back
Top