Post Go back to editing

MAX98390 Linux Driver with Alsa

Category: Software
Product Number: 98390C

Hi,

I am using Max98390C amplifier with speaker in our device having NXP IMX8MP SOM. I am able to play songs using the MAX98390 Development Board. But when I play the audio files in the device using aplay, I am getting the following errors:

[15666.371878] fsl-sai 30c10000.sai: failed to derive required Tx rate: 1411200
[15666.378977] fsl-sai 30c10000.sai: ASoC: error at snd_soc_dai_hw_params on 30c10000.sai: -22
[15666.387360] 30c10000.sai-max98390-aif1: ASoC: error at __soc_pcm_hw_params on 30c10000.sai-max98390-aif1: -22
ALSA lib /usr/src/debug/alsa-lib/1.2.8-r0/src/pcm/pcm_direct.c:1336:(snd1_pcm_direct_initialize_slave) unable to install hw params
ALSA lib /usr/src/debug/alsa-lib/1.2.8-r0/src/pcm/pcm_dmix.c:1011:(snd_pcm_dmix_open) unable to initialize slave
aplay: main:831: audio open error: Invalid argument

speaker-test also outputs the same error.

Below are the dts nodes:

sound {
compatible = "simple-audio-card";
pinctrl-names = "default";
simple-audio-card,name = "max98390-audio-card";
simple-audio-card,format = "i2s";
/*simple-audio-card,widgets = "Speaker", "Speaker";
simple-audio-card,routing = "Speaker", "Speaker";*/
simple-audio-card,bitclock-master = <&cpu_dai>;
simple-audio-card,frame-master = <&cpu_dai>;
/*simple-audio-card,mclk-fs = <256>;*/
status = "okay";

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

&sai1 {
#sound-dai-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sai1>;
assigned-clocks = <&clk IMX8MP_CLK_SAI1>;
assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
assigned-clock-rates = <24576000>;
clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_IPG>, <&clk IMX8MP_CLK_DUMMY>,
<&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_MCLK1>, <&clk IMX8MP_CLK_DUMMY>,
<&clk IMX8MP_CLK_DUMMY>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
/*assigned-clock-rates = <0>, <786432000>, <49152000>, <12288000>, <49152000>;*/
fsl,mode = "i2s-master";
fsl,sai-mclk-direction-output;
status = "okay";
};

&i2c3 {
clock-frequency = <400000>;
pinctrl-names = "default", "gpio";
pinctrl-0 = <&pinctrl_i2c3>;
pinctrl-1 = <&pinctrl_i2c3_gpio>;
scl-gpios = <&gpio5 18 GPIO_ACTIVE_HIGH>;
sda-gpios = <&gpio5 19 GPIO_ACTIVE_HIGH>;
status = "okay";

max98390: amplifier@38 {
#sound-dai-cells = <0>;
compatible = "maxim,max98390";
reg = <0x38>;
maxim,temperature_calib = <1024>;
maxim,r0_calib = <100232>;
reset-gpios = <&gpio4 21 GPIO_ACTIVE_LOW>;
status = "okay";
};

};

pinctrl_sai1: sai1grp {
fsl,pins = <
MX8MP_IOMUXC_SAI1_RXD7__AUDIOMIX_SAI1_TX_SYNC 0xd6
MX8MP_IOMUXC_SAI1_TXC__AUDIOMIX_SAI1_TX_BCLK 0xd6
MX8MP_IOMUXC_SAI1_TXD0__AUDIOMIX_SAI1_TX_DATA00 0xd6
>;
};

Someone please help me to fix this issue?

Thanks

Chris

  • The problem is : failed to derive required Tx rate: 1411200

    and is coming from this line in NXP sai drivers.

    It looks like you're configuring the I2S interface in device-tree for dai-tdm-slot-num = <2>; dai-tdm-slot-width = <16>;

    If the audio file you're trying to play has a sampling rate of 44100 Hz then 2*16*44100 = 1411200 Hz exactly the bit-rate you're requesting to the SAI interface but it is not able to obtain.

    I think it is not able to obtain it because it requires integer division from the 24576000 Hz MCLK rate you're setting in &sai1 node.

    So you either use audio files with 48Khz sample rate and in that case 2*16*48000 = 1536000 * 16 = 24576000 Hz or you set in &sai1 node the MCLK to some multiple of 44100 Hz like 22579200 Hz.

    Regards,

    Bogdan

  • Hi Bogdan,

    Thank you for your reply.

    I changed the assigned-clock-rates = <24576000>;

    &sai1 {
    #sound-dai-cells = <0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_sai1>;
    assigned-clocks = <&clk IMX8MP_CLK_SAI1>;
    assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
    assigned-clock-rates = <24576000>;
    clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_IPG>, <&clk IMX8MP_CLK_DUMMY>,
    <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_MCLK1>, <&clk IMX8MP_CLK_DUMMY>,
    <&clk IMX8MP_CLK_DUMMY>;
    clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
    /*assigned-clock-rates = <0>, <786432000>, <49152000>, <12288000>, <49152000>;*/
    fsl,mode = "i2s-master";
    fsl,sai-mclk-direction-output;
    status = "okay";
    };

    But still, I am having the same issue. But I noticed that there is no soundcard.

    # aplay test.wav
    [ 314.624387] fsl-sai 30c10000.sai: failed to derive required Tx rate: 1411200
    [ 314.631463] fsl-sai 30c10000.sai: ASoC: error at snd_soc_dai_hw_params on 30c10000.sai: -22
    [ 314.639834] 30c10000.sai-max98390-aif1: ASoC: error at __soc_pcm_hw_params on 30c10000.sai-max98390-aif1: -22
    ALSA lib /usr/src/debug/alsa-lib/1.2.8-r0/src/pcm/pcm_direct.c:1336:(snd1_pcm_direct_initialize_slave) unable to install hw params
    ALSA lib /usr/src/debug/alsa-lib/1.2.8-r0/src/pcm/pcm_dmix.c:1011:(snd_pcm_dmix_open) unable to initialize slave
    aplay: main:831: audio open error: Invalid argument

    # dmesg | grep -E "fsl|sound|snd"
    [ 2.807525] No soundcards found.
    [ 314.624387] fsl-sai 30c10000.sai: failed to derive required Tx rate: 1411200
    [ 314.631463] fsl-sai 30c10000.sai: ASoC: error at snd_soc_dai_hw_params on 30c10000.sai: -22

    Thanks

    Chris

  • Hi,

    Take this as reference. Is a limitation of the SAI.

    I was suggesting to replace 
    assigned-clock-rates = <24576000>;
    with
    assigned-clock-rates = <22579200>;

    but I think you may need to use PLL2 for 44.1Khz sampling rates. Better ask on NXP forum for exact solution.

  • Hi Bogdan,

    IMX8MP_AUDIO_PLL2_OUT and 22579200 fixed the issue. I am having sound now. Thank you so much for your help.

    &sai1 {
    #sound-dai-cells = <0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_sai1>;
    assigned-clocks = <&clk IMX8MP_CLK_SAI1>;
    assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL2_OUT>;
    assigned-clock-rates = <22579200>;
    clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_IPG>, <&clk IMX8MP_CLK_DUMMY>,
    <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI1_MCLK1>, <&clk IMX8MP_CLK_DUMMY>,
    <&clk IMX8MP_CLK_DUMMY>;
    clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
    /*assigned-clock-rates = <0>, <786432000>, <49152000>, <12288000>, <49152000>;*/
    fsl,mode = "i2s-master";
    fsl,sai-mclk-direction-output;
    status = "okay";
    };
     

    Thanks

    Chris