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 snd_soc_dapm_stream_stop(rtd, substream->stream);
668 mutex_unlock(&rtd->card->pcm_mutex);
670 snd_soc_pcm_component_pm_runtime_put(rtd, substream, rollback);
672 for_each_rtd_components(rtd, i, component)
673 if (!snd_soc_component_active(component))
674 pinctrl_pm_select_sleep_state(component->dev);
680 * Called by ALSA when a PCM substream is closed. Private data can be
681 * freed here. The cpu DAI, codec DAI, machine and components are also
684 static int soc_pcm_close(struct snd_pcm_substream *substream)
686 return soc_pcm_clean(substream, 0);
690 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
691 * then initialized and any private data can be allocated. This also calls
692 * startup for the cpu DAI, component, machine and codec DAI.
694 static int soc_pcm_open(struct snd_pcm_substream *substream)
696 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
697 struct snd_pcm_runtime *runtime = substream->runtime;
698 struct snd_soc_component *component;
699 struct snd_soc_dai *dai;
700 const char *codec_dai_name = "multicodec";
701 const char *cpu_dai_name = "multicpu";
704 for_each_rtd_components(rtd, i, component)
705 pinctrl_pm_select_default_state(component->dev);
707 ret = snd_soc_pcm_component_pm_runtime_get(rtd, substream);
711 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
713 ret = soc_pcm_components_open(substream);
717 ret = snd_soc_link_startup(substream);
721 /* startup the audio subsystem */
722 for_each_rtd_dais(rtd, i, dai) {
723 ret = snd_soc_dai_startup(dai, substream);
728 /* Dynamic PCM DAI links compat checks use dynamic capabilities */
729 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
732 /* Check that the codec and cpu DAIs are compatible */
733 soc_pcm_init_runtime_hw(substream);
735 if (rtd->num_codecs == 1)
736 codec_dai_name = asoc_rtd_to_codec(rtd, 0)->name;
738 if (rtd->num_cpus == 1)
739 cpu_dai_name = asoc_rtd_to_cpu(rtd, 0)->name;
741 if (soc_pcm_has_symmetry(substream))
742 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
745 if (!runtime->hw.rates) {
746 printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
747 codec_dai_name, cpu_dai_name);
750 if (!runtime->hw.formats) {
751 printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
752 codec_dai_name, cpu_dai_name);
755 if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
756 runtime->hw.channels_min > runtime->hw.channels_max) {
757 printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
758 codec_dai_name, cpu_dai_name);
762 soc_pcm_apply_msb(substream);
764 /* Symmetry only applies if we've already got an active stream. */
765 for_each_rtd_dais(rtd, i, dai) {
766 if (snd_soc_dai_active(dai)) {
767 ret = soc_pcm_apply_symmetry(substream, dai);
773 pr_debug("ASoC: %s <-> %s info:\n",
774 codec_dai_name, cpu_dai_name);
775 pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
776 pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
777 runtime->hw.channels_max);
778 pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min,
779 runtime->hw.rate_max);
781 snd_soc_runtime_activate(rtd, substream->stream);
784 mutex_unlock(&rtd->card->pcm_mutex);
787 soc_pcm_clean(substream, 1);
792 static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
795 * Currently nothing to do for c2c links
796 * Since c2c links are internal nodes in the DAPM graph and
797 * don't interface with the outside world or application layer
798 * we don't have to do any special handling on close.
803 * Called by ALSA when the PCM substream is prepared, can set format, sample
804 * rate, etc. This function is non atomic and can be called multiple times,
805 * it can refer to the runtime info.
807 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
809 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
810 struct snd_soc_dai *dai;
813 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
815 ret = snd_soc_link_prepare(substream);
819 ret = snd_soc_pcm_component_prepare(substream);
823 ret = snd_soc_pcm_dai_prepare(substream);
825 dev_err(rtd->dev, "ASoC: DAI prepare error: %d\n", ret);
829 /* cancel any delayed stream shutdown that is pending */
830 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
833 cancel_delayed_work(&rtd->delayed_work);
836 snd_soc_dapm_stream_event(rtd, substream->stream,
837 SND_SOC_DAPM_STREAM_START);
839 for_each_rtd_dais(rtd, i, dai)
840 snd_soc_dai_digital_mute(dai, 0, substream->stream);
843 mutex_unlock(&rtd->card->pcm_mutex);
847 static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
850 struct snd_interval *interval;
851 int channels = hweight_long(mask);
853 interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
854 interval->min = channels;
855 interval->max = channels;
859 * Called by ALSA when the hardware params are set by application. This
860 * function can also be called multiple times and can allocate buffers
861 * (using snd_pcm_lib_* ). It's non-atomic.
863 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
864 struct snd_pcm_hw_params *params)
866 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
867 struct snd_soc_component *component;
868 struct snd_soc_dai *cpu_dai;
869 struct snd_soc_dai *codec_dai;
872 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
874 ret = soc_pcm_params_symmetry(substream, params);
878 ret = snd_soc_link_hw_params(substream, params);
882 for_each_rtd_codec_dais(rtd, i, codec_dai) {
883 struct snd_pcm_hw_params codec_params;
886 * Skip CODECs which don't support the current stream type,
887 * the idea being that if a CODEC is not used for the currently
888 * set up transfer direction, it should not need to be
889 * configured, especially since the configuration used might
890 * not even be supported by that CODEC. There may be cases
891 * however where a CODEC needs to be set up although it is
892 * actually not being used for the transfer, e.g. if a
893 * capture-only CODEC is acting as an LRCLK and/or BCLK master
894 * for the DAI link including a playback-only CODEC.
895 * If this becomes necessary, we will have to augment the
896 * machine driver setup with information on how to act, so
897 * we can do the right thing here.
899 if (!snd_soc_dai_stream_valid(codec_dai, substream->stream))
902 /* copy params for each codec */
903 codec_params = *params;
905 /* fixup params based on TDM slot masks */
906 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
908 soc_pcm_codec_params_fixup(&codec_params,
911 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
913 soc_pcm_codec_params_fixup(&codec_params,
916 ret = snd_soc_dai_hw_params(codec_dai, substream,
921 codec_dai->rate = params_rate(&codec_params);
922 codec_dai->channels = params_channels(&codec_params);
923 codec_dai->sample_bits = snd_pcm_format_physical_width(
924 params_format(&codec_params));
926 snd_soc_dapm_update_dai(substream, &codec_params, codec_dai);
929 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
931 * Skip CPUs which don't support the current stream
932 * type. See soc_pcm_init_runtime_hw() for more details
934 if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
937 ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
941 /* store the parameters for each DAI */
942 cpu_dai->rate = params_rate(params);
943 cpu_dai->channels = params_channels(params);
944 cpu_dai->sample_bits =
945 snd_pcm_format_physical_width(params_format(params));
947 snd_soc_dapm_update_dai(substream, params, cpu_dai);
950 ret = snd_soc_pcm_component_hw_params(substream, params, &component);
955 mutex_unlock(&rtd->card->pcm_mutex);
959 snd_soc_pcm_component_hw_free(substream, component);
964 for_each_rtd_cpu_dais_rollback(rtd, i, cpu_dai) {
965 if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
968 snd_soc_dai_hw_free(cpu_dai, substream);
975 for_each_rtd_codec_dais_rollback(rtd, i, codec_dai) {
976 if (!snd_soc_dai_stream_valid(codec_dai, substream->stream))
979 snd_soc_dai_hw_free(codec_dai, substream);
983 snd_soc_link_hw_free(substream);
985 mutex_unlock(&rtd->card->pcm_mutex);
990 * Frees resources allocated by hw_params, can be called multiple times
992 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
994 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
995 struct snd_soc_dai *dai;
998 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
1000 /* clear the corresponding DAIs parameters when going to be inactive */
1001 for_each_rtd_dais(rtd, i, dai) {
1002 int active = snd_soc_dai_stream_active(dai, substream->stream);
1004 if (snd_soc_dai_active(dai) == 1) {
1007 dai->sample_bits = 0;
1011 snd_soc_dai_digital_mute(dai, 1, substream->stream);
1014 /* free any machine hw params */
1015 snd_soc_link_hw_free(substream);
1017 /* free any component resources */
1018 snd_soc_pcm_component_hw_free(substream, NULL);
1020 /* now free hw params for the DAIs */
1021 for_each_rtd_dais(rtd, i, dai) {
1022 if (!snd_soc_dai_stream_valid(dai, substream->stream))
1025 snd_soc_dai_hw_free(dai, substream);
1028 mutex_unlock(&rtd->card->pcm_mutex);
1032 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1037 case SNDRV_PCM_TRIGGER_START:
1038 case SNDRV_PCM_TRIGGER_RESUME:
1039 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1040 ret = snd_soc_link_trigger(substream, cmd);
1044 ret = snd_soc_pcm_component_trigger(substream, cmd);
1048 ret = snd_soc_pcm_dai_trigger(substream, cmd);
1050 case SNDRV_PCM_TRIGGER_STOP:
1051 case SNDRV_PCM_TRIGGER_SUSPEND:
1052 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1053 ret = snd_soc_pcm_dai_trigger(substream, cmd);
1057 ret = snd_soc_pcm_component_trigger(substream, cmd);
1061 ret = snd_soc_link_trigger(substream, cmd);
1069 * soc level wrapper for pointer callback
1070 * If cpu_dai, codec_dai, component driver has the delay callback, then
1071 * the runtime->delay will be updated accordingly.
1073 static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1075 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1076 struct snd_soc_dai *cpu_dai;
1077 struct snd_soc_dai *codec_dai;
1078 struct snd_pcm_runtime *runtime = substream->runtime;
1079 snd_pcm_uframes_t offset = 0;
1080 snd_pcm_sframes_t delay = 0;
1081 snd_pcm_sframes_t codec_delay = 0;
1082 snd_pcm_sframes_t cpu_delay = 0;
1085 /* clearing the previous total delay */
1088 offset = snd_soc_pcm_component_pointer(substream);
1090 /* base delay if assigned in pointer callback */
1091 delay = runtime->delay;
1093 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1094 cpu_delay = max(cpu_delay,
1095 snd_soc_dai_delay(cpu_dai, substream));
1099 for_each_rtd_codec_dais(rtd, i, codec_dai) {
1100 codec_delay = max(codec_delay,
1101 snd_soc_dai_delay(codec_dai, substream));
1103 delay += codec_delay;
1105 runtime->delay = delay;
1110 /* connect a FE and BE */
1111 static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
1112 struct snd_soc_pcm_runtime *be, int stream)
1114 struct snd_soc_dpcm *dpcm;
1115 unsigned long flags;
1117 /* only add new dpcms */
1118 for_each_dpcm_be(fe, stream, dpcm) {
1119 if (dpcm->be == be && dpcm->fe == fe)
1123 dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL);
1129 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
1130 dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
1131 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1132 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
1133 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
1134 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1136 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
1137 stream ? "capture" : "playback", fe->dai_link->name,
1138 stream ? "<-" : "->", be->dai_link->name);
1140 dpcm_create_debugfs_state(dpcm, stream);
1145 /* reparent a BE onto another FE */
1146 static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
1147 struct snd_soc_pcm_runtime *be, int stream)
1149 struct snd_soc_dpcm *dpcm;
1150 struct snd_pcm_substream *fe_substream, *be_substream;
1152 /* reparent if BE is connected to other FEs */
1153 if (!be->dpcm[stream].users)
1156 be_substream = snd_soc_dpcm_get_substream(be, stream);
1160 for_each_dpcm_fe(be, stream, dpcm) {
1164 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
1165 stream ? "capture" : "playback",
1166 dpcm->fe->dai_link->name,
1167 stream ? "<-" : "->", dpcm->be->dai_link->name);
1169 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
1170 be_substream->runtime = fe_substream->runtime;
1175 /* disconnect a BE and FE */
1176 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
1178 struct snd_soc_dpcm *dpcm, *d;
1179 unsigned long flags;
1181 for_each_dpcm_be_safe(fe, stream, dpcm, d) {
1182 dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
1183 stream ? "capture" : "playback",
1184 dpcm->be->dai_link->name);
1186 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
1189 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
1190 stream ? "capture" : "playback", fe->dai_link->name,
1191 stream ? "<-" : "->", dpcm->be->dai_link->name);
1193 /* BEs still alive need new FE */
1194 dpcm_be_reparent(fe, dpcm->be, stream);
1196 dpcm_remove_debugfs_state(dpcm);
1198 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1199 list_del(&dpcm->list_be);
1200 list_del(&dpcm->list_fe);
1201 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1206 /* get BE for DAI widget and stream */
1207 static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
1208 struct snd_soc_dapm_widget *widget, int stream)
1210 struct snd_soc_pcm_runtime *be;
1211 struct snd_soc_dapm_widget *w;
1212 struct snd_soc_dai *dai;
1215 dev_dbg(card->dev, "ASoC: find BE for widget %s\n", widget->name);
1217 for_each_card_rtds(card, be) {
1219 if (!be->dai_link->no_pcm)
1222 for_each_rtd_dais(be, i, dai) {
1223 w = snd_soc_dai_get_widget(dai, stream);
1225 dev_dbg(card->dev, "ASoC: try BE : %s\n",
1226 w ? w->name : "(not set)");
1233 /* Widget provided is not a BE */
1237 static int widget_in_list(struct snd_soc_dapm_widget_list *list,
1238 struct snd_soc_dapm_widget *widget)
1240 struct snd_soc_dapm_widget *w;
1243 for_each_dapm_widgets(list, i, w)
1250 static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
1251 enum snd_soc_dapm_direction dir)
1253 struct snd_soc_card *card = widget->dapm->card;
1254 struct snd_soc_pcm_runtime *rtd;
1257 /* adjust dir to stream */
1258 if (dir == SND_SOC_DAPM_DIR_OUT)
1259 stream = SNDRV_PCM_STREAM_PLAYBACK;
1261 stream = SNDRV_PCM_STREAM_CAPTURE;
1263 rtd = dpcm_get_be(card, widget, stream);
1270 int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
1271 int stream, struct snd_soc_dapm_widget_list **list)
1273 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
1276 if (fe->num_cpus > 1) {
1278 "%s doesn't support Multi CPU yet\n", __func__);
1282 /* get number of valid DAI paths and their widgets */
1283 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
1284 dpcm_end_walk_at_be);
1286 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
1287 stream ? "capture" : "playback");
1292 void dpcm_path_put(struct snd_soc_dapm_widget_list **list)
1294 snd_soc_dapm_dai_free_widgets(list);
1297 static bool dpcm_be_is_active(struct snd_soc_dpcm *dpcm, int stream,
1298 struct snd_soc_dapm_widget_list *list)
1300 struct snd_soc_dapm_widget *widget;
1301 struct snd_soc_dai *dai;
1304 /* is there a valid DAI widget for this BE */
1305 for_each_rtd_dais(dpcm->be, i, dai) {
1306 widget = snd_soc_dai_get_widget(dai, stream);
1309 * The BE is pruned only if none of the dai
1310 * widgets are in the active list.
1312 if (widget && widget_in_list(list, widget))
1319 static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
1320 struct snd_soc_dapm_widget_list **list_)
1322 struct snd_soc_dpcm *dpcm;
1325 /* Destroy any old FE <--> BE connections */
1326 for_each_dpcm_be(fe, stream, dpcm) {
1327 if (dpcm_be_is_active(dpcm, stream, *list_))
1330 dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
1331 stream ? "capture" : "playback",
1332 dpcm->be->dai_link->name, fe->dai_link->name);
1333 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1334 dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1338 dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune);
1342 static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1343 struct snd_soc_dapm_widget_list **list_)
1345 struct snd_soc_card *card = fe->card;
1346 struct snd_soc_dapm_widget_list *list = *list_;
1347 struct snd_soc_pcm_runtime *be;
1348 struct snd_soc_dapm_widget *widget;
1349 int i, new = 0, err;
1351 /* Create any new FE <--> BE connections */
1352 for_each_dapm_widgets(list, i, widget) {
1354 switch (widget->id) {
1355 case snd_soc_dapm_dai_in:
1356 if (stream != SNDRV_PCM_STREAM_PLAYBACK)
1359 case snd_soc_dapm_dai_out:
1360 if (stream != SNDRV_PCM_STREAM_CAPTURE)
1367 /* is there a valid BE rtd for this widget */
1368 be = dpcm_get_be(card, widget, stream);
1370 dev_err(fe->dev, "ASoC: no BE found for %s\n",
1375 /* don't connect if FE is not running */
1376 if (!fe->dpcm[stream].runtime && !fe->fe_compr)
1379 /* newly connected FE and BE */
1380 err = dpcm_be_connect(fe, be, stream);
1382 dev_err(fe->dev, "ASoC: can't connect %s\n",
1385 } else if (err == 0) /* already connected */
1389 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1393 dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new);
1398 * Find the corresponding BE DAIs that source or sink audio to this
1401 int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
1402 int stream, struct snd_soc_dapm_widget_list **list, int new)
1405 return dpcm_add_paths(fe, stream, list);
1407 return dpcm_prune_paths(fe, stream, list);
1410 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
1412 struct snd_soc_dpcm *dpcm;
1413 unsigned long flags;
1415 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1416 for_each_dpcm_be(fe, stream, dpcm)
1417 dpcm->be->dpcm[stream].runtime_update =
1418 SND_SOC_DPCM_UPDATE_NO;
1419 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1422 static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
1425 struct snd_soc_dpcm *dpcm;
1427 /* disable any enabled and non active backends */
1428 for_each_dpcm_be(fe, stream, dpcm) {
1430 struct snd_soc_pcm_runtime *be = dpcm->be;
1431 struct snd_pcm_substream *be_substream =
1432 snd_soc_dpcm_get_substream(be, stream);
1434 if (be->dpcm[stream].users == 0)
1435 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1436 stream ? "capture" : "playback",
1437 be->dpcm[stream].state);
1439 if (--be->dpcm[stream].users != 0)
1442 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1445 soc_pcm_close(be_substream);
1446 be_substream->runtime = NULL;
1447 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1451 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1453 struct snd_soc_dpcm *dpcm;
1456 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1457 for_each_dpcm_be(fe, stream, dpcm) {
1459 struct snd_soc_pcm_runtime *be = dpcm->be;
1460 struct snd_pcm_substream *be_substream =
1461 snd_soc_dpcm_get_substream(be, stream);
1463 if (!be_substream) {
1464 dev_err(be->dev, "ASoC: no backend %s stream\n",
1465 stream ? "capture" : "playback");
1469 /* is this op for this BE ? */
1470 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1473 /* first time the dpcm is open ? */
1474 if (be->dpcm[stream].users == DPCM_MAX_BE_USERS)
1475 dev_err(be->dev, "ASoC: too many users %s at open %d\n",
1476 stream ? "capture" : "playback",
1477 be->dpcm[stream].state);
1479 if (be->dpcm[stream].users++ != 0)
1482 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1483 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1486 dev_dbg(be->dev, "ASoC: open %s BE %s\n",
1487 stream ? "capture" : "playback", be->dai_link->name);
1489 be_substream->runtime = be->dpcm[stream].runtime;
1490 err = soc_pcm_open(be_substream);
1492 dev_err(be->dev, "ASoC: BE open failed %d\n", err);
1493 be->dpcm[stream].users--;
1494 if (be->dpcm[stream].users < 0)
1495 dev_err(be->dev, "ASoC: no users %s at unwind %d\n",
1496 stream ? "capture" : "playback",
1497 be->dpcm[stream].state);
1499 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1503 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1510 /* disable any enabled and non active backends */
1511 for_each_dpcm_be_rollback(fe, stream, dpcm) {
1512 struct snd_soc_pcm_runtime *be = dpcm->be;
1513 struct snd_pcm_substream *be_substream =
1514 snd_soc_dpcm_get_substream(be, stream);
1516 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1519 if (be->dpcm[stream].users == 0)
1520 dev_err(be->dev, "ASoC: no users %s at close %d\n",
1521 stream ? "capture" : "playback",
1522 be->dpcm[stream].state);
1524 if (--be->dpcm[stream].users != 0)
1527 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1530 soc_pcm_close(be_substream);
1531 be_substream->runtime = NULL;
1532 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1538 static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
1539 struct snd_soc_pcm_stream *stream)
1541 runtime->hw.rate_min = stream->rate_min;
1542 runtime->hw.rate_max = min_not_zero(stream->rate_max, UINT_MAX);
1543 runtime->hw.channels_min = stream->channels_min;
1544 runtime->hw.channels_max = stream->channels_max;
1545 if (runtime->hw.formats)
1546 runtime->hw.formats &= stream->formats;
1548 runtime->hw.formats = stream->formats;
1549 runtime->hw.rates = stream->rates;
1552 static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
1555 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1556 struct snd_soc_dpcm *dpcm;
1557 struct snd_soc_dai *dai;
1558 int stream = substream->stream;
1560 if (!fe->dai_link->dpcm_merged_format)
1564 * It returns merged BE codec format
1565 * if FE want to use it (= dpcm_merged_format)
1568 for_each_dpcm_be(fe, stream, dpcm) {
1569 struct snd_soc_pcm_runtime *be = dpcm->be;
1570 struct snd_soc_pcm_stream *codec_stream;
1573 for_each_rtd_codec_dais(be, i, dai) {
1575 * Skip CODECs which don't support the current stream
1576 * type. See soc_pcm_init_runtime_hw() for more details
1578 if (!snd_soc_dai_stream_valid(dai, stream))
1581 codec_stream = snd_soc_dai_get_pcm_stream(dai, stream);
1583 *formats &= codec_stream->formats;
1588 static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,
1589 unsigned int *channels_min,
1590 unsigned int *channels_max)
1592 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1593 struct snd_soc_dpcm *dpcm;
1594 int stream = substream->stream;
1596 if (!fe->dai_link->dpcm_merged_chan)
1600 * It returns merged BE codec channel;
1601 * if FE want to use it (= dpcm_merged_chan)
1604 for_each_dpcm_be(fe, stream, dpcm) {
1605 struct snd_soc_pcm_runtime *be = dpcm->be;
1606 struct snd_soc_pcm_stream *codec_stream;
1607 struct snd_soc_pcm_stream *cpu_stream;
1608 struct snd_soc_dai *dai;
1611 for_each_rtd_cpu_dais(be, i, dai) {
1613 * Skip CPUs which don't support the current stream
1614 * type. See soc_pcm_init_runtime_hw() for more details
1616 if (!snd_soc_dai_stream_valid(dai, stream))
1619 cpu_stream = snd_soc_dai_get_pcm_stream(dai, stream);
1621 *channels_min = max(*channels_min,
1622 cpu_stream->channels_min);
1623 *channels_max = min(*channels_max,
1624 cpu_stream->channels_max);
1628 * chan min/max cannot be enforced if there are multiple CODEC
1629 * DAIs connected to a single CPU DAI, use CPU DAI's directly
1631 if (be->num_codecs == 1) {
1632 codec_stream = snd_soc_dai_get_pcm_stream(asoc_rtd_to_codec(be, 0), stream);
1634 *channels_min = max(*channels_min,
1635 codec_stream->channels_min);
1636 *channels_max = min(*channels_max,
1637 codec_stream->channels_max);
1642 static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
1643 unsigned int *rates,
1644 unsigned int *rate_min,
1645 unsigned int *rate_max)
1647 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1648 struct snd_soc_dpcm *dpcm;
1649 int stream = substream->stream;
1651 if (!fe->dai_link->dpcm_merged_rate)
1655 * It returns merged BE codec channel;
1656 * if FE want to use it (= dpcm_merged_chan)
1659 for_each_dpcm_be(fe, stream, dpcm) {
1660 struct snd_soc_pcm_runtime *be = dpcm->be;
1661 struct snd_soc_pcm_stream *pcm;
1662 struct snd_soc_dai *dai;
1665 for_each_rtd_dais(be, i, dai) {
1667 * Skip DAIs which don't support the current stream
1668 * type. See soc_pcm_init_runtime_hw() for more details
1670 if (!snd_soc_dai_stream_valid(dai, stream))
1673 pcm = snd_soc_dai_get_pcm_stream(dai, stream);
1675 *rate_min = max(*rate_min, pcm->rate_min);
1676 *rate_max = min_not_zero(*rate_max, pcm->rate_max);
1677 *rates = snd_pcm_rate_mask_intersect(*rates, pcm->rates);
1682 static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1684 struct snd_pcm_runtime *runtime = substream->runtime;
1685 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1686 struct snd_soc_dai *cpu_dai;
1689 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1691 * Skip CPUs which don't support the current stream
1692 * type. See soc_pcm_init_runtime_hw() for more details
1694 if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
1697 dpcm_init_runtime_hw(runtime,
1698 snd_soc_dai_get_pcm_stream(cpu_dai,
1699 substream->stream));
1702 dpcm_runtime_merge_format(substream, &runtime->hw.formats);
1703 dpcm_runtime_merge_chan(substream, &runtime->hw.channels_min,
1704 &runtime->hw.channels_max);
1705 dpcm_runtime_merge_rate(substream, &runtime->hw.rates,
1706 &runtime->hw.rate_min, &runtime->hw.rate_max);
1709 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
1711 /* Set FE's runtime_update state; the state is protected via PCM stream lock
1712 * for avoiding the race with trigger callback.
1713 * If the state is unset and a trigger is pending while the previous operation,
1714 * process the pending trigger action here.
1716 static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1717 int stream, enum snd_soc_dpcm_update state)
1719 struct snd_pcm_substream *substream =
1720 snd_soc_dpcm_get_substream(fe, stream);
1722 snd_pcm_stream_lock_irq(substream);
1723 if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1724 dpcm_fe_dai_do_trigger(substream,
1725 fe->dpcm[stream].trigger_pending - 1);
1726 fe->dpcm[stream].trigger_pending = 0;
1728 fe->dpcm[stream].runtime_update = state;
1729 snd_pcm_stream_unlock_irq(substream);
1732 static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
1735 struct snd_soc_dpcm *dpcm;
1736 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1737 struct snd_soc_dai *fe_cpu_dai;
1741 /* apply symmetry for FE */
1742 if (soc_pcm_has_symmetry(fe_substream))
1743 fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1745 for_each_rtd_cpu_dais (fe, i, fe_cpu_dai) {
1746 /* Symmetry only applies if we've got an active stream. */
1747 if (snd_soc_dai_active(fe_cpu_dai)) {
1748 err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
1754 /* apply symmetry for BE */
1755 for_each_dpcm_be(fe, stream, dpcm) {
1756 struct snd_soc_pcm_runtime *be = dpcm->be;
1757 struct snd_pcm_substream *be_substream =
1758 snd_soc_dpcm_get_substream(be, stream);
1759 struct snd_soc_pcm_runtime *rtd;
1760 struct snd_soc_dai *dai;
1763 /* A backend may not have the requested substream */
1767 rtd = asoc_substream_to_rtd(be_substream);
1768 if (rtd->dai_link->be_hw_params_fixup)
1771 if (soc_pcm_has_symmetry(be_substream))
1772 be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1774 /* Symmetry only applies if we've got an active stream. */
1775 for_each_rtd_dais(rtd, i, dai) {
1776 if (snd_soc_dai_active(dai)) {
1777 err = soc_pcm_apply_symmetry(fe_substream, dai);
1787 static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1789 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1790 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1791 int stream = fe_substream->stream, ret = 0;
1793 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1795 ret = dpcm_be_dai_startup(fe, stream);
1797 dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret);
1801 dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name);
1803 /* start the DAI frontend */
1804 ret = soc_pcm_open(fe_substream);
1806 dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret);
1810 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1812 dpcm_set_fe_runtime(fe_substream);
1813 snd_pcm_limit_hw_rates(runtime);
1815 ret = dpcm_apply_symmetry(fe_substream, stream);
1817 dev_err(fe->dev, "ASoC: failed to apply dpcm symmetry %d\n",
1822 dpcm_be_dai_startup_unwind(fe, stream);
1824 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1828 int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1830 struct snd_soc_dpcm *dpcm;
1832 /* only shutdown BEs that are either sinks or sources to this FE DAI */
1833 for_each_dpcm_be(fe, stream, dpcm) {
1835 struct snd_soc_pcm_runtime *be = dpcm->be;
1836 struct snd_pcm_substream *be_substream =
1837 snd_soc_dpcm_get_substream(be, stream);
1839 /* is this op for this BE ? */
1840 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1843 if (be->dpcm[stream].users == 0)
1844 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1845 stream ? "capture" : "playback",
1846 be->dpcm[stream].state);
1848 if (--be->dpcm[stream].users != 0)
1851 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1852 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)) {
1853 soc_pcm_hw_free(be_substream);
1854 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1857 dev_dbg(be->dev, "ASoC: close BE %s\n",
1858 be->dai_link->name);
1860 soc_pcm_close(be_substream);
1861 be_substream->runtime = NULL;
1863 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1868 static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1870 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1871 int stream = substream->stream;
1873 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1875 /* shutdown the BEs */
1876 dpcm_be_dai_shutdown(fe, stream);
1878 dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name);
1880 /* now shutdown the frontend */
1881 soc_pcm_close(substream);
1883 /* run the stream event for each BE */
1884 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1886 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1887 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1891 int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1893 struct snd_soc_dpcm *dpcm;
1895 /* only hw_params backends that are either sinks or sources
1896 * to this frontend DAI */
1897 for_each_dpcm_be(fe, stream, dpcm) {
1899 struct snd_soc_pcm_runtime *be = dpcm->be;
1900 struct snd_pcm_substream *be_substream =
1901 snd_soc_dpcm_get_substream(be, stream);
1903 /* is this op for this BE ? */
1904 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1907 /* only free hw when no longer used - check all FEs */
1908 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1911 /* do not free hw if this BE is used by other FE */
1912 if (be->dpcm[stream].users > 1)
1915 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1916 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1917 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1918 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
1919 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
1920 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1923 dev_dbg(be->dev, "ASoC: hw_free BE %s\n",
1924 be->dai_link->name);
1926 soc_pcm_hw_free(be_substream);
1928 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1934 static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1936 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1937 int err, stream = substream->stream;
1939 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1940 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1942 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
1944 /* call hw_free on the frontend */
1945 err = soc_pcm_hw_free(substream);
1947 dev_err(fe->dev,"ASoC: hw_free FE %s failed\n",
1948 fe->dai_link->name);
1950 /* only hw_params backends that are either sinks or sources
1951 * to this frontend DAI */
1952 err = dpcm_be_dai_hw_free(fe, stream);
1954 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1955 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1957 mutex_unlock(&fe->card->mutex);
1961 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1963 struct snd_soc_dpcm *dpcm;
1966 for_each_dpcm_be(fe, stream, dpcm) {
1968 struct snd_soc_pcm_runtime *be = dpcm->be;
1969 struct snd_pcm_substream *be_substream =
1970 snd_soc_dpcm_get_substream(be, stream);
1972 /* is this op for this BE ? */
1973 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1976 /* copy params for each dpcm */
1977 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1978 sizeof(struct snd_pcm_hw_params));
1980 /* perform any hw_params fixups */
1981 ret = snd_soc_link_be_hw_params_fixup(be, &dpcm->hw_params);
1985 /* copy the fixed-up hw params for BE dai */
1986 memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
1987 sizeof(struct snd_pcm_hw_params));
1989 /* only allow hw_params() if no connected FEs are running */
1990 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1993 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1994 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1995 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1998 dev_dbg(be->dev, "ASoC: hw_params BE %s\n",
1999 be->dai_link->name);
2001 ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params);
2003 dev_err(dpcm->be->dev,
2004 "ASoC: hw_params BE failed %d\n", ret);
2008 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
2013 /* disable any enabled and non active backends */
2014 for_each_dpcm_be_rollback(fe, stream, dpcm) {
2015 struct snd_soc_pcm_runtime *be = dpcm->be;
2016 struct snd_pcm_substream *be_substream =
2017 snd_soc_dpcm_get_substream(be, stream);
2019 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2022 /* only allow hw_free() if no connected FEs are running */
2023 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2026 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
2027 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
2028 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
2029 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
2032 soc_pcm_hw_free(be_substream);
2038 static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
2039 struct snd_pcm_hw_params *params)
2041 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2042 int ret, stream = substream->stream;
2044 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2045 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2047 memcpy(&fe->dpcm[stream].hw_params, params,
2048 sizeof(struct snd_pcm_hw_params));
2049 ret = dpcm_be_dai_hw_params(fe, stream);
2051 dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret);
2055 dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
2056 fe->dai_link->name, params_rate(params),
2057 params_channels(params), params_format(params));
2059 /* call hw_params on the frontend */
2060 ret = soc_pcm_hw_params(substream, params);
2062 dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret);
2063 dpcm_be_dai_hw_free(fe, stream);
2065 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
2068 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2069 mutex_unlock(&fe->card->mutex);
2073 static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm,
2074 struct snd_pcm_substream *substream, int cmd)
2078 dev_dbg(dpcm->be->dev, "ASoC: trigger BE %s cmd %d\n",
2079 dpcm->be->dai_link->name, cmd);
2081 ret = soc_pcm_trigger(substream, cmd);
2083 dev_err(dpcm->be->dev,"ASoC: trigger BE failed %d\n", ret);
2088 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
2091 struct snd_soc_dpcm *dpcm;
2094 for_each_dpcm_be(fe, stream, dpcm) {
2096 struct snd_soc_pcm_runtime *be = dpcm->be;
2097 struct snd_pcm_substream *be_substream =
2098 snd_soc_dpcm_get_substream(be, stream);
2100 /* is this op for this BE ? */
2101 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2105 case SNDRV_PCM_TRIGGER_START:
2106 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
2107 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
2108 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2111 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2115 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2117 case SNDRV_PCM_TRIGGER_RESUME:
2118 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
2121 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2125 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2127 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2128 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2131 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2135 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2137 case SNDRV_PCM_TRIGGER_STOP:
2138 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) &&
2139 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2142 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2145 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2149 be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2151 case SNDRV_PCM_TRIGGER_SUSPEND:
2152 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2155 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2158 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2162 be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
2164 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2165 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2168 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2171 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2175 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2182 EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
2184 static int dpcm_dai_trigger_fe_be(struct snd_pcm_substream *substream,
2185 int cmd, bool fe_first)
2187 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2190 /* call trigger on the frontend before the backend. */
2192 dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n",
2193 fe->dai_link->name, cmd);
2195 ret = soc_pcm_trigger(substream, cmd);
2199 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2203 /* call trigger on the frontend after the backend. */
2204 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2208 dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
2209 fe->dai_link->name, cmd);
2211 ret = soc_pcm_trigger(substream, cmd);
2216 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
2218 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2219 int stream = substream->stream;
2221 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2223 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
2226 case SND_SOC_DPCM_TRIGGER_PRE:
2228 case SNDRV_PCM_TRIGGER_START:
2229 case SNDRV_PCM_TRIGGER_RESUME:
2230 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2231 case SNDRV_PCM_TRIGGER_DRAIN:
2232 ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
2234 case SNDRV_PCM_TRIGGER_STOP:
2235 case SNDRV_PCM_TRIGGER_SUSPEND:
2236 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2237 ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
2244 case SND_SOC_DPCM_TRIGGER_POST:
2246 case SNDRV_PCM_TRIGGER_START:
2247 case SNDRV_PCM_TRIGGER_RESUME:
2248 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2249 case SNDRV_PCM_TRIGGER_DRAIN:
2250 ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
2252 case SNDRV_PCM_TRIGGER_STOP:
2253 case SNDRV_PCM_TRIGGER_SUSPEND:
2254 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2255 ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
2262 case SND_SOC_DPCM_TRIGGER_BESPOKE:
2263 /* bespoke trigger() - handles both FE and BEs */
2265 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
2266 fe->dai_link->name, cmd);
2268 ret = snd_soc_pcm_dai_bespoke_trigger(substream, cmd);
2271 dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
2272 fe->dai_link->name);
2278 dev_err(fe->dev, "ASoC: trigger FE cmd: %d failed: %d\n",
2284 case SNDRV_PCM_TRIGGER_START:
2285 case SNDRV_PCM_TRIGGER_RESUME:
2286 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2287 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2289 case SNDRV_PCM_TRIGGER_STOP:
2290 case SNDRV_PCM_TRIGGER_SUSPEND:
2291 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2293 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2294 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2299 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
2303 static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
2305 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2306 int stream = substream->stream;
2308 /* if FE's runtime_update is already set, we're in race;
2309 * process this trigger later at exit
2311 if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2312 fe->dpcm[stream].trigger_pending = cmd + 1;
2313 return 0; /* delayed, assuming it's successful */
2316 /* we're alone, let's trigger */
2317 return dpcm_fe_dai_do_trigger(substream, cmd);
2320 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
2322 struct snd_soc_dpcm *dpcm;
2325 for_each_dpcm_be(fe, stream, dpcm) {
2327 struct snd_soc_pcm_runtime *be = dpcm->be;
2328 struct snd_pcm_substream *be_substream =
2329 snd_soc_dpcm_get_substream(be, stream);
2331 /* is this op for this BE ? */
2332 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2335 if (!snd_soc_dpcm_can_be_prepared(fe, be, stream))
2338 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
2339 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
2340 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND) &&
2341 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2344 dev_dbg(be->dev, "ASoC: prepare BE %s\n",
2345 be->dai_link->name);
2347 ret = soc_pcm_prepare(be_substream);
2349 dev_err(be->dev, "ASoC: backend prepare failed %d\n",
2354 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2359 static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
2361 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2362 int stream = substream->stream, ret = 0;
2364 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2366 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
2368 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2370 /* there is no point preparing this FE if there are no BEs */
2371 if (list_empty(&fe->dpcm[stream].be_clients)) {
2372 dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
2373 fe->dai_link->name);
2378 ret = dpcm_be_dai_prepare(fe, stream);
2382 /* call prepare on the frontend */
2383 ret = soc_pcm_prepare(substream);
2385 dev_err(fe->dev,"ASoC: prepare FE %s failed\n",
2386 fe->dai_link->name);
2390 /* run the stream event for each BE */
2391 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
2392 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2395 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2396 mutex_unlock(&fe->card->mutex);
2401 static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
2403 struct snd_pcm_substream *substream =
2404 snd_soc_dpcm_get_substream(fe, stream);
2405 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2408 dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
2409 stream ? "capture" : "playback", fe->dai_link->name);
2411 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2412 /* call bespoke trigger - FE takes care of all BE triggers */
2413 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
2414 fe->dai_link->name);
2416 err = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
2418 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2420 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
2421 fe->dai_link->name);
2423 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
2425 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2428 err = dpcm_be_dai_hw_free(fe, stream);
2430 dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err);
2432 err = dpcm_be_dai_shutdown(fe, stream);
2434 dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err);
2436 /* run the stream event for each BE */
2437 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2442 static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
2444 struct snd_pcm_substream *substream =
2445 snd_soc_dpcm_get_substream(fe, stream);
2446 struct snd_soc_dpcm *dpcm;
2447 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2449 unsigned long flags;
2451 dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
2452 stream ? "capture" : "playback", fe->dai_link->name);
2454 /* Only start the BE if the FE is ready */
2455 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
2456 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2459 /* startup must always be called for new BEs */
2460 ret = dpcm_be_dai_startup(fe, stream);
2464 /* keep going if FE state is > open */
2465 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
2468 ret = dpcm_be_dai_hw_params(fe, stream);
2472 /* keep going if FE state is > hw_params */
2473 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
2477 ret = dpcm_be_dai_prepare(fe, stream);
2481 /* run the stream event for each BE */
2482 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2484 /* keep going if FE state is > prepare */
2485 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
2486 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
2489 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2490 /* call trigger on the frontend - FE takes care of all BE triggers */
2491 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
2492 fe->dai_link->name);
2494 ret = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
2496 dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret);
2500 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
2501 fe->dai_link->name);
2503 ret = dpcm_be_dai_trigger(fe, stream,
2504 SNDRV_PCM_TRIGGER_START);
2506 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
2514 dpcm_be_dai_hw_free(fe, stream);
2516 dpcm_be_dai_shutdown(fe, stream);
2518 /* disconnect any closed BEs */
2519 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2520 for_each_dpcm_be(fe, stream, dpcm) {
2521 struct snd_soc_pcm_runtime *be = dpcm->be;
2522 if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2523 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2525 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2530 static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
2532 struct snd_soc_dapm_widget_list *list;
2537 if (!fe->dai_link->dynamic)
2540 if (fe->num_cpus > 1) {
2542 "%s doesn't support Multi CPU yet\n", __func__);
2546 /* only check active links */
2547 if (!snd_soc_dai_active(asoc_rtd_to_cpu(fe, 0)))
2550 /* DAPM sync will call this to update DSP paths */
2551 dev_dbg(fe->dev, "ASoC: DPCM %s runtime update for FE %s\n",
2552 new ? "new" : "old", fe->dai_link->name);
2554 for_each_pcm_streams(stream) {
2556 /* skip if FE doesn't have playback/capture capability */
2557 if (!snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream) ||
2558 !snd_soc_dai_stream_valid(asoc_rtd_to_codec(fe, 0), stream))
2561 /* skip if FE isn't currently playing/capturing */
2562 if (!snd_soc_dai_stream_active(asoc_rtd_to_cpu(fe, 0), stream) ||
2563 !snd_soc_dai_stream_active(asoc_rtd_to_codec(fe, 0), stream))
2566 paths = dpcm_path_get(fe, stream, &list);
2568 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2570 stream == SNDRV_PCM_STREAM_PLAYBACK ?
2571 "playback" : "capture");
2575 /* update any playback/capture paths */
2576 count = dpcm_process_paths(fe, stream, &list, new);
2578 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2580 ret = dpcm_run_update_startup(fe, stream);
2582 ret = dpcm_run_update_shutdown(fe, stream);
2584 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
2585 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2587 dpcm_clear_pending_state(fe, stream);
2588 dpcm_be_disconnect(fe, stream);
2591 dpcm_path_put(&list);
2597 /* Called by DAPM mixer/mux changes to update audio routing between PCMs and
2600 int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
2602 struct snd_soc_pcm_runtime *fe;
2605 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2606 /* shutdown all old paths first */
2607 for_each_card_rtds(card, fe) {
2608 ret = soc_dpcm_fe_runtime_update(fe, 0);
2613 /* bring new paths up */
2614 for_each_card_rtds(card, fe) {
2615 ret = soc_dpcm_fe_runtime_update(fe, 1);
2621 mutex_unlock(&card->mutex);
2624 EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);
2626 static void dpcm_fe_dai_cleanup(struct snd_pcm_substream *fe_substream)
2628 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2629 struct snd_soc_dpcm *dpcm;
2630 int stream = fe_substream->stream;
2632 /* mark FE's links ready to prune */
2633 for_each_dpcm_be(fe, stream, dpcm)
2634 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2636 dpcm_be_disconnect(fe, stream);
2638 fe->dpcm[stream].runtime = NULL;
2641 static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
2643 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2646 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2647 ret = dpcm_fe_dai_shutdown(fe_substream);
2649 dpcm_fe_dai_cleanup(fe_substream);
2651 mutex_unlock(&fe->card->mutex);
2655 static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2657 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2658 struct snd_soc_dapm_widget_list *list;
2660 int stream = fe_substream->stream;
2662 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2663 fe->dpcm[stream].runtime = fe_substream->runtime;
2665 ret = dpcm_path_get(fe, stream, &list);
2668 } else if (ret == 0) {
2669 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2670 fe->dai_link->name, stream ? "capture" : "playback");
2673 /* calculate valid and active FE <-> BE dpcms */
2674 dpcm_process_paths(fe, stream, &list, 1);
2676 ret = dpcm_fe_dai_startup(fe_substream);
2678 dpcm_fe_dai_cleanup(fe_substream);
2680 dpcm_clear_pending_state(fe, stream);
2681 dpcm_path_put(&list);
2683 mutex_unlock(&fe->card->mutex);
2687 /* create a new pcm */
2688 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2690 struct snd_soc_dai *codec_dai;
2691 struct snd_soc_dai *cpu_dai;
2692 struct snd_soc_component *component;
2693 struct snd_pcm *pcm;
2695 int ret = 0, playback = 0, capture = 0;
2699 if (rtd->dai_link->dynamic && rtd->num_cpus > 1) {
2701 "DPCM doesn't support Multi CPU for Front-Ends yet\n");
2705 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
2706 if (rtd->dai_link->dpcm_playback) {
2707 stream = SNDRV_PCM_STREAM_PLAYBACK;
2709 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
2710 if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
2717 dev_err(rtd->card->dev,
2718 "No CPU DAIs support playback for stream %s\n",
2719 rtd->dai_link->stream_name);
2723 if (rtd->dai_link->dpcm_capture) {
2724 stream = SNDRV_PCM_STREAM_CAPTURE;
2726 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
2727 if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
2734 dev_err(rtd->card->dev,
2735 "No CPU DAIs support capture for stream %s\n",
2736 rtd->dai_link->stream_name);
2741 /* Adapt stream for codec2codec links */
2742 int cpu_capture = rtd->dai_link->params ?
2743 SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
2744 int cpu_playback = rtd->dai_link->params ?
2745 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
2747 for_each_rtd_codec_dais(rtd, i, codec_dai) {
2748 if (rtd->num_cpus == 1) {
2749 cpu_dai = asoc_rtd_to_cpu(rtd, 0);
2750 } else if (rtd->num_cpus == rtd->num_codecs) {
2751 cpu_dai = asoc_rtd_to_cpu(rtd, i);
2753 dev_err(rtd->card->dev,
2754 "N cpus to M codecs link is not supported yet\n");
2758 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
2759 snd_soc_dai_stream_valid(cpu_dai, cpu_playback))
2761 if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
2762 snd_soc_dai_stream_valid(cpu_dai, cpu_capture))
2767 if (rtd->dai_link->playback_only) {
2772 if (rtd->dai_link->capture_only) {
2777 /* create the PCM */
2778 if (rtd->dai_link->params) {
2779 snprintf(new_name, sizeof(new_name), "codec2codec(%s)",
2780 rtd->dai_link->stream_name);
2782 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2783 playback, capture, &pcm);
2784 } else if (rtd->dai_link->no_pcm) {
2785 snprintf(new_name, sizeof(new_name), "(%s)",
2786 rtd->dai_link->stream_name);
2788 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2789 playback, capture, &pcm);
2791 if (rtd->dai_link->dynamic)
2792 snprintf(new_name, sizeof(new_name), "%s (*)",
2793 rtd->dai_link->stream_name);
2795 snprintf(new_name, sizeof(new_name), "%s %s-%d",
2796 rtd->dai_link->stream_name,
2797 (rtd->num_codecs > 1) ?
2798 "multicodec" : asoc_rtd_to_codec(rtd, 0)->name, num);
2800 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2804 dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n",
2805 new_name, rtd->dai_link->name, ret);
2808 dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
2810 /* DAPM dai link stream work */
2811 if (rtd->dai_link->params)
2812 rtd->close_delayed_work_func = codec2codec_close_delayed_work;
2814 rtd->close_delayed_work_func = snd_soc_close_delayed_work;
2816 pcm->nonatomic = rtd->dai_link->nonatomic;
2818 pcm->private_data = rtd;
2820 if (rtd->dai_link->no_pcm || rtd->dai_link->params) {
2822 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
2824 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
2828 /* ASoC PCM operations */
2829 if (rtd->dai_link->dynamic) {
2830 rtd->ops.open = dpcm_fe_dai_open;
2831 rtd->ops.hw_params = dpcm_fe_dai_hw_params;
2832 rtd->ops.prepare = dpcm_fe_dai_prepare;
2833 rtd->ops.trigger = dpcm_fe_dai_trigger;
2834 rtd->ops.hw_free = dpcm_fe_dai_hw_free;
2835 rtd->ops.close = dpcm_fe_dai_close;
2836 rtd->ops.pointer = soc_pcm_pointer;
2838 rtd->ops.open = soc_pcm_open;
2839 rtd->ops.hw_params = soc_pcm_hw_params;
2840 rtd->ops.prepare = soc_pcm_prepare;
2841 rtd->ops.trigger = soc_pcm_trigger;
2842 rtd->ops.hw_free = soc_pcm_hw_free;
2843 rtd->ops.close = soc_pcm_close;
2844 rtd->ops.pointer = soc_pcm_pointer;
2847 for_each_rtd_components(rtd, i, component) {
2848 const struct snd_soc_component_driver *drv = component->driver;
2851 rtd->ops.ioctl = snd_soc_pcm_component_ioctl;
2853 rtd->ops.sync_stop = snd_soc_pcm_component_sync_stop;
2855 rtd->ops.copy_user = snd_soc_pcm_component_copy_user;
2857 rtd->ops.page = snd_soc_pcm_component_page;
2859 rtd->ops.mmap = snd_soc_pcm_component_mmap;
2863 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
2866 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
2868 ret = snd_soc_pcm_component_new(rtd);
2870 dev_err(rtd->dev, "ASoC: pcm %s constructor failed for dailink %s: %d\n",
2871 new_name, rtd->dai_link->name, ret);
2875 pcm->no_device_suspend = true;
2877 dev_dbg(rtd->card->dev, "%s <-> %s mapping ok\n",
2878 (rtd->num_codecs > 1) ? "multicodec" : asoc_rtd_to_codec(rtd, 0)->name,
2879 (rtd->num_cpus > 1) ? "multicpu" : asoc_rtd_to_cpu(rtd, 0)->name);
2883 /* is the current PCM operation for this FE ? */
2884 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2886 if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2890 EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
2892 /* is the current PCM operation for this BE ? */
2893 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2894 struct snd_soc_pcm_runtime *be, int stream)
2896 if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2897 ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2898 be->dpcm[stream].runtime_update))
2902 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
2904 /* get the substream for this BE */
2905 struct snd_pcm_substream *
2906 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
2908 return be->pcm->streams[stream].substream;
2910 EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
2912 static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
2913 struct snd_soc_pcm_runtime *be,
2915 const enum snd_soc_dpcm_state *states,
2918 struct snd_soc_dpcm *dpcm;
2921 unsigned long flags;
2924 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2925 for_each_dpcm_fe(be, stream, dpcm) {
2930 state = dpcm->fe->dpcm[stream].state;
2931 for (i = 0; i < num_states; i++) {
2932 if (state == states[i]) {
2938 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2940 /* it's safe to do this BE DAI */
2945 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2946 * are not running, paused or suspended for the specified stream direction.
2948 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2949 struct snd_soc_pcm_runtime *be, int stream)
2951 const enum snd_soc_dpcm_state state[] = {
2952 SND_SOC_DPCM_STATE_START,
2953 SND_SOC_DPCM_STATE_PAUSED,
2954 SND_SOC_DPCM_STATE_SUSPEND,
2957 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2959 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
2962 * We can only change hw params a BE DAI if any of it's FE are not prepared,
2963 * running, paused or suspended for the specified stream direction.
2965 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2966 struct snd_soc_pcm_runtime *be, int stream)
2968 const enum snd_soc_dpcm_state state[] = {
2969 SND_SOC_DPCM_STATE_START,
2970 SND_SOC_DPCM_STATE_PAUSED,
2971 SND_SOC_DPCM_STATE_SUSPEND,
2972 SND_SOC_DPCM_STATE_PREPARE,
2975 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2977 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
2980 * We can only prepare a BE DAI if any of it's FE are not prepared,
2981 * running or paused for the specified stream direction.
2983 int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe,
2984 struct snd_soc_pcm_runtime *be, int stream)
2986 const enum snd_soc_dpcm_state state[] = {
2987 SND_SOC_DPCM_STATE_START,
2988 SND_SOC_DPCM_STATE_PAUSED,
2989 SND_SOC_DPCM_STATE_PREPARE,
2992 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2994 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_prepared);