The audio codec es8316 can’t work on I2S0 for Xaiver NX

Hi, Engineers
dmesg.txt (91.3 KB)
es8316.c (38.1 KB)
tegra_machine_driver_mobile.c (24.3 KB)
tegra194-audio-p3668.dtsi (2.1 KB)

The audio chip has been successfully registered in our system, but it can’t work normally. There is no sound when playing music.
Measure I2S_LRCK and I2S_SDO and I2S_SCK with an oscilloscope and there is no signal, Only I2S_MCK has a signal, Here are the pictures



es8316.c and DTS and dmesg links are also placed above.

1. sudo find /sys/kernel/debug/asoc/ -name 'x Playback’

/sys/kernel/debug/asoc/jetson-xaviernx-ape/codec:es8316.1-0010/dapm/x Playback

2. sudo find /sys/kernel/debug/asoc/ -name ‘x Playback’ | xargs -i cat {};

x Playback: Off  in 0 out 0
 stream Playback inactive
 in  "static" "I2S5 DAP Transmit-x Playback"

3. cat /proc/asound/cards

 0 [tegrahdaxnx    ]: tegra-hda-xnx - tegra-hda-xnx
                      tegra-hda-xnx at 0x3518000 irq 66
 1 [jetsonxaviernxa]: jetson-xaviernx - jetson-xaviernx-ape
                      jetson-xaviernx-ape

4. sudo cat /sys/kernel/debug/asoc/codecs

tegra186-dspk.1
tegra186-dspk.0
tegra186-asrc
tegra186-arad
tegra210-ope.0
tegra210-mvc.1
tegra210-mvc.0
tegra186-afc.5
tegra186-afc.4
tegra186-afc.3
tegra186-afc.2
tegra186-afc.1
tegra186-afc.0
tegra210-sfc.3
tegra210-sfc.2
tegra210-sfc.1
tegra210-sfc.0
tegra210-mixer
tegra210-adx.3
tegra210-adx.2
tegra210-adx.1
tegra210-adx.0
tegra210-amx.3
tegra210-amx.2
tegra210-amx.1
tegra210-amx.0
tegra210-dmic.3
tegra210-dmic.2
tegra210-dmic.1
tegra210-dmic.0
tegra210-i2s.5
tegra210-i2s.4
tegra210-i2s.3
tegra210-i2s.2
tegra210-i2s.1
tegra210-i2s.0
tegra186-admaif
tegra210-axbar
spdif_dit:spdif-dit.13@d
spdif_dit:spdif-dit.12@c
spdif_dit:spdif-dit.11@b
spdif_dit:spdif-dit.10@a
spdif_dit:spdif-dit.9@9
spdif_dit:spdif-dit.8@8
spdif_dit:spdif-dit.7@7
spdif_dit:spdif-dit.6@6
spdif_dit:spdif-dit.5@5
spdif_dit:spdif-dit.4@4
spdif_dit:spdif-dit.3@3
spdif_dit:spdif-dit.2@2
spdif_dit:spdif-dit.1@1
spdif_dit:spdif-dit.0@0
es8316.1-0010
snd-soc-dummy

5. es8316 dts:

	i2c@c240000 { 
		es8316_codec: es8316@10 {
			compatible = "everest,es8316";
			reg = <0x10>;
			status = "okay";
		};
	};

