1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-compress.c -- ALSA SoC Compress
5 // Copyright (C) 2012 Intel Corp.
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>
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>
25 static int soc_compr_components_open(struct snd_compr_stream *cstream,
26 struct snd_soc_component **last)
28 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
29 struct snd_soc_component *component;
32 for_each_rtd_components(rtd, i, component) {
33 if (!component->driver->compress_ops ||
34 !component->driver->compress_ops->open)
37 ret = component->driver->compress_ops->open(component, cstream);
39 dev_err(component->dev,
40 "Compress ASoC: can't open platform %s: %d\n",
41 component->name, ret);
52 static int soc_compr_components_free(struct snd_compr_stream *cstream,
53 struct snd_soc_component *last)
55 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
56 struct snd_soc_component *component;
59 for_each_rtd_components(rtd, i, component) {
60 if (component == last)
63 if (!component->driver->compress_ops ||
64 !component->driver->compress_ops->free)
67 component->driver->compress_ops->free(component, cstream);
73 static int soc_compr_open(struct snd_compr_stream *cstream)
75 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
76 struct snd_soc_component *component = NULL;
77 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
81 if (cstream->direction == SND_COMPRESS_PLAYBACK)
82 stream = SNDRV_PCM_STREAM_PLAYBACK;
84 stream = SNDRV_PCM_STREAM_CAPTURE;
86 ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
90 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
92 ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
96 ret = soc_compr_components_open(cstream, &component);
100 ret = snd_soc_link_compr_startup(cstream);
104 snd_soc_runtime_activate(rtd, stream);
106 mutex_unlock(&rtd->card->pcm_mutex);
111 soc_compr_components_free(cstream, component);
113 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
115 mutex_unlock(&rtd->card->pcm_mutex);
117 snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1);
122 static int soc_compr_open_fe(struct snd_compr_stream *cstream)
124 struct snd_soc_pcm_runtime *fe = cstream->private_data;
125 struct snd_pcm_substream *fe_substream =
126 fe->pcm->streams[cstream->direction].substream;
127 struct snd_soc_component *component;
128 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
129 struct snd_soc_dpcm *dpcm;
130 struct snd_soc_dapm_widget_list *list;
134 if (cstream->direction == SND_COMPRESS_PLAYBACK)
135 stream = SNDRV_PCM_STREAM_PLAYBACK;
137 stream = SNDRV_PCM_STREAM_CAPTURE;
139 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
140 fe->dpcm[stream].runtime = fe_substream->runtime;
142 ret = dpcm_path_get(fe, stream, &list);
146 dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n",
147 fe->dai_link->name, stream ? "capture" : "playback");
148 /* calculate valid and active FE <-> BE dpcms */
149 dpcm_process_paths(fe, stream, &list, 1);
150 fe->dpcm[stream].runtime = fe_substream->runtime;
152 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
154 ret = dpcm_be_dai_startup(fe, stream);
156 /* clean up all links */
157 for_each_dpcm_be(fe, stream, dpcm)
158 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
160 dpcm_be_disconnect(fe, stream);
161 fe->dpcm[stream].runtime = NULL;
165 ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
169 ret = soc_compr_components_open(cstream, &component);
173 ret = snd_soc_link_compr_startup(cstream);
177 dpcm_clear_pending_state(fe, stream);
178 dpcm_path_put(&list);
180 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
181 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
183 snd_soc_runtime_activate(fe, stream);
185 mutex_unlock(&fe->card->mutex);
190 soc_compr_components_free(cstream, component);
192 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
194 dpcm_path_put(&list);
196 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
197 mutex_unlock(&fe->card->mutex);
201 static int soc_compr_free(struct snd_compr_stream *cstream)
203 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
204 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
205 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
208 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
210 if (cstream->direction == SND_COMPRESS_PLAYBACK)
211 stream = SNDRV_PCM_STREAM_PLAYBACK;
213 stream = SNDRV_PCM_STREAM_CAPTURE;
215 snd_soc_runtime_deactivate(rtd, stream);
217 snd_soc_dai_digital_mute(codec_dai, 1, stream);
219 if (!snd_soc_dai_active(cpu_dai))
222 if (!snd_soc_dai_active(codec_dai))
225 snd_soc_link_compr_shutdown(cstream);
227 soc_compr_components_free(cstream, NULL);
229 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
231 snd_soc_dapm_stream_stop(rtd, stream);
233 mutex_unlock(&rtd->card->pcm_mutex);
235 snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0);
240 static int soc_compr_free_fe(struct snd_compr_stream *cstream)
242 struct snd_soc_pcm_runtime *fe = cstream->private_data;
243 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
244 struct snd_soc_dpcm *dpcm;
247 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
249 if (cstream->direction == SND_COMPRESS_PLAYBACK)
250 stream = SNDRV_PCM_STREAM_PLAYBACK;
252 stream = SNDRV_PCM_STREAM_CAPTURE;
254 snd_soc_runtime_deactivate(fe, stream);
256 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
258 ret = dpcm_be_dai_hw_free(fe, stream);
260 dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret);
262 ret = dpcm_be_dai_shutdown(fe, stream);
264 /* mark FE's links ready to prune */
265 for_each_dpcm_be(fe, stream, dpcm)
266 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
268 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
270 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
271 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
273 dpcm_be_disconnect(fe, stream);
275 fe->dpcm[stream].runtime = NULL;
277 snd_soc_link_compr_shutdown(cstream);
279 soc_compr_components_free(cstream, NULL);
281 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
283 mutex_unlock(&fe->card->mutex);
287 static int soc_compr_components_trigger(struct snd_compr_stream *cstream,
290 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
291 struct snd_soc_component *component;
294 for_each_rtd_components(rtd, i, component) {
295 if (!component->driver->compress_ops ||
296 !component->driver->compress_ops->trigger)
299 ret = component->driver->compress_ops->trigger(
300 component, cstream, cmd);
308 static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
310 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
311 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
312 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
316 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
318 if (cstream->direction == SND_COMPRESS_PLAYBACK)
319 stream = SNDRV_PCM_STREAM_PLAYBACK;
321 stream = SNDRV_PCM_STREAM_CAPTURE;
323 ret = soc_compr_components_trigger(cstream, cmd);
327 ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
332 case SNDRV_PCM_TRIGGER_START:
333 snd_soc_dai_digital_mute(codec_dai, 0, stream);
335 case SNDRV_PCM_TRIGGER_STOP:
336 snd_soc_dai_digital_mute(codec_dai, 1, stream);
341 mutex_unlock(&rtd->card->pcm_mutex);
345 static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
347 struct snd_soc_pcm_runtime *fe = cstream->private_data;
348 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
351 if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
352 cmd == SND_COMPR_TRIGGER_DRAIN)
353 return soc_compr_components_trigger(cstream, cmd);
355 if (cstream->direction == SND_COMPRESS_PLAYBACK)
356 stream = SNDRV_PCM_STREAM_PLAYBACK;
358 stream = SNDRV_PCM_STREAM_CAPTURE;
360 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
362 ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
366 ret = soc_compr_components_trigger(cstream, cmd);
370 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
372 ret = dpcm_be_dai_trigger(fe, stream, cmd);
375 case SNDRV_PCM_TRIGGER_START:
376 case SNDRV_PCM_TRIGGER_RESUME:
377 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
378 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
380 case SNDRV_PCM_TRIGGER_STOP:
381 case SNDRV_PCM_TRIGGER_SUSPEND:
382 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
384 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
385 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
390 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
391 mutex_unlock(&fe->card->mutex);
395 static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
396 struct snd_compr_params *params)
398 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
399 struct snd_soc_component *component;
402 for_each_rtd_components(rtd, i, component) {
403 if (!component->driver->compress_ops ||
404 !component->driver->compress_ops->set_params)
407 ret = component->driver->compress_ops->set_params(
408 component, cstream, params);
416 static int soc_compr_set_params(struct snd_compr_stream *cstream,
417 struct snd_compr_params *params)
419 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
420 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
423 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
426 * First we call set_params for the CPU DAI, then the component
427 * driver this should configure the SoC side. If the machine has
428 * compressed ops then we call that as well. The expectation is
429 * that these callbacks will configure everything for this compress
430 * path, like configuring a PCM port for a CODEC.
432 ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
436 ret = soc_compr_components_set_params(cstream, params);
440 ret = snd_soc_link_compr_set_params(cstream);
444 if (cstream->direction == SND_COMPRESS_PLAYBACK)
445 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
446 SND_SOC_DAPM_STREAM_START);
448 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
449 SND_SOC_DAPM_STREAM_START);
451 /* cancel any delayed stream shutdown that is pending */
453 mutex_unlock(&rtd->card->pcm_mutex);
455 cancel_delayed_work_sync(&rtd->delayed_work);
460 mutex_unlock(&rtd->card->pcm_mutex);
464 static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
465 struct snd_compr_params *params)
467 struct snd_soc_pcm_runtime *fe = cstream->private_data;
468 struct snd_pcm_substream *fe_substream =
469 fe->pcm->streams[cstream->direction].substream;
470 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
473 if (cstream->direction == SND_COMPRESS_PLAYBACK)
474 stream = SNDRV_PCM_STREAM_PLAYBACK;
476 stream = SNDRV_PCM_STREAM_CAPTURE;
478 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
481 * Create an empty hw_params for the BE as the machine driver must
482 * fix this up to match DSP decoder and ASRC configuration.
483 * I.e. machine driver fixup for compressed BE is mandatory.
485 memset(&fe->dpcm[fe_substream->stream].hw_params, 0,
486 sizeof(struct snd_pcm_hw_params));
488 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
490 ret = dpcm_be_dai_hw_params(fe, stream);
494 ret = dpcm_be_dai_prepare(fe, stream);
498 ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
502 ret = soc_compr_components_set_params(cstream, params);
506 ret = snd_soc_link_compr_set_params(cstream);
510 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
511 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
514 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
515 mutex_unlock(&fe->card->mutex);
519 static int soc_compr_get_params(struct snd_compr_stream *cstream,
520 struct snd_codec *params)
522 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
523 struct snd_soc_component *component;
524 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
527 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
529 ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
533 for_each_rtd_components(rtd, i, component) {
534 if (!component->driver->compress_ops ||
535 !component->driver->compress_ops->get_params)
538 ret = component->driver->compress_ops->get_params(
539 component, cstream, params);
544 mutex_unlock(&rtd->card->pcm_mutex);
548 static int soc_compr_get_caps(struct snd_compr_stream *cstream,
549 struct snd_compr_caps *caps)
551 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
552 struct snd_soc_component *component;
555 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
557 for_each_rtd_components(rtd, i, component) {
558 if (!component->driver->compress_ops ||
559 !component->driver->compress_ops->get_caps)
562 ret = component->driver->compress_ops->get_caps(
563 component, cstream, caps);
567 mutex_unlock(&rtd->card->pcm_mutex);
571 static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
572 struct snd_compr_codec_caps *codec)
574 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
575 struct snd_soc_component *component;
578 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
580 for_each_rtd_components(rtd, i, component) {
581 if (!component->driver->compress_ops ||
582 !component->driver->compress_ops->get_codec_caps)
585 ret = component->driver->compress_ops->get_codec_caps(
586 component, cstream, codec);
590 mutex_unlock(&rtd->card->pcm_mutex);
594 static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
596 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
597 struct snd_soc_component *component;
598 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
601 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
603 ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
607 for_each_rtd_components(rtd, i, component) {
608 if (!component->driver->compress_ops ||
609 !component->driver->compress_ops->ack)
612 ret = component->driver->compress_ops->ack(
613 component, cstream, bytes);
619 mutex_unlock(&rtd->card->pcm_mutex);
623 static int soc_compr_pointer(struct snd_compr_stream *cstream,
624 struct snd_compr_tstamp *tstamp)
626 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
627 struct snd_soc_component *component;
629 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
631 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
633 ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
637 for_each_rtd_components(rtd, i, component) {
638 if (!component->driver->compress_ops ||
639 !component->driver->compress_ops->pointer)
642 ret = component->driver->compress_ops->pointer(
643 component, cstream, tstamp);
647 mutex_unlock(&rtd->card->pcm_mutex);
651 static int soc_compr_copy(struct snd_compr_stream *cstream,
652 char __user *buf, size_t count)
654 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
655 struct snd_soc_component *component;
658 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
660 for_each_rtd_components(rtd, i, component) {
661 if (!component->driver->compress_ops ||
662 !component->driver->compress_ops->copy)
665 ret = component->driver->compress_ops->copy(
666 component, cstream, buf, count);
670 mutex_unlock(&rtd->card->pcm_mutex);
674 static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
675 struct snd_compr_metadata *metadata)
677 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
678 struct snd_soc_component *component;
679 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
682 ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata);
686 for_each_rtd_components(rtd, i, component) {
687 if (!component->driver->compress_ops ||
688 !component->driver->compress_ops->set_metadata)
691 ret = component->driver->compress_ops->set_metadata(
692 component, cstream, metadata);
700 static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
701 struct snd_compr_metadata *metadata)
703 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
704 struct snd_soc_component *component;
705 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
708 ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata);
712 for_each_rtd_components(rtd, i, component) {
713 if (!component->driver->compress_ops ||
714 !component->driver->compress_ops->get_metadata)
717 return component->driver->compress_ops->get_metadata(
718 component, cstream, metadata);
724 /* ASoC Compress operations */
725 static struct snd_compr_ops soc_compr_ops = {
726 .open = soc_compr_open,
727 .free = soc_compr_free,
728 .set_params = soc_compr_set_params,
729 .set_metadata = soc_compr_set_metadata,
730 .get_metadata = soc_compr_get_metadata,
731 .get_params = soc_compr_get_params,
732 .trigger = soc_compr_trigger,
733 .pointer = soc_compr_pointer,
734 .ack = soc_compr_ack,
735 .get_caps = soc_compr_get_caps,
736 .get_codec_caps = soc_compr_get_codec_caps
739 /* ASoC Dynamic Compress operations */
740 static struct snd_compr_ops soc_compr_dyn_ops = {
741 .open = soc_compr_open_fe,
742 .free = soc_compr_free_fe,
743 .set_params = soc_compr_set_params_fe,
744 .get_params = soc_compr_get_params,
745 .set_metadata = soc_compr_set_metadata,
746 .get_metadata = soc_compr_get_metadata,
747 .trigger = soc_compr_trigger_fe,
748 .pointer = soc_compr_pointer,
749 .ack = soc_compr_ack,
750 .get_caps = soc_compr_get_caps,
751 .get_codec_caps = soc_compr_get_codec_caps
755 * snd_soc_new_compress - create a new compress.
757 * @rtd: The runtime for which we will create compress
758 * @num: the device index number (zero based - shared with normal PCMs)
760 * Return: 0 for success, else error.
762 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
764 struct snd_soc_component *component;
765 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
766 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
767 struct snd_compr *compr;
768 struct snd_pcm *be_pcm;
770 int ret = 0, direction = 0;
771 int playback = 0, capture = 0;
774 if (rtd->num_cpus > 1 ||
775 rtd->num_codecs > 1) {
776 dev_err(rtd->card->dev,
777 "Compress ASoC: Multi CPU/Codec not supported\n");
781 /* check client and interface hw capabilities */
782 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
783 snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
785 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
786 snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE))
790 * Compress devices are unidirectional so only one of the directions
791 * should be set, check for that (xor)
793 if (playback + capture != 1) {
794 dev_err(rtd->card->dev,
795 "Compress ASoC: Invalid direction for P %d, C %d\n",
801 direction = SND_COMPRESS_PLAYBACK;
803 direction = SND_COMPRESS_CAPTURE;
805 compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL);
809 compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops),
814 if (rtd->dai_link->dynamic) {
815 snprintf(new_name, sizeof(new_name), "(%s)",
816 rtd->dai_link->stream_name);
818 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
819 rtd->dai_link->dpcm_playback,
820 rtd->dai_link->dpcm_capture, &be_pcm);
822 dev_err(rtd->card->dev,
823 "Compress ASoC: can't create compressed for %s: %d\n",
824 rtd->dai_link->name, ret);
830 if (rtd->dai_link->dpcm_playback)
831 be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
832 else if (rtd->dai_link->dpcm_capture)
833 be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
834 memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops));
836 snprintf(new_name, sizeof(new_name), "%s %s-%d",
837 rtd->dai_link->stream_name, codec_dai->name, num);
839 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
842 for_each_rtd_components(rtd, i, component) {
843 if (!component->driver->compress_ops ||
844 !component->driver->compress_ops->copy)
847 compr->ops->copy = soc_compr_copy;
851 mutex_init(&compr->lock);
852 ret = snd_compress_new(rtd->card->snd_card, num, direction,
855 component = asoc_rtd_to_codec(rtd, 0)->component;
856 dev_err(component->dev,
857 "Compress ASoC: can't create compress for codec %s: %d\n",
858 component->name, ret);
862 /* DAPM dai link stream work */
863 rtd->close_delayed_work_func = snd_soc_close_delayed_work;
866 compr->private_data = rtd;
868 dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
869 codec_dai->name, cpu_dai->name);
873 EXPORT_SYMBOL_GPL(snd_soc_new_compress);