18c2ecf20Sopenharmony_ci============================================== 28c2ecf20Sopenharmony_ciCreating codec to codec dai link for ALSA dapm 38c2ecf20Sopenharmony_ci============================================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciMostly the flow of audio is always from CPU to codec so your system 68c2ecf20Sopenharmony_ciwill look as below: 78c2ecf20Sopenharmony_ci:: 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci --------- --------- 108c2ecf20Sopenharmony_ci | | dai | | 118c2ecf20Sopenharmony_ci CPU -------> codec 128c2ecf20Sopenharmony_ci | | | | 138c2ecf20Sopenharmony_ci --------- --------- 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciIn case your system looks as below: 168c2ecf20Sopenharmony_ci:: 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci --------- 198c2ecf20Sopenharmony_ci | | 208c2ecf20Sopenharmony_ci codec-2 218c2ecf20Sopenharmony_ci | | 228c2ecf20Sopenharmony_ci --------- 238c2ecf20Sopenharmony_ci | 248c2ecf20Sopenharmony_ci dai-2 258c2ecf20Sopenharmony_ci | 268c2ecf20Sopenharmony_ci ---------- --------- 278c2ecf20Sopenharmony_ci | | dai-1 | | 288c2ecf20Sopenharmony_ci CPU -------> codec-1 298c2ecf20Sopenharmony_ci | | | | 308c2ecf20Sopenharmony_ci ---------- --------- 318c2ecf20Sopenharmony_ci | 328c2ecf20Sopenharmony_ci dai-3 338c2ecf20Sopenharmony_ci | 348c2ecf20Sopenharmony_ci --------- 358c2ecf20Sopenharmony_ci | | 368c2ecf20Sopenharmony_ci codec-3 378c2ecf20Sopenharmony_ci | | 388c2ecf20Sopenharmony_ci --------- 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciSuppose codec-2 is a bluetooth chip and codec-3 is connected to 418c2ecf20Sopenharmony_cia speaker and you have a below scenario: 428c2ecf20Sopenharmony_cicodec-2 will receive the audio data and the user wants to play that 438c2ecf20Sopenharmony_ciaudio through codec-3 without involving the CPU.This 448c2ecf20Sopenharmony_ciaforementioned case is the ideal case when codec to codec 458c2ecf20Sopenharmony_ciconnection should be used. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciYour dai_link should appear as below in your machine 488c2ecf20Sopenharmony_cifile: 498c2ecf20Sopenharmony_ci:: 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /* 528c2ecf20Sopenharmony_ci * this pcm stream only supports 24 bit, 2 channel and 538c2ecf20Sopenharmony_ci * 48k sampling rate. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci static const struct snd_soc_pcm_stream dsp_codec_params = { 568c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S24_LE, 578c2ecf20Sopenharmony_ci .rate_min = 48000, 588c2ecf20Sopenharmony_ci .rate_max = 48000, 598c2ecf20Sopenharmony_ci .channels_min = 2, 608c2ecf20Sopenharmony_ci .channels_max = 2, 618c2ecf20Sopenharmony_ci }; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci { 648c2ecf20Sopenharmony_ci .name = "CPU-DSP", 658c2ecf20Sopenharmony_ci .stream_name = "CPU-DSP", 668c2ecf20Sopenharmony_ci .cpu_dai_name = "samsung-i2s.0", 678c2ecf20Sopenharmony_ci .codec_name = "codec-2, 688c2ecf20Sopenharmony_ci .codec_dai_name = "codec-2-dai_name", 698c2ecf20Sopenharmony_ci .platform_name = "samsung-i2s.0", 708c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 718c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_CBM_CFM, 728c2ecf20Sopenharmony_ci .ignore_suspend = 1, 738c2ecf20Sopenharmony_ci .params = &dsp_codec_params, 748c2ecf20Sopenharmony_ci }, 758c2ecf20Sopenharmony_ci { 768c2ecf20Sopenharmony_ci .name = "DSP-CODEC", 778c2ecf20Sopenharmony_ci .stream_name = "DSP-CODEC", 788c2ecf20Sopenharmony_ci .cpu_dai_name = "wm0010-sdi2", 798c2ecf20Sopenharmony_ci .codec_name = "codec-3, 808c2ecf20Sopenharmony_ci .codec_dai_name = "codec-3-dai_name", 818c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 828c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_CBM_CFM, 838c2ecf20Sopenharmony_ci .ignore_suspend = 1, 848c2ecf20Sopenharmony_ci .params = &dsp_codec_params, 858c2ecf20Sopenharmony_ci }, 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciAbove code snippet is motivated from sound/soc/samsung/speyside.c. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciNote the "params" callback which lets the dapm know that this 908c2ecf20Sopenharmony_cidai_link is a codec to codec connection. 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciIn dapm core a route is created between cpu_dai playback widget 938c2ecf20Sopenharmony_ciand codec_dai capture widget for playback path and vice-versa is 948c2ecf20Sopenharmony_citrue for capture path. In order for this aforementioned route to get 958c2ecf20Sopenharmony_citriggered, DAPM needs to find a valid endpoint which could be either 968c2ecf20Sopenharmony_cia sink or source widget corresponding to playback and capture path 978c2ecf20Sopenharmony_cirespectively. 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciIn order to trigger this dai_link widget, a thin codec driver for 1008c2ecf20Sopenharmony_cithe speaker amp can be created as demonstrated in wm8727.c file, it 1018c2ecf20Sopenharmony_cisets appropriate constraints for the device even if it needs no control. 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciMake sure to name your corresponding cpu and codec playback and capture 1048c2ecf20Sopenharmony_cidai names ending with "Playback" and "Capture" respectively as dapm core 1058c2ecf20Sopenharmony_ciwill link and power those dais based on the name. 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciA dai_link in a "simple-audio-card" will automatically be detected as 1088c2ecf20Sopenharmony_cicodec to codec when all DAIs on the link belong to codec components. 1098c2ecf20Sopenharmony_ciThe dai_link will be initialized with the subset of stream parameters 1108c2ecf20Sopenharmony_ci(channels, format, sample rate) supported by all DAIs on the link. Since 1118c2ecf20Sopenharmony_cithere is no way to provide these parameters in the device tree, this is 1128c2ecf20Sopenharmony_cimostly useful for communication with simple fixed-function codecs, such 1138c2ecf20Sopenharmony_cias a Bluetooth controller or cellular modem. 114