Help Req for MAX98357 on custom carrier board

Hi,

I am trying to get the MAX98357 codec working on a custom carrier board for the verdin imx8mm. the codec is connected to the i2s_1 interface as follows:

The overlay I am trying to use is as follows:

&{/} {
   codec_ext: max98357a@0 {
      compatible = "maxim,max98357a";
      #sound-dai-cells = <0>;
      status = "okay";
   };

   sound {
      compatible = "simple-audio-card";
      status = "okay";
      simple-audio-card,name = "max98357a";

      simple-audio-card,format = "i2s";
      simple-audio-card,bitclock-master = <&dailink_master_cpu>;
      simple-audio-card,frame-master = <&dailink_master_cpu>;

      simple-audio-card,codec {
         sound-dai = <&codec_ext>;
         dai-tdm-slot-num = <2>;
         dai-tdm-slot-width = <16>;
      };

      dailink_master_cpu: simple-audio-card,cpu {
         sound-dai = <&sai2>;
      };
   };
};

but I get errors such as:

torizon@verdin-imx8mm-14756428:~$ dmesg | grep simple-card
[    8.209311] asoc-simple-card sound-card: parse error -22
[    8.214659] asoc-simple-card: probe of sound-card failed with error -22

torizon@verdin-imx8mm-14756428:~$ dmesg | grep sound
[    1.581745]   No soundcards found.
[    8.191661] OF: /sound-card/simple-audio-card,codec: could not find phandle 134
[    8.209311] asoc-simple-card sound-card: parse error -22
[    8.214659] asoc-simple-card: probe of sound-card failed with error -22

torizon@verdin-imx8mm-14756428:~$ dmesg | grep sai
[   37.138267] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.145418] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.153949]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.163563] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.170710] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.179112]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.188039] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.195165] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.203555]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.217864] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.224995] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.233393]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.243354] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.250486] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.258854]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.269695] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.276774] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.285201]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.294706] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.301828] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.310235]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.321191] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.328269] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.336671]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.346028] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.353151] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.361550]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.372110] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.379262] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.387630]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.396901] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.404018] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.412418]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.422003] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.429153] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.437523]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.446927] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.454050] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.462453]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.471925] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.479061] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.487434]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.496864] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.503982] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.512381]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.523288] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.530418] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.538789]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.548168] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.555301] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.563711]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.574438] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.581562] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.589971]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.599375] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.606455] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.614861]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.625667] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.632797] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.641205]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.650649] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.657727] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.666126]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.676657] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.683780] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.692368]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.702706] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.709859] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.718242]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.727832] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.734974] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.743403]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.752736] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.759904] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.768277]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.777608] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.784721] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.793159]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.802464] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.809593] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.817964]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.827289] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.834403] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.842793]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.852092] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.859217] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.867595]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.876932] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.884068] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.892467]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)
[   37.901747] fsl-sai 30020000.sai: failed to derive required Tx rate: 1411200
[   37.908827] fsl-sai 30020000.sai: ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22
[   37.917229]  30020000.sai-HiFi: ASoC: __soc_pcm_hw_params() failed (-22)

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

