No audio on Custom Board using NAU8822

Hello,

I have a custom board based on the iMX8M Plus where I am trying to make the audio work. Here is the relevant schematic part:



And, I added the following device-tree nodes:

/ {

	sound_card: sound-card {
		compatible = "simple-audio-card";
		simple-audio-card,bitclock-master = <&dailink_master>;
		simple-audio-card,format = "i2s";
		simple-audio-card,frame-master = <&dailink_master>;
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,name = "imx8mp-nau8822";
		simple-audio-card,routing =
			"Headphones", "LHP",
			"Headphones", "RHP",
			"Speaker", "LSPK",
			"Speaker", "RSPK",
			"Line Out", "AUXOUT1",
			"Line Out", "AUXOUT2",
			"LAUX", "Line In",
			"RAUX", "Line In",
			"LMICP",    "Mic In",
			"RMICP",    "Mic In";
		simple-audio-card,widgets =
			"Headphones", "Headphones",
			"Line Out", "Line Out",
			"Speaker", "Speaker",
			"Microphone", "Mic In",
			"Line", "Line In";

		dailink_master: simple-audio-card,codec {
			sound-dai = <&nau8822_1a>;
			clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_MCLK1>;
		};

		simple-audio-card,cpu {
			sound-dai = <&sai1>;
		};
	};
};

/* Verdin I2C_1 */
&i2c4 {
	status = "okay";

	/* Audio Codec */
	nau8822_1a: codec-nau@1a {
		compatible = "nuvoton,nau8822";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_sai1>;
		#sound-dai-cells = <0>;
		reg = <0x1a>;
	};
};

However, I can’t seem to be able to use it to play audio:

torizon@verdin-imx8mp-15133370:~$ lsmod | grep nau8822
snd_soc_nau8822        53248  0
torizon@verdin-imx8mp-15133370:~$ cat /proc/asound/cards
--- no soundcards ---

In a container with /dev/snd, gstreamer, and all necessary libraries:

root@db0418a7b30d:/app/gui/bundle# gst-launch-1.0 audiotestsrc ! audioconvert ! pulsesink
Setting pipeline to PAUSED ...
XDG_RUNTIME_DIR (/tmp/1000-runtime-dir) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
ERROR: from element /GstPipeline:pipeline0/GstPulseSink:pulsesink0: Failed to connect: Connection refused
Additional debug info:
../ext/pulse/pulsesink.c(616): gst_pulseringbuffer_open_device (): /GstPipeline:pipeline0/GstPulseSink:pulsesink0
ERROR: pipeline doesn't want to preroll.
Failed to set pipeline to PAUSED.
Setting pipeline to NULL ...
Freeing pipeline ...

What is wrong with my configuration, what am I missing?

Thank you for your time.

Best regards,

Hello @mnano,

We also use the NAU8822 codec on the Verdin Development Board.

Did you base your device tree on it?
If yes, then the required configuration should already be in place for it to work.

Either way, the addition of the node is actually done with a sound node: imx8mp-verdin-dev.dtsi « freescale « dts « boot « arm64 « arch - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules
I would recommend that your custom device tree does the same, everything else looks identical or equivalent on this node.

It is also possible that the configuration from your device tree is missing the adjustments to the sai1 node:

/* Verdin I2S_1 */
&sai1 {
	assigned-clocks = <&clk IMX8MP_CLK_SAI1>;
	assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
	assigned-clock-rates = <24576000>;
	fsl,sai-mclk-direction-output;
	status = "okay";
};

Best Regards,
Bruno

1 Like

Hello @mnano,

Were you able to get your problem resolved?

Best Regards,
Bruno

Hello,

Yes, this is now solved. Thank you for your help. I had to do multiple things:

  • Updated the linux + device-tree branches that I was using for building my image to toradex_5.15-2.2.x-imx
  • Updated base torizon-core-docker image to monthly 22
  • Changed the sound/codec related nodes in my custom board device tree to:
/ {

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,bitclock-master = <&codec_dai>;
		simple-audio-card,format = "i2s";
		simple-audio-card,frame-master = <&codec_dai>;
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,name = "verdin-nau8822";
		simple-audio-card,routing =
			"Headphones", "LHP",
			"Headphones", "RHP",
			"Speaker", "LSPK",
			"Speaker", "RSPK",
			"Line Out", "AUXOUT1",
			"Line Out", "AUXOUT2",
			"LAUX", "Line In",
			"RAUX", "Line In",
			"LMICP", "Mic In",
			"RMICP", "Mic In";
		simple-audio-card,widgets =
			"Headphones", "Headphones",
			"Line Out", "Line Out",
			"Speaker", "Speaker",
			"Microphone", "Mic In",
			"Line", "Line In";

		codec_dai: simple-audio-card,codec {
			clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_MCLK1>;
			sound-dai = <&nau8822_1a>;
		};

		simple-audio-card,cpu {
			sound-dai = <&sai1>;
		};
	};
};

/* Verdin I2C_1 */
&i2c4 {
	status = "okay";

	/* Audio Codec */
	nau8822_1a: audio-codec@1a {
		compatible = "nuvoton,nau8822";
		reg = <0x1a>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_sai1>;
		#sound-dai-cells = <0>;
	};
};

/* Verdin I2S_1 */
&sai1 {
	assigned-clocks = <&clk IMX8MP_CLK_SAI1>;
	assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
	assigned-clock-rates = <24576000>;
	fsl,sai-mclk-direction-output;
	status = "okay";
};

Now this works and audio works perfectly. I think that I was using outdated base submodules (linux/device-trees) and some configuration somewhere did not match.

Best regards,

Hello @mnano,

Thanks for the update.

Best Regards,
Bruno