Raspberry Pi / sound

Sound on Raspberry Pi: vchiq and bcm2835_audio

FreeBSD has had VCHIQ and Pi audio drivers for years, but only for 32-bit ARM. Two patches make them build and play on arm64.

A black loudspeaker with pink sound waves and a music note, a small raspberry imp listening.

first sound Pi 4, FreeBSD 15.1. The repository is not public yet.

Before these modules /dev/sndstat on a Pi 4 running arm64 FreeBSD was empty. Sound on the Pi goes through the VideoCore GPU firmware, and the kernel talks to the firmware over VCHIQ. The drivers in the FreeBSD tree assumed 32-bit pointers, so on arm64 they did not build.

What works

  • pcm0 attaches on the Pi 4, and a test melody plays on the 3.5 mm jack with 0 underruns.
  • The firmware answers VCHIQ protocol version 8.

Not done yet: HDMI audio (not tried), detach and kldunload, the Zero 2 W (not tried). The Pi 5 is out of scope: it has no analogue jack and its audio path is different.

Build and load

  1. Apply the two patches to the kernel sources: patches/0001-vchiq-arm64.patch and patches/0002-bcm2835_audio-arm64.patch. The second one also fixes the audio message size, which is 20 bytes on the wire.

  2. Build both modules against the source tree:

    cd driver && make SYSDIR=/usr/src/sys
    
  3. Load them, VCHIQ first:

    kldload ./vchiq/vchiq.ko ./bcm2835_audio/bcm2835_audio.ko
    
  4. Pick the output:

    sysctl dev.pcm.0.dest=1        # 0 auto, 1 headphone jack, 2 HDMI
    

The bug that kept it silent

The first builds loaded and played nothing. The fix was memory barriers in remote_event_signal, the function that tells the VideoCore firmware new data is waiting in shared memory. With them in place the tone and the melody came out of the jack.

Built with ssg