jeremynz
Posts: 20
Joined: Fri Sep 05, 2014 12:20 am

Help needed with I2S device tree overlay

Wed Mar 20, 2019 5:41 am

My Pi is interfaced to a 4G modem that has a PCM (I2S) audio output. I'd like this audio interface to show up as an ALSA device. I'm running a 4.14 kernel (Raspbian Squeeze) and from what I've read, I should be able to get this going using just a device tree overlay.

The format from the modem is fairly fixed: the modem is the clock master, audio sample rate is 8 kHz, there's a single 16-bit channel in each direction, I2S clock freq is 512 kHz.

It seems like this should be straight-forward but I'm having trouble translating this into a working device tree overlay.

Here's where I'm at, based on a previous example from mksounds/Hiassoft [viewtopic.php?p=1317745#p1317677]

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    fragment@0 {
        target-path = "/";
        __overlay__ {
            dual_soundcard: dual-soundcard {
                compatible = "simple-audio-card";
                simple-audio-card,name = "Sierra Audio";

                status="okay";

                capture_link: simple-audio-card,dai-link@0 {
                    format = "i2s";
                    bitclock-master = <&p_codec_dai>;
                    frame-master = <&p_codec_dai>;

                    r_cpu_dai: cpu {
                        sound-dai = <&i2s>;

                        dai-tdm-slot-num = <2>;
                        dai-tdm-slot-width = <128>;
                    };

                    r_codec_dai: codec {
                        sound-dai = <&codec_in>;
                    };
                };

                playback_link: simple-audio-card,dai-link@1 {
                    format = "i2s";
                    bitclock-master = <&p_codec_dai>;
                    frame-master = <&p_codec_dai>;

                    p_cpu_dai: cpu {
                        sound-dai = <&i2s>;

                        dai-tdm-slot-num = <2>;
                        dai-tdm-slot-width = <128>;
                    };

                    p_codec_dai: codec {
                        sound-dai = <&codec_out>;
                    };
                };
            };
        };
    };

    fragment@1 {
        target-path = "/";
        __overlay__ {
            codec_out: spdif-transmitter {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "linux,spdif-dit";
                status = "okay";
            };
            codec_in: spdif-receiver {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "linux,spdif-dir";
                status = "okay";
            };
        };
    };

    fragment@2 {
        target = <&i2s>;
        __overlay__ {
            #sound-dai-cells = <0>;
            status = "okay";
        };
    };

};
That seems to load fine, but I don't get any audio. I tried changing dai-tdm-slot-num and dai-tdm-slot-width to 1 and 16, but the driver stopped loading.

I would appreciate any pointers on how to get this going. I'm not even sure that the use of spdif-transmitter is correct in this scenario...
Last edited by jeremynz on Wed Mar 20, 2019 6:33 am, edited 1 time in total.

jeremynz
Posts: 20
Joined: Fri Sep 05, 2014 12:20 am

Re: Help needed with I2S device tree overlay

Wed Mar 20, 2019 5:57 am

A brief update,

I set dai-tdm-slot-num to 2 and dai-tdm-slot-width to 32 and i now get some form of audio when i use aplay to play to the new card.

I'm playing a .wav file with a single tone, but the audio I receive at the remote end is patchy, sometimes you hear the tone (with noise), sometimes there's nothing, and sometimes it's just white noise.

Capturing is even less successful. Although arecord -l returns a new device, I am unable to record at all.

Code: Select all

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Audio [Sierra Audio], device 1: bcm2835-i2s-dir-hifi dir-hifi-1 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
  
  $ arecord -D plughw:1 test.wav
arecord: main:788: audio open error: No such file or directory


HiassofT
Posts: 200
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Help needed with I2S device tree overlay

Wed Mar 20, 2019 10:58 am

The dual_soundcard overlay creates a card with two devices, playback on device 0 and record on device 1
card 1: Audio [Sierra Audio], device 1: bcm2835-i2s-dir-hifi dir-hifi-1 []
So for recording you have to use arecord -D plughw:1,1 (or hw:1,1) to select the correct device.

You probably also have to make sure to select the correct sample rate and format, depending on what your I2S device supports.

so long,

Hias

jeremynz
Posts: 20
Joined: Fri Sep 05, 2014 12:20 am

Re: Help needed with I2S device tree overlay

Fri Mar 22, 2019 12:12 am

HiassofT wrote:
Wed Mar 20, 2019 10:58 am
The dual_soundcard overlay creates a card with two devices, playback on device 0 and record on device 1
card 1: Audio [Sierra Audio], device 1: bcm2835-i2s-dir-hifi dir-hifi-1 []
So for recording you have to use arecord -D plughw:1,1 (or hw:1,1) to select the correct device.

You probably also have to make sure to select the correct sample rate and format, depending on what your I2S device supports.
Thanks! arecord is working now, and I think the problems I was having playing audio via aplay to the remote phone are perhaps due to the audio codecs used by the cellular network.

Return to “Device Tree”