codec-to-codec.rst 3.8 KB

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