This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM625: with rt5640 (alc5640) codec tinyplay question

Part Number: AM625
Other Parts Discussed in Thread: TLV320AIC3106

Hi 

excuse me, 

want to ask AM625 with rt5640 codec tinyplay question as below information

OS:android 12

kernel: 5.10.153 (08.05)

driver was integrated successfully (codec driver & machine driver), when I use 'tinyplay' test a wav file

as below part of log (Error playing sample), we modified davinci-mcasp.c or machine driver clock, but it no work. (no sound)

is it possible modify BIT clock from SOC side to 2.822 Mhz (I want to try it matches codec or not)

because, from the attachment file waveform (blue wave), soc BIT clock about 1.4Mhz

or what else cay try

thx

console:/ # tinyplay /data/16bit441k-15s.wav
[ 1210.734785] imx-rt5640.c imx_aif1_hw_params in.....params_rate(params) is 44100
[ 1210.742175] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
[ 1210.747481] davinci-mcasp.c SND_SOC_DAIFMT_CBS_CFS...
[ 1210.752531] rt5640.c rt5640_set_dai_fmt...
[ 1210.756633] rt5640.c rt5640_set_dai_pll...
[ 1210.760722] rt5640.c rt5640_set_dai_pll...1
[ 1210.766195] rt5640.c rt5640_set_dai_sysclk
[ 1210.766625] imx-rt5640.c imx_aif1_hw_params end
[ 1210.775275] rt5640.c rt5640_hw_params....
[ 1210.779281] soc-utils.c snd_soc_params_to_frame_size.... sample_size is 16
[ 1210.786142] soc-utils.c ready into snd_soc_calc_frame_size
[ 1210.791619] soc-utils.c snd_soc_calc_frame_size.... sample_size is 16, channels is 2, tdm_slots is 1
[ 1210.800734] bclk is 1411200Hz and lrck is 44100Hz
[ 1210.805431] bclk_ms is 0 and pre_div is 1 for iis 0
[ 1210.810306] davinci-mcasp.c channels is 2
[ 1210.814310] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
[ 1210.819615] davinci-mcasp.c SND_SOC_DAIFMT_CBS_CFS...
[ 1210.824661] davinci-mcasp.c mcasp->bclk_master is 1, mcasp->bclk_div is 0, mcasp->sysclk_freq is 0
[ 1210.833604] davinci-mcasp.c slots is 4, rate is 44100, sbits is 16
[ 1210.839772] davinci-mcasp.c ready into davinci_mcasp_calc_clk_div...
[ 1210.839772]
[ 1210.847618] bclk_freq is 2822400
[ 1210.850860] davinci-mcasp 2b00000.mcasp: Sample-rate is off by -1000000 PPM
Playing sample: 2 ch, 44100 hz, 16 bit 2646000 bytes
aaaaaa........
cccccc........
Error playing sample

  • Hi TI

    update my trace code, in order to match rt5640 clock requirement, then I compare EVM log

    I modified the machine driver let davinci-mcasp.c line 1243,  mcasp->sysclk_freq is 96000000

    It already produces MCLK is 24.576Mhz, BCLK is 3.072Mhz, lrclk is 48Khz

    but tinyplay still get Error playing sample, did any advice

    thx

    4137.davinci-mcasp.c

    console:/ # tinyplay /data/16bit48k.wav
    [ 64.210130] imx-rt5640.c imx_aif1_hw_params in.....params_rate(params) is 48000
    [ 64.217697] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [ 64.223094] davinci-mcasp.c SND_SOC_DAIFMT_CBS_CFS...
    [ 64.228222] rt5640.c rt5640_set_dai_fmt...SND_SOC_DAIFMT_CBM_CFM
    [ 64.234937] davinci-mcasp.c davinci_mcasp_set_sysclk......
    [ 64.240535] davinci-mcasp.c MCASP_CLK_HCLK_AHCLK....
    [ 64.245551] davinci-mcasp.c davinci_mcasp_set_sysclk....freq is 96000000
    [ 64.252294] rt5640.c rt5640_set_dai_pll...
    [ 64.256458] rt5640.c rt5640_set_dai_pll...1
    [ 64.261571] rt5640.c rt5640_set_dai_sysclk
    [ 64.262434] rt5640.c Sysclk is 24576000Hz and clock id is 1
    [ 64.272121] imx-rt5640.c imx_aif1_hw_params end
    [ 64.276658] rt5640.c rt5640_hw_params....
    [ 64.280667] soc-utils.c snd_soc_params_to_frame_size.... sample_size is 16
    [ 64.287571] soc-utils.c ready into snd_soc_calc_frame_size
    [ 64.293074] soc-utils.c snd_soc_calc_frame_size.... sample_size is 16, channels is 2, tdm_slots is 2
    [ 64.302203] bclk is 3072000Hz and lrck is 48000Hz
    [ 64.306907] bclk_ms is 1 and pre_div is 1 for iis 0
    [ 64.312248] davinci-mcasp.c channels is 2
    [ 64.316263] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [ 64.321570] davinci-mcasp.c SND_SOC_DAIFMT_CBS_CFS...
    [ 64.326636] davinci-mcasp.c mcasp->bclk_master is 1, mcasp->bclk_div is 0, mcasp->sysclk_freq is 96000000
    [ 64.336193] davinci-mcasp.c slots is 4, rate is 48000, sbits is 16
    [ 64.342370] davinci-mcasp.c ready into davinci_mcasp_calc_clk_div...
    [ 64.342370]
    [ 64.350192] bclk_freq is 3072000, div is 31, reg is 1572864
    [ 64.355879] davinci-mcasp 2b00000.mcasp: Sample-rate is off by 8064 PPM
    Playing sample: 2 ch, 48000 hz, 16 bit 23040000 bytes
    aaaaaa........
    [ 64.381826] pcm_native.c snd_pcm_xferi_frames_ioctl.....
    [ 64.388519] pcm_lib.c __snd_pcm_lib_xfer....
    [ 64.392801] pcm_lib.c __snd_pcm_lib_xfer....1
    [ 64.397206] pcm_lib.c __snd_pcm_lib_xfer....2
    [ 64.401564] pcm_lib.c __snd_pcm_lib_xfer....3
    [ 64.405911] pcm_lib.c __snd_pcm_lib_xfer....5
    [ 64.410366] pcm_native.c snd_pcm_xferi_frames_ioctl snd_pcm_lib_write result is 4096
    [ 64.418102] pcm_native.c snd_pcm_xferi_frames_ioctl result is 4096.....
    [ 64.424844] pcm_native.c snd_pcm_xferi_frames_ioctl.....
    [ 64.430196] pcm_lib.c __snd_pcm_lib_xfer....
    [ 64.434491] pcm_lib.c __snd_pcm_lib_xfer....1
    [ 64.438919] pcm_lib.c __snd_pcm_lib_xfer....2
    [ 64.443327] pcm_lib.c __snd_pcm_lib_xfer....3
    [ 64.447680] pcm_lib.c __snd_pcm_lib_xfer....5
    [ 64.452035] pcm_lib.c __snd_pcm_lib_xfer....4
    [ 74.462398] pcm_native.c snd_pcm_xferi_frames_ioctl snd_pcm_lib_write result is 96
    [ 74.470007] pcm_native.c snd_pcm_xferi_frames_ioctl result is 96.....
    [ 74.477017] pcm_native.c snd_pcm_xferi_frames_ioctl.....
    [ 74.482354] pcm_lib.c __snd_pcm_lib_xfer....
    [ 74.486623] pcm_lib.c __snd_pcm_lib_xfer....1
    [ 74.490973] pcm_lib.c __snd_pcm_lib_xfer....2
    [ 74.495343] pcm_lib.c __snd_pcm_lib_xfer....3
    [ 74.499687] pcm_lib.c __snd_pcm_lib_xfer....4
    [ 77.558213] AidlLazyServiceRegistrar: Trying to shut down the service. No clients in use for any service in process.
    [ 77.569803] AidlLazyServiceRegistrar: Unregistered all clients and exiting
    [ 77.582553] init: Service 'apexd' (pid 284) exited with status 0 oneshot service took 61.818001 seconds in background
    [ 77.593233] init: Sending signal 9 to service 'apexd' (pid 284) process group...
    [ 77.601160] libprocessgroup: Successfully killed process cgroup uid 0 pid 284 in 0ms
    [ 84.702391] pcm_native.c snd_pcm_xferi_frames_ioctl snd_pcm_lib_write result is -5
    [ 84.709978] pcm_native.c snd_pcm_xferi_frames_ioctl result is -5.....
    cccccc........
    Error playing sample
    [ 85.726384] ti-udma 485c0100.dma-controller: chan1 teardown timeout!
    console:/ #

  • Hi Victor,

    From the logs that you have shared, I understand McASP is slave and RT5640 is codec master, correct?

    On AM62x McASP is slave and tlv320aic3106 is the master.

    DTS file with this configuration as a reference can be found in the below link:

    https://git.ti.com/cgit/ti-linux-kernel/ti-linux-kernel/tree/arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi?h=ti-rt-linux-5.10.y

    As you would see in this file,
    clock-frequency = <12288000> which is the MCLK from codec
    Hope this helps. Please don't hesitate to contact for further assistance.

    Best Regards
    Suren

  • Hi Suren Porwar

    thx your information, yes, in my case, RT5640 is codec master, and we check TI AM625 tlv320aic3106 is master too

    do you know , if our rt5640 use 24.576Mhz MCLK as photo, mcasp side is supported or not (mcasp is slave) ? or need to modify some code

    this is part of the schematics of our codec 

    because tinyplay still have problem

    tinyplay /data/16bit48k.wav                                                    

    [  328.225517] soc-dai.c snd_soc_dai_startup...

    [  328.229831] soc-dai.c soc_dai_ret...ret is 0

    [  328.234095] soc-dai.c snd_soc_dai_startup...

    [  328.238360] soc-dai.c soc_dai_ret...ret is 0

    [  328.243516] soc-dai.c snd_soc_dai_startup...

    [  328.247824] soc-dai.c soc_dai_ret...ret is 0

    [  328.252091] soc-dai.c snd_soc_dai_startup...

    [  328.256354] soc-dai.c soc_dai_ret...ret is 0

    [  328.260695] imx-rt5640.c imx_aif1_hw_params in.....params_rate(params) is 48000

    [  328.267995] soc-dai.c snd_soc_dai_set_fmt...

    [  328.272258] davinci-mcasp.c davinci_mcasp_set_dai_fmt...

    [  328.277562] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...

    [  328.282609] soc-dai.c dai->driver->ops->set_fmt...ret is 0

    [  328.288083] soc-dai.c soc_dai_ret...ret is 0

    [  328.292344] soc-dai.c snd_soc_dai_set_fmt...

    [  328.296608] rt5640.c rt5640_set_dai_fmt...fmt is 4101

    [  328.301651] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_MASTER_MASK is 4096

    [  328.309206] rt5640.c rt5640_set_dai_fmt...SND_SOC_DAIFMT_CBM_CFM

    [  328.315204] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_INV_MASK is 0

    [  328.322240] rt5640.c SND_SOC_DAIFMT_NB_NF

    [  328.326243] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_FORMAT_MASK is 5

    [  328.333537] rt5640.c SND_SOC_DAIFMT_DSP_B

    [  328.337549] rt5640.c rt5640_set_dai_fmt...3 dai_sel is 1

    [  328.342855] rt5640.c rt5640_set_dai_fmt...4

    [  328.347033] rt5640.c rt5640_set_dai_fmt...5

    [  328.351212] soc-dai.c dai->driver->ops->set_fmt...ret is 0

    [  328.356695] soc-dai.c soc_dai_ret...ret is 0

    [  328.360964] soc-dai.c snd_soc_dai_set_sysclk...

    [  328.365488] davinci-mcasp.c davinci_mcasp_set_sysclk......

    [  328.370964] davinci-mcasp.c MCASP_CLK_HCLK_AHCLK....

    [  328.375920] davinci-mcasp.c davinci_mcasp_set_sysclk....freq is 96000000

    [  328.382664] soc-dai.c soc_dai_ret...ret is 0

    [  328.386979] soc-dai.c snd_soc_dai_set_pll...

    [  328.391274] rt5640.c rt5640_set_dai_pll...

    [  328.395407] soc-dai.c soc_dai_ret...ret is 0

    [  328.399676] soc-dai.c snd_soc_dai_set_sysclk...

    [  328.404200] rt5640.c rt5640_set_dai_sysclk...

    [  328.408550] soc-dai.c soc_dai_ret...ret is 0

    [  328.412811] imx-rt5640.c imx_aif1_hw_params end

    [  328.417335] soc-dai.c snd_soc_dai_hw_params...

    [  328.421773] rt5640.c rt5640_hw_params....

    [  328.425776] soc-utils.c snd_soc_params_to_frame_size.... sample_size is 16

    [  328.432639] soc-utils.c ready into snd_soc_calc_frame_size

    [  328.438115] soc-utils.c snd_soc_calc_frame_size.... sample_size is 16, channels is 2, tdm_slots is 1

    [  328.447232] bclk is 1536000Hz and lrck is 48000Hz

    [  328.451928] bclk_ms is 0 and pre_div is 1 for iis 0

    [  328.456807] soc-dai.c soc_dai_ret...ret is 0

    [  328.461074] soc-dai.c snd_soc_dai_hw_params...

    [  328.465512] davinci-mcasp.c channels is 2

    [  328.469514] davinci-mcasp.c davinci_mcasp_set_dai_fmt...

    [  328.474818] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...

    [  328.479864] davinci-mcasp.c mcasp->bclk_master is 0, mcasp->bclk_div is 0, mcasp->sysclk_freq is 96000000 --> I compare the TI AM625, get need to set 96Mhz, is it to be modified in my case?

    [  328.489432] soc-dai.c soc_dai_ret...ret is 0

    Playing sample: 2 ch, 48000 hz, 16 bit 23040000 bytes

    [  328.494844] soc-dai.c snd_soc_pcm_dai_prepare...

    [  328.503668] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_STANDBY...

    [  328.526689] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_PREPARE...

    [  328.535076] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_ON...

    [  328.541263] soc-dai.c snd_soc_dai_digital_mute...

    [  328.545966] soc-dai.c soc_dai_ret...ret is -524

    [  328.550489] soc-dai.c snd_soc_dai_digital_mute...

    [  328.555186] soc-dai.c soc_dai_ret...ret is -524

    aaaaaa........[  328.559851] soc-dai.c snd_soc_pcm_dai_trigger...

     cccccc........[  348.893254] soc-dai.c snd_soc_pcm_dai_trigger...

     Error playing sample

    [  348.899056] soc-dai.c snd_soc_dai_digital_mute...

    [  348.905800] soc-dai.c soc_dai_ret...ret is -524

    [  348.910323] soc-dai.c snd_soc_dai_digital_mute...

    [  348.915018] soc-dai.c soc_dai_ret...ret is -524

    [  349.949081] ti-udma 485c0100.dma-controller: chan1 teardown timeout!

    console:/sys/class/i2c-dev/i2c-2/device/2-001c #

  • Hi Victor,

    Can you share the changes you have made and DTS file with your changes to understand the issue?

    Thanks

    Best Regards

    Suren

  • Hi Suren Porwar

    OK, As an attachment file (I am not sure file is upload or not, file name -> k3-am62x-sk-common-ms5t04)

    I also put part of dts code in below, and machine driver I changed, because previous project used, if any information, reply me

    thx

    #if 1 //====>audio test rt5640
    	codec_audio: sound {
    		compatible = "fsl,imx-audio-rt5640";
    		model = "rt5640-audio";
    		audio-routing =
    			"Headphone Jack", "HPOL",
    			"Headphone Jack", "HPOR",
    			"Ext Spk", "SPOLP",
    			"Ext Spk", "SPOLN",
    			"Ext Spk", "SPORP",
    			"Ext Spk", "SPORN",
    			"DMIC","IN1P";
    
    		cpu-dai = <&mcasp0>;
    		audio-codec = <&rt5640>;
    		clocks = <&ext_rt5640_mclk>;
    
    	};
    	
    #endif //====>audio test rt5640
    
    
    #if 1 //====>audio test
    &mcasp0 {
    	status = "okay";
    	#sound-dai-cells = <0>;
    
    	pinctrl-names = "default";
    	pinctrl-0 = <&main_mcasp0_pins_default>;
    	op-mode = <0>;          /* MCASP_IIS_MODE */
    	tdm-slots = <4>;
    	auxclk-fs-ratio = <0>;
    
    	serial-dir = <  /* 0: INACTIVE, 1: TX, 2: RX */
    	       1 0 2 0
    	       0 0 0 0
    	       0 0 0 0
    	       0 0 0 0
    	>;
    	tx-num-evt = <32>;
    	rx-num-evt = <32>;
    
    };
    #endif //<====audio test
    
    #if 1 //====>audio test
    	main_mcasp0_pins_default: main-mcasp0-pins-default {
    		pinctrl-single,pins = <
    			AM62X_IOPAD(0x00a4, PIN_INPUT, 0) /* (B20) MCASP0_ACLKX bitclk*/
    			AM62X_IOPAD(0x00a8, PIN_INPUT, 0) /* (D20) MCASP0_AFSX lrclk*/
    			AM62X_IOPAD(0x00a0, PIN_OUTPUT, 2) /* (L25) MCASP0_AXR0  serial data in/out*/
    			AM62X_IOPAD(0x0098, PIN_INPUT, 0) /* (A19) MCASP0_AXR2  serial data in/out*/
    		>;
    	};
    #endif //<===audio test
    
    #if 1 //audio test rt5640
    	rt5640: audio-codec@1c {
    		#sound-dai-cells = <0>;
    		compatible = "realtek,rt5640";
    		reg = <0x1c>;
    		status = "okay";
    
    		
    		/* Regulators //may be not used in rt5640
    		AVDD-supply = <&vcc_3v3_sys>;
    		IOVDD-supply = <&vcc_3v3_sys>;
    		DRVDD-supply = <&vcc_3v3_sys>;
    		DVDD-supply = <&vcc_1v8>;
    		*/
    	};
    #endif 
    
    #if 1 //====>audio test rt5640
    	ext_rt5640_mclk: clk-0 {
    		#clock-cells = <0>;
    		compatible = "fixed-clock";
    		clock-frequency = <24576000>;
    	};
    #endif //====>audio test rt5640
    
     

  • Hi Victor,

    I see you are using tdm_slots =<4>

    In the case of I2S, there are two slots per frame. Each slot consists of 32 bits. Even if the data payload is only 16 bits or 24 bits, it is encapsulated within a 32-bit word. Based on this logic: 2 slots * 32 bits per slot * 48 kHz = 3.072 MHz bit clock should be BCLK.

    Your log shows 1536000 as BCLK. 

    Please refer this below document on designing a system with McASP.

    https://www.ti.com/lit/an/sprack0/sprack0.pdf

    Hope this helps in your debugging.

    Best Regards

    Suren

  • Hi Suren Porwar

    thx, actually I try 2 and 4 before, now I modified tdm_slots =<2>

    and thx for the pdf, I read page 12 like our schematics, look like below soc & codec side

    one of strange is when I tinyplay command, no data output from soc (red waveform)

    and this is my mcasp0 interface

    	main_mcasp0_pins_default: main-mcasp0-pins-default {
    		pinctrl-single,pins = <
    			AM62X_IOPAD(0x00a4, PIN_INPUT, 0) /* (B20) MCASP0_ACLKX bitclk*/
    			AM62X_IOPAD(0x00a8, PIN_INPUT, 0) /* (D20) MCASP0_AFSX lrclk*/
    			AM62X_IOPAD(0x00a0, PIN_OUTPUT, 0) /* (E18) MCASP0_AXR0 serial data out*/
    			AM62X_IOPAD(0x0098, PIN_INPUT, 0) /* (A19) MCASP0_AXR2 serial data in*/
    		>;
    	};

    is there any need to be modifed or I missed

    //soc side

    //codec side

  • Hi Victor,

    Have you verified your changes by running our Linux SDK instead of Android?

    You could run aplay command to play a wav file.

    Also, do you know why BCLK is 1536000 from the codec? Shouldn't this be double

    Let me know how it goes.

    Best Regards

    Suren

  • Hi Suren Porwar

    Have you verified your changes by running our Linux SDK instead of Android? You could run aplay command to play a wav file.

    --> I will evaluate the Linux SDK to try, if available, i will show you result (build linux , and implement rt5640, then play), now let focus on Android first.

    Also, do you know why BCLK is 1536000 from the codec? Shouldn't this be double

    --> OK, let me describe it

    first, rt5640 have part of code like below decide bit clock, I try frame_size = 32 or 64, but no work

    and codec vendor tell me, MCLK = 24.576Mhz (external osc), and will divided 2 to match requirements (I am still cowork with them)

     

    \ti-kernel-aosp\common\sound\soc\codecs\rt5640.c
    static int rt5640_hw_params(struct snd_pcm_substream *substream,
            struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
    {
            
            ...
            
            frame_size = snd_soc_params_to_frame_size(params);    //////// ---> I trace here, frame_size will decide rt5640 bit clock, it call below soc-utils.c
            if (frame_size < 0) {
                    dev_err(component->dev, "Unsupported frame size: %d\n", frame_size);
                    return frame_size;
            }
            if (frame_size > 32)
                    bclk_ms = 1;
            else
                    bclk_ms = 0;
            rt5640->bclk[dai->id] = rt5640->lrck[dai->id] * (32 << bclk_ms);	//////// ---> rt5640 bit clock (48000*32 or 48000*64)
     
            printk("bclk is %dHz and lrck is %dHz\n", rt5640->bclk[dai->id], rt5640->lrck[dai->id]);
            printk("bclk_ms is %d and pre_div is %d for iis %d\n",bclk_ms, pre_div, dai->id);
    }
    
    
    \ti-kernel-aosp\common\sound\soc\soc-utils.c              
    int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
    {
            return sample_size * channels * tdm_slots;  ////-----> here will get 16*2*1 or 16*2*2 = 32 or 64
    }
    
     
    int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params)
    {
            int sample_size;
     
            sample_size = snd_pcm_format_width(params_format(params));
            if (sample_size < 0)
                    return sample_size;
     
            return snd_soc_calc_frame_size(sample_size, params_channels(params),1);  ////----> will call here, sample_size is 16, params_channels is 2, last parameter I try 1 or 2
    }

    //tinyplay log ====> I try to bit clock frame_size to 64 let rt5640 bit clock is 3072000Hz , no work
    
    
    
    console:/ # tinyplay /data/16bit48k.wav
    [   99.880488] soc-dai.c snd_soc_dai_startup...
    [   99.884808] soc-dai.c soc_dai_ret...ret is 0
    [   99.889128] soc-dai.c snd_soc_dai_startup...
    [   99.893392] soc-dai.c soc_dai_ret...ret is 0
    [   99.898617] soc-dai.c snd_soc_dai_startup...
    [   99.902950] soc-dai.c soc_dai_ret...ret is 0
    [   99.907216] soc-dai.c snd_soc_dai_startup...
    [   99.911480] soc-dai.c soc_dai_ret...ret is 0
    [   99.915835] imx-rt5640.c imx_aif1_hw_params in.....params_rate(params) is 48000
    [   99.923134] soc-dai.c snd_soc_dai_set_fmt...
    [   99.927399] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [   99.932702] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...
    [   99.937748] soc-dai.c dai->driver->ops->set_fmt...ret is 0
    [   99.943222] soc-dai.c soc_dai_ret...ret is 0
    [   99.947482] soc-dai.c snd_soc_dai_set_fmt...
    [   99.951746] rt5640.c rt5640_set_dai_fmt...fmt is 4101
    [   99.956787] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_MASTER_MASK is 4096
    [   99.964341] rt5640.c rt5640_set_dai_fmt...SND_SOC_DAIFMT_CBM_CFM
    [   99.970337] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_INV_MASK is 0
    [   99.977372] rt5640.c SND_SOC_DAIFMT_NB_NF
    [   99.981374] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_FORMAT_MASK is 5
    [   99.988669] rt5640.c SND_SOC_DAIFMT_DSP_B
    [   99.992686] rt5640.c rt5640_set_dai_fmt...3 dai_sel is 1
    [   99.997989] rt5640.c rt5640_set_dai_fmt...4
    [  100.002167] rt5640.c rt5640_set_dai_fmt...5
    [  100.006392] soc-dai.c dai->driver->ops->set_fmt...ret is 0
    [  100.011876] soc-dai.c soc_dai_ret...ret is 0
    [  100.016148] soc-dai.c snd_soc_dai_set_sysclk...
    [  100.020672] davinci-mcasp.c davinci_mcasp_set_sysclk......
    [  100.026147] davinci-mcasp.c MCASP_CLK_HCLK_AHCLK....
    [  100.031105] davinci-mcasp.c davinci_mcasp_set_sysclk....freq is 24576000
    [  100.037795] soc-dai.c soc_dai_ret...ret is 0
    [  100.042059] soc-dai.c snd_soc_dai_set_pll...
    [  100.046322] rt5640.c rt5640_set_dai_pll...
    [  100.050412] soc-dai.c soc_dai_ret...ret is 0
    [  100.054674] soc-dai.c snd_soc_dai_set_sysclk...
    [  100.059197] rt5640.c rt5640_set_dai_sysclk...
    [  100.063545] soc-dai.c soc_dai_ret...ret is 0
    [  100.067812] imx-rt5640.c imx_aif1_hw_params end
    [  100.072507] soc-dai.c snd_soc_dai_hw_params...
    [  100.077107] rt5640.c rt5640_hw_params....
    [  100.081118] soc-utils.c snd_soc_params_to_frame_size.... sample_size is 16
    [  100.087981] soc-utils.c ready into snd_soc_calc_frame_size
    [  100.093459] soc-utils.c snd_soc_calc_frame_size.... sample_size is 16, channels is 2, tdm_slots is 2
    [  100.102576] bclk is 3072000Hz and lrck is 48000Hz
    [  100.107273] bclk_ms is 1 and pre_div is 1 for iis 0
    [  100.112153] soc-dai.c soc_dai_ret...ret is 0
    [  100.116429] soc-dai.c snd_soc_dai_hw_params...
    [  100.120867] davinci-mcasp.c channels is 2
    [  100.124871] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [  100.130175] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...
    [  100.135221] davinci-mcasp.c mcasp->bclk_master is 0, mcasp->bclk_div is 0, mcasp->sysclk_freq is 24576000
    [  100.144788] soc-dai.c soc_dai_ret...ret is 0
    Playing sample: 2 ch, 48000 hz, 16 bit 23040000 bytes[  100.149600] soc-dai.c snd_soc_pcm_dai_prepare...
    
    [  100.158927] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_STANDBY...
    [  100.181937] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_PREPARE...
    [  100.190317] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_ON...
    [  100.196505] soc-dai.c snd_soc_dai_digital_mute...
    [  100.201205] soc-dai.c soc_dai_ret...ret is -524
    [  100.205729] soc-dai.c snd_soc_dai_digital_mute...
    [  100.210426] soc-dai.c soc_dai_ret...ret is -524
    aaaaaa........[  100.215075] soc-dai.c snd_soc_pcm_dai_trigger...
    
    [  100.220902] pcm_lib.c wait_for_avail...
    cccccc........
    [  110.307450] pcm_lib.c wait_for_avail...
    dddddd........[  120.547579] soc-dai.c snd_soc_pcm_dai_trigger...
    
    Error playing sample

    second, I have another thinking, because I already try some modified code still can not playing successfully,

    therefore, I am not sure, if I change MCLK to 12.288Mhz same with TI-AM625, it works or not (just evaluate....)

     

  • Hi Victor,

    I found this commit on latest kernel:

    https://github.com/torvalds/linux/commit/9f138bb2eaf661788df459dfcaf38feb080af41f

    See if this helps.

    Best Regards

    Suren

  • Hi Victor,

    I found this commit on latest kernel:

    https://github.com/torvalds/linux/commit/9f138bb2eaf661788df459dfcaf38feb080af41f

    See if this helps.

    Best Regards

    Suren

  • Hi Suren Porwar

    I see the patch and refer to our board

    the use case maybe not same, maybe not useful, but thx

    //part of machine driver rt5640
    
    static int imx_aif1_hw_params(struct snd_pcm_substream *substream,
    			     struct snd_pcm_hw_params *params)
    {
    ...
    ...
    ...
    
    	fmt = 0x5 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM;
    	
    	//set cpu DAI configuration
    	ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), fmt);
    	if (ret) {
    		printk("failed to set cpu dai fmt: %d\n");
    		return ret;
    	}
    	
    	//set codec DAI configuration 
    	ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0), fmt);
    	if (ret) {
    		printk("failed to set codec dai fmt: %d\n");
    		return ret;
    	}
    	
    	//ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,  SND_SOC_CLOCK_OUT);  
    	ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, 24576000, SND_SOC_CLOCK_IN);
    	if (ret < 0) {
    		printk("Can't set cpu clock %d\n");
    		return ret;
    	}
    	
    	ret = snd_soc_dai_set_pll(asoc_rtd_to_codec(rtd, 0), 0, RT5640_PLL1_S_MCLK,
    			24576000, params_rate(params)*512); // source 0: RT5660_PLL1_S_MCLK
    	if (ret < 0) {
    		pr_info("set pll failed\n");
    		return ret;
    	}
    	//ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,  SND_SOC_CLOCK_IN);
    	ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), RT5640_SCLK_S_PLL1, params_rate(params)*512, 0);  //// ===> here set rt5640.c use RT5640_SCLK_S_PLL1 case
    	if (ret < 0) {
    		printk("Can't set codec clock %d\n");
    		return ret;
    	}
    	printk("imx-rt5640.c imx_aif1_hw_params end\n");	
    	return ret;
    }

    //part of rt5640.c 
    
    static int rt5640_set_dai_sysclk(struct snd_soc_dai *dai,
    		int clk_id, unsigned int freq, int dir)
    {
    
    ...
    ...
    	printk("rt5640.c rt5640_set_dai_sysclk...\n");
    	if (freq == rt5640->sysclk && clk_id == rt5640->sysclk_src)
    		return 0;
    
    	switch (clk_id) {
    	case RT5640_SCLK_S_MCLK:
    		printk("rt5640.c rt5640_set_dai_sysclk RT5640_SCLK_S_MCLK...\n");
    		reg_val |= RT5640_SCLK_SRC_MCLK;
    		break;
    	case RT5640_SCLK_S_PLL1:
    		printk("rt5640.c rt5640_set_dai_sysclk RT5640_SCLK_S_PLL1...\n"); /// now we use this case
    		reg_val |= RT5640_SCLK_SRC_PLL1;
    		pll_bit |= RT5640_PWR_PLL;
    		break;
    ...
    ...
    
    	printk("rt5640.c Sysclk is %dHz and clock id is %d\n", freq, clk_id);
    	return 0;
    }

    on the other hands, I trace the tinyplay error below

    part of ti-aosp\external\tinyalsa\pcm.c
    
    if (!pcm->running) {
    ...
    ...
    ...
    fprintf(stderr,"aaaaaa........\n");
    if (pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)){ ///// ===> the ioctl SNDRV_PCM_IOCTL_WRITEI_FRAMES is successfully.
    fprintf(stderr,"bbbbbb........\n");
    return oops(pcm, errno, "cannot write initial data");
    }
    fprintf(stderr,"cccccc........\n");
    pcm->running = 1;
    return 0;
    }
    if (pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) { ////===> here is the same ioctl, write pcm data, meet IO error
    fprintf(stderr,"dddddd........\n");
    pcm->prepared = 0;
    pcm->running = 0;
    if (errno == EPIPE) {
    fprintf(stderr,"eeeeee.......\n");
    /* we failed to make our window -- try to restart if we are
    * allowed to do so. Otherwise, simply allow the EPIPE error to
    * propagate up to the app level */
    pcm->underruns++;
    if (pcm->flags & PCM_NORESTART){
    fprintf(stderr,"ffffff........\n");
    return -EPIPE;
    }
    continue;
    }
    return oops(pcm, errno, "cannot write stream data");
    }
     above mention, last will call \ti-kernel-aosp\common\sound\core\pcm_lib.c ,block IO error, seems IRQ timeout, therefore no data pass to codec?

    //part of pcm_lib.c
    if (!tout) {
    pcm_dbg(substream->pcm,
    "%s write error (DMA or IRQ trouble?)\n",
    is_playback ? "playback" : "capture");
    printk("pcm_lib.c write error (DMA or IRQ trouble?)...\n");  ===> error in here
    err = -EIO;
    break;
    }

    //part of log

    console:/ # tinyplay /data/16bit48k.wav
    [ 79.448361] soc-dai.c snd_soc_dai_startup...
    [ 79.452848] soc-dai.c soc_dai_ret...ret is 0
    [ 79.457280] soc-dai.c snd_soc_dai_startup...
    [ 79.463150] soc-dai.c soc_dai_ret...ret is 0
    [ 79.471521] soc-dai.c snd_soc_dai_startup...
    [ 79.476006] soc-dai.c soc_dai_ret...ret is 0
    [ 79.480692] soc-dai.c snd_soc_dai_startup...
    [ 79.485226] soc-dai.c soc_dai_ret...ret is 0
    [ 79.489720] imx-rt5640.c imx_aif1_hw_params in.....params_rate(params) is 48000
    [ 79.498105] soc-dai.c snd_soc_dai_set_fmt...
    [ 79.502693] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [ 79.508135] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...
    [ 79.513270] soc-dai.c dai->driver->ops->set_fmt...ret is 0
    [ 79.519134] soc-dai.c soc_dai_ret...ret is 0
    [ 79.524142] soc-dai.c snd_soc_dai_set_fmt...
    [ 79.528500] rt5640.c rt5640_set_dai_fmt...fmt is 4101
    [ 79.534782] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_MASTER_MASK is 4096
    [ 79.542449] rt5640.c rt5640_set_dai_fmt...SND_SOC_DAIFMT_CBM_CFM
    [ 79.548768] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_INV_MASK is 0
    [ 79.555879] rt5640.c SND_SOC_DAIFMT_NB_NF
    [ 79.559931] rt5640.c rt5640_set_dai_fmt...fmt & SND_SOC_DAIFMT_FORMAT_MASK is 5
    [ 79.567512] rt5640.c SND_SOC_DAIFMT_DSP_B
    [ 79.571619] rt5640.c rt5640_set_dai_fmt...3 dai_sel is 1
    [ 79.576972] rt5640.c rt5640_set_dai_fmt...4
    [ 79.581437] rt5640.c rt5640_set_dai_fmt...5
    [ 79.585734] soc-dai.c dai->driver->ops->set_fmt...ret is 0
    [ 79.591309] soc-dai.c soc_dai_ret...ret is 0
    [ 79.595625] soc-dai.c snd_soc_dai_set_sysclk...
    [ 79.600423] davinci-mcasp.c davinci_mcasp_set_sysclk......
    [ 79.606027] davinci-mcasp.c MCASP_CLK_HCLK_AHCLK....
    [ 79.611074] davinci-mcasp.c davinci_mcasp_set_sysclk....freq is 24576000
    [ 79.618152] soc-dai.c soc_dai_ret...ret is 0
    [ 79.622517] soc-dai.c snd_soc_dai_set_pll...
    [ 79.626836] rt5640.c rt5640_set_dai_pll...
    [ 79.631279] rt5640.c rt5640_set_dai_pll...1
    [ 79.636005] rt5640.c rt5640_set_dai_pll...RT5640_PLL1_S_MCLK
    [ 79.643487] soc-dai.c soc_dai_ret...ret is 0
    [ 79.648058] soc-dai.c snd_soc_dai_set_sysclk...
    [ 79.652842] rt5640.c rt5640_set_dai_sysclk...
    [ 79.657275] rt5640.c rt5640_set_dai_sysclk RT5640_SCLK_S_PLL1...
    [ 79.664509] rt5640.c Sysclk is 24576000Hz and clock id is 1
    [ 79.670227] soc-dai.c soc_dai_ret...ret is 0
    [ 79.674570] imx-rt5640.c imx_aif1_hw_params end
    [ 79.679154] soc-dai.c snd_soc_dai_hw_params...
    [ 79.683858] rt5640.c rt5640_hw_params....
    [ 79.688070] soc-utils.c snd_soc_params_to_frame_size.... sample_size is 16
    [ 79.695034] soc-utils.c ready into snd_soc_calc_frame_size
    [ 79.702042] soc-utils.c snd_soc_calc_frame_size.... sample_size is 16, channels is 2, tdm_slots is 1
    [ 79.711339] bclk is 1536000Hz and lrck is 48000Hz
    [ 79.717315] bclk_ms is 0 and pre_div is 1 for iis 0
    [ 79.722492] soc-dai.c soc_dai_ret...ret is 0
    [ 79.727020] soc-dai.c snd_soc_dai_hw_params...
    [ 79.732452] davinci-mcasp.c channels is 2
    [ 79.736575] davinci-mcasp.c davinci_mcasp_set_dai_fmt...
    [ 79.742005] davinci-mcasp.c SND_SOC_DAIFMT_CBM_CFM...
    [ 79.747502] davinci-mcasp.c mcasp->bclk_master is 0, mcasp->bclk_div is 0, mcasp->sysclk_freq is 24576000
    [ 79.757215] soc-dai.c soc_dai_ret...ret is 0
    Playing sample: 2 ch, 48000 hz, 16 bit 23040000 bytes
    [ 79.763061] soc-dai.c snd_soc_pcm_dai_prepare...
    [ 79.772163] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_STANDBY...
    [ 79.792142] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_PREPARE...
    [ 79.801852] rt5640.c rt5640_set_bias_level case SND_SOC_BIAS_ON...
    [ 79.808242] soc-dai.c snd_soc_dai_digital_mute...
    [ 79.813199] soc-dai.c soc_dai_ret...ret is -524
    [ 79.819123] soc-dai.c snd_soc_dai_digital_mute...
    [ 79.824578] soc-dai.c soc_dai_ret...ret is -524
    aaaaaa........
    [ 79.829392] pcm.h snd_pcm_playback_avail avail is 4096
    [ 79.836304] pcm.h snd_pcm_playback_avail avail is 0
    [ 79.841207] pcm.h snd_pcm_playback_avail avail is 0
    [ 79.846142] soc-dai.c snd_soc_pcm_dai_trigger...
    [ 79.850785] pcm.h snd_pcm_playback_avail avail is 0
    cccccc........
    [ 79.856337] pcm.h snd_pcm_playback_avail avail is 96
    [ 79.862553] pcm.h snd_pcm_playback_avail avail is 96
    [ 79.867992] pcm_lib.c in the wait_for_avail...
    [ 79.872464] pcm_lib.c wait_for_avail snd_pcm_avail...
    [ 79.877521] pcm.h snd_pcm_playback_avail avail is 0
    [ 90.083577] pcm_lib.c wait_for_avail tout is 0...
    [ 90.088309] pcm_lib.c write error (DMA or IRQ trouble?)...
    [ 90.093780] pcm_lib.c err = wait_for_avail(substream, &avail) , err is -5
    [ 90.101120] pcm.h snd_pcm_playback_avail avail is 0
    [ 90.105992] pcm_lib.c in the wait_for_avail...
    [ 90.110424] pcm_lib.c wait_for_avail snd_pcm_avail...
    [ 90.115460] pcm.h snd_pcm_playback_avail avail is 0

    [ 100.323572] pcm_lib.c wait_for_avail tout is 0...
    [ 100.328308] pcm_lib.c write error (DMA or IRQ trouble?)...
    [ 100.333779] pcm_lib.c err = wait_for_avail(substream, &avail) , err is -5
    dddddd........
    [ 100.340756] soc-dai.c snd_soc_pcm_dai_trigger...
    Error playing sample
    [ 100.346707] soc-dai.c snd_soc_dai_digital_mute...
    [ 100.353272] soc-dai.c soc_dai_ret...ret is -524
    [ 100.357795] soc-dai.c snd_soc_dai_digital_mute...
    [ 100.362490] soc-dai.c soc_dai_ret...ret is -524
    [ 101.379575] ti-udma 485c0100.dma-controller: chan1 teardown timeout!

  • Hi Suren Porwar

    Finally, I check soc no data output when play music, the reason is mcasp0 setting got wrong, fix it.

    really thx help