The errors you’re encountering suggest there are issues with the device tree configuration for your MAX98357 codec on the custom carrier board. Let’s address the potential problems step by step:

  1. Device Tree Node Reference Error: The error OF: /sound-card/simple-audio-card,codec: could not find phandle indicates a problem with referencing the codec in the device tree. Ensure that the phandle (&codec_ext) correctly references the codec node you’ve defined. Double-check the node names and references for typos or misconfigurations.

  2. ASoC Parse Error: The parse error -22 and probe of sound-card failed with error -22 messages suggest that the Simple-Card framework is having trouble parsing your device tree configuration. This could be due to incorrect property names, values, or missing required properties. Ensure that all required properties for simple-audio-card are correctly set. You might be missing some required nodes or properties that are essential for the ASoC (ALSA System on Chip) framework to initialize the sound card properly.

  3. SAI Configuration: The repeated errors related to fsl-sai and ASoC: error at snd_soc_dai_hw_params on 30020000.sai: -22 indicate that there’s an issue with the SAI (Serial Audio Interface) configuration, particularly with the bit clock rate derivation. This could be due to incompatible settings between the codec and the SAI interface regarding sample rate, bit depth, or the I2S format. Ensure that the SAI configuration in the device tree matches the requirements of the MAX98357 codec, including the correct I2S format, bit depth, and any specific clock settings.

  4. Clock Configuration: Ensure that the codec and the SAI interface have the necessary clock sources defined and enabled in the device tree. The MAX98357 requires a specific bit clock and LRCLK (frame clock) configuration that must be compatible with what the SAI interface is configured to provide.

  5. I2S Configuration: The MAX98357 is an I2S device, so ensure that the simple-audio-card,format property is correctly set to "i2s". Also, verify that the dai-tdm-slot-num and dai-tdm-slot-width properties match the codec’s requirements. The MAX98357 typically works with a slot width of 16 or 32 bits, depending on your audio

Please, also check if these links can help you solve your problem:

Audio (Linux) | Toradex Developer Center.

Hello @geopaxpvtltd,

Based on a previous case where a MAX98357a was used with a Verdin iMX8MP, I think you may be missing some configuration on the sai2 node.
Also remember to disable any unused audio codec node.

The following was needed for the Verdin iMX8MP:

&nau8822_1a {
        status = "disabled";
};

/* VERDIN I2S_1 */
&sai1 {
        assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL2_OUT>;
        assigned-clock-rates = <12288000>;
        status = "okay";
};

Some changes will be needed for the Verdin iMX8MM, such as the usage of sai2 instead of sai1, but this may be a good starting point.

Best Regards,
Bruno

Hi @bruno.tx !

I have disabled the nau8822_1a already. but I am unsure what changes are required on the clock rates and parents for the imx8mm specifically and how to calculate these values.

Would you be able to offer any clues?

BR.

Hello @geopaxpvtltd,

Sorry for the delay on this topic.
The clock for a 44.1 kHz sample rate would need to be lower.

Can you try the following device tree overlay and let me know if it works for you?

/dts-v1/;
/plugin/;

#include <dt-bindings/clock/imx8mm-clock.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include "imx8mm-pinfunc.h"

/{
    compatible = "toradex,verdin-imx8mm-wifi-dev",
    	"toradex,verdin-imx8mm-wifi",
    	"toradex,verdin-imx8mm",
    	"fsl,imx8mm";
};

&{/} {
    codec_ext: max98357a {
        compatible = "maxim,max98357a";
        #sound-dai-cells = <0>;
        status = "okay";
        pinctrl-names = "default";
    };

    sound {
        compatible = "simple-audio-card";
        status = "okay";
        simple-audio-card,name = "max98357a";

        simple-audio-card,format = "i2s";
        simple-audio-card,bitclock-master = <&dailink_master_cpu>;
        simple-audio-card,frame-master = <&dailink_master_cpu>;

        simple-audio-card,routing =
            "HiFi Playback", "SD_MODE",
            "SD_MODE", "Speaker";
        
        simple-audio-card,widgets =
            "Speaker", "Speaker";
        
        simple-audio-card,codec {
            sound-dai = <&codec_ext>;
        };

        /*
        simple-audio-card,codec {
            sound-dai = <&codec_ext>;
            dai-tdm-slot-num = <2>;
            dai-tdm-slot-width = <16>;
        };
        */

        dailink_master_cpu: simple-audio-card,cpu {
            sound-dai = <&sai2>;
        };
    };
};

&nau8822_1a {
        status = "disabled";
};

&sai2 {
        assigned-clock-parents = <&clk IMX8MM_AUDIO_PLL2_OUT>;
        assigned-clock-rates = <11289600>;
        status = "okay";
};

I plan to do some more testing later as I have it available here.
It is possible you may actually need the SD_MODE pin to be connected to use this codec, due to the startup procedure present starting on page 17 of the codec’s datasheet.

Best Regards,
Bruno