← Documents Documentation/sound/soc/dpcm.rst GitHub 원문 ↗

Linux 6.18.37 · Sound / ASoC

Dynamic PCM

DPCM이 FE ALSA PCM과 BE DAI를 DSP DAPM graph에서 runtime에 연결하는 구조를 설명합니다. Headset에서 speaker로의 무중단 전환, FE·BE machine link flag, hw_params fixup, dummy route, DSP AIF와 CODEC↔CODEC·hostless FE 방식을 원문 topology와 함께 정리합니다.

Source pathDocumentation/sound/soc/dpcm.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

dpcm.rst:1-387

DPCM이 FE ALSA PCM과 BE DAI를 DSP DAPM graph에서 runtime에 연결하는 구조를 설명합니다. Headset에서 speaker로의 무중단 전환, FE·BE machine link flag, hw_params fixup, dummy route, DSP AIF와 CODEC↔CODEC·hostless FE 방식을 원문 topology와 함께 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ===========
2 Dynamic PCM
3 ===========
4
5 Description
6 ===========
7
8 Dynamic PCM allows an ALSA PCM device to digitally route its PCM audio to
9 various digital endpoints during the PCM stream runtime. e.g. PCM0 can route
10 digital audio to I2S DAI0, I2S DAI1 or PDM DAI2. This is useful for on SoC DSP
11 drivers that expose several ALSA PCMs and can route to multiple DAIs.
12
13 The DPCM runtime routing is determined by the ALSA mixer settings in the same
14 way as the analog signal is routed in an ASoC codec driver. DPCM uses a DAPM
15 graph representing the DSP internal audio paths and uses the mixer settings to
16 determine the path used by each ALSA PCM.
17
18 DPCM re-uses all the existing component codec, platform and DAI drivers without
19 any modifications.
20
21
22 Phone Audio System with SoC based DSP
23 -------------------------------------
24
25 Consider the following phone audio subsystem. This will be used in this
26 document for all examples :-
27 ::
28
29 | Front End PCMs | SoC DSP | Back End DAIs | Audio devices |
30
31 *************
32 PCM0 <------------> * * <----DAI0-----> Codec Headset
33 * *
34 PCM1 <------------> * * <----DAI1-----> Codec Speakers
35 * DSP *
36 PCM2 <------------> * * <----DAI2-----> MODEM
37 * *
38 PCM3 <------------> * * <----DAI3-----> BT
39 * *
40 * * <----DAI4-----> DMIC
41 * *
42 * * <----DAI5-----> FM
43 *************
44
45 This diagram shows a simple smart phone audio subsystem. It supports Bluetooth,
46 FM digital radio, Speakers, Headset Jack, digital microphones and cellular
47 modem. This sound card exposes 4 DSP front end (FE) ALSA PCM devices and
48 supports 6 back end (BE) DAIs. Each FE PCM can digitally route audio data to any
49 of the BE DAIs. The FE PCM devices can also route audio to more than 1 BE DAI.
50
51
52
53 Example - DPCM Switching playback from DAI0 to DAI1
54 ---------------------------------------------------
55
56 Audio is being played to the Headset. After a while the user removes the headset
57 and audio continues playing on the speakers.
58
59 Playback on PCM0 to Headset would look like :-
60 ::
61
62 *************
63 PCM0 <============> * * <====DAI0=====> Codec Headset
64 * *
65 PCM1 <------------> * * <----DAI1-----> Codec Speakers
66 * DSP *
67 PCM2 <------------> * * <----DAI2-----> MODEM
68 * *
69 PCM3 <------------> * * <----DAI3-----> BT
70 * *
71 * * <----DAI4-----> DMIC
72 * *
73 * * <----DAI5-----> FM
74 *************
75
76 The headset is removed from the jack by user so the speakers must now be used :-
77 ::
78
79 *************
80 PCM0 <============> * * <----DAI0-----> Codec Headset
81 * *
82 PCM1 <------------> * * <====DAI1=====> Codec Speakers
83 * DSP *
84 PCM2 <------------> * * <----DAI2-----> MODEM
85 * *
86 PCM3 <------------> * * <----DAI3-----> BT
87 * *
88 * * <----DAI4-----> DMIC
89 * *
90 * * <----DAI5-----> FM
91 *************
92
93 The audio driver processes this as follows :-
94
95 1. Machine driver receives Jack removal event.
96
97 2. Machine driver OR audio HAL disables the Headset path.
98
99 3. DPCM runs the PCM trigger(stop), hw_free(), shutdown() operations on DAI0
100 for headset since the path is now disabled.
101
102 4. Machine driver or audio HAL enables the speaker path.
103
104 5. DPCM runs the PCM ops for startup(), hw_params(), prepare() and
105 trigger(start) for DAI1 Speakers since the path is enabled.
106
107 In this example, the machine driver or userspace audio HAL can alter the routing
108 and then DPCM will take care of managing the DAI PCM operations to either bring
109 the link up or down. Audio playback does not stop during this transition.
110
111
112
113 DPCM machine driver
114 ===================
115
116 The DPCM enabled ASoC machine driver is similar to normal machine drivers
117 except that we also have to :-
118
119 1. Define the FE and BE DAI links.
120
121 2. Define any FE/BE PCM operations.
122
123 3. Define widget graph connections.
124
125
126 FE and BE DAI links
127 -------------------
128 ::
129
130 | Front End PCMs | SoC DSP | Back End DAIs | Audio devices |
131
132 *************
133 PCM0 <------------> * * <----DAI0-----> Codec Headset
134 * *
135 PCM1 <------------> * * <----DAI1-----> Codec Speakers
136 * DSP *
137 PCM2 <------------> * * <----DAI2-----> MODEM
138 * *
139 PCM3 <------------> * * <----DAI3-----> BT
140 * *
141 * * <----DAI4-----> DMIC
142 * *
143 * * <----DAI5-----> FM
144 *************
145
146 For the example above we have to define 4 FE DAI links and 6 BE DAI links. The
147 FE DAI links are defined as follows :-
148 ::
149
150 SND_SOC_DAILINK_DEFS(pcm0,
151 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")),
152 DAILINK_COMP_ARRAY(COMP_DUMMY()),
153 DAILINK_COMP_ARRAY(COMP_PLATFORM("dsp-audio")));
154
155 static struct snd_soc_dai_link machine_dais[] = {
156 {
157 .name = "PCM0 System",
158 .stream_name = "System Playback",
159 SND_SOC_DAILINK_REG(pcm0),
160 .dynamic = 1,
161 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
162 },
163 .....< other FE and BE DAI links here >
164 };
165
166 This FE DAI link is pretty similar to a regular DAI link except that we also
167 set the DAI link to a DPCM FE with the ``dynamic = 1``.
168 There is also an option to specify the ordering of the trigger call for
169 each FE. This allows the ASoC core to trigger the DSP before or after the other
170 components (as some DSPs have strong requirements for the ordering DAI/DSP
171 start and stop sequences).
172
173 The FE DAI above sets the codec and code DAIs to dummy devices since the BE is
174 dynamic and will change depending on runtime config.
175
176 The BE DAIs are configured as follows :-
177 ::
178
179 SND_SOC_DAILINK_DEFS(headset,
180 DAILINK_COMP_ARRAY(COMP_CPU("ssp-dai.0")),
181 DAILINK_COMP_ARRAY(COMP_CODEC("rt5640.0-001c", "rt5640-aif1")));
182
183 static struct snd_soc_dai_link machine_dais[] = {
184 .....< FE DAI links here >
185 {
186 .name = "Codec Headset",
187 SND_SOC_DAILINK_REG(headset),
188 .no_pcm = 1,
189 .ignore_suspend = 1,
190 .ignore_pmdown_time = 1,
191 .be_hw_params_fixup = hswult_ssp0_fixup,
192 .ops = &haswell_ops,
193 },
194 .....< other BE DAI links here >
195 };
196
197 This BE DAI link connects DAI0 to the codec (in this case RT5460 AIF1). It sets
198 the ``no_pcm`` flag to mark it has a BE.
199
200 The BE has also flags set for ignoring suspend and PM down time. This allows
201 the BE to work in a hostless mode where the host CPU is not transferring data
202 like a BT phone call :-
203 ::
204
205 *************
206 PCM0 <------------> * * <----DAI0-----> Codec Headset
207 * *
208 PCM1 <------------> * * <----DAI1-----> Codec Speakers
209 * DSP *
210 PCM2 <------------> * * <====DAI2=====> MODEM
211 * *
212 PCM3 <------------> * * <====DAI3=====> BT
213 * *
214 * * <----DAI4-----> DMIC
215 * *
216 * * <----DAI5-----> FM
217 *************
218
219 This allows the host CPU to sleep while the DSP, MODEM DAI and the BT DAI are
220 still in operation.
221
222 A BE DAI link can also set the codec to a dummy device if the codec is a device
223 that is managed externally.
224
225 Likewise a BE DAI can also set a dummy cpu DAI if the CPU DAI is managed by the
226 DSP firmware.
227
228
229 FE/BE PCM operations
230 --------------------
231
232 The BE above also exports some PCM operations and a ``fixup`` callback. The fixup
233 callback is used by the machine driver to (re)configure the DAI based upon the
234 FE hw params. i.e. the DSP may perform SRC or ASRC from the FE to BE.
235
236 e.g. DSP converts all FE hw params to run at fixed rate of 48k, 16bit, stereo for
237 DAI0. This means all FE hw_params have to be fixed in the machine driver for
238 DAI0 so that the DAI is running at desired configuration regardless of the FE
239 configuration.
240 ::
241
242 static int dai0_fixup(struct snd_soc_pcm_runtime *rtd,
243 struct snd_pcm_hw_params *params)
244 {
245 struct snd_interval *rate = hw_param_interval(params,
246 SNDRV_PCM_HW_PARAM_RATE);
247 struct snd_interval *channels = hw_param_interval(params,
248 SNDRV_PCM_HW_PARAM_CHANNELS);
249
250 /* The DSP will convert the FE rate to 48k, stereo */
251 rate->min = rate->max = 48000;
252 channels->min = channels->max = 2;
253
254 /* set DAI0 to 16 bit */
255 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
256 return 0;
257 }
258
259 The other PCM operation are the same as for regular DAI links. Use as necessary.
260
261
262 Widget graph connections
263 ------------------------
264
265 The BE DAI links will normally be connected to the graph at initialisation time
266 by the ASoC DAPM core. However, if the BE codec or BE DAI is a dummy then this
267 has to be set explicitly in the driver :-
268 ::
269
270 /* BE for codec Headset - DAI0 is dummy and managed by DSP FW */
271 {"DAI0 CODEC IN", NULL, "AIF1 Capture"},
272 {"AIF1 Playback", NULL, "DAI0 CODEC OUT"},
273
274
275 Writing a DPCM DSP driver
276 =========================
277
278 The DPCM DSP driver looks much like a standard platform class ASoC driver
279 combined with elements from a codec class driver. A DSP platform driver must
280 implement :-
281
282 1. Front End PCM DAIs - i.e. struct snd_soc_dai_driver.
283
284 2. DAPM graph showing DSP audio routing from FE DAIs to BEs.
285
286 3. DAPM widgets from DSP graph.
287
288 4. Mixers for gains, routing, etc.
289
290 5. DMA configuration.
291
292 6. BE AIF widgets.
293
294 Items 6 is important for routing the audio outside of the DSP. AIF need to be
295 defined for each BE and each stream direction. e.g for BE DAI0 above we would
296 have :-
297 ::
298
299 SND_SOC_DAPM_AIF_IN("DAI0 RX", NULL, 0, SND_SOC_NOPM, 0, 0),
300 SND_SOC_DAPM_AIF_OUT("DAI0 TX", NULL, 0, SND_SOC_NOPM, 0, 0),
301
302 The BE AIF are used to connect the DSP graph to the graphs for the other
303 component drivers (e.g. codec graph).
304
305
306 Hostless PCM streams
307 ====================
308
309 A hostless PCM stream is a stream that is not routed through the host CPU. An
310 example of this would be a phone call from handset to modem.
311 ::
312
313 *************
314 PCM0 <------------> * * <----DAI0-----> Codec Headset
315 * *
316 PCM1 <------------> * * <====DAI1=====> Codec Speakers/Mic
317 * DSP *
318 PCM2 <------------> * * <====DAI2=====> MODEM
319 * *
320 PCM3 <------------> * * <----DAI3-----> BT
321 * *
322 * * <----DAI4-----> DMIC
323 * *
324 * * <----DAI5-----> FM
325 *************
326
327 In this case the PCM data is routed via the DSP. The host CPU in this use case
328 is only used for control and can sleep during the runtime of the stream.
329
330 The host can control the hostless link either by :-
331
332 1. Configuring the link as a CODEC <-> CODEC style link. In this case the link
333 is enabled or disabled by the state of the DAPM graph. This usually means
334 there is a mixer control that can be used to connect or disconnect the path
335 between both DAIs.
336
337 2. Hostless FE. This FE has a virtual connection to the BE DAI links on the DAPM
338 graph. Control is then carried out by the FE as regular PCM operations.
339 This method gives more control over the DAI links, but requires much more
340 userspace code to control the link. Its recommended to use CODEC<->CODEC
341 unless your HW needs more fine grained sequencing of the PCM ops.
342
343
344 CODEC <-> CODEC link
345 --------------------
346
347 This DAI link is enabled when DAPM detects a valid path within the DAPM graph.
348 The machine driver sets some additional parameters to the DAI link i.e.
349 ::
350
351 static const struct snd_soc_pcm_stream dai_params = {
352 .formats = SNDRV_PCM_FMTBIT_S32_LE,
353 .rate_min = 8000,
354 .rate_max = 8000,
355 .channels_min = 2,
356 .channels_max = 2,
357 };
358
359 static struct snd_soc_dai_link dais[] = {
360 < ... more DAI links above ... >
361 {
362 .name = "MODEM",
363 .stream_name = "MODEM",
364 .cpu_dai_name = "dai2",
365 .codec_dai_name = "modem-aif1",
366 .codec_name = "modem",
367 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
368 | SND_SOC_DAIFMT_CBP_CFP,
369 .c2c_params = &dai_params,
370 .num_c2c_params = 1,
371 }
372 < ... more DAI links here ... >
373
374 These parameters are used to configure the DAI hw_params() when DAPM detects a
375 valid path and then calls the PCM operations to start the link. DAPM will also
376 call the appropriate PCM operations to disable the DAI when the path is no
377 longer valid.
378
379
380 Hostless FE
381 -----------
382
383 The DAI link(s) are enabled by a FE that does not read or write any PCM data.
384 This means creating a new FE that is connected with a virtual path to both
385 DAI links. The DAI links will be started when the FE PCM is started and stopped
386 when the FE PCM is stopped. Note that the FE PCM cannot read or write data in
387 this configuration.
388

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

DPCM runtime routing

1-21

Dynamic PCM(DPCM)은 ALSA PCM device가 PCM stream 실행 중에 디지털 오디오를 여러 digital endpoint로 route할 수 있게 한다. 예를 들어 PCM0은 I2S DAI0, I2S DAI1 또는 PDM DAI2로 오디오를 보낼 수 있다. 여러 ALSA PCM을 노출하고 여러 DAI로 route할 수 있는 SoC DSP driver에 유용하다.

DPCM runtime route는 ASoC codec driver의 analog signal routing과 마찬가지로 ALSA mixer 설정으로 결정된다. DPCM은 DSP 내부 audio path를 나타내는 DAPM graph를 사용하고, mixer 설정으로 각 ALSA PCM이 사용할 path를 선택한다.

DPCM은 기존 component codec, platform, DAI driver를 수정하지 않고 그대로 재사용한다.

DPCM 핵심
요소역할
FE ALSA PCMApplication에 노출되는 front-end stream
BE DAICodec·MODEM·BT·DMIC·FM 등 digital endpoint
DAPM graphDSP 내부 audio path 표현
ALSA mixerRuntime route 선택

Runtime에 FE PCM과 digital endpoint를 연결하는 요소다.

DPCM route 결정
ALSA PCM activityFE PCM
ALSA mixer settingsDAPM graphSelected DSP pathBE DAIDigital endpoint

Mixer 설정이 DSP graph의 활성 FE→BE path를 바꾼다.

===========
Dynamic PCM
===========

Description
===========

Dynamic PCM allows an ALSA PCM device to digitally route its PCM audio to
various digital endpoints during the PCM stream runtime. e.g. PCM0 can route
digital audio to I2S DAI0, I2S DAI1 or PDM DAI2. This is useful for on SoC DSP
drivers that expose several ALSA PCMs and can route to multiple DAIs.

The DPCM runtime routing is determined by the ALSA mixer settings in the same
way as the analog signal is routed in an ASoC codec driver. DPCM uses a DAPM
graph representing the DSP internal audio paths and uses the mixer settings to
determine the path used by each ALSA PCM.

DPCM re-uses all the existing component codec, platform and DAI drivers without
any modifications.

SoC DSP 기반 phone audio system

22-53

예제 smartphone audio subsystem은 Bluetooth, FM digital radio, speaker, headset jack, digital microphone, cellular modem을 지원한다. Sound card는 DSP front end(FE) ALSA PCM device 4개와 back end(BE) DAI 6개를 노출한다.

각 FE PCM은 어느 BE DAI로든 digital audio를 route할 수 있으며, 하나의 FE PCM을 둘 이상의 BE DAI에 동시에 연결할 수도 있다.

Phone audio FE·BE
구분항목연결 대상
FEPCM0-PCM3SoC DSP front-end ALSA PCM
BEDAI0Codec Headset
BEDAI1Codec Speakers
BEDAI2MODEM
BEDAI3BT
BEDAI4DMIC
BEDAI5FM

원문 topology의 FE와 BE endpoint를 정리한다.

Phone DPCM 전체 topology
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI0Codec Headset
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI1Codec Speakers
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI2MODEM
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI3BT
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI4DMIC
PCM0 / PCM1 / PCM2 / PCM3SoC DSP routing graphDAI5FM

네 FE가 DSP graph를 통해 여섯 BE 중 하나 이상으로 route될 수 있다.

Phone Audio System with SoC based DSP
-------------------------------------

Consider the following phone audio subsystem. This will be used in this
document for all examples :-
::

  | Front End PCMs    |  SoC DSP  | Back End DAIs | Audio devices |
  
                      *************
  PCM0 <------------> *           * <----DAI0-----> Codec Headset
                      *           *
  PCM1 <------------> *           * <----DAI1-----> Codec Speakers
                      *   DSP     *
  PCM2 <------------> *           * <----DAI2-----> MODEM
                      *           *
  PCM3 <------------> *           * <----DAI3-----> BT
                      *           *
                      *           * <----DAI4-----> DMIC
                      *           *
                      *           * <----DAI5-----> FM
                      *************

This diagram shows a simple smart phone audio subsystem. It supports Bluetooth,
FM digital radio, Speakers, Headset Jack, digital microphones and cellular
modem. This sound card exposes 4 DSP front end (FE) ALSA PCM devices and
supports 6 back end (BE) DAIs. Each FE PCM can digitally route audio data to any
of the BE DAIs. The FE PCM devices can also route audio to more than 1 BE DAI.



Example - DPCM Switching playback from DAI0 to DAI1

Playback을 DAI0에서 DAI1로 전환

54-112

처음에는 PCM0의 오디오가 DAI0을 통해 headset으로 재생된다. 사용자가 headset을 제거하면 재생을 멈추지 않고 DAI1의 speaker로 계속 출력해야 한다.

Machine driver가 jack removal event를 받고 machine driver 또는 audio HAL이 Headset path를 disable한다. DPCM은 비활성화된 DAI0에서 `trigger(stop)`, `hw_free()`, `shutdown()`을 실행한다.

그다음 machine driver 또는 audio HAL이 speaker path를 enable한다. DPCM은 새로 활성화된 DAI1 speaker에서 `startup()`, `hw_params()`, `prepare()`, `trigger(start)`를 실행한다.

Routing 변경 주체는 machine driver 또는 userspace audio HAL이고, DPCM이 link를 올리고 내리는 DAI PCM operation을 관리한다. 이 전환 중 audio playback은 중단되지 않는다.

전환 전: Headset 활성
PCM0Active DSP pathDAI0Codec Headset
PCM1-PCM3Inactive DSP pathsDAI1-DAI5

PCM0이 DSP를 거쳐 DAI0 Headset 경로에 연결된다.

전환 후: Speaker 활성
PCM0Active DSP pathDAI1Codec Speakers
DAI0Disabled pathCodec Headset

같은 PCM0 stream을 유지하면서 BE만 DAI1로 교체한다.

Headset→Speaker operation 순서
단계주체동작
1Machine driverJack removal event 수신
2Machine driver / audio HALHeadset path disable
3DPCM on DAI0trigger(stop) → hw_free() → shutdown()
4Machine driver / audio HALSpeaker path enable
5DPCM on DAI1startup() → hw_params() → prepare() → trigger(start)

Path disable과 enable에 따른 DPCM PCM callback 순서다.

---------------------------------------------------

Audio is being played to the Headset. After a while the user removes the headset
and audio continues playing on the speakers.

Playback on PCM0 to Headset would look like :-
::

                      *************
  PCM0 <============> *           * <====DAI0=====> Codec Headset
                      *           *
  PCM1 <------------> *           * <----DAI1-----> Codec Speakers
                      *   DSP     *
  PCM2 <------------> *           * <----DAI2-----> MODEM
                      *           *
  PCM3 <------------> *           * <----DAI3-----> BT
                      *           *
                      *           * <----DAI4-----> DMIC
                      *           *
                      *           * <----DAI5-----> FM
                      *************

The headset is removed from the jack by user so the speakers must now be used :-
::

                      *************
  PCM0 <============> *           * <----DAI0-----> Codec Headset
                      *           *
  PCM1 <------------> *           * <====DAI1=====> Codec Speakers
                      *   DSP     *
  PCM2 <------------> *           * <----DAI2-----> MODEM
                      *           *
  PCM3 <------------> *           * <----DAI3-----> BT
                      *           *
                      *           * <----DAI4-----> DMIC
                      *           *
                      *           * <----DAI5-----> FM
                      *************

The audio driver processes this as follows :-

1. Machine driver receives Jack removal event.

2. Machine driver OR audio HAL disables the Headset path.

3. DPCM runs the PCM trigger(stop), hw_free(), shutdown() operations on DAI0
   for headset since the path is now disabled.

4. Machine driver or audio HAL enables the speaker path.

5. DPCM runs the PCM ops for startup(), hw_params(), prepare() and
   trigger(start) for DAI1 Speakers since the path is enabled.

In this example, the machine driver or userspace audio HAL can alter the routing
and then DPCM will take care of managing the DAI PCM operations to either bring
the link up or down. Audio playback does not stop during this transition.


DPCM machine driver 요구사항

113-125

DPCM을 사용하는 ASoC machine driver는 일반 machine driver와 비슷하지만 FE·BE DAI link, FE·BE PCM operation, widget graph connection을 추가로 정의해야 한다.

DPCM machine driver 추가 항목
항목목적
FE·BE DAI linksApplication PCM과 physical endpoint 분리
FE·BE PCM operations각 link의 lifecycle·parameter 처리
Widget graph connectionsDSP 내부·외부 DAPM route 구성

일반 machine driver에 더해 필요한 세 정의다.

DPCM machine driver
===================

The DPCM enabled ASoC machine driver is similar to normal machine drivers
except that we also have to :-

1. Define the FE and BE DAI links.

2. Define any FE/BE PCM operations.

3. Define widget graph connections.

FE·BE PCM operation과 fixup

230-262

BE는 일반 PCM operation과 함께 `fixup` callback을 내보낼 수 있다. Machine driver는 FE hw parameter를 바탕으로 DAI를 재설정하는 데 fixup을 사용한다. DSP가 FE와 BE 사이에서 SRC 또는 ASRC를 수행할 수 있기 때문이다.

예제에서는 DSP가 모든 FE parameter를 DAI0용 48 kHz, 16-bit, stereo로 변환한다. 따라서 `dai0_fixup()`은 rate interval의 min·max를 48000으로, channel interval의 min·max를 2로 고정하고 `params_set_format()`으로 `SNDRV_PCM_FORMAT_S16_LE`를 설정한다.

그 밖의 PCM operation은 일반 DAI link와 같으며 필요에 따라 사용한다.

dai0_fixup 결과
Parameter설정
Rate48000 Hz fixed
Channels2, stereo fixed
FormatSNDRV_PCM_FORMAT_S16_LE

FE 설정과 무관하게 DAI0 BE가 사용할 고정 hardware parameter다.

FE parameter에서 BE parameter로
Arbitrary FE hw_paramsDSP SRC / ASRCdai0_fixup()48 kHz / 16-bit / stereoDAI0 BE

DSP 변환 능력을 반영해 machine fixup이 physical DAI 조건을 고정한다.

--------------------

The BE above also exports some PCM operations and a ``fixup`` callback. The fixup
callback is used by the machine driver to (re)configure the DAI based upon the
FE hw params. i.e. the DSP may perform SRC or ASRC from the FE to BE.

e.g. DSP converts all FE hw params to run at fixed rate of 48k, 16bit, stereo for
DAI0. This means all FE hw_params have to be fixed in the machine driver for
DAI0 so that the DAI is running at desired configuration regardless of the FE
configuration.
::

  static int dai0_fixup(struct snd_soc_pcm_runtime *rtd,
			struct snd_pcm_hw_params *params)
  {
	struct snd_interval *rate = hw_param_interval(params,
			SNDRV_PCM_HW_PARAM_RATE);
	struct snd_interval *channels = hw_param_interval(params,
						SNDRV_PCM_HW_PARAM_CHANNELS);

	/* The DSP will convert the FE rate to 48k, stereo */
	rate->min = rate->max = 48000;
	channels->min = channels->max = 2;

	/* set DAI0 to 16 bit */
	params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
	return 0;
  }

The other PCM operation are the same as for regular DAI links. Use as necessary.


Widget graph connections

Dummy BE의 widget graph 연결

263-275

BE DAI link는 보통 초기화 때 ASoC DAPM core가 graph에 연결한다. 하지만 BE codec 또는 BE DAI가 dummy이면 driver가 명시적으로 route를 설정해야 한다.

Headset BE 예제에서는 DSP firmware가 관리하는 dummy DAI0을 codec AIF1에 연결한다. Capture route는 `AIF1 Capture`에서 `DAI0 CODEC IN`으로, playback route는 `DAI0 CODEC OUT`에서 `AIF1 Playback`으로 직접 이어진다.

Dummy DAI0 route
DestinationPathSource
DAI0 CODEC INNULLAIF1 Capture
AIF1 PlaybackNULLDAI0 CODEC OUT

경로 이름 없이 직접 연결하는 두 방향 route다.

------------------------

The BE DAI links will normally be connected to the graph at initialisation time
by the ASoC DAPM core. However, if the BE codec or BE DAI is a dummy then this
has to be set explicitly in the driver :-
::

  /* BE for codec Headset -  DAI0 is dummy and managed by DSP FW */
  {"DAI0 CODEC IN", NULL, "AIF1 Capture"},
  {"AIF1 Playback", NULL, "DAI0 CODEC OUT"},


Writing a DPCM DSP driver

DPCM DSP driver 작성

276-305

DPCM DSP driver는 표준 platform class ASoC driver에 codec class driver의 요소를 결합한 형태다.

DSP platform driver는 `struct snd_soc_dai_driver`로 FE PCM DAI를 제공하고, FE에서 BE까지의 DSP audio route를 보여 주는 DAPM graph와 widget, gain·routing mixer, DMA 설정, BE AIF widget을 구현해야 한다.

BE AIF widget은 DSP 밖으로 audio를 route하는 데 특히 중요하다. 각 BE와 각 stream 방향마다 정의해야 한다. DAI0 예제는 `SND_SOC_DAPM_AIF_IN`으로 `DAI0 RX`, `SND_SOC_DAPM_AIF_OUT`으로 `DAI0 TX`를 만든다. 이 BE AIF가 DSP graph를 codec graph 같은 다른 component driver graph에 연결한다.

DPCM DSP platform driver 항목
항목내용
FE PCM DAIsstruct snd_soc_dai_driver
DAPM graphFE DAI에서 BE까지의 DSP routing
DAPM widgetsDSP graph node
MixersGain과 route control
DMAPCM data transfer 설정
BE AIF widgets각 BE·stream 방향의 외부 연결

DSP 내부 graph와 외부 BE를 모두 표현해야 한다.

DSP graph 외부 연결
FE DAIDSP DAPM widgets / mixersDAI0 RX / TX AIFCodec component graph

BE AIF가 DSP 내부 path와 다른 component graph를 잇는다.

=========================

The DPCM DSP driver looks much like a standard platform class ASoC driver
combined with elements from a codec class driver. A DSP platform driver must
implement :-

1. Front End PCM DAIs - i.e. struct snd_soc_dai_driver.

2. DAPM graph showing DSP audio routing from FE DAIs to BEs.

3. DAPM widgets from DSP graph.

4. Mixers for gains, routing, etc.

5. DMA configuration.

6. BE AIF widgets.

Items 6 is important for routing the audio outside of the DSP. AIF need to be
defined for each BE and each stream direction. e.g for BE DAI0 above we would
have :-
::

  SND_SOC_DAPM_AIF_IN("DAI0 RX", NULL, 0, SND_SOC_NOPM, 0, 0),
  SND_SOC_DAPM_AIF_OUT("DAI0 TX", NULL, 0, SND_SOC_NOPM, 0, 0),

The BE AIF are used to connect the DSP graph to the graphs for the other
component drivers (e.g. codec graph).

Hostless PCM stream

306-343

Hostless PCM stream은 host CPU를 통과하지 않는 stream이다. Handset과 modem 사이의 phone call이 예다. PCM data는 DSP를 통해 route되고 host CPU는 control에만 사용되므로 stream 실행 중 sleep할 수 있다.

Host는 두 방식으로 hostless link를 제어한다. 첫째, CODEC↔CODEC style link로 구성하면 DAPM graph 상태가 link를 enable·disable한다. 보통 mixer control이 두 DAI 사이 path를 연결하거나 끊는다.

둘째, hostless FE를 사용하면 FE가 DAPM graph에서 BE DAI link에 virtual connection을 갖고 일반 PCM operation으로 제어한다. 이 방법은 DAI link를 더 세밀하게 제어하지만 userspace 코드가 훨씬 많이 필요하다. Hardware가 PCM operation의 더 세밀한 sequencing을 요구하지 않으면 CODEC↔CODEC 방식이 권장된다.

Hostless handset↔MODEM call
Codec Speakers / MicDAI1SoC DSPDAI2MODEM
Host CPUControl onlySleep during stream

CPU data path 없이 DSP가 codec microphone·speaker와 modem을 연결한다.

Hostless 제어 방식
방식제어특성
CODEC↔CODECDAPM path·mixer state단순하고 권장되는 기본 방식
Hostless FEFE PCM operations세밀한 sequence, 더 많은 userspace 코드

자동 DAPM 방식과 FE PCM 방식의 tradeoff다.

Hostless PCM streams
====================

A hostless PCM stream is a stream that is not routed through the host CPU. An
example of this would be a phone call from handset to modem.
::

                      *************
  PCM0 <------------> *           * <----DAI0-----> Codec Headset
                      *           *
  PCM1 <------------> *           * <====DAI1=====> Codec Speakers/Mic
                      *   DSP     *
  PCM2 <------------> *           * <====DAI2=====> MODEM
                      *           *
  PCM3 <------------> *           * <----DAI3-----> BT
                      *           *
                      *           * <----DAI4-----> DMIC
                      *           *
                      *           * <----DAI5-----> FM
                      *************

In this case the PCM data is routed via the DSP. The host CPU in this use case
is only used for control and can sleep during the runtime of the stream.

The host can control the hostless link either by :-

 1. Configuring the link as a CODEC <-> CODEC style link. In this case the link
    is enabled or disabled by the state of the DAPM graph. This usually means
    there is a mixer control that can be used to connect or disconnect the path
    between both DAIs.

 2. Hostless FE. This FE has a virtual connection to the BE DAI links on the DAPM
    graph. Control is then carried out by the FE as regular PCM operations.
    This method gives more control over the DAI links, but requires much more
    userspace code to control the link. Its recommended to use CODEC<->CODEC
    unless your HW needs more fine grained sequencing of the PCM ops.

Hostless FE

380-387

Hostless FE는 PCM data를 읽거나 쓰지 않는 FE가 DAI link를 enable하는 방식이다. 새 FE를 만들고 DAPM graph에서 두 DAI link에 virtual path로 연결한다.

FE PCM을 시작하면 DAI link가 시작되고 FE PCM을 정지하면 link도 정지한다. 이 구성의 FE PCM은 data를 read하거나 write할 수 없다.

Hostless FE 제어
Hostless FE PCM startVirtual DAPM pathsBE DAI links start
Hostless FE PCM stopVirtual DAPM pathsBE DAI links stop
FE read / writeNot supported

Data transfer 없이 FE PCM lifecycle만으로 두 BE link를 제어한다.

Hostless FE
-----------

The DAI link(s) are enabled by a FE that does not read or write any PCM data.
This means creating a new FE that is connected with a virtual path to both
DAI links. The DAI links will be started when the FE PCM is started and stopped
when the FE PCM is stopped. Note that the FE PCM cannot read or write data in
this configuration.