DT Support for SPH0645 MIC and MAX98357a in same device tree

Hi all,

I have a SPH0645 I2S mic and a MAX98357a amplifier on my PCB, the mic uses SAI3 and the audio amp uses SAI1. I am using an iMX8MP

First I had the MAX98357a working very well, now for some reason when I tried to add the mic to my device tree it seems to have messed up playback through my amplifier. It has somehow made the MIC the default playback device, I was able to force aplay to use the MAX98357 but then the rate was totally wrong.

My DT looked like this:

/ {
	model = "Toradex Verdin iMX8M Plus WB on Dahlia Board";
	compatible = "toradex,verdin-imx8mp-wifi-dahlia",
		     "toradex,verdin-imx8mp-wifi",
		     "toradex,verdin-imx8mp",
		     "fsl,imx8mp";

	codec_ext: max98357a@0 {
		compatible = "maxim,max98357a";
		#sound-dai-cells = <0>;
		sdmode-gpios = <&gpio3 0 GPIO_ACTIVE_HIGH>;
	};

	sound_ext {
		compatible = "simple-audio-card";
		simple-audio-card,name = "max98357a";
		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&dailink_master1>;
		simple-audio-card,frame-master = <&dailink_master1>;


		dailink_master1: simple-audio-card,cpu {
			sound-dai = <&sai1>;
		    dai-tdm-slot-num = <2>;
		    dai-tdm-slot-width = <16>;
		};

		simple-audio-card,codec {
			sound-dai = <&codec_ext>;
		};


	};

};

Now I added this for the MIC:

/ {
	model = "Toradex Verdin iMX8M Plus WB on Dahlia Board";
	compatible = "toradex,verdin-imx8mp-wifi-dahlia",
		     "toradex,verdin-imx8mp-wifi",
		     "toradex,verdin-imx8mp",
		     "fsl,imx8mp";

	codec_ext: max98357a@0 {
		compatible = "maxim,max98357a";
		#sound-dai-cells = <0>;
		sdmode-gpios = <&gpio3 0 GPIO_ACTIVE_HIGH>;
	};

	sound {
		compatible = "fsl,imx-audio-sph0645",
                     "fsl,imx-mic-sph0645";
		model = "sph0645-audio";
		cpu-dai = <&sai3>;
		status = "okay";
	};

	sound_ext {
		compatible = "simple-audio-card";
		simple-audio-card,name = "max98357a";
		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&dailink_master1>;
		simple-audio-card,frame-master = <&dailink_master1>;


		dailink_master1: simple-audio-card,cpu {
			sound-dai = <&sai1>;
		    dai-tdm-slot-num = <2>;
		    dai-tdm-slot-width = <16>;
		};

		simple-audio-card,codec {
			sound-dai = <&codec_ext>;
		};


	};

};

What have I done wrong? For some reason both appear as playback devices:

root@verdin-imx8mp-07129897:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: imxaudiosph0645 [imx-audio-sph0645], device 0: imx-sph0645 snd-soc-dummy-dai-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: max98357a [max98357a], device 0: 30c10000.sai-HiFi HiFi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Hi @eoin_oc1 !

We didn’t find any driver on the current Linux Kernel from Toradex.

We found it on some old Linux repository (randomly found) https://github.com/alejandrolozano2/linux-imx8mq-8mics, which is not applicable for Toradex modules.

Could you please try using simple-audio-card instead of the driver for this IC?

Best regards,

I found a driver already and managed to make some progress on the other issues.

For some reason I must specify this to be able to playback through the MAX98357 like before:

aplay -D plughw:1 africa-6.wav

No idea why, but otherwise it gets the rate completely wrong, for example if I do this the sample rate is completely wrong:


root@verdin-imx8mp-07129897:~# aplay -D hw:1 africa-6.wav
Playing WAVE 'africa-6.wav' : [  210.208366] fsl-sai 30c10000.sai: Tx rate: 512000 22 11289600 25600
Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Warning: rate is not accurate (requested = 22050Hz, got = 16000Hz)
         please, try the plug plugin

The extra printf here is from a mod I made to the kernel driver.

I can capture something from the MIC but for some reason the sound is horrific, mainly just noise but there is something in there that resembles my voice.

Now my DT looks like this:

	codec_ext: max98357a@0 {
		compatible = "maxim,max98357a";
		#sound-dai-cells = <0>;
		sdmode-gpios = <&gpio3 0 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};
	sph0645_ext: sph0645@1 {
		compatible = "fsl,imx-audio-sph0645","fsl,imx-mic-sph0645";
		model = "sph0645-audio";
		#sound-dai-cells = <1>;
		cpu-dai = <&sai3>;
		status = "okay";
	};



	sound_ext {
		compatible = "simple-audio-card";
		simple-audio-card,name = "max98357a";
		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&dailink_master1>;
		simple-audio-card,frame-master = <&dailink_master1>;


		dailink_master1: simple-audio-card,cpu {
			sound-dai = <&sai1>;
		    dai-tdm-slot-num = <2>;
		    dai-tdm-slot-width = <16>;
		};

		simple-audio-card,codec {
			sound-dai = <&codec_ext>;
		};


	};

        sound_mic {
                compatible = "simple-audio-card";
                simple-audio-card,name = "sph0645";
                simple-audio-card,format = "i2s";
				simple-audio-card,bit-format = "s32_be";
                simple-audio-card,bitclock-master = <&dailink_master2>;
                simple-audio-card,frame-master = <&dailink_master2>;


				dailink_master2: simple-audio-card,cpu {
					sound-dai = <&sai3>;
					dai-tdm-slot-num = <1>;
					dai-tdm-slot-width = <32>;
				};

				simple-audio-card,codec {
					sound-dai = <&sph0645_ext>;

				};


        };

I have been playing with the various dt properties, documentation is extremely poor as to what they do. I also did a capture of the I2S data from the MIC and it is nothing like what appears in the .wav file. All of the number in the .wav file are negative numbers

Hi @eoin_oc1!

Thanks for the feedback!

AFAIK, when you use hw instead of plughw, you are responsible for setting the right properties (e.g. sample rate, “data type”, etc). With plughw, there is an underlying heuristics that does a best attempt to set those properties for you.

Does this happen when you use plughw as well?

If you are having a hard time integrating this external device, we can point a Toradex partner to help you with that. Just let us know :slight_smile:

Best regards,

I have given up on this and tried to outsource it instead, thanks for your ideas

Hi @eoin_oc1 !

Thanks for the feedback.

Please mark your last message as the solution :slight_smile: (as it is kind of a solution :stuck_out_tongue: )

Best regards,