ASoC: soc-component: add mark for snd_soc_link_compr_startup/shutdown()
[linux-2.6-microblaze.git] / sound / soc / soc-compress.c
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // soc-compress.c  --  ALSA SoC Compress
4 //
5 // Copyright (C) 2012 Intel Corp.
6 //
7 // Authors: Namarta Kohli <namartax.kohli@intel.com>
8 //          Ramesh Babu K V <ramesh.babu@linux.intel.com>
9 //          Vinod Koul <vinod.koul@linux.intel.com>
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/workqueue.h>
16 #include <sound/core.h>
17 #include <sound/compress_params.h>
18 #include <sound/compress_driver.h>
19 #include <sound/soc.h>
20 #include <sound/initval.h>
21 #include <sound/soc-dpcm.h>
22 #include <sound/soc-link.h>
23 #include <linux/pm_runtime.h>
24
25 static int soc_compr_free(struct snd_compr_stream *cstream)
26 {
27         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
28         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
29         struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
30         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
31
32         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
33
34         snd_soc_runtime_deactivate(rtd, stream);
35
36         snd_soc_dai_digital_mute(codec_dai, 1, stream);
37
38         if (!snd_soc_dai_active(cpu_dai))
39                 cpu_dai->rate = 0;
40
41         if (!snd_soc_dai_active(codec_dai))
42                 codec_dai->rate = 0;
43
44         snd_soc_link_compr_shutdown(cstream, 0);
45
46         snd_soc_component_compr_free(cstream, 0);
47
48         snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
49
50         snd_soc_dapm_stream_stop(rtd, stream);
51
52         mutex_unlock(&rtd->card->pcm_mutex);
53
54         snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0);
55
56         return 0;
57 }
58
59 static int soc_compr_open(struct snd_compr_stream *cstream)
60 {
61         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
62         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
63         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
64         int ret;
65
66         ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
67         if (ret < 0)
68                 goto pm_err;
69
70         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
71
72         ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
73         if (ret < 0)
74                 goto out;
75
76         ret = snd_soc_component_compr_open(cstream);
77         if (ret < 0)
78                 goto machine_err;
79
80         ret = snd_soc_link_compr_startup(cstream);
81         if (ret < 0)
82                 goto machine_err;
83
84         snd_soc_runtime_activate(rtd, stream);
85
86         mutex_unlock(&rtd->card->pcm_mutex);
87
88         return 0;
89
90 machine_err:
91         snd_soc_component_compr_free(cstream, 1);
92
93         snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
94 out:
95         mutex_unlock(&rtd->card->pcm_mutex);
96 pm_err:
97         snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1);
98
99         return ret;
100 }
101
102 static int soc_compr_open_fe(struct snd_compr_stream *cstream)
103 {
104         struct snd_soc_pcm_runtime *fe = cstream->private_data;
105         struct snd_pcm_substream *fe_substream =
106                  fe->pcm->streams[cstream->direction].substream;
107         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
108         struct snd_soc_dpcm *dpcm;
109         struct snd_soc_dapm_widget_list *list;
110         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
111         int ret;
112
113         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
114         fe->dpcm[stream].runtime = fe_substream->runtime;
115
116         ret = dpcm_path_get(fe, stream, &list);
117         if (ret < 0)
118                 goto be_err;
119         else if (ret == 0)
120                 dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n",
121                         fe->dai_link->name, stream ? "capture" : "playback");
122         /* calculate valid and active FE <-> BE dpcms */
123         dpcm_process_paths(fe, stream, &list, 1);
124         fe->dpcm[stream].runtime = fe_substream->runtime;
125
126         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
127
128         ret = dpcm_be_dai_startup(fe, stream);
129         if (ret < 0) {
130                 /* clean up all links */
131                 for_each_dpcm_be(fe, stream, dpcm)
132                         dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
133
134                 dpcm_be_disconnect(fe, stream);
135                 fe->dpcm[stream].runtime = NULL;
136                 goto out;
137         }
138
139         ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
140         if (ret < 0)
141                 goto out;
142
143         ret = snd_soc_component_compr_open(cstream);
144         if (ret < 0)
145                 goto open_err;
146
147         ret = snd_soc_link_compr_startup(cstream);
148         if (ret < 0)
149                 goto machine_err;
150
151         dpcm_clear_pending_state(fe, stream);
152         dpcm_path_put(&list);
153
154         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
155         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
156
157         snd_soc_runtime_activate(fe, stream);
158
159         mutex_unlock(&fe->card->mutex);
160
161         return 0;
162
163 machine_err:
164         snd_soc_component_compr_free(cstream, 1);
165 open_err:
166         snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
167 out:
168         dpcm_path_put(&list);
169 be_err:
170         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
171         mutex_unlock(&fe->card->mutex);
172         return ret;
173 }
174
175 static int soc_compr_free_fe(struct snd_compr_stream *cstream)
176 {
177         struct snd_soc_pcm_runtime *fe = cstream->private_data;
178         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
179         struct snd_soc_dpcm *dpcm;
180         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
181         int ret;
182
183         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
184
185         snd_soc_runtime_deactivate(fe, stream);
186
187         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
188
189         ret = dpcm_be_dai_hw_free(fe, stream);
190         if (ret < 0)
191                 dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret);
192
193         ret = dpcm_be_dai_shutdown(fe, stream);
194
195         /* mark FE's links ready to prune */
196         for_each_dpcm_be(fe, stream, dpcm)
197                 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
198
199         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
200
201         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
202         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
203
204         dpcm_be_disconnect(fe, stream);
205
206         fe->dpcm[stream].runtime = NULL;
207
208         snd_soc_link_compr_shutdown(cstream, 0);
209
210         snd_soc_component_compr_free(cstream, 0);
211
212         snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
213
214         mutex_unlock(&fe->card->mutex);
215         return 0;
216 }
217
218 static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
219 {
220         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
221         struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
222         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
223         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
224         int ret;
225
226         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
227
228         ret = snd_soc_component_compr_trigger(cstream, cmd);
229         if (ret < 0)
230                 goto out;
231
232         ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
233         if (ret < 0)
234                 goto out;
235
236         switch (cmd) {
237         case SNDRV_PCM_TRIGGER_START:
238                 snd_soc_dai_digital_mute(codec_dai, 0, stream);
239                 break;
240         case SNDRV_PCM_TRIGGER_STOP:
241                 snd_soc_dai_digital_mute(codec_dai, 1, stream);
242                 break;
243         }
244
245 out:
246         mutex_unlock(&rtd->card->pcm_mutex);
247         return ret;
248 }
249
250 static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
251 {
252         struct snd_soc_pcm_runtime *fe = cstream->private_data;
253         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
254         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
255         int ret;
256
257         if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
258             cmd == SND_COMPR_TRIGGER_DRAIN)
259                 return snd_soc_component_compr_trigger(cstream, cmd);
260
261         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
262
263         ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
264         if (ret < 0)
265                 goto out;
266
267         ret = snd_soc_component_compr_trigger(cstream, cmd);
268         if (ret < 0)
269                 goto out;
270
271         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
272
273         ret = dpcm_be_dai_trigger(fe, stream, cmd);
274
275         switch (cmd) {
276         case SNDRV_PCM_TRIGGER_START:
277         case SNDRV_PCM_TRIGGER_RESUME:
278         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
279                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
280                 break;
281         case SNDRV_PCM_TRIGGER_STOP:
282         case SNDRV_PCM_TRIGGER_SUSPEND:
283                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
284                 break;
285         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
286                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
287                 break;
288         }
289
290 out:
291         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
292         mutex_unlock(&fe->card->mutex);
293         return ret;
294 }
295
296 static int soc_compr_set_params(struct snd_compr_stream *cstream,
297                                 struct snd_compr_params *params)
298 {
299         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
300         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
301         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
302         int ret;
303
304         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
305
306         /*
307          * First we call set_params for the CPU DAI, then the component
308          * driver this should configure the SoC side. If the machine has
309          * compressed ops then we call that as well. The expectation is
310          * that these callbacks will configure everything for this compress
311          * path, like configuring a PCM port for a CODEC.
312          */
313         ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
314         if (ret < 0)
315                 goto err;
316
317         ret = snd_soc_component_compr_set_params(cstream, params);
318         if (ret < 0)
319                 goto err;
320
321         ret = snd_soc_link_compr_set_params(cstream);
322         if (ret < 0)
323                 goto err;
324
325         snd_soc_dapm_stream_event(rtd, stream, SND_SOC_DAPM_STREAM_START);
326
327         /* cancel any delayed stream shutdown that is pending */
328         rtd->pop_wait = 0;
329         mutex_unlock(&rtd->card->pcm_mutex);
330
331         cancel_delayed_work_sync(&rtd->delayed_work);
332
333         return 0;
334
335 err:
336         mutex_unlock(&rtd->card->pcm_mutex);
337         return ret;
338 }
339
340 static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
341                                    struct snd_compr_params *params)
342 {
343         struct snd_soc_pcm_runtime *fe = cstream->private_data;
344         struct snd_pcm_substream *fe_substream =
345                  fe->pcm->streams[cstream->direction].substream;
346         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
347         int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
348         int ret;
349
350         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
351
352         /*
353          * Create an empty hw_params for the BE as the machine driver must
354          * fix this up to match DSP decoder and ASRC configuration.
355          * I.e. machine driver fixup for compressed BE is mandatory.
356          */
357         memset(&fe->dpcm[fe_substream->stream].hw_params, 0,
358                 sizeof(struct snd_pcm_hw_params));
359
360         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
361
362         ret = dpcm_be_dai_hw_params(fe, stream);
363         if (ret < 0)
364                 goto out;
365
366         ret = dpcm_be_dai_prepare(fe, stream);
367         if (ret < 0)
368                 goto out;
369
370         ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
371         if (ret < 0)
372                 goto out;
373
374         ret = snd_soc_component_compr_set_params(cstream, params);
375         if (ret < 0)
376                 goto out;
377
378         ret = snd_soc_link_compr_set_params(cstream);
379         if (ret < 0)
380                 goto out;
381
382         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
383         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
384
385 out:
386         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
387         mutex_unlock(&fe->card->mutex);
388         return ret;
389 }
390
391 static int soc_compr_get_params(struct snd_compr_stream *cstream,
392                                 struct snd_codec *params)
393 {
394         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
395         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
396         int ret = 0;
397
398         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
399
400         ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
401         if (ret < 0)
402                 goto err;
403
404         ret = snd_soc_component_compr_get_params(cstream, params);
405 err:
406         mutex_unlock(&rtd->card->pcm_mutex);
407         return ret;
408 }
409
410 static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
411 {
412         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
413         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
414         int ret;
415
416         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
417
418         ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
419         if (ret < 0)
420                 goto err;
421
422         ret = snd_soc_component_compr_ack(cstream, bytes);
423 err:
424         mutex_unlock(&rtd->card->pcm_mutex);
425         return ret;
426 }
427
428 static int soc_compr_pointer(struct snd_compr_stream *cstream,
429                              struct snd_compr_tstamp *tstamp)
430 {
431         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
432         int ret;
433         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
434
435         mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
436
437         ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
438         if (ret < 0)
439                 goto out;
440
441         ret = snd_soc_component_compr_pointer(cstream, tstamp);
442 out:
443         mutex_unlock(&rtd->card->pcm_mutex);
444         return ret;
445 }
446
447 static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
448                                   struct snd_compr_metadata *metadata)
449 {
450         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
451         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
452         int ret;
453
454         ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata);
455         if (ret < 0)
456                 return ret;
457
458         return snd_soc_component_compr_set_metadata(cstream, metadata);
459 }
460
461 static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
462                                   struct snd_compr_metadata *metadata)
463 {
464         struct snd_soc_pcm_runtime *rtd = cstream->private_data;
465         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
466         int ret;
467
468         ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata);
469         if (ret < 0)
470                 return ret;
471
472         return snd_soc_component_compr_get_metadata(cstream, metadata);
473 }
474
475 /* ASoC Compress operations */
476 static struct snd_compr_ops soc_compr_ops = {
477         .open           = soc_compr_open,
478         .free           = soc_compr_free,
479         .set_params     = soc_compr_set_params,
480         .set_metadata   = soc_compr_set_metadata,
481         .get_metadata   = soc_compr_get_metadata,
482         .get_params     = soc_compr_get_params,
483         .trigger        = soc_compr_trigger,
484         .pointer        = soc_compr_pointer,
485         .ack            = soc_compr_ack,
486         .get_caps       = snd_soc_component_compr_get_caps,
487         .get_codec_caps = snd_soc_component_compr_get_codec_caps,
488 };
489
490 /* ASoC Dynamic Compress operations */
491 static struct snd_compr_ops soc_compr_dyn_ops = {
492         .open           = soc_compr_open_fe,
493         .free           = soc_compr_free_fe,
494         .set_params     = soc_compr_set_params_fe,
495         .get_params     = soc_compr_get_params,
496         .set_metadata   = soc_compr_set_metadata,
497         .get_metadata   = soc_compr_get_metadata,
498         .trigger        = soc_compr_trigger_fe,
499         .pointer        = soc_compr_pointer,
500         .ack            = soc_compr_ack,
501         .get_caps       = snd_soc_component_compr_get_caps,
502         .get_codec_caps = snd_soc_component_compr_get_codec_caps,
503 };
504
505 /**
506  * snd_soc_new_compress - create a new compress.
507  *
508  * @rtd: The runtime for which we will create compress
509  * @num: the device index number (zero based - shared with normal PCMs)
510  *
511  * Return: 0 for success, else error.
512  */
513 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
514 {
515         struct snd_soc_component *component;
516         struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
517         struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
518         struct snd_compr *compr;
519         struct snd_pcm *be_pcm;
520         char new_name[64];
521         int ret = 0, direction = 0;
522         int playback = 0, capture = 0;
523         int i;
524
525         /*
526          * make sure these are same value,
527          * and then use these as equally
528          */
529         BUILD_BUG_ON((int)SNDRV_PCM_STREAM_PLAYBACK != (int)SND_COMPRESS_PLAYBACK);
530         BUILD_BUG_ON((int)SNDRV_PCM_STREAM_CAPTURE  != (int)SND_COMPRESS_CAPTURE);
531
532         if (rtd->num_cpus > 1 ||
533             rtd->num_codecs > 1) {
534                 dev_err(rtd->card->dev,
535                         "Compress ASoC: Multi CPU/Codec not supported\n");
536                 return -EINVAL;
537         }
538
539         /* check client and interface hw capabilities */
540         if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
541             snd_soc_dai_stream_valid(cpu_dai,   SNDRV_PCM_STREAM_PLAYBACK))
542                 playback = 1;
543         if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
544             snd_soc_dai_stream_valid(cpu_dai,   SNDRV_PCM_STREAM_CAPTURE))
545                 capture = 1;
546
547         /*
548          * Compress devices are unidirectional so only one of the directions
549          * should be set, check for that (xor)
550          */
551         if (playback + capture != 1) {
552                 dev_err(rtd->card->dev,
553                         "Compress ASoC: Invalid direction for P %d, C %d\n",
554                         playback, capture);
555                 return -EINVAL;
556         }
557
558         if (playback)
559                 direction = SND_COMPRESS_PLAYBACK;
560         else
561                 direction = SND_COMPRESS_CAPTURE;
562
563         compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL);
564         if (!compr)
565                 return -ENOMEM;
566
567         compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops),
568                                   GFP_KERNEL);
569         if (!compr->ops)
570                 return -ENOMEM;
571
572         if (rtd->dai_link->dynamic) {
573                 snprintf(new_name, sizeof(new_name), "(%s)",
574                         rtd->dai_link->stream_name);
575
576                 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
577                                 rtd->dai_link->dpcm_playback,
578                                 rtd->dai_link->dpcm_capture, &be_pcm);
579                 if (ret < 0) {
580                         dev_err(rtd->card->dev,
581                                 "Compress ASoC: can't create compressed for %s: %d\n",
582                                 rtd->dai_link->name, ret);
583                         return ret;
584                 }
585
586                 rtd->pcm = be_pcm;
587                 rtd->fe_compr = 1;
588                 if (rtd->dai_link->dpcm_playback)
589                         be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
590                 else if (rtd->dai_link->dpcm_capture)
591                         be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
592                 memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops));
593         } else {
594                 snprintf(new_name, sizeof(new_name), "%s %s-%d",
595                         rtd->dai_link->stream_name, codec_dai->name, num);
596
597                 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
598         }
599
600         for_each_rtd_components(rtd, i, component) {
601                 if (!component->driver->compress_ops ||
602                     !component->driver->compress_ops->copy)
603                         continue;
604
605                 compr->ops->copy = snd_soc_component_compr_copy;
606                 break;
607         }
608
609         mutex_init(&compr->lock);
610         ret = snd_compress_new(rtd->card->snd_card, num, direction,
611                                 new_name, compr);
612         if (ret < 0) {
613                 component = asoc_rtd_to_codec(rtd, 0)->component;
614                 dev_err(component->dev,
615                         "Compress ASoC: can't create compress for codec %s: %d\n",
616                         component->name, ret);
617                 return ret;
618         }
619
620         /* DAPM dai link stream work */
621         rtd->close_delayed_work_func = snd_soc_close_delayed_work;
622
623         rtd->compr = compr;
624         compr->private_data = rtd;
625
626         dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
627                 codec_dai->name, cpu_dai->name);
628
629         return 0;
630 }
631 EXPORT_SYMBOL_GPL(snd_soc_new_compress);