blob: f11421f080650d14d9329ed968941be176fc6c07 [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>
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +020010 * Mark Brown <broonie@opensource.wolfsonmicro.com>
Liam Girdwoodddee6272011-06-09 14:45:53 +010011 *
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>
Nicolin Chen988e8cc2013-11-04 14:57:31 +080022#include <linux/pinctrl/consumer.h>
Mark Brownd6652ef2011-12-03 20:14:31 +000023#include <linux/pm_runtime.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010024#include <linux/slab.h>
25#include <linux/workqueue.h>
Liam Girdwood01d75842012-04-25 12:12:49 +010026#include <linux/export.h>
Liam Girdwoodf86dcef2012-04-25 12:12:50 +010027#include <linux/debugfs.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010028#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/soc.h>
Liam Girdwood01d75842012-04-25 12:12:49 +010032#include <sound/soc-dpcm.h>
Liam Girdwoodddee6272011-06-09 14:45:53 +010033#include <sound/initval.h>
34
Liam Girdwood01d75842012-04-25 12:12:49 +010035#define DPCM_MAX_BE_USERS 8
36
Ricard Wanderlofcde79032015-08-24 14:16:51 +020037/*
38 * snd_soc_dai_stream_valid() - check if a DAI supports the given stream
39 *
40 * Returns true if the DAI supports the indicated stream type.
41 */
42static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream)
43{
44 struct snd_soc_pcm_stream *codec_stream;
45
46 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
47 codec_stream = &dai->driver->playback;
48 else
49 codec_stream = &dai->driver->capture;
50
51 /* If the codec specifies any rate at all, it supports the stream. */
52 return codec_stream->rates;
53}
54
Lars-Peter Clausen90996f42013-05-14 11:05:30 +020055/**
Lars-Peter Clausen24894b72014-03-05 13:17:43 +010056 * snd_soc_runtime_activate() - Increment active count for PCM runtime components
57 * @rtd: ASoC PCM runtime that is activated
58 * @stream: Direction of the PCM stream
59 *
60 * Increments the active count for all the DAIs and components attached to a PCM
61 * runtime. Should typically be called when a stream is opened.
62 *
63 * Must be called with the rtd->pcm_mutex being held
64 */
65void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
66{
67 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +020068 int i;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +010069
70 lockdep_assert_held(&rtd->pcm_mutex);
71
72 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
73 cpu_dai->playback_active++;
Benoit Cousson2e5894d2014-07-08 23:19:35 +020074 for (i = 0; i < rtd->num_codecs; i++)
75 rtd->codec_dais[i]->playback_active++;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +010076 } else {
77 cpu_dai->capture_active++;
Benoit Cousson2e5894d2014-07-08 23:19:35 +020078 for (i = 0; i < rtd->num_codecs; i++)
79 rtd->codec_dais[i]->capture_active++;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +010080 }
81
82 cpu_dai->active++;
Lars-Peter Clausencdde4cc2014-03-05 13:17:47 +010083 cpu_dai->component->active++;
Benoit Cousson2e5894d2014-07-08 23:19:35 +020084 for (i = 0; i < rtd->num_codecs; i++) {
85 rtd->codec_dais[i]->active++;
86 rtd->codec_dais[i]->component->active++;
87 }
Lars-Peter Clausen24894b72014-03-05 13:17:43 +010088}
89
90/**
91 * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components
92 * @rtd: ASoC PCM runtime that is deactivated
93 * @stream: Direction of the PCM stream
94 *
95 * Decrements the active count for all the DAIs and components attached to a PCM
96 * runtime. Should typically be called when a stream is closed.
97 *
98 * Must be called with the rtd->pcm_mutex being held
99 */
100void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
101{
102 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200103 int i;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100104
105 lockdep_assert_held(&rtd->pcm_mutex);
106
107 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
108 cpu_dai->playback_active--;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200109 for (i = 0; i < rtd->num_codecs; i++)
110 rtd->codec_dais[i]->playback_active--;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100111 } else {
112 cpu_dai->capture_active--;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200113 for (i = 0; i < rtd->num_codecs; i++)
114 rtd->codec_dais[i]->capture_active--;
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100115 }
116
117 cpu_dai->active--;
Lars-Peter Clausencdde4cc2014-03-05 13:17:47 +0100118 cpu_dai->component->active--;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200119 for (i = 0; i < rtd->num_codecs; i++) {
120 rtd->codec_dais[i]->component->active--;
121 rtd->codec_dais[i]->active--;
122 }
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100123}
124
125/**
Lars-Peter Clausen208a1582014-03-05 13:17:42 +0100126 * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
127 * @rtd: The ASoC PCM runtime that should be checked.
128 *
129 * This function checks whether the power down delay should be ignored for a
130 * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
131 * been configured to ignore the delay, or if none of the components benefits
132 * from having the delay.
133 */
134bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
135{
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200136 int i;
137 bool ignore = true;
138
Lars-Peter Clausen208a1582014-03-05 13:17:42 +0100139 if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
140 return true;
141
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200142 for (i = 0; i < rtd->num_codecs; i++)
143 ignore &= rtd->codec_dais[i]->component->ignore_pmdown_time;
144
145 return rtd->cpu_dai->component->ignore_pmdown_time && ignore;
Lars-Peter Clausen208a1582014-03-05 13:17:42 +0100146}
147
148/**
Lars-Peter Clausen90996f42013-05-14 11:05:30 +0200149 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
150 * @substream: the pcm substream
151 * @hw: the hardware parameters
152 *
153 * Sets the substream runtime hardware parameters.
154 */
155int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
156 const struct snd_pcm_hardware *hw)
157{
158 struct snd_pcm_runtime *runtime = substream->runtime;
159 runtime->hw.info = hw->info;
160 runtime->hw.formats = hw->formats;
161 runtime->hw.period_bytes_min = hw->period_bytes_min;
162 runtime->hw.period_bytes_max = hw->period_bytes_max;
163 runtime->hw.periods_min = hw->periods_min;
164 runtime->hw.periods_max = hw->periods_max;
165 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
166 runtime->hw.fifo_size = hw->fifo_size;
167 return 0;
168}
169EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
170
Liam Girdwood01d75842012-04-25 12:12:49 +0100171/* DPCM stream event, send event to FE and all active BEs. */
Liam Girdwood23607022014-01-17 17:03:55 +0000172int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
Liam Girdwood01d75842012-04-25 12:12:49 +0100173 int event)
174{
175 struct snd_soc_dpcm *dpcm;
176
177 list_for_each_entry(dpcm, &fe->dpcm[dir].be_clients, list_be) {
178
179 struct snd_soc_pcm_runtime *be = dpcm->be;
180
Liam Girdwood103d84a2012-11-19 14:39:15 +0000181 dev_dbg(be->dev, "ASoC: BE %s event %d dir %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +0100182 be->dai_link->name, event, dir);
183
Banajit Goswamib1cd2e32017-07-14 23:15:05 -0700184 if ((event == SND_SOC_DAPM_STREAM_STOP) &&
185 (be->dpcm[dir].users >= 1))
186 continue;
187
Liam Girdwood01d75842012-04-25 12:12:49 +0100188 snd_soc_dapm_stream_event(be, dir, event);
189 }
190
191 snd_soc_dapm_stream_event(fe, dir, event);
192
193 return 0;
194}
195
Dong Aisheng17841022011-08-29 17:15:14 +0800196static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
197 struct snd_soc_dai *soc_dai)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100198{
199 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100200 int ret;
201
Nicolin Chen3635bf02013-11-13 18:56:24 +0800202 if (soc_dai->rate && (soc_dai->driver->symmetric_rates ||
203 rtd->dai_link->symmetric_rates)) {
204 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %dHz rate\n",
205 soc_dai->rate);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100206
Lars-Peter Clausen4dcdd432015-10-18 15:39:28 +0200207 ret = snd_pcm_hw_constraint_single(substream->runtime,
Nicolin Chen3635bf02013-11-13 18:56:24 +0800208 SNDRV_PCM_HW_PARAM_RATE,
Lars-Peter Clausen4dcdd432015-10-18 15:39:28 +0200209 soc_dai->rate);
Nicolin Chen3635bf02013-11-13 18:56:24 +0800210 if (ret < 0) {
211 dev_err(soc_dai->dev,
212 "ASoC: Unable to apply rate constraint: %d\n",
213 ret);
214 return ret;
215 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100216 }
217
Nicolin Chen3635bf02013-11-13 18:56:24 +0800218 if (soc_dai->channels && (soc_dai->driver->symmetric_channels ||
219 rtd->dai_link->symmetric_channels)) {
220 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d channel(s)\n",
221 soc_dai->channels);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100222
Lars-Peter Clausen4dcdd432015-10-18 15:39:28 +0200223 ret = snd_pcm_hw_constraint_single(substream->runtime,
Nicolin Chen3635bf02013-11-13 18:56:24 +0800224 SNDRV_PCM_HW_PARAM_CHANNELS,
Nicolin Chen3635bf02013-11-13 18:56:24 +0800225 soc_dai->channels);
226 if (ret < 0) {
227 dev_err(soc_dai->dev,
228 "ASoC: Unable to apply channel symmetry constraint: %d\n",
229 ret);
230 return ret;
231 }
232 }
233
234 if (soc_dai->sample_bits && (soc_dai->driver->symmetric_samplebits ||
235 rtd->dai_link->symmetric_samplebits)) {
236 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d sample bits\n",
237 soc_dai->sample_bits);
238
Lars-Peter Clausen4dcdd432015-10-18 15:39:28 +0200239 ret = snd_pcm_hw_constraint_single(substream->runtime,
Nicolin Chen3635bf02013-11-13 18:56:24 +0800240 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
Nicolin Chen3635bf02013-11-13 18:56:24 +0800241 soc_dai->sample_bits);
242 if (ret < 0) {
243 dev_err(soc_dai->dev,
244 "ASoC: Unable to apply sample bits symmetry constraint: %d\n",
245 ret);
246 return ret;
247 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100248 }
249
250 return 0;
251}
252
Nicolin Chen3635bf02013-11-13 18:56:24 +0800253static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
254 struct snd_pcm_hw_params *params)
255{
256 struct snd_soc_pcm_runtime *rtd = substream->private_data;
257 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200258 unsigned int rate, channels, sample_bits, symmetry, i;
Nicolin Chen3635bf02013-11-13 18:56:24 +0800259
260 rate = params_rate(params);
261 channels = params_channels(params);
262 sample_bits = snd_pcm_format_physical_width(params_format(params));
263
264 /* reject unmatched parameters when applying symmetry */
265 symmetry = cpu_dai->driver->symmetric_rates ||
Nicolin Chen3635bf02013-11-13 18:56:24 +0800266 rtd->dai_link->symmetric_rates;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200267
268 for (i = 0; i < rtd->num_codecs; i++)
269 symmetry |= rtd->codec_dais[i]->driver->symmetric_rates;
270
Nicolin Chen3635bf02013-11-13 18:56:24 +0800271 if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) {
272 dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
273 cpu_dai->rate, rate);
274 return -EINVAL;
275 }
276
277 symmetry = cpu_dai->driver->symmetric_channels ||
Nicolin Chen3635bf02013-11-13 18:56:24 +0800278 rtd->dai_link->symmetric_channels;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200279
280 for (i = 0; i < rtd->num_codecs; i++)
281 symmetry |= rtd->codec_dais[i]->driver->symmetric_channels;
282
Nicolin Chen3635bf02013-11-13 18:56:24 +0800283 if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) {
284 dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
285 cpu_dai->channels, channels);
286 return -EINVAL;
287 }
288
289 symmetry = cpu_dai->driver->symmetric_samplebits ||
Nicolin Chen3635bf02013-11-13 18:56:24 +0800290 rtd->dai_link->symmetric_samplebits;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200291
292 for (i = 0; i < rtd->num_codecs; i++)
293 symmetry |= rtd->codec_dais[i]->driver->symmetric_samplebits;
294
Nicolin Chen3635bf02013-11-13 18:56:24 +0800295 if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) {
296 dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
297 cpu_dai->sample_bits, sample_bits);
298 return -EINVAL;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100299 }
300
301 return 0;
302}
303
Lars-Peter Clausen62e5f672013-11-30 17:38:58 +0100304static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream)
305{
306 struct snd_soc_pcm_runtime *rtd = substream->private_data;
307 struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver;
Lars-Peter Clausen62e5f672013-11-30 17:38:58 +0100308 struct snd_soc_dai_link *link = rtd->dai_link;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200309 unsigned int symmetry, i;
Lars-Peter Clausen62e5f672013-11-30 17:38:58 +0100310
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200311 symmetry = cpu_driver->symmetric_rates || link->symmetric_rates ||
312 cpu_driver->symmetric_channels || link->symmetric_channels ||
313 cpu_driver->symmetric_samplebits || link->symmetric_samplebits;
314
315 for (i = 0; i < rtd->num_codecs; i++)
316 symmetry = symmetry ||
317 rtd->codec_dais[i]->driver->symmetric_rates ||
318 rtd->codec_dais[i]->driver->symmetric_channels ||
319 rtd->codec_dais[i]->driver->symmetric_samplebits;
320
321 return symmetry;
Lars-Peter Clausen62e5f672013-11-30 17:38:58 +0100322}
323
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200324static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits)
Mark Brown58ba9b22012-01-16 18:38:51 +0000325{
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200326 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Takashi Iwaic6068d32014-12-31 17:10:34 +0100327 int ret;
Mark Brown58ba9b22012-01-16 18:38:51 +0000328
329 if (!bits)
330 return;
331
Lars-Peter Clausen0e2a3752014-12-29 18:43:38 +0100332 ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 0, bits);
333 if (ret != 0)
334 dev_warn(rtd->dev, "ASoC: Failed to set MSB %d: %d\n",
335 bits, ret);
Mark Brown58ba9b22012-01-16 18:38:51 +0000336}
337
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200338static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
Lars-Peter Clausenbd477c32013-05-14 11:05:31 +0200339{
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200340 struct snd_soc_pcm_runtime *rtd = substream->private_data;
341 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200342 struct snd_soc_dai *codec_dai;
343 int i;
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200344 unsigned int bits = 0, cpu_bits;
345
346 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200347 for (i = 0; i < rtd->num_codecs; i++) {
348 codec_dai = rtd->codec_dais[i];
349 if (codec_dai->driver->playback.sig_bits == 0) {
350 bits = 0;
351 break;
352 }
353 bits = max(codec_dai->driver->playback.sig_bits, bits);
354 }
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200355 cpu_bits = cpu_dai->driver->playback.sig_bits;
356 } else {
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200357 for (i = 0; i < rtd->num_codecs; i++) {
358 codec_dai = rtd->codec_dais[i];
Daniel Mack5e63dfc2014-10-07 14:33:46 +0200359 if (codec_dai->driver->capture.sig_bits == 0) {
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200360 bits = 0;
361 break;
362 }
363 bits = max(codec_dai->driver->capture.sig_bits, bits);
364 }
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200365 cpu_bits = cpu_dai->driver->capture.sig_bits;
366 }
367
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200368 soc_pcm_set_msb(substream, bits);
369 soc_pcm_set_msb(substream, cpu_bits);
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200370}
371
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200372static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
Lars-Peter Clausenbd477c32013-05-14 11:05:31 +0200373{
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200374 struct snd_pcm_runtime *runtime = substream->runtime;
Lars-Peter Clausen78e45c92013-11-27 09:58:18 +0100375 struct snd_pcm_hardware *hw = &runtime->hw;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200376 struct snd_soc_pcm_runtime *rtd = substream->private_data;
377 struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver;
378 struct snd_soc_dai_driver *codec_dai_drv;
379 struct snd_soc_pcm_stream *codec_stream;
380 struct snd_soc_pcm_stream *cpu_stream;
381 unsigned int chan_min = 0, chan_max = UINT_MAX;
382 unsigned int rate_min = 0, rate_max = UINT_MAX;
383 unsigned int rates = UINT_MAX;
384 u64 formats = ULLONG_MAX;
385 int i;
Lars-Peter Clausen78e45c92013-11-27 09:58:18 +0100386
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200387 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
388 cpu_stream = &cpu_dai_drv->playback;
Lars-Peter Clausen16d7ea92014-01-06 14:19:16 +0100389 else
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200390 cpu_stream = &cpu_dai_drv->capture;
Lars-Peter Clausen78e45c92013-11-27 09:58:18 +0100391
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200392 /* first calculate min/max only for CODECs in the DAI link */
393 for (i = 0; i < rtd->num_codecs; i++) {
Ricard Wanderlofcde79032015-08-24 14:16:51 +0200394
395 /*
396 * Skip CODECs which don't support the current stream type.
397 * Otherwise, since the rate, channel, and format values will
398 * zero in that case, we would have no usable settings left,
399 * causing the resulting setup to fail.
400 * At least one CODEC should match, otherwise we should have
401 * bailed out on a higher level, since there would be no
402 * CODEC to support the transfer direction in that case.
403 */
404 if (!snd_soc_dai_stream_valid(rtd->codec_dais[i],
405 substream->stream))
406 continue;
407
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200408 codec_dai_drv = rtd->codec_dais[i]->driver;
409 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
410 codec_stream = &codec_dai_drv->playback;
411 else
412 codec_stream = &codec_dai_drv->capture;
413 chan_min = max(chan_min, codec_stream->channels_min);
414 chan_max = min(chan_max, codec_stream->channels_max);
415 rate_min = max(rate_min, codec_stream->rate_min);
416 rate_max = min_not_zero(rate_max, codec_stream->rate_max);
417 formats &= codec_stream->formats;
418 rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates);
419 }
420
421 /*
422 * chan min/max cannot be enforced if there are multiple CODEC DAIs
423 * connected to a single CPU DAI, use CPU DAI's directly and let
424 * channel allocation be fixed up later
425 */
426 if (rtd->num_codecs > 1) {
427 chan_min = cpu_stream->channels_min;
428 chan_max = cpu_stream->channels_max;
429 }
430
431 hw->channels_min = max(chan_min, cpu_stream->channels_min);
432 hw->channels_max = min(chan_max, cpu_stream->channels_max);
433 if (hw->formats)
434 hw->formats &= formats & cpu_stream->formats;
435 else
436 hw->formats = formats & cpu_stream->formats;
437 hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates);
Lars-Peter Clausen78e45c92013-11-27 09:58:18 +0100438
439 snd_pcm_limit_hw_rates(runtime);
440
441 hw->rate_min = max(hw->rate_min, cpu_stream->rate_min);
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200442 hw->rate_min = max(hw->rate_min, rate_min);
Lars-Peter Clausen78e45c92013-11-27 09:58:18 +0100443 hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max);
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200444 hw->rate_max = min_not_zero(hw->rate_max, rate_max);
Lars-Peter Clausenbd477c32013-05-14 11:05:31 +0200445}
446
Mark Brown58ba9b22012-01-16 18:38:51 +0000447/*
Liam Girdwoodddee6272011-06-09 14:45:53 +0100448 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
449 * then initialized and any private data can be allocated. This also calls
450 * startup for the cpu DAI, platform, machine and codec DAI.
451 */
452static int soc_pcm_open(struct snd_pcm_substream *substream)
453{
454 struct snd_soc_pcm_runtime *rtd = substream->private_data;
455 struct snd_pcm_runtime *runtime = substream->runtime;
456 struct snd_soc_platform *platform = rtd->platform;
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000457 struct snd_soc_component *component;
458 struct snd_soc_rtdcom_list *rtdcom;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100459 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200460 struct snd_soc_dai *codec_dai;
461 const char *codec_dai_name = "multicodec";
462 int i, ret = 0;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100463
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800464 pinctrl_pm_select_default_state(cpu_dai->dev);
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200465 for (i = 0; i < rtd->num_codecs; i++)
466 pinctrl_pm_select_default_state(rtd->codec_dais[i]->dev);
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000467
468 for_each_rtdcom(rtd, rtdcom) {
469 component = rtdcom->component;
470
471 pm_runtime_get_sync(component->dev);
472 }
Mark Brownd6652ef2011-12-03 20:14:31 +0000473
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100474 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100475
476 /* startup the audio subsystem */
Mark Brownc5914b02013-10-30 17:47:39 -0700477 if (cpu_dai->driver->ops && cpu_dai->driver->ops->startup) {
Liam Girdwoodddee6272011-06-09 14:45:53 +0100478 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
479 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000480 dev_err(cpu_dai->dev, "ASoC: can't open interface"
481 " %s: %d\n", cpu_dai->name, ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100482 goto out;
483 }
484 }
485
486 if (platform->driver->ops && platform->driver->ops->open) {
487 ret = platform->driver->ops->open(substream);
488 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000489 dev_err(platform->dev, "ASoC: can't open platform"
Lars-Peter Clausenf4333202014-06-16 18:13:02 +0200490 " %s: %d\n", platform->component.name, ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100491 goto platform_err;
492 }
493 }
494
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200495 for (i = 0; i < rtd->num_codecs; i++) {
496 codec_dai = rtd->codec_dais[i];
497 if (codec_dai->driver->ops && codec_dai->driver->ops->startup) {
498 ret = codec_dai->driver->ops->startup(substream,
499 codec_dai);
500 if (ret < 0) {
501 dev_err(codec_dai->dev,
502 "ASoC: can't open codec %s: %d\n",
503 codec_dai->name, ret);
504 goto codec_dai_err;
505 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100506 }
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200507
508 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
509 codec_dai->tx_mask = 0;
510 else
511 codec_dai->rx_mask = 0;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100512 }
513
514 if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
515 ret = rtd->dai_link->ops->startup(substream);
516 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000517 pr_err("ASoC: %s startup failed: %d\n",
Mark Brown25bfe662012-02-01 21:30:32 +0000518 rtd->dai_link->name, ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100519 goto machine_err;
520 }
521 }
522
Liam Girdwood01d75842012-04-25 12:12:49 +0100523 /* Dynamic PCM DAI links compat checks use dynamic capabilities */
524 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
525 goto dynamic;
526
Liam Girdwoodddee6272011-06-09 14:45:53 +0100527 /* Check that the codec and cpu DAIs are compatible */
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200528 soc_pcm_init_runtime_hw(substream);
529
530 if (rtd->num_codecs == 1)
531 codec_dai_name = rtd->codec_dai->name;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100532
Lars-Peter Clausen62e5f672013-11-30 17:38:58 +0100533 if (soc_pcm_has_symmetry(substream))
534 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
535
Liam Girdwoodddee6272011-06-09 14:45:53 +0100536 ret = -EINVAL;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100537 if (!runtime->hw.rates) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000538 printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200539 codec_dai_name, cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100540 goto config_err;
541 }
542 if (!runtime->hw.formats) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000543 printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200544 codec_dai_name, cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100545 goto config_err;
546 }
547 if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
548 runtime->hw.channels_min > runtime->hw.channels_max) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000549 printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200550 codec_dai_name, cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100551 goto config_err;
552 }
553
Benoit Coussonc8dd1fe2014-07-01 09:47:55 +0200554 soc_pcm_apply_msb(substream);
Mark Brown58ba9b22012-01-16 18:38:51 +0000555
Liam Girdwoodddee6272011-06-09 14:45:53 +0100556 /* Symmetry only applies if we've already got an active stream. */
Dong Aisheng17841022011-08-29 17:15:14 +0800557 if (cpu_dai->active) {
558 ret = soc_pcm_apply_symmetry(substream, cpu_dai);
559 if (ret != 0)
560 goto config_err;
561 }
562
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200563 for (i = 0; i < rtd->num_codecs; i++) {
564 if (rtd->codec_dais[i]->active) {
565 ret = soc_pcm_apply_symmetry(substream,
566 rtd->codec_dais[i]);
567 if (ret != 0)
568 goto config_err;
569 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100570 }
571
Liam Girdwood103d84a2012-11-19 14:39:15 +0000572 pr_debug("ASoC: %s <-> %s info:\n",
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200573 codec_dai_name, cpu_dai->name);
Liam Girdwood103d84a2012-11-19 14:39:15 +0000574 pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
575 pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
Liam Girdwoodddee6272011-06-09 14:45:53 +0100576 runtime->hw.channels_max);
Liam Girdwood103d84a2012-11-19 14:39:15 +0000577 pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min,
Liam Girdwoodddee6272011-06-09 14:45:53 +0100578 runtime->hw.rate_max);
579
Liam Girdwood01d75842012-04-25 12:12:49 +0100580dynamic:
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100581
582 snd_soc_runtime_activate(rtd, substream->stream);
583
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100584 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100585 return 0;
586
587config_err:
588 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
589 rtd->dai_link->ops->shutdown(substream);
590
591machine_err:
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200592 i = rtd->num_codecs;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100593
594codec_dai_err:
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200595 while (--i >= 0) {
596 codec_dai = rtd->codec_dais[i];
597 if (codec_dai->driver->ops->shutdown)
598 codec_dai->driver->ops->shutdown(substream, codec_dai);
599 }
600
Liam Girdwoodddee6272011-06-09 14:45:53 +0100601 if (platform->driver->ops && platform->driver->ops->close)
602 platform->driver->ops->close(substream);
603
604platform_err:
605 if (cpu_dai->driver->ops->shutdown)
606 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
607out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100608 mutex_unlock(&rtd->pcm_mutex);
Mark Brownd6652ef2011-12-03 20:14:31 +0000609
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000610 for_each_rtdcom(rtd, rtdcom) {
611 component = rtdcom->component;
612
613 pm_runtime_mark_last_busy(component->dev);
614 pm_runtime_put_autosuspend(component->dev);
Sanyog Kale3f809782016-01-05 17:14:49 +0530615 }
616
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200617 for (i = 0; i < rtd->num_codecs; i++) {
618 if (!rtd->codec_dais[i]->active)
619 pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
620 }
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800621 if (!cpu_dai->active)
622 pinctrl_pm_select_sleep_state(cpu_dai->dev);
Mark Brownd6652ef2011-12-03 20:14:31 +0000623
Liam Girdwoodddee6272011-06-09 14:45:53 +0100624 return ret;
625}
626
627/*
628 * Power down the audio subsystem pmdown_time msecs after close is called.
629 * This is to ensure there are no pops or clicks in between any music tracks
630 * due to DAPM power cycling.
631 */
632static void close_delayed_work(struct work_struct *work)
633{
634 struct snd_soc_pcm_runtime *rtd =
635 container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200636 struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
Liam Girdwoodddee6272011-06-09 14:45:53 +0100637
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100638 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100639
Liam Girdwood103d84a2012-11-19 14:39:15 +0000640 dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n",
Liam Girdwoodddee6272011-06-09 14:45:53 +0100641 codec_dai->driver->playback.stream_name,
642 codec_dai->playback_active ? "active" : "inactive",
Misael Lopez Cruz9bffb1f2012-12-13 12:23:05 -0600643 rtd->pop_wait ? "yes" : "no");
Liam Girdwoodddee6272011-06-09 14:45:53 +0100644
645 /* are we waiting on this codec DAI stream */
Misael Lopez Cruz9bffb1f2012-12-13 12:23:05 -0600646 if (rtd->pop_wait == 1) {
647 rtd->pop_wait = 0;
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800648 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
Liam Girdwoodd9b09512012-03-07 16:32:59 +0000649 SND_SOC_DAPM_STREAM_STOP);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100650 }
651
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100652 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100653}
654
655/*
656 * Called by ALSA when a PCM substream is closed. Private data can be
657 * freed here. The cpu DAI, codec DAI, machine and platform are also
658 * shutdown.
659 */
Liam Girdwood91d5e6b2011-06-09 17:04:59 +0100660static int soc_pcm_close(struct snd_pcm_substream *substream)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100661{
662 struct snd_soc_pcm_runtime *rtd = substream->private_data;
663 struct snd_soc_platform *platform = rtd->platform;
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000664 struct snd_soc_component *component;
665 struct snd_soc_rtdcom_list *rtdcom;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100666 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200667 struct snd_soc_dai *codec_dai;
668 int i;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100669
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100670 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100671
Lars-Peter Clausen24894b72014-03-05 13:17:43 +0100672 snd_soc_runtime_deactivate(rtd, substream->stream);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100673
Dong Aisheng17841022011-08-29 17:15:14 +0800674 /* clear the corresponding DAIs rate when inactive */
675 if (!cpu_dai->active)
676 cpu_dai->rate = 0;
677
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200678 for (i = 0; i < rtd->num_codecs; i++) {
679 codec_dai = rtd->codec_dais[i];
680 if (!codec_dai->active)
681 codec_dai->rate = 0;
682 }
Sascha Hauer25b76792011-08-17 09:20:01 +0200683
Ramesh Babuae116012014-10-15 12:34:59 +0530684 snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream);
685
Liam Girdwoodddee6272011-06-09 14:45:53 +0100686 if (cpu_dai->driver->ops->shutdown)
687 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
688
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200689 for (i = 0; i < rtd->num_codecs; i++) {
690 codec_dai = rtd->codec_dais[i];
691 if (codec_dai->driver->ops->shutdown)
692 codec_dai->driver->ops->shutdown(substream, codec_dai);
693 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100694
695 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
696 rtd->dai_link->ops->shutdown(substream);
697
698 if (platform->driver->ops && platform->driver->ops->close)
699 platform->driver->ops->close(substream);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100700
701 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Lars-Peter Clausen208a1582014-03-05 13:17:42 +0100702 if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
Peter Ujfalusi1d69c5c2011-10-14 14:43:33 +0300703 /* powered down playback stream now */
704 snd_soc_dapm_stream_event(rtd,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800705 SNDRV_PCM_STREAM_PLAYBACK,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800706 SND_SOC_DAPM_STREAM_STOP);
Peter Ujfalusi1d69c5c2011-10-14 14:43:33 +0300707 } else {
708 /* start delayed pop wq here for playback streams */
Misael Lopez Cruz9bffb1f2012-12-13 12:23:05 -0600709 rtd->pop_wait = 1;
Mark Brownd4e1a732013-07-18 11:52:17 +0100710 queue_delayed_work(system_power_efficient_wq,
711 &rtd->delayed_work,
712 msecs_to_jiffies(rtd->pmdown_time));
Peter Ujfalusi1d69c5c2011-10-14 14:43:33 +0300713 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100714 } else {
715 /* capture streams can be powered down now */
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800716 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
Liam Girdwoodd9b09512012-03-07 16:32:59 +0000717 SND_SOC_DAPM_STREAM_STOP);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100718 }
719
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100720 mutex_unlock(&rtd->pcm_mutex);
Mark Brownd6652ef2011-12-03 20:14:31 +0000721
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000722 for_each_rtdcom(rtd, rtdcom) {
723 component = rtdcom->component;
Sanyog Kale3f809782016-01-05 17:14:49 +0530724
Kuninori Morimoto90be7112017-08-08 06:18:10 +0000725 pm_runtime_mark_last_busy(component->dev);
726 pm_runtime_put_autosuspend(component->dev);
Sanyog Kale3f809782016-01-05 17:14:49 +0530727 }
728
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200729 for (i = 0; i < rtd->num_codecs; i++) {
730 if (!rtd->codec_dais[i]->active)
731 pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
732 }
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800733 if (!cpu_dai->active)
734 pinctrl_pm_select_sleep_state(cpu_dai->dev);
Mark Brownd6652ef2011-12-03 20:14:31 +0000735
Liam Girdwoodddee6272011-06-09 14:45:53 +0100736 return 0;
737}
738
739/*
740 * Called by ALSA when the PCM substream is prepared, can set format, sample
741 * rate, etc. This function is non atomic and can be called multiple times,
742 * it can refer to the runtime info.
743 */
744static int soc_pcm_prepare(struct snd_pcm_substream *substream)
745{
746 struct snd_soc_pcm_runtime *rtd = substream->private_data;
747 struct snd_soc_platform *platform = rtd->platform;
748 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200749 struct snd_soc_dai *codec_dai;
750 int i, ret = 0;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100751
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100752 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100753
754 if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
755 ret = rtd->dai_link->ops->prepare(substream);
756 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000757 dev_err(rtd->card->dev, "ASoC: machine prepare error:"
758 " %d\n", ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100759 goto out;
760 }
761 }
762
763 if (platform->driver->ops && platform->driver->ops->prepare) {
764 ret = platform->driver->ops->prepare(substream);
765 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000766 dev_err(platform->dev, "ASoC: platform prepare error:"
767 " %d\n", ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100768 goto out;
769 }
770 }
771
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200772 for (i = 0; i < rtd->num_codecs; i++) {
773 codec_dai = rtd->codec_dais[i];
774 if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) {
775 ret = codec_dai->driver->ops->prepare(substream,
776 codec_dai);
777 if (ret < 0) {
778 dev_err(codec_dai->dev,
Jarkko Nikula90cc7f12014-12-23 11:04:41 +0200779 "ASoC: codec DAI prepare error: %d\n",
780 ret);
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200781 goto out;
782 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100783 }
784 }
785
Mark Brownc5914b02013-10-30 17:47:39 -0700786 if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) {
Liam Girdwoodddee6272011-06-09 14:45:53 +0100787 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
788 if (ret < 0) {
Jarkko Nikula90cc7f12014-12-23 11:04:41 +0200789 dev_err(cpu_dai->dev,
790 "ASoC: cpu DAI prepare error: %d\n", ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100791 goto out;
792 }
793 }
794
795 /* cancel any delayed stream shutdown that is pending */
796 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
Misael Lopez Cruz9bffb1f2012-12-13 12:23:05 -0600797 rtd->pop_wait) {
798 rtd->pop_wait = 0;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100799 cancel_delayed_work(&rtd->delayed_work);
800 }
801
Liam Girdwoodd9b09512012-03-07 16:32:59 +0000802 snd_soc_dapm_stream_event(rtd, substream->stream,
803 SND_SOC_DAPM_STREAM_START);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100804
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200805 for (i = 0; i < rtd->num_codecs; i++)
806 snd_soc_dai_digital_mute(rtd->codec_dais[i], 0,
807 substream->stream);
Ramesh Babuae116012014-10-15 12:34:59 +0530808 snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100809
810out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100811 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100812 return ret;
813}
814
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200815static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
816 unsigned int mask)
817{
818 struct snd_interval *interval;
819 int channels = hweight_long(mask);
820
821 interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
822 interval->min = channels;
823 interval->max = channels;
824}
825
Benoit Cousson93e69582014-07-08 23:19:38 +0200826int soc_dai_hw_params(struct snd_pcm_substream *substream,
827 struct snd_pcm_hw_params *params,
828 struct snd_soc_dai *dai)
829{
830 int ret;
831
832 if (dai->driver->ops && dai->driver->ops->hw_params) {
833 ret = dai->driver->ops->hw_params(substream, params, dai);
834 if (ret < 0) {
835 dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
836 dai->name, ret);
837 return ret;
838 }
839 }
840
841 return 0;
842}
843
Liam Girdwoodddee6272011-06-09 14:45:53 +0100844/*
845 * Called by ALSA when the hardware params are set by application. This
846 * function can also be called multiple times and can allocate buffers
847 * (using snd_pcm_lib_* ). It's non-atomic.
848 */
849static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
850 struct snd_pcm_hw_params *params)
851{
852 struct snd_soc_pcm_runtime *rtd = substream->private_data;
853 struct snd_soc_platform *platform = rtd->platform;
854 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200855 int i, ret = 0;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100856
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100857 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100858 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
859 ret = rtd->dai_link->ops->hw_params(substream, params);
860 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000861 dev_err(rtd->card->dev, "ASoC: machine hw_params"
862 " failed: %d\n", ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100863 goto out;
864 }
865 }
866
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200867 for (i = 0; i < rtd->num_codecs; i++) {
868 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
869 struct snd_pcm_hw_params codec_params;
870
Ricard Wanderlofcde79032015-08-24 14:16:51 +0200871 /*
872 * Skip CODECs which don't support the current stream type,
873 * the idea being that if a CODEC is not used for the currently
874 * set up transfer direction, it should not need to be
875 * configured, especially since the configuration used might
876 * not even be supported by that CODEC. There may be cases
877 * however where a CODEC needs to be set up although it is
878 * actually not being used for the transfer, e.g. if a
879 * capture-only CODEC is acting as an LRCLK and/or BCLK master
880 * for the DAI link including a playback-only CODEC.
881 * If this becomes necessary, we will have to augment the
882 * machine driver setup with information on how to act, so
883 * we can do the right thing here.
884 */
885 if (!snd_soc_dai_stream_valid(codec_dai, substream->stream))
886 continue;
887
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200888 /* copy params for each codec */
889 codec_params = *params;
890
891 /* fixup params based on TDM slot masks */
892 if (codec_dai->tx_mask)
893 soc_pcm_codec_params_fixup(&codec_params,
894 codec_dai->tx_mask);
895 if (codec_dai->rx_mask)
896 soc_pcm_codec_params_fixup(&codec_params,
897 codec_dai->rx_mask);
898
Benoit Cousson93e69582014-07-08 23:19:38 +0200899 ret = soc_dai_hw_params(substream, &codec_params, codec_dai);
900 if(ret < 0)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100901 goto codec_err;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200902
903 codec_dai->rate = params_rate(&codec_params);
904 codec_dai->channels = params_channels(&codec_params);
905 codec_dai->sample_bits = snd_pcm_format_physical_width(
906 params_format(&codec_params));
Liam Girdwoodddee6272011-06-09 14:45:53 +0100907 }
908
Benoit Cousson93e69582014-07-08 23:19:38 +0200909 ret = soc_dai_hw_params(substream, params, cpu_dai);
910 if (ret < 0)
911 goto interface_err;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100912
913 if (platform->driver->ops && platform->driver->ops->hw_params) {
914 ret = platform->driver->ops->hw_params(substream, params);
915 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +0000916 dev_err(platform->dev, "ASoC: %s hw params failed: %d\n",
Lars-Peter Clausenf4333202014-06-16 18:13:02 +0200917 platform->component.name, ret);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100918 goto platform_err;
919 }
920 }
921
Nicolin Chen3635bf02013-11-13 18:56:24 +0800922 /* store the parameters for each DAIs */
Dong Aisheng17841022011-08-29 17:15:14 +0800923 cpu_dai->rate = params_rate(params);
Nicolin Chen3635bf02013-11-13 18:56:24 +0800924 cpu_dai->channels = params_channels(params);
925 cpu_dai->sample_bits =
926 snd_pcm_format_physical_width(params_format(params));
927
jiada wang957ce0c2017-09-20 15:25:30 +0900928
929 ret = soc_pcm_params_symmetry(substream, params);
930 if (ret)
931 goto platform_err;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100932out:
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100933 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100934 return ret;
935
936platform_err:
Mark Brownc5914b02013-10-30 17:47:39 -0700937 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
Liam Girdwoodddee6272011-06-09 14:45:53 +0100938 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
939
940interface_err:
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200941 i = rtd->num_codecs;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100942
943codec_err:
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200944 while (--i >= 0) {
945 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
946 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
947 codec_dai->driver->ops->hw_free(substream, codec_dai);
948 codec_dai->rate = 0;
949 }
950
Liam Girdwoodddee6272011-06-09 14:45:53 +0100951 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
952 rtd->dai_link->ops->hw_free(substream);
953
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100954 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100955 return ret;
956}
957
958/*
959 * Frees resources allocated by hw_params, can be called multiple times
960 */
961static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
962{
963 struct snd_soc_pcm_runtime *rtd = substream->private_data;
964 struct snd_soc_platform *platform = rtd->platform;
965 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200966 struct snd_soc_dai *codec_dai;
Nicolin Chen7f62b6e2013-12-04 11:18:36 +0800967 bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200968 int i;
Liam Girdwoodddee6272011-06-09 14:45:53 +0100969
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +0100970 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
Liam Girdwoodddee6272011-06-09 14:45:53 +0100971
Nicolin Chend3383422013-11-20 18:37:09 +0800972 /* clear the corresponding DAIs parameters when going to be inactive */
973 if (cpu_dai->active == 1) {
974 cpu_dai->rate = 0;
975 cpu_dai->channels = 0;
976 cpu_dai->sample_bits = 0;
977 }
978
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200979 for (i = 0; i < rtd->num_codecs; i++) {
980 codec_dai = rtd->codec_dais[i];
981 if (codec_dai->active == 1) {
982 codec_dai->rate = 0;
983 codec_dai->channels = 0;
984 codec_dai->sample_bits = 0;
985 }
Nicolin Chend3383422013-11-20 18:37:09 +0800986 }
987
Liam Girdwoodddee6272011-06-09 14:45:53 +0100988 /* apply codec digital mute */
Benoit Cousson2e5894d2014-07-08 23:19:35 +0200989 for (i = 0; i < rtd->num_codecs; i++) {
990 if ((playback && rtd->codec_dais[i]->playback_active == 1) ||
991 (!playback && rtd->codec_dais[i]->capture_active == 1))
992 snd_soc_dai_digital_mute(rtd->codec_dais[i], 1,
993 substream->stream);
994 }
Liam Girdwoodddee6272011-06-09 14:45:53 +0100995
996 /* free any machine hw params */
997 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
998 rtd->dai_link->ops->hw_free(substream);
999
1000 /* free any DMA resources */
1001 if (platform->driver->ops && platform->driver->ops->hw_free)
1002 platform->driver->ops->hw_free(substream);
1003
1004 /* now free hw params for the DAIs */
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001005 for (i = 0; i < rtd->num_codecs; i++) {
1006 codec_dai = rtd->codec_dais[i];
1007 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
1008 codec_dai->driver->ops->hw_free(substream, codec_dai);
1009 }
Liam Girdwoodddee6272011-06-09 14:45:53 +01001010
Mark Brownc5914b02013-10-30 17:47:39 -07001011 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
Liam Girdwoodddee6272011-06-09 14:45:53 +01001012 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
1013
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +01001014 mutex_unlock(&rtd->pcm_mutex);
Liam Girdwoodddee6272011-06-09 14:45:53 +01001015 return 0;
1016}
1017
1018static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1019{
1020 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1021 struct snd_soc_platform *platform = rtd->platform;
1022 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001023 struct snd_soc_dai *codec_dai;
1024 int i, ret;
Liam Girdwoodddee6272011-06-09 14:45:53 +01001025
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001026 for (i = 0; i < rtd->num_codecs; i++) {
1027 codec_dai = rtd->codec_dais[i];
1028 if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) {
1029 ret = codec_dai->driver->ops->trigger(substream,
1030 cmd, codec_dai);
1031 if (ret < 0)
1032 return ret;
1033 }
Liam Girdwoodddee6272011-06-09 14:45:53 +01001034 }
1035
1036 if (platform->driver->ops && platform->driver->ops->trigger) {
1037 ret = platform->driver->ops->trigger(substream, cmd);
1038 if (ret < 0)
1039 return ret;
1040 }
1041
Mark Brownc5914b02013-10-30 17:47:39 -07001042 if (cpu_dai->driver->ops && cpu_dai->driver->ops->trigger) {
Liam Girdwoodddee6272011-06-09 14:45:53 +01001043 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
1044 if (ret < 0)
1045 return ret;
1046 }
Jarkko Nikula4792b0d2014-04-28 14:17:52 +02001047
1048 if (rtd->dai_link->ops && rtd->dai_link->ops->trigger) {
1049 ret = rtd->dai_link->ops->trigger(substream, cmd);
1050 if (ret < 0)
1051 return ret;
1052 }
1053
Liam Girdwoodddee6272011-06-09 14:45:53 +01001054 return 0;
1055}
1056
Mark Brown45c0a182012-05-09 21:46:27 +01001057static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
1058 int cmd)
Liam Girdwood07bf84a2012-04-25 12:12:52 +01001059{
1060 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood07bf84a2012-04-25 12:12:52 +01001061 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001062 struct snd_soc_dai *codec_dai;
1063 int i, ret;
Liam Girdwood07bf84a2012-04-25 12:12:52 +01001064
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001065 for (i = 0; i < rtd->num_codecs; i++) {
1066 codec_dai = rtd->codec_dais[i];
1067 if (codec_dai->driver->ops &&
1068 codec_dai->driver->ops->bespoke_trigger) {
1069 ret = codec_dai->driver->ops->bespoke_trigger(substream,
1070 cmd, codec_dai);
1071 if (ret < 0)
1072 return ret;
1073 }
Liam Girdwood07bf84a2012-04-25 12:12:52 +01001074 }
1075
Mark Brownc5914b02013-10-30 17:47:39 -07001076 if (cpu_dai->driver->ops && cpu_dai->driver->ops->bespoke_trigger) {
Liam Girdwood07bf84a2012-04-25 12:12:52 +01001077 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
1078 if (ret < 0)
1079 return ret;
1080 }
1081 return 0;
1082}
Liam Girdwoodddee6272011-06-09 14:45:53 +01001083/*
1084 * soc level wrapper for pointer callback
1085 * If cpu_dai, codec_dai, platform driver has the delay callback, than
1086 * the runtime->delay will be updated accordingly.
1087 */
1088static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1089{
1090 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1091 struct snd_soc_platform *platform = rtd->platform;
1092 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001093 struct snd_soc_dai *codec_dai;
Liam Girdwoodddee6272011-06-09 14:45:53 +01001094 struct snd_pcm_runtime *runtime = substream->runtime;
1095 snd_pcm_uframes_t offset = 0;
1096 snd_pcm_sframes_t delay = 0;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001097 snd_pcm_sframes_t codec_delay = 0;
1098 int i;
Liam Girdwoodddee6272011-06-09 14:45:53 +01001099
1100 if (platform->driver->ops && platform->driver->ops->pointer)
1101 offset = platform->driver->ops->pointer(substream);
1102
Mark Brownc5914b02013-10-30 17:47:39 -07001103 if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay)
Liam Girdwoodddee6272011-06-09 14:45:53 +01001104 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
1105
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001106 for (i = 0; i < rtd->num_codecs; i++) {
1107 codec_dai = rtd->codec_dais[i];
1108 if (codec_dai->driver->ops && codec_dai->driver->ops->delay)
1109 codec_delay = max(codec_delay,
1110 codec_dai->driver->ops->delay(substream,
1111 codec_dai));
1112 }
1113 delay += codec_delay;
Liam Girdwoodddee6272011-06-09 14:45:53 +01001114
Liam Girdwoodddee6272011-06-09 14:45:53 +01001115 runtime->delay = delay;
1116
1117 return offset;
1118}
1119
Liam Girdwood01d75842012-04-25 12:12:49 +01001120/* connect a FE and BE */
1121static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
1122 struct snd_soc_pcm_runtime *be, int stream)
1123{
1124 struct snd_soc_dpcm *dpcm;
1125
1126 /* only add new dpcms */
1127 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1128 if (dpcm->be == be && dpcm->fe == fe)
1129 return 0;
1130 }
1131
1132 dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL);
1133 if (!dpcm)
1134 return -ENOMEM;
1135
1136 dpcm->be = be;
1137 dpcm->fe = fe;
1138 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
1139 dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
1140 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
1141 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
1142
Jarkko Nikula7cc302d2013-09-30 17:08:15 +03001143 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001144 stream ? "capture" : "playback", fe->dai_link->name,
1145 stream ? "<-" : "->", be->dai_link->name);
1146
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001147#ifdef CONFIG_DEBUG_FS
Lars-Peter Clausen6553bf062015-04-09 10:52:38 +02001148 if (fe->debugfs_dpcm_root)
1149 dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
1150 fe->debugfs_dpcm_root, &dpcm->state);
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001151#endif
Liam Girdwood01d75842012-04-25 12:12:49 +01001152 return 1;
1153}
1154
1155/* reparent a BE onto another FE */
1156static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
1157 struct snd_soc_pcm_runtime *be, int stream)
1158{
1159 struct snd_soc_dpcm *dpcm;
1160 struct snd_pcm_substream *fe_substream, *be_substream;
1161
1162 /* reparent if BE is connected to other FEs */
1163 if (!be->dpcm[stream].users)
1164 return;
1165
1166 be_substream = snd_soc_dpcm_get_substream(be, stream);
1167
1168 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
1169 if (dpcm->fe == fe)
1170 continue;
1171
Jarkko Nikula7cc302d2013-09-30 17:08:15 +03001172 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001173 stream ? "capture" : "playback",
1174 dpcm->fe->dai_link->name,
1175 stream ? "<-" : "->", dpcm->be->dai_link->name);
1176
1177 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
1178 be_substream->runtime = fe_substream->runtime;
1179 break;
1180 }
1181}
1182
1183/* disconnect a BE and FE */
Liam Girdwood23607022014-01-17 17:03:55 +00001184void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001185{
1186 struct snd_soc_dpcm *dpcm, *d;
1187
1188 list_for_each_entry_safe(dpcm, d, &fe->dpcm[stream].be_clients, list_be) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001189 dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001190 stream ? "capture" : "playback",
1191 dpcm->be->dai_link->name);
1192
1193 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
1194 continue;
1195
Jarkko Nikula7cc302d2013-09-30 17:08:15 +03001196 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001197 stream ? "capture" : "playback", fe->dai_link->name,
1198 stream ? "<-" : "->", dpcm->be->dai_link->name);
1199
1200 /* BEs still alive need new FE */
1201 dpcm_be_reparent(fe, dpcm->be, stream);
1202
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001203#ifdef CONFIG_DEBUG_FS
1204 debugfs_remove(dpcm->debugfs_state);
1205#endif
Liam Girdwood01d75842012-04-25 12:12:49 +01001206 list_del(&dpcm->list_be);
1207 list_del(&dpcm->list_fe);
1208 kfree(dpcm);
1209 }
1210}
1211
1212/* get BE for DAI widget and stream */
1213static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
1214 struct snd_soc_dapm_widget *widget, int stream)
1215{
1216 struct snd_soc_pcm_runtime *be;
Mengdong Lin1a497982015-11-18 02:34:11 -05001217 int i;
Liam Girdwood01d75842012-04-25 12:12:49 +01001218
1219 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Mengdong Lin1a497982015-11-18 02:34:11 -05001220 list_for_each_entry(be, &card->rtd_list, list) {
Liam Girdwood01d75842012-04-25 12:12:49 +01001221
Liam Girdwood35ea0652012-06-05 19:26:59 +01001222 if (!be->dai_link->no_pcm)
1223 continue;
1224
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001225 if (be->cpu_dai->playback_widget == widget)
Liam Girdwood01d75842012-04-25 12:12:49 +01001226 return be;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001227
Mengdong Lin1a497982015-11-18 02:34:11 -05001228 for (i = 0; i < be->num_codecs; i++) {
1229 struct snd_soc_dai *dai = be->codec_dais[i];
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001230 if (dai->playback_widget == widget)
1231 return be;
1232 }
Liam Girdwood01d75842012-04-25 12:12:49 +01001233 }
1234 } else {
1235
Mengdong Lin1a497982015-11-18 02:34:11 -05001236 list_for_each_entry(be, &card->rtd_list, list) {
Liam Girdwood01d75842012-04-25 12:12:49 +01001237
Liam Girdwood35ea0652012-06-05 19:26:59 +01001238 if (!be->dai_link->no_pcm)
1239 continue;
1240
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001241 if (be->cpu_dai->capture_widget == widget)
Liam Girdwood01d75842012-04-25 12:12:49 +01001242 return be;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001243
Mengdong Lin1a497982015-11-18 02:34:11 -05001244 for (i = 0; i < be->num_codecs; i++) {
1245 struct snd_soc_dai *dai = be->codec_dais[i];
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001246 if (dai->capture_widget == widget)
1247 return be;
1248 }
Liam Girdwood01d75842012-04-25 12:12:49 +01001249 }
1250 }
1251
Liam Girdwood103d84a2012-11-19 14:39:15 +00001252 dev_err(card->dev, "ASoC: can't get %s BE for %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001253 stream ? "capture" : "playback", widget->name);
1254 return NULL;
1255}
1256
1257static inline struct snd_soc_dapm_widget *
Benoit Cousson37018612014-04-24 14:01:45 +02001258 dai_get_widget(struct snd_soc_dai *dai, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001259{
1260 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
Benoit Cousson37018612014-04-24 14:01:45 +02001261 return dai->playback_widget;
Liam Girdwood01d75842012-04-25 12:12:49 +01001262 else
Benoit Cousson37018612014-04-24 14:01:45 +02001263 return dai->capture_widget;
Liam Girdwood01d75842012-04-25 12:12:49 +01001264}
1265
1266static int widget_in_list(struct snd_soc_dapm_widget_list *list,
1267 struct snd_soc_dapm_widget *widget)
1268{
1269 int i;
1270
1271 for (i = 0; i < list->num_widgets; i++) {
1272 if (widget == list->widgets[i])
1273 return 1;
1274 }
1275
1276 return 0;
1277}
1278
Piotr Stankiewicz5fdd0222016-05-13 17:03:56 +01001279static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
1280 enum snd_soc_dapm_direction dir)
1281{
1282 struct snd_soc_card *card = widget->dapm->card;
1283 struct snd_soc_pcm_runtime *rtd;
1284 int i;
1285
1286 if (dir == SND_SOC_DAPM_DIR_OUT) {
1287 list_for_each_entry(rtd, &card->rtd_list, list) {
1288 if (!rtd->dai_link->no_pcm)
1289 continue;
1290
1291 if (rtd->cpu_dai->playback_widget == widget)
1292 return true;
1293
1294 for (i = 0; i < rtd->num_codecs; ++i) {
1295 struct snd_soc_dai *dai = rtd->codec_dais[i];
1296 if (dai->playback_widget == widget)
1297 return true;
1298 }
1299 }
1300 } else { /* SND_SOC_DAPM_DIR_IN */
1301 list_for_each_entry(rtd, &card->rtd_list, list) {
1302 if (!rtd->dai_link->no_pcm)
1303 continue;
1304
1305 if (rtd->cpu_dai->capture_widget == widget)
1306 return true;
1307
1308 for (i = 0; i < rtd->num_codecs; ++i) {
1309 struct snd_soc_dai *dai = rtd->codec_dais[i];
1310 if (dai->capture_widget == widget)
1311 return true;
1312 }
1313 }
1314 }
1315
1316 return false;
1317}
1318
Liam Girdwood23607022014-01-17 17:03:55 +00001319int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
Lars-Peter Clausen1ce43ac2015-07-26 19:04:59 +02001320 int stream, struct snd_soc_dapm_widget_list **list)
Liam Girdwood01d75842012-04-25 12:12:49 +01001321{
1322 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
Liam Girdwood01d75842012-04-25 12:12:49 +01001323 int paths;
1324
Liam Girdwood01d75842012-04-25 12:12:49 +01001325 /* get number of valid DAI paths and their widgets */
Piotr Stankiewicz67420642016-05-13 17:03:55 +01001326 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
Piotr Stankiewicz5fdd0222016-05-13 17:03:56 +01001327 dpcm_end_walk_at_be);
Liam Girdwood01d75842012-04-25 12:12:49 +01001328
Liam Girdwood103d84a2012-11-19 14:39:15 +00001329 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
Liam Girdwood01d75842012-04-25 12:12:49 +01001330 stream ? "capture" : "playback");
1331
Liam Girdwood01d75842012-04-25 12:12:49 +01001332 return paths;
1333}
1334
Liam Girdwood01d75842012-04-25 12:12:49 +01001335static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
1336 struct snd_soc_dapm_widget_list **list_)
1337{
1338 struct snd_soc_dpcm *dpcm;
1339 struct snd_soc_dapm_widget_list *list = *list_;
1340 struct snd_soc_dapm_widget *widget;
1341 int prune = 0;
1342
1343 /* Destroy any old FE <--> BE connections */
1344 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001345 unsigned int i;
Liam Girdwood01d75842012-04-25 12:12:49 +01001346
1347 /* is there a valid CPU DAI widget for this BE */
Benoit Cousson37018612014-04-24 14:01:45 +02001348 widget = dai_get_widget(dpcm->be->cpu_dai, stream);
Liam Girdwood01d75842012-04-25 12:12:49 +01001349
1350 /* prune the BE if it's no longer in our active list */
1351 if (widget && widget_in_list(list, widget))
1352 continue;
1353
1354 /* is there a valid CODEC DAI widget for this BE */
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001355 for (i = 0; i < dpcm->be->num_codecs; i++) {
1356 struct snd_soc_dai *dai = dpcm->be->codec_dais[i];
1357 widget = dai_get_widget(dai, stream);
Liam Girdwood01d75842012-04-25 12:12:49 +01001358
Benoit Cousson2e5894d2014-07-08 23:19:35 +02001359 /* prune the BE if it's no longer in our active list */
1360 if (widget && widget_in_list(list, widget))
1361 continue;
1362 }
Liam Girdwood01d75842012-04-25 12:12:49 +01001363
Liam Girdwood103d84a2012-11-19 14:39:15 +00001364 dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001365 stream ? "capture" : "playback",
1366 dpcm->be->dai_link->name, fe->dai_link->name);
1367 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1368 dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1369 prune++;
1370 }
1371
Liam Girdwood103d84a2012-11-19 14:39:15 +00001372 dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune);
Liam Girdwood01d75842012-04-25 12:12:49 +01001373 return prune;
1374}
1375
1376static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1377 struct snd_soc_dapm_widget_list **list_)
1378{
1379 struct snd_soc_card *card = fe->card;
1380 struct snd_soc_dapm_widget_list *list = *list_;
1381 struct snd_soc_pcm_runtime *be;
1382 int i, new = 0, err;
1383
1384 /* Create any new FE <--> BE connections */
1385 for (i = 0; i < list->num_widgets; i++) {
1386
Mark Brown46162742013-06-05 19:36:11 +01001387 switch (list->widgets[i]->id) {
1388 case snd_soc_dapm_dai_in:
Koro Chenc5b85402015-07-06 10:02:10 +08001389 if (stream != SNDRV_PCM_STREAM_PLAYBACK)
1390 continue;
1391 break;
Mark Brown46162742013-06-05 19:36:11 +01001392 case snd_soc_dapm_dai_out:
Koro Chenc5b85402015-07-06 10:02:10 +08001393 if (stream != SNDRV_PCM_STREAM_CAPTURE)
1394 continue;
Mark Brown46162742013-06-05 19:36:11 +01001395 break;
1396 default:
Liam Girdwood01d75842012-04-25 12:12:49 +01001397 continue;
Mark Brown46162742013-06-05 19:36:11 +01001398 }
Liam Girdwood01d75842012-04-25 12:12:49 +01001399
1400 /* is there a valid BE rtd for this widget */
1401 be = dpcm_get_be(card, list->widgets[i], stream);
1402 if (!be) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001403 dev_err(fe->dev, "ASoC: no BE found for %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001404 list->widgets[i]->name);
1405 continue;
1406 }
1407
1408 /* make sure BE is a real BE */
1409 if (!be->dai_link->no_pcm)
1410 continue;
1411
1412 /* don't connect if FE is not running */
Liam Girdwood23607022014-01-17 17:03:55 +00001413 if (!fe->dpcm[stream].runtime && !fe->fe_compr)
Liam Girdwood01d75842012-04-25 12:12:49 +01001414 continue;
1415
1416 /* newly connected FE and BE */
1417 err = dpcm_be_connect(fe, be, stream);
1418 if (err < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001419 dev_err(fe->dev, "ASoC: can't connect %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001420 list->widgets[i]->name);
1421 break;
1422 } else if (err == 0) /* already connected */
1423 continue;
1424
1425 /* new */
1426 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1427 new++;
1428 }
1429
Liam Girdwood103d84a2012-11-19 14:39:15 +00001430 dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new);
Liam Girdwood01d75842012-04-25 12:12:49 +01001431 return new;
1432}
1433
1434/*
1435 * Find the corresponding BE DAIs that source or sink audio to this
1436 * FE substream.
1437 */
Liam Girdwood23607022014-01-17 17:03:55 +00001438int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
Liam Girdwood01d75842012-04-25 12:12:49 +01001439 int stream, struct snd_soc_dapm_widget_list **list, int new)
1440{
1441 if (new)
1442 return dpcm_add_paths(fe, stream, list);
1443 else
1444 return dpcm_prune_paths(fe, stream, list);
1445}
1446
Liam Girdwood23607022014-01-17 17:03:55 +00001447void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001448{
1449 struct snd_soc_dpcm *dpcm;
1450
1451 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
1452 dpcm->be->dpcm[stream].runtime_update =
1453 SND_SOC_DPCM_UPDATE_NO;
1454}
1455
1456static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
1457 int stream)
1458{
1459 struct snd_soc_dpcm *dpcm;
1460
1461 /* disable any enabled and non active backends */
1462 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1463
1464 struct snd_soc_pcm_runtime *be = dpcm->be;
1465 struct snd_pcm_substream *be_substream =
1466 snd_soc_dpcm_get_substream(be, stream);
1467
1468 if (be->dpcm[stream].users == 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001469 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001470 stream ? "capture" : "playback",
1471 be->dpcm[stream].state);
1472
1473 if (--be->dpcm[stream].users != 0)
1474 continue;
1475
1476 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1477 continue;
1478
1479 soc_pcm_close(be_substream);
1480 be_substream->runtime = NULL;
1481 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1482 }
1483}
1484
Liam Girdwood23607022014-01-17 17:03:55 +00001485int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001486{
1487 struct snd_soc_dpcm *dpcm;
1488 int err, count = 0;
1489
1490 /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1491 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1492
1493 struct snd_soc_pcm_runtime *be = dpcm->be;
1494 struct snd_pcm_substream *be_substream =
1495 snd_soc_dpcm_get_substream(be, stream);
1496
Russell King - ARM Linux2062b4c2013-10-31 15:09:20 +00001497 if (!be_substream) {
1498 dev_err(be->dev, "ASoC: no backend %s stream\n",
1499 stream ? "capture" : "playback");
1500 continue;
1501 }
1502
Liam Girdwood01d75842012-04-25 12:12:49 +01001503 /* is this op for this BE ? */
1504 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1505 continue;
1506
1507 /* first time the dpcm is open ? */
1508 if (be->dpcm[stream].users == DPCM_MAX_BE_USERS)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001509 dev_err(be->dev, "ASoC: too many users %s at open %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001510 stream ? "capture" : "playback",
1511 be->dpcm[stream].state);
1512
1513 if (be->dpcm[stream].users++ != 0)
1514 continue;
1515
1516 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1517 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1518 continue;
1519
Russell King - ARM Linux2062b4c2013-10-31 15:09:20 +00001520 dev_dbg(be->dev, "ASoC: open %s BE %s\n",
1521 stream ? "capture" : "playback", be->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001522
1523 be_substream->runtime = be->dpcm[stream].runtime;
1524 err = soc_pcm_open(be_substream);
1525 if (err < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001526 dev_err(be->dev, "ASoC: BE open failed %d\n", err);
Liam Girdwood01d75842012-04-25 12:12:49 +01001527 be->dpcm[stream].users--;
1528 if (be->dpcm[stream].users < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001529 dev_err(be->dev, "ASoC: no users %s at unwind %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001530 stream ? "capture" : "playback",
1531 be->dpcm[stream].state);
1532
1533 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1534 goto unwind;
1535 }
1536
1537 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1538 count++;
1539 }
1540
1541 return count;
1542
1543unwind:
1544 /* disable any enabled and non active backends */
1545 list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1546 struct snd_soc_pcm_runtime *be = dpcm->be;
1547 struct snd_pcm_substream *be_substream =
1548 snd_soc_dpcm_get_substream(be, stream);
1549
1550 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1551 continue;
1552
1553 if (be->dpcm[stream].users == 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001554 dev_err(be->dev, "ASoC: no users %s at close %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001555 stream ? "capture" : "playback",
1556 be->dpcm[stream].state);
1557
1558 if (--be->dpcm[stream].users != 0)
1559 continue;
1560
1561 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1562 continue;
1563
1564 soc_pcm_close(be_substream);
1565 be_substream->runtime = NULL;
1566 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1567 }
1568
1569 return err;
1570}
1571
Lars-Peter Clausen08ae9b42014-01-06 14:19:06 +01001572static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001573 struct snd_soc_pcm_stream *stream,
1574 u64 formats)
Lars-Peter Clausen08ae9b42014-01-06 14:19:06 +01001575{
1576 runtime->hw.rate_min = stream->rate_min;
1577 runtime->hw.rate_max = stream->rate_max;
1578 runtime->hw.channels_min = stream->channels_min;
1579 runtime->hw.channels_max = stream->channels_max;
Lars-Peter Clausen002220a2014-01-06 14:19:07 +01001580 if (runtime->hw.formats)
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001581 runtime->hw.formats &= formats & stream->formats;
Lars-Peter Clausen002220a2014-01-06 14:19:07 +01001582 else
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001583 runtime->hw.formats = formats & stream->formats;
Lars-Peter Clausen08ae9b42014-01-06 14:19:06 +01001584 runtime->hw.rates = stream->rates;
1585}
1586
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001587static u64 dpcm_runtime_base_format(struct snd_pcm_substream *substream)
1588{
1589 struct snd_soc_pcm_runtime *fe = substream->private_data;
1590 struct snd_soc_dpcm *dpcm;
1591 u64 formats = ULLONG_MAX;
1592 int stream = substream->stream;
1593
1594 if (!fe->dai_link->dpcm_merged_format)
1595 return formats;
1596
1597 /*
1598 * It returns merged BE codec format
1599 * if FE want to use it (= dpcm_merged_format)
1600 */
1601
1602 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1603 struct snd_soc_pcm_runtime *be = dpcm->be;
1604 struct snd_soc_dai_driver *codec_dai_drv;
1605 struct snd_soc_pcm_stream *codec_stream;
1606 int i;
1607
1608 for (i = 0; i < be->num_codecs; i++) {
1609 codec_dai_drv = be->codec_dais[i]->driver;
1610 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1611 codec_stream = &codec_dai_drv->playback;
1612 else
1613 codec_stream = &codec_dai_drv->capture;
1614
1615 formats &= codec_stream->formats;
1616 }
1617 }
1618
1619 return formats;
1620}
1621
Mark Brown45c0a182012-05-09 21:46:27 +01001622static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001623{
1624 struct snd_pcm_runtime *runtime = substream->runtime;
1625 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1626 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1627 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001628 u64 format = dpcm_runtime_base_format(substream);
Liam Girdwood01d75842012-04-25 12:12:49 +01001629
Lars-Peter Clausen08ae9b42014-01-06 14:19:06 +01001630 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001631 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback, format);
Lars-Peter Clausen08ae9b42014-01-06 14:19:06 +01001632 else
Kuninori Morimotob073ed42015-05-12 02:03:33 +00001633 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture, format);
Liam Girdwood01d75842012-04-25 12:12:49 +01001634}
1635
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001636static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
1637
1638/* Set FE's runtime_update state; the state is protected via PCM stream lock
1639 * for avoiding the race with trigger callback.
1640 * If the state is unset and a trigger is pending while the previous operation,
1641 * process the pending trigger action here.
1642 */
1643static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1644 int stream, enum snd_soc_dpcm_update state)
1645{
1646 struct snd_pcm_substream *substream =
1647 snd_soc_dpcm_get_substream(fe, stream);
1648
1649 snd_pcm_stream_lock_irq(substream);
1650 if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1651 dpcm_fe_dai_do_trigger(substream,
1652 fe->dpcm[stream].trigger_pending - 1);
1653 fe->dpcm[stream].trigger_pending = 0;
1654 }
1655 fe->dpcm[stream].runtime_update = state;
1656 snd_pcm_stream_unlock_irq(substream);
1657}
1658
PC Liao906c7d62015-12-11 11:33:51 +08001659static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
1660 int stream)
1661{
1662 struct snd_soc_dpcm *dpcm;
1663 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1664 struct snd_soc_dai *fe_cpu_dai = fe->cpu_dai;
1665 int err;
1666
1667 /* apply symmetry for FE */
1668 if (soc_pcm_has_symmetry(fe_substream))
1669 fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1670
1671 /* Symmetry only applies if we've got an active stream. */
1672 if (fe_cpu_dai->active) {
1673 err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
1674 if (err < 0)
1675 return err;
1676 }
1677
1678 /* apply symmetry for BE */
1679 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1680 struct snd_soc_pcm_runtime *be = dpcm->be;
1681 struct snd_pcm_substream *be_substream =
1682 snd_soc_dpcm_get_substream(be, stream);
1683 struct snd_soc_pcm_runtime *rtd = be_substream->private_data;
1684 int i;
1685
Jeeja KPf1176612016-09-06 14:17:55 +05301686 if (rtd->dai_link->be_hw_params_fixup)
1687 continue;
1688
PC Liao906c7d62015-12-11 11:33:51 +08001689 if (soc_pcm_has_symmetry(be_substream))
1690 be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
1691
1692 /* Symmetry only applies if we've got an active stream. */
1693 if (rtd->cpu_dai->active) {
1694 err = soc_pcm_apply_symmetry(be_substream, rtd->cpu_dai);
1695 if (err < 0)
1696 return err;
1697 }
1698
1699 for (i = 0; i < rtd->num_codecs; i++) {
1700 if (rtd->codec_dais[i]->active) {
1701 err = soc_pcm_apply_symmetry(be_substream,
1702 rtd->codec_dais[i]);
1703 if (err < 0)
1704 return err;
1705 }
1706 }
1707 }
1708
1709 return 0;
1710}
1711
Liam Girdwood01d75842012-04-25 12:12:49 +01001712static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1713{
1714 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1715 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1716 int stream = fe_substream->stream, ret = 0;
1717
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001718 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
Liam Girdwood01d75842012-04-25 12:12:49 +01001719
1720 ret = dpcm_be_dai_startup(fe, fe_substream->stream);
1721 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001722 dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01001723 goto be_err;
1724 }
1725
Liam Girdwood103d84a2012-11-19 14:39:15 +00001726 dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001727
1728 /* start the DAI frontend */
1729 ret = soc_pcm_open(fe_substream);
1730 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001731 dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01001732 goto unwind;
1733 }
1734
1735 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1736
1737 dpcm_set_fe_runtime(fe_substream);
1738 snd_pcm_limit_hw_rates(runtime);
1739
PC Liao906c7d62015-12-11 11:33:51 +08001740 ret = dpcm_apply_symmetry(fe_substream, stream);
1741 if (ret < 0) {
1742 dev_err(fe->dev, "ASoC: failed to apply dpcm symmetry %d\n",
1743 ret);
1744 goto unwind;
1745 }
1746
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001747 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01001748 return 0;
1749
1750unwind:
1751 dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
1752be_err:
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001753 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01001754 return ret;
1755}
1756
Liam Girdwood23607022014-01-17 17:03:55 +00001757int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001758{
1759 struct snd_soc_dpcm *dpcm;
1760
1761 /* only shutdown BEs that are either sinks or sources to this FE DAI */
1762 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1763
1764 struct snd_soc_pcm_runtime *be = dpcm->be;
1765 struct snd_pcm_substream *be_substream =
1766 snd_soc_dpcm_get_substream(be, stream);
1767
1768 /* is this op for this BE ? */
1769 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1770 continue;
1771
1772 if (be->dpcm[stream].users == 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001773 dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001774 stream ? "capture" : "playback",
1775 be->dpcm[stream].state);
1776
1777 if (--be->dpcm[stream].users != 0)
1778 continue;
1779
1780 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1781 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
1782 continue;
1783
Liam Girdwood103d84a2012-11-19 14:39:15 +00001784 dev_dbg(be->dev, "ASoC: close BE %s\n",
彭东林94d215c2016-09-26 08:29:31 +00001785 be->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001786
1787 soc_pcm_close(be_substream);
1788 be_substream->runtime = NULL;
1789
1790 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1791 }
1792 return 0;
1793}
1794
1795static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1796{
1797 struct snd_soc_pcm_runtime *fe = substream->private_data;
1798 int stream = substream->stream;
1799
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001800 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
Liam Girdwood01d75842012-04-25 12:12:49 +01001801
1802 /* shutdown the BEs */
1803 dpcm_be_dai_shutdown(fe, substream->stream);
1804
Liam Girdwood103d84a2012-11-19 14:39:15 +00001805 dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001806
1807 /* now shutdown the frontend */
1808 soc_pcm_close(substream);
1809
1810 /* run the stream event for each BE */
1811 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1812
1813 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001814 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01001815 return 0;
1816}
1817
Liam Girdwood23607022014-01-17 17:03:55 +00001818int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001819{
1820 struct snd_soc_dpcm *dpcm;
1821
1822 /* only hw_params backends that are either sinks or sources
1823 * to this frontend DAI */
1824 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1825
1826 struct snd_soc_pcm_runtime *be = dpcm->be;
1827 struct snd_pcm_substream *be_substream =
1828 snd_soc_dpcm_get_substream(be, stream);
1829
1830 /* is this op for this BE ? */
1831 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1832 continue;
1833
1834 /* only free hw when no longer used - check all FEs */
1835 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1836 continue;
1837
Qiao Zhou36fba622014-12-03 10:13:43 +08001838 /* do not free hw if this BE is used by other FE */
1839 if (be->dpcm[stream].users > 1)
1840 continue;
1841
Liam Girdwood01d75842012-04-25 12:12:49 +01001842 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1843 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1844 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
Patrick Lai08b27842012-12-19 19:36:02 -08001845 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
Vinod Koul5e82d2b2016-02-01 22:26:40 +05301846 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
1847 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
Liam Girdwood01d75842012-04-25 12:12:49 +01001848 continue;
1849
Liam Girdwood103d84a2012-11-19 14:39:15 +00001850 dev_dbg(be->dev, "ASoC: hw_free BE %s\n",
彭东林94d215c2016-09-26 08:29:31 +00001851 be->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001852
1853 soc_pcm_hw_free(be_substream);
1854
1855 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1856 }
1857
1858 return 0;
1859}
1860
Mark Brown45c0a182012-05-09 21:46:27 +01001861static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001862{
1863 struct snd_soc_pcm_runtime *fe = substream->private_data;
1864 int err, stream = substream->stream;
1865
1866 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001867 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
Liam Girdwood01d75842012-04-25 12:12:49 +01001868
Liam Girdwood103d84a2012-11-19 14:39:15 +00001869 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01001870
1871 /* call hw_free on the frontend */
1872 err = soc_pcm_hw_free(substream);
1873 if (err < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00001874 dev_err(fe->dev,"ASoC: hw_free FE %s failed\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001875 fe->dai_link->name);
1876
1877 /* only hw_params backends that are either sinks or sources
1878 * to this frontend DAI */
1879 err = dpcm_be_dai_hw_free(fe, stream);
1880
1881 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001882 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01001883
1884 mutex_unlock(&fe->card->mutex);
1885 return 0;
1886}
1887
Liam Girdwood23607022014-01-17 17:03:55 +00001888int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01001889{
1890 struct snd_soc_dpcm *dpcm;
1891 int ret;
1892
1893 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1894
1895 struct snd_soc_pcm_runtime *be = dpcm->be;
1896 struct snd_pcm_substream *be_substream =
1897 snd_soc_dpcm_get_substream(be, stream);
1898
1899 /* is this op for this BE ? */
1900 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1901 continue;
1902
Liam Girdwood01d75842012-04-25 12:12:49 +01001903 /* copy params for each dpcm */
1904 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1905 sizeof(struct snd_pcm_hw_params));
1906
1907 /* perform any hw_params fixups */
1908 if (be->dai_link->be_hw_params_fixup) {
1909 ret = be->dai_link->be_hw_params_fixup(be,
1910 &dpcm->hw_params);
1911 if (ret < 0) {
1912 dev_err(be->dev,
Liam Girdwood103d84a2012-11-19 14:39:15 +00001913 "ASoC: hw_params BE fixup failed %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001914 ret);
1915 goto unwind;
1916 }
1917 }
1918
Kuninori Morimotob0639bd2016-01-21 01:47:12 +00001919 /* only allow hw_params() if no connected FEs are running */
1920 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1921 continue;
1922
1923 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1924 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1925 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1926 continue;
1927
1928 dev_dbg(be->dev, "ASoC: hw_params BE %s\n",
彭东林94d215c2016-09-26 08:29:31 +00001929 be->dai_link->name);
Kuninori Morimotob0639bd2016-01-21 01:47:12 +00001930
Liam Girdwood01d75842012-04-25 12:12:49 +01001931 ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params);
1932 if (ret < 0) {
1933 dev_err(dpcm->be->dev,
Liam Girdwood103d84a2012-11-19 14:39:15 +00001934 "ASoC: hw_params BE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01001935 goto unwind;
1936 }
1937
1938 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1939 }
1940 return 0;
1941
1942unwind:
1943 /* disable any enabled and non active backends */
1944 list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1945 struct snd_soc_pcm_runtime *be = dpcm->be;
1946 struct snd_pcm_substream *be_substream =
1947 snd_soc_dpcm_get_substream(be, stream);
1948
1949 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1950 continue;
1951
1952 /* only allow hw_free() if no connected FEs are running */
1953 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1954 continue;
1955
1956 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1957 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1958 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1959 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1960 continue;
1961
1962 soc_pcm_hw_free(be_substream);
1963 }
1964
1965 return ret;
1966}
1967
Mark Brown45c0a182012-05-09 21:46:27 +01001968static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1969 struct snd_pcm_hw_params *params)
Liam Girdwood01d75842012-04-25 12:12:49 +01001970{
1971 struct snd_soc_pcm_runtime *fe = substream->private_data;
1972 int ret, stream = substream->stream;
1973
1974 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001975 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
Liam Girdwood01d75842012-04-25 12:12:49 +01001976
1977 memcpy(&fe->dpcm[substream->stream].hw_params, params,
1978 sizeof(struct snd_pcm_hw_params));
1979 ret = dpcm_be_dai_hw_params(fe, substream->stream);
1980 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001981 dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01001982 goto out;
1983 }
1984
Liam Girdwood103d84a2012-11-19 14:39:15 +00001985 dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01001986 fe->dai_link->name, params_rate(params),
1987 params_channels(params), params_format(params));
1988
1989 /* call hw_params on the frontend */
1990 ret = soc_pcm_hw_params(substream, params);
1991 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00001992 dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01001993 dpcm_be_dai_hw_free(fe, stream);
1994 } else
1995 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1996
1997out:
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01001998 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01001999 mutex_unlock(&fe->card->mutex);
2000 return ret;
2001}
2002
2003static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm,
2004 struct snd_pcm_substream *substream, int cmd)
2005{
2006 int ret;
2007
Liam Girdwood103d84a2012-11-19 14:39:15 +00002008 dev_dbg(dpcm->be->dev, "ASoC: trigger BE %s cmd %d\n",
彭东林94d215c2016-09-26 08:29:31 +00002009 dpcm->be->dai_link->name, cmd);
Liam Girdwood01d75842012-04-25 12:12:49 +01002010
2011 ret = soc_pcm_trigger(substream, cmd);
2012 if (ret < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002013 dev_err(dpcm->be->dev,"ASoC: trigger BE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01002014
2015 return ret;
2016}
2017
Liam Girdwood23607022014-01-17 17:03:55 +00002018int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
Mark Brown45c0a182012-05-09 21:46:27 +01002019 int cmd)
Liam Girdwood01d75842012-04-25 12:12:49 +01002020{
2021 struct snd_soc_dpcm *dpcm;
2022 int ret = 0;
2023
2024 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2025
2026 struct snd_soc_pcm_runtime *be = dpcm->be;
2027 struct snd_pcm_substream *be_substream =
2028 snd_soc_dpcm_get_substream(be, stream);
2029
2030 /* is this op for this BE ? */
2031 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2032 continue;
2033
2034 switch (cmd) {
2035 case SNDRV_PCM_TRIGGER_START:
2036 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
2037 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
2038 continue;
2039
2040 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2041 if (ret)
2042 return ret;
2043
2044 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2045 break;
2046 case SNDRV_PCM_TRIGGER_RESUME:
2047 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
2048 continue;
2049
2050 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2051 if (ret)
2052 return ret;
2053
2054 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2055 break;
2056 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2057 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
2058 continue;
2059
2060 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2061 if (ret)
2062 return ret;
2063
2064 be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2065 break;
2066 case SNDRV_PCM_TRIGGER_STOP:
2067 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2068 continue;
2069
2070 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2071 continue;
2072
2073 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2074 if (ret)
2075 return ret;
2076
2077 be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2078 break;
2079 case SNDRV_PCM_TRIGGER_SUSPEND:
Nicolin Chen868a6ca2014-05-12 20:12:05 +08002080 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
Liam Girdwood01d75842012-04-25 12:12:49 +01002081 continue;
2082
2083 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2084 continue;
2085
2086 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2087 if (ret)
2088 return ret;
2089
2090 be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
2091 break;
2092 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2093 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2094 continue;
2095
2096 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2097 continue;
2098
2099 ret = dpcm_do_trigger(dpcm, be_substream, cmd);
2100 if (ret)
2101 return ret;
2102
2103 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2104 break;
2105 }
2106 }
2107
2108 return ret;
2109}
2110EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
2111
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002112static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
Liam Girdwood01d75842012-04-25 12:12:49 +01002113{
2114 struct snd_soc_pcm_runtime *fe = substream->private_data;
2115 int stream = substream->stream, ret;
2116 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2117
2118 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
2119
2120 switch (trigger) {
2121 case SND_SOC_DPCM_TRIGGER_PRE:
2122 /* call trigger on the frontend before the backend. */
2123
Liam Girdwood103d84a2012-11-19 14:39:15 +00002124 dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002125 fe->dai_link->name, cmd);
2126
2127 ret = soc_pcm_trigger(substream, cmd);
2128 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002129 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01002130 goto out;
2131 }
2132
2133 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2134 break;
2135 case SND_SOC_DPCM_TRIGGER_POST:
2136 /* call trigger on the frontend after the backend. */
2137
2138 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2139 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002140 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
Liam Girdwood01d75842012-04-25 12:12:49 +01002141 goto out;
2142 }
2143
Liam Girdwood103d84a2012-11-19 14:39:15 +00002144 dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002145 fe->dai_link->name, cmd);
2146
2147 ret = soc_pcm_trigger(substream, cmd);
2148 break;
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002149 case SND_SOC_DPCM_TRIGGER_BESPOKE:
2150 /* bespoke trigger() - handles both FE and BEs */
2151
Liam Girdwood103d84a2012-11-19 14:39:15 +00002152 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002153 fe->dai_link->name, cmd);
2154
2155 ret = soc_pcm_bespoke_trigger(substream, cmd);
2156 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002157 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002158 goto out;
2159 }
2160 break;
Liam Girdwood01d75842012-04-25 12:12:49 +01002161 default:
Liam Girdwood103d84a2012-11-19 14:39:15 +00002162 dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
Liam Girdwood01d75842012-04-25 12:12:49 +01002163 fe->dai_link->name);
2164 ret = -EINVAL;
2165 goto out;
2166 }
2167
2168 switch (cmd) {
2169 case SNDRV_PCM_TRIGGER_START:
2170 case SNDRV_PCM_TRIGGER_RESUME:
2171 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2172 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2173 break;
2174 case SNDRV_PCM_TRIGGER_STOP:
2175 case SNDRV_PCM_TRIGGER_SUSPEND:
Liam Girdwood01d75842012-04-25 12:12:49 +01002176 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2177 break;
Patrick Lai9f169b92016-12-31 22:44:39 -08002178 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2179 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2180 break;
Liam Girdwood01d75842012-04-25 12:12:49 +01002181 }
2182
2183out:
2184 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
2185 return ret;
2186}
2187
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002188static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
2189{
2190 struct snd_soc_pcm_runtime *fe = substream->private_data;
2191 int stream = substream->stream;
2192
2193 /* if FE's runtime_update is already set, we're in race;
2194 * process this trigger later at exit
2195 */
2196 if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2197 fe->dpcm[stream].trigger_pending = cmd + 1;
2198 return 0; /* delayed, assuming it's successful */
2199 }
2200
2201 /* we're alone, let's trigger */
2202 return dpcm_fe_dai_do_trigger(substream, cmd);
2203}
2204
Liam Girdwood23607022014-01-17 17:03:55 +00002205int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
Liam Girdwood01d75842012-04-25 12:12:49 +01002206{
2207 struct snd_soc_dpcm *dpcm;
2208 int ret = 0;
2209
2210 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2211
2212 struct snd_soc_pcm_runtime *be = dpcm->be;
2213 struct snd_pcm_substream *be_substream =
2214 snd_soc_dpcm_get_substream(be, stream);
2215
2216 /* is this op for this BE ? */
2217 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2218 continue;
2219
2220 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
Koro Chen95f444d2015-10-28 10:15:34 +08002221 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
2222 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
Liam Girdwood01d75842012-04-25 12:12:49 +01002223 continue;
2224
Liam Girdwood103d84a2012-11-19 14:39:15 +00002225 dev_dbg(be->dev, "ASoC: prepare BE %s\n",
彭东林94d215c2016-09-26 08:29:31 +00002226 be->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01002227
2228 ret = soc_pcm_prepare(be_substream);
2229 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002230 dev_err(be->dev, "ASoC: backend prepare failed %d\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002231 ret);
2232 break;
2233 }
2234
2235 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2236 }
2237 return ret;
2238}
2239
Mark Brown45c0a182012-05-09 21:46:27 +01002240static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
Liam Girdwood01d75842012-04-25 12:12:49 +01002241{
2242 struct snd_soc_pcm_runtime *fe = substream->private_data;
2243 int stream = substream->stream, ret = 0;
2244
2245 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2246
Liam Girdwood103d84a2012-11-19 14:39:15 +00002247 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
Liam Girdwood01d75842012-04-25 12:12:49 +01002248
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002249 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
Liam Girdwood01d75842012-04-25 12:12:49 +01002250
2251 /* there is no point preparing this FE if there are no BEs */
2252 if (list_empty(&fe->dpcm[stream].be_clients)) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002253 dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002254 fe->dai_link->name);
2255 ret = -EINVAL;
2256 goto out;
2257 }
2258
2259 ret = dpcm_be_dai_prepare(fe, substream->stream);
2260 if (ret < 0)
2261 goto out;
2262
2263 /* call prepare on the frontend */
2264 ret = soc_pcm_prepare(substream);
2265 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002266 dev_err(fe->dev,"ASoC: prepare FE %s failed\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002267 fe->dai_link->name);
2268 goto out;
2269 }
2270
2271 /* run the stream event for each BE */
2272 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
2273 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2274
2275out:
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002276 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood01d75842012-04-25 12:12:49 +01002277 mutex_unlock(&fe->card->mutex);
2278
2279 return ret;
2280}
2281
Liam Girdwoodbe3f3f22012-04-26 16:16:10 +01002282static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
2283 unsigned int cmd, void *arg)
2284{
2285 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2286 struct snd_soc_platform *platform = rtd->platform;
2287
Mark Brownc5914b02013-10-30 17:47:39 -07002288 if (platform->driver->ops && platform->driver->ops->ioctl)
Liam Girdwoodbe3f3f22012-04-26 16:16:10 +01002289 return platform->driver->ops->ioctl(substream, cmd, arg);
2290 return snd_pcm_lib_ioctl(substream, cmd, arg);
2291}
2292
Liam Girdwood618dae12012-04-25 12:12:51 +01002293static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
2294{
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002295 struct snd_pcm_substream *substream =
2296 snd_soc_dpcm_get_substream(fe, stream);
2297 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
Liam Girdwood618dae12012-04-25 12:12:51 +01002298 int err;
Liam Girdwood01d75842012-04-25 12:12:49 +01002299
Liam Girdwood103d84a2012-11-19 14:39:15 +00002300 dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
Liam Girdwood618dae12012-04-25 12:12:51 +01002301 stream ? "capture" : "playback", fe->dai_link->name);
2302
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002303 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2304 /* call bespoke trigger - FE takes care of all BE triggers */
Liam Girdwood103d84a2012-11-19 14:39:15 +00002305 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002306 fe->dai_link->name);
2307
2308 err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
2309 if (err < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002310 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002311 } else {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002312 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002313 fe->dai_link->name);
2314
2315 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
2316 if (err < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002317 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002318 }
Liam Girdwood618dae12012-04-25 12:12:51 +01002319
2320 err = dpcm_be_dai_hw_free(fe, stream);
2321 if (err < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002322 dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err);
Liam Girdwood618dae12012-04-25 12:12:51 +01002323
2324 err = dpcm_be_dai_shutdown(fe, stream);
2325 if (err < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002326 dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err);
Liam Girdwood618dae12012-04-25 12:12:51 +01002327
2328 /* run the stream event for each BE */
2329 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2330
2331 return 0;
2332}
2333
2334static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
2335{
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002336 struct snd_pcm_substream *substream =
2337 snd_soc_dpcm_get_substream(fe, stream);
Liam Girdwood618dae12012-04-25 12:12:51 +01002338 struct snd_soc_dpcm *dpcm;
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002339 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
Liam Girdwood618dae12012-04-25 12:12:51 +01002340 int ret;
2341
Liam Girdwood103d84a2012-11-19 14:39:15 +00002342 dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
Liam Girdwood618dae12012-04-25 12:12:51 +01002343 stream ? "capture" : "playback", fe->dai_link->name);
2344
2345 /* Only start the BE if the FE is ready */
2346 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
2347 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2348 return -EINVAL;
2349
2350 /* startup must always be called for new BEs */
2351 ret = dpcm_be_dai_startup(fe, stream);
Dan Carpenterfffc0ca2013-01-10 11:59:57 +03002352 if (ret < 0)
Liam Girdwood618dae12012-04-25 12:12:51 +01002353 goto disconnect;
Liam Girdwood618dae12012-04-25 12:12:51 +01002354
2355 /* keep going if FE state is > open */
2356 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
2357 return 0;
2358
2359 ret = dpcm_be_dai_hw_params(fe, stream);
Dan Carpenterfffc0ca2013-01-10 11:59:57 +03002360 if (ret < 0)
Liam Girdwood618dae12012-04-25 12:12:51 +01002361 goto close;
Liam Girdwood618dae12012-04-25 12:12:51 +01002362
2363 /* keep going if FE state is > hw_params */
2364 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
2365 return 0;
2366
2367
2368 ret = dpcm_be_dai_prepare(fe, stream);
Dan Carpenterfffc0ca2013-01-10 11:59:57 +03002369 if (ret < 0)
Liam Girdwood618dae12012-04-25 12:12:51 +01002370 goto hw_free;
Liam Girdwood618dae12012-04-25 12:12:51 +01002371
2372 /* run the stream event for each BE */
2373 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2374
2375 /* keep going if FE state is > prepare */
2376 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
2377 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
2378 return 0;
2379
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002380 if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2381 /* call trigger on the frontend - FE takes care of all BE triggers */
Liam Girdwood103d84a2012-11-19 14:39:15 +00002382 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002383 fe->dai_link->name);
Liam Girdwood618dae12012-04-25 12:12:51 +01002384
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002385 ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
2386 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002387 dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret);
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002388 goto hw_free;
2389 }
2390 } else {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002391 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002392 fe->dai_link->name);
2393
2394 ret = dpcm_be_dai_trigger(fe, stream,
2395 SNDRV_PCM_TRIGGER_START);
2396 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002397 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
Liam Girdwood07bf84a2012-04-25 12:12:52 +01002398 goto hw_free;
2399 }
Liam Girdwood618dae12012-04-25 12:12:51 +01002400 }
2401
2402 return 0;
2403
2404hw_free:
2405 dpcm_be_dai_hw_free(fe, stream);
2406close:
2407 dpcm_be_dai_shutdown(fe, stream);
2408disconnect:
2409 /* disconnect any non started BEs */
2410 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2411 struct snd_soc_pcm_runtime *be = dpcm->be;
2412 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2413 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2414 }
2415
2416 return ret;
2417}
2418
2419static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
2420{
2421 int ret;
2422
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002423 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
Liam Girdwood618dae12012-04-25 12:12:51 +01002424 ret = dpcm_run_update_startup(fe, stream);
2425 if (ret < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002426 dev_err(fe->dev, "ASoC: failed to startup some BEs\n");
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002427 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood618dae12012-04-25 12:12:51 +01002428
2429 return ret;
2430}
2431
2432static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
2433{
2434 int ret;
2435
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002436 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
Liam Girdwood618dae12012-04-25 12:12:51 +01002437 ret = dpcm_run_update_shutdown(fe, stream);
2438 if (ret < 0)
Liam Girdwood103d84a2012-11-19 14:39:15 +00002439 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
Takashi Iwaiea9d0d72014-11-04 16:52:28 +01002440 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
Liam Girdwood618dae12012-04-25 12:12:51 +01002441
2442 return ret;
2443}
2444
2445/* Called by DAPM mixer/mux changes to update audio routing between PCMs and
2446 * any DAI links.
2447 */
Lars-Peter Clausenc3f48ae2013-07-24 15:27:36 +02002448int soc_dpcm_runtime_update(struct snd_soc_card *card)
Liam Girdwood618dae12012-04-25 12:12:51 +01002449{
Mengdong Lin1a497982015-11-18 02:34:11 -05002450 struct snd_soc_pcm_runtime *fe;
2451 int old, new, paths;
Liam Girdwood618dae12012-04-25 12:12:51 +01002452
Liam Girdwood618dae12012-04-25 12:12:51 +01002453 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
Mengdong Lin1a497982015-11-18 02:34:11 -05002454 list_for_each_entry(fe, &card->rtd_list, list) {
Liam Girdwood618dae12012-04-25 12:12:51 +01002455 struct snd_soc_dapm_widget_list *list;
Liam Girdwood618dae12012-04-25 12:12:51 +01002456
2457 /* make sure link is FE */
2458 if (!fe->dai_link->dynamic)
2459 continue;
2460
2461 /* only check active links */
2462 if (!fe->cpu_dai->active)
2463 continue;
2464
2465 /* DAPM sync will call this to update DSP paths */
Liam Girdwood103d84a2012-11-19 14:39:15 +00002466 dev_dbg(fe->dev, "ASoC: DPCM runtime update for FE %s\n",
Liam Girdwood618dae12012-04-25 12:12:51 +01002467 fe->dai_link->name);
2468
2469 /* skip if FE doesn't have playback capability */
Qiao Zhou075207d2014-11-17 16:02:57 +08002470 if (!fe->cpu_dai->driver->playback.channels_min
2471 || !fe->codec_dai->driver->playback.channels_min)
2472 goto capture;
2473
2474 /* skip if FE isn't currently playing */
2475 if (!fe->cpu_dai->playback_active
2476 || !fe->codec_dai->playback_active)
Liam Girdwood618dae12012-04-25 12:12:51 +01002477 goto capture;
2478
2479 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
2480 if (paths < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002481 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
Liam Girdwood618dae12012-04-25 12:12:51 +01002482 fe->dai_link->name, "playback");
2483 mutex_unlock(&card->mutex);
2484 return paths;
2485 }
2486
2487 /* update any new playback paths */
2488 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1);
2489 if (new) {
2490 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2491 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
2492 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2493 }
2494
2495 /* update any old playback paths */
2496 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0);
2497 if (old) {
2498 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2499 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
2500 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2501 }
2502
Qiao Zhou7ed9de72014-06-04 19:42:06 +08002503 dpcm_path_put(&list);
Liam Girdwood618dae12012-04-25 12:12:51 +01002504capture:
2505 /* skip if FE doesn't have capture capability */
Qiao Zhou075207d2014-11-17 16:02:57 +08002506 if (!fe->cpu_dai->driver->capture.channels_min
2507 || !fe->codec_dai->driver->capture.channels_min)
2508 continue;
2509
2510 /* skip if FE isn't currently capturing */
2511 if (!fe->cpu_dai->capture_active
2512 || !fe->codec_dai->capture_active)
Liam Girdwood618dae12012-04-25 12:12:51 +01002513 continue;
2514
2515 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
2516 if (paths < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002517 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
Liam Girdwood618dae12012-04-25 12:12:51 +01002518 fe->dai_link->name, "capture");
2519 mutex_unlock(&card->mutex);
2520 return paths;
2521 }
2522
2523 /* update any new capture paths */
2524 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1);
2525 if (new) {
2526 dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2527 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
2528 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2529 }
2530
2531 /* update any old capture paths */
2532 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0);
2533 if (old) {
2534 dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2535 dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
2536 dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2537 }
2538
2539 dpcm_path_put(&list);
2540 }
2541
2542 mutex_unlock(&card->mutex);
2543 return 0;
2544}
Liam Girdwood01d75842012-04-25 12:12:49 +01002545int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
2546{
2547 struct snd_soc_dpcm *dpcm;
2548 struct list_head *clients =
2549 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients;
2550
2551 list_for_each_entry(dpcm, clients, list_be) {
2552
2553 struct snd_soc_pcm_runtime *be = dpcm->be;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002554 int i;
Liam Girdwood01d75842012-04-25 12:12:49 +01002555
2556 if (be->dai_link->ignore_suspend)
2557 continue;
2558
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002559 for (i = 0; i < be->num_codecs; i++) {
2560 struct snd_soc_dai *dai = be->codec_dais[i];
2561 struct snd_soc_dai_driver *drv = dai->driver;
Liam Girdwood01d75842012-04-25 12:12:49 +01002562
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002563 dev_dbg(be->dev, "ASoC: BE digital mute %s\n",
2564 be->dai_link->name);
2565
2566 if (drv->ops && drv->ops->digital_mute &&
2567 dai->playback_active)
2568 drv->ops->digital_mute(dai, mute);
2569 }
Liam Girdwood01d75842012-04-25 12:12:49 +01002570 }
2571
2572 return 0;
2573}
2574
Mark Brown45c0a182012-05-09 21:46:27 +01002575static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
Liam Girdwood01d75842012-04-25 12:12:49 +01002576{
2577 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2578 struct snd_soc_dpcm *dpcm;
2579 struct snd_soc_dapm_widget_list *list;
2580 int ret;
2581 int stream = fe_substream->stream;
2582
2583 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2584 fe->dpcm[stream].runtime = fe_substream->runtime;
2585
Qiao Zhou8f70e512014-09-10 17:54:07 +08002586 ret = dpcm_path_get(fe, stream, &list);
2587 if (ret < 0) {
2588 mutex_unlock(&fe->card->mutex);
2589 return ret;
2590 } else if (ret == 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002591 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
Liam Girdwood01d75842012-04-25 12:12:49 +01002592 fe->dai_link->name, stream ? "capture" : "playback");
Liam Girdwood01d75842012-04-25 12:12:49 +01002593 }
2594
2595 /* calculate valid and active FE <-> BE dpcms */
2596 dpcm_process_paths(fe, stream, &list, 1);
2597
2598 ret = dpcm_fe_dai_startup(fe_substream);
2599 if (ret < 0) {
2600 /* clean up all links */
2601 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
2602 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2603
2604 dpcm_be_disconnect(fe, stream);
2605 fe->dpcm[stream].runtime = NULL;
2606 }
2607
2608 dpcm_clear_pending_state(fe, stream);
2609 dpcm_path_put(&list);
2610 mutex_unlock(&fe->card->mutex);
2611 return ret;
2612}
2613
Mark Brown45c0a182012-05-09 21:46:27 +01002614static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
Liam Girdwood01d75842012-04-25 12:12:49 +01002615{
2616 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2617 struct snd_soc_dpcm *dpcm;
2618 int stream = fe_substream->stream, ret;
2619
2620 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2621 ret = dpcm_fe_dai_shutdown(fe_substream);
2622
2623 /* mark FE's links ready to prune */
2624 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
2625 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2626
2627 dpcm_be_disconnect(fe, stream);
2628
2629 fe->dpcm[stream].runtime = NULL;
2630 mutex_unlock(&fe->card->mutex);
2631 return ret;
2632}
2633
Liam Girdwoodddee6272011-06-09 14:45:53 +01002634/* create a new pcm */
2635int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2636{
Liam Girdwoodddee6272011-06-09 14:45:53 +01002637 struct snd_soc_platform *platform = rtd->platform;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002638 struct snd_soc_dai *codec_dai;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002639 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2640 struct snd_pcm *pcm;
2641 char new_name[64];
2642 int ret = 0, playback = 0, capture = 0;
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002643 int i;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002644
Liam Girdwood01d75842012-04-25 12:12:49 +01002645 if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
Liam Girdwood1e9de422014-01-07 17:51:42 +00002646 playback = rtd->dai_link->dpcm_playback;
2647 capture = rtd->dai_link->dpcm_capture;
Liam Girdwood01d75842012-04-25 12:12:49 +01002648 } else {
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002649 for (i = 0; i < rtd->num_codecs; i++) {
2650 codec_dai = rtd->codec_dais[i];
2651 if (codec_dai->driver->playback.channels_min)
2652 playback = 1;
2653 if (codec_dai->driver->capture.channels_min)
2654 capture = 1;
2655 }
2656
2657 capture = capture && cpu_dai->driver->capture.channels_min;
2658 playback = playback && cpu_dai->driver->playback.channels_min;
Liam Girdwood01d75842012-04-25 12:12:49 +01002659 }
Sangsu Parka5002312012-01-02 17:15:10 +09002660
Fabio Estevamd6bead02013-08-29 10:32:13 -03002661 if (rtd->dai_link->playback_only) {
2662 playback = 1;
2663 capture = 0;
2664 }
2665
2666 if (rtd->dai_link->capture_only) {
2667 playback = 0;
2668 capture = 1;
2669 }
2670
Liam Girdwood01d75842012-04-25 12:12:49 +01002671 /* create the PCM */
2672 if (rtd->dai_link->no_pcm) {
2673 snprintf(new_name, sizeof(new_name), "(%s)",
2674 rtd->dai_link->stream_name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002675
Liam Girdwood01d75842012-04-25 12:12:49 +01002676 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2677 playback, capture, &pcm);
2678 } else {
2679 if (rtd->dai_link->dynamic)
2680 snprintf(new_name, sizeof(new_name), "%s (*)",
2681 rtd->dai_link->stream_name);
2682 else
2683 snprintf(new_name, sizeof(new_name), "%s %s-%d",
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002684 rtd->dai_link->stream_name,
2685 (rtd->num_codecs > 1) ?
2686 "multicodec" : rtd->codec_dai->name, num);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002687
Liam Girdwood01d75842012-04-25 12:12:49 +01002688 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2689 capture, &pcm);
2690 }
Liam Girdwoodddee6272011-06-09 14:45:53 +01002691 if (ret < 0) {
Liam Girdwood103d84a2012-11-19 14:39:15 +00002692 dev_err(rtd->card->dev, "ASoC: can't create pcm for %s\n",
Liam Girdwood5cb9b742012-07-06 16:54:52 +01002693 rtd->dai_link->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002694 return ret;
2695 }
Liam Girdwood103d84a2012-11-19 14:39:15 +00002696 dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002697
2698 /* DAPM dai link stream work */
2699 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
2700
Vinod Koul48c76992015-02-12 09:59:53 +05302701 pcm->nonatomic = rtd->dai_link->nonatomic;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002702 rtd->pcm = pcm;
2703 pcm->private_data = rtd;
Liam Girdwood01d75842012-04-25 12:12:49 +01002704
2705 if (rtd->dai_link->no_pcm) {
2706 if (playback)
2707 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
2708 if (capture)
2709 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
2710 goto out;
2711 }
2712
2713 /* ASoC PCM operations */
2714 if (rtd->dai_link->dynamic) {
2715 rtd->ops.open = dpcm_fe_dai_open;
2716 rtd->ops.hw_params = dpcm_fe_dai_hw_params;
2717 rtd->ops.prepare = dpcm_fe_dai_prepare;
2718 rtd->ops.trigger = dpcm_fe_dai_trigger;
2719 rtd->ops.hw_free = dpcm_fe_dai_hw_free;
2720 rtd->ops.close = dpcm_fe_dai_close;
2721 rtd->ops.pointer = soc_pcm_pointer;
Liam Girdwoodbe3f3f22012-04-26 16:16:10 +01002722 rtd->ops.ioctl = soc_pcm_ioctl;
Liam Girdwood01d75842012-04-25 12:12:49 +01002723 } else {
2724 rtd->ops.open = soc_pcm_open;
2725 rtd->ops.hw_params = soc_pcm_hw_params;
2726 rtd->ops.prepare = soc_pcm_prepare;
2727 rtd->ops.trigger = soc_pcm_trigger;
2728 rtd->ops.hw_free = soc_pcm_hw_free;
2729 rtd->ops.close = soc_pcm_close;
2730 rtd->ops.pointer = soc_pcm_pointer;
Liam Girdwoodbe3f3f22012-04-26 16:16:10 +01002731 rtd->ops.ioctl = soc_pcm_ioctl;
Liam Girdwood01d75842012-04-25 12:12:49 +01002732 }
2733
Liam Girdwoodddee6272011-06-09 14:45:53 +01002734 if (platform->driver->ops) {
Liam Girdwood01d75842012-04-25 12:12:49 +01002735 rtd->ops.ack = platform->driver->ops->ack;
Takashi Iwai29d1a872017-05-10 20:02:35 +02002736 rtd->ops.copy_user = platform->driver->ops->copy_user;
2737 rtd->ops.copy_kernel = platform->driver->ops->copy_kernel;
2738 rtd->ops.fill_silence = platform->driver->ops->fill_silence;
Liam Girdwood01d75842012-04-25 12:12:49 +01002739 rtd->ops.page = platform->driver->ops->page;
2740 rtd->ops.mmap = platform->driver->ops->mmap;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002741 }
2742
2743 if (playback)
Liam Girdwood01d75842012-04-25 12:12:49 +01002744 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002745
2746 if (capture)
Liam Girdwood01d75842012-04-25 12:12:49 +01002747 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002748
Johan Hovoldc641e5b2017-07-12 17:55:29 +02002749 if (platform->driver->pcm_new) {
2750 ret = platform->driver->pcm_new(rtd);
2751 if (ret < 0) {
2752 dev_err(platform->dev,
2753 "ASoC: pcm constructor failed: %d\n",
2754 ret);
2755 return ret;
Liam Girdwoodddee6272011-06-09 14:45:53 +01002756 }
2757 }
Johan Hovoldc641e5b2017-07-12 17:55:29 +02002758
2759 pcm->private_free = platform->driver->pcm_free;
Liam Girdwood01d75842012-04-25 12:12:49 +01002760out:
Benoit Cousson2e5894d2014-07-08 23:19:35 +02002761 dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
2762 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
2763 cpu_dai->name);
Liam Girdwoodddee6272011-06-09 14:45:53 +01002764 return ret;
2765}
Liam Girdwood01d75842012-04-25 12:12:49 +01002766
2767/* is the current PCM operation for this FE ? */
2768int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2769{
2770 if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2771 return 1;
2772 return 0;
2773}
2774EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
2775
2776/* is the current PCM operation for this BE ? */
2777int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2778 struct snd_soc_pcm_runtime *be, int stream)
2779{
2780 if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2781 ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2782 be->dpcm[stream].runtime_update))
2783 return 1;
2784 return 0;
2785}
2786EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
2787
2788/* get the substream for this BE */
2789struct snd_pcm_substream *
2790 snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
2791{
2792 return be->pcm->streams[stream].substream;
2793}
2794EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
2795
2796/* get the BE runtime state */
2797enum snd_soc_dpcm_state
2798 snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream)
2799{
2800 return be->dpcm[stream].state;
2801}
2802EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state);
2803
2804/* set the BE runtime state */
2805void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be,
2806 int stream, enum snd_soc_dpcm_state state)
2807{
2808 be->dpcm[stream].state = state;
2809}
2810EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state);
2811
2812/*
2813 * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2814 * are not running, paused or suspended for the specified stream direction.
2815 */
2816int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2817 struct snd_soc_pcm_runtime *be, int stream)
2818{
2819 struct snd_soc_dpcm *dpcm;
2820 int state;
2821
2822 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2823
2824 if (dpcm->fe == fe)
2825 continue;
2826
2827 state = dpcm->fe->dpcm[stream].state;
2828 if (state == SND_SOC_DPCM_STATE_START ||
2829 state == SND_SOC_DPCM_STATE_PAUSED ||
2830 state == SND_SOC_DPCM_STATE_SUSPEND)
2831 return 0;
2832 }
2833
2834 /* it's safe to free/stop this BE DAI */
2835 return 1;
2836}
2837EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
2838
2839/*
2840 * We can only change hw params a BE DAI if any of it's FE are not prepared,
2841 * running, paused or suspended for the specified stream direction.
2842 */
2843int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2844 struct snd_soc_pcm_runtime *be, int stream)
2845{
2846 struct snd_soc_dpcm *dpcm;
2847 int state;
2848
2849 list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2850
2851 if (dpcm->fe == fe)
2852 continue;
2853
2854 state = dpcm->fe->dpcm[stream].state;
2855 if (state == SND_SOC_DPCM_STATE_START ||
2856 state == SND_SOC_DPCM_STATE_PAUSED ||
2857 state == SND_SOC_DPCM_STATE_SUSPEND ||
2858 state == SND_SOC_DPCM_STATE_PREPARE)
2859 return 0;
2860 }
2861
2862 /* it's safe to change hw_params */
2863 return 1;
2864}
2865EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002866
2867#ifdef CONFIG_DEBUG_FS
Lars-Peter Clausen852801412016-11-22 11:29:14 +01002868static const char *dpcm_state_string(enum snd_soc_dpcm_state state)
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002869{
2870 switch (state) {
2871 case SND_SOC_DPCM_STATE_NEW:
2872 return "new";
2873 case SND_SOC_DPCM_STATE_OPEN:
2874 return "open";
2875 case SND_SOC_DPCM_STATE_HW_PARAMS:
2876 return "hw_params";
2877 case SND_SOC_DPCM_STATE_PREPARE:
2878 return "prepare";
2879 case SND_SOC_DPCM_STATE_START:
2880 return "start";
2881 case SND_SOC_DPCM_STATE_STOP:
2882 return "stop";
2883 case SND_SOC_DPCM_STATE_SUSPEND:
2884 return "suspend";
2885 case SND_SOC_DPCM_STATE_PAUSED:
2886 return "paused";
2887 case SND_SOC_DPCM_STATE_HW_FREE:
2888 return "hw_free";
2889 case SND_SOC_DPCM_STATE_CLOSE:
2890 return "close";
2891 }
2892
2893 return "unknown";
2894}
2895
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002896static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
2897 int stream, char *buf, size_t size)
2898{
2899 struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
2900 struct snd_soc_dpcm *dpcm;
2901 ssize_t offset = 0;
2902
2903 /* FE state */
2904 offset += snprintf(buf + offset, size - offset,
2905 "[%s - %s]\n", fe->dai_link->name,
2906 stream ? "Capture" : "Playback");
2907
2908 offset += snprintf(buf + offset, size - offset, "State: %s\n",
2909 dpcm_state_string(fe->dpcm[stream].state));
2910
2911 if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2912 (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2913 offset += snprintf(buf + offset, size - offset,
2914 "Hardware Params: "
2915 "Format = %s, Channels = %d, Rate = %d\n",
2916 snd_pcm_format_name(params_format(params)),
2917 params_channels(params),
2918 params_rate(params));
2919
2920 /* BEs state */
2921 offset += snprintf(buf + offset, size - offset, "Backends:\n");
2922
2923 if (list_empty(&fe->dpcm[stream].be_clients)) {
2924 offset += snprintf(buf + offset, size - offset,
2925 " No active DSP links\n");
2926 goto out;
2927 }
2928
2929 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2930 struct snd_soc_pcm_runtime *be = dpcm->be;
2931 params = &dpcm->hw_params;
2932
2933 offset += snprintf(buf + offset, size - offset,
2934 "- %s\n", be->dai_link->name);
2935
2936 offset += snprintf(buf + offset, size - offset,
2937 " State: %s\n",
2938 dpcm_state_string(be->dpcm[stream].state));
2939
2940 if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2941 (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2942 offset += snprintf(buf + offset, size - offset,
2943 " Hardware Params: "
2944 "Format = %s, Channels = %d, Rate = %d\n",
2945 snd_pcm_format_name(params_format(params)),
2946 params_channels(params),
2947 params_rate(params));
2948 }
2949
2950out:
2951 return offset;
2952}
2953
2954static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
2955 size_t count, loff_t *ppos)
2956{
2957 struct snd_soc_pcm_runtime *fe = file->private_data;
2958 ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
2959 char *buf;
2960
2961 buf = kmalloc(out_count, GFP_KERNEL);
2962 if (!buf)
2963 return -ENOMEM;
2964
2965 if (fe->cpu_dai->driver->playback.channels_min)
2966 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK,
2967 buf + offset, out_count - offset);
2968
2969 if (fe->cpu_dai->driver->capture.channels_min)
2970 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE,
2971 buf + offset, out_count - offset);
2972
Liam Girdwoodf57b8482012-04-27 11:33:46 +01002973 ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002974
Liam Girdwoodf57b8482012-04-27 11:33:46 +01002975 kfree(buf);
2976 return ret;
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002977}
2978
2979static const struct file_operations dpcm_state_fops = {
Liam Girdwoodf57b8482012-04-27 11:33:46 +01002980 .open = simple_open,
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002981 .read = dpcm_state_read_file,
2982 .llseek = default_llseek,
2983};
2984
Lars-Peter Clausen2e55b902015-04-09 10:52:37 +02002985void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002986{
Mark Brownb3bba9a2012-05-08 10:33:47 +01002987 if (!rtd->dai_link)
Lars-Peter Clausen2e55b902015-04-09 10:52:37 +02002988 return;
Mark Brownb3bba9a2012-05-08 10:33:47 +01002989
Lars-Peter Clausen6553bf062015-04-09 10:52:38 +02002990 if (!rtd->card->debugfs_card_root)
2991 return;
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01002992
2993 rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
2994 rtd->card->debugfs_card_root);
2995 if (!rtd->debugfs_dpcm_root) {
2996 dev_dbg(rtd->dev,
2997 "ASoC: Failed to create dpcm debugfs directory %s\n",
2998 rtd->dai_link->name);
Lars-Peter Clausen2e55b902015-04-09 10:52:37 +02002999 return;
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01003000 }
3001
Fabio Estevamf1e3f402017-07-29 11:40:55 -03003002 debugfs_create_file("state", 0444, rtd->debugfs_dpcm_root,
3003 rtd, &dpcm_state_fops);
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01003004}
3005#endif