~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/soc-pcm.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * soc-pcm.c  --  ALSA SoC PCM
  3  *
  4  * Copyright 2005 Wolfson Microelectronics PLC.
  5  * Copyright 2005 Openedhand Ltd.
  6  * Copyright (C) 2010 Slimlogic Ltd.
  7  * Copyright (C) 2010 Texas Instruments Inc.
  8  *
  9  * Authors: Liam Girdwood <lrg@ti.com>
 10  *          Mark Brown <broonie@opensource.wolfsonmicro.com>
 11  *
 12  *  This program is free software; you can redistribute  it and/or modify it
 13  *  under  the terms of  the GNU General  Public License as published by the
 14  *  Free Software Foundation;  either version 2 of the  License, or (at your
 15  *  option) any later version.
 16  *
 17  */
 18 
 19 #include <linux/kernel.h>
 20 #include <linux/init.h>
 21 #include <linux/delay.h>
 22 #include <linux/pinctrl/consumer.h>
 23 #include <linux/pm_runtime.h>
 24 #include <linux/slab.h>
 25 #include <linux/workqueue.h>
 26 #include <linux/export.h>
 27 #include <linux/debugfs.h>
 28 #include <sound/core.h>
 29 #include <sound/pcm.h>
 30 #include <sound/pcm_params.h>
 31 #include <sound/soc.h>
 32 #include <sound/soc-dpcm.h>
 33 #include <sound/initval.h>
 34 
 35 #define DPCM_MAX_BE_USERS       8
 36 
 37 /**
 38  * snd_soc_runtime_activate() - Increment active count for PCM runtime components
 39  * @rtd: ASoC PCM runtime that is activated
 40  * @stream: Direction of the PCM stream
 41  *
 42  * Increments the active count for all the DAIs and components attached to a PCM
 43  * runtime. Should typically be called when a stream is opened.
 44  *
 45  * Must be called with the rtd->pcm_mutex being held
 46  */
 47 void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
 48 {
 49         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 50         int i;
 51 
 52         lockdep_assert_held(&rtd->pcm_mutex);
 53 
 54         if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
 55                 cpu_dai->playback_active++;
 56                 for (i = 0; i < rtd->num_codecs; i++)
 57                         rtd->codec_dais[i]->playback_active++;
 58         } else {
 59                 cpu_dai->capture_active++;
 60                 for (i = 0; i < rtd->num_codecs; i++)
 61                         rtd->codec_dais[i]->capture_active++;
 62         }
 63 
 64         cpu_dai->active++;
 65         cpu_dai->component->active++;
 66         for (i = 0; i < rtd->num_codecs; i++) {
 67                 rtd->codec_dais[i]->active++;
 68                 rtd->codec_dais[i]->component->active++;
 69         }
 70 }
 71 
 72 /**
 73  * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components
 74  * @rtd: ASoC PCM runtime that is deactivated
 75  * @stream: Direction of the PCM stream
 76  *
 77  * Decrements the active count for all the DAIs and components attached to a PCM
 78  * runtime. Should typically be called when a stream is closed.
 79  *
 80  * Must be called with the rtd->pcm_mutex being held
 81  */
 82 void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
 83 {
 84         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 85         int i;
 86 
 87         lockdep_assert_held(&rtd->pcm_mutex);
 88 
 89         if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
 90                 cpu_dai->playback_active--;
 91                 for (i = 0; i < rtd->num_codecs; i++)
 92                         rtd->codec_dais[i]->playback_active--;
 93         } else {
 94                 cpu_dai->capture_active--;
 95                 for (i = 0; i < rtd->num_codecs; i++)
 96                         rtd->codec_dais[i]->capture_active--;
 97         }
 98 
 99         cpu_dai->active--;
