Jetson nano connect RT5639 CODEC using I2S4 interface

Hi,nvidia:
I’m trying to porting realtek’s 5639 codec to Nano, with nano’s I2S and I2C interface.When i use aplay to play test.wav, The following problems occur:

  1. The headphones can hear the sound,but the sound from the headphones is very quiet;
  2. The headphones hear a lot of noise, the correct sound is very low.

Here is my debug log:

  1. aplay cmd:
    ~# aplay -D plughw:CARD=tegrasndt210ref,DEV=0 test.wav
    Playing WAVE ‘test.wav’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
  2. I2S4 output clocks:
    FS: 44.1khz
    MCLK: 11.29Mhz
    SCLK: 1.41Mhz
  3. ~# cat /proc/device-tree/sound/mclk-fs | xxd
    00000000: 0000 0100
  4. Reference linking:
    Porting realtek rt5639 codec to Nano
    Porting realtek ALC5640(rt5640) codec to Nano

Please check if can gain some ideas from : NVIDIA Jetson Linux Driver Package Software Features : Audio Setup and Development | NVIDIA Docs

Hi wly,

It appears to be a clock related issue. However the clock rates for FS, MCLK and SCLK are as expected. Did you actually probe these clocks or these are from clock tree dump?

Please note that, driver change is required to setup sysclk for codec.
Can you please attach kernel logs, DT and driver changes you made to confirm if setup is OK?

Thanks,
Sameer.

Hi spujar.
Thank you very much for your reply.
The clock is measured by means of an oscilloscope, and make sure it’s right.
tegra_machine_driver_mobile.c:

	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, RT5640_SCLK_S_MCLK,
					     aud_mclk, SND_SOC_CLOCK_IN);
		/*err = rt5640_manage_codec_sysclk(dai_params, rtd->codec_dai,
				 RT5640_PLL1_S_BCLK1);*/
		
		if (err < 0) {
			dev_err(card->dev, "codec_dai clock not set\n");
			return err;
		}
	}

tegra210-soc-base.dtsi:

	i2c3: i2c@7000c500 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "nvidia,tegra210-i2c";
		reg = <0x0 0x7000c500 0x0 0x100>;
		interrupts = <0 92 0x04>;
		iommus = <&smmu TEGRA_SWGROUP_PPCS>;
		//status = "disabled";
		clock-frequency = <400000>;
		dmas = <&apbdma 23>, <&apbdma 23>;
		dma-names = "rx", "tx";
                clocks = <&tegra_car TEGRA210_CLK_I2C3>, <&tegra_car TEGRA210_CLK_PLL_P>;
                clock-names = "div-clk", "parent";
                resets = <&tegra_car 67>;
                reset-names = "i2c";

	    status = "okay";
        rt5640_codec: rt5640_codec@1c {
			compatible = "realtek,rt5639";
			reg = <0x1c>;
			status = "okay";
		};
	};

tegra210-porg-p3448-common.dtsi:

tegra_sound: sound {
	status = "okay";
	compatible = "nvidia,tegra-audio-t210ref-mobile-rt565x";
	nvidia,model = "tegra-snd-t210ref-mobile-rt5639";

	clocks = <&tegra_car TEGRA210_CLK_PLL_A>,
		 <&tegra_car TEGRA210_CLK_PLL_A_OUT0>,
		 <&tegra_car TEGRA210_CLK_EXTERN1>;
	clock-names = "pll_a", "pll_a_out0", "extern1";
	assigned-clocks = <&tegra_car TEGRA210_CLK_EXTERN1>;
	assigned-clock-parents = <&tegra_car TEGRA210_CLK_PLL_A_OUT0>;

	nvidia,num-codec-link = <1>;
	nvidia,audio-routing =
		"x Headphone Jack", 	"x HPOL",
		"x Headphone Jack", 	"x HPOR";

	nvidia,xbar = <&tegra_axbar>;
	mclk-fs = <256>;

	hdr40_snd_link_i2s: i2s_dai_link1: nvidia,dai-link-1 {
		link-name = "rt5640-playback";
		cpu-dai = <&tegra_i2s4>;
		codec-dai = <&rt5640_codec>;
		cpu-dai-name = "I2S4";
		codec-dai-name = "rt5640-aif1";                                                             
		format = "i2s";
		bitclock-slave;
		frame-slave;
		bitclock-noninversion;
		frame-noninversion;
		bit-format = "s16_le";
		srate = <48000>;
		num-channel = <2>;
		ignore_suspend;
		name-prefix = "x";
		status = "okay";
	};
};

Hi wly

Setup wise it looks good and you get expected clock rates. Can you please attach scopes of clock signals? Sometimes if signal is weak or distorted, it can have impact over the audio quality. It would be good to double check this.

You can attach the scopes of I2S signals with or without the audio codec connected.

Thanks,
Sameer.

Hi spujar.
Thank you very much for your reply.
The output signal of I2S4 is stable and correct,
We connected the I2S4 directly to the PCM5100A(a simple CODEC compared to RT5639), and we could hear perfect sound all the time.

Hi wly

This confirms that the clock and driver configurations are fine from SoC point of view. Also since you strongly believe the clock and signal strength to be fine (with RT5639 board connected), I don’t have a reason to doubt these anymore. There is some problem with your RT5639 codec board or the related driver. Please confirm if you see the same behavior with another RT5639 board as well.

Did you happen to make any changes to RT5639 driver? Please share in case you have done any changes.

Thanks.

Hi spujar
In order to solve the hardware problem, we made the board again. I will feedback my test record later.
Thank you very much Spujar

Hi spujar
I’ll change the board and get the perfect sound. It’s my problem. Sorry.
Thank you very much for your support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.