diff options
Diffstat (limited to 'sound/soc/soc-compress.c')
-rw-r--r-- | sound/soc/soc-compress.c | 301 |
1 files changed, 300 insertions, 1 deletions
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 53c9ecdd119f..5e9690c85d8f 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <sound/compress_driver.h> | 24 | #include <sound/compress_driver.h> |
25 | #include <sound/soc.h> | 25 | #include <sound/soc.h> |
26 | #include <sound/initval.h> | 26 | #include <sound/initval.h> |
27 | #include <sound/soc-dpcm.h> | ||
27 | 28 | ||
28 | static int soc_compr_open(struct snd_compr_stream *cstream) | 29 | static int soc_compr_open(struct snd_compr_stream *cstream) |
29 | { | 30 | { |
@@ -75,6 +76,98 @@ out: | |||
75 | return ret; | 76 | return ret; |
76 | } | 77 | } |
77 | 78 | ||
79 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) | ||
80 | { | ||
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; | ||
88 | int stream; | ||
89 | int ret = 0; | ||
90 | |||
91 | if (cstream->direction == SND_COMPRESS_PLAYBACK) | ||
92 | stream = SNDRV_PCM_STREAM_PLAYBACK; | ||
93 | else | ||
94 | stream = SNDRV_PCM_STREAM_CAPTURE; | ||
95 | |||
96 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
97 | |||
98 | if (platform->driver->compr_ops && platform->driver->compr_ops->open) { | ||
99 | ret = platform->driver->compr_ops->open(cstream); | ||
100 | if (ret < 0) { | ||
101 | pr_err("compress asoc: can't open platform %s\n", platform->name); | ||
102 | goto out; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { | ||
107 | ret = fe->dai_link->compr_ops->startup(cstream); | ||
108 | if (ret < 0) { | ||
109 | pr_err("compress asoc: %s startup failed\n", fe->dai_link->name); | ||
110 | goto machine_err; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | fe->dpcm[stream].runtime = fe_substream->runtime; | ||
115 | |||
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"); | ||
119 | } | ||
120 | |||
121 | /* calculate valid and active FE <-> BE dpcms */ | ||
122 | dpcm_process_paths(fe, stream, &list, 1); | ||
123 | |||
124 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
125 | |||
126 | ret = dpcm_be_dai_startup(fe, stream); | ||
127 | if (ret < 0) { | ||
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; | ||
131 | |||
132 | dpcm_be_disconnect(fe, stream); | ||
133 | fe->dpcm[stream].runtime = NULL; | ||
134 | goto fe_err; | ||
135 | } | ||
136 | |||
137 | dpcm_clear_pending_state(fe, stream); | ||
138 | dpcm_path_put(&list); | ||
139 | |||
140 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; | ||
141 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
142 | |||
143 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { | ||
144 | cpu_dai->playback_active++; | ||
145 | codec_dai->playback_active++; | ||
146 | } else { | ||
147 | cpu_dai->capture_active++; | ||
148 | codec_dai->capture_active++; | ||
149 | } | ||
150 | |||
151 | cpu_dai->active++; | ||
152 | codec_dai->active++; | ||
153 | fe->codec->active++; | ||
154 | |||
155 | mutex_unlock(&fe->card->mutex); | ||
156 | |||
157 | return 0; | ||
158 | |||
159 | fe_err: | ||
160 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) | ||
161 | fe->dai_link->compr_ops->shutdown(cstream); | ||
162 | machine_err: | ||
163 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) | ||
164 | platform->driver->compr_ops->free(cstream); | ||
165 | out: | ||
166 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
167 | mutex_unlock(&fe->card->mutex); | ||
168 | return ret; | ||
169 | } | ||
170 | |||
78 | /* | 171 | /* |
79 | * Power down the audio subsystem pmdown_time msecs after close is called. | 172 | * Power down the audio subsystem pmdown_time msecs after close is called. |
80 | * This is to ensure there are no pops or clicks in between any music tracks | 173 | * This is to ensure there are no pops or clicks in between any music tracks |
@@ -164,6 +257,65 @@ static int soc_compr_free(struct snd_compr_stream *cstream) | |||
164 | return 0; | 257 | return 0; |
165 | } | 258 | } |
166 | 259 | ||
260 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) | ||
261 | { | ||
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; | ||
267 | int stream, ret; | ||
268 | |||
269 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
270 | |||
271 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { | ||
272 | stream = SNDRV_PCM_STREAM_PLAYBACK; | ||
273 | cpu_dai->playback_active--; | ||
274 | codec_dai->playback_active--; | ||
275 | } else { | ||
276 | stream = SNDRV_PCM_STREAM_CAPTURE; | ||
277 | cpu_dai->capture_active--; | ||
278 | codec_dai->capture_active--; | ||
279 | } | ||
280 | |||
281 | cpu_dai->active--; | ||
282 | codec_dai->active--; | ||
283 | fe->codec->active--; | ||
284 | |||
285 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
286 | |||
287 | ret = dpcm_be_dai_hw_free(fe, stream); | ||
288 | if (ret < 0) | ||
289 | dev_err(fe->dev, "compressed hw_free failed %d\n", ret); | ||
290 | |||
291 | ret = dpcm_be_dai_shutdown(fe, stream); | ||
292 | |||
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; | ||
296 | |||
297 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
298 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); | ||
299 | else | ||
300 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); | ||
301 | |||
302 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
303 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
304 | |||
305 | dpcm_be_disconnect(fe, stream); | ||
306 | |||
307 | fe->dpcm[stream].runtime = NULL; | ||
308 | |||
309 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) | ||
310 | fe->dai_link->compr_ops->shutdown(cstream); | ||
311 | |||
312 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) | ||
313 | platform->driver->compr_ops->free(cstream); | ||
314 | |||
315 | mutex_unlock(&fe->card->mutex); | ||
316 | return 0; | ||
317 | } | ||
318 | |||
167 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) | 319 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
168 | { | 320 | { |
169 | 321 | ||
@@ -194,6 +346,59 @@ out: | |||
194 | return ret; | 346 | return ret; |
195 | } | 347 | } |
196 | 348 | ||
349 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) | ||
350 | { | ||
351 | struct snd_soc_pcm_runtime *fe = cstream->private_data; | ||
352 | struct snd_soc_platform *platform = fe->platform; | ||
353 | int ret = 0, stream; | ||
354 | |||
355 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || | ||
356 | cmd == SND_COMPR_TRIGGER_DRAIN) { | ||
357 | |||
358 | if (platform->driver->compr_ops && | ||
359 | platform->driver->compr_ops->trigger) | ||
360 | return platform->driver->compr_ops->trigger(cstream, cmd); | ||
361 | } | ||
362 | |||
363 | if (cstream->direction == SND_COMPRESS_PLAYBACK) | ||
364 | stream = SNDRV_PCM_STREAM_PLAYBACK; | ||
365 | else | ||
366 | stream = SNDRV_PCM_STREAM_CAPTURE; | ||
367 | |||
368 | |||
369 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
370 | |||
371 | if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { | ||
372 | ret = platform->driver->compr_ops->trigger(cstream, cmd); | ||
373 | if (ret < 0) | ||
374 | goto out; | ||
375 | } | ||
376 | |||
377 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
378 | |||
379 | ret = dpcm_be_dai_trigger(fe, stream, cmd); | ||
380 | |||
381 | switch (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; | ||
386 | break; | ||
387 | case SNDRV_PCM_TRIGGER_STOP: | ||
388 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
389 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; | ||
390 | break; | ||
391 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
392 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | out: | ||
397 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
398 | mutex_unlock(&fe->card->mutex); | ||
399 | return ret; | ||
400 | } | ||
401 | |||
197 | static int soc_compr_set_params(struct snd_compr_stream *cstream, | 402 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
198 | struct snd_compr_params *params) | 403 | struct snd_compr_params *params) |
199 | { | 404 | { |
@@ -241,6 +446,64 @@ err: | |||
241 | return ret; | 446 | return ret; |
242 | } | 447 | } |
243 | 448 | ||
449 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, | ||
450 | struct snd_compr_params *params) | ||
451 | { | ||
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; | ||
455 | int ret = 0, stream; | ||
456 | |||
457 | if (cstream->direction == SND_COMPRESS_PLAYBACK) | ||
458 | stream = SNDRV_PCM_STREAM_PLAYBACK; | ||
459 | else | ||
460 | stream = SNDRV_PCM_STREAM_CAPTURE; | ||
461 | |||
462 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
463 | |||
464 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { | ||
465 | ret = platform->driver->compr_ops->set_params(cstream, params); | ||
466 | if (ret < 0) | ||
467 | goto out; | ||
468 | } | ||
469 | |||
470 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { | ||
471 | ret = fe->dai_link->compr_ops->set_params(cstream); | ||
472 | if (ret < 0) | ||
473 | goto out; | ||
474 | } | ||
475 | |||
476 | /* | ||
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. | ||
480 | */ | ||
481 | memset(&fe->dpcm[fe_substream->stream].hw_params, 0, | ||
482 | sizeof(struct snd_pcm_hw_params)); | ||
483 | |||
484 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
485 | |||
486 | ret = dpcm_be_dai_hw_params(fe, stream); | ||
487 | if (ret < 0) | ||
488 | goto out; | ||
489 | |||
490 | ret = dpcm_be_dai_prepare(fe, stream); | ||
491 | if (ret < 0) | ||
492 | goto out; | ||
493 | |||
494 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
495 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); | ||
496 | else | ||
497 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); | ||
498 | |||
499 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; | ||
500 | |||
501 | out: | ||
502 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
503 | mutex_unlock(&fe->card->mutex); | ||
504 | return ret; | ||
505 | } | ||
506 | |||
244 | static int soc_compr_get_params(struct snd_compr_stream *cstream, | 507 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
245 | struct snd_codec *params) | 508 | struct snd_codec *params) |
246 | { | 509 | { |
@@ -360,6 +623,7 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream, | |||
360 | 623 | ||
361 | return ret; | 624 | return ret; |
362 | } | 625 | } |
626 | |||
363 | /* ASoC Compress operations */ | 627 | /* ASoC Compress operations */ |
364 | static struct snd_compr_ops soc_compr_ops = { | 628 | static struct snd_compr_ops soc_compr_ops = { |
365 | .open = soc_compr_open, | 629 | .open = soc_compr_open, |
@@ -375,6 +639,21 @@ static struct snd_compr_ops soc_compr_ops = { | |||
375 | .get_codec_caps = soc_compr_get_codec_caps | 639 | .get_codec_caps = soc_compr_get_codec_caps |
376 | }; | 640 | }; |
377 | 641 | ||
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 | ||
655 | }; | ||
656 | |||
378 | /* create a new compress */ | 657 | /* create a new compress */ |
379 | int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) | 658 | int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
380 | { | 659 | { |
@@ -383,6 +662,7 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) | |||
383 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 662 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
384 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | 663 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
385 | struct snd_compr *compr; | 664 | struct snd_compr *compr; |
665 | struct snd_pcm *be_pcm; | ||
386 | char new_name[64]; | 666 | char new_name[64]; |
387 | int ret = 0, direction = 0; | 667 | int ret = 0, direction = 0; |
388 | 668 | ||
@@ -410,7 +690,26 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) | |||
410 | ret = -ENOMEM; | 690 | ret = -ENOMEM; |
411 | goto compr_err; | 691 | goto compr_err; |
412 | } | 692 | } |
413 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); | 693 | |
694 | if (rtd->dai_link->dynamic) { | ||
695 | snprintf(new_name, sizeof(new_name), "(%s)", | ||
696 | rtd->dai_link->stream_name); | ||
697 | |||
698 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, | ||
699 | 1, 0, &be_pcm); | ||
700 | if (ret < 0) { | ||
701 | dev_err(rtd->card->dev, "ASoC: can't create compressed for %s\n", | ||
702 | rtd->dai_link->name); | ||
703 | goto compr_err; | ||
704 | } | ||
705 | |||
706 | rtd->pcm = be_pcm; | ||
707 | rtd->fe_compr = 1; | ||
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)); | ||
711 | } else | ||
712 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); | ||
414 | 713 | ||
415 | /* Add copy callback for not memory mapped DSPs */ | 714 | /* Add copy callback for not memory mapped DSPs */ |
416 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) | 715 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) |