AnsweredAssumed Answered

Problem with SGTL5000 audio codec and Simple Audio Card driver on i.MX8MM

Question asked by Martin Townsend on Aug 27, 2019
Latest reply on Sep 13, 2019 by Martin Townsend

Hi,

We are trying to get an SGTL5000 Audio Codec working, for recording audio
only, with our i.MX8MM board running the NXP linux-imx 4.14.98 Kernel.
We are using the Simple Audio Card driver and have set it up using the
following device tree fragment (which is included from arch/arm64/boot/dts/freescale/fsl-imx8mm-evk.dts):

/ {
regulators {
reg_3p3v: regulator-reg3v3 {
compatible = "regulator-fixed";
regulator-name = "reg_3p3v";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
};
reg_1p8v: regulator-reg1v8 {
compatible = "regulator-fixed";
regulator-name = "reg_1p8v";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
};
};

sound {
compatible = "simple-audio-card";
simple-audio-card,format = "i2s";
simple-audio-card,frame-master = <&codecdai>;
simple-audio-card,bitclock-master = <&codecdai>;
simple-audio-card,widgets =
"Line", "Line In Jack";
simple-audio-card,routing =
"LINE_IN", "Line In Jack";

cpudai: simple-audio-card,cpu {
sound-dai = <&sai3>;
};

codecdai: simple-audio-card,codec {
sound-dai = <&codec>;
clocks = <&clk IMX8MM_CLK_SAI3_ROOT>;
};
};
};

&iomuxc {
imx8mm-evk {
pinctrl_sai3_db: sai3grp {
fsl,pins = <
MX8MM_IOMUXC_SAI3_TXFS_SAI3_TX_SYNC 0xd6
MX8MM_IOMUXC_SAI3_TXC_SAI3_TX_BCLK 0xd6
MX8MM_IOMUXC_SAI3_MCLK_SAI3_MCLK 0xd6
MX8MM_IOMUXC_SAI3_TXD_SAI3_TX_DATA0 0xd6
MX8MM_IOMUXC_SAI3_RXD_SAI3_RX_DATA0 0xd6
>;
};
};
};

&i2c1 {
status = "okay";

codec: sgtl5000@a {
#sound-dai-cells = <0>;
compatible = "fsl,sgtl5000";
reg = <0xa>;
#if 0
micbias-resistor-k-ohms = <2>;
micbias-voltage-m-volts = <2250>;
#endif
VDDA-supply = <&reg_3p3v>;
VDDIO-supply = <&reg_3p3v>;
VDDD-supply = <&reg_1p8v>;
clocks = <&clk IMX8MM_CLK_SAI3_ROOT>;
clock-names = "sys_mclk";
};
};

&sai3 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sai3_db>;

#sound-dai-cells = <0>;
};

and added the following kernel configuration:

CONFIG_SND_SOC_IMX_SGTL5000=y
CONFIG_SND_SOC_SGTL5000=y

You may notice that the SGTL5000 is the I2S master, when we tried to use the
SAI as I2S master we would get the following error:

root@imx8mmevk:~# arecord -d 10 /tmp/test-mic.wav
[ 1343.737133] sgtl5000 0-000a: PLL not supported in slave mode
[ 1343.742855] sgtl5000 0-000a: sgtl5000->sysclk: 24576000 frame_rate: 44100
[ 1343.749691] sgtl5000 0-000a: 557 ratio is not supported. SYS_MCLK needs to be 256, 384 or 512 * fs
[ 1343.758698] sgtl5000 0-000a: ASoC: can't set sgtl5000 hw params: -22
ALSA lib ../../../alsa-lib-1.1.5/src/pcm/pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params
ALSA lib ../../../alsa-lib-1.1.5/src/pcm/pcm_dsnoop.c:649:(snd_pcm_dsnoop_open) unable to initialize slave
arecord: main:828: audio open error: Invalid argument

I'm guessing that the SAI interface isn't dividing the clock down to the
expected value that the audio codec driver is expecting, ie a multiple of 256,
384 opr 512. With the SGTL5000 as I2S master I think it uses an internal PLL
and with this setup we don't get the above message but we get silence on the
captured audio. The I2C interface works as we can read the chip ID, we have
checked all the signals going into the audio codec and we see

MCLK : 24.5Mhz
LRCLK : 44.1Khz
SCLK : 1.4Mhz
DOUT : There is data here, it is not all 0’s

Here's the recorded audio:
root@imx8mmevk:~# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: D30030000saisgt [30030000.sai-sgtl5000], device 0: 30030000.sai-sgtl5000 sgtl5000-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
root@imx8mmevk:~# arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
sysdefault:CARD=D30030000saisgt
30030000.sai-sgtl5000,
Default Audio Device
root@imx8mmevk:~# arecord -f cd -d 2 -D sysdefault:CARD=D30030000saisgt /tmp/test-mic.wav
Recording WAVE '/tmp/test-mic.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
root@imx8mmevk:~# hexdump -C /tmp/test-mic.wav
00000000 52 49 46 46 44 62 05 00 57 41 56 45 66 6d 74 20 |RIFFDb..WAVEfmt |
00000010 10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00 |........D.......|
00000020 04 00 10 00 64 61 74 61 20 62 05 00 00 00 00 00 |....data b......|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00056240 00 00 00 00 00 00 00 00 00 00 00 00 |............|
0005624c


Also, if we change the sample rate to say between 8Mhz and 16Mhz, it doesn’t seem
to change the above LRCLK and SCLK to match accordingly.

Can you see anything that we are doing wrong? Is the Simple Audio Card Driver
supported on your vendor specific kernel (4.14.98)? Are their patches available
for SAI or SGTL5000 for this kernel that we may require?

Many Thanks in Advance,
Martin.

Outcomes