How to enable SPDIF on AML-S905X-CC

I would like to use SPDIF header on board for digital audio output. Does it needs to be enabled with some device tree overlay? Command aplay -l shows only one card:

**** List of PLAYBACK Hardware Devices ****
card 0: LIBRETECHCC [LIBRETECH-CC], device 0: fe.dai-link-0 (*) []
Subdevices: 1/1
Subdevice #0: subdevice #0

Analog audio works from 3.5mm jack by default.

Do you have a TOSLINK adapter? It should just work with some adjustments to alsamixer.

See spdif_out_ao_6_pins in https://boot.libre.computer/ci/aml-s905x-cc.dts

Yes, I have Toslink adapter attached. I did take look of alsamixer but was not sure about settings and what should be changed. After configurations are done, should I see with aplay -l command (or similar) when SPDIF output is enabled?

Just checked, you do need a device tree overlay. Please wait.

OK, that’s awesome! The reason why I asked for help was when I noticed on the all-h3-cc-h5 Board side that there was spdif.dts overlay used to enable SPDIF and wondered could it be same thing in AML-S905X-CC board also.

Just checking is there any progress on this? I’m developing a commercial streamer device and evaluating AML-S905X-CC SBC due to it’s very competitively priced. Integrated SPDIF would be a very big advantage over other manufacturers, but of course I would like to try it. Secondly, is the SPDIF output directly supported in some other distros? I’m currently using this Debian 11 Bullseye:

Linux raspberrypi 6.1.29-06024-g1987da89199c #1 SMP PREEMPT_DYNAMIC Wed May 24 04:26:03 UTC 2023 aarch64 GNU/Linux

Clone the latest libretech-wiring-tool and use ./ldto instead of ldto. This SPDIF overlay will be pushed via apt in a week or so. Please let us know if you run into any issues.

Which distro was used to test this overlay? Enabling spdif.dts didn’t affect (no new device seen with aplay -l) and merging the overlay resulted that all audio was broken.

gevol@raspbian-bullseye-aml-s905x-cc:~ $ speaker-test

speaker-test 1.2.4

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Playback open error: -2,No such file or directory

It doesn’t show up as a new device since the SPDIF controller just takes the existing PCM output and encodes it for SPDIF and outputs the signal on the pin.

Test with sudo and set channels to 2.

I solved the problem with following procedure:

  1. sudo ./ltdo merge spdif
  2. cd /boot/efi/dtb/amlogic
  3. sudo dtc -I dtb -O dts meson-gxl-s905x-libretech-cc.dtb -o meson-gxl-s905x-libretech-cc.dts
  4. edit “meson-gxl-s905x-libretech-cc.dts” by moving node “dai-link-4” in sound node from the first to last:
        sound {
                compatible = "amlogic,gx-sound-card";
                model = "LIBRETECH-CC";
                audio-aux-devs = <0x38>;
                audio-widgets = "Line\0Lineout";
                audio-routing = "AU2 INL\0ACODEC LOLN\0AU2 INR\0ACODEC LORN\0Lineout\0AU2 OUTL\0Lineout\0AU2 OUTR";
                assigned-clocks = <0x03 0x0d 0x03 0x0e 0x03 0x0f>;
                assigned-clock-parents = <0x00 0x00 0x00>;
                assigned-clock-rates = <0x11940000 0x10266000 0x17700000>;
                status = "okay";

                dai-link-0 {
                        sound-dai = <0x39 0x00 0x00>;
                };

                dai-link-1 {
                        sound-dai = <0x39 0x00 0x02>;
                        dai-format = "i2s";
                        mclk-fs = <0x100>;

                        codec-0 {
                                sound-dai = <0x39 0x01 0x00>;
                        };

                        codec-1 {
                                sound-dai = <0x39 0x02 0x00>;
                        };
                };

                dai-link-2 {
                        sound-dai = <0x39 0x01 0x02>;

                        codec-0 {
                                sound-dai = <0x16>;
                        };
                };

                dai-link-3 {
                        sound-dai = <0x39 0x02 0x02>;

                        codec-0 {
                                sound-dai = <0x3a>;
                        };
                };
				
				dai-link-4 {
					sound-dai = <0x39 0x00 0x03>;

					codec-0 {
						sound-dai = <&spdif_dit>;
					};
				};
        };
  1. sudo dtc -I dts -O dtb meson-gxl-s905x-libretech-cc.dts -o meson-gxl-s905x-libretech-cc.dtb
  2. sudo reboot

