Jeston NX + audio Codec RT5640 cant work

Hi :
We has a issue when debug RT564,
The driver section contains rt5640. ctegra_rt5640 in the directory kernel/kernel-4.9/sound/soc.The hardware connection I2C is I2C2, and I2S is I2S1. The device tree is added according to the following steps for testing and error is found. The oscilloscope is used to measure I2S without signal output, please help to analyze.
1, device tree TEGRA194-AUDIO-P3668. DTSI modification:
i2c@3160000 {
rt5640: rt5640@1c {
compatible = “realtek,rt5640”;
reg = <0x1c>;
interrupt-parent = <&tegra_main_gpio>;
interrupts = <&tegra_main_gpio TEGRA194_MAIN_GPIO(Q, 5) IRQ_TYPE_EDGE_FALLING>;
realtek,ldo1-en-gpios =
<&tegra_main_gpio TEGRA194_MAIN_GPIO(R, 0) GPIO_ACTIVE_HIGH>;
sel_jd_source = <3>;
status = “okay”;
};
};
tegra_sound: sound {
status = “okay”;
compatible = “nvidia,tegra-audio-t186ref-mobile-rt565x”;
nvidia,model = “jetson-xaviernx-ape”;
clocks = <&bpmp_clks TEGRA194_CLK_PLLA>,
<&bpmp_clks TEGRA194_CLK_PLLA_OUT0>,
<&bpmp_clks TEGRA194_CLK_AUD_MCLK>;
clock-names = “pll_a”, “pll_a_out0”, “extern1”;
assigned-clocks = <&bpmp_clks TEGRA194_CLK_PLLA_OUT0>,
<&bpmp_clks TEGRA194_CLK_AUD_MCLK>;
assigned-clock-parents = <&bpmp_clks TEGRA194_CLK_PLLA>,
<&bpmp_clks TEGRA194_CLK_PLLA_OUT0>;

            nvidia,audio-routing =
                    "x Headphone Jack", "x HPOL",
                    "x Headphone Jack", "x HPOR",
                    "x Int Spk", "x SPORP",
                    "x Int Spk", "x SPORN",
                    "x Int Spk", "x SPOLP",
                    "x Int Spk", "x SPOLN",
                    "x IN1P", "x Mic Jack",
                    "x IN1P", "x MICBIAS1",
                    "x IN2P", "x Int Mic",
                    "x IN2P", "x MICBIAS1",
                    "x IN3P", "x Int Mic",
                    "x IN3P", "x MICBIAS1";
            mclk-fs = <256>;
            nvidia,dai-link-3 {
                    name-prefix = "x";
                    cpu-dai = <&tegra_i2s3>;
                    cpu-dai-name = "I2S3";
                    link-name = "rt5640_playback";
                    codec-dai = <&rt5640>;
                    codec-dai-name = "rt5640-aif1";

                    format = "i2s";
                    bitclock-slave;
                    frame-slave;
                    bitclock-noninversion;
                    frame-noninversion;
                    bit-format = "s16_le";
                    bclk_ratio = <0>;
                    srate = <48000>;
                    num-channel = <2>;
                    ignore_suspend;
                    status = "okay";
            };

            hdr40_snd_link_i2s: nvidia,dai-link-5 {
                    name-prefix = "x";
            };

    };

2:use: speaker-test -c2 -twav -D plughw:CARD=jetsonxaviernxa,DEV=0
An error appears:
Time per period = 0.056267

0 - Front Left

1 - Front Right

Write error: -32,Broken pipe

Time per period = 0.056780

0 - Front Left
Oscilloscope measures I2S without signal output, please help to see how to add audio module of NX platform?
thanks

Hello!

The first thing that you need to check is that the pinmux for the I2S pins are configured correctly. Are you using the Jetson Xavier NX devkit or the Jetson Xavier NX module with another board?

You can check the pinmux by executing the following …

$ sudo grep dap3 /sys/kernel/debug/tegra_pinctrl_reg
Bank: 0 Reg: 0x02431048 Val: 0x00000440 -> dap3_fs_pt4
Bank: 0 Reg: 0x02431050 Val: 0x00000450 -> dap3_din_pt3
Bank: 0 Reg: 0x02431058 Val: 0x00000400 -> dap3_dout_pt2
Bank: 0 Reg: 0x02431060 Val: 0x00000440 -> dap3_sclk_pt1

You should see the above.

If that looks good then please refer to this thread.

Regards,
Jon

Hi Jon:
We use our customize carrier board, pinmux looks good, hardware port is I2S1,
what port we need set on software? I2S3?

Hello!

Looking at the pinmux spreadsheet you will see that I2S1 on the module maps to DAP3 on the Tegra SoC and so yes I2S3 is the correct interface.

Regards,
Jon

hi Jon:
got it,will try this one,thanks

