1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-pcm.c -- ALSA SoC PCM
5 // Copyright 2005 Wolfson Microelectronics PLC.
6 // Copyright 2005 Openedhand Ltd.
7 // Copyright (C) 2010 Slimlogic Ltd.
8 // Copyright (C) 2010 Texas Instruments Inc.
10 // Authors: Liam Girdwood <lrg@ti.com>
11 // Mark Brown <broonie@opensource.wolfsonmicro.com>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
16 #include <linux/pinctrl/consumer.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/slab.h>
19 #include <linux/workqueue.h>
20 #include <linux/export.h>
21 #include <linux/debugfs.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dpcm.h>
27 #include <sound/soc-link.h>
28 #include <sound/initval.h>
30 #define DPCM_MAX_BE_USERS 8
32 #ifdef CONFIG_DEBUG_FS
33 static const char *dpcm_state_string(enum snd_soc_dpcm_state state)
36 case SND_SOC_DPCM_STATE_NEW:
38 case SND_SOC_DPCM_STATE_OPEN:
40 case SND_SOC_DPCM_STATE_HW_PARAMS:
42 case SND_SOC_DPCM_STATE_PREPARE:
44 case SND_SOC_DPCM_STATE_START:
46 case SND_SOC_DPCM_STATE_STOP:
48 case SND_SOC_DPCM_STATE_SUSPEND:
50 case SND_SOC_DPCM_STATE_PAUSED:
52 case SND_SOC_DPCM_STATE_HW_FREE:
54 case SND_SOC_DPCM_STATE_CLOSE:
61 static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
62 int stream, char *buf, size_t size)
64 struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
65 struct snd_soc_dpcm *dpcm;
70 offset += scnprintf(buf + offset, size - offset,
71 "[%s - %s]\n", fe->dai_link->name,
72 stream ? "Capture" : "Playback");
74 offset += scnprintf(buf + offset, size - offset, "State: %s\n",
75 dpcm_state_string(fe->dpcm[stream].state));
77 if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
78 (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
79 offset += scnprintf(buf + offset, size - offset,
81 "Format = %s, Channels = %d, Rate = %d\n",
82 snd_pcm_format_name(params_format(params)),
83 params_channels(params),
87 offset += scnprintf(buf + offset, size - offset, "Backends:\n");
89 if (list_empty(&fe->dpcm[stream].be_clients)) {
90 offset += scnprintf(buf + offset, size - offset,
91 " No active DSP links\n");
95 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
96 for_each_dpcm_be(fe, stream, dpcm) {
97 struct snd_soc_pcm_runtime *be = dpcm->be;
98 params = &dpcm->hw_params;
100 offset += scnprintf(buf + offset, size - offset,
101 "- %s\n", be->dai_link->name);
103 offset += scnprintf(buf + offset, size - offset,
105 dpcm_state_string(be->dpcm[stream].state));
107 if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
108 (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
109 offset += scnprintf(buf + offset, size - offset,
111 "Format = %s, Channels = %d, Rate = %d\n",
112 snd_pcm_format_name(params_format(params)),
113 params_channels(params),
114 params_rate(params));
116 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
121 static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
122 size_t count, loff_t *ppos)
124 struct snd_soc_pcm_runtime *fe = file->private_data;
125 ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
129 if (fe->num_cpus > 1) {
131 "%s doesn't support Multi CPU yet\n", __func__);
135 buf = kmalloc(out_count, GFP_KERNEL);
139 for_each_pcm_streams(stream)
140 if (snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream))
141 offset += dpcm_show_state(fe, stream,
145 ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
151 static const struct file_operations dpcm_state_fops = {
153 .read = dpcm_state_read_file,
154 .llseek = default_llseek,
157 void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
162 if (!rtd->dai_link->dynamic)
165 if (!rtd->card->debugfs_card_root)
168 rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
169 rtd->card->debugfs_card_root);
171 debugfs_create_file("state", 0444, rtd->debugfs_dpcm_root,
172 rtd, &dpcm_state_fops);
175 static void dpcm_create_debugfs_state(struct snd_soc_dpcm *dpcm, int stream)
179 name = kasprintf(GFP_KERNEL, "%s:%s", dpcm->be->dai_link->name,
180 stream ? "capture" : "playback");
182 dpcm->debugfs_state = debugfs_create_dir(
183 name, dpcm->fe->debugfs_dpcm_root);
184 debugfs_create_u32("state", 0644, dpcm->debugfs_state,
190 static void dpcm_remove_debugfs_state(struct snd_soc_dpcm *dpcm)
192 debugfs_remove_recursive(dpcm->debugfs_state);
196 static inline void dpcm_create_debugfs_state(struct snd_soc_dpcm *dpcm,
201 static inline void dpcm_remove_debugfs_state(struct snd_soc_dpcm *dpcm)
207 * snd_soc_runtime_action() - Increment/Decrement active count for
208 * PCM runtime components
209 * @rtd: ASoC PCM runtime that is activated
210 * @stream: Direction of the PCM stream
211 * @action: Activate stream if 1. Deactivate if -1.
213 * Increments/Decrements the active count for all the DAIs and components
214 * attached to a PCM runtime.
215 * Should typically be called when a stream is opened.
217 * Must be called with the rtd->card->pcm_mutex being held
219 void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
220 int stream, int action)
222 struct snd_soc_dai *dai;
225 lockdep_assert_held(&rtd->card->pcm_mutex);
227 for_each_rtd_dais(rtd, i, dai)
228 snd_soc_dai_action(dai, stream, action);
230 EXPORT_SYMBOL_GPL(snd_soc_runtime_action);
233 * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
234 * @rtd: The ASoC PCM runtime that should be checked.
236 * This function checks whether the power down delay should be ignored for a
237 * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
238 * been configured to ignore the delay, or if none of the components benefits
239 * from having the delay.
241 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
243 struct snd_soc_component *component;
247 if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
250 for_each_rtd_components(rtd, i, component)
251 ignore &= !component->driver->use_pmdown_time;
257 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
258 * @substream: the pcm substream
259 * @hw: the hardware parameters
261 * Sets the substream runtime hardware parameters.
263 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
264 const struct snd_pcm_hardware *hw)
266 struct snd_pcm_runtime *runtime = substream->runtime;
267 runtime->hw.info = hw->info;
268 runtime->hw.formats = hw->formats;
269 runtime->hw.period_bytes_min = hw->period_bytes_min;
270 runtime->hw.period_bytes_max = hw->period_bytes_max;
271 runtime->hw.periods_min = hw->periods_min;
272 runtime->hw.periods_max = hw->periods_max;
273 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
274 runtime->hw.fifo_size = hw->fifo_size;
277 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
279 /* DPCM stream event, send event to FE and all active BEs. */
280 int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
283 struct snd_soc_dpcm *dpcm;
285 for_each_dpcm_be(fe, dir, dpcm) {
287 struct snd_soc_pcm_runtime *be = dpcm->be;
289 dev_dbg(be->dev, "ASoC: BE %s event %d dir %d\n",
290 be->dai_link->name, event, dir);
292 if ((event == SND_SOC_DAPM_STREAM_STOP) &&
293 (be->dpcm[dir].users >= 1))
296 snd_soc_dapm_stream_event(be, dir, event);
299 snd_soc_dapm_stream_event(fe, dir, event);
304 static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
305 struct snd_soc_dai *soc_dai)
307 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
310 if (soc_dai->rate && (soc_dai->driver->symmetric_rates ||
311 rtd->dai_link->symmetric_rates)) {
312 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %dHz rate\n",
315 ret = snd_pcm_hw_constraint_single(substream->runtime,
316 SNDRV_PCM_HW_PARAM_RATE,
319 dev_err(soc_dai->dev,
320 "ASoC: Unable to apply rate constraint: %d\n",
326 if (soc_dai->channels && (soc_dai->driver->symmetric_channels ||
327 rtd->dai_link->symmetric_channels)) {
328 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d channel(s)\n",
331 ret = snd_pcm_hw_constraint_single(substream->runtime,
332 SNDRV_PCM_HW_PARAM_CHANNELS,
335 dev_err(soc_dai->dev,
336 "ASoC: Unable to apply channel symmetry constraint: %d\n",
342 if (soc_dai->sample_bits && (soc_dai->driver->symmetric_samplebits ||
343 rtd->dai_link->symmetric_samplebits)) {
344 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d sample bits\n",
345 soc_dai->sample_bits);
347 ret = snd_pcm_hw_constraint_single(substream->runtime,
348 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
349 soc_dai->sample_bits);
351 dev_err(soc_dai->dev,
352 "ASoC: Unable to apply sample bits symmetry constraint: %d\n",
361 static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
362 struct snd_pcm_hw_params *params)
364 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
365 struct snd_soc_dai *dai;
366 struct snd_soc_dai *cpu_dai;
367 unsigned int rate, channels, sample_bits, symmetry, i;
369 rate = params_rate(params);
370 channels = params_channels(params);
371 sample_bits = snd_pcm_format_physical_width(params_format(params));
373 /* reject unmatched parameters when applying symmetry */
374 symmetry = rtd->dai_link->symmetric_rates;
376 for_each_rtd_cpu_dais(rtd, i, dai)
377 symmetry |= dai->driver->symmetric_rates;
380 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
381 if (cpu_dai->rate && cpu_dai->rate != rate) {
382 dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
383 cpu_dai->rate, rate);
389 symmetry = rtd->dai_link->symmetric_channels;
391 for_each_rtd_dais(rtd, i, dai)
392 symmetry |= dai->driver->symmetric_channels;
395 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
396 if (cpu_dai->channels &&
397 cpu_dai->channels != channels) {
398 dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
399 cpu_dai->channels, channels);
405 symmetry = rtd->dai_link->symmetric_samplebits;
407 for_each_rtd_dais(rtd, i, dai)
408 symmetry |= dai->driver->symmetric_samplebits;
411 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
412 if (cpu_dai->sample_bits &&
413 cpu_dai->sample_bits != sample_bits) {
414 dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
415 cpu_dai->sample_bits, sample_bits);
424 static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream)
426 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
427 struct snd_soc_dai_link *link = rtd->dai_link;
428 struct snd_soc_dai *dai;
429 unsigned int symmetry, i;
431 symmetry = link->symmetric_rates ||
432 link->symmetric_channels ||
433 link->symmetric_samplebits;
435 for_each_rtd_dais(rtd, i, dai)
436 symmetry = symmetry ||
437 dai->driver->symmetric_rates ||
438 dai->driver->symmetric_channels ||
439 dai->driver->symmetric_samplebits;
444 static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits)
446 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
452 ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 0, bits);
454 dev_warn(rtd->dev, "ASoC: Failed to set MSB %d: %d\n",
458 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
460 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
461 struct snd_soc_dai *cpu_dai;
462 struct snd_soc_dai *codec_dai;
463 struct snd_soc_pcm_stream *pcm_codec, *pcm_cpu;
464 int stream = substream->stream;
466 unsigned int bits = 0, cpu_bits = 0;
468 for_each_rtd_codec_dais(rtd, i, codec_dai) {
469 pcm_codec = snd_soc_dai_get_pcm_stream(codec_dai, stream);
471 if (pcm_codec->sig_bits == 0) {
475 bits = max(pcm_codec->sig_bits, bits);
478 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
479 pcm_cpu = snd_soc_dai_get_pcm_stream(cpu_dai, stream);
481 if (pcm_cpu->sig_bits == 0) {
485 cpu_bits = max(pcm_cpu->sig_bits, cpu_bits);
488 soc_pcm_set_msb(substream, bits);
489 soc_pcm_set_msb(substream, cpu_bits);
493 * snd_soc_runtime_calc_hw() - Calculate hw limits for a PCM stream
494 * @rtd: ASoC PCM runtime
495 * @hw: PCM hardware parameters (output)
496 * @stream: Direction of the PCM stream
498 * Calculates the subset of stream parameters supported by all DAIs
499 * associated with the PCM stream.
501 int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
502 struct snd_pcm_hardware *hw, int stream)
504 struct snd_soc_dai *codec_dai;
505 struct snd_soc_dai *cpu_dai;
506 struct snd_soc_pcm_stream *codec_stream;
507 struct snd_soc_pcm_stream *cpu_stream;
508 unsigned int chan_min = 0, chan_max = UINT_MAX;
509 unsigned int cpu_chan_min = 0, cpu_chan_max = UINT_MAX;
510 unsigned int rate_min = 0, rate_max = UINT_MAX;
511 unsigned int cpu_rate_min = 0, cpu_rate_max = UINT_MAX;
512 unsigned int rates = UINT_MAX, cpu_rates = UINT_MAX;
513 u64 formats = ULLONG_MAX;
516 /* first calculate min/max only for CPUs in the DAI link */
517 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
520 * Skip CPUs which don't support the current stream type.
521 * Otherwise, since the rate, channel, and format values will
522 * zero in that case, we would have no usable settings left,
523 * causing the resulting setup to fail.
525 if (!snd_soc_dai_stream_valid(cpu_dai, stream))
528 cpu_stream = snd_soc_dai_get_pcm_stream(cpu_dai, stream);
530 cpu_chan_min = max(cpu_chan_min, cpu_stream->channels_min);
531 cpu_chan_max = min(cpu_chan_max, cpu_stream->channels_max);
532 cpu_rate_min = max(cpu_rate_min, cpu_stream->rate_min);
533 cpu_rate_max = min_not_zero(cpu_rate_max, cpu_stream->rate_max);
534 formats &= cpu_stream->formats;
535 cpu_rates = snd_pcm_rate_mask_intersect(cpu_stream->rates,
539 /* second calculate min/max only for CODECs in the DAI link */
540 for_each_rtd_codec_dais(rtd, i, codec_dai) {
543 * Skip CODECs which don't support the current stream type.
544 * Otherwise, since the rate, channel, and format values will
545 * zero in that case, we would have no usable settings left,
546 * causing the resulting setup to fail.
548 if (!snd_soc_dai_stream_valid(codec_dai, stream))
551 codec_stream = snd_soc_dai_get_pcm_stream(codec_dai, stream);
553 chan_min = max(chan_min, codec_stream->channels_min);
554 chan_max = min(chan_max, codec_stream->channels_max);
555 rate_min = max(rate_min, codec_stream->rate_min);
556 rate_max = min_not_zero(rate_max, codec_stream->rate_max);
557 formats &= codec_stream->formats;
558 rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates);
561 /* Verify both a valid CPU DAI and a valid CODEC DAI were found */
562 if (!chan_min || !cpu_chan_min)
566 * chan min/max cannot be enforced if there are multiple CODEC DAIs
567 * connected to CPU DAI(s), use CPU DAI's directly and let
568 * channel allocation be fixed up later
570 if (rtd->num_codecs > 1) {
571 chan_min = cpu_chan_min;
572 chan_max = cpu_chan_max;
575 /* finally find a intersection between CODECs and CPUs */
576 hw->channels_min = max(chan_min, cpu_chan_min);
577 hw->channels_max = min(chan_max, cpu_chan_max);
578 hw->formats = formats;
579 hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_rates);
581 snd_pcm_hw_limit_rates(hw);
583 hw->rate_min = max(hw->rate_min, cpu_rate_min);
584 hw->rate_min = max(hw->rate_min, rate_min);
585 hw->rate_max = min_not_zero(hw->rate_max, cpu_rate_max);
586 hw->rate_max = min_not_zero(hw->rate_max, rate_max);
590 EXPORT_SYMBOL_GPL(snd_soc_runtime_calc_hw);
592 static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
594 struct snd_pcm_hardware *hw = &substream->runtime->hw;
595 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
596 u64 formats = hw->formats;
599 * At least one CPU and one CODEC should match. Otherwise, we should
600 * have bailed out on a higher level, since there would be no CPU or
601 * CODEC to support the transfer direction in that case.
603 snd_soc_runtime_calc_hw(rtd, hw, substream->stream);
606 hw->formats &= formats;
609 static int soc_pcm_components_open(struct snd_pcm_substream *substream)
611 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
612 struct snd_soc_component *component;
615 for_each_rtd_components(rtd, i, component) {
616 ret = snd_soc_component_module_get_when_open(component, substream);
620 ret = snd_soc_component_open(component, substream);
628 static int soc_pcm_components_close(struct snd_pcm_substream *substream,
631 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
632 struct snd_soc_component *component;
635 for_each_rtd_components(rtd, i, component) {
636 r = snd_soc_component_close(component, substream, rollback);
638 ret = r; /* use last ret */
640 snd_soc_component_module_put_when_close(component, substream, rollback);
646 static int soc_pcm_clean(struct snd_pcm_substream *substream, int rollback)
648 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
649 struct snd_soc_component *component;
650 struct snd_soc_dai *dai;
653 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
656 snd_soc_runtime_deactivate(rtd, substream->stream);
658 for_each_rtd_dais(rtd, i, dai)
659 snd_soc_dai_shutdown(dai, substream, rollback);
661 snd_soc_link_shutdown(substream, rollback);
663 soc_pcm_components_close(substream, rollback);
666 mutex_unlock(&rtd->card->pcm_mutex);
668 snd_soc_pcm_component_pm_runtime_put(rtd, substream, rollback);
670 for_each_rtd_components(rtd, i, component)
671 if (!snd_soc_component_active(component))
672 pinctrl_pm_select_sleep_state(component->dev);
678 * Called by ALSA when a PCM substream is closed. Private data can be
679 * freed here. The cpu DAI, codec DAI, machine and components are also
682 static int soc_pcm_close(struct snd_pcm_substream *substream)
684 return soc_pcm_clean(substream, 0);
688 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
689 * then initialized and any private data can be allocated. This also calls
690 * startup for the cpu DAI, component, machine and codec DAI.
692 static int soc_pcm_open(struct snd_pcm_substream *substream)
694 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
695 struct snd_pcm_runtime *runtime = substream->runtime;
696 struct snd_soc_component *component;
697 struct snd_soc_dai *dai;
698 const char *codec_dai_name = "multicodec";
699 const char *cpu_dai_name = "multicpu";
702 for_each_rtd_components(rtd, i, component)
703 pinctrl_pm_select_default_state(component->dev);
705 ret = snd_soc_pcm_component_pm_runtime_get(rtd, substream);
709 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
711 ret = soc_pcm_components_open(substream);
715 ret = snd_soc_link_startup(substream);
719 /* startup the audio subsystem */
720 for_each_rtd_dais(rtd, i, dai) {
721 ret = snd_soc_dai_startup(dai, substream);
725 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
731 /* Dynamic PCM DAI links compat checks use dynamic capabilities */
732 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
735 /* Check that the codec and cpu DAIs are compatible */
736 soc_pcm_init_runtime_hw(substream);
738 if (rtd->num_codecs == 1)
739 codec_dai_name = asoc_rtd_to_codec(rtd, 0)->name;
741 if (rtd->num_cpus == 1)
742 cpu_dai_name = asoc_rtd_to_cpu(rtd, 0)->name;
744 if (soc_pcm_has_symmetry(substream))
745 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
748 if (!runtime->hw.rates) {
749 printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
750 codec_dai_name, cpu_dai_name);
753 if (!runtime->hw.formats) {
754 printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
755 codec_dai_name, cpu_dai_name);
758 if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
759 runtime->hw.channels_min > runtime->hw.channels_max) {
760 printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
761 codec_dai_name, cpu_dai_name);
765 soc_pcm_apply_msb(substream);
767 /* Symmetry only applies if we've already got an active stream. */
768 for_each_rtd_dais(rtd, i, dai) {
769 if (snd_soc_dai_active(dai)) {
770 ret = soc_pcm_apply_symmetry(substream, dai);
776 pr_debug("ASoC: %s <-> %s info:\n",
777 codec_dai_name, cpu_dai_name);
778 pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
779 pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
780 runtime->hw.channels_max);
781 pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min,
782 runtime->hw.rate_max);
784 snd_soc_runtime_activate(rtd, substream->stream);
787 mutex_unlock(&rtd->card->pcm_mutex);
790 soc_pcm_clean(substream, 1);
795 static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
798 * Currently nothing to do for c2c links
799 * Since c2c links are internal nodes in the DAPM graph and
800 * don't interface with the outside world or application layer
801 * we don't have to do any special handling on close.
806 * Called by ALSA when the PCM substream is prepared, can set format, sample
807 * rate, etc. This function is non atomic and can be called multiple times,
808 * it can refer to the runtime info.
810 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
812 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
813 struct snd_soc_dai *dai;
816 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
818 ret = snd_soc_link_prepare(substream);
822 ret = snd_soc_pcm_component_prepare(substream);
826 ret = snd_soc_pcm_dai_prepare(substream);
828 dev_err(rtd->dev, "ASoC: DAI prepare error: %d\n", ret);
832 /* cancel any delayed stream shutdown that is pending */
833 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
836 cancel_delayed_work(&rtd->delayed_work);
839 snd_soc_dapm_stream_event(rtd, substream->stream,
840 SND_SOC_DAPM_STREAM_START);
842 for_each_rtd_dais(rtd, i, dai)
843 snd_soc_dai_digital_mute(dai, 0, substream->stream);
846 mutex_unlock(&rtd->card->pcm_mutex);
850 static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
853 struct snd_interval *interval;
854 int channels = hweight_long(mask);
856 interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
857 interval->min = channels;
858 interval->max = channels;
861 static int soc_pcm_hw_clean(struct snd_pcm_substream *substream, int rollback)
863 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
864 struct snd_soc_dai *dai;
867 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
869 /* clear the corresponding DAIs parameters when going to be inactive */
870 for_each_rtd_dais(rtd, i, dai) {
871 int active = snd_soc_dai_stream_active(dai, substream->stream);
873 if (snd_soc_dai_active(dai) == 1) {
876 dai->sample_bits = 0;
880 snd_soc_dai_digital_mute(dai, 1, substream->stream);
883 /* run the stream event */
884 snd_soc_dapm_stream_stop(rtd, substream->stream);
886 /* free any machine hw params */
887 snd_soc_link_hw_free(substream, rollback);
889 /* free any component resources */
890 snd_soc_pcm_component_hw_free(substream, rollback);
892 /* now free hw params for the DAIs */
893 for_each_rtd_dais(rtd, i, dai) {
894 if (!snd_soc_dai_stream_valid(dai, substream->stream))
897 snd_soc_dai_hw_free(dai, substream, rollback);
900 mutex_unlock(&rtd->card->pcm_mutex);
905 * Frees resources allocated by hw_params, can be called multiple times
907 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
909 return soc_pcm_hw_clean(substream, 0);
913 * Called by ALSA when the hardware params are set by application. This
914 * function can also be called multiple times and can allocate buffers
915 * (using snd_pcm_lib_* ). It's non-atomic.
917 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
918 struct snd_pcm_hw_params *params)
920 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
921 struct snd_soc_dai *cpu_dai;
922 struct snd_soc_dai *codec_dai;
925 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
927 ret = soc_pcm_params_symmetry(substream, params);
931 ret = snd_soc_link_hw_params(substream, params);
935 for_each_rtd_codec_dais(rtd, i, codec_dai) {
936 struct snd_pcm_hw_params codec_params;
939 * Skip CODECs which don't support the current stream type,
940 * the idea being that if a CODEC is not used for the currently
941 * set up transfer direction, it should not need to be
942 * configured, especially since the configuration used might
943 * not even be supported by that CODEC. There may be cases
944 * however where a CODEC needs to be set up although it is
945 * actually not being used for the transfer, e.g. if a
946 * capture-only CODEC is acting as an LRCLK and/or BCLK master
947 * for the DAI link including a playback-only CODEC.
948 * If this becomes necessary, we will have to augment the
949 * machine driver setup with information on how to act, so
950 * we can do the right thing here.
952 if (!snd_soc_dai_stream_valid(codec_dai, substream->stream))
955 /* copy params for each codec */
956 codec_params = *params;
958 /* fixup params based on TDM slot masks */
959 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
961 soc_pcm_codec_params_fixup(&codec_params,
964 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
966 soc_pcm_codec_params_fixup(&codec_params,
969 ret = snd_soc_dai_hw_params(codec_dai, substream,
974 codec_dai->rate = params_rate(&codec_params);
975 codec_dai->channels = params_channels(&codec_params);
976 codec_dai->sample_bits = snd_pcm_format_physical_width(
977 params_format(&codec_params));
979 snd_soc_dapm_update_dai(substream, &codec_params, codec_dai);
982 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
984 * Skip CPUs which don't support the current stream
985 * type. See soc_pcm_init_runtime_hw() for more details
987 if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
990 ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
994 /* store the parameters for each DAI */
995 cpu_dai->rate = params_rate(params);
996 cpu_dai->channels = params_channels(params);
997 cpu_dai->sample_bits =
998 snd_pcm_format_physical_width(params_format(params));
1000 snd_soc_dapm_update_dai(substream, params, cpu_dai);
1003 ret = snd_soc_pcm_component_hw_params(substream, params);
1005 mutex_unlock(&rtd->card->pcm_mutex);
1008 soc_pcm_hw_clean(substream, 1);
1013 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1018 case SNDRV_PCM_TRIGGER_START:
1019 case SNDRV_PCM_TRIGGER_RESUME:
1020 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1021 ret = snd_soc_link_trigger(substream, cmd);
1025 ret = snd_soc_pcm_component_trigger(substream, cmd);
1029 ret = snd_soc_pcm_dai_trigger(substream, cmd);
1031 case SNDRV_PCM_TRIGGER_STOP:
1032 case SNDRV_PCM_TRIGGER_SUSPEND:
1033 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1034 ret = snd_soc_pcm_dai_trigger(substream, cmd);
1038 ret = snd_soc_pcm_component_trigger(substream, cmd);
1042 ret = snd_soc_link_trigger(substream, cmd);
1050 * soc level wrapper for pointer callback
1051 * If cpu_dai, codec_dai, component driver has the delay callback, then
1052 * the runtime->delay will be updated accordingly.
1054 static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1056 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1057 struct snd_soc_dai *cpu_dai;
1058 struct snd_soc_dai *codec_dai;
1059 struct snd_pcm_runtime *runtime = substream->runtime;
1060 snd_pcm_uframes_t offset = 0;
1061 snd_pcm_sframes_t delay = 0;
1062 snd_pcm_sframes_t codec_delay = 0;
1063 snd_pcm_sframes_t cpu_delay = 0;
1066 /* clearing the previous total delay */
1069 offset = snd_soc_pcm_component_pointer(substream);
1071 /* base delay if assigned in pointer callback */
1072 delay = runtime->delay;
1074 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1075 cpu_delay = max(cpu_delay,
1076 snd_soc_dai_delay(cpu_dai, substream));
1080 for_each_rtd_codec_dais(rtd, i, codec_dai) {
1081 codec_delay = max(codec_delay,
1082 snd_soc_dai_delay(codec_dai, substream));
1084 delay += codec_delay;
1086 runtime->delay = delay;
1091 /* connect a FE and BE */
1092 static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
1093 struct snd_soc_pcm_runtime *be, int stream)
1095 struct snd_soc_dpcm *dpcm;
1096 unsigned long flags;
1098 /* only add new dpcms */
1099 for_each_dpcm_be(fe, stream, dpcm) {
1100 if (dpcm->be == be && dpcm->fe == fe)
1104 dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL);
1110 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
1111 dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
1112 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1113 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
1114 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
1115 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1117 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
1118 stream ? "capture" : "playback", fe->dai_link->name,
1119 stream ? "<-" : "->", be->dai_link->name);
1121 dpcm_create_debugfs_state(dpcm, stream);
1126 /* reparent a BE onto another FE */
1127 static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
1128 struct snd_soc_pcm_runtime *be, int stream)
1130 struct snd_soc_dpcm *dpcm;
1131 struct snd_pcm_substream *fe_substream, *be_substream;
1133 /* reparent if BE is connected to other FEs */
1134 if (!be->dpcm[stream].users)
1137 be_substream = snd_soc_dpcm_get_substream(be, stream);
1139 for_each_dpcm_fe(be, stream, dpcm) {
1143 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
1144 stream ? "capture" : "playback",
1145 dpcm->fe->dai_link->name,
1146 stream ? "<-" : "->", dpcm->be->dai_link->name);
1148 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
1149 be_substream->runtime = fe_substream->runtime;
1154 /* disconnect a BE and FE */
1155 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
1157 struct snd_soc_dpcm *dpcm, *d;
1158 unsigned long flags;
1160 for_each_dpcm_be_safe(fe, stream, dpcm, d) {
1161 dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
1162 stream ? "capture" : "playback",
1163 dpcm->be->dai_link->name);
1165 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
1168 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
1169 stream ? "capture" : "playback", fe->dai_link->name,
1170 stream ? "<-" : "->", dpcm->be->dai_link->name);
1172 /* BEs still alive need new FE */
1173 dpcm_be_reparent(fe, dpcm->be, stream);
1175 dpcm_remove_debugfs_state(dpcm);
1177 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1178 list_del(&dpcm->list_be);
1179 list_del(&dpcm->list_fe);
1180 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1185 /* get BE for DAI widget and stream */
1186 static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
1187 struct snd_soc_dapm_widget *widget, int stream)
1189 struct snd_soc_pcm_runtime *be;
1190 struct snd_soc_dapm_widget *w;
1191 struct snd_soc_dai *dai;
1194 dev_dbg(card->dev, "ASoC: find BE for widget %s\n", widget->name);
1196 for_each_card_rtds(card, be) {
1198 if (!be->dai_link->no_pcm)
1201 for_each_rtd_dais(be, i, dai) {
1202 w = snd_soc_dai_get_widget(dai, stream);
1204 dev_dbg(card->dev, "ASoC: try BE : %s\n",
1205 w ? w->name : "(not set)");
1212 /* Widget provided is not a BE */
1216 static int widget_in_list(struct snd_soc_dapm_widget_list *list,
1217 struct snd_soc_dapm_widget *widget)
1219 struct snd_soc_dapm_widget *w;
1222 for_each_dapm_widgets(list, i, w)
1229 static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
1230 enum snd_soc_dapm_direction dir)
1232 struct snd_soc_card *card = widget->dapm->card;
1233 struct snd_soc_pcm_runtime *rtd;
1236 /* adjust dir to stream */
1237 if (dir == SND_SOC_DAPM_DIR_OUT)
1238 stream = SNDRV_PCM_STREAM_PLAYBACK;
1240 stream = SNDRV_PCM_STREAM_CAPTURE;
1242 rtd = dpcm_get_be(card, widget, stream);
1249 int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
1250 int stream, struct snd_soc_dapm_widget_list **list)
1252 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
1255 if (fe->num_cpus > 1) {
1257 "%s doesn't support Multi CPU yet\n", __func__);
1261 /* get number of valid DAI paths and their widgets */
1262 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
1263 fe->card->component_chaining ?
1264 NULL : dpcm_end_walk_at_be);
1266 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
1267 stream ? "capture" : "playback");
1272 void dpcm_path_put(struct snd_soc_dapm_widget_list **list)
1274 snd_soc_dapm_dai_free_widgets(list);
1277 static bool dpcm_be_is_active(struct snd_soc_dpcm *dpcm, int stream,
1278 struct snd_soc_dapm_widget_list *list)
1280 struct snd_soc_dapm_widget *widget;
1281 struct snd_soc_dai *dai;
1284 /* is there a valid DAI widget for this BE */
1285 for_each_rtd_dais(dpcm->be, i, dai) {
1286 widget = snd_soc_dai_get_widget(dai, stream);
1289 * The BE is pruned only if none of the dai
1290 * widgets are in the active list.
1292 if (widget && widget_in_list(list, widget))
1299 static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
1300 struct snd_soc_dapm_widget_list **list_)
1302 struct snd_soc_dpcm *dpcm;
1305 /* Destroy any old FE <--> BE connections */
1306 for_each_dpcm_be(fe, stream, dpcm) {
1307 if (dpcm_be_is_active(dpcm, stream, *list_))
1310 dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
1311 stream ? "capture" : "playback",
1312 dpcm->be->dai_link->name, fe->dai_link->name);
1313 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1314 dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1318 dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune);
1322 static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1323 struct snd_soc_dapm_widget_list **list_)
1325 struct snd_soc_card *card = fe->card;
1326 struct snd_soc_dapm_widget_list *list = *list_;
1327 struct snd_soc_pcm_runtime *be;
1328 struct snd_soc_dapm_widget *widget;
1329 int i, new = 0, err;
1331 /* Create any new FE <--> BE connections */
1332 for_each_dapm_widgets(list, i, widget) {
1334 switch (widget->id) {
1335 case snd_soc_dapm_dai_in:
1336 if (stream != SNDRV_PCM_STREAM_PLAYBACK)
1339 case snd_soc_dapm_dai_out:
1340 if (stream != SNDRV_PCM_STREAM_CAPTURE)
1347 /* is there a valid BE rtd for this widget */
1348 be = dpcm_get_be(card, widget, stream);
1350 dev_err(fe->dev, "ASoC: no BE found for %s\n",
1355 /* don't connect if FE is not running */
1356 if (!fe->dpcm[stream].runtime && !fe->fe_compr)
1359 /* newly connected FE and BE */
1360 err = dpcm_be_connect(fe, be, stream);
1362 dev_err(fe->dev, "ASoC: can't connect %s\n",
1365 } else if (err == 0) /* already connected */
1369 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1373 dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new);
1378 * Find the corresponding BE DAIs that source or sink audio to this
1381 int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
1382 int stream, struct snd_soc_dapm_widget_list **list, int new)
1385 return dpcm_add_paths(fe, stream, list);
1387 return dpcm_prune_paths(fe, stream, list);
1390 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
1392 struct snd_soc_dpcm *dpcm;
1393 unsigned long flags;
1395 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1396 for_each_dpcm_be(fe, stream, dpcm)
1397 dpcm->be->dpcm[stream].runtime_update =
1398 SND_SOC_DPCM_UPDATE_NO;
1399 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1402 static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
1405 struct snd_soc_dpcm *dpcm;
1407 /* disable any enabled and non active backends */
1408 for_each_dpcm_be(fe, stream, dpcm) {
1410 struct snd_soc_pcm_runtime *be = dpcm->be;
1411 struct snd_pcm_substream *be_substream =
1412 snd_soc_dpcm_get_substream(be, stream);
1414 if (be->dpcm[stream].users == 0)
1415 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1416 stream ? "capture" : "playback",
1417 be->dpcm[stream].state);
1419 if (--be->dpcm[stream].users != 0)
1422 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1425 soc_pcm_close(be_substream);
1426 be_substream->runtime = NULL;
1427 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1431 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1433 struct snd_soc_dpcm *dpcm;
1436 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1437 for_each_dpcm_be(fe, stream, dpcm) {
1439 struct snd_soc_pcm_runtime *be = dpcm->be;
1440 struct snd_pcm_substream *be_substream =
1441 snd_soc_dpcm_get_substream(be, stream);
1443 if (!be_substream) {
1444 dev_err(be->dev, "ASoC: no backend %s stream\n",
1445 stream ? "capture" : "playback");
1449 /* is this op for this BE ? */
1450 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1453 /* first time the dpcm is open ? */
1454 if (be->dpcm[stream].users == DPCM_MAX_BE_USERS)
1455 dev_err(be->dev, "ASoC: too many users %s at open %d\n",
1456 stream ? "capture" : "playback",
1457 be->dpcm[stream].state);
1459 if (be->dpcm[stream].users++ != 0)
1462 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1463 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1466 dev_dbg(be->dev, "ASoC: open %s BE %s\n",
1467 stream ? "capture" : "playback", be->dai_link->name);
1469 be_substream->runtime = be->dpcm[stream].runtime;
1470 err = soc_pcm_open(be_substream);
1472 dev_err(be->dev, "ASoC: BE open failed %d\n", err);
1473 be->dpcm[stream].users--;
1474 if (be->dpcm[stream].users < 0)
1475 dev_err(be->dev, "ASoC: no users %s at unwind %d\n",
1476 stream ? "capture" : "playback",
1477 be->dpcm[stream].state);
1479 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1483 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1490 /* disable any enabled and non active backends */
1491 for_each_dpcm_be_rollback(fe, stream, dpcm) {
1492 struct snd_soc_pcm_runtime *be = dpcm->be;
1493 struct snd_pcm_substream *be_substream =
1494 snd_soc_dpcm_get_substream(be, stream);
1496 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1499 if (be->dpcm[stream].users == 0)
1500 dev_err(be->dev, "ASoC: no users %s at close %d\n",
1501 stream ? "capture" : "playback",
1502 be->dpcm[stream].state);
1504 if (--be->dpcm[stream].users != 0)
1507 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1510 soc_pcm_close(be_substream);
1511 be_substream->runtime = NULL;
1512 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1518 static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
1519 struct snd_soc_pcm_stream *stream)
1521 runtime->hw.rate_min = stream->rate_min;
1522 runtime->hw.rate_max = min_not_zero(stream->rate_max, UINT_MAX);
1523 runtime->hw.channels_min = stream->channels_min;
1524 runtime->hw.channels_max = stream->channels_max;
1525 if (runtime->hw.formats)
1526 runtime->hw.formats &= stream->formats;
1528 runtime->hw.formats = stream->formats;
1529 runtime->hw.rates = stream->rates;
1532 static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
1535 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1536 struct snd_soc_dpcm *dpcm;
1537 struct snd_soc_dai *dai;
1538 int stream = substream->stream;
1540 if (!fe->dai_link->dpcm_merged_format)
1544 * It returns merged BE codec format
1545 * if FE want to use it (= dpcm_merged_format)
1548 for_each_dpcm_be(fe, stream, dpcm) {
1549 struct snd_soc_pcm_runtime *be = dpcm->be;
1550 struct snd_soc_pcm_stream *codec_stream;
1553 for_each_rtd_codec_dais(be, i, dai) {
1555 * Skip CODECs which don't support the current stream
1556 * type. See soc_pcm_init_runtime_hw() for more details
1558 if (!snd_soc_dai_stream_valid(dai, stream))
1561 codec_stream = snd_soc_dai_get_pcm_stream(dai, stream);
1563 *formats &= codec_stream->formats;
1568 static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,
1569 unsigned int *channels_min,
1570 unsigned int *channels_max)
1572 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1573 struct snd_soc_dpcm *dpcm;
1574 int stream = substream->stream;
1576 if (!fe->dai_link->dpcm_merged_chan)
1580 * It returns merged BE codec channel;
1581 * if FE want to use it (= dpcm_merged_chan)
1584 for_each_dpcm_be(fe, stream, dpcm) {
1585 struct snd_soc_pcm_runtime *be = dpcm->be;
1586 struct snd_soc_pcm_stream *codec_stream;
1587 struct snd_soc_pcm_stream *cpu_stream;
1588 struct snd_soc_dai *dai;
1591 for_each_rtd_cpu_dais(be, i, dai) {
1593 * Skip CPUs which don't support the current stream
1594 * type. See soc_pcm_init_runtime_hw() for more details
1596 if (!snd_soc_dai_stream_valid(dai, stream))
1599 cpu_stream = snd_soc_dai_get_pcm_stream(dai, stream);
1601 *channels_min = max(*channels_min,
1602 cpu_stream->channels_min);
1603 *channels_max = min(*channels_max,
1604 cpu_stream->channels_max);
1608 * chan min/max cannot be enforced if there are multiple CODEC
1609 * DAIs connected to a single CPU DAI, use CPU DAI's directly
1611 if (be->num_codecs == 1) {
1612 codec_stream = snd_soc_dai_get_pcm_stream(asoc_rtd_to_codec(be, 0), stream);
1614 *channels_min = max(*channels_min,
1615 codec_stream->channels_min);
1616 *channels_max = min(*channels_max,
1617 codec_stream->channels_max);
1622 static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
1623 unsigned int *rates,
1624 unsigned int *rate_min,
1625 unsigned int *rate_max)
1627 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1628 struct snd_soc_dpcm *dpcm;
1629 int stream = substream->stream;
1631 if (!fe->dai_link->dpcm_merged_rate)
1635 * It returns merged BE codec channel;
1636 * if FE want to use it (= dpcm_merged_chan)
1639 for_each_dpcm_be(fe, stream, dpcm) {
1640 struct snd_soc_pcm_runtime *be = dpcm->be;
1641 struct snd_soc_pcm_stream *pcm;
1642 struct snd_soc_dai *dai;
1645 for_each_rtd_dais(be, i, dai) {
1647 * Skip DAIs which don't support the current stream
1648 * type. See soc_pcm_init_runtime_hw() for more details
1650 if (!snd_soc_dai_stream_valid(dai, stream))
1653 pcm = snd_soc_dai_get_pcm_stream(dai, stream);
1655 *rate_min = max(*rate_min, pcm->rate_min);
1656 *rate_max = min_not_zero(*rate_max, pcm->rate_max);
1657 *rates = snd_pcm_rate_mask_intersect(*rates, pcm->rates);
1662 static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1664 struct snd_pcm_runtime *runtime = substream->runtime;
1665 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1666 struct snd_soc_dai *cpu_dai;
1669 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1671 * Skip CPUs which don't support the current stream
1672 * type. See soc_pcm_init_runtime_hw() for more details
1674 if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
1677 dpcm_init_runtime_hw(runtime,
1678 snd_soc_dai_get_pcm_stream(cpu_dai,
1679 substream->stream));
1682 dpcm_runtime_merge_format(substream, &runtime->hw.formats);
1683 dpcm_runtime_merge_chan(substream, &runtime->hw.channels_min,
1684 &runtime->hw.channels_max);
1685 dpcm_runtime_merge_rate(substream, &runtime->hw.rates,
1686 &runtime->hw.rate_min, &runtime->hw.rate_max);
1689 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
1691 /* Set FE's runtime_update state; the state is protected via PCM stream lock
1692 * for avoiding the race with trigger callback.
1693 * If the state is unset and a trigger is pending while the previous operation,
1694 * process the pending trigger action here.
1696 static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1697 int stream, enum snd_soc_dpcm_update state)
1699 struct snd_pcm_substream *substream =
1700 snd_soc_dpcm_get_substream(fe, stream);
1702 snd_pcm_stream_lock_irq(substream);
1703 if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1704 dpcm_fe_dai_do_trigger(substream,
1705 fe->dpcm[stream].trigger_pending - 1);
1706 fe->dpcm[stream].trigger_pending = 0;
1708 fe->dpcm[stream].runtime_update = state;
1709 snd_pcm_stream_unlock_irq(substream);
1712 static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
1715 struct snd_soc_dpcm *dpcm;
1716 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1717 struct snd_soc_dai *fe_cpu_dai;
1721 /* apply symmetry for FE */
1722 if (soc_pcm_has_symmetry(fe_substream))
1723 fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1725 for_each_rtd_cpu_dais (fe, i, fe_cpu_dai) {
1726 /* Symmetry only applies if we've got an active stream. */
1727 if (snd_soc_dai_active(fe_cpu_dai)) {
1728 err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
1734 /* apply symmetry for BE */
1735 for_each_dpcm_be(fe, stream, dpcm) {
1736 struct snd_soc_pcm_runtime *be = dpcm->be;
1737 struct snd_pcm_substream *be_substream =
1738 snd_soc_dpcm_get_substream(be, stream);
1739 struct snd_soc_pcm_runtime *rtd;
1740 struct snd_soc_dai *dai;
1743 /* A backend may not have the requested substream */
1747 rtd = asoc_substream_to_rtd(be_substream);
1748 if (rtd->dai_link->be_hw_params_fixup)
1751 if (soc_pcm_has_symmetry(be_substream))
1752 be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1754 /* Symmetry only applies if we've got an active stream. */
1755 for_each_rtd_dais(rtd, i, dai) {
1756 if (snd_soc_dai_active(dai)) {
1757 err = soc_pcm_apply_symmetry(fe_substream, dai);
1767 static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1769 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1770 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1771 int stream = fe_substream->stream, ret = 0;
1773 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1775 ret = dpcm_be_dai_startup(fe, stream);
1777 dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret);
1781 dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name);
1783 /* start the DAI frontend */
1784 ret = soc_pcm_open(fe_substream);
1786 dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret);
1790 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1792 dpcm_set_fe_runtime(fe_substream);
1793 snd_pcm_limit_hw_rates(runtime);
1795 ret = dpcm_apply_symmetry(fe_substream, stream);
1797 dev_err(fe->dev, "ASoC: failed to apply dpcm symmetry %d\n",
1802 dpcm_be_dai_startup_unwind(fe, stream);
1804 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1808 int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1810 struct snd_soc_dpcm *dpcm;
1812 /* only shutdown BEs that are either sinks or sources to this FE DAI */
1813 for_each_dpcm_be(fe, stream, dpcm) {
1815 struct snd_soc_pcm_runtime *be = dpcm->be;
1816 struct snd_pcm_substream *be_substream =
1817 snd_soc_dpcm_get_substream(be, stream);
1819 /* is this op for this BE ? */
1820 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1823 if (be->dpcm[stream].users == 0)
1824 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1825 stream ? "capture" : "playback",
1826 be->dpcm[stream].state);
1828 if (--be->dpcm[stream].users != 0)
1831 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1832 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)) {
1833 soc_pcm_hw_free(be_substream);
1834 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1837 dev_dbg(be->dev, "ASoC: close BE %s\n",
1838 be->dai_link->name);
1840 soc_pcm_close(be_substream);
1841 be_substream->runtime = NULL;
1843 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1848 static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1850 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1851 int stream = substream->stream;
1853 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1855 /* shutdown the BEs */
1856 dpcm_be_dai_shutdown(fe, stream);
1858 dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name);
1860 /* now shutdown the frontend */
1861 soc_pcm_close(substream);
1863 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1864 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1868 int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1870 struct snd_soc_dpcm *dpcm;
1872 /* only hw_params backends that are either sinks or sources
1873 * to this frontend DAI */
1874 for_each_dpcm_be(fe, stream, dpcm) {
1876 struct snd_soc_pcm_runtime *be = dpcm->be;
1877 struct snd_pcm_substream *be_substream =
1878 snd_soc_dpcm_get_substream(be, stream);
1880 /* is this op for this BE ? */
1881 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1884 /* only free hw when no longer used - check all FEs */
1885 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1888 /* do not free hw if this BE is used by other FE */
1889 if (be->dpcm[stream].users > 1)
1892 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1893 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1894 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1895 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
1896 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
1897 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1900 dev_dbg(be->dev, "ASoC: hw_free BE %s\n",
1901 be->dai_link->name);
1903 soc_pcm_hw_free(be_substream);
1905 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1911 static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1913 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1914 int err, stream = substream->stream;
1916 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1917 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1919 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
1921 /* call hw_free on the frontend */
1922 err = soc_pcm_hw_free(substream);
1924 dev_err(fe->dev,"ASoC: hw_free FE %s failed\n",
1925 fe->dai_link->name);
1927 /* only hw_params backends that are either sinks or sources
1928 * to this frontend DAI */
1929 err = dpcm_be_dai_hw_free(fe, stream);
1931 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1932 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1934 mutex_unlock(&fe->card->mutex);
1938 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1940 struct snd_soc_dpcm *dpcm;
1943 for_each_dpcm_be(fe, stream, dpcm) {
1945 struct snd_soc_pcm_runtime *be = dpcm->be;
1946 struct snd_pcm_substream *be_substream =
1947 snd_soc_dpcm_get_substream(be, stream);
1949 /* is this op for this BE ? */
1950 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1953 /* copy params for each dpcm */
1954 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1955 sizeof(struct snd_pcm_hw_params));
1957 /* perform any hw_params fixups */
1958 ret = snd_soc_link_be_hw_params_fixup(be, &dpcm->hw_params);
1962 /* copy the fixed-up hw params for BE dai */
1963 memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
1964 sizeof(struct snd_pcm_hw_params));
1966 /* only allow hw_params() if no connected FEs are running */
1967 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1970 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1971 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1972 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1975 dev_dbg(be->dev, "ASoC: hw_params BE %s\n",
1976 be->dai_link->name);
1978 ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params);
1980 dev_err(dpcm->be->dev,
1981 "ASoC: hw_params BE failed %d\n", ret);
1985 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1990 /* disable any enabled and non active backends */
1991 for_each_dpcm_be_rollback(fe, stream, dpcm) {
1992 struct snd_soc_pcm_runtime *be = dpcm->be;
1993 struct snd_pcm_substream *be_substream =
1994 snd_soc_dpcm_get_substream(be, stream);
1996 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1999 /* only allow hw_free() if no connected FEs are running */
2000 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2003 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
2004 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
2005 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
2006 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
2009 soc_pcm_hw_free(be_substream);
2015 static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
2016 struct snd_pcm_hw_params *params)
2018 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2019 int ret, stream = substream->stream;
2021 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2022 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2024 memcpy(&fe->dpcm[stream].hw_params, params,
2025 sizeof(struct snd_pcm_hw_params));
2026 ret = dpcm_be_dai_hw_params(fe, stream);
2028 dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret);
2032 dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
2033 fe->dai_link->name, params_rate(params),
2034 params_channels(params), params_format(params));
2036 /* call hw_params on the frontend */
2037 ret = soc_pcm_hw_params(substream, params);
2039 dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret);
2040 dpcm_be_dai_hw_free(fe, stream);
2042 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
2045 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2046 mutex_unlock(&fe->card->mutex);
2050 static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm,
2051 struct snd_pcm_substream *substream, int cmd)
2055 dev_dbg(dpcm->be->dev, "ASoC: trigger BE %s cmd %d\n",
2056 dpcm->be->dai_link->name, cmd);
2058 ret = soc_pcm_trigger(substream, cmd);
2060 dev_err(dpcm->be->dev,"ASoC: trigger BE failed %d\n", ret);
2065 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
2068 struct snd_soc_dpcm *dpcm;
2071 for_each_dpcm_be(fe, stream, dpcm) {
2073 struct snd_soc_pcm_runtime *be = dpcm->be;
2074 struct snd_pcm_substream *be_substream =
2075 snd_soc_dpcm_get_substream(be, stream);
2077 /* is this op for this BE ? */
2078 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2082 case SNDRV_PCM_TRIGGER_START:
2083 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
2084 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
2085 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2088 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2092 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2094 case SNDRV_PCM_TRIGGER_RESUME:
2095 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
2098 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2102 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2104 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2105 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2108 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2112 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2114 case SNDRV_PCM_TRIGGER_STOP:
2115 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) &&
2116 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2119 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2122 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2126 be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2128 case SNDRV_PCM_TRIGGER_SUSPEND:
2129 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2132 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2135 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2139 be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
2141 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2142 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2145 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2148 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2152 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2159 EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
2161 static int dpcm_dai_trigger_fe_be(struct snd_pcm_substream *substream,
2162 int cmd, bool fe_first)
2164 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2167 /* call trigger on the frontend before the backend. */
2169 dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n",
2170 fe->dai_link->name, cmd);
2172 ret = soc_pcm_trigger(substream, cmd);
2176 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2180 /* call trigger on the frontend after the backend. */
2181 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2185 dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
2186 fe->dai_link->name, cmd);
2188 ret = soc_pcm_trigger(substream, cmd);
2193 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
2195 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2196 int stream = substream->stream;
2198 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2200 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
2203 case SND_SOC_DPCM_TRIGGER_PRE:
2205 case SNDRV_PCM_TRIGGER_START:
2206 case SNDRV_PCM_TRIGGER_RESUME:
2207 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2208 case SNDRV_PCM_TRIGGER_DRAIN:
2209 ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
2211 case SNDRV_PCM_TRIGGER_STOP:
2212 case SNDRV_PCM_TRIGGER_SUSPEND:
2213 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2214 ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
2221 case SND_SOC_DPCM_TRIGGER_POST:
2223 case SNDRV_PCM_TRIGGER_START:
2224 case SNDRV_PCM_TRIGGER_RESUME:
2225 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2226 case SNDRV_PCM_TRIGGER_DRAIN:
2227 ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
2229 case SNDRV_PCM_TRIGGER_STOP:
2230 case SNDRV_PCM_TRIGGER_SUSPEND:
2231 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2232 ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
2239 case SND_SOC_DPCM_TRIGGER_BESPOKE:
2240 /* bespoke trigger() - handles both FE and BEs */
2242 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
2243 fe->dai_link->name, cmd);
2245 ret = snd_soc_pcm_dai_bespoke_trigger(substream, cmd);
2248 dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
2249 fe->dai_link->name);
2255 dev_err(fe->dev, "ASoC: trigger FE cmd: %d failed: %d\n",
2261 case SNDRV_PCM_TRIGGER_START:
2262 case SNDRV_PCM_TRIGGER_RESUME:
2263 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2264 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2266 case SNDRV_PCM_TRIGGER_STOP:
2267 case SNDRV_PCM_TRIGGER_SUSPEND:
2268 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2270 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2271 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2276 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
2280 static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
2282 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2283 int stream = substream->stream;
2285 /* if FE's runtime_update is already set, we're in race;
2286 * process this trigger later at exit
2288 if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2289 fe->dpcm[stream].trigger_pending = cmd + 1;
2290 return 0; /* delayed, assuming it's successful */
2293 /* we're alone, let's trigger */
2294 return dpcm_fe_dai_do_trigger(substream, cmd);
2297 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
2299 struct snd_soc_dpcm *dpcm;
2302 for_each_dpcm_be(fe, stream, dpcm) {
2304 struct snd_soc_pcm_runtime *be = dpcm->be;
2305 struct snd_pcm_substream *be_substream =
2306 snd_soc_dpcm_get_substream(be, stream);
2308 /* is this op for this BE ? */
2309 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2312 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
2313 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
2314 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND) &&
2315 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2318 dev_dbg(be->dev, "ASoC: prepare BE %s\n",
2319 be->dai_link->name);
2321 ret = soc_pcm_prepare(be_substream);
2323 dev_err(be->dev, "ASoC: backend prepare failed %d\n",
2328 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2333 static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
2335 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2336 int stream = substream->stream, ret = 0;
2338 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2340 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
2342 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2344 /* there is no point preparing this FE if there are no BEs */
2345 if (list_empty(&fe->dpcm[stream].be_clients)) {
2346 dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
2347 fe->dai_link->name);
2352 ret = dpcm_be_dai_prepare(fe, stream);
2356 /* call prepare on the frontend */
2357 ret = soc_pcm_prepare(substream);
2359 dev_err(fe->dev,"ASoC: prepare FE %s failed\n",
2360 fe->dai_link->name);
2364 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2367 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2368 mutex_unlock(&fe->card->mutex);
2373 static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
2375 struct snd_pcm_substream *substream =
2376 snd_soc_dpcm_get_substream(fe, stream);
2377 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2380 dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
2381 stream ? "capture" : "playback", fe->dai_link->name);
2383 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2384 /* call bespoke trigger - FE takes care of all BE triggers */
2385 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
2386 fe->dai_link->name);
2388 err = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
2390 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2392 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
2393 fe->dai_link->name);
2395 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
2397 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2400 err = dpcm_be_dai_hw_free(fe, stream);
2402 dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err);
2404 err = dpcm_be_dai_shutdown(fe, stream);
2406 dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err);
2408 /* run the stream event for each BE */
2409 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2414 static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
2416 struct snd_pcm_substream *substream =
2417 snd_soc_dpcm_get_substream(fe, stream);
2418 struct snd_soc_dpcm *dpcm;
2419 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2421 unsigned long flags;
2423 dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
2424 stream ? "capture" : "playback", fe->dai_link->name);
2426 /* Only start the BE if the FE is ready */
2427 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
2428 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2431 /* startup must always be called for new BEs */
2432 ret = dpcm_be_dai_startup(fe, stream);
2436 /* keep going if FE state is > open */
2437 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
2440 ret = dpcm_be_dai_hw_params(fe, stream);
2444 /* keep going if FE state is > hw_params */
2445 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
2449 ret = dpcm_be_dai_prepare(fe, stream);
2453 /* run the stream event for each BE */
2454 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2456 /* keep going if FE state is > prepare */
2457 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
2458 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
2461 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2462 /* call trigger on the frontend - FE takes care of all BE triggers */
2463 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
2464 fe->dai_link->name);
2466 ret = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
2468 dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret);
2472 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
2473 fe->dai_link->name);
2475 ret = dpcm_be_dai_trigger(fe, stream,
2476 SNDRV_PCM_TRIGGER_START);
2478 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
2486 dpcm_be_dai_hw_free(fe, stream);
2488 dpcm_be_dai_shutdown(fe, stream);
2490 /* disconnect any closed BEs */
2491 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2492 for_each_dpcm_be(fe, stream, dpcm) {
2493 struct snd_soc_pcm_runtime *be = dpcm->be;
2494 if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2495 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2497 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2502 static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
2504 struct snd_soc_dapm_widget_list *list;
2509 if (!fe->dai_link->dynamic)
2512 if (fe->num_cpus > 1) {
2514 "%s doesn't support Multi CPU yet\n", __func__);
2518 /* only check active links */
2519 if (!snd_soc_dai_active(asoc_rtd_to_cpu(fe, 0)))
2522 /* DAPM sync will call this to update DSP paths */
2523 dev_dbg(fe->dev, "ASoC: DPCM %s runtime update for FE %s\n",
2524 new ? "new" : "old", fe->dai_link->name);
2526 for_each_pcm_streams(stream) {
2528 /* skip if FE doesn't have playback/capture capability */
2529 if (!snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream) ||
2530 !snd_soc_dai_stream_valid(asoc_rtd_to_codec(fe, 0), stream))
2533 /* skip if FE isn't currently playing/capturing */
2534 if (!snd_soc_dai_stream_active(asoc_rtd_to_cpu(fe, 0), stream) ||
2535 !snd_soc_dai_stream_active(asoc_rtd_to_codec(fe, 0), stream))
2538 paths = dpcm_path_get(fe, stream, &list);
2540 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2542 stream == SNDRV_PCM_STREAM_PLAYBACK ?
2543 "playback" : "capture");
2547 /* update any playback/capture paths */
2548 count = dpcm_process_paths(fe, stream, &list, new);
2550 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2552 ret = dpcm_run_update_startup(fe, stream);
2554 ret = dpcm_run_update_shutdown(fe, stream);
2556 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
2557 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2559 dpcm_clear_pending_state(fe, stream);
2560 dpcm_be_disconnect(fe, stream);
2563 dpcm_path_put(&list);
2569 /* Called by DAPM mixer/mux changes to update audio routing between PCMs and
2572 int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
2574 struct snd_soc_pcm_runtime *fe;
2577 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2578 /* shutdown all old paths first */
2579 for_each_card_rtds(card, fe) {
2580 ret = soc_dpcm_fe_runtime_update(fe, 0);
2585 /* bring new paths up */
2586 for_each_card_rtds(card, fe) {
2587 ret = soc_dpcm_fe_runtime_update(fe, 1);
2593 mutex_unlock(&card->mutex);
2596 EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);
2598 static void dpcm_fe_dai_cleanup(struct snd_pcm_substream *fe_substream)
2600 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2601 struct snd_soc_dpcm *dpcm;
2602 int stream = fe_substream->stream;
2604 /* mark FE's links ready to prune */
2605 for_each_dpcm_be(fe, stream, dpcm)
2606 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2608 dpcm_be_disconnect(fe, stream);
2610 fe->dpcm[stream].runtime = NULL;
2613 static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
2615 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2618 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2619 ret = dpcm_fe_dai_shutdown(fe_substream);
2621 dpcm_fe_dai_cleanup(fe_substream);
2623 mutex_unlock(&fe->card->mutex);
2627 static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2629 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2630 struct snd_soc_dapm_widget_list *list;
2632 int stream = fe_substream->stream;
2634 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2635 fe->dpcm[stream].runtime = fe_substream->runtime;
2637 ret = dpcm_path_get(fe, stream, &list);
2640 } else if (ret == 0) {
2641 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2642 fe->dai_link->name, stream ? "capture" : "playback");
2645 /* calculate valid and active FE <-> BE dpcms */
2646 dpcm_process_paths(fe, stream, &list, 1);
2648 ret = dpcm_fe_dai_startup(fe_substream);
2650 dpcm_fe_dai_cleanup(fe_substream);
2652 dpcm_clear_pending_state(fe, stream);
2653 dpcm_path_put(&list);
2655 mutex_unlock(&fe->card->mutex);
2659 /* create a new pcm */
2660 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2662 struct snd_soc_dai *codec_dai;
2663 struct snd_soc_dai *cpu_dai;
2664 struct snd_soc_component *component;
2665 struct snd_pcm *pcm;
2667 int ret = 0, playback = 0, capture = 0;
2671 if (rtd->dai_link->dynamic && rtd->num_cpus > 1) {
2673 "DPCM doesn't support Multi CPU for Front-Ends yet\n");
2677 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
2678 if (rtd->dai_link->dpcm_playback) {
2679 stream = SNDRV_PCM_STREAM_PLAYBACK;
2681 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
2682 if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
2689 dev_err(rtd->card->dev,
2690 "No CPU DAIs support playback for stream %s\n",
2691 rtd->dai_link->stream_name);
2695 if (rtd->dai_link->dpcm_capture) {
2696 stream = SNDRV_PCM_STREAM_CAPTURE;
2698 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
2699 if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
2706 dev_err(rtd->card->dev,
2707 "No CPU DAIs support capture for stream %s\n",
2708 rtd->dai_link->stream_name);
2713 /* Adapt stream for codec2codec links */
2714 int cpu_capture = rtd->dai_link->params ?
2715 SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
2716 int cpu_playback = rtd->dai_link->params ?
2717 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
2719 for_each_rtd_codec_dais(rtd, i, codec_dai) {
2720 if (rtd->num_cpus == 1) {
2721 cpu_dai = asoc_rtd_to_cpu(rtd, 0);
2722 } else if (rtd->num_cpus == rtd->num_codecs) {
2723 cpu_dai = asoc_rtd_to_cpu(rtd, i);
2725 dev_err(rtd->card->dev,
2726 "N cpus to M codecs link is not supported yet\n");
2730 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
2731 snd_soc_dai_stream_valid(cpu_dai, cpu_playback))
2733 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
2734 snd_soc_dai_stream_valid(cpu_dai, cpu_capture))
2739 if (rtd->dai_link->playback_only) {
2744 if (rtd->dai_link->capture_only) {
2749 /* create the PCM */
2750 if (rtd->dai_link->params) {
2751 snprintf(new_name, sizeof(new_name), "codec2codec(%s)",
2752 rtd->dai_link->stream_name);
2754 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2755 playback, capture, &pcm);
2756 } else if (rtd->dai_link->no_pcm) {
2757 snprintf(new_name, sizeof(new_name), "(%s)",
2758 rtd->dai_link->stream_name);
2760 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2761 playback, capture, &pcm);
2763 if (rtd->dai_link->dynamic)
2764 snprintf(new_name, sizeof(new_name), "%s (*)",
2765 rtd->dai_link->stream_name);
2767 snprintf(new_name, sizeof(new_name), "%s %s-%d",
2768 rtd->dai_link->stream_name,
2769 (rtd->num_codecs > 1) ?
2770 "multicodec" : asoc_rtd_to_codec(rtd, 0)->name, num);
2772 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2776 dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n",
2777 new_name, rtd->dai_link->name, ret);
2780 dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
2782 /* DAPM dai link stream work */
2783 if (rtd->dai_link->params)
2784 rtd->close_delayed_work_func = codec2codec_close_delayed_work;
2786 rtd->close_delayed_work_func = snd_soc_close_delayed_work;
2788 pcm->nonatomic = rtd->dai_link->nonatomic;
2790 pcm->private_data = rtd;
2792 if (rtd->dai_link->no_pcm || rtd->dai_link->params) {
2794 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
2796 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
2800 /* ASoC PCM operations */
2801 if (rtd->dai_link->dynamic) {
2802 rtd->ops.open = dpcm_fe_dai_open;
2803 rtd->ops.hw_params = dpcm_fe_dai_hw_params;
2804 rtd->ops.prepare = dpcm_fe_dai_prepare;
2805 rtd->ops.trigger = dpcm_fe_dai_trigger;
2806 rtd->ops.hw_free = dpcm_fe_dai_hw_free;
2807 rtd->ops.close = dpcm_fe_dai_close;
2808 rtd->ops.pointer = soc_pcm_pointer;
2810 rtd->ops.open = soc_pcm_open;
2811 rtd->ops.hw_params = soc_pcm_hw_params;
2812 rtd->ops.prepare = soc_pcm_prepare;
2813 rtd->ops.trigger = soc_pcm_trigger;
2814 rtd->ops.hw_free = soc_pcm_hw_free;
2815 rtd->ops.close = soc_pcm_close;
2816 rtd->ops.pointer = soc_pcm_pointer;
2819 for_each_rtd_components(rtd, i, component) {
2820 const struct snd_soc_component_driver *drv = component->driver;
2823 rtd->ops.ioctl = snd_soc_pcm_component_ioctl;
2825 rtd->ops.sync_stop = snd_soc_pcm_component_sync_stop;
2827 rtd->ops.copy_user = snd_soc_pcm_component_copy_user;
2829 rtd->ops.page = snd_soc_pcm_component_page;
2831 rtd->ops.mmap = snd_soc_pcm_component_mmap;
2835 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
2838 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
2840 ret = snd_soc_pcm_component_new(rtd);
2842 dev_err(rtd->dev, "ASoC: pcm %s constructor failed for dailink %s: %d\n",
2843 new_name, rtd->dai_link->name, ret);
2847 pcm->no_device_suspend = true;
2849 dev_dbg(rtd->card->dev, "%s <-> %s mapping ok\n",
2850 (rtd->num_codecs > 1) ? "multicodec" : asoc_rtd_to_codec(rtd, 0)->name,
2851 (rtd->num_cpus > 1) ? "multicpu" : asoc_rtd_to_cpu(rtd, 0)->name);
2855 /* is the current PCM operation for this FE ? */
2856 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2858 if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2862 EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
2864 /* is the current PCM operation for this BE ? */
2865 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2866 struct snd_soc_pcm_runtime *be, int stream)
2868 if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2869 ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2870 be->dpcm[stream].runtime_update))
2874 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
2876 /* get the substream for this BE */
2877 struct snd_pcm_substream *
2878 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
2880 return be->pcm->streams[stream].substream;
2882 EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
2884 static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
2885 struct snd_soc_pcm_runtime *be,
2887 const enum snd_soc_dpcm_state *states,
2890 struct snd_soc_dpcm *dpcm;
2893 unsigned long flags;
2896 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2897 for_each_dpcm_fe(be, stream, dpcm) {
2902 state = dpcm->fe->dpcm[stream].state;
2903 for (i = 0; i < num_states; i++) {
2904 if (state == states[i]) {
2910 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2912 /* it's safe to do this BE DAI */
2917 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2918 * are not running, paused or suspended for the specified stream direction.
2920 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2921 struct snd_soc_pcm_runtime *be, int stream)
2923 const enum snd_soc_dpcm_state state[] = {
2924 SND_SOC_DPCM_STATE_START,
2925 SND_SOC_DPCM_STATE_PAUSED,
2926 SND_SOC_DPCM_STATE_SUSPEND,
2929 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2931 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
2934 * We can only change hw params a BE DAI if any of it's FE are not prepared,
2935 * running, paused or suspended for the specified stream direction.
2937 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2938 struct snd_soc_pcm_runtime *be, int stream)
2940 const enum snd_soc_dpcm_state state[] = {
2941 SND_SOC_DPCM_STATE_START,
2942 SND_SOC_DPCM_STATE_PAUSED,
2943 SND_SOC_DPCM_STATE_SUSPEND,
2944 SND_SOC_DPCM_STATE_PREPARE,
2947 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2949 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);