blob: b281be490d912c00e03be2ede6d273a52e151c60 [file] [log] [blame]
Liam Girdwoodddee6272011-06-09 14:45:53 +01001/*
2 * soc-pcm.c -- ALSA SoC PCM
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
8 *
9 * Authors: Liam Girdwood <lrg@ti.com>
10 * Mark Brown <broonie@opensource.wolfsonmicro.com>
11 *
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.
16 *
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/delay.h>
Mark Brownd6652ef2011-12-03 20:14:31 +000022#include <linux/pm_runtime.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010023#include <linux/slab.h>
24#include <linux/workqueue.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070025#include <linux/debugfs.h>
26#include <linux/dma-mapping.h>
27#include <linux/export.h>
Iliyan Malchev734dc212012-10-02 09:22:36 -070028#include <linux/bug.h>
SathishKumar Manief4feb32012-10-09 13:31:13 -070029#include <linux/ratelimit.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010030#include <sound/core.h>
31#include <sound/pcm.h>
32#include <sound/pcm_params.h>
33#include <sound/soc.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070034#include <sound/soc-dpcm.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010035#include <sound/initval.h>
36
Steve Mucklef132c6c2012-06-06 18:30:57 -070037#define MAX_BE_USERS 8 /* adjust if too low for everday use */
38
39static int soc_dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
40
41/* ASoC no host IO hardware.
42 * TODO: fine tune these values for all host less transfers.
43 */
44static const struct snd_pcm_hardware no_host_hardware = {
45 .info = SNDRV_PCM_INFO_MMAP |
46 SNDRV_PCM_INFO_MMAP_VALID |
47 SNDRV_PCM_INFO_INTERLEAVED |
48 SNDRV_PCM_INFO_PAUSE |
49 SNDRV_PCM_INFO_RESUME,
50 .formats = SNDRV_PCM_FMTBIT_S16_LE |
51 SNDRV_PCM_FMTBIT_S32_LE,
52 .period_bytes_min = PAGE_SIZE >> 2,
53 .period_bytes_max = PAGE_SIZE >> 1,
54 .periods_min = 2,
55 .periods_max = 4,
56 .buffer_bytes_max = PAGE_SIZE,
57};
58
59/*
60 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
61 * are not running, paused or suspended for the specified stream direction.
62 */
63int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
64 struct snd_soc_pcm_runtime *be, int stream)
65{
66 struct snd_soc_dpcm_params *dpcm_params;
67
68 list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
69
70 if (dpcm_params->fe == fe)
71 continue;
72
73 if (dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_START ||
74 dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PAUSED ||
75 dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_SUSPEND)
76 return 0;
77 }
78 return 1;
79}
80EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
81
82/*
83 * We can only change hw params a BE DAI if any of it's FE are not prepared,
84 * running, paused or suspended for the specified stream direction.
85 */
86static int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
87 struct snd_soc_pcm_runtime *be, int stream)
88{
89 struct snd_soc_dpcm_params *dpcm_params;
90
91 list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
92
93 if (dpcm_params->fe == fe)
94 continue;
95
96 if (dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_START ||
97 dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PAUSED ||
98 dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_SUSPEND ||
99 dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE)
100 return 0;
101 }
102 return 1;
103}
104
Dong Aisheng17841022011-08-29 17:15:14 +0800105static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
106 struct snd_soc_dai *soc_dai)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100107{
108 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100109 int ret;
110
Dong Aisheng17841022011-08-29 17:15:14 +0800111 if (!soc_dai->driver->symmetric_rates &&
Liam Girdwoodddee6272011-06-09 14:45:53 +0100112 !rtd->dai_link->symmetric_rates)
113 return 0;
114
115 /* This can happen if multiple streams are starting simultaneously -
116 * the second can need to get its constraints before the first has
117 * picked a rate. Complain and allow the application to carry on.
118 */
Dong Aisheng17841022011-08-29 17:15:14 +0800119 if (!soc_dai->rate) {
120 dev_warn(soc_dai->dev,
Liam Girdwoodddee6272011-06-09 14:45:53 +0100121 "Not enforcing symmetric_rates due to race\n");
122 return 0;
123 }
124
Dong Aisheng17841022011-08-29 17:15:14 +0800125 dev_dbg(soc_dai->dev, "Symmetry forces %dHz rate\n", soc_dai->rate);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100126
127 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
128 SNDRV_PCM_HW_PARAM_RATE,
Dong Aisheng17841022011-08-29 17:15:14 +0800129 soc_dai->rate, soc_dai->rate);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100130 if (ret < 0) {
Dong Aisheng17841022011-08-29 17:15:14 +0800131 dev_err(soc_dai->dev,
Liam Girdwoodddee6272011-06-09 14:45:53 +0100132 "Unable to apply rate symmetry constraint: %d\n", ret);
133 return ret;
134 }
135
136 return 0;
137}
138
139/*
Mark Brown58ba9b22012-01-16 18:38:51 +0000140 * List of sample sizes that might go over the bus for parameter
141 * application. There ought to be a wildcard sample size for things
142 * like the DAC/ADC resolution to use but there isn't right now.
143 */
144static int sample_sizes[] = {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700145 8, 16, 24, 32,
Mark Brown58ba9b22012-01-16 18:38:51 +0000146};
147
148static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
149 struct snd_soc_dai *dai)
150{
151 int ret, i, bits;
152
153 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
154 bits = dai->driver->playback.sig_bits;
155 else
156 bits = dai->driver->capture.sig_bits;
157
158 if (!bits)
159 return;
160
161 for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
Mark Brown278047f2012-01-19 18:04:18 +0000162 if (bits >= sample_sizes[i])
163 continue;
164
165 ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0,
166 sample_sizes[i], bits);
Mark Brown58ba9b22012-01-16 18:38:51 +0000167 if (ret != 0)
168 dev_warn(dai->dev,
169 "Failed to set MSB %d/%d: %d\n",
170 bits, sample_sizes[i], ret);
171 }
172}
173
174/*
Steve Mucklef132c6c2012-06-06 18:30:57 -0700175 * stream event, send event to FE and all active BEs.
176 */
177int soc_dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe,
178 int dir, const char *stream, int event)
179{
180 struct snd_soc_dpcm_params *dpcm_params;
181
182 snd_soc_dapm_rtd_stream_event(fe, dir, event);
183
184 list_for_each_entry(dpcm_params, &fe->dpcm[dir].be_clients, list_be) {
185
186 struct snd_soc_pcm_runtime *be = dpcm_params->be;
187
188 dev_dbg(be->dev, "pm: BE %s stream %s event %d dir %d\n",
189 be->dai_link->name, stream, event, dir);
190
191 snd_soc_dapm_rtd_stream_event(be, dir, event);
192 }
193
194 return 0;
195}
196
197/*
Liam Girdwoodddee6272011-06-09 14:45:53 +0100198 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
199 * then initialized and any private data can be allocated. This also calls
200 * startup for the cpu DAI, platform, machine and codec DAI.
201 */
202static int soc_pcm_open(struct snd_pcm_substream *substream)
203{
204 struct snd_soc_pcm_runtime *rtd = substream->private_data;
205 struct snd_pcm_runtime *runtime = substream->runtime;
206 struct snd_soc_platform *platform = rtd->platform;
207 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
208 struct snd_soc_dai *codec_dai = rtd->codec_dai;
209 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
210 struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
211 int ret = 0;
212
Mark Brownd6652ef2011-12-03 20:14:31 +0000213 pm_runtime_get_sync(cpu_dai->dev);
214 pm_runtime_get_sync(codec_dai->dev);
215 pm_runtime_get_sync(platform->dev);
216
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100217 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100218
Steve Mucklef132c6c2012-06-06 18:30:57 -0700219 if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST)
220 snd_soc_set_runtime_hwparams(substream, &no_host_hardware);
221
Liam Girdwoodddee6272011-06-09 14:45:53 +0100222 /* startup the audio subsystem */
223 if (cpu_dai->driver->ops->startup) {
224 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
225 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700226 printk(KERN_ERR "asoc: can't open interface %s\n",
227 cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100228 goto out;
229 }
230 }
231
232 if (platform->driver->ops && platform->driver->ops->open) {
233 ret = platform->driver->ops->open(substream);
234 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700235 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100236 goto platform_err;
237 }
238 }
239
240 if (codec_dai->driver->ops->startup) {
Helen Zeng5749b092012-06-10 11:50:29 -0700241 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
242 ret = codec_dai->driver->ops->startup(substream,
243 codec_dai);
244 if (ret < 0) {
245 printk(KERN_ERR "asoc: can't open codec %s\n",
246 codec_dai->name);
247 goto codec_dai_err;
248 }
249 } else {
250 if (!codec_dai->capture_active) {
251 ret = codec_dai->driver->ops->startup(substream,
252 codec_dai);
253 if (ret < 0) {
254 printk(KERN_ERR "can't open codec %s\n",
255 codec_dai->name);
256 goto codec_dai_err;
257 }
258 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100259 }
260 }
261
262 if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
263 ret = rtd->dai_link->ops->startup(substream);
264 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700265 printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100266 goto machine_err;
267 }
268 }
269
Steve Mucklef132c6c2012-06-06 18:30:57 -0700270 /* DSP DAI links compat checks are different */
271 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
272 goto dynamic;
273
Liam Girdwoodddee6272011-06-09 14:45:53 +0100274 /* Check that the codec and cpu DAIs are compatible */
275 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
276 runtime->hw.rate_min =
277 max(codec_dai_drv->playback.rate_min,
278 cpu_dai_drv->playback.rate_min);
279 runtime->hw.rate_max =
280 min(codec_dai_drv->playback.rate_max,
281 cpu_dai_drv->playback.rate_max);
282 runtime->hw.channels_min =
283 max(codec_dai_drv->playback.channels_min,
284 cpu_dai_drv->playback.channels_min);
285 runtime->hw.channels_max =
286 min(codec_dai_drv->playback.channels_max,
287 cpu_dai_drv->playback.channels_max);
288 runtime->hw.formats =
289 codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
290 runtime->hw.rates =
291 codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
292 if (codec_dai_drv->playback.rates
293 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
294 runtime->hw.rates |= cpu_dai_drv->playback.rates;
295 if (cpu_dai_drv->playback.rates
296 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
297 runtime->hw.rates |= codec_dai_drv->playback.rates;
298 } else {
299 runtime->hw.rate_min =
300 max(codec_dai_drv->capture.rate_min,
301 cpu_dai_drv->capture.rate_min);
302 runtime->hw.rate_max =
303 min(codec_dai_drv->capture.rate_max,
304 cpu_dai_drv->capture.rate_max);
305 runtime->hw.channels_min =
306 max(codec_dai_drv->capture.channels_min,
307 cpu_dai_drv->capture.channels_min);
308 runtime->hw.channels_max =
309 min(codec_dai_drv->capture.channels_max,
310 cpu_dai_drv->capture.channels_max);
311 runtime->hw.formats =
312 codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
313 runtime->hw.rates =
314 codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
315 if (codec_dai_drv->capture.rates
316 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
317 runtime->hw.rates |= cpu_dai_drv->capture.rates;
318 if (cpu_dai_drv->capture.rates
319 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
320 runtime->hw.rates |= codec_dai_drv->capture.rates;
321 }
322
323 ret = -EINVAL;
324 snd_pcm_limit_hw_rates(runtime);
325 if (!runtime->hw.rates) {
326 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
327 codec_dai->name, cpu_dai->name);
328 goto config_err;
329 }
330 if (!runtime->hw.formats) {
331 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
332 codec_dai->name, cpu_dai->name);
333 goto config_err;
334 }
335 if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
336 runtime->hw.channels_min > runtime->hw.channels_max) {
337 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
338 codec_dai->name, cpu_dai->name);
339 goto config_err;
340 }
341
Mark Brown58ba9b22012-01-16 18:38:51 +0000342 soc_pcm_apply_msb(substream, codec_dai);
343 soc_pcm_apply_msb(substream, cpu_dai);
344
Liam Girdwoodddee6272011-06-09 14:45:53 +0100345 /* Symmetry only applies if we've already got an active stream. */
Dong Aisheng17841022011-08-29 17:15:14 +0800346 if (cpu_dai->active) {
347 ret = soc_pcm_apply_symmetry(substream, cpu_dai);
348 if (ret != 0)
349 goto config_err;
350 }
351
352 if (codec_dai->active) {
353 ret = soc_pcm_apply_symmetry(substream, codec_dai);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100354 if (ret != 0)
355 goto config_err;
356 }
357
358 pr_debug("asoc: %s <-> %s info:\n",
359 codec_dai->name, cpu_dai->name);
360 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
361 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
362 runtime->hw.channels_max);
363 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
364 runtime->hw.rate_max);
365
Steve Mucklef132c6c2012-06-06 18:30:57 -0700366dynamic:
Liam Girdwoodddee6272011-06-09 14:45:53 +0100367 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
368 cpu_dai->playback_active++;
369 codec_dai->playback_active++;
370 } else {
371 cpu_dai->capture_active++;
372 codec_dai->capture_active++;
373 }
374 cpu_dai->active++;
375 codec_dai->active++;
376 rtd->codec->active++;
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100377 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100378 return 0;
379
380config_err:
381 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
382 rtd->dai_link->ops->shutdown(substream);
383
384machine_err:
385 if (codec_dai->driver->ops->shutdown)
386 codec_dai->driver->ops->shutdown(substream, codec_dai);
387
388codec_dai_err:
389 if (platform->driver->ops && platform->driver->ops->close)
390 platform->driver->ops->close(substream);
391
392platform_err:
393 if (cpu_dai->driver->ops->shutdown)
394 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
395out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100396 mutex_unlock(&rtd->pcm_mutex);
Mark Brownd6652ef2011-12-03 20:14:31 +0000397
398 pm_runtime_put(platform->dev);
399 pm_runtime_put(codec_dai->dev);
400 pm_runtime_put(cpu_dai->dev);
401
Liam Girdwoodddee6272011-06-09 14:45:53 +0100402 return ret;
403}
404
405/*
406 * Power down the audio subsystem pmdown_time msecs after close is called.
407 * This is to ensure there are no pops or clicks in between any music tracks
408 * due to DAPM power cycling.
409 */
410static void close_delayed_work(struct work_struct *work)
411{
412 struct snd_soc_pcm_runtime *rtd =
413 container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
414 struct snd_soc_dai *codec_dai = rtd->codec_dai;
415
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100416 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100417
418 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
419 codec_dai->driver->playback.stream_name,
420 codec_dai->playback_active ? "active" : "inactive",
421 codec_dai->pop_wait ? "yes" : "no");
422
423 /* are we waiting on this codec DAI stream */
424 if (codec_dai->pop_wait == 1) {
425 codec_dai->pop_wait = 0;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700426 snd_soc_dapm_stream_event(rtd,
427 codec_dai->driver->playback.stream_name,
428 SND_SOC_DAPM_STREAM_STOP);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100429 }
430
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100431 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100432}
433
434/*
435 * Called by ALSA when a PCM substream is closed. Private data can be
436 * freed here. The cpu DAI, codec DAI, machine and platform are also
437 * shutdown.
438 */
Liam Girdwood91d5e6b2011-06-09 17:04:59 +0100439static int soc_pcm_close(struct snd_pcm_substream *substream)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100440{
441 struct snd_soc_pcm_runtime *rtd = substream->private_data;
442 struct snd_soc_platform *platform = rtd->platform;
443 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
444 struct snd_soc_dai *codec_dai = rtd->codec_dai;
445 struct snd_soc_codec *codec = rtd->codec;
446
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100447 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100448
449 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
450 cpu_dai->playback_active--;
451 codec_dai->playback_active--;
452 } else {
453 cpu_dai->capture_active--;
454 codec_dai->capture_active--;
455 }
456
457 cpu_dai->active--;
458 codec_dai->active--;
459 codec->active--;
460
Dong Aisheng17841022011-08-29 17:15:14 +0800461 /* clear the corresponding DAIs rate when inactive */
462 if (!cpu_dai->active)
463 cpu_dai->rate = 0;
464
465 if (!codec_dai->active)
466 codec_dai->rate = 0;
Sascha Hauer25b76792011-08-17 09:20:01 +0200467
Liam Girdwoodddee6272011-06-09 14:45:53 +0100468 /* Muting the DAC suppresses artifacts caused during digital
469 * shutdown, for example from stopping clocks.
470 */
471 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
472 snd_soc_dai_digital_mute(codec_dai, 1);
473
Helen Zengd5131792012-06-28 11:24:11 -0700474 if (cpu_dai->driver->ops->shutdown)
475 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
476
477 if (codec_dai->driver->ops->shutdown) {
Helen Zeng5749b092012-06-10 11:50:29 -0700478 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
479 codec_dai->driver->ops->shutdown(substream, codec_dai);
480 } else {
481 if (!codec_dai->capture_active)
482 codec_dai->driver->ops->shutdown(substream,
483 codec_dai);
484 }
485 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100486
Liam Girdwoodddee6272011-06-09 14:45:53 +0100487 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
488 rtd->dai_link->ops->shutdown(substream);
489
490 if (platform->driver->ops && platform->driver->ops->close)
491 platform->driver->ops->close(substream);
492 cpu_dai->runtime = NULL;
493
494 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700495 if (codec->ignore_pmdown_time ||
496 rtd->dai_link->ignore_pmdown_time ||
497 !rtd->pmdown_time) {
Peter Ujfalusi1d69c5c2011-10-14 14:43:33 +0300498 /* powered down playback stream now */
499 snd_soc_dapm_stream_event(rtd,
Steve Mucklef132c6c2012-06-06 18:30:57 -0700500 codec_dai->driver->playback.stream_name,
501 SND_SOC_DAPM_STREAM_STOP);
Peter Ujfalusi1d69c5c2011-10-14 14:43:33 +0300502 } else {
503 /* start delayed pop wq here for playback streams */
504 codec_dai->pop_wait = 1;
505 schedule_delayed_work(&rtd->delayed_work,
506 msecs_to_jiffies(rtd->pmdown_time));
507 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100508 } else {
509 /* capture streams can be powered down now */
Helen Zeng5749b092012-06-10 11:50:29 -0700510 if (!codec_dai->capture_active)
511 snd_soc_dapm_stream_event(rtd,
Steve Mucklef132c6c2012-06-06 18:30:57 -0700512 codec_dai->driver->capture.stream_name,
513 SND_SOC_DAPM_STREAM_STOP);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100514 }
515
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100516 mutex_unlock(&rtd->pcm_mutex);
Mark Brownd6652ef2011-12-03 20:14:31 +0000517
518 pm_runtime_put(platform->dev);
519 pm_runtime_put(codec_dai->dev);
520 pm_runtime_put(cpu_dai->dev);
521
Liam Girdwoodddee6272011-06-09 14:45:53 +0100522 return 0;
523}
524
525/*
526 * Called by ALSA when the PCM substream is prepared, can set format, sample
527 * rate, etc. This function is non atomic and can be called multiple times,
528 * it can refer to the runtime info.
529 */
530static int soc_pcm_prepare(struct snd_pcm_substream *substream)
531{
532 struct snd_soc_pcm_runtime *rtd = substream->private_data;
533 struct snd_soc_platform *platform = rtd->platform;
534 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
535 struct snd_soc_dai *codec_dai = rtd->codec_dai;
536 int ret = 0;
537
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100538 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100539
540 if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
541 ret = rtd->dai_link->ops->prepare(substream);
542 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700543 printk(KERN_ERR "asoc: machine prepare error\n");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100544 goto out;
545 }
546 }
547
548 if (platform->driver->ops && platform->driver->ops->prepare) {
549 ret = platform->driver->ops->prepare(substream);
550 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700551 printk(KERN_ERR "asoc: platform prepare error\n");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100552 goto out;
553 }
554 }
555
556 if (codec_dai->driver->ops->prepare) {
557 ret = codec_dai->driver->ops->prepare(substream, codec_dai);
558 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700559 printk(KERN_ERR "asoc: codec DAI prepare error\n");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100560 goto out;
561 }
562 }
563
564 if (cpu_dai->driver->ops->prepare) {
565 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
566 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700567 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100568 goto out;
569 }
570 }
571
572 /* cancel any delayed stream shutdown that is pending */
573 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
574 codec_dai->pop_wait) {
575 codec_dai->pop_wait = 0;
576 cancel_delayed_work(&rtd->delayed_work);
577 }
578
Steve Mucklef132c6c2012-06-06 18:30:57 -0700579 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
580 snd_soc_dapm_stream_event(rtd,
581 codec_dai->driver->playback.stream_name,
582 SND_SOC_DAPM_STREAM_START);
Helen Zeng5749b092012-06-10 11:50:29 -0700583 else {
584 if (codec_dai->capture_active == 1)
585 snd_soc_dapm_stream_event(rtd,
Steve Mucklef132c6c2012-06-06 18:30:57 -0700586 codec_dai->driver->capture.stream_name,
587 SND_SOC_DAPM_STREAM_START);
Helen Zeng5749b092012-06-10 11:50:29 -0700588 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100589 snd_soc_dai_digital_mute(codec_dai, 0);
590
591out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100592 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100593 return ret;
594}
595
596/*
597 * Called by ALSA when the hardware params are set by application. This
598 * function can also be called multiple times and can allocate buffers
599 * (using snd_pcm_lib_* ). It's non-atomic.
600 */
601static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
602 struct snd_pcm_hw_params *params)
603{
604 struct snd_soc_pcm_runtime *rtd = substream->private_data;
605 struct snd_soc_platform *platform = rtd->platform;
606 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
607 struct snd_soc_dai *codec_dai = rtd->codec_dai;
608 int ret = 0;
609
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100610 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100611
612 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
613 ret = rtd->dai_link->ops->hw_params(substream, params);
614 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700615 printk(KERN_ERR "asoc: machine hw_params failed\n");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100616 goto out;
617 }
618 }
619
620 if (codec_dai->driver->ops->hw_params) {
Helen Zeng5749b092012-06-10 11:50:29 -0700621 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
622 ret = codec_dai->driver->ops->hw_params(substream,
623 params, codec_dai);
624 if (ret < 0) {
625 printk(KERN_ERR "not set codec %s hw params\n",
626 codec_dai->name);
627 goto codec_err;
628 }
629 } else {
630 if (codec_dai->capture_active == 1) {
631 ret = codec_dai->driver->ops->hw_params(
632 substream, params, codec_dai);
633 if (ret < 0) {
634 printk(KERN_ERR "fail: %s hw params\n",
635 codec_dai->name);
636 goto codec_err;
637 }
638 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100639 }
640 }
641
642 if (cpu_dai->driver->ops->hw_params) {
643 ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
644 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700645 printk(KERN_ERR "asoc: interface %s hw params failed\n",
646 cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100647 goto interface_err;
648 }
649 }
650
651 if (platform->driver->ops && platform->driver->ops->hw_params) {
652 ret = platform->driver->ops->hw_params(substream, params);
653 if (ret < 0) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700654 printk(KERN_ERR "asoc: platform %s hw params failed\n",
655 platform->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100656 goto platform_err;
657 }
658 }
659
Dong Aisheng17841022011-08-29 17:15:14 +0800660 /* store the rate for each DAIs */
661 cpu_dai->rate = params_rate(params);
662 codec_dai->rate = params_rate(params);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100663
Steve Mucklef132c6c2012-06-06 18:30:57 -0700664 /* malloc a page for hostless IO.
665 * FIXME: rework with alsa-lib changes so that this malloc is not required.
666 */
667 if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST) {
668 substream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV;
669 substream->dma_buffer.dev.dev = rtd->dev;
670 substream->dma_buffer.dev.dev->coherent_dma_mask = DMA_BIT_MASK(32);
671 substream->dma_buffer.private_data = NULL;
672
673 ret = snd_pcm_lib_malloc_pages(substream, PAGE_SIZE);
674 if (ret < 0)
675 goto platform_err;
676 }
677
Liam Girdwoodddee6272011-06-09 14:45:53 +0100678out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100679 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100680 return ret;
681
682platform_err:
683 if (cpu_dai->driver->ops->hw_free)
684 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
685
686interface_err:
687 if (codec_dai->driver->ops->hw_free)
688 codec_dai->driver->ops->hw_free(substream, codec_dai);
689
690codec_err:
691 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
692 rtd->dai_link->ops->hw_free(substream);
693
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100694 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100695 return ret;
696}
697
698/*
699 * Frees resources allocated by hw_params, can be called multiple times
700 */
701static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
702{
703 struct snd_soc_pcm_runtime *rtd = substream->private_data;
704 struct snd_soc_platform *platform = rtd->platform;
705 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
706 struct snd_soc_dai *codec_dai = rtd->codec_dai;
707 struct snd_soc_codec *codec = rtd->codec;
708
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100709 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100710
711 /* apply codec digital mute */
712 if (!codec->active)
713 snd_soc_dai_digital_mute(codec_dai, 1);
714
715 /* free any machine hw params */
716 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
717 rtd->dai_link->ops->hw_free(substream);
718
719 /* free any DMA resources */
720 if (platform->driver->ops && platform->driver->ops->hw_free)
721 platform->driver->ops->hw_free(substream);
722
723 /* now free hw params for the DAIs */
724 if (codec_dai->driver->ops->hw_free)
725 codec_dai->driver->ops->hw_free(substream, codec_dai);
726
727 if (cpu_dai->driver->ops->hw_free)
728 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
729
Steve Mucklef132c6c2012-06-06 18:30:57 -0700730 if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST)
731 snd_pcm_lib_free_pages(substream);
732
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100733 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100734 return 0;
735}
736
737static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
738{
739 struct snd_soc_pcm_runtime *rtd = substream->private_data;
740 struct snd_soc_platform *platform = rtd->platform;
741 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
742 struct snd_soc_dai *codec_dai = rtd->codec_dai;
743 int ret;
744
745 if (codec_dai->driver->ops->trigger) {
Helen Zeng5749b092012-06-10 11:50:29 -0700746 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
747 ret = codec_dai->driver->ops->trigger(substream,
748 cmd, codec_dai);
749 if (ret < 0)
750 return ret;
751 } else {
752 if (codec_dai->capture_active == 1) {
753 ret = codec_dai->driver->ops->trigger(
754 substream, cmd, codec_dai);
755 if (ret < 0)
756 return ret;
757 }
758 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100759 }
760
761 if (platform->driver->ops && platform->driver->ops->trigger) {
762 ret = platform->driver->ops->trigger(substream, cmd);
763 if (ret < 0)
764 return ret;
765 }
766
767 if (cpu_dai->driver->ops->trigger) {
768 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
769 if (ret < 0)
770 return ret;
771 }
772 return 0;
773}
774
Steve Mucklef132c6c2012-06-06 18:30:57 -0700775int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, int cmd)
776{
777 struct snd_soc_pcm_runtime *rtd = substream->private_data;
778 struct snd_soc_platform *platform = rtd->platform;
779 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
780 struct snd_soc_dai *codec_dai = rtd->codec_dai;
781 int ret;
782
783 if (codec_dai->driver->ops->bespoke_trigger) {
784 ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai);
785 if (ret < 0)
786 return ret;
787 }
788
789 if (platform->driver->bespoke_trigger) {
790 ret = platform->driver->bespoke_trigger(substream, cmd);
791 if (ret < 0)
792 return ret;
793 }
794
795 if (cpu_dai->driver->ops->bespoke_trigger) {
796 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
797 if (ret < 0)
798 return ret;
799 }
800 return 0;
801}
802
Liam Girdwoodddee6272011-06-09 14:45:53 +0100803/*
804 * soc level wrapper for pointer callback
805 * If cpu_dai, codec_dai, platform driver has the delay callback, than
806 * the runtime->delay will be updated accordingly.
807 */
808static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
809{
810 struct snd_soc_pcm_runtime *rtd = substream->private_data;
811 struct snd_soc_platform *platform = rtd->platform;
812 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
813 struct snd_soc_dai *codec_dai = rtd->codec_dai;
814 struct snd_pcm_runtime *runtime = substream->runtime;
815 snd_pcm_uframes_t offset = 0;
816 snd_pcm_sframes_t delay = 0;
817
818 if (platform->driver->ops && platform->driver->ops->pointer)
819 offset = platform->driver->ops->pointer(substream);
820
821 if (cpu_dai->driver->ops->delay)
822 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
823
824 if (codec_dai->driver->ops->delay)
825 delay += codec_dai->driver->ops->delay(substream, codec_dai);
826
827 if (platform->driver->delay)
828 delay += platform->driver->delay(substream, codec_dai);
829
830 runtime->delay = delay;
831
832 return offset;
833}
834
Steve Mucklef132c6c2012-06-06 18:30:57 -0700835static inline int be_connect(struct snd_soc_pcm_runtime *fe,
836 struct snd_soc_pcm_runtime *be, int stream)
837{
838 struct snd_soc_dpcm_params *dpcm_params;
839
840 if (!fe->dpcm[stream].runtime) {
841 dev_err(fe->dev, "%s no runtime\n", fe->dai_link->name);
842 return -ENODEV;
843 }
844
845 /* only add new dpcm_paramss */
846 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
847 if (dpcm_params->be == be && dpcm_params->fe == fe)
848 return 0;
849 }
850
851 dpcm_params = kzalloc(sizeof(struct snd_soc_dpcm_params), GFP_KERNEL);
852 if (!dpcm_params)
853 return -ENOMEM;
854
855 dpcm_params->be = be;
856 dpcm_params->fe = fe;
857 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
858 dpcm_params->state = SND_SOC_DPCM_LINK_STATE_NEW;
859 list_add(&dpcm_params->list_be, &fe->dpcm[stream].be_clients);
860 list_add(&dpcm_params->list_fe, &be->dpcm[stream].fe_clients);
861
862 dev_dbg(fe->dev, " connected new DSP %s path %s %s %s\n",
863 stream ? "capture" : "playback", fe->dai_link->name,
864 stream ? "<-" : "->", be->dai_link->name);
865
866#ifdef CONFIG_DEBUG_FS
867 dpcm_params->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
868 fe->debugfs_dpcm_root, &dpcm_params->state);
869#endif
870
871 return 1;
872}
873
874static inline void be_reparent(struct snd_soc_pcm_runtime *fe,
875 struct snd_soc_pcm_runtime *be, int stream)
876{
877 struct snd_soc_dpcm_params *dpcm_params;
878 struct snd_pcm_substream *fe_substream, *be_substream;
879
880 /* reparent if BE is connected to other FEs */
881 if (!be->dpcm[stream].users)
882 return;
883
884 be_substream = snd_soc_dpcm_get_substream(be, stream);
885
886 list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
887 if (dpcm_params->fe != fe) {
888
889 dev_dbg(fe->dev, " reparent %s path %s %s %s\n",
890 stream ? "capture" : "playback",
891 dpcm_params->fe->dai_link->name,
892 stream ? "<-" : "->", dpcm_params->be->dai_link->name);
893
894 fe_substream = snd_soc_dpcm_get_substream(dpcm_params->fe,
895 stream);
896 be_substream->runtime = fe_substream->runtime;
897 break;
898 }
899 }
900}
901
902static inline void be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
903{
904 struct snd_soc_dpcm_params *dpcm_params, *d;
905
906 list_for_each_entry_safe(dpcm_params, d, &fe->dpcm[stream].be_clients, list_be) {
907 dev_dbg(fe->dev, "BE %s disconnect check for %s\n",
908 stream ? "capture" : "playback",
909 dpcm_params->be->dai_link->name);
910
911 if (dpcm_params->state == SND_SOC_DPCM_LINK_STATE_FREE) {
912 dev_dbg(fe->dev, " freed DSP %s path %s %s %s\n",
913 stream ? "capture" : "playback", fe->dai_link->name,
914 stream ? "<-" : "->", dpcm_params->be->dai_link->name);
915
916 /* BEs still alive need new FE */
917 be_reparent(fe, dpcm_params->be, stream);
918
919#ifdef CONFIG_DEBUG_FS
920 debugfs_remove(dpcm_params->debugfs_state);
921#endif
922
923 list_del(&dpcm_params->list_be);
924 list_del(&dpcm_params->list_fe);
925 kfree(dpcm_params);
926 }
927 }
928}
929
930static struct snd_soc_pcm_runtime *be_get_rtd(struct snd_soc_card *card,
931 struct snd_soc_dapm_widget *widget)
932{
933 struct snd_soc_pcm_runtime *be;
934 int i;
935
936 if (!widget->sname) {
937 dev_err(card->dev, "widget %s has no stream\n", widget->name);
938 return NULL;
939 }
940
941 for (i = 0; i < card->num_links; i++) {
942 be = &card->rtd[i];
943
944 if (!strcmp(widget->sname, be->dai_link->stream_name))
945 return be;
946 }
947
948 dev_err(card->dev, "can't get BE for %s\n", widget->name);
949 return NULL;
950}
951
952static struct snd_soc_dapm_widget *be_get_widget(struct snd_soc_card *card,
953 struct snd_soc_pcm_runtime *rtd)
954{
955 struct snd_soc_dapm_widget *widget;
956
957 list_for_each_entry(widget, &card->widgets, list) {
958
959 if (!widget->sname)
960 continue;
961
962 if (!strcmp(widget->sname, rtd->dai_link->stream_name))
963 return widget;
964 }
965
966 dev_err(card->dev, "can't get widget for %s\n",
967 rtd->dai_link->stream_name);
968 return NULL;
969}
970
971static int widget_in_list(struct snd_soc_dapm_widget_list *list,
972 struct snd_soc_dapm_widget *widget)
973{
974 int i;
975
976 for (i = 0; i < list->num_widgets; i++) {
977 if (widget == list->widgets[i])
978 return 1;
979 }
980
981 return 0;
982}
983
984static int fe_path_get(struct snd_soc_pcm_runtime *fe,
985 int stream, struct snd_soc_dapm_widget_list **list_)
986{
987 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
988 struct snd_soc_dapm_widget_list *list;
989 int paths;
990
991 list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) +
992 sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL);
993 if (list == NULL)
994 return -ENOMEM;
995
996 /* get number of valid DAI paths and their widgets */
997 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list);
998
999 dev_dbg(fe->dev, "found %d audio %s paths\n", paths,
1000 stream ? "capture" : "playback");
1001
1002 *list_ = list;
1003 return paths;
1004}
1005
1006static inline void fe_path_put(struct snd_soc_dapm_widget_list **list)
1007{
1008 kfree(*list);
1009}
1010
1011static int be_prune_old(struct snd_soc_pcm_runtime *fe, int stream,
1012 struct snd_soc_dapm_widget_list **list_)
1013{
1014 struct snd_soc_card *card = fe->card;
1015 struct snd_soc_dpcm_params *dpcm_params;
1016 struct snd_soc_dapm_widget_list *list = *list_;
1017 struct snd_soc_dapm_widget *widget;
1018 int old = 0;
1019
1020 /* Destroy any old FE <--> BE connections */
1021 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1022
1023 /* is there a valid widget for this BE */
1024 widget = be_get_widget(card, dpcm_params->be);
1025 if (!widget) {
1026 dev_err(fe->dev, "no widget found for %s\n",
1027 dpcm_params->be->dai_link->name);
1028 continue;
1029 }
1030
1031 /* prune the BE if it's no longer in our active list */
1032 if (widget_in_list(list, widget))
1033 continue;
1034
1035 dev_dbg(fe->dev, "pruning %s BE %s for %s\n",
1036 stream ? "capture" : "playback", dpcm_params->be->dai_link->name,
1037 fe->dai_link->name);
1038 dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
1039 dpcm_params->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1040 old++;
1041 }
1042
1043 dev_dbg(fe->dev, "found %d old BEs\n", old);
1044 return old;
1045}
1046
1047static int be_add_new(struct snd_soc_pcm_runtime *fe, int stream,
1048 struct snd_soc_dapm_widget_list **list_)
1049{
1050 struct snd_soc_card *card = fe->card;
1051 struct snd_soc_dapm_widget_list *list = *list_;
1052 enum snd_soc_dapm_type be_type;
1053 int i, new = 0, err;
1054
1055 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1056 be_type = snd_soc_dapm_aif_out;
1057 else
1058 be_type = snd_soc_dapm_aif_in;
1059
1060 /* Create any new FE <--> BE connections */
1061 for (i = 0; i < list->num_widgets; i++) {
1062
1063 if (list->widgets[i]->id == be_type) {
1064 struct snd_soc_pcm_runtime *be;
1065
1066 /* is there a valid BE rtd for this widget */
1067 be = be_get_rtd(card, list->widgets[i]);
1068 if (!be) {
1069 dev_err(fe->dev, "no BE found for %s\n",
1070 list->widgets[i]->name);
1071 continue;
1072 }
1073
1074 /* don't connect if FE is not running */
1075 if (!fe->dpcm[stream].runtime)
1076 continue;
1077
1078 /* newly connected FE and BE */
1079 err = be_connect(fe, be, stream);
1080 if (err < 0) {
1081 dev_err(fe->dev, "can't connect %s\n", list->widgets[i]->name);
1082 break;
1083 } else if (err == 0) /* already connected */
1084 continue;
1085
1086 /* new */
1087 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1088 new++;
1089 }
1090 }
1091
1092 dev_dbg(fe->dev, "found %d new BEs\n", new);
1093 return new;
1094}
1095
1096/*
1097 * Find the corresponding BE DAIs that source or sink audio to this
1098 * FE substream.
1099 */
1100static int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
1101 int stream, struct snd_soc_dapm_widget_list **list, int new)
1102{
1103 if (new)
1104 return be_add_new(fe, stream, list);
1105 else
1106 return be_prune_old(fe, stream, list);
1107 return 0;
1108}
1109
1110/*
1111 * Clear the runtime pending state of all BE's.
1112 */
1113static void fe_clear_pending(struct snd_soc_pcm_runtime *fe, int stream)
1114{
1115 struct snd_soc_dpcm_params *dpcm_params;
1116
1117 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
1118 dpcm_params->be->dpcm[stream].runtime_update =
1119 SND_SOC_DPCM_UPDATE_NO;
1120}
1121
1122/* Unwind the BE startup */
1123static void soc_dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe, int stream)
1124{
1125 struct snd_soc_dpcm_params *dpcm_params;
1126
1127 /* disable any enabled and non active backends */
1128 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1129
1130 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1131 struct snd_pcm_substream *be_substream =
1132 snd_soc_dpcm_get_substream(be, stream);
1133
1134 if (be->dpcm[stream].users == 0)
1135 dev_err(be->dev, "no users %s at close - state %d\n",
1136 stream ? "capture" : "playback", be->dpcm[stream].state);
1137
1138 if (--be->dpcm[stream].users != 0)
1139 continue;
1140
1141 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1142 continue;
1143
1144 soc_pcm_close(be_substream);
1145 be_substream->runtime = NULL;
1146
1147 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1148 }
1149}
1150
1151/* Startup all new BE */
1152static int soc_dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1153{
1154 struct snd_soc_dpcm_params *dpcm_params;
1155 int err, count = 0;
1156
1157 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1158 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1159
1160 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1161 struct snd_pcm_substream *be_substream =
1162 snd_soc_dpcm_get_substream(be, stream);
1163
1164 /* is this op for this BE ? */
1165 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1166 continue;
1167
1168 /* first time the dpcm_params is open ? */
1169 if (be->dpcm[stream].users == MAX_BE_USERS)
1170 dev_err(be->dev, "too many users %s at open - state %d\n",
1171 stream ? "capture" : "playback", be->dpcm[stream].state);
1172
1173 if (be->dpcm[stream].users++ != 0)
1174 continue;
1175
1176 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1177 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1178 continue;
1179
1180 dev_dbg(be->dev, "dpcm: open BE %s\n", be->dai_link->name);
1181
1182 be_substream->runtime = be->dpcm[stream].runtime;
1183 err = soc_pcm_open(be_substream);
1184 if (err < 0) {
1185 dev_err(be->dev, "BE open failed %d\n", err);
1186 be->dpcm[stream].users--;
1187 if (be->dpcm[stream].users < 0)
1188 dev_err(be->dev, "no users %s at unwind - state %d\n",
1189 stream ? "capture" : "playback",
1190 be->dpcm[stream].state);
1191
1192 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1193 goto unwind;
1194 }
1195
1196 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1197 count++;
1198 }
1199
1200 return count;
1201
1202unwind:
1203 /* disable any enabled and non active backends */
1204 list_for_each_entry_continue_reverse(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1205 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1206 struct snd_pcm_substream *be_substream =
1207 snd_soc_dpcm_get_substream(be, stream);
1208
1209 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1210 continue;
1211
1212 if (be->dpcm[stream].users == 0)
1213 dev_err(be->dev, "no users %s at close - state %d\n",
1214 stream ? "capture" : "playback", be->dpcm[stream].state);
1215
1216 if (--be->dpcm[stream].users != 0)
1217 continue;
1218
1219 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1220 continue;
1221
1222 soc_pcm_close(be_substream);
1223 be_substream->runtime = NULL;
1224
1225 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1226 }
1227
1228 return err;
1229}
1230
1231void soc_dpcm_set_dynamic_runtime(struct snd_pcm_substream *substream)
1232{
1233 struct snd_pcm_runtime *runtime = substream->runtime;
1234 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1235 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1236 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
1237
1238 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1239 runtime->hw.rate_min = cpu_dai_drv->playback.rate_min;
1240 runtime->hw.rate_max = cpu_dai_drv->playback.rate_max;
1241 runtime->hw.channels_min = cpu_dai_drv->playback.channels_min;
1242 runtime->hw.channels_max = cpu_dai_drv->playback.channels_max;
1243 runtime->hw.formats &= cpu_dai_drv->playback.formats;
1244 runtime->hw.rates = cpu_dai_drv->playback.rates;
1245 } else {
1246 runtime->hw.rate_min = cpu_dai_drv->capture.rate_min;
1247 runtime->hw.rate_max = cpu_dai_drv->capture.rate_max;
1248 runtime->hw.channels_min = cpu_dai_drv->capture.channels_min;
1249 runtime->hw.channels_max = cpu_dai_drv->capture.channels_max;
1250 runtime->hw.formats &= cpu_dai_drv->capture.formats;
1251 runtime->hw.rates = cpu_dai_drv->capture.rates;
1252 }
1253}
1254
1255static int soc_dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1256{
1257 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1258 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1259 int stream = fe_substream->stream, ret = 0;
1260
1261 mutex_lock(&fe->card->dpcm_mutex);
1262 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1263
1264 ret = soc_dpcm_be_dai_startup(fe, fe_substream->stream);
1265 if (ret < 0) {
1266 dev_err(fe->dev,"dpcm: failed to start some BEs %d\n", ret);
1267 goto be_err;
1268 }
1269
1270 dev_dbg(fe->dev, "dpcm: open FE %s\n", fe->dai_link->name);
1271
1272 /* start the DAI frontend */
1273 ret = soc_pcm_open(fe_substream);
1274 if (ret < 0) {
1275 dev_err(fe->dev,"dpcm: failed to start FE %d\n", ret);
1276 goto unwind;
1277 }
1278
1279 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1280
1281 soc_dpcm_set_dynamic_runtime(fe_substream);
1282 snd_pcm_limit_hw_rates(runtime);
1283
1284 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1285 mutex_unlock(&fe->card->dpcm_mutex);
1286 return 0;
1287
1288unwind:
1289 soc_dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
1290be_err:
1291 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1292 mutex_unlock(&fe->card->dpcm_mutex);
1293 return ret;
1294}
1295
1296/* BE shutdown - called on DAPM sync updates (i.e. FE is already running)*/
1297static int soc_dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1298{
1299 struct snd_soc_dpcm_params *dpcm_params;
1300
1301 /* only shutdown backends that are either sinks or sources to this frontend DAI */
1302 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1303
1304 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1305 struct snd_pcm_substream *be_substream =
1306 snd_soc_dpcm_get_substream(be, stream);
1307
1308 /* is this op for this BE ? */
1309 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1310 continue;
1311
1312 if (be->dpcm[stream].users == 0)
1313 dev_err(be->dev, "no users %s at close - state %d\n",
1314 stream ? "capture" : "playback", be->dpcm[stream].state);
1315
1316 if (--be->dpcm[stream].users != 0)
1317 continue;
1318
1319 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1320 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
1321 continue;
1322
1323 dev_dbg(be->dev, "dpcm: close BE %s\n",
1324 dpcm_params->fe->dai_link->name);
1325
1326 soc_pcm_close(be_substream);
1327 be_substream->runtime = NULL;
1328
1329 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1330 }
1331 return 0;
1332}
1333
1334/* FE +BE shutdown - called on FE PCM ops */
1335static int soc_dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1336{
1337 struct snd_soc_pcm_runtime *fe = substream->private_data;
1338 int stream = substream->stream;
1339
1340 mutex_lock(&fe->card->dpcm_mutex);
1341 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1342
1343 dev_dbg(fe->dev, "dpcm: close FE %s\n", fe->dai_link->name);
1344
1345 /* now shutdown the frontend */
1346 soc_pcm_close(substream);
1347
1348 /* shutdown the BEs */
1349 soc_dpcm_be_dai_shutdown(fe, substream->stream);
1350 /* run the stream event for each BE */
1351 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1352 soc_dpcm_dapm_stream_event(fe, stream,
1353 fe->cpu_dai->driver->playback.stream_name,
1354 SND_SOC_DAPM_STREAM_STOP);
1355 else
1356 soc_dpcm_dapm_stream_event(fe, stream,
1357 fe->cpu_dai->driver->capture.stream_name,
1358 SND_SOC_DAPM_STREAM_STOP);
1359
1360 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1361 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1362
1363 mutex_unlock(&fe->card->dpcm_mutex);
1364 return 0;
1365}
1366
1367static int soc_dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1368{
1369 struct snd_soc_dpcm_params *dpcm_params;
1370 int ret;
1371
1372 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1373
1374 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1375 struct snd_pcm_substream *be_substream =
1376 snd_soc_dpcm_get_substream(be, stream);
1377
1378 /* is this op for this BE ? */
1379 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1380 continue;
1381
1382 /* only allow hw_params() if no connected FEs are running */
1383 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1384 continue;
1385
1386 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1387 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1388 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1389 continue;
1390
1391 dev_dbg(be->dev, "dpcm: hw_params BE %s\n",
1392 dpcm_params->fe->dai_link->name);
1393
1394 /* copy params for each dpcm_params */
1395 memcpy(&dpcm_params->hw_params, &fe->dpcm[stream].hw_params,
1396 sizeof(struct snd_pcm_hw_params));
1397
1398 /* perform any hw_params fixups */
1399 if (be->dai_link->be_hw_params_fixup) {
1400 ret = be->dai_link->be_hw_params_fixup(be,
1401 &dpcm_params->hw_params);
1402 if (ret < 0) {
1403 dev_err(be->dev,
1404 "dpcm: hw_params BE fixup failed %d\n",
1405 ret);
1406 goto unwind;
1407 }
1408 }
1409
1410 ret = soc_pcm_hw_params(be_substream, &dpcm_params->hw_params);
1411 if (ret < 0) {
1412 dev_err(dpcm_params->be->dev, "dpcm: hw_params BE failed %d\n", ret);
1413 goto unwind;
1414 }
1415
1416 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1417 }
1418 return 0;
1419
1420unwind:
1421 /* disable any enabled and non active backends */
1422 list_for_each_entry_continue_reverse(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1423 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1424 struct snd_pcm_substream *be_substream =
1425 snd_soc_dpcm_get_substream(be, stream);
1426
1427 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1428 continue;
1429
1430 /* only allow hw_free() if no connected FEs are running */
1431 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1432 continue;
1433
1434 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1435 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1436 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1437 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1438 continue;
1439
1440 soc_pcm_hw_free(be_substream);
1441 }
1442
1443 return ret;
1444}
1445
1446int soc_dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1447 struct snd_pcm_hw_params *params)
1448{
1449 struct snd_soc_pcm_runtime *fe = substream->private_data;
1450 int ret, stream = substream->stream;
1451
1452 mutex_lock(&fe->card->dpcm_mutex);
1453 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1454
1455 memcpy(&fe->dpcm[substream->stream].hw_params, params,
1456 sizeof(struct snd_pcm_hw_params));
1457 ret = soc_dpcm_be_dai_hw_params(fe, substream->stream);
1458 if (ret < 0) {
1459 dev_err(fe->dev,"dpcm: hw_params failed for some BEs %d\n", ret);
1460 goto out;
1461 }
1462
1463 dev_dbg(fe->dev, "dpcm: hw_params FE %s rate %d chan %x fmt %d\n",
1464 fe->dai_link->name, params_rate(params), params_channels(params),
1465 params_format(params));
1466
1467 /* call hw_params on the frontend */
1468 ret = soc_pcm_hw_params(substream, params);
1469 if (ret < 0) {
1470 dev_err(fe->dev,"dpcm: hw_params FE failed %d\n", ret);
1471 soc_dpcm_be_dai_hw_free(fe, stream);
1472 } else
1473 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1474
1475out:
1476 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1477 mutex_unlock(&fe->card->dpcm_mutex);
1478 return ret;
1479}
1480
1481static int dpcm_do_trigger(struct snd_soc_dpcm_params *dpcm_params,
1482 struct snd_pcm_substream *substream, int cmd)
1483{
1484 int ret;
1485
1486 dev_dbg(dpcm_params->be->dev, "dpcm: trigger BE %s cmd %d\n",
1487 dpcm_params->fe->dai_link->name, cmd);
1488
1489 ret = soc_pcm_trigger(substream, cmd);
1490 if (ret < 0)
1491 dev_err(dpcm_params->be->dev,"dpcm: trigger BE failed %d\n", ret);
1492
1493 return ret;
1494}
1495
1496int soc_dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd)
1497{
1498 struct snd_soc_dpcm_params *dpcm_params;
1499 int ret = 0;
1500
Steve Mucklef132c6c2012-06-06 18:30:57 -07001501 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1502
1503 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1504 struct snd_pcm_substream *be_substream =
1505 snd_soc_dpcm_get_substream(be, stream);
1506
1507 /* is this op for this BE ? */
1508 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1509 continue;
1510
1511 switch (cmd) {
1512 case SNDRV_PCM_TRIGGER_START:
1513 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1514 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1515 continue;
1516
1517 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1518 if (ret)
1519 return ret;
1520
1521 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1522 break;
1523 case SNDRV_PCM_TRIGGER_RESUME:
1524 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1525 continue;
1526
1527 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1528 if (ret)
1529 return ret;
1530
1531 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1532 break;
1533 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1534 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
1535 continue;
1536
1537 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1538 if (ret)
1539 return ret;
1540
1541 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1542 break;
1543 case SNDRV_PCM_TRIGGER_STOP:
1544 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1545 continue;
1546
1547 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1548 continue;
1549
1550 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1551 if (ret)
1552 return ret;
1553
1554 be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1555 break;
1556 case SNDRV_PCM_TRIGGER_SUSPEND:
1557 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)
1558 continue;
1559
1560 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1561 continue;
1562
1563 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1564 if (ret)
1565 return ret;
1566
1567 be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
1568 break;
1569 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1570 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1571 continue;
1572
1573 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1574 continue;
1575
1576 ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
1577 if (ret)
1578 return ret;
1579
1580 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
1581 break;
1582 }
1583 }
1584
1585 return ret;
1586}
1587EXPORT_SYMBOL_GPL(soc_dpcm_be_dai_trigger);
1588
1589int soc_dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
1590{
1591 struct snd_soc_pcm_runtime *fe = substream->private_data;
1592 int stream = substream->stream, ret;
1593 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1594
1595 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1596
1597 switch (trigger) {
1598 case SND_SOC_DPCM_TRIGGER_PRE:
1599 /* call trigger on the frontend before the backend. */
1600
1601 dev_dbg(fe->dev, "dpcm: pre trigger FE %s cmd %d\n",
1602 fe->dai_link->name, cmd);
1603
1604 ret = soc_pcm_trigger(substream, cmd);
1605 if (ret < 0) {
1606 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1607 goto out;
1608 }
1609
1610 ret = soc_dpcm_be_dai_trigger(fe, substream->stream, cmd);
1611 break;
1612 case SND_SOC_DPCM_TRIGGER_POST:
1613 /* call trigger on the frontend after the backend. */
1614
1615 ret = soc_dpcm_be_dai_trigger(fe, substream->stream, cmd);
1616 if (ret < 0) {
1617 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1618 goto out;
1619 }
1620
1621 dev_dbg(fe->dev, "dpcm: post trigger FE %s cmd %d\n",
1622 fe->dai_link->name, cmd);
1623
1624 ret = soc_pcm_trigger(substream, cmd);
1625 break;
1626 case SND_SOC_DPCM_TRIGGER_BESPOKE:
1627 /* bespoke trigger() - handles both FE and BEs */
1628
1629 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd %d\n",
1630 fe->dai_link->name, cmd);
1631
1632 ret = soc_pcm_bespoke_trigger(substream, cmd);
1633 if (ret < 0) {
1634 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1635 goto out;
1636 }
1637 break;
1638 default:
1639 dev_err(fe->dev, "dpcm: invalid trigger cmd %d for %s\n", cmd,
1640 fe->dai_link->name);
1641 ret = -EINVAL;
1642 goto out;
1643 }
1644
1645 switch (cmd) {
1646 case SNDRV_PCM_TRIGGER_START:
1647 case SNDRV_PCM_TRIGGER_RESUME:
1648 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1649 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1650 break;
1651 case SNDRV_PCM_TRIGGER_STOP:
1652 case SNDRV_PCM_TRIGGER_SUSPEND:
Steve Mucklef132c6c2012-06-06 18:30:57 -07001653 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1654 break;
Banajit Goswami9c5f4d12013-02-14 18:24:08 -08001655 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1656 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
1657 break;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001658 }
1659
1660out:
1661 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1662 return ret;
1663}
1664
1665static int soc_dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
1666{
1667 struct snd_soc_dpcm_params *dpcm_params;
1668 int ret = 0;
1669
1670 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1671
1672 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1673 struct snd_pcm_substream *be_substream =
1674 snd_soc_dpcm_get_substream(be, stream);
1675
1676 /* is this op for this BE ? */
1677 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1678 continue;
1679
1680 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1681 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1682 continue;
1683
1684 dev_dbg(be->dev, "dpcm: prepare BE %s\n",
1685 dpcm_params->fe->dai_link->name);
1686
1687 ret = soc_pcm_prepare(be_substream);
1688 if (ret < 0) {
1689 dev_err(be->dev, "dpcm: backend prepare failed %d\n",
1690 ret);
1691 break;
1692 }
1693
1694 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
1695 }
1696 return ret;
1697}
1698
1699int soc_dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
1700{
1701 struct snd_soc_pcm_runtime *fe = substream->private_data;
1702 int stream = substream->stream, ret = 0;
1703
1704 mutex_lock(&fe->card->dpcm_mutex);
1705
1706 dev_dbg(fe->dev, "dpcm: prepare FE %s\n", fe->dai_link->name);
1707
1708 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1709
1710 /* there is no point preparing this FE if there are no BEs */
1711 if (list_empty(&fe->dpcm[stream].be_clients)) {
1712 dev_err(fe->dev, "dpcm: no backend DAIs enabled for %s\n",
1713 fe->dai_link->name);
1714 ret = -EINVAL;
1715 goto out;
1716 }
1717
1718 ret = soc_dpcm_be_dai_prepare(fe, substream->stream);
1719 if (ret < 0)
1720 goto out;
1721
1722 /* call prepare on the frontend */
1723 ret = soc_pcm_prepare(substream);
1724 if (ret < 0) {
1725 dev_err(fe->dev,"dpcm: prepare FE %s failed\n", fe->dai_link->name);
1726 goto out;
1727 }
1728
1729 /* run the stream event for each BE */
1730 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1731 soc_dpcm_dapm_stream_event(fe, stream,
1732 fe->cpu_dai->driver->playback.stream_name,
1733 SND_SOC_DAPM_STREAM_START);
1734 else
1735 soc_dpcm_dapm_stream_event(fe, stream,
1736 fe->cpu_dai->driver->capture.stream_name,
1737 SND_SOC_DAPM_STREAM_START);
1738
1739 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
1740
1741out:
1742 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1743 mutex_unlock(&fe->card->dpcm_mutex);
1744 return ret;
1745}
1746
1747static int soc_dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1748{
1749 struct snd_soc_dpcm_params *dpcm_params;
1750
1751 /* only hw_params backends that are either sinks or sources
1752 * to this frontend DAI */
1753 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1754
1755 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1756 struct snd_pcm_substream *be_substream =
1757 snd_soc_dpcm_get_substream(be, stream);
1758
1759 /* is this op for this BE ? */
1760 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1761 continue;
1762
1763 /* only free hw when no longer used - check all FEs */
1764 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1765 continue;
1766
1767 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1768 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1769 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
Banajit Goswamib7dd6152012-10-24 15:57:26 -07001770 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
Steve Mucklef132c6c2012-06-06 18:30:57 -07001771 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1772 continue;
1773
1774 dev_dbg(be->dev, "dpcm: hw_free BE %s\n",
1775 dpcm_params->fe->dai_link->name);
1776
1777 soc_pcm_hw_free(be_substream);
1778
1779 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1780 }
1781
1782 return 0;
1783}
1784
1785int soc_dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1786{
1787 struct snd_soc_pcm_runtime *fe = substream->private_data;
1788 int err, stream = substream->stream;
1789
1790 mutex_lock(&fe->card->dpcm_mutex);
1791 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1792
1793 dev_dbg(fe->dev, "dpcm: hw_free FE %s\n", fe->dai_link->name);
1794
1795 /* call hw_free on the frontend */
1796 err = soc_pcm_hw_free(substream);
1797 if (err < 0)
1798 dev_err(fe->dev,"dpcm: hw_free FE %s failed\n", fe->dai_link->name);
1799
1800 /* only hw_params backends that are either sinks or sources
1801 * to this frontend DAI */
1802 err = soc_dpcm_be_dai_hw_free(fe, stream);
1803
1804 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1805 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1806
1807 mutex_unlock(&fe->card->dpcm_mutex);
1808 return 0;
1809}
1810
1811static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
1812 unsigned int cmd, void *arg)
1813{
1814 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1815 struct snd_soc_platform *platform = rtd->platform;
1816
1817 if (platform->driver->ops->ioctl)
1818 return platform->driver->ops->ioctl(substream, cmd, arg);
1819 return snd_pcm_lib_ioctl(substream, cmd, arg);
1820}
1821
1822static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1823{
1824 struct snd_pcm_substream *substream = snd_soc_dpcm_get_substream(fe, stream);
1825 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1826 int err;
1827
1828 dev_dbg(fe->dev, "runtime %s close on FE %s\n",
1829 stream ? "capture" : "playback", fe->dai_link->name);
1830
1831 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
1832 /* call bespoke trigger - FE takes care of all BE triggers */
1833 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd stop\n",
1834 fe->dai_link->name);
1835
1836 err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
1837 if (err < 0)
1838 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
1839 } else {
1840 dev_dbg(fe->dev, "dpcm: trigger FE %s cmd stop\n",
1841 fe->dai_link->name);
1842
1843 err = soc_dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
1844 if (err < 0)
1845 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
1846 }
1847
1848 err = soc_dpcm_be_dai_hw_free(fe, stream);
1849 if (err < 0)
1850 dev_err(fe->dev,"dpcm: hw_free FE failed %d\n", err);
1851
1852 err = soc_dpcm_be_dai_shutdown(fe, stream);
1853 if (err < 0)
1854 dev_err(fe->dev,"dpcm: shutdown FE failed %d\n", err);
1855
1856 /* run the stream event for each BE */
1857 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1858 soc_dpcm_dapm_stream_event(fe, stream,
1859 fe->cpu_dai->driver->playback.stream_name,
1860 SND_SOC_DAPM_STREAM_NOP);
1861 else
1862 soc_dpcm_dapm_stream_event(fe, stream,
1863 fe->cpu_dai->driver->capture.stream_name,
1864 SND_SOC_DAPM_STREAM_NOP);
1865
1866 return 0;
1867}
1868
1869static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
1870{
1871 struct snd_pcm_substream *substream = snd_soc_dpcm_get_substream(fe, stream);
1872 struct snd_soc_dpcm_params *dpcm_params;
1873 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1874 int ret;
1875
1876 dev_dbg(fe->dev, "runtime %s open on FE %s\n",
1877 stream ? "capture" : "playback", fe->dai_link->name);
1878
1879 /* Only start the BE if the FE is ready */
1880 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
1881 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
1882 return -EINVAL;
1883
1884 /* startup must always be called for new BEs */
1885 ret = soc_dpcm_be_dai_startup(fe, stream);
1886 if (ret < 0) {
1887 goto disconnect;
1888 return ret;
1889 }
1890
1891 /* keep going if FE state is > open */
1892 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
1893 return 0;
1894
1895 ret = soc_dpcm_be_dai_hw_params(fe, stream);
1896 if (ret < 0) {
1897 goto close;
1898 return ret;
1899 }
1900
1901 /* keep going if FE state is > hw_params */
1902 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
1903 return 0;
1904
1905
1906 ret = soc_dpcm_be_dai_prepare(fe, stream);
1907 if (ret < 0) {
1908 goto hw_free;
1909 return ret;
1910 }
1911
1912 /* run the stream event for each BE */
1913 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1914 soc_dpcm_dapm_stream_event(fe, stream,
1915 fe->cpu_dai->driver->playback.stream_name,
1916 SND_SOC_DAPM_STREAM_NOP);
1917 else
1918 soc_dpcm_dapm_stream_event(fe, stream,
1919 fe->cpu_dai->driver->capture.stream_name,
1920 SND_SOC_DAPM_STREAM_NOP);
1921
1922 /* keep going if FE state is > prepare */
1923 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
1924 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
1925 return 0;
1926
1927 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
1928 /* call trigger on the frontend - FE takes care of all BE triggers */
1929 dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd start\n",
1930 fe->dai_link->name);
1931
1932 ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
1933 if (ret < 0) {
1934 dev_err(fe->dev,"dpcm: bespoke trigger FE failed %d\n", ret);
1935 goto hw_free;
1936 }
1937 } else {
1938 dev_dbg(fe->dev, "dpcm: trigger FE %s cmd start\n",
1939 fe->dai_link->name);
1940
1941 ret = soc_dpcm_be_dai_trigger(fe, stream,
1942 SNDRV_PCM_TRIGGER_START);
1943 if (ret < 0) {
1944 dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
1945 goto hw_free;
1946 }
1947 }
1948
1949 return 0;
1950
1951hw_free:
1952 soc_dpcm_be_dai_hw_free(fe, stream);
1953close:
1954 soc_dpcm_be_dai_shutdown(fe, stream);
1955disconnect:
1956 /* disconnect any non started BEs */
1957 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
1958 struct snd_soc_pcm_runtime *be = dpcm_params->be;
1959 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1960 dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
1961 }
1962
1963 return ret;
1964}
1965
1966static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
1967{
1968 int ret;
1969
1970 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1971 ret = dpcm_run_update_startup(fe, stream);
1972 if (ret < 0)
1973 dev_err(fe->dev, "failed to startup some BEs\n");
1974 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1975
1976 return ret;
1977}
1978
1979static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
1980{
1981 int ret;
1982
1983 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1984 ret = dpcm_run_update_shutdown(fe, stream);
1985 if (ret < 0)
1986 dev_err(fe->dev, "failed to shutdown some BEs\n");
1987 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
1988
1989 return ret;
1990}
1991
1992/* called when any mixer updates change FE -> BE the stream */
1993int soc_dpcm_runtime_update(struct snd_soc_dapm_widget *widget)
1994{
1995 struct snd_soc_card *card;
1996 int i, ret = 0, old, new, paths;
1997
1998 if (widget->codec)
1999 card = widget->codec->card;
2000 else if (widget->platform)
2001 card = widget->platform->card;
2002 else
2003 return -EINVAL;
2004
2005 mutex_lock(&card->dpcm_mutex);
2006
2007 for (i = 0; i < card->num_rtd; i++) {
2008 struct snd_soc_dapm_widget_list *list;
2009 struct snd_soc_pcm_runtime *fe = &card->rtd[i];
2010
2011 /* make sure link is FE */
2012 if (!fe->dai_link->dynamic)
2013 continue;
2014
2015 /* only check active links */
2016 if (!fe->cpu_dai->active)
2017 continue;
2018
2019 /* DAPM sync will call this to update DSP paths */
2020 dev_dbg(fe->dev, "DPCM runtime update for FE %s\n", fe->dai_link->name);
2021
2022 /* skip if FE doesn't have playback capability */
2023 if (!fe->cpu_dai->driver->playback.channels_min)
2024 goto capture;
2025
2026 paths = fe_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
2027 if (paths < 0) {
SathishKumar Manief4feb32012-10-09 13:31:13 -07002028 pr_warn_ratelimited("%s no valid %s route from source to sink\n",
Steve Mucklef132c6c2012-06-06 18:30:57 -07002029 fe->dai_link->name, "playback");
Iliyan Malchev734dc212012-10-02 09:22:36 -07002030 WARN_ON(1);
Steve Mucklef132c6c2012-06-06 18:30:57 -07002031 ret = paths;
2032 goto out;
2033 }
2034
2035 /* update any new playback paths */
2036 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1);
2037 if (new) {
2038 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2039 fe_clear_pending(fe, SNDRV_PCM_STREAM_PLAYBACK);
2040 be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2041 }
2042
2043 /* update any old playback paths */
2044 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0);
2045 if (old) {
2046 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2047 fe_clear_pending(fe, SNDRV_PCM_STREAM_PLAYBACK);
2048 be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2049 }
2050
Banajit Goswamiebeaafc2012-08-19 23:09:58 -07002051 fe_path_put(&list);
2052
Steve Mucklef132c6c2012-06-06 18:30:57 -07002053capture:
2054 /* skip if FE doesn't have capture capability */
2055 if (!fe->cpu_dai->driver->capture.channels_min)
2056 continue;
2057
2058 paths = fe_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
2059 if (paths < 0) {
SathishKumar Manief4feb32012-10-09 13:31:13 -07002060 pr_warn_ratelimited("%s no valid %s route from source to sink\n",
Steve Mucklef132c6c2012-06-06 18:30:57 -07002061 fe->dai_link->name, "capture");
2062 ret = paths;
2063 goto out;
2064 }
2065
2066 /* update any new capture paths */
2067 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1);
2068 if (new) {
2069 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2070 fe_clear_pending(fe, SNDRV_PCM_STREAM_CAPTURE);
2071 be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2072 }
2073
2074 /* update any old capture paths */
2075 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0);
2076 if (old) {
2077 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2078 fe_clear_pending(fe, SNDRV_PCM_STREAM_CAPTURE);
2079 be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2080 }
2081
2082 fe_path_put(&list);
2083 }
2084
2085out:
2086 mutex_unlock(&card->dpcm_mutex);
2087 return ret;
2088}
2089
2090int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
2091{
2092 struct snd_soc_dpcm_params *dpcm_params;
2093
2094 list_for_each_entry(dpcm_params,
2095 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2096
2097 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2098 struct snd_soc_dai *dai = be->codec_dai;
2099 struct snd_soc_dai_driver *drv = dai->driver;
2100
2101 if (be->dai_link->ignore_suspend)
2102 continue;
2103
2104 dev_dbg(be->dev, "BE digital mute %s\n", be->dai_link->name);
2105
2106 if (drv->ops->digital_mute && dai->playback_active)
2107 drv->ops->digital_mute(dai, mute);
2108 }
2109
2110 return 0;
2111}
2112
2113int soc_dpcm_be_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe)
2114{
2115 struct snd_soc_dpcm_params *dpcm_params;
2116
2117 /* suspend for playback */
2118 list_for_each_entry(dpcm_params,
2119 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2120
2121 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2122 struct snd_soc_dai *dai = be->cpu_dai;
2123 struct snd_soc_dai_driver *drv = dai->driver;
2124
2125 if (be->dai_link->ignore_suspend)
2126 continue;
2127
2128 dev_dbg(be->dev, "pm: BE CPU DAI playback suspend %s\n",
2129 be->dai_link->name);
2130
2131 if (drv->suspend && !drv->ac97_control)
2132 drv->suspend(dai);
2133 }
2134
2135 /* suspend for capture */
2136 list_for_each_entry(dpcm_params,
2137 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2138
2139 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2140 struct snd_soc_dai *dai = be->cpu_dai;
2141 struct snd_soc_dai_driver *drv = dai->driver;
2142
2143 if (be->dai_link->ignore_suspend)
2144 continue;
2145
2146 dev_dbg(be->dev, "pm: BE CPU DAI capture suspend %s\n",
2147 be->dai_link->name);
2148
2149 if (drv->suspend && !drv->ac97_control)
2150 drv->suspend(dai);
2151 }
2152
2153 return 0;
2154}
2155
2156int soc_dpcm_be_ac97_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe)
2157{
2158 struct snd_soc_dpcm_params *dpcm_params;
2159
2160 /* suspend for playback */
2161 list_for_each_entry(dpcm_params,
2162 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2163
2164 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2165 struct snd_soc_dai *dai = be->cpu_dai;
2166 struct snd_soc_dai_driver *drv = dai->driver;
2167
2168 if (be->dai_link->ignore_suspend)
2169 continue;
2170
2171 dev_dbg(be->dev, "pm: BE CPU DAI playback suspend %s\n",
2172 be->dai_link->name);
2173
2174 if (drv->suspend && drv->ac97_control)
2175 drv->suspend(dai);
2176 }
2177
2178 /* suspend for capture */
2179 list_for_each_entry(dpcm_params,
2180 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2181
2182 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2183 struct snd_soc_dai *dai = be->cpu_dai;
2184 struct snd_soc_dai_driver *drv = dai->driver;
2185
2186 if (be->dai_link->ignore_suspend)
2187 continue;
2188
2189 dev_dbg(be->dev, "pm: BE CPU DAI capture suspend %s\n",
2190 be->dai_link->name);
2191
2192 if (drv->suspend && drv->ac97_control)
2193 drv->suspend(dai);
2194 }
2195
2196 return 0;
2197}
2198
2199int soc_dpcm_be_platform_suspend(struct snd_soc_pcm_runtime *fe)
2200{
2201 struct snd_soc_dpcm_params *dpcm_params;
2202
2203 /* suspend for playback */
2204 list_for_each_entry(dpcm_params,
2205 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2206
2207 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2208 struct snd_soc_platform *platform = be->platform;
2209 struct snd_soc_platform_driver *drv = platform->driver;
2210 struct snd_soc_dai *dai = be->cpu_dai;
2211
2212 if (be->dai_link->ignore_suspend)
2213 continue;
2214
2215 dev_dbg(be->dev, "pm: BE platform playback suspend %s\n",
2216 be->dai_link->name);
2217
2218 if (drv->suspend && !platform->suspended) {
2219 drv->suspend(dai);
2220 platform->suspended = 1;
2221 }
2222 }
2223
2224 /* suspend for capture */
2225 list_for_each_entry(dpcm_params,
2226 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2227
2228 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2229 struct snd_soc_platform *platform = be->platform;
2230 struct snd_soc_platform_driver *drv = platform->driver;
2231 struct snd_soc_dai *dai = be->cpu_dai;
2232
2233 if (be->dai_link->ignore_suspend)
2234 continue;
2235
2236 dev_dbg(be->dev, "pm: BE platform capture suspend %s\n",
2237 be->dai_link->name);
2238
2239 if (drv->suspend && !platform->suspended) {
2240 drv->suspend(dai);
2241 platform->suspended = 1;
2242 }
2243 }
2244 return 0;
2245}
2246
2247int soc_dpcm_fe_suspend(struct snd_soc_pcm_runtime *fe)
2248{
2249 struct snd_soc_dai *dai = fe->cpu_dai;
2250 struct snd_soc_dai_driver *dai_drv = dai->driver;
2251 struct snd_soc_platform *platform = fe->platform;
2252 struct snd_soc_platform_driver *plat_drv = platform->driver;
2253
2254 if (dai_drv->suspend && !dai_drv->ac97_control)
2255 dai_drv->suspend(dai);
2256
2257 if (plat_drv->suspend && !platform->suspended) {
2258 plat_drv->suspend(dai);
2259 platform->suspended = 1;
2260 }
2261
2262 soc_dpcm_be_cpu_dai_suspend(fe);
2263 soc_dpcm_be_platform_suspend(fe);
2264
2265 return 0;
2266}
2267
2268int soc_dpcm_be_cpu_dai_resume(struct snd_soc_pcm_runtime *fe)
2269{
2270 struct snd_soc_dpcm_params *dpcm_params;
2271
2272 /* resume for playback */
2273 list_for_each_entry(dpcm_params,
2274 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2275
2276 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2277 struct snd_soc_dai *dai = be->cpu_dai;
2278 struct snd_soc_dai_driver *drv = dai->driver;
2279
2280 if (be->dai_link->ignore_suspend)
2281 continue;
2282
2283 dev_dbg(be->dev, "pm: BE CPU DAI playback resume %s\n",
2284 be->dai_link->name);
2285
2286 if (drv->resume && !drv->ac97_control)
2287 drv->resume(dai);
2288 }
2289
2290 /* suspend for capture */
2291 list_for_each_entry(dpcm_params,
2292 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2293
2294 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2295 struct snd_soc_dai *dai = be->cpu_dai;
2296 struct snd_soc_dai_driver *drv = dai->driver;
2297
2298 if (be->dai_link->ignore_suspend)
2299 continue;
2300
2301 dev_dbg(be->dev, "pm: BE CPU DAI capture resume %s\n",
2302 be->dai_link->name);
2303
2304 if (drv->resume && !drv->ac97_control)
2305 drv->resume(dai);
2306 }
2307
2308 return 0;
2309}
2310
2311int soc_dpcm_be_ac97_cpu_dai_resume(struct snd_soc_pcm_runtime *fe)
2312{
2313 struct snd_soc_dpcm_params *dpcm_params;
2314
2315 /* resume for playback */
2316 list_for_each_entry(dpcm_params,
2317 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2318
2319 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2320 struct snd_soc_dai *dai = be->cpu_dai;
2321 struct snd_soc_dai_driver *drv = dai->driver;
2322
2323 if (be->dai_link->ignore_suspend)
2324 continue;
2325
2326 dev_dbg(be->dev, "pm: BE CPU DAI playback resume %s\n",
2327 be->dai_link->name);
2328
2329 if (drv->resume && drv->ac97_control)
2330 drv->resume(dai);
2331 }
2332
2333 /* suspend for capture */
2334 list_for_each_entry(dpcm_params,
2335 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2336
2337 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2338 struct snd_soc_dai *dai = be->cpu_dai;
2339 struct snd_soc_dai_driver *drv = dai->driver;
2340
2341 if (be->dai_link->ignore_suspend)
2342 continue;
2343
2344 dev_dbg(be->dev, "pm: BE CPU DAI capture resume %s\n",
2345 be->dai_link->name);
2346
2347 if (drv->resume && drv->ac97_control)
2348 drv->resume(dai);
2349 }
2350
2351 return 0;
2352}
2353
2354int soc_dpcm_be_platform_resume(struct snd_soc_pcm_runtime *fe)
2355{
2356 struct snd_soc_dpcm_params *dpcm_params;
2357
2358 /* resume for playback */
2359 list_for_each_entry(dpcm_params,
2360 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
2361
2362 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2363 struct snd_soc_platform *platform = be->platform;
2364 struct snd_soc_platform_driver *drv = platform->driver;
2365 struct snd_soc_dai *dai = be->cpu_dai;
2366
2367 if (be->dai_link->ignore_suspend)
2368 continue;
2369
2370 dev_dbg(be->dev, "pm: BE platform playback resume %s\n",
2371 be->dai_link->name);
2372
2373 if (drv->resume && platform->suspended) {
2374 drv->resume(dai);
2375 platform->suspended = 0;
2376 }
2377 }
2378
2379 /* resume for capture */
2380 list_for_each_entry(dpcm_params,
2381 &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
2382
2383 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2384 struct snd_soc_platform *platform = be->platform;
2385 struct snd_soc_platform_driver *drv = platform->driver;
2386 struct snd_soc_dai *dai = be->cpu_dai;
2387
2388 if (be->dai_link->ignore_suspend)
2389 continue;
2390
2391 dev_dbg(be->dev, "pm: BE platform capture resume %s\n",
2392 be->dai_link->name);
2393
2394 if (drv->resume && platform->suspended) {
2395 drv->resume(dai);
2396 platform->suspended = 0;
2397 }
2398 }
2399
2400 return 0;
2401}
2402
2403int soc_dpcm_fe_resume(struct snd_soc_pcm_runtime *fe)
2404{
2405 struct snd_soc_dai *dai = fe->cpu_dai;
2406 struct snd_soc_dai_driver *dai_drv = dai->driver;
2407 struct snd_soc_platform *platform = fe->platform;
2408 struct snd_soc_platform_driver *plat_drv = platform->driver;
2409
2410 soc_dpcm_be_cpu_dai_resume(fe);
2411 soc_dpcm_be_platform_resume(fe);
2412
2413 if (dai_drv->resume && !dai_drv->ac97_control)
2414 dai_drv->resume(dai);
2415
2416 if (plat_drv->resume && platform->suspended) {
2417 plat_drv->resume(dai);
2418 platform->suspended = 0;
2419 }
2420
2421 return 0;
2422}
2423
2424/* called when opening FE stream */
2425int soc_dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2426{
2427 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2428 struct snd_soc_dpcm_params *dpcm_params;
2429 struct snd_soc_dapm_widget_list *list;
2430 int ret;
2431 int stream = fe_substream->stream;
2432
2433 fe->dpcm[stream].runtime = fe_substream->runtime;
2434
2435 if (fe_path_get(fe, stream, &list) <= 0) {
SathishKumar Manief4feb32012-10-09 13:31:13 -07002436 pr_warn_ratelimited("asoc: %s no valid %s route from source to sink\n",
Steve Mucklef132c6c2012-06-06 18:30:57 -07002437 fe->dai_link->name, stream ? "capture" : "playback");
2438 return -EINVAL;
2439 }
2440
2441 /* calculate valid and active FE <-> BE dpcm_paramss */
2442 dpcm_process_paths(fe, stream, &list, 1);
2443
2444 ret = soc_dpcm_fe_dai_startup(fe_substream);
2445 if (ret < 0) {
2446 /* clean up all links */
2447 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
2448 dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
2449
2450 be_disconnect(fe, stream);
2451 fe->dpcm[stream].runtime = NULL;
2452 }
2453
2454 fe_clear_pending(fe, stream);
2455 fe_path_put(&list);
2456 return ret;
2457}
2458
2459/* called when closing FE stream */
2460int soc_dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
2461{
2462 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2463 struct snd_soc_dpcm_params *dpcm_params;
2464 int stream = fe_substream->stream, ret;
2465
2466 ret = soc_dpcm_fe_dai_shutdown(fe_substream);
2467
2468 /* mark FE's links ready to prune */
2469 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
2470 dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
2471
2472 be_disconnect(fe, stream);
2473
2474 fe->dpcm[stream].runtime = NULL;
2475
2476 return ret;
2477}
2478
Liam Girdwoodddee6272011-06-09 14:45:53 +01002479/* create a new pcm */
2480int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2481{
2482 struct snd_soc_codec *codec = rtd->codec;
2483 struct snd_soc_platform *platform = rtd->platform;
2484 struct snd_soc_dai *codec_dai = rtd->codec_dai;
2485 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002486 struct snd_pcm_substream *substream[2];
Liam Girdwoodddee6272011-06-09 14:45:53 +01002487 struct snd_pcm *pcm;
2488 char new_name[64];
2489 int ret = 0, playback = 0, capture = 0;
2490
Steve Mucklef132c6c2012-06-06 18:30:57 -07002491 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
2492 if (cpu_dai->driver->playback.channels_min)
2493 playback = 1;
2494 if (cpu_dai->driver->capture.channels_min)
2495 capture = 1;
2496 } else {
2497 if (codec_dai->driver->playback.channels_min)
2498 playback = 1;
2499 if (codec_dai->driver->capture.channels_min)
2500 capture = 1;
2501 }
Sangsu Parka5002312012-01-02 17:15:10 +09002502
Steve Mucklef132c6c2012-06-06 18:30:57 -07002503 /* create the PCM */
2504 if (rtd->dai_link->no_pcm) {
2505 snprintf(new_name, sizeof(new_name), "(%s)",
2506 rtd->dai_link->stream_name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002507
Steve Mucklef132c6c2012-06-06 18:30:57 -07002508 ret = snd_pcm_new_soc_be(rtd->card->snd_card, new_name, num,
2509 playback, capture, &pcm);
2510 } else {
2511 if (rtd->dai_link->dynamic)
2512 snprintf(new_name, sizeof(new_name), "%s (*)",
2513 rtd->dai_link->stream_name);
2514 else
2515 snprintf(new_name, sizeof(new_name), "%s %s-%d",
2516 rtd->dai_link->stream_name, codec_dai->name, num);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002517
Steve Mucklef132c6c2012-06-06 18:30:57 -07002518 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2519 capture, &pcm);
2520 }
Liam Girdwoodddee6272011-06-09 14:45:53 +01002521 if (ret < 0) {
2522 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
2523 return ret;
2524 }
Steve Mucklef132c6c2012-06-06 18:30:57 -07002525 dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num, new_name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002526
2527 rtd->pcm = pcm;
2528 pcm->private_data = rtd;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002529 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
2530
2531 substream[SNDRV_PCM_STREAM_PLAYBACK] =
2532 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
2533 substream[SNDRV_PCM_STREAM_CAPTURE] =
2534 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
2535
2536 if (rtd->dai_link->no_pcm) {
2537 if (playback)
2538 substream[SNDRV_PCM_STREAM_PLAYBACK]->private_data = rtd;
2539 if (capture)
2540 substream[SNDRV_PCM_STREAM_CAPTURE]->private_data = rtd;
2541 goto out;
2542 }
2543
2544 /* setup any hostless PCMs - i.e. no host IO is performed */
2545 if (rtd->dai_link->no_host_mode) {
2546 if (substream[SNDRV_PCM_STREAM_PLAYBACK]) {
2547 substream[SNDRV_PCM_STREAM_PLAYBACK]->hw_no_buffer = 1;
2548 snd_soc_set_runtime_hwparams(
2549 substream[SNDRV_PCM_STREAM_PLAYBACK],
2550 &no_host_hardware);
2551 }
2552 if (substream[SNDRV_PCM_STREAM_CAPTURE]) {
2553 substream[SNDRV_PCM_STREAM_CAPTURE]->hw_no_buffer = 1;
2554 snd_soc_set_runtime_hwparams(
2555 substream[SNDRV_PCM_STREAM_CAPTURE],
2556 &no_host_hardware);
2557 }
2558 }
2559
2560 /* ASoC PCM operations */
2561 if (rtd->dai_link->dynamic) {
2562 rtd->ops.open = soc_dpcm_fe_dai_open;
2563 rtd->ops.hw_params = soc_dpcm_fe_dai_hw_params;
2564 rtd->ops.prepare = soc_dpcm_fe_dai_prepare;
2565 rtd->ops.trigger = soc_dpcm_fe_dai_trigger;
2566 rtd->ops.hw_free = soc_dpcm_fe_dai_hw_free;
2567 rtd->ops.close = soc_dpcm_fe_dai_close;
2568 rtd->ops.pointer = soc_pcm_pointer;
2569 rtd->ops.ioctl = soc_pcm_ioctl;
2570 } else {
2571 rtd->ops.open = soc_pcm_open;
2572 rtd->ops.hw_params = soc_pcm_hw_params;
2573 rtd->ops.prepare = soc_pcm_prepare;
2574 rtd->ops.trigger = soc_pcm_trigger;
2575 rtd->ops.hw_free = soc_pcm_hw_free;
2576 rtd->ops.close = soc_pcm_close;
2577 rtd->ops.pointer = soc_pcm_pointer;
2578 rtd->ops.ioctl = soc_pcm_ioctl;
2579 }
2580
Liam Girdwoodddee6272011-06-09 14:45:53 +01002581 if (platform->driver->ops) {
Steve Mucklef132c6c2012-06-06 18:30:57 -07002582 rtd->ops.ack = platform->driver->ops->ack;
2583 rtd->ops.copy = platform->driver->ops->copy;
2584 rtd->ops.silence = platform->driver->ops->silence;
2585 rtd->ops.page = platform->driver->ops->page;
2586 rtd->ops.mmap = platform->driver->ops->mmap;
Santosh Mardif86a70e2012-10-09 10:40:17 +05302587 rtd->ops.restart = platform->driver->ops->restart;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002588 }
2589
2590 if (playback)
Steve Mucklef132c6c2012-06-06 18:30:57 -07002591 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002592
2593 if (capture)
Steve Mucklef132c6c2012-06-06 18:30:57 -07002594 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002595
2596 if (platform->driver->pcm_new) {
2597 ret = platform->driver->pcm_new(rtd);
2598 if (ret < 0) {
2599 pr_err("asoc: platform pcm constructor failed\n");
2600 return ret;
2601 }
2602 }
2603
2604 pcm->private_free = platform->driver->pcm_free;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002605out:
Liam Girdwoodddee6272011-06-09 14:45:53 +01002606 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
2607 cpu_dai->name);
2608 return ret;
2609}
Steve Mucklef132c6c2012-06-06 18:30:57 -07002610
2611#ifdef CONFIG_DEBUG_FS
2612static char *dpcm_state_string(enum snd_soc_dpcm_state state)
2613{
2614 switch (state) {
2615 case SND_SOC_DPCM_STATE_NEW:
2616 return "new";
2617 case SND_SOC_DPCM_STATE_OPEN:
2618 return "open";
2619 case SND_SOC_DPCM_STATE_HW_PARAMS:
2620 return "hw_params";
2621 case SND_SOC_DPCM_STATE_PREPARE:
2622 return "prepare";
2623 case SND_SOC_DPCM_STATE_START:
2624 return "start";
2625 case SND_SOC_DPCM_STATE_STOP:
2626 return "stop";
2627 case SND_SOC_DPCM_STATE_SUSPEND:
2628 return "suspend";
2629 case SND_SOC_DPCM_STATE_PAUSED:
2630 return "paused";
2631 case SND_SOC_DPCM_STATE_HW_FREE:
2632 return "hw_free";
2633 case SND_SOC_DPCM_STATE_CLOSE:
2634 return "close";
2635 }
2636
2637 return "unknown";
2638}
2639
2640static int soc_dpcm_state_open_file(struct inode *inode, struct file *file)
2641{
2642 file->private_data = inode->i_private;
2643 return 0;
2644}
2645
2646static ssize_t soc_dpcm_show_state(struct snd_soc_pcm_runtime *fe,
2647 int stream, char *buf, size_t size)
2648{
2649 struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
2650 struct snd_soc_dpcm_params *dpcm_params;
2651 ssize_t offset = 0;
2652
2653 /* FE state */
2654 offset += snprintf(buf + offset, size - offset,
2655 "[%s - %s]\n", fe->dai_link->name,
2656 stream ? "Capture" : "Playback");
2657
2658 offset += snprintf(buf + offset, size - offset, "State: %s\n",
2659 dpcm_state_string(fe->dpcm[stream].state));
2660
2661 if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2662 (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2663 offset += snprintf(buf + offset, size - offset,
2664 "Hardware Params: "
2665 "Format = %s, Channels = %d, Rate = %d\n",
2666 snd_pcm_format_name(params_format(params)),
2667 params_channels(params),
2668 params_rate(params));
2669
2670 /* BEs state */
2671 offset += snprintf(buf + offset, size - offset, "Backends:\n");
2672
2673 if (list_empty(&fe->dpcm[stream].be_clients)) {
2674 offset += snprintf(buf + offset, size - offset,
2675 " No active DSP links\n");
2676 goto out;
2677 }
2678
2679 list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
2680 struct snd_soc_pcm_runtime *be = dpcm_params->be;
2681
2682 offset += snprintf(buf + offset, size - offset,
2683 "- %s\n", be->dai_link->name);
2684
2685 offset += snprintf(buf + offset, size - offset,
2686 " State: %s\n",
2687 dpcm_state_string(fe->dpcm[stream].state));
2688
2689 if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2690 (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2691 offset += snprintf(buf + offset, size - offset,
2692 " Hardware Params: "
2693 "Format = %s, Channels = %d, Rate = %d\n",
2694 snd_pcm_format_name(params_format(params)),
2695 params_channels(params),
2696 params_rate(params));
2697 }
2698
2699out:
2700 return offset;
2701}
2702
2703static ssize_t soc_dpcm_state_read_file(struct file *file, char __user *user_buf,
2704 size_t count, loff_t *ppos)
2705{
2706 struct snd_soc_pcm_runtime *fe = file->private_data;
2707 ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
2708 char *buf;
2709
2710 buf = kmalloc(out_count, GFP_KERNEL);
2711 if (!buf)
2712 return -ENOMEM;
2713
2714 if (fe->cpu_dai->driver->playback.channels_min)
2715 offset += soc_dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK,
2716 buf + offset, out_count - offset);
2717
2718 if (fe->cpu_dai->driver->capture.channels_min)
2719 offset += soc_dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE,
2720 buf + offset, out_count - offset);
2721
2722 ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
2723
2724 kfree(buf);
2725
2726 return ret;
2727}
2728
2729static const struct file_operations soc_dpcm_state_fops = {
2730 .open = soc_dpcm_state_open_file,
2731 .read = soc_dpcm_state_read_file,
2732 .llseek = default_llseek,
2733};
2734
2735int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
2736{
2737 rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
2738 rtd->card->debugfs_card_root);
2739 if (!rtd->debugfs_dpcm_root) {
2740 dev_dbg(rtd->dev,
2741 "ASoC: Failed to create dpcm debugfs directory %s\n",
2742 rtd->dai_link->name);
2743 return -EINVAL;
2744 }
2745
2746 rtd->debugfs_dpcm_state = debugfs_create_file("state", 0644,
2747 rtd->debugfs_dpcm_root,
2748 rtd, &soc_dpcm_state_fops);
2749
2750 return 0;
2751}
2752#endif