The i.MX8M Mini provides five transmit/receive Serial Audio Interfaces (SAI).

On the ConnectCore 8M Mini Development Kit, the SAI2 interface is connected to a Maxim 98089 low-power stereo codec with the following features:

  • Analog inputs: line-in A, line-in B, microphone:

    • Two line-in audio inputs through the LINE1_IN_ and LINE2_IN_ lines of the J53 connector.

    • Microphone audio input through the on-board jack connector.

  • Analog outputs: line-out, headphone, speakers:

    • Line-out audio output through the LINE_OUT_ lines of the J53 connector.

    • Headphone audio output through the on-board jack connector.

    • Speaker audio output through the SPKL_ and SPKR_ lines of the J53 connector.

  • Digital input/out multi-format audio interface.

  • Digital processing, filters, volume control, amplifiers.

The codec is a slave chip that the CPU controls via the SAI2 port of the ConnectCore 8M Mini system-on-chip. The CPU drives audio data using the inter-IC sound bus standard (I2S).

All audio output comes out through this codec and can be reproduced using a pair of speakers or headphones.

Kernel configuration

You can manage the audio driver support through the following kernel configuration options:

  • SoC Audio for NXP i.MX CPUs (CONFIG_SND_IMX_SOC)

  • SoC Audio support for i.MX boards with max98088/max98089 (CONFIG_SND_SOC_IMX_MAX98088)

These options are enabled as built-in on the default ConnectCore 8M Mini kernel configuration file.

Kernel driver

The drivers for the audio interface and MAX98089 codec are located at:

File Description

sound/soc/fsl/fsl_sai.c

SAI driver

sound/soc/fsl/snd-soc-imx-max98088.c

Driver interface with codec

sound/soc/codecs/max98088.c

MAX98088/9 codec driver

Device tree bindings and customization

The SAI interface is documented at Documentation/devicetree/bindings/sound/fsl-sai.txt.

The interface between the SAI and the codec is documented at Documentation/devicetree/bindings/sound/imx-audio-max98088.txt.

The MAX98088/9 codec is documented at Documentation/devicetree/bindings/sound/max98088.txt.

The device tree must contain entries for:

  • The SAI interface

  • The interface between the SAI and the audio codec

  • The audio codec

Example: SAI2 on ConnectCore 8M Mini Development Kit

Definition of the SAI

i.MX8M Mini device tree
[...]

sai2: sai@30020000 {
	#sound-dai-cells = <0>;
	compatible = "fsl,imx8mm-sai", "fsl,imx8mq-sai";
	reg = <0x30020000 0x10000>;
	interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&clk IMX8MM_CLK_SAI2_IPG>, <&clk IMX8MM_CLK_DUMMY>,
		<&clk IMX8MM_CLK_SAI2_ROOT>,
		<&clk IMX8MM_CLK_DUMMY>, <&clk IMX8MM_CLK_DUMMY>;
	clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
	dmas = <&sdma2 2 2 0>, <&sdma2 3 2 0>;
	dma-names = "rx", "tx";
	status = "disabled";
};

[...]
ConnectCore 8M Mini Development Kit device tree
[...]

&sai2 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&pinctrl_sai2>;
	pinctrl-1 = <&pinctrl_sai2_sleep>;
	assigned-clocks = <&clk IMX8MM_CLK_SAI2>;
	assigned-clock-parents = <&clk IMX8MM_AUDIO_PLL1_OUT>;
	assigned-clock-rates = <12288000>;
	status = "okay";
};

[...]

/* IOMUX */
&iomuxc {
	[...]

	pinctrl_sai2: sai2grp {
		fsl,pins = <
			MX8MM_IOMUXC_SAI2_RXD0_SAI2_RX_DATA0		0xd6
			MX8MM_IOMUXC_SAI2_TXD0_SAI2_TX_DATA0		0xd6
			MX8MM_IOMUXC_SAI2_TXFS_SAI2_TX_SYNC		0xd6
			MX8MM_IOMUXC_SAI2_TXC_SAI2_TX_BCLK		0xd6
			MX8MM_IOMUXC_SAI2_MCLK_SAI2_MCLK		0xd6
		>;
	};

	pinctrl_sai2_sleep: sai2sleepgrp {
		fsl,pins = <
			MX8MM_IOMUXC_SAI2_RXD0_GPIO4_IO23		0x100
			MX8MM_IOMUXC_SAI2_TXD0_GPIO4_IO26		0x100
			MX8MM_IOMUXC_SAI2_TXFS_GPIO4_IO24		0x100
			MX8MM_IOMUXC_SAI2_TXC_GPIO4_IO25		0x100
			MX8MM_IOMUXC_SAI2_MCLK_GPIO4_IO27		0x100
		>;
	};

	[...]
};

Interface between SAI and audio codec

ConnectCore 8M Mini Development Kit device tree
[...]



sound_max98089: sound-max98089 {
	compatible = "fsl,imx-audio-max98088";
	model = "imx-max98088";
	cpu-dai = <&sai2>;
	audio-codec = <&max98089>;
	audio-routing =
		"Headphone Jack", "HPL",
		"Headphone Jack", "HPR",
		"Ext Spk", "SPKL",
		"Ext Spk", "SPKR",
		"LineOut", "RECL",
		"LineOut", "RECR",
		"Mic1", "MIC1",
		"Mic2", "MIC2",
		"LineInA", "INA1",
		"LineInA", "INA2",
		"LineInB", "INB1",
		"LineInB", "INB2";
	status = "okay";
};

[...]

Audio codec (I2C2 slave)

ConnectCore 8M Mini Development Kit device tree
&i2c2 {
	[...]

	max98089: codec@10 {
		compatible = "maxim,max98089";
		reg = <0x10>;
		clocks = <&clk IMX8MM_CLK_SAI2_ROOT>;
		clock-names = "mclk";
		vcc-supply = <&reg_3v3_audio>;
		dvdd-supply = <&reg_1v8_ext>;
	};

	[...]
};

Using the audio interface

Audio controls

The audio codec is controlled from Linux via the ALSA framework. Digi Embedded Yocto provides an initial configuration that enables:

  • Line in A

  • Line in B

  • Microphone

  • Headphones

  • Speakers

  • Line out

You can use the command line application alsamixer to manage these interfaces and their associated controls such as volume, gain, and filters.

Audio playback

Since all output routes are enabled by default, any sound will play on headphones, speakers, and line-out.

To play a wav file:

# aplay sound.wav

To play an mp3 file using gstreamer:

# gst-launch-1.0 filesrc location=sound.mp3 ! id3demux ! queue ! beepdec ! alsasink

Audio recording

Since microphone, line-in A, and line-in B input routes are enabled by default, any recorded sound will mix the audio coming from these inputs.

To record a stereo WAV audio file with 10 seconds duration from line-in:

# arecord -f cd sound.wav --duration 10

To record a mono WAV audio file from the microphone:

# arecord --format=S16_LE --channels=1 --rate=44100 micro.wav --duration=10