Skip to content

overlays: Add spdif-gpio21 - #7748

Open
ehb wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
ehb:overlays-spdif-gpio21
Open

ehb wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
ehb:overlays-spdif-gpio21

Conversation

@ehb

@ehb ehb commented Nov 10, 2026 •

Copy link
Copy Markdown

A sound card for S/PDIF output straight from GPIO21 (PCM_DOUT), without a transceiver chip:
a TOSLINK module or a coaxial driver on header pin 40 is all the hardware. As suggested on
the forum (https://forums.raspberrypi.com/viewtopic.php?p=2392395), this is an overlay of its
own instead of borrowing hifiberry-dac.

The overlay only wires up what the kernel already has: the generic linux,spdif-dit codec on a
simple-audio-card, the Pi as bit and frame clock producer, 2 x 32-bit slots per frame, and
GPIO21 alone switched to its I2S function, so GPIOs 18-20 stay free. The S/PDIF line coding
(biphase-mark, at twice the audio rate as S32_LE) happens in userspace; the README entry says
so, as plain PCM played to this card does not produce audio. The userspace side is an ALSA
plugin behind alsa-lib's iec958 plugin: https://github.com/ehb/rpi-gpio-spdif

The same overlay should work on a Pi 5: the pin group uses the legacy brcm,pins/brcm,function properties, which the RP1 pin driver maps (GPIO21 ALT0 to i2s0).

Tested on a Pi 4B (LibreELEC 12.2.1, kernel 6.12), applied with dtoverlay at runtime (also on
every boot, by a service before the media player starts; not through config.txt):

  • the card appears as spdifgpio21, GPIO18-20 stay inputs, GPIO21 is PCM_DOUT
  • 44.1/48/96 kHz audio (I2S at 88.2/96/192 kHz) plays; a receiver decodes PCM, AC3 and DTS
    passthrough
  • lip sync checked with a flash/click test video

Checked, not run: both overlays and overlay_map built from this branch (cpp + dtc -@) and
applied with fdtoverlay to the base trees of Pi 1 B+, Zero W, Zero 2 W, Pi 3 B, Pi 4 B and
Pi 5 B, then read back (pins, clock producer, card). The Pi 5 variant has not run on
hardware
; I have no Pi 5. Feedback or a test by someone with a Pi 5 is welcome.

@pelwell

pelwell commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

I wouldn't be surprised if your non-pi5 overlay works on Pi 5 as is - the pinctrl/GPIO driver for RP1 has support for the legacy brcm, properties, mapping the ALT functions where possible - but I can try both.

Add an overlay that turns the I2S block into a sound card for an S/PDIF
transmitter on GPIO21 (PCM_DOUT), without a transceiver chip: the generic
linux,spdif-dit codec on a simple-audio-card, the Pi as bit and frame
clock producer, 2 x 32-bit slots per frame, and a pin group for GPIO21
alone, so GPIOs 18-20 stay free. Userspace supplies the biphase-mark
coded line signal as S32_LE at twice the audio rate.

The pin group uses the legacy brcm,pins/brcm,function properties, which
the RP1 pin driver maps as well (GPIO21 ALT0 to i2s0), so the same
overlay should also serve the Pi 5.

Assisted-by: claude-code:claude-opus-5-5
Signed-off-by: ehb <2213942+ehb@users.noreply.github.com>
@ehb
ehb force-pushed the overlays-spdif-gpio21 branch from ea1cf60 to d95f044 Compare November 10, 2026 20:54
@ehb

ehb commented Nov 10, 2026

Copy link
Copy Markdown
Author

Good point, thanks. With the RP1 legacy mapping it gets simpler, so I've reworked it: the overlay now adds its own pin group under &gpio (brcm,pins 21, brcm,function ALT0) and points the I2S block at it, instead of rewriting i2s_pins (which the Pi 5 tree doesn't have). That makes it one overlay for all models; the -pi5 variant and the overlay_map entry are gone. Applied to the Pi 1/Zero/3/4/5 base trees it resolves everywhere, and on my Pi 4 pin 21 is now owned by the I2S block with 18-20 unclaimed. A run on a Pi 5 would be very welcome.

@ehb ehb changed the title overlays: Add spdif-gpio21 and spdif-gpio21-pi5 overlays: Add spdif-gpio21 Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants