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);
78 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
81 ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
85 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
87 ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
91 ret = soc_compr_components_open(cstream, &component);
95 ret = snd_soc_link_compr_startup(cstream);
99 snd_soc_runtime_activate(rtd, stream);
101 mutex_unlock(&rtd->card->pcm_mutex);
106 soc_compr_components_free(cstream, component);
108 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
110 mutex_unlock(&rtd->card->pcm_mutex);
112 snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1);
117 static int soc_compr_open_fe(struct snd_compr_stream *cstream)
119 struct snd_soc_pcm_runtime *fe = cstream->private_data;
120 struct snd_pcm_substream *fe_substream =
121 fe->pcm->streams[cstream->direction].substream;
122 struct snd_soc_component *component;
123 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
124 struct snd_soc_dpcm *dpcm;
125 struct snd_soc_dapm_widget_list *list;
126 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
129 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
130 fe->dpcm[stream].runtime = fe_substream->runtime;
132 ret = dpcm_path_get(fe, stream, &list);
136 dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n",
137 fe->dai_link->name, stream ? "capture" : "playback");
138 /* calculate valid and active FE <-> BE dpcms */
139 dpcm_process_paths(fe, stream, &list, 1);
140 fe->dpcm[stream].runtime = fe_substream->runtime;
142 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
144 ret = dpcm_be_dai_startup(fe, stream);
146 /* clean up all links */
147 for_each_dpcm_be(fe, stream, dpcm)
148 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
150 dpcm_be_disconnect(fe, stream);
151 fe->dpcm[stream].runtime = NULL;
155 ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
159 ret = soc_compr_components_open(cstream, &component);
163 ret = snd_soc_link_compr_startup(cstream);
167 dpcm_clear_pending_state(fe, stream);
168 dpcm_path_put(&list);
170 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
171 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
173 snd_soc_runtime_activate(fe, stream);
175 mutex_unlock(&fe->card->mutex);
180 soc_compr_components_free(cstream, component);
182 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
184 dpcm_path_put(&list);
186 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
187 mutex_unlock(&fe->card->mutex);
191 static int soc_compr_free(struct snd_compr_stream *cstream)
193 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
194 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
195 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
196 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
198 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
200 snd_soc_runtime_deactivate(rtd, stream);
202 snd_soc_dai_digital_mute(codec_dai, 1, stream);
204 if (!snd_soc_dai_active(cpu_dai))
207 if (!snd_soc_dai_active(codec_dai))
210 snd_soc_link_compr_shutdown(cstream);
212 soc_compr_components_free(cstream, NULL);
214 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
216 snd_soc_dapm_stream_stop(rtd, stream);
218 mutex_unlock(&rtd->card->pcm_mutex);
220 snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0);
225 static int soc_compr_free_fe(struct snd_compr_stream *cstream)
227 struct snd_soc_pcm_runtime *fe = cstream->private_data;
228 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
229 struct snd_soc_dpcm *dpcm;
230 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
233 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
235 snd_soc_runtime_deactivate(fe, stream);
237 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
239 ret = dpcm_be_dai_hw_free(fe, stream);
241 dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret);
243 ret = dpcm_be_dai_shutdown(fe, stream);
245 /* mark FE's links ready to prune */
246 for_each_dpcm_be(fe, stream, dpcm)
247 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
249 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
251 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
252 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
254 dpcm_be_disconnect(fe, stream);
256 fe->dpcm[stream].runtime = NULL;
258 snd_soc_link_compr_shutdown(cstream);
260 soc_compr_components_free(cstream, NULL);
262 snd_soc_dai_compr_shutdown(cpu_dai, cstream);
264 mutex_unlock(&fe->card->mutex);
268 static int soc_compr_components_trigger(struct snd_compr_stream *cstream,
271 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
272 struct snd_soc_component *component;
275 for_each_rtd_components(rtd, i, component) {
276 if (!component->driver->compress_ops ||
277 !component->driver->compress_ops->trigger)
280 ret = component->driver->compress_ops->trigger(
281 component, cstream, cmd);
289 static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
291 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
292 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
293 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
294 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
297 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
299 ret = soc_compr_components_trigger(cstream, cmd);
303 ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
308 case SNDRV_PCM_TRIGGER_START:
309 snd_soc_dai_digital_mute(codec_dai, 0, stream);
311 case SNDRV_PCM_TRIGGER_STOP:
312 snd_soc_dai_digital_mute(codec_dai, 1, stream);
317 mutex_unlock(&rtd->card->pcm_mutex);
321 static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
323 struct snd_soc_pcm_runtime *fe = cstream->private_data;
324 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
325 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
328 if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
329 cmd == SND_COMPR_TRIGGER_DRAIN)
330 return soc_compr_components_trigger(cstream, cmd);
332 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
334 ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
338 ret = soc_compr_components_trigger(cstream, cmd);
342 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
344 ret = dpcm_be_dai_trigger(fe, stream, cmd);
347 case SNDRV_PCM_TRIGGER_START:
348 case SNDRV_PCM_TRIGGER_RESUME:
349 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
350 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
352 case SNDRV_PCM_TRIGGER_STOP:
353 case SNDRV_PCM_TRIGGER_SUSPEND:
354 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
356 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
357 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
362 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
363 mutex_unlock(&fe->card->mutex);
367 static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
368 struct snd_compr_params *params)
370 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
371 struct snd_soc_component *component;
374 for_each_rtd_components(rtd, i, component) {
375 if (!component->driver->compress_ops ||
376 !component->driver->compress_ops->set_params)
379 ret = component->driver->compress_ops->set_params(
380 component, cstream, params);
388 static int soc_compr_set_params(struct snd_compr_stream *cstream,
389 struct snd_compr_params *params)
391 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
392 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
393 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
396 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
399 * First we call set_params for the CPU DAI, then the component
400 * driver this should configure the SoC side. If the machine has
401 * compressed ops then we call that as well. The expectation is
402 * that these callbacks will configure everything for this compress
403 * path, like configuring a PCM port for a CODEC.
405 ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
409 ret = soc_compr_components_set_params(cstream, params);
413 ret = snd_soc_link_compr_set_params(cstream);
417 snd_soc_dapm_stream_event(rtd, stream, SND_SOC_DAPM_STREAM_START);
419 /* cancel any delayed stream shutdown that is pending */
421 mutex_unlock(&rtd->card->pcm_mutex);
423 cancel_delayed_work_sync(&rtd->delayed_work);
428 mutex_unlock(&rtd->card->pcm_mutex);
432 static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
433 struct snd_compr_params *params)
435 struct snd_soc_pcm_runtime *fe = cstream->private_data;
436 struct snd_pcm_substream *fe_substream =
437 fe->pcm->streams[cstream->direction].substream;
438 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
439 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
442 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
445 * Create an empty hw_params for the BE as the machine driver must
446 * fix this up to match DSP decoder and ASRC configuration.
447 * I.e. machine driver fixup for compressed BE is mandatory.
449 memset(&fe->dpcm[fe_substream->stream].hw_params, 0,
450 sizeof(struct snd_pcm_hw_params));
452 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
454 ret = dpcm_be_dai_hw_params(fe, stream);
458 ret = dpcm_be_dai_prepare(fe, stream);
462 ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
466 ret = soc_compr_components_set_params(cstream, params);
470 ret = snd_soc_link_compr_set_params(cstream);
474 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
475 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
478 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
479 mutex_unlock(&fe->card->mutex);
483 static int soc_compr_get_params(struct snd_compr_stream *cstream,
484 struct snd_codec *params)
486 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
487 struct snd_soc_component *component;
488 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
491 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
493 ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
497 for_each_rtd_components(rtd, i, component) {
498 if (!component->driver->compress_ops ||
499 !component->driver->compress_ops->get_params)
502 ret = component->driver->compress_ops->get_params(
503 component, cstream, params);
508 mutex_unlock(&rtd->card->pcm_mutex);
512 static int soc_compr_get_caps(struct snd_compr_stream *cstream,
513 struct snd_compr_caps *caps)
515 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
516 struct snd_soc_component *component;
519 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
521 for_each_rtd_components(rtd, i, component) {
522 if (!component->driver->compress_ops ||
523 !component->driver->compress_ops->get_caps)
526 ret = component->driver->compress_ops->get_caps(
527 component, cstream, caps);
531 mutex_unlock(&rtd->card->pcm_mutex);
535 static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
536 struct snd_compr_codec_caps *codec)
538 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
539 struct snd_soc_component *component;
542 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
544 for_each_rtd_components(rtd, i, component) {
545 if (!component->driver->compress_ops ||
546 !component->driver->compress_ops->get_codec_caps)
549 ret = component->driver->compress_ops->get_codec_caps(
550 component, cstream, codec);
554 mutex_unlock(&rtd->card->pcm_mutex);
558 static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
560 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
561 struct snd_soc_component *component;
562 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
565 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
567 ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
571 for_each_rtd_components(rtd, i, component) {
572 if (!component->driver->compress_ops ||
573 !component->driver->compress_ops->ack)
576 ret = component->driver->compress_ops->ack(
577 component, cstream, bytes);
583 mutex_unlock(&rtd->card->pcm_mutex);
587 static int soc_compr_pointer(struct snd_compr_stream *cstream,
588 struct snd_compr_tstamp *tstamp)
590 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
591 struct snd_soc_component *component;
593 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
595 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
597 ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
601 for_each_rtd_components(rtd, i, component) {
602 if (!component->driver->compress_ops ||
603 !component->driver->compress_ops->pointer)
606 ret = component->driver->compress_ops->pointer(
607 component, cstream, tstamp);
611 mutex_unlock(&rtd->card->pcm_mutex);
615 static int soc_compr_copy(struct snd_compr_stream *cstream,
616 char __user *buf, size_t count)
618 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
619 struct snd_soc_component *component;
622 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
624 for_each_rtd_components(rtd, i, component) {
625 if (!component->driver->compress_ops ||
626 !component->driver->compress_ops->copy)
629 ret = component->driver->compress_ops->copy(
630 component, cstream, buf, count);
634 mutex_unlock(&rtd->card->pcm_mutex);
638 static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
639 struct snd_compr_metadata *metadata)
641 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
642 struct snd_soc_component *component;
643 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
646 ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata);
650 for_each_rtd_components(rtd, i, component) {
651 if (!component->driver->compress_ops ||
652 !component->driver->compress_ops->set_metadata)
655 ret = component->driver->compress_ops->set_metadata(
656 component, cstream, metadata);
664 static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
665 struct snd_compr_metadata *metadata)
667 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
668 struct snd_soc_component *component;
669 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
672 ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata);
676 for_each_rtd_components(rtd, i, component) {
677 if (!component->driver->compress_ops ||
678 !component->driver->compress_ops->get_metadata)
681 return component->driver->compress_ops->get_metadata(
682 component, cstream, metadata);
688 /* ASoC Compress operations */
689 static struct snd_compr_ops soc_compr_ops = {
690 .open = soc_compr_open,
691 .free = soc_compr_free,
692 .set_params = soc_compr_set_params,
693 .set_metadata = soc_compr_set_metadata,
694 .get_metadata = soc_compr_get_metadata,
695 .get_params = soc_compr_get_params,
696 .trigger = soc_compr_trigger,
697 .pointer = soc_compr_pointer,
698 .ack = soc_compr_ack,
699 .get_caps = soc_compr_get_caps,
700 .get_codec_caps = soc_compr_get_codec_caps
703 /* ASoC Dynamic Compress operations */
704 static struct snd_compr_ops soc_compr_dyn_ops = {
705 .open = soc_compr_open_fe,
706 .free = soc_compr_free_fe,
707 .set_params = soc_compr_set_params_fe,
708 .get_params = soc_compr_get_params,
709 .set_metadata = soc_compr_set_metadata,
710 .get_metadata = soc_compr_get_metadata,
711 .trigger = soc_compr_trigger_fe,
712 .pointer = soc_compr_pointer,
713 .ack = soc_compr_ack,
714 .get_caps = soc_compr_get_caps,
715 .get_codec_caps = soc_compr_get_codec_caps
719 * snd_soc_new_compress - create a new compress.
721 * @rtd: The runtime for which we will create compress
722 * @num: the device index number (zero based - shared with normal PCMs)
724 * Return: 0 for success, else error.
726 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
728 struct snd_soc_component *component;
729 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
730 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
731 struct snd_compr *compr;
732 struct snd_pcm *be_pcm;
734 int ret = 0, direction = 0;
735 int playback = 0, capture = 0;
739 * make sure these are same value,
740 * and then use these as equally
742 BUILD_BUG_ON((int)SNDRV_PCM_STREAM_PLAYBACK != (int)SND_COMPRESS_PLAYBACK);
743 BUILD_BUG_ON((int)SNDRV_PCM_STREAM_CAPTURE != (int)SND_COMPRESS_CAPTURE);
745 if (rtd->num_cpus > 1 ||
746 rtd->num_codecs > 1) {
747 dev_err(rtd->card->dev,
748 "Compress ASoC: Multi CPU/Codec not supported\n");
752 /* check client and interface hw capabilities */
753 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
754 snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
756 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
757 snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE))
761 * Compress devices are unidirectional so only one of the directions
762 * should be set, check for that (xor)
764 if (playback + capture != 1) {
765 dev_err(rtd->card->dev,
766 "Compress ASoC: Invalid direction for P %d, C %d\n",
772 direction = SND_COMPRESS_PLAYBACK;
774 direction = SND_COMPRESS_CAPTURE;
776 compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL);
780 compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops),
785 if (rtd->dai_link->dynamic) {
786 snprintf(new_name, sizeof(new_name), "(%s)",
787 rtd->dai_link->stream_name);
789 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
790 rtd->dai_link->dpcm_playback,
791 rtd->dai_link->dpcm_capture, &be_pcm);
793 dev_err(rtd->card->dev,
794 "Compress ASoC: can't create compressed for %s: %d\n",
795 rtd->dai_link->name, ret);
801 if (rtd->dai_link->dpcm_playback)
802 be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
803 else if (rtd->dai_link->dpcm_capture)
804 be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
805 memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops));
807 snprintf(new_name, sizeof(new_name), "%s %s-%d",
808 rtd->dai_link->stream_name, codec_dai->name, num);
810 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
813 for_each_rtd_components(rtd, i, component) {
814 if (!component->driver->compress_ops ||
815 !component->driver->compress_ops->copy)
818 compr->ops->copy = soc_compr_copy;
822 mutex_init(&compr->lock);
823 ret = snd_compress_new(rtd->card->snd_card, num, direction,
826 component = asoc_rtd_to_codec(rtd, 0)->component;
827 dev_err(component->dev,
828 "Compress ASoC: can't create compress for codec %s: %d\n",
829 component->name, ret);
833 /* DAPM dai link stream work */
834 rtd->close_delayed_work_func = snd_soc_close_delayed_work;
837 compr->private_data = rtd;
839 dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
840 codec_dai->name, cpu_dai->name);
844 EXPORT_SYMBOL_GPL(snd_soc_new_compress);