6. I2S pinmux:

	pinmux@2430000 {
		status = "okay";
		pinctrl-names = "default";
		pinctrl-0 = <&hdr40_pinmux>;

		hdr40_pinmux: header-40pin-pinmux {
			pin7 {
				nvidia,pins = HDR40_PIN7;
				nvidia,function = HDR40_CLK;
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			pin12 {
				nvidia,pins = HDR40_PIN12;
				nvidia,function = HDR40_I2S;
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			pin35 {
				nvidia,pins = HDR40_PIN35;
				nvidia,function = HDR40_I2S;
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			pin38 {
				nvidia,pins = HDR40_PIN38;
				nvidia,function = HDR40_I2S;
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			pin40 {
				nvidia,pins = HDR40_PIN40;
				nvidia,function = HDR40_I2S;
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
		};        
        
	};

Looking forward to your reply, thank you

Hi:
Now I2S_MCK , I2S_SCK , I2S_LRCK have signals here, But es8316 there was still no sound , some problem with routing

1. es8316 I2C dts is here:

	i2c@3160000 {
		status="okay";
		es8316_codec: es8316@10 {
			compatible = "everest,es8316";
			reg = <0x10>;
            clocks = <&tegra_car TEGRA186_CLK_AUD_MCLK>;
            clock-names = "mclk";
			status = "okay";
		};
	};

2. file sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c diff is here:

--- a/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c
+++ b/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c
@@ -29,10 +29,16 @@
 #include <sound/soc.h>
 #include <dt-bindings/sound/tas2552.h>
 #include "rt5659.h"
+#include "es8316.h"
 #include "sgtl5000.h"
 #include "tegra_asoc_machine_alt.h"
 #include "tegra210_xbar_alt.h"
 
+enum {
+       ES8316_SCLK_S_MCLK = 0,
+       ES8316_SCLK_S_PLL1,
+       ES8316_SCLK_S_RCCLK,
+};
 #define DRV_NAME "tegra-asoc:"
 
 #define PARAMS(sformat, channels)              \
@@ -169,6 +175,8 @@ static const struct snd_soc_dapm_widget tegra_machine_dapm_widgets[] = {
        SND_SOC_DAPM_LINE("y Line Out", NULL),
        SND_SOC_DAPM_LINE("x Line In", NULL),
        SND_SOC_DAPM_LINE("y Line In", NULL),
+       SND_SOC_DAPM_LINE("x IN", NULL),
+       SND_SOC_DAPM_LINE("x OUT",NULL),
 };
 
 static struct snd_soc_pcm_stream tegra_machine_asrc_link_params[] = {
@@ -335,13 +343,33 @@ static int tegra_machine_dai_init(struct snd_soc_pcm_runtime *runtime,
 
        aud_mclk = machine->audio_clock.set_aud_mclk_rate;
 
-       pr_debug("pll_a_out0 = %u Hz, aud_mclk = %u Hz, sample rate = %u Hz\n",
+       printk("pll_a_out0 = %u Hz, aud_mclk = %u Hz, sample rate = %u Hz\n",
                 machine->audio_clock.set_pll_out_rate, aud_mclk, srate);
 
        err = tegra_machine_set_params(card, machine, srate, channels, formats);
        if (err < 0)
                return err;
 
+       rtd = snd_soc_get_pcm_runtime(card, "es8316-playback"); //wxz
+       if (rtd) {
+               printk("%s===========8316=======es8316-playback=========== %d\n",__func__,__LINE__);
+               dai_params =
+               (struct snd_soc_pcm_stream *)rtd->dai_link->params;
+
+               dai_params->formats = (machine->fmt_via_kcontrol == 2) ?
+                       (1ULL << SNDRV_PCM_FORMAT_S32_LE) : formats;
+
+        dai_params->rate_min = srate;
+        //dai_params->channels_min = channels;
+
+               //err = es8316_set_dai_sysclk(rtd->codec_dai, ES8316_SCLK_S_MCLK,aud_mclk, SND_SOC_CLOCK_IN);
+               err = snd_soc_dai_set_sysclk(rtd->codec_dai, ES8316_SCLK_S_MCLK, 12288000,SND_SOC_CLOCK_IN);
+               if (err < 0) {
+                       dev_err(card->dev, "codec_dai clock not set\n");
+                       return err;
+               }
+       }
+
        rtd = snd_soc_get_pcm_runtime(card, "rt565x-playback");
        if (rtd) {
                dai_params =
@@ -541,6 +569,21 @@ static int tegra_machine_fepi_init(struct snd_soc_pcm_runtime *rtd)
        return 0;
 }
 
+static int tegra_machine_es8316_init(struct snd_soc_pcm_runtime *rtd)  //wxz
+{
+       struct device *dev = rtd->card->dev;
+       int err;
+
+       //err = es8316_set_dai_sysclk(rtd->codec_dai, ES8316_SCLK_S_MCLK, 11289600,SND_SOC_CLOCK_IN);
+       err = snd_soc_dai_set_sysclk(rtd->codec_dai, ES8316_SCLK_S_MCLK, 12288000,SND_SOC_CLOCK_IN);
+       if (err) {
+               dev_err(dev, "failed to set es8316 sysclk!\n");
+               return err;
+       }
+
+       return 0;
+}
+
 static int tegra_machine_rt565x_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_card *card = rtd->card;
@@ -602,6 +645,8 @@ static int codec_init(struct tegra_machine *machine)
                        dai_links[i].init = tegra_machine_fepi_init;
                else if (strstr(dai_links[i].name, "respeaker-4-mic-array"))
                        dai_links[i].init = tegra_machine_respeaker_init;
+               else if (strstr(dai_links[i].name, "es8316-playback"))  //wxz
+                       dai_links[i].init = tegra_machine_es8316_init;
        }
 
        return 0;
@@ -784,8 +829,8 @@ static int tegra_machine_driver_probe(struct platform_device *pdev)
 
        ret = snd_soc_register_card(card);
        if (ret) {
-               dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
-                       ret);
+               dev_err(&pdev->dev, "snd_soc_register_card failed (%d) %s %d\n",
+                       ret,__FILE__,__LINE__);
                goto cleanup_asoc;
        }

3. sound dts tegra186-p3636-0001-a00-audio.dtsi diff is here:

--- a/kernel-dts/common/tegra186-p3636-0001-a00-audio.dtsi
+++ b/kernel-dts/common/tegra186-p3636-0001-a00-audio.dtsi
@@ -42,11 +42,67 @@
 
                mclk-fs = <256>;
 
+               nvidia,audio-routing = 
+                "x HPCP L", 	"x HPVOL L",
+            	"x HPCP R",		"x HPVOL R",
+                "x Headphone", 	"x HPOL",
+            	"x Headphone", 	"x HPOR",
+				"x micbias",            	"x MIC1",
+				"x micbias",            	"x MIC2",
+				"x micbias",            	"x DMIC",
+				"x MIC1",               	"x Differential Mux",
+				"x MIC2",               	"x Differential Mux",
+				"x Differential Mux",   	"x Line input PGA", 
+				"x Line input PGA",     	"x Mono ADC", 
+				"x Mono ADC",           	"x Digital Mic Mux", 
+				"x DMIC",               	"x Digital Mic Mux", 
+				"x DMIC",               	"x Digital Mic Mux", 
+				"x Digital Mic Mux",    	"x I2S OUT",
+				"x I2S IN",             	"x DAC SRC Mux", 
+				"x I2S IN",             	"x DAC SRC Mux", 
+				"x I2S IN",             	"x DAC SRC Mux", 
+				"x I2S IN",             	"x DAC SRC Mux", 
+				"x DAC SRC Mux",        	"x Left DAC", 
+				"x DAC SRC Mux",        	"x Right DAC",
+				"x MIC1",               	"x Left Hp mux", 
+				"x MIC2",               	"x Left Hp mux", 
+				"x Differential Mux",   	"x Left Hp mux", 
+				"x Line input PGA",     	"x Left Hp mux", 
+				"x MIC1",               	"x Right Hp mux", 
+				"x MIC2",               	"x Right Hp mux", 
+				"x Differential Mux",   	"x Right Hp mux", 
+				"x Line input PGA",     	"x Right Hp mux", 
+				"x Left Hp mux",        	"x Left Hp mixer",
+				"x Left DAC",				"x Left Hp mixer",
+				"x Right Hp mux",  			"x Right Hp mixer",  	
+				"x Right DAC",     			"x Right Hp mixer",  	
+				"x Left Hp mixer", 			"x HPCP L",				
+				"x Right Hp mixer",			"x HPCP R";
+
+               nvidia,xbar = <&tegra_axbar>;
+
                /* TODO Avoid rt565x_dai_link definition by modifying common base file
                 * since current base does not have definition of dai link as
                 * rt565x_dai_link,  had to add here
                 */
-               hdr40_snd_link_i2s: rt565x_dai_link: nvidia,dai-link-1 { };
+               hdr40_snd_link_i2s: rt565x_dai_link: nvidia,dai-link-1 {
+                       link-name = "es8316-playback";
+                       cpu-dai = <&tegra_i2s1>;
+                       codec-dai = <&es8316_codec>;
+                       cpu-dai-name = "I2S1";
+                       codec-dai-name = "es8316-hifi";
+                       format = "i2s";
+			bitclock-master;
+			frame-master;
+                       bit-format = "s16_le";
+                       srate = <48000>;
+                       num-channel = <2>;
+                       ignore_suspend;
+                       name-prefix = "x";
+                       status = "okay";                        
+               };
                hdr40_i2c1: i2c@c240000 { };
        };
 };

Look forward to your reply, thanks

Hi @wangxiaozhuang, This is the wrong category for your issue. I am moving this topic from the Triton Inference Server category to Jetson Xavier NX.