Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 1 | ============================================== |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 2 | Creating codec to codec dai link for ALSA dapm |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 3 | ============================================== |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 4 | |
| 5 | Mostly the flow of audio is always from CPU to codec so your system |
| 6 | will look as below: |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 7 | :: |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 8 | |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 9 | --------- --------- |
| 10 | | | dai | | |
| 11 | CPU -------> codec |
| 12 | | | | | |
| 13 | --------- --------- |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 14 | |
| 15 | In case your system looks as below: |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 16 | :: |
| 17 | |
| 18 | --------- |
| 19 | | | |
| 20 | codec-2 |
| 21 | | | |
| 22 | --------- |
| 23 | | |
| 24 | dai-2 |
| 25 | | |
| 26 | ---------- --------- |
| 27 | | | dai-1 | | |
| 28 | CPU -------> codec-1 |
| 29 | | | | | |
| 30 | ---------- --------- |
| 31 | | |
| 32 | dai-3 |
| 33 | | |
| 34 | --------- |
| 35 | | | |
| 36 | codec-3 |
| 37 | | | |
| 38 | --------- |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 39 | |
| 40 | Suppose codec-2 is a bluetooth chip and codec-3 is connected to |
| 41 | a speaker and you have a below scenario: |
| 42 | codec-2 will receive the audio data and the user wants to play that |
| 43 | audio through codec-3 without involving the CPU.This |
| 44 | aforementioned case is the ideal case when codec to codec |
| 45 | connection should be used. |
| 46 | |
| 47 | Your dai_link should appear as below in your machine |
| 48 | file: |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 49 | :: |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 50 | |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 51 | /* |
| 52 | * this pcm stream only supports 24 bit, 2 channel and |
| 53 | * 48k sampling rate. |
| 54 | */ |
| 55 | static const struct snd_soc_pcm_stream dsp_codec_params = { |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 56 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 57 | .rate_min = 48000, |
| 58 | .rate_max = 48000, |
| 59 | .channels_min = 2, |
| 60 | .channels_max = 2, |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 61 | }; |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 62 | |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 63 | { |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 64 | .name = "CPU-DSP", |
| 65 | .stream_name = "CPU-DSP", |
| 66 | .cpu_dai_name = "samsung-i2s.0", |
| 67 | .codec_name = "codec-2, |
| 68 | .codec_dai_name = "codec-2-dai_name", |
| 69 | .platform_name = "samsung-i2s.0", |
| 70 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 71 | | SND_SOC_DAIFMT_CBM_CFM, |
| 72 | .ignore_suspend = 1, |
| 73 | .params = &dsp_codec_params, |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 74 | }, |
| 75 | { |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 76 | .name = "DSP-CODEC", |
| 77 | .stream_name = "DSP-CODEC", |
| 78 | .cpu_dai_name = "wm0010-sdi2", |
| 79 | .codec_name = "codec-3, |
| 80 | .codec_dai_name = "codec-3-dai_name", |
| 81 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 82 | | SND_SOC_DAIFMT_CBM_CFM, |
| 83 | .ignore_suspend = 1, |
| 84 | .params = &dsp_codec_params, |
Takashi Iwai | c6ab9e5 | 2016-11-11 16:55:29 +0100 | [diff] [blame] | 85 | }, |
anish kumar | 452a256 | 2016-10-23 21:03:53 -0700 | [diff] [blame] | 86 | |
| 87 | Above code snippet is motivated from sound/soc/samsung/speyside.c. |
| 88 | |
| 89 | Note the "params" callback which lets the dapm know that this |
| 90 | dai_link is a codec to codec connection. |
| 91 | |
| 92 | In dapm core a route is created between cpu_dai playback widget |
| 93 | and codec_dai capture widget for playback path and vice-versa is |
| 94 | true for capture path. In order for this aforementioned route to get |
| 95 | triggered, DAPM needs to find a valid endpoint which could be either |
| 96 | a sink or source widget corresponding to playback and capture path |
| 97 | respectively. |
| 98 | |
| 99 | In order to trigger this dai_link widget, a thin codec driver for |
| 100 | the speaker amp can be created as demonstrated in wm8727.c file, it |
| 101 | sets appropriate constraints for the device even if it needs no control. |
| 102 | |
| 103 | Make sure to name your corresponding cpu and codec playback and capture |
| 104 | dai names ending with "Playback" and "Capture" respectively as dapm core |
| 105 | will link and power those dais based on the name. |
| 106 | |
| 107 | Note that in current device tree there is no way to mark a dai_link |
| 108 | as codec to codec. However, it may change in future. |