Finally, I2S must be selected as the SPDIF source in alsamixer’s settings.

gevol@raspbian-bullseye-aml-s905x-cc:/boot/efi/dtb/amlogic $ amixer
Simple mixer control 'ACODEC',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB] [on]
  Front Right: Playback 255 [100%] [0.00dB] [on]
...
...
Simple mixer control 'AIU ACODEC SRC',0
  Capabilities: enum
  Items: 'DISABLED' 'I2S' 'PCM'
  Item0: 'I2S'
Simple mixer control 'AIU HDMI CTRL SRC',0
  Capabilities: enum
  Items: 'DISABLED' 'PCM' 'I2S'
  Item0: 'I2S'
Simple mixer control 'AIU SPDIF SRC SEL',0
  Capabilities: enum
  Items: 'SPDIF' 'I2S'
  Item0: 'I2S'

Now the audio is coming through SPDIF and Toslink adapter.

1 Like

Hi Librespot, are going to fix the issue with the provided spdif.dts overlay regarding to correct dai-link sub node order? According to my tests “dai-link-4” node can’t be the first (before dai-link-0) due it will break the audio totally. When it’s the last sub-node then audio and SPDIF output in Header 9J1 will work.

gevol@raspbian-bullseye-aml-s905x-cc:~/libretech-wiring-tool $ sudo ./ldto merge spdif
Overlay spdif: merged for next boot
gevol@raspbian-bullseye-aml-s905x-cc:~/libretech-wiring-tool $ sudo ./ldto diff
--- CURRENT
+++ NEXT
@@ -7,6 +7,14 @@
        compatible = "libretech,aml-s905x-cc\0amlogic,s905x\0amlogic,meson-gxl";
        model = "Libre Computer AML-S905X-CC";

+       audio-codec {
+               phandle = <0xa8>;
+               sound-name-prefix = "SPDIF";
+               status = "okay";
+               compatible = "linux,spdif-dit";
+               #sound-dai-cells = <0x00>;
+       };
+
        aliases {
                mmc0 = "/soc/apb@d0000000/mmc@74000";
                mmc1 = "/soc/apb@d0000000/mmc@72000";
@@ -320,6 +328,8 @@
                        };

                        audio-controller@5400 {
+                               pinctrl-names = "default";
+                               pinctrl-0 = <0x92>;
                                compatible = "amlogic,aiu-gxl\0amlogic,aiu";
                                #sound-dai-cells = <0x02>;
                                sound-name-prefix = "AIU";
@@ -1811,6 +1821,14 @@
                assigned-clock-rates = <0x11940000 0x10266000 0x17700000>;
                status = "okay";

+               dai-link-4 {
+                       sound-dai = <0x3a 0x00 0x03>;
+
+                       codec-0 {
+                               sound-dai = <0xa8>;
+                       };
+               };
+
                dai-link-0 {
                        sound-dai = <0x3a 0x00 0x00>;
                };
@@ -1869,6 +1887,7 @@
        };

        __symbols__ {
+               spdif_dit = "/audio-codec";
                hwrom_reserved = "/reserved-memory/hwrom@0";
                secmon_reserved = "/reserved-memory/secmon@10000000";
                secmon_reserved_alt = "/reserved-memory/secmon@5000000";

The issue is due to how fdtoverlay handles merging of the overlay into the main DT. We are still evaluating how to make the merge sort alphabetically.

OK, great! Hopefully a solution will be found for this, because the same type of issue can be encountered with another overlay or configuration.