100         cpu_dai->component->active--;
101         for (i = 0; i < rtd->num_codecs; i++) {
102                 rtd->codec_dais[i]->component->active--;
103                 rtd->codec_dais[i]->active--;
104         }
105 }
106 
107 /**
108  * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
109  * @rtd: The ASoC PCM runtime that should be checked.
110  *
111  * This function checks whether the power down delay should be ignored for a
112  * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
113  * been configured to ignore the delay, or if none of the components benefits
114  * from having the delay.
115  */
116 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
117 {
118         int i;
119         bool ignore = true;
120 
121         if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
122                 return true;
123 
124         for (i = 0; i < rtd->num_codecs; i++)
125                 ignore &= rtd->codec_dais[i]->component->ignore_pmdown_time;
126 
127         return rtd->cpu_dai->component->ignore_pmdown_time && ignore;
128 }
129 
130 /**
131  * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
132  * @substream: the pcm substream
133  * @hw: the hardware parameters
134  *
135  * Sets the substream runtime hardware parameters.
136  */
137 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
138         const struct snd_pcm_hardware *hw)
139 {
140         struct snd_pcm_runtime *runtime = substream->runtime;
141         runtime->hw.info = hw->info;
142         runtime->hw.formats = hw->formats;
143         runtime->hw.period_bytes_min = hw->period_bytes_min;
144         runtime->hw.period_bytes_max = hw->period_bytes_max;
145         runtime->hw.periods_min = hw->periods_min;
146         runtime->hw.periods_max = hw->periods_max;
147         runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
148         runtime->hw.fifo_size = hw->fifo_size;
149         return 0;
150 }
151 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
152 
153 /* DPCM stream event, send event to FE and all active BEs. */
154 int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
155         int event)
156 {
157         struct snd_soc_dpcm *dpcm;
158 
159         list_for_each_entry(dpcm, &fe->dpcm[dir].be_clients, list_be) {
160 
161                 struct snd_soc_pcm_runtime *be = dpcm->be;
162 
163                 dev_dbg(be->dev, "ASoC: BE %s event %d dir %d\n",
164                                 be->dai_link->name, event, dir);
165 
166                 if ((event == SND_SOC_DAPM_STREAM_STOP) &&
167                     (be->dpcm[dir].users >= 1))
168                         continue;
169 
170                 snd_soc_dapm_stream_event(be, dir, event);
171         }
172 
173         snd_soc_dapm_stream_event(fe, dir, event);
174 
175         return 0;
176 }
177 
178 static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
179                                         struct snd_soc_dai *soc_dai)
180 {
181         struct snd_soc_pcm_runtime *rtd = substream->private_data;
182         int ret;
183 
184         if (soc_dai->rate && (soc_dai->driver->symmetric_rates ||
185                                 rtd->dai_link->symmetric_rates)) {
186                 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %dHz rate\n",
187                                 soc_dai->rate);
188 
189                 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
190                                                 SNDRV_PCM_HW_PARAM_RATE,
191                                                 soc_dai->rate, soc_dai->rate);
192                 if (ret < 0) {
193                         dev_err(soc_dai->dev,
194                                 "ASoC: Unable to apply rate constraint: %d\n",
195                                 ret);
196                         return ret;
197                 }
198         }
199 
200         if (soc_dai->channels && (soc_dai->driver->symmetric_channels ||
201                                 rtd->dai_link->symmetric_channels)) {
202                 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d channel(s)\n",
203                                 soc_dai->channels);
204 
205                 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
206                                                 SNDRV_PCM_HW_PARAM_CHANNELS,
207                                                 soc_dai->channels,
208                                                 soc_dai->channels);
209                 if (ret < 0) {
210                         dev_err(soc_dai->dev,
211                                 "ASoC: Unable to apply channel symmetry constraint: %d\n",
212                                 ret);
213                         return ret;
214                 }
215         }
216 
217         if (soc_dai->sample_bits && (soc_dai->driver->symmetric_samplebits ||
218                                 rtd->dai_link->symmetric_samplebits)) {
219                 dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d sample bits\n",
220                                 soc_dai->sample_bits);
221 
222                 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
223                                                 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
224                                                 soc_dai->sample_bits,
225                                                 soc_dai->sample_bits);
226                 if (ret < 0) {
227                         dev_err(soc_dai->dev,
228                                 "ASoC: Unable to apply sample bits symmetry constraint: %d\n",
229                                 ret);
230                         return ret;
231                 }
232         }
233 
234         return 0;
235 }
236 
237 static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
238                                 struct snd_pcm_hw_params *params)
239 {
240         struct snd_soc_pcm_runtime *rtd = substream->private_data;
241         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
242         unsigned int rate, channels, sample_bits, symmetry, i;
243 
244         rate = params_rate(params);
245         channels = params_channels(params);
246         sample_bits = snd_pcm_format_physical_width(params_format(params));
247 
248         /* reject unmatched parameters when applying symmetry */
249         symmetry = cpu_dai->driver->symmetric_rates ||
250                 rtd->dai_link->symmetric_rates;
251 
252         for (i = 0; i < rtd->num_codecs; i++)
253                 symmetry |= rtd->codec_dais[i]->driver->symmetric_rates;
254 
255         if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) {
256                 dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
257                                 cpu_dai->rate, rate);
258                 return -EINVAL;
259         }
260 
261         symmetry = cpu_dai->driver->symmetric_channels ||
262                 rtd->dai_link->symmetric_channels;
263 
264         for (i = 0; i < rtd->num_codecs; i++)
265                 symmetry |= rtd->codec_dais[i]->driver->symmetric_channels;
266 
267         if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) {
268                 dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
269                                 cpu_dai->channels, channels);
270                 return -EINVAL;
271         }
272 
273         symmetry = cpu_dai->driver->symmetric_samplebits ||
274                 rtd->dai_link->symmetric_samplebits;
275 
276         for (i = 0; i < rtd->num_codecs; i++)
277                 symmetry |= rtd->codec_dais[i]->driver->symmetric_samplebits;
278 
279         if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) {
280                 dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
281                                 cpu_dai->sample_bits, sample_bits);
282                 return -EINVAL;
283         }
284 
285         return 0;
286 }
287 
288 static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream)
289 {
290         struct snd_soc_pcm_runtime *rtd = substream->private_data;
291         struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver;
292         struct snd_soc_dai_link *link = rtd->dai_link;
293         unsigned int symmetry, i;
294 
295         symmetry = cpu_driver->symmetric_rates || link->symmetric_rates ||
296                 cpu_driver->symmetric_channels || link->symmetric_channels ||
297                 cpu_driver->symmetric_samplebits || link->symmetric_samplebits;
298 
299         for (i = 0; i < rtd->num_codecs; i++)
300                 symmetry = symmetry ||
301                         rtd->codec_dais[i]->driver->symmetric_rates ||
302                         rtd->codec_dais[i]->driver->symmetric_channels ||
303                         rtd->codec_dais[i]->driver->symmetric_samplebits;
304 
305         return symmetry;
306 }
307 
308 static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits)
309 {
310         struct snd_soc_pcm_runtime *rtd = substream->private_data;
311         int ret;
312 
313         if (!bits)
314                 return;
315 
316         ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 0, bits);
317         if (ret != 0)
318                 dev_warn(rtd->dev, "ASoC: Failed to set MSB %d: %d\n",
319                                  bits, ret);
320 }
321 
322 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
323 {
324         struct snd_soc_pcm_runtime *rtd = substream->private_data;
325         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
326         struct snd_soc_dai *codec_dai;
327         int i;
328         unsigned int bits = 0, cpu_bits;
329 
330         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
331                 for (i = 0; i < rtd->num_codecs; i++) {
332                         codec_dai = rtd->codec_dais[i];
333                         if (codec_dai->driver->playback.sig_bits == 0) {
334                                 bits = 0;
335                                 break;
336                         }
337                         bits = max(codec_dai->driver->playback.sig_bits, bits);
338                 }
339                 cpu_bits = cpu_dai->driver->playback.sig_bits;
340         } else {
341                 for (i = 0; i < rtd->num_codecs; i++) {
342                         codec_dai = rtd->codec_dais[i];
343                         if (codec_dai->driver->capture.sig_bits == 0) {
344                                 bits = 0;
345                                 break;
346                         }
347                         bits = max(codec_dai->driver->capture.sig_bits, bits);
348                 }
349                 cpu_bits = cpu_dai->driver->capture.sig_bits;
350         }
351 
352         soc_pcm_set_msb(substream, bits);
353         soc_pcm_set_msb(substream, cpu_bits);
354 }
355 
356 static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
357 {
358         struct snd_pcm_runtime *runtime = substream->runtime;
359         struct snd_pcm_hardware *hw = &runtime->hw;
360         struct snd_soc_pcm_runtime *rtd = substream->private_data;
361         struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver;
362         struct snd_soc_dai_driver *codec_dai_drv;
363         struct snd_soc_pcm_stream *codec_stream;
364         struct snd_soc_pcm_stream *cpu_stream;
365         unsigned int chan_min = 0, chan_max = UINT_MAX;
366         unsigned int rate_min = 0, rate_max = UINT_MAX;
367         unsigned int rates = UINT_MAX;
368         u64 formats = ULLONG_MAX;
369         int i;
370 
371         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
372                 cpu_stream = &cpu_dai_drv->playback;
373         else
374                 cpu_stream = &cpu_dai_drv->capture;
375 
376         /* first calculate min/max only for CODECs in the DAI link */
377         for (i = 0; i < rtd->num_codecs; i++) {
378                 codec_dai_drv = rtd->codec_dais[i]->driver;
379                 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
380                         codec_stream = &codec_dai_drv->playback;
381                 else
382                         codec_stream = &codec_dai_drv->capture;
383                 chan_min = max(chan_min, codec_stream->channels_min);
384                 chan_max = min(chan_max, codec_stream->channels_max);
385                 rate_min = max(rate_min, codec_stream->rate_min);
386                 rate_max = min_not_zero(rate_max, codec_stream->rate_max);
387                 formats &= codec_stream->formats;
388                 rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates);
389         }
390 
391         /*
392          * chan min/max cannot be enforced if there are multiple CODEC DAIs
393          * connected to a single CPU DAI, use CPU DAI's directly and let
394          * channel allocation be fixed up later
395          */
396         if (rtd->num_codecs > 1) {
397                 chan_min = cpu_stream->channels_min;
398                 chan_max = cpu_stream->channels_max;
399         }
400 
401         hw->channels_min = max(chan_min, cpu_stream->channels_min);
402         hw->channels_max = min(chan_max, cpu_stream->channels_max);
403         if (hw->formats)
404                 hw->formats &= formats & cpu_stream->formats;
405         else
406                 hw->formats = formats & cpu_stream->formats;
407         hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates);
408 
409         snd_pcm_limit_hw_rates(runtime);
410 
411         hw->rate_min = max(hw->rate_min, cpu_stream->rate_min);
412         hw->rate_min = max(hw->rate_min, rate_min);
413         hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max);
414         hw->rate_max = min_not_zero(hw->rate_max, rate_max);
415 }
416 
417 /*
418  * Called by ALSA when a PCM substream is opened, the runtime->hw record is
419  * then initialized and any private data can be allocated. This also calls
420  * startup for the cpu DAI, platform, machine and codec DAI.
421  */
422 static int soc_pcm_open(struct snd_pcm_substream *substream)
423 {
424         struct snd_soc_pcm_runtime *rtd = substream->private_data;
425         struct snd_pcm_runtime *runtime = substream->runtime;
426         struct snd_soc_platform *platform = rtd->platform;
427         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
428         struct snd_soc_dai *codec_dai;
429         const char *codec_dai_name = "multicodec";
430         int i, ret = 0;
431 
432         pinctrl_pm_select_default_state(cpu_dai->dev);
433         for (i = 0; i < rtd->num_codecs; i++)
434                 pinctrl_pm_select_default_state(rtd->codec_dais[i]->dev);
435         pm_runtime_get_sync(cpu_dai->dev);
436         for (i = 0; i < rtd->num_codecs; i++)
437                 pm_runtime_get_sync(rtd->codec_dais[i]->dev);
438         pm_runtime_get_sync(platform->dev);
439 
440         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
441 
442         /* startup the audio subsystem */
443         if (cpu_dai->driver->ops && cpu_dai->driver->ops->startup) {
444                 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
445                 if (ret < 0) {
446                         dev_err(cpu_dai->dev, "ASoC: can't open interface"
447                                 " %s: %d\n", cpu_dai->name, ret);
448                         goto out;
449                 }
450         }
451 
452         if (platform->driver->ops && platform->driver->ops->open) {
453                 ret = platform->driver->ops->open(substream);
454                 if (ret < 0) {
455                         dev_err(platform->dev, "ASoC: can't open platform"
456                                 " %s: %d\n", platform->component.name, ret);
457                         goto platform_err;
458                 }
459         }
460 
461         for (i = 0; i < rtd->num_codecs; i++) {
462                 codec_dai = rtd->codec_dais[i];
463                 if (codec_dai->driver->ops && codec_dai->driver->ops->startup) {
464                         ret = codec_dai->driver->ops->startup(substream,
465                                                               codec_dai);
466                         if (ret < 0) {
467                                 dev_err(codec_dai->dev,
468                                         "ASoC: can't open codec %s: %d\n",
469                                         codec_dai->name, ret);
470                                 goto codec_dai_err;
471                         }
472                 }
473 
474                 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
475                         codec_dai->tx_mask = 0;
476                 else
477                         codec_dai->rx_mask = 0;
478         }
479 
480         if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
481                 ret = rtd->dai_link->ops->startup(substream);
482                 if (ret < 0) {
483                         pr_err("ASoC: %s startup failed: %d\n",
484                                rtd->dai_link->name, ret);
485                         goto machine_err;
486                 }
487         }
488 
489         /* Dynamic PCM DAI links compat checks use dynamic capabilities */
490         if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
491                 goto dynamic;
492 
493         /* Check that the codec and cpu DAIs are compatible */
494         soc_pcm_init_runtime_hw(substream);
495 
496         if (rtd->num_codecs == 1)
497                 codec_dai_name = rtd->codec_dai->name;
498 
499         if (soc_pcm_has_symmetry(substream))
500                 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
501 
502         ret = -EINVAL;
503         if (!runtime->hw.rates) {
504                 printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
505                         codec_dai_name, cpu_dai->name);
506                 goto config_err;
507         }
508         if (!runtime->hw.formats) {
509                 printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
510                         codec_dai_name, cpu_dai->name);
511                 goto config_err;
512         }
513         if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
514             runtime->hw.channels_min > runtime->hw.channels_max) {
515                 printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
516                                 codec_dai_name, cpu_dai->name);
517                 goto config_err;
518         }
519 
520         soc_pcm_apply_msb(substream);
521 
522         /* Symmetry only applies if we've already got an active stream. */
523         if (cpu_dai->active) {
524                 ret = soc_pcm_apply_symmetry(substream, cpu_dai);
525                 if (ret != 0)
526                         goto config_err;
527         }
528 
529         for (i = 0; i < rtd->num_codecs; i++) {
530                 if (rtd->codec_dais[i]->active) {
531                         ret = soc_pcm_apply_symmetry(substream,
532                                                      rtd->codec_dais[i]);
533                         if (ret != 0)
534                                 goto config_err;
535                 }
536         }
537 
538         pr_debug("ASoC: %s <-> %s info:\n",
539                         codec_dai_name, cpu_dai->name);
540         pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
541         pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
542                  runtime->hw.channels_max);
543         pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min,
544                  runtime->hw.rate_max);
545 
546 dynamic:
547 
548         snd_soc_runtime_activate(rtd, substream->stream);
549 
550         mutex_unlock(&rtd->pcm_mutex);
551         return 0;
552 
553 config_err:
554         if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
555                 rtd->dai_link->ops->shutdown(substream);
556 
557 machine_err:
558         i = rtd->num_codecs;
559 
560 codec_dai_err:
561         while (--i >= 0) {
562                 codec_dai = rtd->codec_dais[i];
563                 if (codec_dai->driver->ops->shutdown)
564                         codec_dai->driver->ops->shutdown(substream, codec_dai);
565         }
566 
567         if (platform->driver->ops && platform->driver->ops->close)
568                 platform->driver->ops->close(substream);
569 
570 platform_err:
571         if (cpu_dai->driver->ops->shutdown)
572                 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
573 out:
574         mutex_unlock(&rtd->pcm_mutex);
575 
576         pm_runtime_put(platform->dev);
577         for (i = 0; i < rtd->num_codecs; i++)
578                 pm_runtime_put(rtd->codec_dais[i]->dev);
579         pm_runtime_put(cpu_dai->dev);
580         for (i = 0; i < rtd->num_codecs; i++) {
581                 if (!rtd->codec_dais[i]->active)
582                         pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
583         }
584         if (!cpu_dai->active)
585                 pinctrl_pm_select_sleep_state(cpu_dai->dev);
586 
587         return ret;
588 }
589 
590 /*
591  * Power down the audio subsystem pmdown_time msecs after close is called.
592  * This is to ensure there are no pops or clicks in between any music tracks
593  * due to DAPM power cycling.
594  */
595 static void close_delayed_work(struct work_struct *work)
596 {
597         struct snd_soc_pcm_runtime *rtd =
598                         container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
599         struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
600 
601         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
602 
603         dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n",
604                  codec_dai->driver->playback.stream_name,
605                  codec_dai->playback_active ? "active" : "inactive",
606                  rtd->pop_wait ? "yes" : "no");
607 
608         /* are we waiting on this codec DAI stream */
609         if (rtd->pop_wait == 1) {
610                 rtd->pop_wait = 0;
611                 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
612                                           SND_SOC_DAPM_STREAM_STOP);
613         }
614 
615         mutex_unlock(&rtd->pcm_mutex);
616 }
617 
618 /*
619  * Called by ALSA when a PCM substream is closed. Private data can be
620  * freed here. The cpu DAI, codec DAI, machine and platform are also
621  * shutdown.
622  */
623 static int soc_pcm_close(struct snd_pcm_substream *substream)
624 {
625         struct snd_soc_pcm_runtime *rtd = substream->private_data;
626         struct snd_soc_platform *platform = rtd->platform;
627         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
628         struct snd_soc_dai *codec_dai;
629         int i;
630 
631         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
632 
633         snd_soc_runtime_deactivate(rtd, substream->stream);
634 
635         /* clear the corresponding DAIs rate when inactive */
636         if (!cpu_dai->active)
637                 cpu_dai->rate = 0;
638 
639         for (i = 0; i < rtd->num_codecs; i++) {
640                 codec_dai = rtd->codec_dais[i];
641                 if (!codec_dai->active)
642                         codec_dai->rate = 0;
643         }
644 
645         snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream);
646 
647         if (cpu_dai->driver->ops->shutdown)
648                 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
649 
650         for (i = 0; i < rtd->num_codecs; i++) {
651                 codec_dai = rtd->codec_dais[i];
652                 if (codec_dai->driver->ops->shutdown)
653                         codec_dai->driver->ops->shutdown(substream, codec_dai);
654         }
655 
656         if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
657                 rtd->dai_link->ops->shutdown(substream);
658 
659         if (platform->driver->ops && platform->driver->ops->close)
660                 platform->driver->ops->close(substream);
661 
662         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
663                 if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
664                         /* powered down playback stream now */
665                         snd_soc_dapm_stream_event(rtd,
666                                                   SNDRV_PCM_STREAM_PLAYBACK,
667                                                   SND_SOC_DAPM_STREAM_STOP);
668                 } else {
669                         /* start delayed pop wq here for playback streams */
670                         rtd->pop_wait = 1;
671                         queue_delayed_work(system_power_efficient_wq,
672                                            &rtd->delayed_work,
673                                            msecs_to_jiffies(rtd->pmdown_time));
674                 }
675         } else {
676                 /* capture streams can be powered down now */
677                 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
678                                           SND_SOC_DAPM_STREAM_STOP);
679         }
680 
681         mutex_unlock(&rtd->pcm_mutex);
682 
683         pm_runtime_put(platform->dev);
684         for (i = 0; i < rtd->num_codecs; i++)
685                 pm_runtime_put(rtd->codec_dais[i]->dev);
686         pm_runtime_put(cpu_dai->dev);
687         for (i = 0; i < rtd->num_codecs; i++) {
688                 if (!rtd->codec_dais[i]->active)
689                         pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
690         }
691         if (!cpu_dai->active)
692                 pinctrl_pm_select_sleep_state(cpu_dai->dev);
693 
694         return 0;
695 }
696 
697 /*
698  * Called by ALSA when the PCM substream is prepared, can set format, sample
699  * rate, etc.  This function is non atomic and can be called multiple times,
700  * it can refer to the runtime info.
701  */
702 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
703 {
704         struct snd_soc_pcm_runtime *rtd = substream->private_data;
705         struct snd_soc_platform *platform = rtd->platform;
706         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
707         struct snd_soc_dai *codec_dai;
708         int i, ret = 0;
709 
710         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
711 
712         if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
713                 ret = rtd->dai_link->ops->prepare(substream);
714                 if (ret < 0) {
715                         dev_err(rtd->card->dev, "ASoC: machine prepare error:"
716                                 " %d\n", ret);
717                         goto out;
718                 }
719         }
720 
721         if (platform->driver->ops && platform->driver->ops->prepare) {
722                 ret = platform->driver->ops->prepare(substream);
723                 if (ret < 0) {
724                         dev_err(platform->dev, "ASoC: platform prepare error:"
725                                 " %d\n", ret);
726                         goto out;
727                 }
728         }
729 
730         for (i = 0; i < rtd->num_codecs; i++) {
731                 codec_dai = rtd->codec_dais[i];
732                 if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) {
733                         ret = codec_dai->driver->ops->prepare(substream,
734                                                               codec_dai);
735                         if (ret < 0) {
736                                 dev_err(codec_dai->dev,
737                                         "ASoC: codec DAI prepare error: %d\n",
738                                         ret);
739                                 goto out;
740                         }
741                 }
742         }
743 
744         if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) {
745                 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
746                 if (ret < 0) {
747                         dev_err(cpu_dai->dev,
748                                 "ASoC: cpu DAI prepare error: %d\n", ret);
749                         goto out;
750                 }
751         }
752 
753         /* cancel any delayed stream shutdown that is pending */
754         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
755             rtd->pop_wait) {
756                 rtd->pop_wait = 0;
757                 cancel_delayed_work(&rtd->delayed_work);
758         }
759 
760         snd_soc_dapm_stream_event(rtd, substream->stream,
761                         SND_SOC_DAPM_STREAM_START);
762 
763         for (i = 0; i < rtd->num_codecs; i++)
764                 snd_soc_dai_digital_mute(rtd->codec_dais[i], 0,
765                                          substream->stream);
766         snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream);
767 
768 out:
769         mutex_unlock(&rtd->pcm_mutex);
770         return ret;
771 }
772 
773 static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
774                                        unsigned int mask)
775 {
776         struct snd_interval *interval;
777         int channels = hweight_long(mask);
778 
779         interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
780         interval->min = channels;
781         interval->max = channels;
782 }
783 
784 int soc_dai_hw_params(struct snd_pcm_substream *substream,
785                       struct snd_pcm_hw_params *params,
786                       struct snd_soc_dai *dai)
787 {
788         int ret;
789 
790         if (dai->driver->ops && dai->driver->ops->hw_params) {
791                 ret = dai->driver->ops->hw_params(substream, params, dai);
792                 if (ret < 0) {
793                         dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
794                                 dai->name, ret);
795                         return ret;
796                 }
797         }
798 
799         return 0;
800 }
801 
802 /*
803  * Called by ALSA when the hardware params are set by application. This
804  * function can also be called multiple times and can allocate buffers
805  * (using snd_pcm_lib_* ). It's non-atomic.
806  */
807 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
808                                 struct snd_pcm_hw_params *params)
809 {
810         struct snd_soc_pcm_runtime *rtd = substream->private_data;
811         struct snd_soc_platform *platform = rtd->platform;
812         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
813         int i, ret = 0;
814 
815         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
816 
817         ret = soc_pcm_params_symmetry(substream, params);
818         if (ret)
819                 goto out;
820 
821         if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
822                 ret = rtd->dai_link->ops->hw_params(substream, params);
823                 if (ret < 0) {
824                         dev_err(rtd->card->dev, "ASoC: machine hw_params"
825                                 " failed: %d\n", ret);
826                         goto out;
827                 }
828         }
829 
830         for (i = 0; i < rtd->num_codecs; i++) {
831                 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
832                 struct snd_pcm_hw_params codec_params;
833 
834                 /* copy params for each codec */
835                 codec_params = *params;
836 
837                 /* fixup params based on TDM slot masks */
838                 if (codec_dai->tx_mask)
839                         soc_pcm_codec_params_fixup(&codec_params,
840                                                    codec_dai->tx_mask);
841                 if (codec_dai->rx_mask)
842                         soc_pcm_codec_params_fixup(&codec_params,
843                                                    codec_dai->rx_mask);
844 
845                 ret = soc_dai_hw_params(substream, &codec_params, codec_dai);
846                 if(ret < 0)
847                         goto codec_err;
848 
849                 codec_dai->rate = params_rate(&codec_params);
850                 codec_dai->channels = params_channels(&codec_params);
851                 codec_dai->sample_bits = snd_pcm_format_physical_width(
852                                                 params_format(&codec_params));
853         }
854 
855         ret = soc_dai_hw_params(substream, params, cpu_dai);
856         if (ret < 0)
857                 goto interface_err;
858 
859         if (platform->driver->ops && platform->driver->ops->hw_params) {
860                 ret = platform->driver->ops->hw_params(substream, params);
861                 if (ret < 0) {
862                         dev_err(platform->dev, "ASoC: %s hw params failed: %d\n",
863                                platform->component.name, ret);
864                         goto platform_err;
865                 }
866         }
867 
868         /* store the parameters for each DAIs */
869         cpu_dai->rate = params_rate(params);
870         cpu_dai->channels = params_channels(params);
871         cpu_dai->sample_bits =
872                 snd_pcm_format_physical_width(params_format(params));
873 
874 out:
875         mutex_unlock(&rtd->pcm_mutex);
876         return ret;
877 
878 platform_err:
879         if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
880                 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
881 
882 interface_err:
883         i = rtd->num_codecs;
884 
885 codec_err:
886         while (--i >= 0) {
887                 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
888                 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
889                         codec_dai->driver->ops->hw_free(substream, codec_dai);
890                 codec_dai->rate = 0;
891         }
892 
893         if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
894                 rtd->dai_link->ops->hw_free(substream);
895 
896         mutex_unlock(&rtd->pcm_mutex);
897         return ret;
898 }
899 
900 /*
901  * Frees resources allocated by hw_params, can be called multiple times
902  */
903 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
904 {
905         struct snd_soc_pcm_runtime *rtd = substream->private_data;
906         struct snd_soc_platform *platform = rtd->platform;
907         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
908         struct snd_soc_dai *codec_dai;
909         bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
910         int i;
911 
912         mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
913 
914         /* clear the corresponding DAIs parameters when going to be inactive */
915         if (cpu_dai->active == 1) {
916                 cpu_dai->rate = 0;
917                 cpu_dai->channels = 0;
918                 cpu_dai->sample_bits = 0;
919         }
920 
921         for (i = 0; i < rtd->num_codecs; i++) {
922                 codec_dai = rtd->codec_dais[i];
923                 if (codec_dai->active == 1) {
924                         codec_dai->rate = 0;
925                         codec_dai->channels = 0;
926                         codec_dai->sample_bits = 0;
927                 }
928         }
929 
930         /* apply codec digital mute */
931         for (i = 0; i < rtd->num_codecs; i++) {
932                 if ((playback && rtd->codec_dais[i]->playback_active == 1) ||
933                     (!playback && rtd->codec_dais[i]->capture_active == 1))
934                         snd_soc_dai_digital_mute(rtd->codec_dais[i], 1,
935                                                  substream->stream);
936         }
937 
938         /* free any machine hw params */
939         if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
940                 rtd->dai_link->ops->hw_free(substream);
941 
942         /* free any DMA resources */
943         if (platform->driver->ops && platform->driver->ops->hw_free)
944                 platform->driver->ops->hw_free(substream);
945 
946         /* now free hw params for the DAIs  */
947         for (i = 0; i < rtd->num_codecs; i++) {
948                 codec_dai = rtd->codec_dais[i];
949                 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
950                         codec_dai->driver->ops->hw_free(substream, codec_dai);
951         }
952 
953         if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
954                 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
955 
956         mutex_unlock(&rtd->pcm_mutex);
957         return 0;
958 }
959 
960 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
961 {
962         struct snd_soc_pcm_runtime *rtd = substream->private_data;
963         struct snd_soc_platform *platform = rtd->platform;
964         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
965         struct snd_soc_dai *codec_dai;
966         int i, ret;
967 
968         for (i = 0; i < rtd->num_codecs; i++) {
969                 codec_dai = rtd->codec_dais[i];
970                 if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) {
971                         ret = codec_dai->driver->ops->trigger(substream,
972                                                               cmd, codec_dai);
973                         if (ret < 0)
974                                 return ret;
975                 }
976         }
977 
978         if (platform->driver->ops && platform->driver->ops->trigger) {
979                 ret = platform->driver->ops->trigger(substream, cmd);
980                 if (ret < 0)
981                         return ret;
982         }
983 
984         if (cpu_dai->driver->ops && cpu_dai->driver->ops->trigger) {
985                 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
986                 if (ret < 0)
987                         return ret;
988         }
989 
990         if (rtd->dai_link->ops && rtd->dai_link->ops->trigger) {
991                 ret = rtd->dai_link->ops->trigger(substream, cmd);
992                 if (ret < 0)
993                         return ret;
994         }
995 
996         return 0;
997 }
998 
999 static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
1000                                    int cmd)
1001 {
1002         struct snd_soc_pcm_runtime *rtd = substream->private_data;
1003         struct snd_soc_platform *platform = rtd->platform;
1004         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1005         struct snd_soc_dai *codec_dai;
1006         int i, ret;
1007 
1008         for (i = 0; i < rtd->num_codecs; i++) {
1009                 codec_dai = rtd->codec_dais[i];
1010                 if (codec_dai->driver->ops &&
1011                     codec_dai->driver->ops->bespoke_trigger) {
1012                         ret = codec_dai->driver->ops->bespoke_trigger(substream,
1013                                                                 cmd, codec_dai);
1014                         if (ret < 0)
1015                                 return ret;
1016                 }
1017         }
1018 
1019         if (platform->driver->bespoke_trigger) {
1020                 ret = platform->driver->bespoke_trigger(substream, cmd);
1021                 if (ret < 0)
1022                         return ret;
1023         }
1024 
1025         if (cpu_dai->driver->ops && cpu_dai->driver->ops->bespoke_trigger) {
1026                 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
1027                 if (ret < 0)
1028                         return ret;
1029         }
1030         return 0;
1031 }
1032 /*
1033  * soc level wrapper for pointer callback
1034  * If cpu_dai, codec_dai, platform driver has the delay callback, than
1035  * the runtime->delay will be updated accordingly.
1036  */
1037 static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1038 {
1039         struct snd_soc_pcm_runtime *rtd = substream->private_data;
1040         struct snd_soc_platform *platform = rtd->platform;
1041         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1042         struct snd_soc_dai *codec_dai;
1043         struct snd_pcm_runtime *runtime = substream->runtime;
1044         snd_pcm_uframes_t offset = 0;
1045         snd_pcm_sframes_t delay = 0;
1046         snd_pcm_sframes_t codec_delay = 0;
1047         int i;
1048 
1049         if (platform->driver->ops && platform->driver->ops->pointer)
1050                 offset = platform->driver->ops->pointer(substream);
1051 
1052         if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay)
1053                 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
1054 
1055         for (i = 0; i < rtd->num_codecs; i++) {
1056                 codec_dai = rtd->codec_dais[i];
1057                 if (codec_dai->driver->ops && codec_dai->driver->ops->delay)
1058                         codec_delay = max(codec_delay,
1059                                         codec_dai->driver->ops->delay(substream,
1060                                                                     codec_dai));
1061         }
1062         delay += codec_delay;
1063 
1064         /*
1065          * None of the existing platform drivers implement delay(), so
1066          * for now the codec_dai of first multicodec entry is used
1067          */
1068         if (platform->driver->delay)
1069                 delay += platform->driver->delay(substream, rtd->codec_dais[0]);
1070 
1071         runtime->delay = delay;
1072 
1073         return offset;
1074 }
1075 
1076 /* connect a FE and BE */
1077 static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
1078                 struct snd_soc_pcm_runtime *be, int stream)
1079 {
1080         struct snd_soc_dpcm *dpcm;
1081 
1082         /* only add new dpcms */
1083         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1084                 if (dpcm->be == be && dpcm->fe == fe)
1085                         return 0;
1086         }
1087 
1088         dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL);
1089         if (!dpcm)
1090                 return -ENOMEM;
1091 
1092         dpcm->be = be;
1093         dpcm->fe = fe;
1094         be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
1095         dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
1096         list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
1097         list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
1098 
1099         dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
1100                         stream ? "capture" : "playback",  fe->dai_link->name,
1101                         stream ? "<-" : "->", be->dai_link->name);
1102 
1103 #ifdef CONFIG_DEBUG_FS
1104         if (fe->debugfs_dpcm_root)
1105                 dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
1106                                 fe->debugfs_dpcm_root, &dpcm->state);
1107 #endif
1108         return 1;
1109 }
1110 
1111 /* reparent a BE onto another FE */
1112 static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
1113                         struct snd_soc_pcm_runtime *be, int stream)
1114 {
1115         struct snd_soc_dpcm *dpcm;
1116         struct snd_pcm_substream *fe_substream, *be_substream;
1117 
1118         /* reparent if BE is connected to other FEs */
1119         if (!be->dpcm[stream].users)
1120                 return;
1121 
1122         be_substream = snd_soc_dpcm_get_substream(be, stream);
1123 
1124         list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
1125                 if (dpcm->fe == fe)
1126                         continue;
1127 
1128                 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
1129                         stream ? "capture" : "playback",
1130                         dpcm->fe->dai_link->name,
1131                         stream ? "<-" : "->", dpcm->be->dai_link->name);
1132 
1133                 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
1134                 be_substream->runtime = fe_substream->runtime;
1135                 break;
1136         }
1137 }
1138 
1139 /* disconnect a BE and FE */
1140 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
1141 {
1142         struct snd_soc_dpcm *dpcm, *d;
1143 
1144         list_for_each_entry_safe(dpcm, d, &fe->dpcm[stream].be_clients, list_be) {
1145                 dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
1146                                 stream ? "capture" : "playback",
1147                                 dpcm->be->dai_link->name);
1148 
1149                 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
1150                         continue;
1151 
1152                 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
1153                         stream ? "capture" : "playback", fe->dai_link->name,
1154                         stream ? "<-" : "->", dpcm->be->dai_link->name);
1155 
1156                 /* BEs still alive need new FE */
1157                 dpcm_be_reparent(fe, dpcm->be, stream);
1158 
1159 #ifdef CONFIG_DEBUG_FS
1160                 debugfs_remove(dpcm->debugfs_state);
1161 #endif
1162                 list_del(&dpcm->list_be);
1163                 list_del(&dpcm->list_fe);
1164                 kfree(dpcm);
1165         }
1166 }
1167 
1168 /* get BE for DAI widget and stream */
1169 static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
1170                 struct snd_soc_dapm_widget *widget, int stream)
1171 {
1172         struct snd_soc_pcm_runtime *be;
1173         int i, j;
1174 
1175         if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
1176                 for (i = 0; i < card->num_links; i++) {
1177                         be = &card->rtd[i];
1178 
1179                         if (!be->dai_link->no_pcm)
1180                                 continue;
1181 
1182                         if (be->cpu_dai->playback_widget == widget)
1183                                 return be;
1184 
1185                         for (j = 0; j < be->num_codecs; j++) {
1186                                 struct snd_soc_dai *dai = be->codec_dais[j];
1187                                 if (dai->playback_widget == widget)
1188                                         return be;
1189                         }
1190                 }
1191         } else {
1192 
1193                 for (i = 0; i < card->num_links; i++) {
1194                         be = &card->rtd[i];
1195 
1196                         if (!be->dai_link->no_pcm)
1197                                 continue;
1198 
1199                         if (be->cpu_dai->capture_widget == widget)
1200                                 return be;
1201 
1202                         for (j = 0; j < be->num_codecs; j++) {
1203                                 struct snd_soc_dai *dai = be->codec_dais[j];
1204                                 if (dai->capture_widget == widget)
1205                                         return be;
1206                         }
1207                 }
1208         }
1209 
1210         dev_err(card->dev, "ASoC: can't get %s BE for %s\n",
1211                 stream ? "capture" : "playback", widget->name);
1212         return NULL;
1213 }
1214 
1215 static inline struct snd_soc_dapm_widget *
1216         dai_get_widget(struct snd_soc_dai *dai, int stream)
1217 {
1218         if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1219                 return dai->playback_widget;
1220         else
1221                 return dai->capture_widget;
1222 }
1223 
1224 static int widget_in_list(struct snd_soc_dapm_widget_list *list,
1225                 struct snd_soc_dapm_widget *widget)
1226 {
1227         int i;
1228 
1229         for (i = 0; i < list->num_widgets; i++) {
1230                 if (widget == list->widgets[i])
1231                         return 1;
1232         }
1233 
1234         return 0;
1235 }
1236 
1237 int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
1238         int stream, struct snd_soc_dapm_widget_list **list_)
1239 {
1240         struct snd_soc_dai *cpu_dai = fe->cpu_dai;
1241         struct snd_soc_dapm_widget_list *list;
1242         int paths;
1243 
1244         list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) +
1245                         sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL);
1246         if (list == NULL)
1247                 return -ENOMEM;
1248 
1249         /* get number of valid DAI paths and their widgets */
1250         paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list);
1251 
1252         dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
1253                         stream ? "capture" : "playback");
1254 
1255         *list_ = list;
1256         return paths;
1257 }
1258 
1259 static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
1260         struct snd_soc_dapm_widget_list **list_)
1261 {
1262         struct snd_soc_dpcm *dpcm;
1263         struct snd_soc_dapm_widget_list *list = *list_;
1264         struct snd_soc_dapm_widget *widget;
1265         int prune = 0;
1266 
1267         /* Destroy any old FE <--> BE connections */
1268         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1269                 unsigned int i;
1270 
1271                 /* is there a valid CPU DAI widget for this BE */
1272                 widget = dai_get_widget(dpcm->be->cpu_dai, stream);
1273 
1274                 /* prune the BE if it's no longer in our active list */
1275                 if (widget && widget_in_list(list, widget))
1276                         continue;
1277 
1278                 /* is there a valid CODEC DAI widget for this BE */
1279                 for (i = 0; i < dpcm->be->num_codecs; i++) {
1280                         struct snd_soc_dai *dai = dpcm->be->codec_dais[i];
1281                         widget = dai_get_widget(dai, stream);
1282 
1283                         /* prune the BE if it's no longer in our active list */
1284                         if (widget && widget_in_list(list, widget))
1285                                 continue;
1286                 }
1287 
1288                 dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
1289                         stream ? "capture" : "playback",
1290                         dpcm->be->dai_link->name, fe->dai_link->name);
1291                 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
1292                 dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1293                 prune++;
1294         }
1295 
1296         dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune);
1297         return prune;
1298 }
1299 
1300 static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1301         struct snd_soc_dapm_widget_list **list_)
1302 {
1303         struct snd_soc_card *card = fe->card;
1304         struct snd_soc_dapm_widget_list *list = *list_;
1305         struct snd_soc_pcm_runtime *be;
1306         int i, new = 0, err;
1307 
1308         /* Create any new FE <--> BE connections */
1309         for (i = 0; i < list->num_widgets; i++) {
1310 
1311                 switch (list->widgets[i]->id) {
1312                 case snd_soc_dapm_dai_in:
1313                 case snd_soc_dapm_dai_out:
1314                         break;
1315                 default:
1316                         continue;
1317                 }
1318 
1319                 /* is there a valid BE rtd for this widget */
1320                 be = dpcm_get_be(card, list->widgets[i], stream);
1321                 if (!be) {
1322                         dev_err(fe->dev, "ASoC: no BE found for %s\n",
1323                                         list->widgets[i]->name);
1324                         continue;
1325                 }
1326 
1327                 /* make sure BE is a real BE */
1328                 if (!be->dai_link->no_pcm)
1329                         continue;
1330 
1331                 /* don't connect if FE is not running */
1332                 if (!fe->dpcm[stream].runtime && !fe->fe_compr)
1333                         continue;
1334 
1335                 /* newly connected FE and BE */
1336                 err = dpcm_be_connect(fe, be, stream);
1337                 if (err < 0) {
1338                         dev_err(fe->dev, "ASoC: can't connect %s\n",
1339                                 list->widgets[i]->name);
1340                         break;
1341                 } else if (err == 0) /* already connected */
1342                         continue;
1343 
1344                 /* new */
1345                 be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
1346                 new++;
1347         }
1348 
1349         dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new);
1350         return new;
1351 }
1352 
1353 /*
1354  * Find the corresponding BE DAIs that source or sink audio to this
1355  * FE substream.
1356  */
1357 int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
1358         int stream, struct snd_soc_dapm_widget_list **list, int new)
1359 {
1360         if (new)
1361                 return dpcm_add_paths(fe, stream, list);
1362         else
1363                 return dpcm_prune_paths(fe, stream, list);
1364 }
1365 
1366 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
1367 {
1368         struct snd_soc_dpcm *dpcm;
1369 
1370         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
1371                 dpcm->be->dpcm[stream].runtime_update =
1372                                                 SND_SOC_DPCM_UPDATE_NO;
1373 }
1374 
1375 static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
1376         int stream)
1377 {
1378         struct snd_soc_dpcm *dpcm;
1379 
1380         /* disable any enabled and non active backends */
1381         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1382 
1383                 struct snd_soc_pcm_runtime *be = dpcm->be;
1384                 struct snd_pcm_substream *be_substream =
1385                         snd_soc_dpcm_get_substream(be, stream);
1386 
1387                 if (be->dpcm[stream].users == 0)
1388                         dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1389                                 stream ? "capture" : "playback",
1390                                 be->dpcm[stream].state);
1391 
1392                 if (--be->dpcm[stream].users != 0)
1393                         continue;
1394 
1395                 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1396                         continue;
1397 
1398                 soc_pcm_close(be_substream);
1399                 be_substream->runtime = NULL;
1400                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1401         }
1402 }
1403 
1404 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1405 {
1406         struct snd_soc_dpcm *dpcm;
1407         int err, count = 0;
1408 
1409         /* only startup BE DAIs that are either sinks or sources to this FE DAI */
1410         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1411 
1412                 struct snd_soc_pcm_runtime *be = dpcm->be;
1413                 struct snd_pcm_substream *be_substream =
1414                         snd_soc_dpcm_get_substream(be, stream);
1415 
1416                 if (!be_substream) {
1417                         dev_err(be->dev, "ASoC: no backend %s stream\n",
1418                                 stream ? "capture" : "playback");
1419                         continue;
1420                 }
1421 
1422                 /* is this op for this BE ? */
1423                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1424                         continue;
1425 
1426                 /* first time the dpcm is open ? */
1427                 if (be->dpcm[stream].users == DPCM_MAX_BE_USERS)
1428                         dev_err(be->dev, "ASoC: too many users %s at open %d\n",
1429                                 stream ? "capture" : "playback",
1430                                 be->dpcm[stream].state);
1431 
1432                 if (be->dpcm[stream].users++ != 0)
1433                         continue;
1434 
1435                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
1436                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1437                         continue;
1438 
1439                 dev_dbg(be->dev, "ASoC: open %s BE %s\n",
1440                         stream ? "capture" : "playback", be->dai_link->name);
1441 
1442                 be_substream->runtime = be->dpcm[stream].runtime;
1443                 err = soc_pcm_open(be_substream);
1444                 if (err < 0) {
1445                         dev_err(be->dev, "ASoC: BE open failed %d\n", err);
1446                         be->dpcm[stream].users--;
1447                         if (be->dpcm[stream].users < 0)
1448                                 dev_err(be->dev, "ASoC: no users %s at unwind %d\n",
1449                                         stream ? "capture" : "playback",
1450                                         be->dpcm[stream].state);
1451 
1452                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1453                         goto unwind;
1454                 }
1455 
1456                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1457                 count++;
1458         }
1459 
1460         return count;
1461 
1462 unwind:
1463         /* disable any enabled and non active backends */
1464         list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1465                 struct snd_soc_pcm_runtime *be = dpcm->be;
1466                 struct snd_pcm_substream *be_substream =
1467                         snd_soc_dpcm_get_substream(be, stream);
1468 
1469                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1470                         continue;
1471 
1472                 if (be->dpcm[stream].users == 0)
1473                         dev_err(be->dev, "ASoC: no users %s at close %d\n",
1474                                 stream ? "capture" : "playback",
1475                                 be->dpcm[stream].state);
1476 
1477                 if (--be->dpcm[stream].users != 0)
1478                         continue;
1479 
1480                 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
1481                         continue;
1482 
1483                 soc_pcm_close(be_substream);
1484                 be_substream->runtime = NULL;
1485                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1486         }
1487 
1488         return err;
1489 }
1490 
1491 static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
1492         struct snd_soc_pcm_stream *stream)
1493 {
1494         runtime->hw.rate_min = stream->rate_min;
1495         runtime->hw.rate_max = stream->rate_max;
1496         runtime->hw.channels_min = stream->channels_min;
1497         runtime->hw.channels_max = stream->channels_max;
1498         if (runtime->hw.formats)
1499                 runtime->hw.formats &= stream->formats;
1500         else
1501                 runtime->hw.formats = stream->formats;
1502         runtime->hw.rates = stream->rates;
1503 }
1504 
1505 static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1506 {
1507         struct snd_pcm_runtime *runtime = substream->runtime;
1508         struct snd_soc_pcm_runtime *rtd = substream->private_data;
1509         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1510         struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
1511 
1512         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1513                 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback);
1514         else
1515                 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture);
1516 }
1517 
1518 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
1519 
1520 /* Set FE's runtime_update state; the state is protected via PCM stream lock
1521  * for avoiding the race with trigger callback.
1522  * If the state is unset and a trigger is pending while the previous operation,
1523  * process the pending trigger action here.
1524  */
1525 static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1526                                      int stream, enum snd_soc_dpcm_update state)
1527 {
1528         struct snd_pcm_substream *substream =
1529                 snd_soc_dpcm_get_substream(fe, stream);
1530 
1531         snd_pcm_stream_lock_irq(substream);
1532         if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1533                 dpcm_fe_dai_do_trigger(substream,
1534                                        fe->dpcm[stream].trigger_pending - 1);
1535                 fe->dpcm[stream].trigger_pending = 0;
1536         }
1537         fe->dpcm[stream].runtime_update = state;
1538         snd_pcm_stream_unlock_irq(substream);
1539 }
1540 
1541 static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1542 {
1543         struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1544         struct snd_pcm_runtime *runtime = fe_substream->runtime;
1545         int stream = fe_substream->stream, ret = 0;
1546 
1547         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1548 
1549         ret = dpcm_be_dai_startup(fe, fe_substream->stream);
1550         if (ret < 0) {
1551                 dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret);
1552                 goto be_err;
1553         }
1554 
1555         dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name);
1556 
1557         /* start the DAI frontend */
1558         ret = soc_pcm_open(fe_substream);
1559         if (ret < 0) {
1560                 dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret);
1561                 goto unwind;
1562         }
1563 
1564         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1565 
1566         dpcm_set_fe_runtime(fe_substream);
1567         snd_pcm_limit_hw_rates(runtime);
1568 
1569         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1570         return 0;
1571 
1572 unwind:
1573         dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
1574 be_err:
1575         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1576         return ret;
1577 }
1578 
1579 int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1580 {
1581         struct snd_soc_dpcm *dpcm;
1582 
1583         /* only shutdown BEs that are either sinks or sources to this FE DAI */
1584         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1585 
1586                 struct snd_soc_pcm_runtime *be = dpcm->be;
1587                 struct snd_pcm_substream *be_substream =
1588                         snd_soc_dpcm_get_substream(be, stream);
1589 
1590                 /* is this op for this BE ? */
1591                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1592                         continue;
1593 
1594                 if (be->dpcm[stream].users == 0)
1595                         dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
1596                                 stream ? "capture" : "playback",
1597                                 be->dpcm[stream].state);
1598 
1599                 if (--be->dpcm[stream].users != 0)
1600                         continue;
1601 
1602                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1603                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
1604                         continue;
1605 
1606                 dev_dbg(be->dev, "ASoC: close BE %s\n",
1607                         dpcm->fe->dai_link->name);
1608 
1609                 soc_pcm_close(be_substream);
1610                 be_substream->runtime = NULL;
1611 
1612                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1613         }
1614         return 0;
1615 }
1616 
1617 static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1618 {
1619         struct snd_soc_pcm_runtime *fe = substream->private_data;
1620         int stream = substream->stream;
1621 
1622         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1623 
1624         /* shutdown the BEs */
1625         dpcm_be_dai_shutdown(fe, substream->stream);
1626 
1627         dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name);
1628 
1629         /* now shutdown the frontend */
1630         soc_pcm_close(substream);
1631 
1632         /* run the stream event for each BE */
1633         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1634 
1635         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1636         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1637         return 0;
1638 }
1639 
1640 int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1641 {
1642         struct snd_soc_dpcm *dpcm;
1643 
1644         /* only hw_params backends that are either sinks or sources
1645          * to this frontend DAI */
1646         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1647 
1648                 struct snd_soc_pcm_runtime *be = dpcm->be;
1649                 struct snd_pcm_substream *be_substream =
1650                         snd_soc_dpcm_get_substream(be, stream);
1651 
1652                 /* is this op for this BE ? */
1653                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1654                         continue;
1655 
1656                 /* only free hw when no longer used - check all FEs */
1657                 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1658                                 continue;
1659 
1660                 /* do not free hw if this BE is used by other FE */
1661                 if (be->dpcm[stream].users > 1)
1662                         continue;
1663 
1664                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1665                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1666                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1667                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
1668                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
1669                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1670                         continue;
1671 
1672                 dev_dbg(be->dev, "ASoC: hw_free BE %s\n",
1673                         dpcm->fe->dai_link->name);
1674 
1675                 soc_pcm_hw_free(be_substream);
1676 
1677                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1678         }
1679 
1680         return 0;
1681 }
1682 
1683 static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1684 {
1685         struct snd_soc_pcm_runtime *fe = substream->private_data;
1686         int err, stream = substream->stream;
1687 
1688         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1689         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1690 
1691         dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
1692 
1693         /* call hw_free on the frontend */
1694         err = soc_pcm_hw_free(substream);
1695         if (err < 0)
1696                 dev_err(fe->dev,"ASoC: hw_free FE %s failed\n",
1697                         fe->dai_link->name);
1698 
1699         /* only hw_params backends that are either sinks or sources
1700          * to this frontend DAI */
1701         err = dpcm_be_dai_hw_free(fe, stream);
1702 
1703         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1704         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1705 
1706         mutex_unlock(&fe->card->mutex);
1707         return 0;
1708 }
1709 
1710 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1711 {
1712         struct snd_soc_dpcm *dpcm;
1713         int ret;
1714 
1715         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1716 
1717                 struct snd_soc_pcm_runtime *be = dpcm->be;
1718                 struct snd_pcm_substream *be_substream =
1719                         snd_soc_dpcm_get_substream(be, stream);
1720 
1721                 /* is this op for this BE ? */
1722                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1723                         continue;
1724 
1725                 /* only allow hw_params() if no connected FEs are running */
1726                 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
1727                         continue;
1728 
1729                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1730                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1731                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
1732                         continue;
1733 
1734                 dev_dbg(be->dev, "ASoC: hw_params BE %s\n",
1735                         dpcm->fe->dai_link->name);
1736 
1737                 /* copy params for each dpcm */
1738                 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1739                                 sizeof(struct snd_pcm_hw_params));
1740 
1741                 /* perform any hw_params fixups */
1742                 if (be->dai_link->be_hw_params_fixup) {
1743                         ret = be->dai_link->be_hw_params_fixup(be,
1744                                         &dpcm->hw_params);
1745                         if (ret < 0) {
1746                                 dev_err(be->dev,
1747                                         "ASoC: hw_params BE fixup failed %d\n",
1748                                         ret);
1749                                 goto unwind;
1750                         }
1751                 }
1752 
1753                 ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params);
1754                 if (ret < 0) {
1755                         dev_err(dpcm->be->dev,
1756                                 "ASoC: hw_params BE failed %d\n", ret);
1757                         goto unwind;
1758                 }
1759 
1760                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1761         }
1762         return 0;
1763 
1764 unwind:
1765         /* disable any enabled and non active backends */
1766         list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1767                 struct snd_soc_pcm_runtime *be = dpcm->be;
1768                 struct snd_pcm_substream *be_substream =
1769                         snd_soc_dpcm_get_substream(be, stream);
1770 
1771                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1772                         continue;
1773 
1774                 /* only allow hw_free() if no connected FEs are running */
1775                 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1776                         continue;
1777 
1778                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
1779                    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
1780                    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
1781                    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1782                         continue;
1783 
1784                 soc_pcm_hw_free(be_substream);
1785         }
1786 
1787         return ret;
1788 }
1789 
1790 static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1791                                  struct snd_pcm_hw_params *params)
1792 {
1793         struct snd_soc_pcm_runtime *fe = substream->private_data;
1794         int ret, stream = substream->stream;
1795 
1796         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1797         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1798 
1799         memcpy(&fe->dpcm[substream->stream].hw_params, params,
1800                         sizeof(struct snd_pcm_hw_params));
1801         ret = dpcm_be_dai_hw_params(fe, substream->stream);
1802         if (ret < 0) {
1803                 dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret);
1804                 goto out;
1805         }
1806 
1807         dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
1808                         fe->dai_link->name, params_rate(params),
1809                         params_channels(params), params_format(params));
1810 
1811         /* call hw_params on the frontend */
1812         ret = soc_pcm_hw_params(substream, params);
1813         if (ret < 0) {
1814                 dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret);
1815                 dpcm_be_dai_hw_free(fe, stream);
1816          } else
1817                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1818 
1819 out:
1820         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1821         mutex_unlock(&fe->card->mutex);
1822         return ret;
1823 }
1824 
1825 static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm,
1826                 struct snd_pcm_substream *substream, int cmd)
1827 {
1828         int ret;
1829 
1830         dev_dbg(dpcm->be->dev, "ASoC: trigger BE %s cmd %d\n",
1831                         dpcm->fe->dai_link->name, cmd);
1832 
1833         ret = soc_pcm_trigger(substream, cmd);
1834         if (ret < 0)
1835                 dev_err(dpcm->be->dev,"ASoC: trigger BE failed %d\n", ret);
1836 
1837         return ret;
1838 }
1839 
1840 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
1841                                int cmd)
1842 {
1843         struct snd_soc_dpcm *dpcm;
1844         int ret = 0;
1845 
1846         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1847 
1848                 struct snd_soc_pcm_runtime *be = dpcm->be;
1849                 struct snd_pcm_substream *be_substream =
1850                         snd_soc_dpcm_get_substream(be, stream);
1851 
1852                 /* is this op for this BE ? */
1853                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1854                         continue;
1855 
1856                 switch (cmd) {
1857                 case SNDRV_PCM_TRIGGER_START:
1858                         if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
1859                             (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
1860                                 continue;
1861 
1862                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1863                         if (ret)
1864                                 return ret;
1865 
1866                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1867                         break;
1868                 case SNDRV_PCM_TRIGGER_RESUME:
1869                         if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
1870                                 continue;
1871 
1872                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1873                         if (ret)
1874                                 return ret;
1875 
1876                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1877                         break;
1878                 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1879                         if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
1880                                 continue;
1881 
1882                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1883                         if (ret)
1884                                 return ret;
1885 
1886                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1887                         break;
1888                 case SNDRV_PCM_TRIGGER_STOP:
1889                         if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1890                                 continue;
1891 
1892                         if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1893                                 continue;
1894 
1895                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1896                         if (ret)
1897                                 return ret;
1898 
1899                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1900                         break;
1901                 case SNDRV_PCM_TRIGGER_SUSPEND:
1902                         if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1903                                 continue;
1904 
1905                         if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1906                                 continue;
1907 
1908                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1909                         if (ret)
1910                                 return ret;
1911 
1912                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
1913                         break;
1914                 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1915                         if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
1916                                 continue;
1917 
1918                         if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1919                                 continue;
1920 
1921                         ret = dpcm_do_trigger(dpcm, be_substream, cmd);
1922                         if (ret)
1923                                 return ret;
1924 
1925                         be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
1926                         break;
1927                 }
1928         }
1929 
1930         return ret;
1931 }
1932 EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
1933 
1934 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
1935 {
1936         struct snd_soc_pcm_runtime *fe = substream->private_data;
1937         int stream = substream->stream, ret;
1938         enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
1939 
1940         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
1941 
1942         switch (trigger) {
1943         case SND_SOC_DPCM_TRIGGER_PRE:
1944                 /* call trigger on the frontend before the backend. */
1945 
1946                 dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n",
1947                                 fe->dai_link->name, cmd);
1948 
1949                 ret = soc_pcm_trigger(substream, cmd);
1950                 if (ret < 0) {
1951                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
1952                         goto out;
1953                 }
1954 
1955                 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
1956                 break;
1957         case SND_SOC_DPCM_TRIGGER_POST:
1958                 /* call trigger on the frontend after the backend. */
1959 
1960                 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
1961                 if (ret < 0) {
1962                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
1963                         goto out;
1964                 }
1965 
1966                 dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
1967                                 fe->dai_link->name, cmd);
1968 
1969                 ret = soc_pcm_trigger(substream, cmd);
1970                 break;
1971         case SND_SOC_DPCM_TRIGGER_BESPOKE:
1972                 /* bespoke trigger() - handles both FE and BEs */
1973 
1974                 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
1975                                 fe->dai_link->name, cmd);
1976 
1977                 ret = soc_pcm_bespoke_trigger(substream, cmd);
1978                 if (ret < 0) {
1979                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
1980                         goto out;
1981                 }
1982                 break;
1983         default:
1984                 dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
1985                                 fe->dai_link->name);
1986                 ret = -EINVAL;
1987                 goto out;
1988         }
1989 
1990         switch (cmd) {
1991         case SNDRV_PCM_TRIGGER_START:
1992         case SNDRV_PCM_TRIGGER_RESUME:
1993         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1994                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
1995                 break;
1996         case SNDRV_PCM_TRIGGER_STOP:
1997         case SNDRV_PCM_TRIGGER_SUSPEND:
1998                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
1999                 break;
2000         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2001                 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2002                 break;
2003         }
2004 
2005 out:
2006         fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
2007         return ret;
2008 }
2009 
2010 static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
2011 {
2012         struct snd_soc_pcm_runtime *fe = substream->private_data;
2013         int stream = substream->stream;
2014 
2015         /* if FE's runtime_update is already set, we're in race;
2016          * process this trigger later at exit
2017          */
2018         if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2019                 fe->dpcm[stream].trigger_pending = cmd + 1;
2020                 return 0; /* delayed, assuming it's successful */
2021         }
2022 
2023         /* we're alone, let's trigger */
2024         return dpcm_fe_dai_do_trigger(substream, cmd);
2025 }
2026 
2027 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
2028 {
2029         struct snd_soc_dpcm *dpcm;
2030         int ret = 0;
2031 
2032         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2033 
2034                 struct snd_soc_pcm_runtime *be = dpcm->be;
2035                 struct snd_pcm_substream *be_substream =
2036                         snd_soc_dpcm_get_substream(be, stream);
2037 
2038                 /* is this op for this BE ? */
2039                 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2040                         continue;
2041 
2042                 if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
2043                     (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
2044                         continue;
2045 
2046                 dev_dbg(be->dev, "ASoC: prepare BE %s\n",
2047                         dpcm->fe->dai_link->name);
2048 
2049                 ret = soc_pcm_prepare(be_substream);
2050                 if (ret < 0) {
2051                         dev_err(be->dev, "ASoC: backend prepare failed %d\n",
2052                                 ret);
2053                         break;
2054                 }
2055 
2056                 be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2057         }
2058         return ret;
2059 }
2060 
2061 static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
2062 {
2063         struct snd_soc_pcm_runtime *fe = substream->private_data;
2064         int stream = substream->stream, ret = 0;
2065 
2066         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2067 
2068         dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
2069 
2070         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2071 
2072         /* there is no point preparing this FE if there are no BEs */
2073         if (list_empty(&fe->dpcm[stream].be_clients)) {
2074                 dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
2075                                 fe->dai_link->name);
2076                 ret = -EINVAL;
2077                 goto out;
2078         }
2079 
2080         ret = dpcm_be_dai_prepare(fe, substream->stream);
2081         if (ret < 0)
2082                 goto out;
2083 
2084         /* call prepare on the frontend */
2085         ret = soc_pcm_prepare(substream);
2086         if (ret < 0) {
2087                 dev_err(fe->dev,"ASoC: prepare FE %s failed\n",
2088                         fe->dai_link->name);
2089                 goto out;
2090         }
2091 
2092         /* run the stream event for each BE */
2093         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
2094         fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2095 
2096 out:
2097         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2098         mutex_unlock(&fe->card->mutex);
2099 
2100         return ret;
2101 }
2102 
2103 static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
2104                      unsigned int cmd, void *arg)
2105 {
2106         struct snd_soc_pcm_runtime *rtd = substream->private_data;
2107         struct snd_soc_platform *platform = rtd->platform;
2108 
2109         if (platform->driver->ops && platform->driver->ops->ioctl)
2110                 return platform->driver->ops->ioctl(substream, cmd, arg);
2111         return snd_pcm_lib_ioctl(substream, cmd, arg);
2112 }
2113 
2114 static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
2115 {
2116         struct snd_pcm_substream *substream =
2117                 snd_soc_dpcm_get_substream(fe, stream);
2118         enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2119         int err;
2120 
2121         dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
2122                         stream ? "capture" : "playback", fe->dai_link->name);
2123 
2124         if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2125                 /* call bespoke trigger - FE takes care of all BE triggers */
2126                 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
2127                                 fe->dai_link->name);
2128 
2129                 err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
2130                 if (err < 0)
2131                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2132         } else {
2133                 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
2134                         fe->dai_link->name);
2135 
2136                 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
2137                 if (err < 0)
2138                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2139         }
2140 
2141         err = dpcm_be_dai_hw_free(fe, stream);
2142         if (err < 0)
2143                 dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err);
2144 
2145         err = dpcm_be_dai_shutdown(fe, stream);
2146         if (err < 0)
2147                 dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err);
2148 
2149         /* run the stream event for each BE */
2150         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2151 
2152         return 0;
2153 }
2154 
2155 static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
2156 {
2157         struct snd_pcm_substream *substream =
2158                 snd_soc_dpcm_get_substream(fe, stream);
2159         struct snd_soc_dpcm *dpcm;
2160         enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2161         int ret;
2162 
2163         dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
2164                         stream ? "capture" : "playback", fe->dai_link->name);
2165 
2166         /* Only start the BE if the FE is ready */
2167         if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
2168                 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2169                 return -EINVAL;
2170 
2171         /* startup must always be called for new BEs */
2172         ret = dpcm_be_dai_startup(fe, stream);
2173         if (ret < 0)
2174                 goto disconnect;
2175 
2176         /* keep going if FE state is > open */
2177         if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
2178                 return 0;
2179 
2180         ret = dpcm_be_dai_hw_params(fe, stream);
2181         if (ret < 0)
2182                 goto close;
2183 
2184         /* keep going if FE state is > hw_params */
2185         if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
2186                 return 0;
2187 
2188 
2189         ret = dpcm_be_dai_prepare(fe, stream);
2190         if (ret < 0)
2191                 goto hw_free;
2192 
2193         /* run the stream event for each BE */
2194         dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2195 
2196         /* keep going if FE state is > prepare */
2197         if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
2198                 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
2199                 return 0;
2200 
2201         if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
2202                 /* call trigger on the frontend - FE takes care of all BE triggers */
2203                 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
2204                                 fe->dai_link->name);
2205 
2206                 ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
2207                 if (ret < 0) {
2208                         dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret);
2209                         goto hw_free;
2210                 }
2211         } else {
2212                 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
2213                         fe->dai_link->name);
2214 
2215                 ret = dpcm_be_dai_trigger(fe, stream,
2216                                         SNDRV_PCM_TRIGGER_START);
2217                 if (ret < 0) {
2218                         dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
2219                         goto hw_free;
2220                 }
2221         }
2222 
2223         return 0;
2224 
2225 hw_free:
2226         dpcm_be_dai_hw_free(fe, stream);
2227 close:
2228         dpcm_be_dai_shutdown(fe, stream);
2229 disconnect:
2230         /* disconnect any non started BEs */
2231         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2232                 struct snd_soc_pcm_runtime *be = dpcm->be;
2233                 if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
2234                                 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2235         }
2236 
2237         return ret;
2238 }
2239 
2240 static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
2241 {
2242         int ret;
2243 
2244         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2245         ret = dpcm_run_update_startup(fe, stream);
2246         if (ret < 0)
2247                 dev_err(fe->dev, "ASoC: failed to startup some BEs\n");
2248         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2249 
2250         return ret;
2251 }
2252 
2253 static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
2254 {
2255         int ret;
2256 
2257         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2258         ret = dpcm_run_update_shutdown(fe, stream);
2259         if (ret < 0)
2260                 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
2261         dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2262 
2263         return ret;
2264 }
2265 
2266 /* Called by DAPM mixer/mux changes to update audio routing between PCMs and
2267  * any DAI links.
2268  */
2269 int soc_dpcm_runtime_update(struct snd_soc_card *card)
2270 {
2271         int i, old, new, paths;
2272 
2273         mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2274         for (i = 0; i < card->num_rtd; i++) {
2275                 struct snd_soc_dapm_widget_list *list;
2276                 struct snd_soc_pcm_runtime *fe = &card->rtd[i];
2277 
2278                 /* make sure link is FE */
2279                 if (!fe->dai_link->dynamic)
2280                         continue;
2281 
2282                 /* only check active links */
2283                 if (!fe->cpu_dai->active)
2284                         continue;
2285 
2286                 /* DAPM sync will call this to update DSP paths */
2287                 dev_dbg(fe->dev, "ASoC: DPCM runtime update for FE %s\n",
2288                         fe->dai_link->name);
2289 
2290                 /* skip if FE doesn't have playback capability */
2291                 if (!fe->cpu_dai->driver->playback.channels_min
2292                     || !fe->codec_dai->driver->playback.channels_min)
2293                         goto capture;
2294 
2295                 /* skip if FE isn't currently playing */
2296                 if (!fe->cpu_dai->playback_active
2297                     || !fe->codec_dai->playback_active)
2298                         goto capture;
2299 
2300                 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
2301                 if (paths < 0) {
2302                         dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2303                                         fe->dai_link->name,  "playback");
2304                         mutex_unlock(&card->mutex);
2305                         return paths;
2306                 }
2307 
2308                 /* update any new playback paths */
2309                 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1);
2310                 if (new) {
2311                         dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2312                         dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
2313                         dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2314                 }
2315 
2316                 /* update any old playback paths */
2317                 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0);
2318                 if (old) {
2319                         dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
2320                         dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
2321                         dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
2322                 }
2323 
2324                 dpcm_path_put(&list);
2325 capture:
2326                 /* skip if FE doesn't have capture capability */
2327                 if (!fe->cpu_dai->driver->capture.channels_min
2328                     || !fe->codec_dai->driver->capture.channels_min)
2329                         continue;
2330 
2331                 /* skip if FE isn't currently capturing */
2332                 if (!fe->cpu_dai->capture_active
2333                     || !fe->codec_dai->capture_active)
2334                         continue;
2335 
2336                 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
2337                 if (paths < 0) {
2338                         dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2339                                         fe->dai_link->name,  "capture");
2340                         mutex_unlock(&card->mutex);
2341                         return paths;
2342                 }
2343 
2344                 /* update any new capture paths */
2345                 new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1);
2346                 if (new) {
2347                         dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2348                         dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
2349                         dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2350                 }
2351 
2352                 /* update any old capture paths */
2353                 old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0);
2354                 if (old) {
2355                         dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE);
2356                         dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
2357                         dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
2358                 }
2359 
2360                 dpcm_path_put(&list);
2361         }
2362 
2363         mutex_unlock(&card->mutex);
2364         return 0;
2365 }
2366 int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
2367 {
2368         struct snd_soc_dpcm *dpcm;
2369         struct list_head *clients =
2370                 &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients;
2371 
2372         list_for_each_entry(dpcm, clients, list_be) {
2373 
2374                 struct snd_soc_pcm_runtime *be = dpcm->be;
2375                 int i;
2376 
2377                 if (be->dai_link->ignore_suspend)
2378                         continue;
2379 
2380                 for (i = 0; i < be->num_codecs; i++) {
2381                         struct snd_soc_dai *dai = be->codec_dais[i];
2382                         struct snd_soc_dai_driver *drv = dai->driver;
2383 
2384                         dev_dbg(be->dev, "ASoC: BE digital mute %s\n",
2385                                          be->dai_link->name);
2386 
2387                         if (drv->ops && drv->ops->digital_mute &&
2388                                                         dai->playback_active)
2389                                 drv->ops->digital_mute(dai, mute);
2390                 }
2391         }
2392 
2393         return 0;
2394 }
2395 
2396 static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2397 {
2398         struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2399         struct snd_soc_dpcm *dpcm;
2400         struct snd_soc_dapm_widget_list *list;
2401         int ret;
2402         int stream = fe_substream->stream;
2403 
2404         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2405         fe->dpcm[stream].runtime = fe_substream->runtime;
2406 
2407         ret = dpcm_path_get(fe, stream, &list);
2408         if (ret < 0) {
2409                 mutex_unlock(&fe->card->mutex);
2410                 return ret;
2411         } else if (ret == 0) {
2412                 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2413                         fe->dai_link->name, stream ? "capture" : "playback");
2414         }
2415 
2416         /* calculate valid and active FE <-> BE dpcms */
2417         dpcm_process_paths(fe, stream, &list, 1);
2418 
2419         ret = dpcm_fe_dai_startup(fe_substream);
2420         if (ret < 0) {
2421                 /* clean up all links */
2422                 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
2423                         dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2424 
2425                 dpcm_be_disconnect(fe, stream);
2426                 fe->dpcm[stream].runtime = NULL;
2427         }
2428 
2429         dpcm_clear_pending_state(fe, stream);
2430         dpcm_path_put(&list);
2431         mutex_unlock(&fe->card->mutex);
2432         return ret;
2433 }
2434 
2435 static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
2436 {
2437         struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
2438         struct snd_soc_dpcm *dpcm;
2439         int stream = fe_substream->stream, ret;
2440 
2441         mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2442         ret = dpcm_fe_dai_shutdown(fe_substream);
2443 
2444         /* mark FE's links ready to prune */
2445         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
2446                 dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
2447 
2448         dpcm_be_disconnect(fe, stream);
2449 
2450         fe->dpcm[stream].runtime = NULL;
2451         mutex_unlock(&fe->card->mutex);
2452         return ret;
2453 }
2454 
2455 /* create a new pcm */
2456 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2457 {
2458         struct snd_soc_platform *platform = rtd->platform;
2459         struct snd_soc_dai *codec_dai;
2460         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2461         struct snd_pcm *pcm;
2462         char new_name[64];
2463         int ret = 0, playback = 0, capture = 0;
2464         int i;
2465 
2466         if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
2467                 playback = rtd->dai_link->dpcm_playback;
2468                 capture = rtd->dai_link->dpcm_capture;
2469         } else {
2470                 for (i = 0; i < rtd->num_codecs; i++) {
2471                         codec_dai = rtd->codec_dais[i];
2472                         if (codec_dai->driver->playback.channels_min)
2473                                 playback = 1;
2474                         if (codec_dai->driver->capture.channels_min)
2475                                 capture = 1;
2476                 }
2477 
2478                 capture = capture && cpu_dai->driver->capture.channels_min;
2479                 playback = playback && cpu_dai->driver->playback.channels_min;
2480         }
2481 
2482         if (rtd->dai_link->playback_only) {
2483                 playback = 1;
2484                 capture = 0;
2485         }
2486 
2487         if (rtd->dai_link->capture_only) {
2488                 playback = 0;
2489                 capture = 1;
2490         }
2491 
2492         /* create the PCM */
2493         if (rtd->dai_link->no_pcm) {
2494                 snprintf(new_name, sizeof(new_name), "(%s)",
2495                         rtd->dai_link->stream_name);
2496 
2497                 ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
2498                                 playback, capture, &pcm);
2499         } else {
2500                 if (rtd->dai_link->dynamic)
2501                         snprintf(new_name, sizeof(new_name), "%s (*)",
2502                                 rtd->dai_link->stream_name);
2503                 else
2504                         snprintf(new_name, sizeof(new_name), "%s %s-%d",
2505                                 rtd->dai_link->stream_name,
2506                                 (rtd->num_codecs > 1) ?
2507                                 "multicodec" : rtd->codec_dai->name, num);
2508 
2509                 ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
2510                         capture, &pcm);
2511         }
2512         if (ret < 0) {
2513                 dev_err(rtd->card->dev, "ASoC: can't create pcm for %s\n",
2514                         rtd->dai_link->name);
2515                 return ret;
2516         }
2517         dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
2518 
2519         /* DAPM dai link stream work */
2520         INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
2521 
2522         pcm->nonatomic = rtd->dai_link->nonatomic;
2523         rtd->pcm = pcm;
2524         pcm->private_data = rtd;
2525 
2526         if (rtd->dai_link->no_pcm) {
2527                 if (playback)
2528                         pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
2529                 if (capture)
2530                         pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
2531                 goto out;
2532         }
2533 
2534         /* ASoC PCM operations */
2535         if (rtd->dai_link->dynamic) {
2536                 rtd->ops.open           = dpcm_fe_dai_open;
2537                 rtd->ops.hw_params      = dpcm_fe_dai_hw_params;
2538                 rtd->ops.prepare        = dpcm_fe_dai_prepare;
2539                 rtd->ops.trigger        = dpcm_fe_dai_trigger;
2540                 rtd->ops.hw_free        = dpcm_fe_dai_hw_free;
2541                 rtd->ops.close          = dpcm_fe_dai_close;
2542                 rtd->ops.pointer        = soc_pcm_pointer;
2543                 rtd->ops.ioctl          = soc_pcm_ioctl;
2544         } else {
2545                 rtd->ops.open           = soc_pcm_open;
2546                 rtd->ops.hw_params      = soc_pcm_hw_params;
2547                 rtd->ops.prepare        = soc_pcm_prepare;
2548                 rtd->ops.trigger        = soc_pcm_trigger;
2549                 rtd->ops.hw_free        = soc_pcm_hw_free;
2550                 rtd->ops.close          = soc_pcm_close;
2551                 rtd->ops.pointer        = soc_pcm_pointer;
2552                 rtd->ops.ioctl          = soc_pcm_ioctl;
2553         }
2554 
2555         if (platform->driver->ops) {
2556                 rtd->ops.ack            = platform->driver->ops->ack;
2557                 rtd->ops.copy           = platform->driver->ops->copy;
2558                 rtd->ops.silence        = platform->driver->ops->silence;
2559                 rtd->ops.page           = platform->driver->ops->page;
2560                 rtd->ops.mmap           = platform->driver->ops->mmap;
2561         }
2562 
2563         if (playback)
2564                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
2565 
2566         if (capture)
2567                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
2568 
2569         if (platform->driver->pcm_new) {
2570                 ret = platform->driver->pcm_new(rtd);
2571                 if (ret < 0) {
2572                         dev_err(platform->dev,
2573                                 "ASoC: pcm constructor failed: %d\n",
2574                                 ret);
2575                         return ret;
2576                 }
2577         }
2578 
2579         pcm->private_free = platform->driver->pcm_free;
2580 out:
2581         dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
2582                  (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
2583                  cpu_dai->name);
2584         return ret;
2585 }
2586 
2587 /* is the current PCM operation for this FE ? */
2588 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2589 {
2590         if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2591                 return 1;
2592         return 0;
2593 }
2594 EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
2595 
2596 /* is the current PCM operation for this BE ? */
2597 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2598                 struct snd_soc_pcm_runtime *be, int stream)
2599 {
2600         if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2601            ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2602                   be->dpcm[stream].runtime_update))
2603                 return 1;
2604         return 0;
2605 }
2606 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
2607 
2608 /* get the substream for this BE */
2609 struct snd_pcm_substream *
2610         snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
2611 {
2612         return be->pcm->streams[stream].substream;
2613 }
2614 EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
2615 
2616 /* get the BE runtime state */
2617 enum snd_soc_dpcm_state
2618         snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream)
2619 {
2620         return be->dpcm[stream].state;
2621 }
2622 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state);
2623 
2624 /* set the BE runtime state */
2625 void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be,
2626                 int stream, enum snd_soc_dpcm_state state)
2627 {
2628         be->dpcm[stream].state = state;
2629 }
2630 EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state);
2631 
2632 /*
2633  * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
2634  * are not running, paused or suspended for the specified stream direction.
2635  */
2636 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2637                 struct snd_soc_pcm_runtime *be, int stream)
2638 {
2639         struct snd_soc_dpcm *dpcm;
2640         int state;
2641 
2642         list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2643 
2644                 if (dpcm->fe == fe)
2645                         continue;
2646 
2647                 state = dpcm->fe->dpcm[stream].state;
2648                 if (state == SND_SOC_DPCM_STATE_START ||
2649                         state == SND_SOC_DPCM_STATE_PAUSED ||
2650                         state == SND_SOC_DPCM_STATE_SUSPEND)
2651                         return 0;
2652         }
2653 
2654         /* it's safe to free/stop this BE DAI */
2655         return 1;
2656 }
2657 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
2658 
2659 /*
2660  * We can only change hw params a BE DAI if any of it's FE are not prepared,
2661  * running, paused or suspended for the specified stream direction.
2662  */
2663 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2664                 struct snd_soc_pcm_runtime *be, int stream)
2665 {
2666         struct snd_soc_dpcm *dpcm;
2667         int state;
2668 
2669         list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) {
2670 
2671                 if (dpcm->fe == fe)
2672                         continue;
2673 
2674                 state = dpcm->fe->dpcm[stream].state;
2675                 if (state == SND_SOC_DPCM_STATE_START ||
2676                         state == SND_SOC_DPCM_STATE_PAUSED ||
2677                         state == SND_SOC_DPCM_STATE_SUSPEND ||
2678                         state == SND_SOC_DPCM_STATE_PREPARE)
2679                         return 0;
2680         }
2681 
2682         /* it's safe to change hw_params */
2683         return 1;
2684 }
2685 EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
2686 
2687 int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
2688                 int cmd, struct snd_soc_platform *platform)
2689 {
2690         if (platform->driver->ops && platform->driver->ops->trigger)
2691                 return platform->driver->ops->trigger(substream, cmd);
2692         return 0;
2693 }
2694 EXPORT_SYMBOL_GPL(snd_soc_platform_trigger);
2695 
2696 #ifdef CONFIG_DEBUG_FS
2697 static char *dpcm_state_string(enum snd_soc_dpcm_state state)
2698 {
2699         switch (state) {
2700         case SND_SOC_DPCM_STATE_NEW:
2701                 return "new";
2702         case SND_SOC_DPCM_STATE_OPEN:
2703                 return "open";
2704         case SND_SOC_DPCM_STATE_HW_PARAMS:
2705                 return "hw_params";
2706         case SND_SOC_DPCM_STATE_PREPARE:
2707                 return "prepare";
2708         case SND_SOC_DPCM_STATE_START:
2709                 return "start";
2710         case SND_SOC_DPCM_STATE_STOP:
2711                 return "stop";
2712         case SND_SOC_DPCM_STATE_SUSPEND:
2713                 return "suspend";
2714         case SND_SOC_DPCM_STATE_PAUSED:
2715                 return "paused";
2716         case SND_SOC_DPCM_STATE_HW_FREE:
2717                 return "hw_free";
2718         case SND_SOC_DPCM_STATE_CLOSE:
2719                 return "close";
2720         }
2721 
2722         return "unknown";
2723 }
2724 
2725 static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
2726                                 int stream, char *buf, size_t size)
2727 {
2728         struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
2729         struct snd_soc_dpcm *dpcm;
2730         ssize_t offset = 0;
2731 
2732         /* FE state */
2733         offset += snprintf(buf + offset, size - offset,
2734                         "[%s - %s]\n", fe->dai_link->name,
2735                         stream ? "Capture" : "Playback");
2736 
2737         offset += snprintf(buf + offset, size - offset, "State: %s\n",
2738                         dpcm_state_string(fe->dpcm[stream].state));
2739 
2740         if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2741             (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2742                 offset += snprintf(buf + offset, size - offset,
2743                                 "Hardware Params: "
2744                                 "Format = %s, Channels = %d, Rate = %d\n",
2745                                 snd_pcm_format_name(params_format(params)),
2746                                 params_channels(params),
2747                                 params_rate(params));
2748 
2749         /* BEs state */
2750         offset += snprintf(buf + offset, size - offset, "Backends:\n");
2751 
2752         if (list_empty(&fe->dpcm[stream].be_clients)) {
2753                 offset += snprintf(buf + offset, size - offset,
2754                                 " No active DSP links\n");
2755                 goto out;
2756         }
2757 
2758         list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
2759                 struct snd_soc_pcm_runtime *be = dpcm->be;
2760                 params = &dpcm->hw_params;
2761 
2762                 offset += snprintf(buf + offset, size - offset,
2763                                 "- %s\n", be->dai_link->name);
2764 
2765                 offset += snprintf(buf + offset, size - offset,
2766                                 "   State: %s\n",
2767                                 dpcm_state_string(be->dpcm[stream].state));
2768 
2769                 if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
2770                     (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
2771                         offset += snprintf(buf + offset, size - offset,
2772                                 "   Hardware Params: "
2773                                 "Format = %s, Channels = %d, Rate = %d\n",
2774                                 snd_pcm_format_name(params_format(params)),
2775                                 params_channels(params),
2776                                 params_rate(params));
2777         }
2778 
2779 out:
2780         return offset;
2781 }
2782 
2783 static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
2784                                 size_t count, loff_t *ppos)
2785 {
2786         struct snd_soc_pcm_runtime *fe = file->private_data;
2787         ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
2788         char *buf;
2789 
2790         buf = kmalloc(out_count, GFP_KERNEL);
2791         if (!buf)
2792                 return -ENOMEM;
2793 
2794         if (fe->cpu_dai->driver->playback.channels_min)
2795                 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK,
2796                                         buf + offset, out_count - offset);
2797 
2798         if (fe->cpu_dai->driver->capture.channels_min)
2799                 offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE,
2800                                         buf + offset, out_count - offset);
2801 
2802         ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
2803 
2804         kfree(buf);
2805         return ret;
2806 }
2807 
2808 static const struct file_operations dpcm_state_fops = {
2809         .open = simple_open,
2810         .read = dpcm_state_read_file,
2811         .llseek = default_llseek,
2812 };
2813 
2814 void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
2815 {
2816         if (!rtd->dai_link)
2817                 return;
2818 
2819         if (!rtd->card->debugfs_card_root)
2820                 return;
2821 
2822         rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
2823                         rtd->card->debugfs_card_root);
2824         if (!rtd->debugfs_dpcm_root) {
2825                 dev_dbg(rtd->dev,
2826                          "ASoC: Failed to create dpcm debugfs directory %s\n",
2827                          rtd->dai_link->name);
2828                 return;
2829         }
2830 
2831         rtd->debugfs_dpcm_state = debugfs_create_file("state", 0444,
2832                                                 rtd->debugfs_dpcm_root,
2833                                                 rtd, &dpcm_state_fops);
2834 }
2835 #endif
2836 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp