Use the existing Linux ALSA Audio XCVR / S/PDIF driver on i.MX8M Plus; you normally do not implement the S/PDIF protocol from scratch. The i.MX8M Plus Audio XCVR supports eARC, ARC, and S/PDIF modes, and the Linux S/PDIF support exposes one playback device for Tx and one capture device for Rx through ALSA.
Suggested implementation path:
Enable the kernel driver Enable:
CONFIG_SND_IMX_SPDIF
Menu path:
Copy
Device Drivers
-> Sound card support
-> Advanced Linux Sound Architecture
-> ALSA for SoC audio support
-> SoC Audio for Freescale i.MX CPUs
-> SoC Audio support for i.MX boards with S/PDIF
The documented DT bindings are under Documentation/devicetree/bindings/sound/fsl,spdif.txt and Documentation/devicetree/bindings/sound/imx-audio-spdfif.txt .
- Configure the device tree For i.MX8M Plus, use the xcvr audio block and enable the sound card / DAI link. A representative configuration is:
sound-xcvr {
compatible = "fsl,imx-audio-card";
model = "imx-audio-xcvr";
pri-dai-link {
link-name = "XCVR PCM";
cpu {
sound-dai = <&xcvr>;
};
};
};
&xcvr {
#sound-dai-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_xcvr>;
status = "okay";
};
For Tx pin muxing, one documented example uses MX8MP_IOMUXC_SPDIF_TX__AUDIOMIX_SPDIF1_OUT .
- Check board routing / jumpers If using the NXP audio board, set the physical routing for the intended S/PDIF path. For i.MX8M Plus, J1500=1-2 routes the coaxial connector to i.MX8M Plus, and J1500=4-5 routes the optical connector to i.MX8M Plus. If routing through CPLD / HDMI card, J2511=1-3 is documented as “i.MX 8M Plus to CPLD to HDMI card.”
- Use ALSA / IEC958 correctly The S/PDIF Tx driver supports 32, 44.1, and 48 kHz sample rates, with S16_LE and S24_LE formats; for 24-bit output, the file must use 32 bits per channel frame with only the 24 LSBs valid. If the path expects IEC958 subframes rather than raw PCM, do the PCM-to-IEC958 conversion in user space, for example using an ALSA PCM plugin.
Validation steps:
aplay -l
arecord -l
Use these to identify the S/PDIF playback / capture card and device IDs. The documentation shows the S/PDIF device appearing as an ALSA card such as imxspdif [imx-spdif], device 0: S/PDIF PCM .
Tx validation:
aplay -D hw:<card_id>,<pcm_id> audio48k24S.wav
The reference validation method uses an external optical S/PDIF receiver, such as an M-Audio Transit USB sound card with WaveLab, then records the stream externally and plays it back to check correctness.
Rx validation:
arecord -D hw:<card_id>,<pcm_id> -c 2 -d 20 -r 48000 -f S24_LE record.wav
The sample rate passed to arecord must match the incoming S/PDIF stream sample rate. For Rx, the application flow is to open the S/PDIF Rx PCM device, wait for the internal DPLL to lock to the input bit stream, get the input sample rate, set channel / format / rate parameters, then prepare and trigger capture.
For protocol-level checks, use:
iecset -c <card_id>
iecset is the standard utility documented for setting or dumping IEC958 status bits, and the driver also exposes channel-status handling through the ALSA control interface.
For i.MX8M Plus EVK-style validation, NXP also documents loopback-style Linux testing using the imxaudioxcvr card, for example recording from imxaudioxcvr and playing to wm8960audio :
arecord -Dsysdefault:CARD=imxaudioxcvr -c2 -r48000 -fS32_LE -twav | \
aplay -Dsysdefault:CARD=wm8960audio
In short: enable the i.MX S/PDIF / XCVR ALSA driver, configure the xcvr device tree and board routing, then validate Tx/Rx with aplay , arecord , iecset , and an external optical/coax S/PDIF source or sink.