Hi Jon,
1、Now I add the rt5640 in dts file tegra194-audio-p3668.dtsi as below:

    i2c@3160000 {

            rt5640: rt5640@1c {
                    compatible = "realtek,rt5640";
                    reg = <0x1c>;
                    interrupt-parent = <&tegra_main_gpio>;
                    interrupts = <&tegra_main_gpio TEGRA194_MAIN_GPIO(Q, 5) IRQ_TYPE_EDGE_FALLING>;
                    realtek,ldo1-en-gpios =
                    <&tegra_main_gpio TEGRA194_MAIN_GPIO(R, 0) GPIO_ACTIVE_HIGH>;

                    sel_jd_source = <3>;
                    status = "okay";

            };
    };tegra_sound: sound {
	status = "okay";
	compatible = "nvidia,tegra-audio-t186ref-mobile-rt565x";
	nvidia,model = "jetson-xaviernx-ape";
	clocks = <&bpmp_clks TEGRA194_CLK_PLLA>,
		 <&bpmp_clks TEGRA194_CLK_PLLA_OUT0>,
		 <&bpmp_clks TEGRA194_CLK_AUD_MCLK>;
	clock-names = "pll_a", "pll_a_out0", "extern1";
	assigned-clocks = <&bpmp_clks TEGRA194_CLK_PLLA_OUT0>,
			  <&bpmp_clks TEGRA194_CLK_AUD_MCLK>;
	assigned-clock-parents = <&bpmp_clks TEGRA194_CLK_PLLA>,
				 <&bpmp_clks TEGRA194_CLK_PLLA_OUT0>;

	nvidia,audio-routing =
			"x Headphone",	"x OUT",
	                "x IN",		"x Mic",
	                "y Headphone",	"y OUT",
	                "y IN",		"y Mic",
	                "a IN",		"a Mic",
	                "b IN",		"b Mic";
	mclk-fs = <256>;

	/*nvidia,dai-link-1 {
		name-prefix = "n";
	};*/
            nvidia,dai-link-1 {
                    name-prefix = "x";
                    cpu-dai = <&tegra_i2s3>;
                    cpu-dai-name = "I2S3";
                    link-name = "rt5640_playback";
                    codec-dai = <&rt5640>;
                    codec-dai-name = "rt5640-aif1";
                    
                    format = "i2s";
                    bitclock-slave;
                    frame-slave;
                    bitclock-noninversion;
                    frame-noninversion;
                    bit-format = "s16_le";
                    bclk_ratio = <0>;
                    srate = <48000>;
                    num-channel = <2>;
                    ignore_suspend;
                    
                    status = "okay";

            };

2、Also I add the function tegra_machine_dai_init()
rtd = snd_soc_get_pcm_runtime(card, “rt5640_playback”);
if (rtd) {
dai_params =
(struct snd_soc_pcm_stream *)rtd->dai_link->params;

dai_params->rate_min = srate;
dai_params->formats = (machine->fmt_via_kcontrol == 2) ?
		(1ULL << SNDRV_PCM_FORMAT_S32_LE) : formats;

	err = snd_soc_dai_set_sysclk(rtd->codec_dai,
				RT5659_SCLK_S_MCLK, aud_mclk, SND_SOC_CLOCK_IN);
	if (err < 0) {
		dev_err(card->dev, "codec_dai clock not set\n");
		return err;

   }
}

and in the function codec_init(),
if (strstr(dai_links[i].name, “rt565x-playback”) || strstr(dai_links[i].name, “rt5640_playback”) ||
strstr(dai_links[i].name, “rt565x-codec-sysclk-bclk1”))
dai_links[i].init = tegra_machine_rt565x_init;
else if (strstr(dai_links[i].name, “fe-pi-audio-z-v2”))
dai_links[i].init = tegra_machine_fepi_init;
3、rebuild and flash dtb/Image file, when boot stage, I can the error log:
[ 53.936934] sysfs: cannot create duplicate filename ‘/devices/sound/I2S3 CIF’
[ 53.937312] kobject_add_internal failed for I2S3 CIF with -EEXIST, don’t try to register things with the same name in the same directory.
[ 53.937641] tegra-asoc: sound: ASoC: failed to register runtime device: -17
[ 53.937827] tegra-asoc: sound: ASoC: failed to instantiate card -17
[ 53.944761] tegra-asoc: sound: snd_soc_register_card failed (-17)
[ 53.945107] tegra-asoc:: probe of sound failed with error -17

Could you give me some advise on this issue? Thanks

Hi Jon,
root@cookoo:/home/cookoo# grep aud_mclk /sys/kernel/debug/clk/clk_summary
aud_mclk 0 0 43000000 43000000 0 0

Hello!

This would indicate that you have more than one dai-link attempting to use I2S3. Ensure that in your device-tree only one dai-link is using I2S3.

Regards
Jon

Hi Jon,
I modify the device tree to solve the error. Now we can not measure the aud_mclk signal, after execute the playback command.
speaker-test -D hw:jetsonxaviernxa,1 -c 2 -r 48000 -F S16_LE -t sine -f 500

Please give some advise on how to nx output aud_mclk. Thanks!

Hello!

Are you using the Jetson Xavier NX devkit or a custom carrier board for the module?

The first thing to check is that the pinmux is configured correctly. We can check this by dumping …

$ sudo grep aud /sys/kernel/debug/tegra_pinctrl_reg

Regards,
Jon

Hi Jon,
Thanks for your reply. I have resolved it. I do not config the pinmux:
busybox devmem 0x02431020 32 0x00000400

Regards,
zhaocuiqin

Hi Zhaocuiqin,

Great! Thanks for letting us know.

Regards,
Jon