2 * soc-pcm.c -- ALSA SoC PCM
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Authors: Liam Girdwood <lrg@ti.com>
10 * Mark Brown <broonie@opensource.wolfsonmicro.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/pinctrl/consumer.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/slab.h>
25 #include <linux/workqueue.h>
26 #include <linux/export.h>
27 #include <linux/debugfs.h>
28 #include <sound/core.h>
29 #include <sound/pcm.h>
30 #include <sound/pcm_params.h>
31 #include <sound/soc.h>
32 #include <sound/soc-dpcm.h>
33 #include <sound/initval.h>
35 #define DPCM_MAX_BE_USERS 8
38 * snd_soc_runtime_activate() - Increment active count for PCM runtime components
39 * @rtd: ASoC PCM runtime that is activated
40 * @stream: Direction of the PCM stream
42 * Increments the active count for all the DAIs and components attached to a PCM
43 * runtime. Should typically be called when a stream is opened.
45 * Must be called with the rtd->pcm_mutex being held
47 void snd_soc_runtime_activate(struct snd_soc_pcm_runtime
*rtd
, int stream
)
49 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
50 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
52 lockdep_assert_held(&rtd
->pcm_mutex
);
54 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
55 cpu_dai
->playback_active
++;
56 codec_dai
->playback_active
++;
58 cpu_dai
->capture_active
++;
59 codec_dai
->capture_active
++;
64 cpu_dai
->component
->active
++;
65 codec_dai
->component
->active
++;
69 * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components
70 * @rtd: ASoC PCM runtime that is deactivated
71 * @stream: Direction of the PCM stream
73 * Decrements the active count for all the DAIs and components attached to a PCM
74 * runtime. Should typically be called when a stream is closed.
76 * Must be called with the rtd->pcm_mutex being held
78 void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime
*rtd
, int stream
)
80 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
81 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
83 lockdep_assert_held(&rtd
->pcm_mutex
);
85 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
86 cpu_dai
->playback_active
--;
87 codec_dai
->playback_active
--;
89 cpu_dai
->capture_active
--;
90 codec_dai
->capture_active
--;
95 cpu_dai
->component
->active
--;
96 codec_dai
->component
->active
--;
100 * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
101 * @rtd: The ASoC PCM runtime that should be checked.
103 * This function checks whether the power down delay should be ignored for a
104 * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
105 * been configured to ignore the delay, or if none of the components benefits
106 * from having the delay.
108 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime
*rtd
)
110 if (!rtd
->pmdown_time
|| rtd
->dai_link
->ignore_pmdown_time
)
113 return rtd
->cpu_dai
->component
->ignore_pmdown_time
&&
114 rtd
->codec_dai
->component
->ignore_pmdown_time
;
118 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
119 * @substream: the pcm substream
120 * @hw: the hardware parameters
122 * Sets the substream runtime hardware parameters.
124 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
125 const struct snd_pcm_hardware
*hw
)
127 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
128 runtime
->hw
.info
= hw
->info
;
129 runtime
->hw
.formats
= hw
->formats
;
130 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
131 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
132 runtime
->hw
.periods_min
= hw
->periods_min
;
133 runtime
->hw
.periods_max
= hw
->periods_max
;
134 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
135 runtime
->hw
.fifo_size
= hw
->fifo_size
;
138 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
140 /* DPCM stream event, send event to FE and all active BEs. */
141 int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime
*fe
, int dir
,
144 struct snd_soc_dpcm
*dpcm
;
146 list_for_each_entry(dpcm
, &fe
->dpcm
[dir
].be_clients
, list_be
) {
148 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
150 dev_dbg(be
->dev
, "ASoC: BE %s event %d dir %d\n",
151 be
->dai_link
->name
, event
, dir
);
153 snd_soc_dapm_stream_event(be
, dir
, event
);
156 snd_soc_dapm_stream_event(fe
, dir
, event
);
161 static int soc_pcm_apply_symmetry(struct snd_pcm_substream
*substream
,
162 struct snd_soc_dai
*soc_dai
)
164 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
167 if (soc_dai
->rate
&& (soc_dai
->driver
->symmetric_rates
||
168 rtd
->dai_link
->symmetric_rates
)) {
169 dev_dbg(soc_dai
->dev
, "ASoC: Symmetry forces %dHz rate\n",
172 ret
= snd_pcm_hw_constraint_minmax(substream
->runtime
,
173 SNDRV_PCM_HW_PARAM_RATE
,
174 soc_dai
->rate
, soc_dai
->rate
);
176 dev_err(soc_dai
->dev
,
177 "ASoC: Unable to apply rate constraint: %d\n",
183 if (soc_dai
->channels
&& (soc_dai
->driver
->symmetric_channels
||
184 rtd
->dai_link
->symmetric_channels
)) {
185 dev_dbg(soc_dai
->dev
, "ASoC: Symmetry forces %d channel(s)\n",
188 ret
= snd_pcm_hw_constraint_minmax(substream
->runtime
,
189 SNDRV_PCM_HW_PARAM_CHANNELS
,
193 dev_err(soc_dai
->dev
,
194 "ASoC: Unable to apply channel symmetry constraint: %d\n",
200 if (soc_dai
->sample_bits
&& (soc_dai
->driver
->symmetric_samplebits
||
201 rtd
->dai_link
->symmetric_samplebits
)) {
202 dev_dbg(soc_dai
->dev
, "ASoC: Symmetry forces %d sample bits\n",
203 soc_dai
->sample_bits
);
205 ret
= snd_pcm_hw_constraint_minmax(substream
->runtime
,
206 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
207 soc_dai
->sample_bits
,
208 soc_dai
->sample_bits
);
210 dev_err(soc_dai
->dev
,
211 "ASoC: Unable to apply sample bits symmetry constraint: %d\n",
220 static int soc_pcm_params_symmetry(struct snd_pcm_substream
*substream
,
221 struct snd_pcm_hw_params
*params
)
223 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
224 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
225 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
226 unsigned int rate
, channels
, sample_bits
, symmetry
;
228 rate
= params_rate(params
);
229 channels
= params_channels(params
);
230 sample_bits
= snd_pcm_format_physical_width(params_format(params
));
232 /* reject unmatched parameters when applying symmetry */
233 symmetry
= cpu_dai
->driver
->symmetric_rates
||
234 codec_dai
->driver
->symmetric_rates
||
235 rtd
->dai_link
->symmetric_rates
;
236 if (symmetry
&& cpu_dai
->rate
&& cpu_dai
->rate
!= rate
) {
237 dev_err(rtd
->dev
, "ASoC: unmatched rate symmetry: %d - %d\n",
238 cpu_dai
->rate
, rate
);
242 symmetry
= cpu_dai
->driver
->symmetric_channels
||
243 codec_dai
->driver
->symmetric_channels
||
244 rtd
->dai_link
->symmetric_channels
;
245 if (symmetry
&& cpu_dai
->channels
&& cpu_dai
->channels
!= channels
) {
246 dev_err(rtd
->dev
, "ASoC: unmatched channel symmetry: %d - %d\n",
247 cpu_dai
->channels
, channels
);
251 symmetry
= cpu_dai
->driver
->symmetric_samplebits
||
252 codec_dai
->driver
->symmetric_samplebits
||
253 rtd
->dai_link
->symmetric_samplebits
;
254 if (symmetry
&& cpu_dai
->sample_bits
&& cpu_dai
->sample_bits
!= sample_bits
) {
255 dev_err(rtd
->dev
, "ASoC: unmatched sample bits symmetry: %d - %d\n",
256 cpu_dai
->sample_bits
, sample_bits
);
263 static bool soc_pcm_has_symmetry(struct snd_pcm_substream
*substream
)
265 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
266 struct snd_soc_dai_driver
*cpu_driver
= rtd
->cpu_dai
->driver
;
267 struct snd_soc_dai_driver
*codec_driver
= rtd
->codec_dai
->driver
;
268 struct snd_soc_dai_link
*link
= rtd
->dai_link
;
270 return cpu_driver
->symmetric_rates
|| codec_driver
->symmetric_rates
||
271 link
->symmetric_rates
|| cpu_driver
->symmetric_channels
||
272 codec_driver
->symmetric_channels
|| link
->symmetric_channels
||
273 cpu_driver
->symmetric_samplebits
||
274 codec_driver
->symmetric_samplebits
||
275 link
->symmetric_samplebits
;
279 * List of sample sizes that might go over the bus for parameter
280 * application. There ought to be a wildcard sample size for things
281 * like the DAC/ADC resolution to use but there isn't right now.
283 static int sample_sizes
[] = {
287 static void soc_pcm_set_msb(struct snd_pcm_substream
*substream
,
288 struct snd_soc_dai
*dai
, int bits
)
295 for (i
= 0; i
< ARRAY_SIZE(sample_sizes
); i
++) {
296 if (bits
>= sample_sizes
[i
])
299 ret
= snd_pcm_hw_constraint_msbits(substream
->runtime
, 0,
300 sample_sizes
[i
], bits
);
303 "ASoC: Failed to set MSB %d/%d: %d\n",
304 bits
, sample_sizes
[i
], ret
);
308 static void soc_pcm_apply_msb(struct snd_pcm_substream
*substream
)
310 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
311 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
312 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
313 unsigned int bits
= 0, cpu_bits
;
315 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
316 bits
= codec_dai
->driver
->playback
.sig_bits
;
317 cpu_bits
= cpu_dai
->driver
->playback
.sig_bits
;
319 bits
= codec_dai
->driver
->capture
.sig_bits
;
320 cpu_bits
= cpu_dai
->driver
->capture
.sig_bits
;
323 soc_pcm_set_msb(substream
, codec_dai
, bits
);
324 soc_pcm_set_msb(substream
, cpu_dai
, cpu_bits
);
327 static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime
*runtime
,
328 struct snd_soc_pcm_stream
*codec_stream
,
329 struct snd_soc_pcm_stream
*cpu_stream
)
331 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
333 hw
->channels_min
= max(codec_stream
->channels_min
,
334 cpu_stream
->channels_min
);
335 hw
->channels_max
= min(codec_stream
->channels_max
,
336 cpu_stream
->channels_max
);
338 hw
->formats
&= codec_stream
->formats
& cpu_stream
->formats
;
340 hw
->formats
= codec_stream
->formats
& cpu_stream
->formats
;
341 hw
->rates
= snd_pcm_rate_mask_intersect(codec_stream
->rates
,
345 hw
->rate_max
= UINT_MAX
;
347 snd_pcm_limit_hw_rates(runtime
);
349 hw
->rate_min
= max(hw
->rate_min
, cpu_stream
->rate_min
);
350 hw
->rate_min
= max(hw
->rate_min
, codec_stream
->rate_min
);
351 hw
->rate_max
= min_not_zero(hw
->rate_max
, cpu_stream
->rate_max
);
352 hw
->rate_max
= min_not_zero(hw
->rate_max
, codec_stream
->rate_max
);
356 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
357 * then initialized and any private data can be allocated. This also calls
358 * startup for the cpu DAI, platform, machine and codec DAI.
360 static int soc_pcm_open(struct snd_pcm_substream
*substream
)
362 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
363 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
364 struct snd_soc_platform
*platform
= rtd
->platform
;
365 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
366 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
367 struct snd_soc_dai_driver
*cpu_dai_drv
= cpu_dai
->driver
;
368 struct snd_soc_dai_driver
*codec_dai_drv
= codec_dai
->driver
;
371 pinctrl_pm_select_default_state(cpu_dai
->dev
);
372 pinctrl_pm_select_default_state(codec_dai
->dev
);
373 pm_runtime_get_sync(cpu_dai
->dev
);
374 pm_runtime_get_sync(codec_dai
->dev
);
375 pm_runtime_get_sync(platform
->dev
);
377 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
379 /* startup the audio subsystem */
380 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->startup
) {
381 ret
= cpu_dai
->driver
->ops
->startup(substream
, cpu_dai
);
383 dev_err(cpu_dai
->dev
, "ASoC: can't open interface"
384 " %s: %d\n", cpu_dai
->name
, ret
);
389 if (platform
->driver
->ops
&& platform
->driver
->ops
->open
) {
390 ret
= platform
->driver
->ops
->open(substream
);
392 dev_err(platform
->dev
, "ASoC: can't open platform"
393 " %s: %d\n", platform
->name
, ret
);
398 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->startup
) {
399 ret
= codec_dai
->driver
->ops
->startup(substream
, codec_dai
);
401 dev_err(codec_dai
->dev
, "ASoC: can't open codec"
402 " %s: %d\n", codec_dai
->name
, ret
);
407 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->startup
) {
408 ret
= rtd
->dai_link
->ops
->startup(substream
);
410 pr_err("ASoC: %s startup failed: %d\n",
411 rtd
->dai_link
->name
, ret
);
416 /* Dynamic PCM DAI links compat checks use dynamic capabilities */
417 if (rtd
->dai_link
->dynamic
|| rtd
->dai_link
->no_pcm
)
420 /* Check that the codec and cpu DAIs are compatible */
421 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
422 soc_pcm_init_runtime_hw(runtime
, &codec_dai_drv
->playback
,
423 &cpu_dai_drv
->playback
);
425 soc_pcm_init_runtime_hw(runtime
, &codec_dai_drv
->capture
,
426 &cpu_dai_drv
->capture
);
429 if (soc_pcm_has_symmetry(substream
))
430 runtime
->hw
.info
|= SNDRV_PCM_INFO_JOINT_DUPLEX
;
433 if (!runtime
->hw
.rates
) {
434 printk(KERN_ERR
"ASoC: %s <-> %s No matching rates\n",
435 codec_dai
->name
, cpu_dai
->name
);
438 if (!runtime
->hw
.formats
) {
439 printk(KERN_ERR
"ASoC: %s <-> %s No matching formats\n",
440 codec_dai
->name
, cpu_dai
->name
);
443 if (!runtime
->hw
.channels_min
|| !runtime
->hw
.channels_max
||
444 runtime
->hw
.channels_min
> runtime
->hw
.channels_max
) {
445 printk(KERN_ERR
"ASoC: %s <-> %s No matching channels\n",
446 codec_dai
->name
, cpu_dai
->name
);
450 soc_pcm_apply_msb(substream
);
452 /* Symmetry only applies if we've already got an active stream. */
453 if (cpu_dai
->active
) {
454 ret
= soc_pcm_apply_symmetry(substream
, cpu_dai
);
459 if (codec_dai
->active
) {
460 ret
= soc_pcm_apply_symmetry(substream
, codec_dai
);
465 pr_debug("ASoC: %s <-> %s info:\n",
466 codec_dai
->name
, cpu_dai
->name
);
467 pr_debug("ASoC: rate mask 0x%x\n", runtime
->hw
.rates
);
468 pr_debug("ASoC: min ch %d max ch %d\n", runtime
->hw
.channels_min
,
469 runtime
->hw
.channels_max
);
470 pr_debug("ASoC: min rate %d max rate %d\n", runtime
->hw
.rate_min
,
471 runtime
->hw
.rate_max
);
475 snd_soc_runtime_activate(rtd
, substream
->stream
);
477 mutex_unlock(&rtd
->pcm_mutex
);
481 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->shutdown
)
482 rtd
->dai_link
->ops
->shutdown(substream
);
485 if (codec_dai
->driver
->ops
->shutdown
)
486 codec_dai
->driver
->ops
->shutdown(substream
, codec_dai
);
489 if (platform
->driver
->ops
&& platform
->driver
->ops
->close
)
490 platform
->driver
->ops
->close(substream
);
493 if (cpu_dai
->driver
->ops
->shutdown
)
494 cpu_dai
->driver
->ops
->shutdown(substream
, cpu_dai
);
496 mutex_unlock(&rtd
->pcm_mutex
);
498 pm_runtime_put(platform
->dev
);
499 pm_runtime_put(codec_dai
->dev
);
500 pm_runtime_put(cpu_dai
->dev
);
501 if (!codec_dai
->active
)
502 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
503 if (!cpu_dai
->active
)
504 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
510 * Power down the audio subsystem pmdown_time msecs after close is called.
511 * This is to ensure there are no pops or clicks in between any music tracks
512 * due to DAPM power cycling.
514 static void close_delayed_work(struct work_struct
*work
)
516 struct snd_soc_pcm_runtime
*rtd
=
517 container_of(work
, struct snd_soc_pcm_runtime
, delayed_work
.work
);
518 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
520 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
522 dev_dbg(rtd
->dev
, "ASoC: pop wq checking: %s status: %s waiting: %s\n",
523 codec_dai
->driver
->playback
.stream_name
,
524 codec_dai
->playback_active
? "active" : "inactive",
525 rtd
->pop_wait
? "yes" : "no");
527 /* are we waiting on this codec DAI stream */
528 if (rtd
->pop_wait
== 1) {
530 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_PLAYBACK
,
531 SND_SOC_DAPM_STREAM_STOP
);
534 mutex_unlock(&rtd
->pcm_mutex
);
538 * Called by ALSA when a PCM substream is closed. Private data can be
539 * freed here. The cpu DAI, codec DAI, machine and platform are also
542 static int soc_pcm_close(struct snd_pcm_substream
*substream
)
544 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
545 struct snd_soc_platform
*platform
= rtd
->platform
;
546 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
547 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
549 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
551 snd_soc_runtime_deactivate(rtd
, substream
->stream
);
553 /* clear the corresponding DAIs rate when inactive */
554 if (!cpu_dai
->active
)
557 if (!codec_dai
->active
)
560 if (cpu_dai
->driver
->ops
->shutdown
)
561 cpu_dai
->driver
->ops
->shutdown(substream
, cpu_dai
);
563 if (codec_dai
->driver
->ops
->shutdown
)
564 codec_dai
->driver
->ops
->shutdown(substream
, codec_dai
);
566 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->shutdown
)
567 rtd
->dai_link
->ops
->shutdown(substream
);
569 if (platform
->driver
->ops
&& platform
->driver
->ops
->close
)
570 platform
->driver
->ops
->close(substream
);
572 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
573 if (snd_soc_runtime_ignore_pmdown_time(rtd
)) {
574 /* powered down playback stream now */
575 snd_soc_dapm_stream_event(rtd
,
576 SNDRV_PCM_STREAM_PLAYBACK
,
577 SND_SOC_DAPM_STREAM_STOP
);
579 /* start delayed pop wq here for playback streams */
581 queue_delayed_work(system_power_efficient_wq
,
583 msecs_to_jiffies(rtd
->pmdown_time
));
586 /* capture streams can be powered down now */
587 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_CAPTURE
,
588 SND_SOC_DAPM_STREAM_STOP
);
591 mutex_unlock(&rtd
->pcm_mutex
);
593 pm_runtime_put(platform
->dev
);
594 pm_runtime_put(codec_dai
->dev
);
595 pm_runtime_put(cpu_dai
->dev
);
596 if (!codec_dai
->active
)
597 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
598 if (!cpu_dai
->active
)
599 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
605 * Called by ALSA when the PCM substream is prepared, can set format, sample
606 * rate, etc. This function is non atomic and can be called multiple times,
607 * it can refer to the runtime info.
609 static int soc_pcm_prepare(struct snd_pcm_substream
*substream
)
611 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
612 struct snd_soc_platform
*platform
= rtd
->platform
;
613 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
614 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
617 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
619 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->prepare
) {
620 ret
= rtd
->dai_link
->ops
->prepare(substream
);
622 dev_err(rtd
->card
->dev
, "ASoC: machine prepare error:"
628 if (platform
->driver
->ops
&& platform
->driver
->ops
->prepare
) {
629 ret
= platform
->driver
->ops
->prepare(substream
);
631 dev_err(platform
->dev
, "ASoC: platform prepare error:"
637 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->prepare
) {
638 ret
= codec_dai
->driver
->ops
->prepare(substream
, codec_dai
);
640 dev_err(codec_dai
->dev
, "ASoC: DAI prepare error: %d\n",
646 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->prepare
) {
647 ret
= cpu_dai
->driver
->ops
->prepare(substream
, cpu_dai
);
649 dev_err(cpu_dai
->dev
, "ASoC: DAI prepare error: %d\n",
655 /* cancel any delayed stream shutdown that is pending */
656 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
659 cancel_delayed_work(&rtd
->delayed_work
);
662 snd_soc_dapm_stream_event(rtd
, substream
->stream
,
663 SND_SOC_DAPM_STREAM_START
);
665 snd_soc_dai_digital_mute(codec_dai
, 0, substream
->stream
);
668 mutex_unlock(&rtd
->pcm_mutex
);
673 * Called by ALSA when the hardware params are set by application. This
674 * function can also be called multiple times and can allocate buffers
675 * (using snd_pcm_lib_* ). It's non-atomic.
677 static int soc_pcm_hw_params(struct snd_pcm_substream
*substream
,
678 struct snd_pcm_hw_params
*params
)
680 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
681 struct snd_soc_platform
*platform
= rtd
->platform
;
682 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
683 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
686 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
688 ret
= soc_pcm_params_symmetry(substream
, params
);
692 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->hw_params
) {
693 ret
= rtd
->dai_link
->ops
->hw_params(substream
, params
);
695 dev_err(rtd
->card
->dev
, "ASoC: machine hw_params"
696 " failed: %d\n", ret
);
701 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->hw_params
) {
702 ret
= codec_dai
->driver
->ops
->hw_params(substream
, params
, codec_dai
);
704 dev_err(codec_dai
->dev
, "ASoC: can't set %s hw params:"
705 " %d\n", codec_dai
->name
, ret
);
710 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->hw_params
) {
711 ret
= cpu_dai
->driver
->ops
->hw_params(substream
, params
, cpu_dai
);
713 dev_err(cpu_dai
->dev
, "ASoC: %s hw params failed: %d\n",
719 if (platform
->driver
->ops
&& platform
->driver
->ops
->hw_params
) {
720 ret
= platform
->driver
->ops
->hw_params(substream
, params
);
722 dev_err(platform
->dev
, "ASoC: %s hw params failed: %d\n",
723 platform
->name
, ret
);
728 /* store the parameters for each DAIs */
729 cpu_dai
->rate
= params_rate(params
);
730 cpu_dai
->channels
= params_channels(params
);
731 cpu_dai
->sample_bits
=
732 snd_pcm_format_physical_width(params_format(params
));
734 codec_dai
->rate
= params_rate(params
);
735 codec_dai
->channels
= params_channels(params
);
736 codec_dai
->sample_bits
=
737 snd_pcm_format_physical_width(params_format(params
));
740 mutex_unlock(&rtd
->pcm_mutex
);
744 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->hw_free
)
745 cpu_dai
->driver
->ops
->hw_free(substream
, cpu_dai
);
748 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->hw_free
)
749 codec_dai
->driver
->ops
->hw_free(substream
, codec_dai
);
752 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->hw_free
)
753 rtd
->dai_link
->ops
->hw_free(substream
);
755 mutex_unlock(&rtd
->pcm_mutex
);
760 * Frees resources allocated by hw_params, can be called multiple times
762 static int soc_pcm_hw_free(struct snd_pcm_substream
*substream
)
764 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
765 struct snd_soc_platform
*platform
= rtd
->platform
;
766 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
767 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
768 bool playback
= substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
;
770 mutex_lock_nested(&rtd
->pcm_mutex
, rtd
->pcm_subclass
);
772 /* clear the corresponding DAIs parameters when going to be inactive */
773 if (cpu_dai
->active
== 1) {
775 cpu_dai
->channels
= 0;
776 cpu_dai
->sample_bits
= 0;
779 if (codec_dai
->active
== 1) {
781 codec_dai
->channels
= 0;
782 codec_dai
->sample_bits
= 0;
785 /* apply codec digital mute */
786 if ((playback
&& codec_dai
->playback_active
== 1) ||
787 (!playback
&& codec_dai
->capture_active
== 1))
788 snd_soc_dai_digital_mute(codec_dai
, 1, substream
->stream
);
790 /* free any machine hw params */
791 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->hw_free
)
792 rtd
->dai_link
->ops
->hw_free(substream
);
794 /* free any DMA resources */
795 if (platform
->driver
->ops
&& platform
->driver
->ops
->hw_free
)
796 platform
->driver
->ops
->hw_free(substream
);
798 /* now free hw params for the DAIs */
799 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->hw_free
)
800 codec_dai
->driver
->ops
->hw_free(substream
, codec_dai
);
802 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->hw_free
)
803 cpu_dai
->driver
->ops
->hw_free(substream
, cpu_dai
);
805 mutex_unlock(&rtd
->pcm_mutex
);
809 static int soc_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
811 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
812 struct snd_soc_platform
*platform
= rtd
->platform
;
813 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
814 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
817 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->trigger
) {
818 ret
= codec_dai
->driver
->ops
->trigger(substream
, cmd
, codec_dai
);
823 if (platform
->driver
->ops
&& platform
->driver
->ops
->trigger
) {
824 ret
= platform
->driver
->ops
->trigger(substream
, cmd
);
829 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->trigger
) {
830 ret
= cpu_dai
->driver
->ops
->trigger(substream
, cmd
, cpu_dai
);
835 if (rtd
->dai_link
->ops
&& rtd
->dai_link
->ops
->trigger
) {
836 ret
= rtd
->dai_link
->ops
->trigger(substream
, cmd
);
844 static int soc_pcm_bespoke_trigger(struct snd_pcm_substream
*substream
,
847 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
848 struct snd_soc_platform
*platform
= rtd
->platform
;
849 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
850 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
853 if (codec_dai
->driver
->ops
&&
854 codec_dai
->driver
->ops
->bespoke_trigger
) {
855 ret
= codec_dai
->driver
->ops
->bespoke_trigger(substream
, cmd
, codec_dai
);
860 if (platform
->driver
->bespoke_trigger
) {
861 ret
= platform
->driver
->bespoke_trigger(substream
, cmd
);
866 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->bespoke_trigger
) {
867 ret
= cpu_dai
->driver
->ops
->bespoke_trigger(substream
, cmd
, cpu_dai
);
874 * soc level wrapper for pointer callback
875 * If cpu_dai, codec_dai, platform driver has the delay callback, than
876 * the runtime->delay will be updated accordingly.
878 static snd_pcm_uframes_t
soc_pcm_pointer(struct snd_pcm_substream
*substream
)
880 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
881 struct snd_soc_platform
*platform
= rtd
->platform
;
882 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
883 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
884 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
885 snd_pcm_uframes_t offset
= 0;
886 snd_pcm_sframes_t delay
= 0;
888 if (platform
->driver
->ops
&& platform
->driver
->ops
->pointer
)
889 offset
= platform
->driver
->ops
->pointer(substream
);
891 if (cpu_dai
->driver
->ops
&& cpu_dai
->driver
->ops
->delay
)
892 delay
+= cpu_dai
->driver
->ops
->delay(substream
, cpu_dai
);
894 if (codec_dai
->driver
->ops
&& codec_dai
->driver
->ops
->delay
)
895 delay
+= codec_dai
->driver
->ops
->delay(substream
, codec_dai
);
897 if (platform
->driver
->delay
)
898 delay
+= platform
->driver
->delay(substream
, codec_dai
);
900 runtime
->delay
= delay
;
905 /* connect a FE and BE */
906 static int dpcm_be_connect(struct snd_soc_pcm_runtime
*fe
,
907 struct snd_soc_pcm_runtime
*be
, int stream
)
909 struct snd_soc_dpcm
*dpcm
;
911 /* only add new dpcms */
912 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
913 if (dpcm
->be
== be
&& dpcm
->fe
== fe
)
917 dpcm
= kzalloc(sizeof(struct snd_soc_dpcm
), GFP_KERNEL
);
923 be
->dpcm
[stream
].runtime
= fe
->dpcm
[stream
].runtime
;
924 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_NEW
;
925 list_add(&dpcm
->list_be
, &fe
->dpcm
[stream
].be_clients
);
926 list_add(&dpcm
->list_fe
, &be
->dpcm
[stream
].fe_clients
);
928 dev_dbg(fe
->dev
, "connected new DPCM %s path %s %s %s\n",
929 stream
? "capture" : "playback", fe
->dai_link
->name
,
930 stream
? "<-" : "->", be
->dai_link
->name
);
932 #ifdef CONFIG_DEBUG_FS
933 dpcm
->debugfs_state
= debugfs_create_u32(be
->dai_link
->name
, 0644,
934 fe
->debugfs_dpcm_root
, &dpcm
->state
);
939 /* reparent a BE onto another FE */
940 static void dpcm_be_reparent(struct snd_soc_pcm_runtime
*fe
,
941 struct snd_soc_pcm_runtime
*be
, int stream
)
943 struct snd_soc_dpcm
*dpcm
;
944 struct snd_pcm_substream
*fe_substream
, *be_substream
;
946 /* reparent if BE is connected to other FEs */
947 if (!be
->dpcm
[stream
].users
)
950 be_substream
= snd_soc_dpcm_get_substream(be
, stream
);
952 list_for_each_entry(dpcm
, &be
->dpcm
[stream
].fe_clients
, list_fe
) {
956 dev_dbg(fe
->dev
, "reparent %s path %s %s %s\n",
957 stream
? "capture" : "playback",
958 dpcm
->fe
->dai_link
->name
,
959 stream
? "<-" : "->", dpcm
->be
->dai_link
->name
);
961 fe_substream
= snd_soc_dpcm_get_substream(dpcm
->fe
, stream
);
962 be_substream
->runtime
= fe_substream
->runtime
;
967 /* disconnect a BE and FE */
968 void dpcm_be_disconnect(struct snd_soc_pcm_runtime
*fe
, int stream
)
970 struct snd_soc_dpcm
*dpcm
, *d
;
972 list_for_each_entry_safe(dpcm
, d
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
973 dev_dbg(fe
->dev
, "ASoC: BE %s disconnect check for %s\n",
974 stream
? "capture" : "playback",
975 dpcm
->be
->dai_link
->name
);
977 if (dpcm
->state
!= SND_SOC_DPCM_LINK_STATE_FREE
)
980 dev_dbg(fe
->dev
, "freed DSP %s path %s %s %s\n",
981 stream
? "capture" : "playback", fe
->dai_link
->name
,
982 stream
? "<-" : "->", dpcm
->be
->dai_link
->name
);
984 /* BEs still alive need new FE */
985 dpcm_be_reparent(fe
, dpcm
->be
, stream
);
987 #ifdef CONFIG_DEBUG_FS
988 debugfs_remove(dpcm
->debugfs_state
);
990 list_del(&dpcm
->list_be
);
991 list_del(&dpcm
->list_fe
);
996 /* get BE for DAI widget and stream */
997 static struct snd_soc_pcm_runtime
*dpcm_get_be(struct snd_soc_card
*card
,
998 struct snd_soc_dapm_widget
*widget
, int stream
)
1000 struct snd_soc_pcm_runtime
*be
;
1003 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1004 for (i
= 0; i
< card
->num_links
; i
++) {
1007 if (!be
->dai_link
->no_pcm
)
1010 if (be
->cpu_dai
->playback_widget
== widget
||
1011 be
->codec_dai
->playback_widget
== widget
)
1016 for (i
= 0; i
< card
->num_links
; i
++) {
1019 if (!be
->dai_link
->no_pcm
)
1022 if (be
->cpu_dai
->capture_widget
== widget
||
1023 be
->codec_dai
->capture_widget
== widget
)
1028 dev_err(card
->dev
, "ASoC: can't get %s BE for %s\n",
1029 stream
? "capture" : "playback", widget
->name
);
1033 static inline struct snd_soc_dapm_widget
*
1034 dai_get_widget(struct snd_soc_dai
*dai
, int stream
)
1036 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1037 return dai
->playback_widget
;
1039 return dai
->capture_widget
;
1042 static int widget_in_list(struct snd_soc_dapm_widget_list
*list
,
1043 struct snd_soc_dapm_widget
*widget
)
1047 for (i
= 0; i
< list
->num_widgets
; i
++) {
1048 if (widget
== list
->widgets
[i
])
1055 int dpcm_path_get(struct snd_soc_pcm_runtime
*fe
,
1056 int stream
, struct snd_soc_dapm_widget_list
**list_
)
1058 struct snd_soc_dai
*cpu_dai
= fe
->cpu_dai
;
1059 struct snd_soc_dapm_widget_list
*list
;
1062 list
= kzalloc(sizeof(struct snd_soc_dapm_widget_list
) +
1063 sizeof(struct snd_soc_dapm_widget
*), GFP_KERNEL
);
1067 /* get number of valid DAI paths and their widgets */
1068 paths
= snd_soc_dapm_dai_get_connected_widgets(cpu_dai
, stream
, &list
);
1070 dev_dbg(fe
->dev
, "ASoC: found %d audio %s paths\n", paths
,
1071 stream
? "capture" : "playback");
1077 static int dpcm_prune_paths(struct snd_soc_pcm_runtime
*fe
, int stream
,
1078 struct snd_soc_dapm_widget_list
**list_
)
1080 struct snd_soc_dpcm
*dpcm
;
1081 struct snd_soc_dapm_widget_list
*list
= *list_
;
1082 struct snd_soc_dapm_widget
*widget
;
1085 /* Destroy any old FE <--> BE connections */
1086 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1088 /* is there a valid CPU DAI widget for this BE */
1089 widget
= dai_get_widget(dpcm
->be
->cpu_dai
, stream
);
1091 /* prune the BE if it's no longer in our active list */
1092 if (widget
&& widget_in_list(list
, widget
))
1095 /* is there a valid CODEC DAI widget for this BE */
1096 widget
= dai_get_widget(dpcm
->be
->codec_dai
, stream
);
1098 /* prune the BE if it's no longer in our active list */
1099 if (widget
&& widget_in_list(list
, widget
))
1102 dev_dbg(fe
->dev
, "ASoC: pruning %s BE %s for %s\n",
1103 stream
? "capture" : "playback",
1104 dpcm
->be
->dai_link
->name
, fe
->dai_link
->name
);
1105 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
1106 dpcm
->be
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_BE
;
1110 dev_dbg(fe
->dev
, "ASoC: found %d old BE paths for pruning\n", prune
);
1114 static int dpcm_add_paths(struct snd_soc_pcm_runtime
*fe
, int stream
,
1115 struct snd_soc_dapm_widget_list
**list_
)
1117 struct snd_soc_card
*card
= fe
->card
;
1118 struct snd_soc_dapm_widget_list
*list
= *list_
;
1119 struct snd_soc_pcm_runtime
*be
;
1120 int i
, new = 0, err
;
1122 /* Create any new FE <--> BE connections */
1123 for (i
= 0; i
< list
->num_widgets
; i
++) {
1125 switch (list
->widgets
[i
]->id
) {
1126 case snd_soc_dapm_dai_in
:
1127 case snd_soc_dapm_dai_out
:
1133 /* is there a valid BE rtd for this widget */
1134 be
= dpcm_get_be(card
, list
->widgets
[i
], stream
);
1136 dev_err(fe
->dev
, "ASoC: no BE found for %s\n",
1137 list
->widgets
[i
]->name
);
1141 /* make sure BE is a real BE */
1142 if (!be
->dai_link
->no_pcm
)
1145 /* don't connect if FE is not running */
1146 if (!fe
->dpcm
[stream
].runtime
&& !fe
->fe_compr
)
1149 /* newly connected FE and BE */
1150 err
= dpcm_be_connect(fe
, be
, stream
);
1152 dev_err(fe
->dev
, "ASoC: can't connect %s\n",
1153 list
->widgets
[i
]->name
);
1155 } else if (err
== 0) /* already connected */
1159 be
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_BE
;
1163 dev_dbg(fe
->dev
, "ASoC: found %d new BE paths\n", new);
1168 * Find the corresponding BE DAIs that source or sink audio to this
1171 int dpcm_process_paths(struct snd_soc_pcm_runtime
*fe
,
1172 int stream
, struct snd_soc_dapm_widget_list
**list
, int new)
1175 return dpcm_add_paths(fe
, stream
, list
);
1177 return dpcm_prune_paths(fe
, stream
, list
);
1180 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime
*fe
, int stream
)
1182 struct snd_soc_dpcm
*dpcm
;
1184 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
)
1185 dpcm
->be
->dpcm
[stream
].runtime_update
=
1186 SND_SOC_DPCM_UPDATE_NO
;
1189 static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime
*fe
,
1192 struct snd_soc_dpcm
*dpcm
;
1194 /* disable any enabled and non active backends */
1195 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1197 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1198 struct snd_pcm_substream
*be_substream
=
1199 snd_soc_dpcm_get_substream(be
, stream
);
1201 if (be
->dpcm
[stream
].users
== 0)
1202 dev_err(be
->dev
, "ASoC: no users %s at close - state %d\n",
1203 stream
? "capture" : "playback",
1204 be
->dpcm
[stream
].state
);
1206 if (--be
->dpcm
[stream
].users
!= 0)
1209 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_OPEN
)
1212 soc_pcm_close(be_substream
);
1213 be_substream
->runtime
= NULL
;
1214 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
1218 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime
*fe
, int stream
)
1220 struct snd_soc_dpcm
*dpcm
;
1223 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1224 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1226 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1227 struct snd_pcm_substream
*be_substream
=
1228 snd_soc_dpcm_get_substream(be
, stream
);
1230 if (!be_substream
) {
1231 dev_err(be
->dev
, "ASoC: no backend %s stream\n",
1232 stream
? "capture" : "playback");
1236 /* is this op for this BE ? */
1237 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1240 /* first time the dpcm is open ? */
1241 if (be
->dpcm
[stream
].users
== DPCM_MAX_BE_USERS
)
1242 dev_err(be
->dev
, "ASoC: too many users %s at open %d\n",
1243 stream
? "capture" : "playback",
1244 be
->dpcm
[stream
].state
);
1246 if (be
->dpcm
[stream
].users
++ != 0)
1249 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_NEW
) &&
1250 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_CLOSE
))
1253 dev_dbg(be
->dev
, "ASoC: open %s BE %s\n",
1254 stream
? "capture" : "playback", be
->dai_link
->name
);
1256 be_substream
->runtime
= be
->dpcm
[stream
].runtime
;
1257 err
= soc_pcm_open(be_substream
);
1259 dev_err(be
->dev
, "ASoC: BE open failed %d\n", err
);
1260 be
->dpcm
[stream
].users
--;
1261 if (be
->dpcm
[stream
].users
< 0)
1262 dev_err(be
->dev
, "ASoC: no users %s at unwind %d\n",
1263 stream
? "capture" : "playback",
1264 be
->dpcm
[stream
].state
);
1266 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
1270 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_OPEN
;
1277 /* disable any enabled and non active backends */
1278 list_for_each_entry_continue_reverse(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1279 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1280 struct snd_pcm_substream
*be_substream
=
1281 snd_soc_dpcm_get_substream(be
, stream
);
1283 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1286 if (be
->dpcm
[stream
].users
== 0)
1287 dev_err(be
->dev
, "ASoC: no users %s at close %d\n",
1288 stream
? "capture" : "playback",
1289 be
->dpcm
[stream
].state
);
1291 if (--be
->dpcm
[stream
].users
!= 0)
1294 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_OPEN
)
1297 soc_pcm_close(be_substream
);
1298 be_substream
->runtime
= NULL
;
1299 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
1305 static void dpcm_init_runtime_hw(struct snd_pcm_runtime
*runtime
,
1306 struct snd_soc_pcm_stream
*stream
)
1308 runtime
->hw
.rate_min
= stream
->rate_min
;
1309 runtime
->hw
.rate_max
= stream
->rate_max
;
1310 runtime
->hw
.channels_min
= stream
->channels_min
;
1311 runtime
->hw
.channels_max
= stream
->channels_max
;
1312 if (runtime
->hw
.formats
)
1313 runtime
->hw
.formats
&= stream
->formats
;
1315 runtime
->hw
.formats
= stream
->formats
;
1316 runtime
->hw
.rates
= stream
->rates
;
1319 static void dpcm_set_fe_runtime(struct snd_pcm_substream
*substream
)
1321 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1322 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
1323 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1324 struct snd_soc_dai_driver
*cpu_dai_drv
= cpu_dai
->driver
;
1326 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1327 dpcm_init_runtime_hw(runtime
, &cpu_dai_drv
->playback
);
1329 dpcm_init_runtime_hw(runtime
, &cpu_dai_drv
->capture
);
1332 static int dpcm_fe_dai_startup(struct snd_pcm_substream
*fe_substream
)
1334 struct snd_soc_pcm_runtime
*fe
= fe_substream
->private_data
;
1335 struct snd_pcm_runtime
*runtime
= fe_substream
->runtime
;
1336 int stream
= fe_substream
->stream
, ret
= 0;
1338 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1340 ret
= dpcm_be_dai_startup(fe
, fe_substream
->stream
);
1342 dev_err(fe
->dev
,"ASoC: failed to start some BEs %d\n", ret
);
1346 dev_dbg(fe
->dev
, "ASoC: open FE %s\n", fe
->dai_link
->name
);
1348 /* start the DAI frontend */
1349 ret
= soc_pcm_open(fe_substream
);
1351 dev_err(fe
->dev
,"ASoC: failed to start FE %d\n", ret
);
1355 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_OPEN
;
1357 dpcm_set_fe_runtime(fe_substream
);
1358 snd_pcm_limit_hw_rates(runtime
);
1360 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1364 dpcm_be_dai_startup_unwind(fe
, fe_substream
->stream
);
1366 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1370 int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime
*fe
, int stream
)
1372 struct snd_soc_dpcm
*dpcm
;
1374 /* only shutdown BEs that are either sinks or sources to this FE DAI */
1375 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1377 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1378 struct snd_pcm_substream
*be_substream
=
1379 snd_soc_dpcm_get_substream(be
, stream
);
1381 /* is this op for this BE ? */
1382 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1385 if (be
->dpcm
[stream
].users
== 0)
1386 dev_err(be
->dev
, "ASoC: no users %s at close - state %d\n",
1387 stream
? "capture" : "playback",
1388 be
->dpcm
[stream
].state
);
1390 if (--be
->dpcm
[stream
].users
!= 0)
1393 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_FREE
) &&
1394 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_OPEN
))
1397 dev_dbg(be
->dev
, "ASoC: close BE %s\n",
1398 dpcm
->fe
->dai_link
->name
);
1400 soc_pcm_close(be_substream
);
1401 be_substream
->runtime
= NULL
;
1403 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
1408 static int dpcm_fe_dai_shutdown(struct snd_pcm_substream
*substream
)
1410 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1411 int stream
= substream
->stream
;
1413 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1415 /* shutdown the BEs */
1416 dpcm_be_dai_shutdown(fe
, substream
->stream
);
1418 dev_dbg(fe
->dev
, "ASoC: close FE %s\n", fe
->dai_link
->name
);
1420 /* now shutdown the frontend */
1421 soc_pcm_close(substream
);
1423 /* run the stream event for each BE */
1424 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_STOP
);
1426 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_CLOSE
;
1427 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1431 int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime
*fe
, int stream
)
1433 struct snd_soc_dpcm
*dpcm
;
1435 /* only hw_params backends that are either sinks or sources
1436 * to this frontend DAI */
1437 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
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 /* is this op for this BE ? */
1444 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1447 /* only free hw when no longer used - check all FEs */
1448 if (!snd_soc_dpcm_can_be_free_stop(fe
, be
, stream
))
1451 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
1452 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_PREPARE
) &&
1453 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_FREE
) &&
1454 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_PAUSED
) &&
1455 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_STOP
))
1458 dev_dbg(be
->dev
, "ASoC: hw_free BE %s\n",
1459 dpcm
->fe
->dai_link
->name
);
1461 soc_pcm_hw_free(be_substream
);
1463 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_HW_FREE
;
1469 static int dpcm_fe_dai_hw_free(struct snd_pcm_substream
*substream
)
1471 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1472 int err
, stream
= substream
->stream
;
1474 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
1475 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1477 dev_dbg(fe
->dev
, "ASoC: hw_free FE %s\n", fe
->dai_link
->name
);
1479 /* call hw_free on the frontend */
1480 err
= soc_pcm_hw_free(substream
);
1482 dev_err(fe
->dev
,"ASoC: hw_free FE %s failed\n",
1483 fe
->dai_link
->name
);
1485 /* only hw_params backends that are either sinks or sources
1486 * to this frontend DAI */
1487 err
= dpcm_be_dai_hw_free(fe
, stream
);
1489 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_HW_FREE
;
1490 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1492 mutex_unlock(&fe
->card
->mutex
);
1496 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime
*fe
, int stream
)
1498 struct snd_soc_dpcm
*dpcm
;
1501 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1503 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1504 struct snd_pcm_substream
*be_substream
=
1505 snd_soc_dpcm_get_substream(be
, stream
);
1507 /* is this op for this BE ? */
1508 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1511 /* only allow hw_params() if no connected FEs are running */
1512 if (!snd_soc_dpcm_can_be_params(fe
, be
, stream
))
1515 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_OPEN
) &&
1516 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
1517 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_FREE
))
1520 dev_dbg(be
->dev
, "ASoC: hw_params BE %s\n",
1521 dpcm
->fe
->dai_link
->name
);
1523 /* copy params for each dpcm */
1524 memcpy(&dpcm
->hw_params
, &fe
->dpcm
[stream
].hw_params
,
1525 sizeof(struct snd_pcm_hw_params
));
1527 /* perform any hw_params fixups */
1528 if (be
->dai_link
->be_hw_params_fixup
) {
1529 ret
= be
->dai_link
->be_hw_params_fixup(be
,
1533 "ASoC: hw_params BE fixup failed %d\n",
1539 ret
= soc_pcm_hw_params(be_substream
, &dpcm
->hw_params
);
1541 dev_err(dpcm
->be
->dev
,
1542 "ASoC: hw_params BE failed %d\n", ret
);
1546 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_HW_PARAMS
;
1551 /* disable any enabled and non active backends */
1552 list_for_each_entry_continue_reverse(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1553 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1554 struct snd_pcm_substream
*be_substream
=
1555 snd_soc_dpcm_get_substream(be
, stream
);
1557 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1560 /* only allow hw_free() if no connected FEs are running */
1561 if (!snd_soc_dpcm_can_be_free_stop(fe
, be
, stream
))
1564 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_OPEN
) &&
1565 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
1566 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_FREE
) &&
1567 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_STOP
))
1570 soc_pcm_hw_free(be_substream
);
1576 static int dpcm_fe_dai_hw_params(struct snd_pcm_substream
*substream
,
1577 struct snd_pcm_hw_params
*params
)
1579 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1580 int ret
, stream
= substream
->stream
;
1582 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
1583 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1585 memcpy(&fe
->dpcm
[substream
->stream
].hw_params
, params
,
1586 sizeof(struct snd_pcm_hw_params
));
1587 ret
= dpcm_be_dai_hw_params(fe
, substream
->stream
);
1589 dev_err(fe
->dev
,"ASoC: hw_params BE failed %d\n", ret
);
1593 dev_dbg(fe
->dev
, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
1594 fe
->dai_link
->name
, params_rate(params
),
1595 params_channels(params
), params_format(params
));
1597 /* call hw_params on the frontend */
1598 ret
= soc_pcm_hw_params(substream
, params
);
1600 dev_err(fe
->dev
,"ASoC: hw_params FE failed %d\n", ret
);
1601 dpcm_be_dai_hw_free(fe
, stream
);
1603 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_HW_PARAMS
;
1606 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1607 mutex_unlock(&fe
->card
->mutex
);
1611 static int dpcm_do_trigger(struct snd_soc_dpcm
*dpcm
,
1612 struct snd_pcm_substream
*substream
, int cmd
)
1616 dev_dbg(dpcm
->be
->dev
, "ASoC: trigger BE %s cmd %d\n",
1617 dpcm
->fe
->dai_link
->name
, cmd
);
1619 ret
= soc_pcm_trigger(substream
, cmd
);
1621 dev_err(dpcm
->be
->dev
,"ASoC: trigger BE failed %d\n", ret
);
1626 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime
*fe
, int stream
,
1629 struct snd_soc_dpcm
*dpcm
;
1632 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1634 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1635 struct snd_pcm_substream
*be_substream
=
1636 snd_soc_dpcm_get_substream(be
, stream
);
1638 /* is this op for this BE ? */
1639 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1643 case SNDRV_PCM_TRIGGER_START
:
1644 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_PREPARE
) &&
1645 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_STOP
))
1648 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1652 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_START
;
1654 case SNDRV_PCM_TRIGGER_RESUME
:
1655 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_SUSPEND
))
1658 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1662 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_START
;
1664 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1665 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_PAUSED
))
1668 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1672 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_START
;
1674 case SNDRV_PCM_TRIGGER_STOP
:
1675 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_START
)
1678 if (!snd_soc_dpcm_can_be_free_stop(fe
, be
, stream
))
1681 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1685 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_STOP
;
1687 case SNDRV_PCM_TRIGGER_SUSPEND
:
1688 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_START
)
1691 if (!snd_soc_dpcm_can_be_free_stop(fe
, be
, stream
))
1694 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1698 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_SUSPEND
;
1700 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1701 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_START
)
1704 if (!snd_soc_dpcm_can_be_free_stop(fe
, be
, stream
))
1707 ret
= dpcm_do_trigger(dpcm
, be_substream
, cmd
);
1711 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_PAUSED
;
1718 EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger
);
1720 static int dpcm_fe_dai_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1722 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1723 int stream
= substream
->stream
, ret
;
1724 enum snd_soc_dpcm_trigger trigger
= fe
->dai_link
->trigger
[stream
];
1726 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1729 case SND_SOC_DPCM_TRIGGER_PRE
:
1730 /* call trigger on the frontend before the backend. */
1732 dev_dbg(fe
->dev
, "ASoC: pre trigger FE %s cmd %d\n",
1733 fe
->dai_link
->name
, cmd
);
1735 ret
= soc_pcm_trigger(substream
, cmd
);
1737 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", ret
);
1741 ret
= dpcm_be_dai_trigger(fe
, substream
->stream
, cmd
);
1743 case SND_SOC_DPCM_TRIGGER_POST
:
1744 /* call trigger on the frontend after the backend. */
1746 ret
= dpcm_be_dai_trigger(fe
, substream
->stream
, cmd
);
1748 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", ret
);
1752 dev_dbg(fe
->dev
, "ASoC: post trigger FE %s cmd %d\n",
1753 fe
->dai_link
->name
, cmd
);
1755 ret
= soc_pcm_trigger(substream
, cmd
);
1757 case SND_SOC_DPCM_TRIGGER_BESPOKE
:
1758 /* bespoke trigger() - handles both FE and BEs */
1760 dev_dbg(fe
->dev
, "ASoC: bespoke trigger FE %s cmd %d\n",
1761 fe
->dai_link
->name
, cmd
);
1763 ret
= soc_pcm_bespoke_trigger(substream
, cmd
);
1765 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", ret
);
1770 dev_err(fe
->dev
, "ASoC: invalid trigger cmd %d for %s\n", cmd
,
1771 fe
->dai_link
->name
);
1777 case SNDRV_PCM_TRIGGER_START
:
1778 case SNDRV_PCM_TRIGGER_RESUME
:
1779 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1780 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_START
;
1782 case SNDRV_PCM_TRIGGER_STOP
:
1783 case SNDRV_PCM_TRIGGER_SUSPEND
:
1784 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1785 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_STOP
;
1790 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1794 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime
*fe
, int stream
)
1796 struct snd_soc_dpcm
*dpcm
;
1799 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1801 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
1802 struct snd_pcm_substream
*be_substream
=
1803 snd_soc_dpcm_get_substream(be
, stream
);
1805 /* is this op for this BE ? */
1806 if (!snd_soc_dpcm_be_can_update(fe
, be
, stream
))
1809 if ((be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
1810 (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_STOP
))
1813 dev_dbg(be
->dev
, "ASoC: prepare BE %s\n",
1814 dpcm
->fe
->dai_link
->name
);
1816 ret
= soc_pcm_prepare(be_substream
);
1818 dev_err(be
->dev
, "ASoC: backend prepare failed %d\n",
1823 be
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_PREPARE
;
1828 static int dpcm_fe_dai_prepare(struct snd_pcm_substream
*substream
)
1830 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1831 int stream
= substream
->stream
, ret
= 0;
1833 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
1835 dev_dbg(fe
->dev
, "ASoC: prepare FE %s\n", fe
->dai_link
->name
);
1837 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_FE
;
1839 /* there is no point preparing this FE if there are no BEs */
1840 if (list_empty(&fe
->dpcm
[stream
].be_clients
)) {
1841 dev_err(fe
->dev
, "ASoC: no backend DAIs enabled for %s\n",
1842 fe
->dai_link
->name
);
1847 ret
= dpcm_be_dai_prepare(fe
, substream
->stream
);
1851 /* call prepare on the frontend */
1852 ret
= soc_pcm_prepare(substream
);
1854 dev_err(fe
->dev
,"ASoC: prepare FE %s failed\n",
1855 fe
->dai_link
->name
);
1859 /* run the stream event for each BE */
1860 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_START
);
1861 fe
->dpcm
[stream
].state
= SND_SOC_DPCM_STATE_PREPARE
;
1864 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
1865 mutex_unlock(&fe
->card
->mutex
);
1870 static int soc_pcm_ioctl(struct snd_pcm_substream
*substream
,
1871 unsigned int cmd
, void *arg
)
1873 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
1874 struct snd_soc_platform
*platform
= rtd
->platform
;
1876 if (platform
->driver
->ops
&& platform
->driver
->ops
->ioctl
)
1877 return platform
->driver
->ops
->ioctl(substream
, cmd
, arg
);
1878 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1881 static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime
*fe
, int stream
)
1883 struct snd_pcm_substream
*substream
=
1884 snd_soc_dpcm_get_substream(fe
, stream
);
1885 enum snd_soc_dpcm_trigger trigger
= fe
->dai_link
->trigger
[stream
];
1888 dev_dbg(fe
->dev
, "ASoC: runtime %s close on FE %s\n",
1889 stream
? "capture" : "playback", fe
->dai_link
->name
);
1891 if (trigger
== SND_SOC_DPCM_TRIGGER_BESPOKE
) {
1892 /* call bespoke trigger - FE takes care of all BE triggers */
1893 dev_dbg(fe
->dev
, "ASoC: bespoke trigger FE %s cmd stop\n",
1894 fe
->dai_link
->name
);
1896 err
= soc_pcm_bespoke_trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
1898 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", err
);
1900 dev_dbg(fe
->dev
, "ASoC: trigger FE %s cmd stop\n",
1901 fe
->dai_link
->name
);
1903 err
= dpcm_be_dai_trigger(fe
, stream
, SNDRV_PCM_TRIGGER_STOP
);
1905 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", err
);
1908 err
= dpcm_be_dai_hw_free(fe
, stream
);
1910 dev_err(fe
->dev
,"ASoC: hw_free FE failed %d\n", err
);
1912 err
= dpcm_be_dai_shutdown(fe
, stream
);
1914 dev_err(fe
->dev
,"ASoC: shutdown FE failed %d\n", err
);
1916 /* run the stream event for each BE */
1917 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_NOP
);
1922 static int dpcm_run_update_startup(struct snd_soc_pcm_runtime
*fe
, int stream
)
1924 struct snd_pcm_substream
*substream
=
1925 snd_soc_dpcm_get_substream(fe
, stream
);
1926 struct snd_soc_dpcm
*dpcm
;
1927 enum snd_soc_dpcm_trigger trigger
= fe
->dai_link
->trigger
[stream
];
1930 dev_dbg(fe
->dev
, "ASoC: runtime %s open on FE %s\n",
1931 stream
? "capture" : "playback", fe
->dai_link
->name
);
1933 /* Only start the BE if the FE is ready */
1934 if (fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_HW_FREE
||
1935 fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_CLOSE
)
1938 /* startup must always be called for new BEs */
1939 ret
= dpcm_be_dai_startup(fe
, stream
);
1943 /* keep going if FE state is > open */
1944 if (fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_OPEN
)
1947 ret
= dpcm_be_dai_hw_params(fe
, stream
);
1951 /* keep going if FE state is > hw_params */
1952 if (fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_HW_PARAMS
)
1956 ret
= dpcm_be_dai_prepare(fe
, stream
);
1960 /* run the stream event for each BE */
1961 dpcm_dapm_stream_event(fe
, stream
, SND_SOC_DAPM_STREAM_NOP
);
1963 /* keep going if FE state is > prepare */
1964 if (fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_PREPARE
||
1965 fe
->dpcm
[stream
].state
== SND_SOC_DPCM_STATE_STOP
)
1968 if (trigger
== SND_SOC_DPCM_TRIGGER_BESPOKE
) {
1969 /* call trigger on the frontend - FE takes care of all BE triggers */
1970 dev_dbg(fe
->dev
, "ASoC: bespoke trigger FE %s cmd start\n",
1971 fe
->dai_link
->name
);
1973 ret
= soc_pcm_bespoke_trigger(substream
, SNDRV_PCM_TRIGGER_START
);
1975 dev_err(fe
->dev
,"ASoC: bespoke trigger FE failed %d\n", ret
);
1979 dev_dbg(fe
->dev
, "ASoC: trigger FE %s cmd start\n",
1980 fe
->dai_link
->name
);
1982 ret
= dpcm_be_dai_trigger(fe
, stream
,
1983 SNDRV_PCM_TRIGGER_START
);
1985 dev_err(fe
->dev
,"ASoC: trigger FE failed %d\n", ret
);
1993 dpcm_be_dai_hw_free(fe
, stream
);
1995 dpcm_be_dai_shutdown(fe
, stream
);
1997 /* disconnect any non started BEs */
1998 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
1999 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
2000 if (be
->dpcm
[stream
].state
!= SND_SOC_DPCM_STATE_START
)
2001 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
2007 static int dpcm_run_new_update(struct snd_soc_pcm_runtime
*fe
, int stream
)
2011 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_BE
;
2012 ret
= dpcm_run_update_startup(fe
, stream
);
2014 dev_err(fe
->dev
, "ASoC: failed to startup some BEs\n");
2015 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
2020 static int dpcm_run_old_update(struct snd_soc_pcm_runtime
*fe
, int stream
)
2024 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_BE
;
2025 ret
= dpcm_run_update_shutdown(fe
, stream
);
2027 dev_err(fe
->dev
, "ASoC: failed to shutdown some BEs\n");
2028 fe
->dpcm
[stream
].runtime_update
= SND_SOC_DPCM_UPDATE_NO
;
2033 /* Called by DAPM mixer/mux changes to update audio routing between PCMs and
2036 int soc_dpcm_runtime_update(struct snd_soc_card
*card
)
2038 int i
, old
, new, paths
;
2040 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
2041 for (i
= 0; i
< card
->num_rtd
; i
++) {
2042 struct snd_soc_dapm_widget_list
*list
;
2043 struct snd_soc_pcm_runtime
*fe
= &card
->rtd
[i
];
2045 /* make sure link is FE */
2046 if (!fe
->dai_link
->dynamic
)
2049 /* only check active links */
2050 if (!fe
->cpu_dai
->active
)
2053 /* DAPM sync will call this to update DSP paths */
2054 dev_dbg(fe
->dev
, "ASoC: DPCM runtime update for FE %s\n",
2055 fe
->dai_link
->name
);
2057 /* skip if FE doesn't have playback capability */
2058 if (!fe
->cpu_dai
->driver
->playback
.channels_min
)
2061 paths
= dpcm_path_get(fe
, SNDRV_PCM_STREAM_PLAYBACK
, &list
);
2063 dev_warn(fe
->dev
, "ASoC: %s no valid %s path\n",
2064 fe
->dai_link
->name
, "playback");
2065 mutex_unlock(&card
->mutex
);
2069 /* update any new playback paths */
2070 new = dpcm_process_paths(fe
, SNDRV_PCM_STREAM_PLAYBACK
, &list
, 1);
2072 dpcm_run_new_update(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2073 dpcm_clear_pending_state(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2074 dpcm_be_disconnect(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2077 /* update any old playback paths */
2078 old
= dpcm_process_paths(fe
, SNDRV_PCM_STREAM_PLAYBACK
, &list
, 0);
2080 dpcm_run_old_update(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2081 dpcm_clear_pending_state(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2082 dpcm_be_disconnect(fe
, SNDRV_PCM_STREAM_PLAYBACK
);
2086 /* skip if FE doesn't have capture capability */
2087 if (!fe
->cpu_dai
->driver
->capture
.channels_min
)
2090 paths
= dpcm_path_get(fe
, SNDRV_PCM_STREAM_CAPTURE
, &list
);
2092 dev_warn(fe
->dev
, "ASoC: %s no valid %s path\n",
2093 fe
->dai_link
->name
, "capture");
2094 mutex_unlock(&card
->mutex
);
2098 /* update any new capture paths */
2099 new = dpcm_process_paths(fe
, SNDRV_PCM_STREAM_CAPTURE
, &list
, 1);
2101 dpcm_run_new_update(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2102 dpcm_clear_pending_state(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2103 dpcm_be_disconnect(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2106 /* update any old capture paths */
2107 old
= dpcm_process_paths(fe
, SNDRV_PCM_STREAM_CAPTURE
, &list
, 0);
2109 dpcm_run_old_update(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2110 dpcm_clear_pending_state(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2111 dpcm_be_disconnect(fe
, SNDRV_PCM_STREAM_CAPTURE
);
2114 dpcm_path_put(&list
);
2117 mutex_unlock(&card
->mutex
);
2120 int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime
*fe
, int mute
)
2122 struct snd_soc_dpcm
*dpcm
;
2123 struct list_head
*clients
=
2124 &fe
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
;
2126 list_for_each_entry(dpcm
, clients
, list_be
) {
2128 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
2129 struct snd_soc_dai
*dai
= be
->codec_dai
;
2130 struct snd_soc_dai_driver
*drv
= dai
->driver
;
2132 if (be
->dai_link
->ignore_suspend
)
2135 dev_dbg(be
->dev
, "ASoC: BE digital mute %s\n", be
->dai_link
->name
);
2137 if (drv
->ops
&& drv
->ops
->digital_mute
&& dai
->playback_active
)
2138 drv
->ops
->digital_mute(dai
, mute
);
2144 static int dpcm_fe_dai_open(struct snd_pcm_substream
*fe_substream
)
2146 struct snd_soc_pcm_runtime
*fe
= fe_substream
->private_data
;
2147 struct snd_soc_dpcm
*dpcm
;
2148 struct snd_soc_dapm_widget_list
*list
;
2150 int stream
= fe_substream
->stream
;
2152 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
2153 fe
->dpcm
[stream
].runtime
= fe_substream
->runtime
;
2155 if (dpcm_path_get(fe
, stream
, &list
) <= 0) {
2156 dev_dbg(fe
->dev
, "ASoC: %s no valid %s route\n",
2157 fe
->dai_link
->name
, stream
? "capture" : "playback");
2160 /* calculate valid and active FE <-> BE dpcms */
2161 dpcm_process_paths(fe
, stream
, &list
, 1);
2163 ret
= dpcm_fe_dai_startup(fe_substream
);
2165 /* clean up all links */
2166 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
)
2167 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
2169 dpcm_be_disconnect(fe
, stream
);
2170 fe
->dpcm
[stream
].runtime
= NULL
;
2173 dpcm_clear_pending_state(fe
, stream
);
2174 dpcm_path_put(&list
);
2175 mutex_unlock(&fe
->card
->mutex
);
2179 static int dpcm_fe_dai_close(struct snd_pcm_substream
*fe_substream
)
2181 struct snd_soc_pcm_runtime
*fe
= fe_substream
->private_data
;
2182 struct snd_soc_dpcm
*dpcm
;
2183 int stream
= fe_substream
->stream
, ret
;
2185 mutex_lock_nested(&fe
->card
->mutex
, SND_SOC_CARD_CLASS_RUNTIME
);
2186 ret
= dpcm_fe_dai_shutdown(fe_substream
);
2188 /* mark FE's links ready to prune */
2189 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
)
2190 dpcm
->state
= SND_SOC_DPCM_LINK_STATE_FREE
;
2192 dpcm_be_disconnect(fe
, stream
);
2194 fe
->dpcm
[stream
].runtime
= NULL
;
2195 mutex_unlock(&fe
->card
->mutex
);
2199 /* create a new pcm */
2200 int soc_new_pcm(struct snd_soc_pcm_runtime
*rtd
, int num
)
2202 struct snd_soc_platform
*platform
= rtd
->platform
;
2203 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
2204 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
2205 struct snd_pcm
*pcm
;
2207 int ret
= 0, playback
= 0, capture
= 0;
2209 if (rtd
->dai_link
->dynamic
|| rtd
->dai_link
->no_pcm
) {
2210 playback
= rtd
->dai_link
->dpcm_playback
;
2211 capture
= rtd
->dai_link
->dpcm_capture
;
2213 if (codec_dai
->driver
->playback
.channels_min
&&
2214 cpu_dai
->driver
->playback
.channels_min
)
2216 if (codec_dai
->driver
->capture
.channels_min
&&
2217 cpu_dai
->driver
->capture
.channels_min
)
2221 if (rtd
->dai_link
->playback_only
) {
2226 if (rtd
->dai_link
->capture_only
) {
2231 /* create the PCM */
2232 if (rtd
->dai_link
->no_pcm
) {
2233 snprintf(new_name
, sizeof(new_name
), "(%s)",
2234 rtd
->dai_link
->stream_name
);
2236 ret
= snd_pcm_new_internal(rtd
->card
->snd_card
, new_name
, num
,
2237 playback
, capture
, &pcm
);
2239 if (rtd
->dai_link
->dynamic
)
2240 snprintf(new_name
, sizeof(new_name
), "%s (*)",
2241 rtd
->dai_link
->stream_name
);
2243 snprintf(new_name
, sizeof(new_name
), "%s %s-%d",
2244 rtd
->dai_link
->stream_name
, codec_dai
->name
, num
);
2246 ret
= snd_pcm_new(rtd
->card
->snd_card
, new_name
, num
, playback
,
2250 dev_err(rtd
->card
->dev
, "ASoC: can't create pcm for %s\n",
2251 rtd
->dai_link
->name
);
2254 dev_dbg(rtd
->card
->dev
, "ASoC: registered pcm #%d %s\n",num
, new_name
);
2256 /* DAPM dai link stream work */
2257 INIT_DELAYED_WORK(&rtd
->delayed_work
, close_delayed_work
);
2260 pcm
->private_data
= rtd
;
2262 if (rtd
->dai_link
->no_pcm
) {
2264 pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
->private_data
= rtd
;
2266 pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
->private_data
= rtd
;
2270 /* ASoC PCM operations */
2271 if (rtd
->dai_link
->dynamic
) {
2272 rtd
->ops
.open
= dpcm_fe_dai_open
;
2273 rtd
->ops
.hw_params
= dpcm_fe_dai_hw_params
;
2274 rtd
->ops
.prepare
= dpcm_fe_dai_prepare
;
2275 rtd
->ops
.trigger
= dpcm_fe_dai_trigger
;
2276 rtd
->ops
.hw_free
= dpcm_fe_dai_hw_free
;
2277 rtd
->ops
.close
= dpcm_fe_dai_close
;
2278 rtd
->ops
.pointer
= soc_pcm_pointer
;
2279 rtd
->ops
.ioctl
= soc_pcm_ioctl
;
2281 rtd
->ops
.open
= soc_pcm_open
;
2282 rtd
->ops
.hw_params
= soc_pcm_hw_params
;
2283 rtd
->ops
.prepare
= soc_pcm_prepare
;
2284 rtd
->ops
.trigger
= soc_pcm_trigger
;
2285 rtd
->ops
.hw_free
= soc_pcm_hw_free
;
2286 rtd
->ops
.close
= soc_pcm_close
;
2287 rtd
->ops
.pointer
= soc_pcm_pointer
;
2288 rtd
->ops
.ioctl
= soc_pcm_ioctl
;
2291 if (platform
->driver
->ops
) {
2292 rtd
->ops
.ack
= platform
->driver
->ops
->ack
;
2293 rtd
->ops
.copy
= platform
->driver
->ops
->copy
;
2294 rtd
->ops
.silence
= platform
->driver
->ops
->silence
;
2295 rtd
->ops
.page
= platform
->driver
->ops
->page
;
2296 rtd
->ops
.mmap
= platform
->driver
->ops
->mmap
;
2300 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &rtd
->ops
);
2303 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &rtd
->ops
);
2305 if (platform
->driver
->pcm_new
) {
2306 ret
= platform
->driver
->pcm_new(rtd
);
2308 dev_err(platform
->dev
,
2309 "ASoC: pcm constructor failed: %d\n",
2315 pcm
->private_free
= platform
->driver
->pcm_free
;
2317 dev_info(rtd
->card
->dev
, "%s <-> %s mapping ok\n", codec_dai
->name
,
2322 /* is the current PCM operation for this FE ? */
2323 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime
*fe
, int stream
)
2325 if (fe
->dpcm
[stream
].runtime_update
== SND_SOC_DPCM_UPDATE_FE
)
2329 EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update
);
2331 /* is the current PCM operation for this BE ? */
2332 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime
*fe
,
2333 struct snd_soc_pcm_runtime
*be
, int stream
)
2335 if ((fe
->dpcm
[stream
].runtime_update
== SND_SOC_DPCM_UPDATE_FE
) ||
2336 ((fe
->dpcm
[stream
].runtime_update
== SND_SOC_DPCM_UPDATE_BE
) &&
2337 be
->dpcm
[stream
].runtime_update
))
2341 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update
);
2343 /* get the substream for this BE */
2344 struct snd_pcm_substream
*
2345 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime
*be
, int stream
)
2347 return be
->pcm
->streams
[stream
].substream
;
2349 EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream
);
2351 /* get the BE runtime state */
2352 enum snd_soc_dpcm_state
2353 snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime
*be
, int stream
)
2355 return be
->dpcm
[stream
].state
;
2357 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state
);
2359 /* set the BE runtime state */
2360 void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime
*be
,
2361 int stream
, enum snd_soc_dpcm_state state
)
2363 be
->dpcm
[stream
].state
= state
;
2365 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state
);
2368 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2369 * are not running, paused or suspended for the specified stream direction.
2371 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime
*fe
,
2372 struct snd_soc_pcm_runtime
*be
, int stream
)
2374 struct snd_soc_dpcm
*dpcm
;
2377 list_for_each_entry(dpcm
, &be
->dpcm
[stream
].fe_clients
, list_fe
) {
2382 state
= dpcm
->fe
->dpcm
[stream
].state
;
2383 if (state
== SND_SOC_DPCM_STATE_START
||
2384 state
== SND_SOC_DPCM_STATE_PAUSED
||
2385 state
== SND_SOC_DPCM_STATE_SUSPEND
)
2389 /* it's safe to free/stop this BE DAI */
2392 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop
);
2395 * We can only change hw params a BE DAI if any of it's FE are not prepared,
2396 * running, paused or suspended for the specified stream direction.
2398 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime
*fe
,
2399 struct snd_soc_pcm_runtime
*be
, int stream
)
2401 struct snd_soc_dpcm
*dpcm
;
2404 list_for_each_entry(dpcm
, &be
->dpcm
[stream
].fe_clients
, list_fe
) {
2409 state
= dpcm
->fe
->dpcm
[stream
].state
;
2410 if (state
== SND_SOC_DPCM_STATE_START
||
2411 state
== SND_SOC_DPCM_STATE_PAUSED
||
2412 state
== SND_SOC_DPCM_STATE_SUSPEND
||
2413 state
== SND_SOC_DPCM_STATE_PREPARE
)
2417 /* it's safe to change hw_params */
2420 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params
);
2422 int snd_soc_platform_trigger(struct snd_pcm_substream
*substream
,
2423 int cmd
, struct snd_soc_platform
*platform
)
2425 if (platform
->driver
->ops
&& platform
->driver
->ops
->trigger
)
2426 return platform
->driver
->ops
->trigger(substream
, cmd
);
2429 EXPORT_SYMBOL_GPL(snd_soc_platform_trigger
);
2431 #ifdef CONFIG_DEBUG_FS
2432 static char *dpcm_state_string(enum snd_soc_dpcm_state state
)
2435 case SND_SOC_DPCM_STATE_NEW
:
2437 case SND_SOC_DPCM_STATE_OPEN
:
2439 case SND_SOC_DPCM_STATE_HW_PARAMS
:
2441 case SND_SOC_DPCM_STATE_PREPARE
:
2443 case SND_SOC_DPCM_STATE_START
:
2445 case SND_SOC_DPCM_STATE_STOP
:
2447 case SND_SOC_DPCM_STATE_SUSPEND
:
2449 case SND_SOC_DPCM_STATE_PAUSED
:
2451 case SND_SOC_DPCM_STATE_HW_FREE
:
2453 case SND_SOC_DPCM_STATE_CLOSE
:
2460 static ssize_t
dpcm_show_state(struct snd_soc_pcm_runtime
*fe
,
2461 int stream
, char *buf
, size_t size
)
2463 struct snd_pcm_hw_params
*params
= &fe
->dpcm
[stream
].hw_params
;
2464 struct snd_soc_dpcm
*dpcm
;
2468 offset
+= snprintf(buf
+ offset
, size
- offset
,
2469 "[%s - %s]\n", fe
->dai_link
->name
,
2470 stream
? "Capture" : "Playback");
2472 offset
+= snprintf(buf
+ offset
, size
- offset
, "State: %s\n",
2473 dpcm_state_string(fe
->dpcm
[stream
].state
));
2475 if ((fe
->dpcm
[stream
].state
>= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
2476 (fe
->dpcm
[stream
].state
<= SND_SOC_DPCM_STATE_STOP
))
2477 offset
+= snprintf(buf
+ offset
, size
- offset
,
2479 "Format = %s, Channels = %d, Rate = %d\n",
2480 snd_pcm_format_name(params_format(params
)),
2481 params_channels(params
),
2482 params_rate(params
));
2485 offset
+= snprintf(buf
+ offset
, size
- offset
, "Backends:\n");
2487 if (list_empty(&fe
->dpcm
[stream
].be_clients
)) {
2488 offset
+= snprintf(buf
+ offset
, size
- offset
,
2489 " No active DSP links\n");
2493 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
2494 struct snd_soc_pcm_runtime
*be
= dpcm
->be
;
2495 params
= &dpcm
->hw_params
;
2497 offset
+= snprintf(buf
+ offset
, size
- offset
,
2498 "- %s\n", be
->dai_link
->name
);
2500 offset
+= snprintf(buf
+ offset
, size
- offset
,
2502 dpcm_state_string(be
->dpcm
[stream
].state
));
2504 if ((be
->dpcm
[stream
].state
>= SND_SOC_DPCM_STATE_HW_PARAMS
) &&
2505 (be
->dpcm
[stream
].state
<= SND_SOC_DPCM_STATE_STOP
))
2506 offset
+= snprintf(buf
+ offset
, size
- offset
,
2507 " Hardware Params: "
2508 "Format = %s, Channels = %d, Rate = %d\n",
2509 snd_pcm_format_name(params_format(params
)),
2510 params_channels(params
),
2511 params_rate(params
));
2518 static ssize_t
dpcm_state_read_file(struct file
*file
, char __user
*user_buf
,
2519 size_t count
, loff_t
*ppos
)
2521 struct snd_soc_pcm_runtime
*fe
= file
->private_data
;
2522 ssize_t out_count
= PAGE_SIZE
, offset
= 0, ret
= 0;
2525 buf
= kmalloc(out_count
, GFP_KERNEL
);
2529 if (fe
->cpu_dai
->driver
->playback
.channels_min
)
2530 offset
+= dpcm_show_state(fe
, SNDRV_PCM_STREAM_PLAYBACK
,
2531 buf
+ offset
, out_count
- offset
);
2533 if (fe
->cpu_dai
->driver
->capture
.channels_min
)
2534 offset
+= dpcm_show_state(fe
, SNDRV_PCM_STREAM_CAPTURE
,
2535 buf
+ offset
, out_count
- offset
);
2537 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, offset
);
2543 static const struct file_operations dpcm_state_fops
= {
2544 .open
= simple_open
,
2545 .read
= dpcm_state_read_file
,
2546 .llseek
= default_llseek
,
2549 int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime
*rtd
)
2554 rtd
->debugfs_dpcm_root
= debugfs_create_dir(rtd
->dai_link
->name
,
2555 rtd
->card
->debugfs_card_root
);
2556 if (!rtd
->debugfs_dpcm_root
) {
2558 "ASoC: Failed to create dpcm debugfs directory %s\n",
2559 rtd
->dai_link
->name
);
2563 rtd
->debugfs_dpcm_state
= debugfs_create_file("state", 0444,
2564 rtd
->debugfs_dpcm_root
,
2565 rtd
, &dpcm_state_fops
);