2 * soc-compress.c -- ALSA SoC Compress
4 * Copyright (C) 2012 Intel Corp.
6 * Authors: Namarta Kohli <namartax.kohli@intel.com>
7 * Ramesh Babu K V <ramesh.babu@linux.intel.com>
8 * Vinod Koul <vinod.koul@linux.intel.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/workqueue.h>
22 #include <sound/core.h>
23 #include <sound/compress_params.h>
24 #include <sound/compress_driver.h>
25 #include <sound/soc.h>
26 #include <sound/initval.h>
27 #include <sound/soc-dpcm.h>
29 static int soc_compr_open(struct snd_compr_stream
*cstream
)
31 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
32 struct snd_soc_platform
*platform
= rtd
->platform
;
33 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
34 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
37 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
39 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->open
) {
40 ret
= platform
->driver
->compr_ops
->open(cstream
);
42 pr_err("compress asoc: can't open platform %s\n", platform
->name
);
47 if (rtd
->dai_link
->compr_ops
&& rtd
->dai_link
->compr_ops
->startup
) {
48 ret
= rtd
->dai_link
->compr_ops
->startup(cstream
);
50 pr_err("compress asoc: %s startup failed\n", rtd
->dai_link
->name
);
55 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
) {
56 cpu_dai
->playback_active
++;
57 codec_dai
->playback_active
++;
59 cpu_dai
->capture_active
++;
60 codec_dai
->capture_active
++;
67 mutex_unlock(&rtd
->pcm_mutex
);
72 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->free
)
73 platform
->driver
->compr_ops
->free(cstream
);
75 mutex_unlock(&rtd
->pcm_mutex
);
79 static int soc_compr_open_fe(struct snd_compr_stream
*cstream
)
81 struct snd_soc_pcm_runtime
*fe
= cstream
->private_data
;
82 struct snd_pcm_substream
*fe_substream
= fe
->pcm
->streams
[0].substream
;
83 struct snd_soc_platform
*platform
= fe
->platform
;
84 struct snd_soc_dai
*cpu_dai
= fe
->cpu_dai
;
85 struct snd_soc_dai
*codec_dai
= fe
->codec_dai
;
86 struct snd_soc_dpcm
*dpcm
;
87 struct snd_soc_dapm_widget_list
*list
;
91 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
)
92 stream
= SNDRV_PCM_STREAM_PLAYBACK
;
94 stream
= SNDRV_PCM_STREAM_CAPTURE
;
96 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
98 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->open
) {
99 ret
= platform
->driver
->compr_ops
->open(cstream
);
101 pr_err("compress asoc: can't open platform %s\n", platform
->name
);
106 if (fe
->dai_link
->compr_ops
&& fe
->dai_link
->compr_ops
->startup
) {
107 ret
= fe
->dai_link
->compr_ops
->startup(cstream
);
109 pr_err("compress asoc: %s startup failed\n", fe
->dai_link
->name
);
114 fe
->dpcm
[stream
].runtime
= fe_substream
->runtime
;
116 if (dpcm_path_get(fe
, stream
, &list
) <= 0) {
117 dev_dbg(fe
->dev
, "ASoC: %s no valid %s route\n",
118 fe
->dai_link
->name
, stream
? "capture" : "playback");
121 /* calculate valid and active FE <-> BE dpcms */
122 dpcm_process_paths(fe
, stream
, &list
, 1);
124 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
126 ret
= dpcm_be_dai_startup(fe
, stream
);
128 /* clean up all links */
129 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
)
130 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
132 dpcm_be_disconnect(fe
, stream
);
133 fe
->dpcm
[stream
].runtime
= NULL
;
137 dpcm_clear_pending_state(fe
, stream
);
138 dpcm_path_put(&list
);
140 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_OPEN
;
141 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
143 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
) {
144 cpu_dai
->playback_active
++;
145 codec_dai
->playback_active
++;
147 cpu_dai
->capture_active
++;
148 codec_dai
->capture_active
++;
155 mutex_unlock(&fe
->card
->mutex
);
160 if (fe
->dai_link
->compr_ops
&& fe
->dai_link
->compr_ops
->shutdown
)
161 fe
->dai_link
->compr_ops
->shutdown(cstream
);
163 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->free
)
164 platform
->driver
->compr_ops
->free(cstream
);
166 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
167 mutex_unlock(&fe
->card
->mutex
);
172 * Power down the audio subsystem pmdown_time msecs after close is called.
173 * This is to ensure there are no pops or clicks in between any music tracks
174 * due to DAPM power cycling.
176 static void close_delayed_work(struct work_struct
*work
)
178 struct snd_soc_pcm_runtime
*rtd
=
179 container_of(work
, struct snd_soc_pcm_runtime
, delayed_work
.work
);
180 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
182 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
184 dev_dbg(rtd
->dev
, "ASoC: pop wq checking: %s status: %s waiting: %s\n",
185 codec_dai
->driver
->playback
.stream_name
,
186 codec_dai
->playback_active
? "active" : "inactive",
187 rtd
->pop_wait
? "yes" : "no");
189 /* are we waiting on this codec DAI stream */
190 if (rtd
->pop_wait
== 1) {
192 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_PLAYBACK
,
193 SND_SOC_DAPM_STREAM_STOP
);
196 mutex_unlock(&rtd
->pcm_mutex
);
199 static int soc_compr_free(struct snd_compr_stream
*cstream
)
201 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
202 struct snd_soc_platform
*platform
= rtd
->platform
;
203 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
204 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
205 struct snd_soc_codec
*codec
= rtd
->codec
;
207 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
209 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
) {
210 cpu_dai
->playback_active
--;
211 codec_dai
->playback_active
--;
213 cpu_dai
->capture_active
--;
214 codec_dai
->capture_active
--;
217 snd_soc_dai_digital_mute(codec_dai
, 1, cstream
->direction
);
223 if (!cpu_dai
->active
)
226 if (!codec_dai
->active
)
230 if (rtd
->dai_link
->compr_ops
&& rtd
->dai_link
->compr_ops
->shutdown
)
231 rtd
->dai_link
->compr_ops
->shutdown(cstream
);
233 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->free
)
234 platform
->driver
->compr_ops
->free(cstream
);
235 cpu_dai
->runtime
= NULL
;
237 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
) {
238 if (!rtd
->pmdown_time
|| codec
->ignore_pmdown_time
||
239 rtd
->dai_link
->ignore_pmdown_time
) {
240 snd_soc_dapm_stream_event(rtd
,
241 SNDRV_PCM_STREAM_PLAYBACK
,
242 SND_SOC_DAPM_STREAM_STOP
);
245 queue_delayed_work(system_power_efficient_wq
,
247 msecs_to_jiffies(rtd
->pmdown_time
));
250 /* capture streams can be powered down now */
251 snd_soc_dapm_stream_event(rtd
,
252 SNDRV_PCM_STREAM_CAPTURE
,
253 SND_SOC_DAPM_STREAM_STOP
);
256 mutex_unlock(&rtd
->pcm_mutex
);
260 static int soc_compr_free_fe(struct snd_compr_stream
*cstream
)
262 struct snd_soc_pcm_runtime
*fe
= cstream
->private_data
;
263 struct snd_soc_platform
*platform
= fe
->platform
;
264 struct snd_soc_dai
*cpu_dai
= fe
->cpu_dai
;
265 struct snd_soc_dai
*codec_dai
= fe
->codec_dai
;
266 struct snd_soc_dpcm
*dpcm
;
269 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
271 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
) {
272 stream
= SNDRV_PCM_STREAM_PLAYBACK
;
273 cpu_dai
->playback_active
--;
274 codec_dai
->playback_active
--;
276 stream
= SNDRV_PCM_STREAM_CAPTURE
;
277 cpu_dai
->capture_active
--;
278 codec_dai
->capture_active
--;
285 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
287 ret
= dpcm_be_dai_hw_free(fe
, stream
);
289 dev_err(fe
->dev
, "compressed hw_free failed %d\n", ret
);
291 ret
= dpcm_be_dai_shutdown(fe
, stream
);
293 /* mark FE's links ready to prune */
294 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
)
295 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
297 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
298 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_STOP
);
300 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_STOP
);
302 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
303 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
305 dpcm_be_disconnect(fe
, stream
);
307 fe
->dpcm
[stream
].runtime
= NULL
;
309 if (fe
->dai_link
->compr_ops
&& fe
->dai_link
->compr_ops
->shutdown
)
310 fe
->dai_link
->compr_ops
->shutdown(cstream
);
312 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->free
)
313 platform
->driver
->compr_ops
->free(cstream
);
315 mutex_unlock(&fe
->card
->mutex
);
319 static int soc_compr_trigger(struct snd_compr_stream
*cstream
, int cmd
)
322 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
323 struct snd_soc_platform
*platform
= rtd
->platform
;
324 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
327 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
329 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->trigger
) {
330 ret
= platform
->driver
->compr_ops
->trigger(cstream
, cmd
);
336 case SNDRV_PCM_TRIGGER_START
:
337 snd_soc_dai_digital_mute(codec_dai
, 0, cstream
->direction
);
339 case SNDRV_PCM_TRIGGER_STOP
:
340 snd_soc_dai_digital_mute(codec_dai
, 1, cstream
->direction
);
345 mutex_unlock(&rtd
->pcm_mutex
);
349 static int soc_compr_trigger_fe(struct snd_compr_stream
*cstream
, int cmd
)
351 struct snd_soc_pcm_runtime
*fe
= cstream
->private_data
;
352 struct snd_soc_platform
*platform
= fe
->platform
;
355 if (cmd
== SND_COMPR_TRIGGER_PARTIAL_DRAIN
||
356 cmd
== SND_COMPR_TRIGGER_DRAIN
) {
358 if (platform
->driver
->compr_ops
&&
359 platform
->driver
->compr_ops
->trigger
)
360 return platform
->driver
->compr_ops
->trigger(cstream
, cmd
);
363 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
)
364 stream
= SNDRV_PCM_STREAM_PLAYBACK
;
366 stream
= SNDRV_PCM_STREAM_CAPTURE
;
369 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
371 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->trigger
) {
372 ret
= platform
->driver
->compr_ops
->trigger(cstream
, cmd
);
377 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
379 ret
= dpcm_be_dai_trigger(fe
, stream
, cmd
);
382 case SNDRV_PCM_TRIGGER_START
:
383 case SNDRV_PCM_TRIGGER_RESUME
:
384 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
385 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_START
;
387 case SNDRV_PCM_TRIGGER_STOP
:
388 case SNDRV_PCM_TRIGGER_SUSPEND
:
389 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_STOP
;
391 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
392 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_PAUSED
;
397 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
398 mutex_unlock(&fe
->card
->mutex
);
402 static int soc_compr_set_params(struct snd_compr_stream
*cstream
,
403 struct snd_compr_params
*params
)
405 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
406 struct snd_soc_platform
*platform
= rtd
->platform
;
409 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
411 /* first we call set_params for the platform driver
412 * this should configure the soc side
413 * if the machine has compressed ops then we call that as well
414 * expectation is that platform and machine will configure everything
415 * for this compress path, like configuring pcm port for codec
417 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->set_params
) {
418 ret
= platform
->driver
->compr_ops
->set_params(cstream
, params
);
423 if (rtd
->dai_link
->compr_ops
&& rtd
->dai_link
->compr_ops
->set_params
) {
424 ret
= rtd
->dai_link
->compr_ops
->set_params(cstream
);
429 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
)
430 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_PLAYBACK
,
431 SND_SOC_DAPM_STREAM_START
);
433 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_CAPTURE
,
434 SND_SOC_DAPM_STREAM_START
);
436 /* cancel any delayed stream shutdown that is pending */
438 mutex_unlock(&rtd
->pcm_mutex
);
440 cancel_delayed_work_sync(&rtd
->delayed_work
);
445 mutex_unlock(&rtd
->pcm_mutex
);
449 static int soc_compr_set_params_fe(struct snd_compr_stream
*cstream
,
450 struct snd_compr_params
*params
)
452 struct snd_soc_pcm_runtime
*fe
= cstream
->private_data
;
453 struct snd_pcm_substream
*fe_substream
= fe
->pcm
->streams
[0].substream
;
454 struct snd_soc_platform
*platform
= fe
->platform
;
457 if (cstream
->direction
== SND_COMPRESS_PLAYBACK
)
458 stream
= SNDRV_PCM_STREAM_PLAYBACK
;
460 stream
= SNDRV_PCM_STREAM_CAPTURE
;
462 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
464 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->set_params
) {
465 ret
= platform
->driver
->compr_ops
->set_params(cstream
, params
);
470 if (fe
->dai_link
->compr_ops
&& fe
->dai_link
->compr_ops
->set_params
) {
471 ret
= fe
->dai_link
->compr_ops
->set_params(cstream
);
477 * Create an empty hw_params for the BE as the machine driver must
478 * fix this up to match DSP decoder and ASRC configuration.
479 * I.e. machine driver fixup for compressed BE is mandatory.
481 memset(&fe
->dpcm
[fe_substream
->stream
].hw_params
, 0,
482 sizeof(struct snd_pcm_hw_params
));
484 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
486 ret
= dpcm_be_dai_hw_params(fe
, stream
);
490 ret
= dpcm_be_dai_prepare(fe
, stream
);
494 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
495 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_START
);
497 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_START
);
499 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_PREPARE
;
502 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
503 mutex_unlock(&fe
->card
->mutex
);
507 static int soc_compr_get_params(struct snd_compr_stream
*cstream
,
508 struct snd_codec
*params
)
510 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
511 struct snd_soc_platform
*platform
= rtd
->platform
;
514 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
516 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->get_params
)
517 ret
= platform
->driver
->compr_ops
->get_params(cstream
, params
);
519 mutex_unlock(&rtd
->pcm_mutex
);
523 static int soc_compr_get_caps(struct snd_compr_stream
*cstream
,
524 struct snd_compr_caps
*caps
)
526 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
527 struct snd_soc_platform
*platform
= rtd
->platform
;
530 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
532 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->get_caps
)
533 ret
= platform
->driver
->compr_ops
->get_caps(cstream
, caps
);
535 mutex_unlock(&rtd
->pcm_mutex
);
539 static int soc_compr_get_codec_caps(struct snd_compr_stream
*cstream
,
540 struct snd_compr_codec_caps
*codec
)
542 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
543 struct snd_soc_platform
*platform
= rtd
->platform
;
546 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
548 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->get_codec_caps
)
549 ret
= platform
->driver
->compr_ops
->get_codec_caps(cstream
, codec
);
551 mutex_unlock(&rtd
->pcm_mutex
);
555 static int soc_compr_ack(struct snd_compr_stream
*cstream
, size_t bytes
)
557 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
558 struct snd_soc_platform
*platform
= rtd
->platform
;
561 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
563 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->ack
)
564 ret
= platform
->driver
->compr_ops
->ack(cstream
, bytes
);
566 mutex_unlock(&rtd
->pcm_mutex
);
570 static int soc_compr_pointer(struct snd_compr_stream
*cstream
,
571 struct snd_compr_tstamp
*tstamp
)
573 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
574 struct snd_soc_platform
*platform
= rtd
->platform
;
576 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
578 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->pointer
)
579 platform
->driver
->compr_ops
->pointer(cstream
, tstamp
);
581 mutex_unlock(&rtd
->pcm_mutex
);
585 static int soc_compr_copy(struct snd_compr_stream
*cstream
,
586 char __user
*buf
, size_t count
)
588 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
589 struct snd_soc_platform
*platform
= rtd
->platform
;
592 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
594 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->copy
)
595 ret
= platform
->driver
->compr_ops
->copy(cstream
, buf
, count
);
597 mutex_unlock(&rtd
->pcm_mutex
);
601 static int soc_compr_set_metadata(struct snd_compr_stream
*cstream
,
602 struct snd_compr_metadata
*metadata
)
604 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
605 struct snd_soc_platform
*platform
= rtd
->platform
;
608 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->set_metadata
)
609 ret
= platform
->driver
->compr_ops
->set_metadata(cstream
, metadata
);
614 static int soc_compr_get_metadata(struct snd_compr_stream
*cstream
,
615 struct snd_compr_metadata
*metadata
)
617 struct snd_soc_pcm_runtime
*rtd
= cstream
->private_data
;
618 struct snd_soc_platform
*platform
= rtd
->platform
;
621 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->get_metadata
)
622 ret
= platform
->driver
->compr_ops
->get_metadata(cstream
, metadata
);
627 /* ASoC Compress operations */
628 static struct snd_compr_ops soc_compr_ops
= {
629 .open
= soc_compr_open
,
630 .free
= soc_compr_free
,
631 .set_params
= soc_compr_set_params
,
632 .set_metadata
= soc_compr_set_metadata
,
633 .get_metadata
= soc_compr_get_metadata
,
634 .get_params
= soc_compr_get_params
,
635 .trigger
= soc_compr_trigger
,
636 .pointer
= soc_compr_pointer
,
637 .ack
= soc_compr_ack
,
638 .get_caps
= soc_compr_get_caps
,
639 .get_codec_caps
= soc_compr_get_codec_caps
642 /* ASoC Dynamic Compress operations */
643 static struct snd_compr_ops soc_compr_dyn_ops
= {
644 .open
= soc_compr_open_fe
,
645 .free
= soc_compr_free_fe
,
646 .set_params
= soc_compr_set_params_fe
,
647 .get_params
= soc_compr_get_params
,
648 .set_metadata
= soc_compr_set_metadata
,
649 .get_metadata
= soc_compr_get_metadata
,
650 .trigger
= soc_compr_trigger_fe
,
651 .pointer
= soc_compr_pointer
,
652 .ack
= soc_compr_ack
,
653 .get_caps
= soc_compr_get_caps
,
654 .get_codec_caps
= soc_compr_get_codec_caps
657 /* create a new compress */
658 int soc_new_compress(struct snd_soc_pcm_runtime
*rtd
, int num
)
660 struct snd_soc_codec
*codec
= rtd
->codec
;
661 struct snd_soc_platform
*platform
= rtd
->platform
;
662 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
663 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
664 struct snd_compr
*compr
;
665 struct snd_pcm
*be_pcm
;
667 int ret
= 0, direction
= 0;
669 /* check client and interface hw capabilities */
670 snprintf(new_name
, sizeof(new_name
), "%s %s-%d",
671 rtd
->dai_link
->stream_name
, codec_dai
->name
, num
);
673 if (codec_dai
->driver
->playback
.channels_min
)
674 direction
= SND_COMPRESS_PLAYBACK
;
675 else if (codec_dai
->driver
->capture
.channels_min
)
676 direction
= SND_COMPRESS_CAPTURE
;
680 compr
= kzalloc(sizeof(*compr
), GFP_KERNEL
);
682 snd_printk(KERN_ERR
"Cannot allocate compr\n");
686 compr
->ops
= devm_kzalloc(rtd
->card
->dev
, sizeof(soc_compr_ops
),
688 if (compr
->ops
== NULL
) {
689 dev_err(rtd
->card
->dev
, "Cannot allocate compressed ops\n");
694 if (rtd
->dai_link
->dynamic
) {
695 snprintf(new_name
, sizeof(new_name
), "(%s)",
696 rtd
->dai_link
->stream_name
);
698 ret
= snd_pcm_new_internal(rtd
->card
->snd_card
, new_name
, num
,
701 dev_err(rtd
->card
->dev
, "ASoC: can't create compressed for %s\n",
702 rtd
->dai_link
->name
);
708 be_pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
->private_data
= rtd
;
709 be_pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
->private_data
= rtd
;
710 memcpy(compr
->ops
, &soc_compr_dyn_ops
, sizeof(soc_compr_dyn_ops
));
712 memcpy(compr
->ops
, &soc_compr_ops
, sizeof(soc_compr_ops
));
714 /* Add copy callback for not memory mapped DSPs */
715 if (platform
->driver
->compr_ops
&& platform
->driver
->compr_ops
->copy
)
716 compr
->ops
->copy
= soc_compr_copy
;
718 mutex_init(&compr
->lock
);
719 ret
= snd_compress_new(rtd
->card
->snd_card
, num
, direction
, compr
);
721 pr_err("compress asoc: can't create compress for codec %s\n",
726 /* DAPM dai link stream work */
727 INIT_DELAYED_WORK(&rtd
->delayed_work
, close_delayed_work
);
730 compr
->private_data
= rtd
;
732 printk(KERN_INFO
"compress asoc: %s <-> %s mapping ok\n", codec_dai
->name
,