Kuninori Morimoto | ed51758 | 2018-07-02 06:22:44 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // soc-pcm.c -- ALSA SoC PCM |
| 4 | // |
| 5 | // Copyright 2005 Wolfson Microelectronics PLC. |
| 6 | // Copyright 2005 Openedhand Ltd. |
| 7 | // Copyright (C) 2010 Slimlogic Ltd. |
| 8 | // Copyright (C) 2010 Texas Instruments Inc. |
| 9 | // |
| 10 | // Authors: Liam Girdwood <lrg@ti.com> |
| 11 | // Mark Brown <broonie@opensource.wolfsonmicro.com> |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/delay.h> |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 16 | #include <linux/pinctrl/consumer.h> |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 17 | #include <linux/pm_runtime.h> |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 18 | #include <linux/slab.h> |
| 19 | #include <linux/workqueue.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 20 | #include <linux/export.h> |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include <sound/soc.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 26 | #include <sound/soc-dpcm.h> |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 27 | #include <sound/initval.h> |
| 28 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 29 | #define DPCM_MAX_BE_USERS 8 |
| 30 | |
Ricard Wanderlof | cde7903 | 2015-08-24 14:16:51 +0200 | [diff] [blame] | 31 | /* |
| 32 | * snd_soc_dai_stream_valid() - check if a DAI supports the given stream |
| 33 | * |
| 34 | * Returns true if the DAI supports the indicated stream type. |
| 35 | */ |
| 36 | static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream) |
| 37 | { |
| 38 | struct snd_soc_pcm_stream *codec_stream; |
| 39 | |
| 40 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 41 | codec_stream = &dai->driver->playback; |
| 42 | else |
| 43 | codec_stream = &dai->driver->capture; |
| 44 | |
| 45 | /* If the codec specifies any rate at all, it supports the stream. */ |
| 46 | return codec_stream->rates; |
| 47 | } |
| 48 | |
Lars-Peter Clausen | 90996f4 | 2013-05-14 11:05:30 +0200 | [diff] [blame] | 49 | /** |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 50 | * snd_soc_runtime_activate() - Increment active count for PCM runtime components |
| 51 | * @rtd: ASoC PCM runtime that is activated |
| 52 | * @stream: Direction of the PCM stream |
| 53 | * |
| 54 | * Increments the active count for all the DAIs and components attached to a PCM |
| 55 | * runtime. Should typically be called when a stream is opened. |
| 56 | * |
| 57 | * Must be called with the rtd->pcm_mutex being held |
| 58 | */ |
| 59 | void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) |
| 60 | { |
| 61 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 62 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 63 | int i; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 64 | |
| 65 | lockdep_assert_held(&rtd->pcm_mutex); |
| 66 | |
| 67 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 68 | cpu_dai->playback_active++; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 69 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 70 | codec_dai->playback_active++; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 71 | } else { |
| 72 | cpu_dai->capture_active++; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 73 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 74 | codec_dai->capture_active++; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | cpu_dai->active++; |
Lars-Peter Clausen | cdde4cc | 2014-03-05 13:17:47 +0100 | [diff] [blame] | 78 | cpu_dai->component->active++; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 79 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 80 | codec_dai->active++; |
| 81 | codec_dai->component->active++; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 82 | } |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components |
| 87 | * @rtd: ASoC PCM runtime that is deactivated |
| 88 | * @stream: Direction of the PCM stream |
| 89 | * |
| 90 | * Decrements the active count for all the DAIs and components attached to a PCM |
| 91 | * runtime. Should typically be called when a stream is closed. |
| 92 | * |
| 93 | * Must be called with the rtd->pcm_mutex being held |
| 94 | */ |
| 95 | void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) |
| 96 | { |
| 97 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 98 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 99 | int i; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 100 | |
| 101 | lockdep_assert_held(&rtd->pcm_mutex); |
| 102 | |
| 103 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 104 | cpu_dai->playback_active--; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 105 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 106 | codec_dai->playback_active--; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 107 | } else { |
| 108 | cpu_dai->capture_active--; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 109 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 110 | codec_dai->capture_active--; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | cpu_dai->active--; |
Lars-Peter Clausen | cdde4cc | 2014-03-05 13:17:47 +0100 | [diff] [blame] | 114 | cpu_dai->component->active--; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 115 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 116 | codec_dai->component->active--; |
| 117 | codec_dai->active--; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 118 | } |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 122 | * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay |
| 123 | * @rtd: The ASoC PCM runtime that should be checked. |
| 124 | * |
| 125 | * This function checks whether the power down delay should be ignored for a |
| 126 | * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has |
| 127 | * been configured to ignore the delay, or if none of the components benefits |
| 128 | * from having the delay. |
| 129 | */ |
| 130 | bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) |
| 131 | { |
Kuninori Morimoto | fbb1656 | 2017-10-11 01:38:08 +0000 | [diff] [blame] | 132 | struct snd_soc_rtdcom_list *rtdcom; |
| 133 | struct snd_soc_component *component; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 134 | bool ignore = true; |
| 135 | |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 136 | if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) |
| 137 | return true; |
| 138 | |
Kuninori Morimoto | fbb1656 | 2017-10-11 01:38:08 +0000 | [diff] [blame] | 139 | for_each_rtdcom(rtd, rtdcom) { |
| 140 | component = rtdcom->component; |
| 141 | |
Kuninori Morimoto | 72c3818 | 2018-01-19 05:21:19 +0000 | [diff] [blame] | 142 | ignore &= !component->driver->use_pmdown_time; |
Kuninori Morimoto | fbb1656 | 2017-10-11 01:38:08 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Kuninori Morimoto | fbb1656 | 2017-10-11 01:38:08 +0000 | [diff] [blame] | 145 | return ignore; |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
Lars-Peter Clausen | 90996f4 | 2013-05-14 11:05:30 +0200 | [diff] [blame] | 149 | * snd_soc_set_runtime_hwparams - set the runtime hardware parameters |
| 150 | * @substream: the pcm substream |
| 151 | * @hw: the hardware parameters |
| 152 | * |
| 153 | * Sets the substream runtime hardware parameters. |
| 154 | */ |
| 155 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 156 | const struct snd_pcm_hardware *hw) |
| 157 | { |
| 158 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 159 | runtime->hw.info = hw->info; |
| 160 | runtime->hw.formats = hw->formats; |
| 161 | runtime->hw.period_bytes_min = hw->period_bytes_min; |
| 162 | runtime->hw.period_bytes_max = hw->period_bytes_max; |
| 163 | runtime->hw.periods_min = hw->periods_min; |
| 164 | runtime->hw.periods_max = hw->periods_max; |
| 165 | runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; |
| 166 | runtime->hw.fifo_size = hw->fifo_size; |
| 167 | return 0; |
| 168 | } |
| 169 | EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); |
| 170 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 171 | /* DPCM stream event, send event to FE and all active BEs. */ |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 172 | int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir, |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 173 | int event) |
| 174 | { |
| 175 | struct snd_soc_dpcm *dpcm; |
| 176 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 177 | for_each_dpcm_be(fe, dir, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 178 | |
| 179 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 180 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 181 | dev_dbg(be->dev, "ASoC: BE %s event %d dir %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 182 | be->dai_link->name, event, dir); |
| 183 | |
Banajit Goswami | b1cd2e3 | 2017-07-14 23:15:05 -0700 | [diff] [blame] | 184 | if ((event == SND_SOC_DAPM_STREAM_STOP) && |
| 185 | (be->dpcm[dir].users >= 1)) |
| 186 | continue; |
| 187 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 188 | snd_soc_dapm_stream_event(be, dir, event); |
| 189 | } |
| 190 | |
| 191 | snd_soc_dapm_stream_event(fe, dir, event); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 196 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, |
| 197 | struct snd_soc_dai *soc_dai) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 198 | { |
| 199 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 200 | int ret; |
| 201 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 202 | if (soc_dai->rate && (soc_dai->driver->symmetric_rates || |
| 203 | rtd->dai_link->symmetric_rates)) { |
| 204 | dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %dHz rate\n", |
| 205 | soc_dai->rate); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 206 | |
Lars-Peter Clausen | 4dcdd43 | 2015-10-18 15:39:28 +0200 | [diff] [blame] | 207 | ret = snd_pcm_hw_constraint_single(substream->runtime, |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 208 | SNDRV_PCM_HW_PARAM_RATE, |
Lars-Peter Clausen | 4dcdd43 | 2015-10-18 15:39:28 +0200 | [diff] [blame] | 209 | soc_dai->rate); |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 210 | if (ret < 0) { |
| 211 | dev_err(soc_dai->dev, |
| 212 | "ASoC: Unable to apply rate constraint: %d\n", |
| 213 | ret); |
| 214 | return ret; |
| 215 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 218 | if (soc_dai->channels && (soc_dai->driver->symmetric_channels || |
| 219 | rtd->dai_link->symmetric_channels)) { |
| 220 | dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d channel(s)\n", |
| 221 | soc_dai->channels); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 222 | |
Lars-Peter Clausen | 4dcdd43 | 2015-10-18 15:39:28 +0200 | [diff] [blame] | 223 | ret = snd_pcm_hw_constraint_single(substream->runtime, |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 224 | SNDRV_PCM_HW_PARAM_CHANNELS, |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 225 | soc_dai->channels); |
| 226 | if (ret < 0) { |
| 227 | dev_err(soc_dai->dev, |
| 228 | "ASoC: Unable to apply channel symmetry constraint: %d\n", |
| 229 | ret); |
| 230 | return ret; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | if (soc_dai->sample_bits && (soc_dai->driver->symmetric_samplebits || |
| 235 | rtd->dai_link->symmetric_samplebits)) { |
| 236 | dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %d sample bits\n", |
| 237 | soc_dai->sample_bits); |
| 238 | |
Lars-Peter Clausen | 4dcdd43 | 2015-10-18 15:39:28 +0200 | [diff] [blame] | 239 | ret = snd_pcm_hw_constraint_single(substream->runtime, |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 240 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 241 | soc_dai->sample_bits); |
| 242 | if (ret < 0) { |
| 243 | dev_err(soc_dai->dev, |
| 244 | "ASoC: Unable to apply sample bits symmetry constraint: %d\n", |
| 245 | ret); |
| 246 | return ret; |
| 247 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 253 | static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, |
| 254 | struct snd_pcm_hw_params *params) |
| 255 | { |
| 256 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 257 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 258 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 259 | unsigned int rate, channels, sample_bits, symmetry, i; |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 260 | |
| 261 | rate = params_rate(params); |
| 262 | channels = params_channels(params); |
| 263 | sample_bits = snd_pcm_format_physical_width(params_format(params)); |
| 264 | |
| 265 | /* reject unmatched parameters when applying symmetry */ |
| 266 | symmetry = cpu_dai->driver->symmetric_rates || |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 267 | rtd->dai_link->symmetric_rates; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 268 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 269 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 270 | symmetry |= codec_dai->driver->symmetric_rates; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 271 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 272 | if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) { |
| 273 | dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n", |
| 274 | cpu_dai->rate, rate); |
| 275 | return -EINVAL; |
| 276 | } |
| 277 | |
| 278 | symmetry = cpu_dai->driver->symmetric_channels || |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 279 | rtd->dai_link->symmetric_channels; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 280 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 281 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 282 | symmetry |= codec_dai->driver->symmetric_channels; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 283 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 284 | if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) { |
| 285 | dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n", |
| 286 | cpu_dai->channels, channels); |
| 287 | return -EINVAL; |
| 288 | } |
| 289 | |
| 290 | symmetry = cpu_dai->driver->symmetric_samplebits || |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 291 | rtd->dai_link->symmetric_samplebits; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 292 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 293 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 294 | symmetry |= codec_dai->driver->symmetric_samplebits; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 295 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 296 | if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) { |
| 297 | dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n", |
| 298 | cpu_dai->sample_bits, sample_bits); |
| 299 | return -EINVAL; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
Lars-Peter Clausen | 62e5f67 | 2013-11-30 17:38:58 +0100 | [diff] [blame] | 305 | static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream) |
| 306 | { |
| 307 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 308 | struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver; |
Lars-Peter Clausen | 62e5f67 | 2013-11-30 17:38:58 +0100 | [diff] [blame] | 309 | struct snd_soc_dai_link *link = rtd->dai_link; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 310 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 311 | unsigned int symmetry, i; |
Lars-Peter Clausen | 62e5f67 | 2013-11-30 17:38:58 +0100 | [diff] [blame] | 312 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 313 | symmetry = cpu_driver->symmetric_rates || link->symmetric_rates || |
| 314 | cpu_driver->symmetric_channels || link->symmetric_channels || |
| 315 | cpu_driver->symmetric_samplebits || link->symmetric_samplebits; |
| 316 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 317 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 318 | symmetry = symmetry || |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 319 | codec_dai->driver->symmetric_rates || |
| 320 | codec_dai->driver->symmetric_channels || |
| 321 | codec_dai->driver->symmetric_samplebits; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 322 | |
| 323 | return symmetry; |
Lars-Peter Clausen | 62e5f67 | 2013-11-30 17:38:58 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 326 | static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits) |
Mark Brown | 58ba9b2 | 2012-01-16 18:38:51 +0000 | [diff] [blame] | 327 | { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 328 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Takashi Iwai | c6068d3 | 2014-12-31 17:10:34 +0100 | [diff] [blame] | 329 | int ret; |
Mark Brown | 58ba9b2 | 2012-01-16 18:38:51 +0000 | [diff] [blame] | 330 | |
| 331 | if (!bits) |
| 332 | return; |
| 333 | |
Lars-Peter Clausen | 0e2a375 | 2014-12-29 18:43:38 +0100 | [diff] [blame] | 334 | ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 0, bits); |
| 335 | if (ret != 0) |
| 336 | dev_warn(rtd->dev, "ASoC: Failed to set MSB %d: %d\n", |
| 337 | bits, ret); |
Mark Brown | 58ba9b2 | 2012-01-16 18:38:51 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 340 | static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) |
Lars-Peter Clausen | bd477c3 | 2013-05-14 11:05:31 +0200 | [diff] [blame] | 341 | { |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 342 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 343 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 344 | struct snd_soc_dai *codec_dai; |
| 345 | int i; |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 346 | unsigned int bits = 0, cpu_bits; |
| 347 | |
| 348 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 349 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 350 | if (codec_dai->driver->playback.sig_bits == 0) { |
| 351 | bits = 0; |
| 352 | break; |
| 353 | } |
| 354 | bits = max(codec_dai->driver->playback.sig_bits, bits); |
| 355 | } |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 356 | cpu_bits = cpu_dai->driver->playback.sig_bits; |
| 357 | } else { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 358 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Daniel Mack | 5e63dfc | 2014-10-07 14:33:46 +0200 | [diff] [blame] | 359 | if (codec_dai->driver->capture.sig_bits == 0) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 360 | bits = 0; |
| 361 | break; |
| 362 | } |
| 363 | bits = max(codec_dai->driver->capture.sig_bits, bits); |
| 364 | } |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 365 | cpu_bits = cpu_dai->driver->capture.sig_bits; |
| 366 | } |
| 367 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 368 | soc_pcm_set_msb(substream, bits); |
| 369 | soc_pcm_set_msb(substream, cpu_bits); |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 372 | static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) |
Lars-Peter Clausen | bd477c3 | 2013-05-14 11:05:31 +0200 | [diff] [blame] | 373 | { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 374 | struct snd_pcm_runtime *runtime = substream->runtime; |
Lars-Peter Clausen | 78e45c9 | 2013-11-27 09:58:18 +0100 | [diff] [blame] | 375 | struct snd_pcm_hardware *hw = &runtime->hw; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 376 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 377 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 378 | struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver; |
| 379 | struct snd_soc_dai_driver *codec_dai_drv; |
| 380 | struct snd_soc_pcm_stream *codec_stream; |
| 381 | struct snd_soc_pcm_stream *cpu_stream; |
| 382 | unsigned int chan_min = 0, chan_max = UINT_MAX; |
| 383 | unsigned int rate_min = 0, rate_max = UINT_MAX; |
| 384 | unsigned int rates = UINT_MAX; |
| 385 | u64 formats = ULLONG_MAX; |
| 386 | int i; |
Lars-Peter Clausen | 78e45c9 | 2013-11-27 09:58:18 +0100 | [diff] [blame] | 387 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 388 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 389 | cpu_stream = &cpu_dai_drv->playback; |
Lars-Peter Clausen | 16d7ea9 | 2014-01-06 14:19:16 +0100 | [diff] [blame] | 390 | else |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 391 | cpu_stream = &cpu_dai_drv->capture; |
Lars-Peter Clausen | 78e45c9 | 2013-11-27 09:58:18 +0100 | [diff] [blame] | 392 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 393 | /* first calculate min/max only for CODECs in the DAI link */ |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 394 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Ricard Wanderlof | cde7903 | 2015-08-24 14:16:51 +0200 | [diff] [blame] | 395 | |
| 396 | /* |
| 397 | * Skip CODECs which don't support the current stream type. |
| 398 | * Otherwise, since the rate, channel, and format values will |
| 399 | * zero in that case, we would have no usable settings left, |
| 400 | * causing the resulting setup to fail. |
| 401 | * At least one CODEC should match, otherwise we should have |
| 402 | * bailed out on a higher level, since there would be no |
| 403 | * CODEC to support the transfer direction in that case. |
| 404 | */ |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 405 | if (!snd_soc_dai_stream_valid(codec_dai, |
Ricard Wanderlof | cde7903 | 2015-08-24 14:16:51 +0200 | [diff] [blame] | 406 | substream->stream)) |
| 407 | continue; |
| 408 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 409 | codec_dai_drv = codec_dai->driver; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 410 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 411 | codec_stream = &codec_dai_drv->playback; |
| 412 | else |
| 413 | codec_stream = &codec_dai_drv->capture; |
| 414 | chan_min = max(chan_min, codec_stream->channels_min); |
| 415 | chan_max = min(chan_max, codec_stream->channels_max); |
| 416 | rate_min = max(rate_min, codec_stream->rate_min); |
| 417 | rate_max = min_not_zero(rate_max, codec_stream->rate_max); |
| 418 | formats &= codec_stream->formats; |
| 419 | rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates); |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * chan min/max cannot be enforced if there are multiple CODEC DAIs |
| 424 | * connected to a single CPU DAI, use CPU DAI's directly and let |
| 425 | * channel allocation be fixed up later |
| 426 | */ |
| 427 | if (rtd->num_codecs > 1) { |
| 428 | chan_min = cpu_stream->channels_min; |
| 429 | chan_max = cpu_stream->channels_max; |
| 430 | } |
| 431 | |
| 432 | hw->channels_min = max(chan_min, cpu_stream->channels_min); |
| 433 | hw->channels_max = min(chan_max, cpu_stream->channels_max); |
| 434 | if (hw->formats) |
| 435 | hw->formats &= formats & cpu_stream->formats; |
| 436 | else |
| 437 | hw->formats = formats & cpu_stream->formats; |
| 438 | hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates); |
Lars-Peter Clausen | 78e45c9 | 2013-11-27 09:58:18 +0100 | [diff] [blame] | 439 | |
| 440 | snd_pcm_limit_hw_rates(runtime); |
| 441 | |
| 442 | hw->rate_min = max(hw->rate_min, cpu_stream->rate_min); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 443 | hw->rate_min = max(hw->rate_min, rate_min); |
Lars-Peter Clausen | 78e45c9 | 2013-11-27 09:58:18 +0100 | [diff] [blame] | 444 | hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 445 | hw->rate_max = min_not_zero(hw->rate_max, rate_max); |
Lars-Peter Clausen | bd477c3 | 2013-05-14 11:05:31 +0200 | [diff] [blame] | 446 | } |
| 447 | |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 448 | static int soc_pcm_components_close(struct snd_pcm_substream *substream, |
| 449 | struct snd_soc_component *last) |
| 450 | { |
| 451 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 452 | struct snd_soc_rtdcom_list *rtdcom; |
| 453 | struct snd_soc_component *component; |
| 454 | |
| 455 | for_each_rtdcom(rtd, rtdcom) { |
| 456 | component = rtdcom->component; |
| 457 | |
| 458 | if (component == last) |
| 459 | break; |
| 460 | |
| 461 | if (!component->driver->ops || |
| 462 | !component->driver->ops->close) |
| 463 | continue; |
| 464 | |
| 465 | component->driver->ops->close(substream); |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Mark Brown | 58ba9b2 | 2012-01-16 18:38:51 +0000 | [diff] [blame] | 471 | /* |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 472 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is |
| 473 | * then initialized and any private data can be allocated. This also calls |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 474 | * startup for the cpu DAI, component, machine and codec DAI. |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 475 | */ |
| 476 | static int soc_pcm_open(struct snd_pcm_substream *substream) |
| 477 | { |
| 478 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 479 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 480 | struct snd_soc_component *component; |
| 481 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 482 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 483 | struct snd_soc_dai *codec_dai; |
| 484 | const char *codec_dai_name = "multicodec"; |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 485 | int i, ret = 0; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 486 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 487 | pinctrl_pm_select_default_state(cpu_dai->dev); |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 488 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 489 | pinctrl_pm_select_default_state(codec_dai->dev); |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 490 | |
| 491 | for_each_rtdcom(rtd, rtdcom) { |
| 492 | component = rtdcom->component; |
| 493 | |
| 494 | pm_runtime_get_sync(component->dev); |
| 495 | } |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 496 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 497 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 498 | |
| 499 | /* startup the audio subsystem */ |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 500 | if (cpu_dai->driver->ops->startup) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 501 | ret = cpu_dai->driver->ops->startup(substream, cpu_dai); |
| 502 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 503 | dev_err(cpu_dai->dev, "ASoC: can't open interface" |
| 504 | " %s: %d\n", cpu_dai->name, ret); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 505 | goto out; |
| 506 | } |
| 507 | } |
| 508 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 509 | for_each_rtdcom(rtd, rtdcom) { |
| 510 | component = rtdcom->component; |
| 511 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 512 | if (!component->driver->ops || |
| 513 | !component->driver->ops->open) |
| 514 | continue; |
| 515 | |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 516 | ret = component->driver->ops->open(substream); |
| 517 | if (ret < 0) { |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 518 | dev_err(component->dev, |
| 519 | "ASoC: can't open component %s: %d\n", |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 520 | component->name, ret); |
| 521 | goto component_err; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 522 | } |
| 523 | } |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 524 | component = NULL; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 525 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 526 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 527 | if (codec_dai->driver->ops->startup) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 528 | ret = codec_dai->driver->ops->startup(substream, |
| 529 | codec_dai); |
| 530 | if (ret < 0) { |
| 531 | dev_err(codec_dai->dev, |
| 532 | "ASoC: can't open codec %s: %d\n", |
| 533 | codec_dai->name, ret); |
| 534 | goto codec_dai_err; |
| 535 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 536 | } |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 537 | |
| 538 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 539 | codec_dai->tx_mask = 0; |
| 540 | else |
| 541 | codec_dai->rx_mask = 0; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 544 | if (rtd->dai_link->ops->startup) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 545 | ret = rtd->dai_link->ops->startup(substream); |
| 546 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 547 | pr_err("ASoC: %s startup failed: %d\n", |
Mark Brown | 25bfe66 | 2012-02-01 21:30:32 +0000 | [diff] [blame] | 548 | rtd->dai_link->name, ret); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 549 | goto machine_err; |
| 550 | } |
| 551 | } |
| 552 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 553 | /* Dynamic PCM DAI links compat checks use dynamic capabilities */ |
| 554 | if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) |
| 555 | goto dynamic; |
| 556 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 557 | /* Check that the codec and cpu DAIs are compatible */ |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 558 | soc_pcm_init_runtime_hw(substream); |
| 559 | |
| 560 | if (rtd->num_codecs == 1) |
| 561 | codec_dai_name = rtd->codec_dai->name; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 562 | |
Lars-Peter Clausen | 62e5f67 | 2013-11-30 17:38:58 +0100 | [diff] [blame] | 563 | if (soc_pcm_has_symmetry(substream)) |
| 564 | runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 565 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 566 | ret = -EINVAL; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 567 | if (!runtime->hw.rates) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 568 | printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n", |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 569 | codec_dai_name, cpu_dai->name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 570 | goto config_err; |
| 571 | } |
| 572 | if (!runtime->hw.formats) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 573 | printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n", |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 574 | codec_dai_name, cpu_dai->name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 575 | goto config_err; |
| 576 | } |
| 577 | if (!runtime->hw.channels_min || !runtime->hw.channels_max || |
| 578 | runtime->hw.channels_min > runtime->hw.channels_max) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 579 | printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n", |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 580 | codec_dai_name, cpu_dai->name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 581 | goto config_err; |
| 582 | } |
| 583 | |
Benoit Cousson | c8dd1fe | 2014-07-01 09:47:55 +0200 | [diff] [blame] | 584 | soc_pcm_apply_msb(substream); |
Mark Brown | 58ba9b2 | 2012-01-16 18:38:51 +0000 | [diff] [blame] | 585 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 586 | /* Symmetry only applies if we've already got an active stream. */ |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 587 | if (cpu_dai->active) { |
| 588 | ret = soc_pcm_apply_symmetry(substream, cpu_dai); |
| 589 | if (ret != 0) |
| 590 | goto config_err; |
| 591 | } |
| 592 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 593 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 594 | if (codec_dai->active) { |
| 595 | ret = soc_pcm_apply_symmetry(substream, codec_dai); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 596 | if (ret != 0) |
| 597 | goto config_err; |
| 598 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 599 | } |
| 600 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 601 | pr_debug("ASoC: %s <-> %s info:\n", |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 602 | codec_dai_name, cpu_dai->name); |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 603 | pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates); |
| 604 | pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min, |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 605 | runtime->hw.channels_max); |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 606 | pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min, |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 607 | runtime->hw.rate_max); |
| 608 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 609 | dynamic: |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 610 | |
| 611 | snd_soc_runtime_activate(rtd, substream->stream); |
| 612 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 613 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 614 | return 0; |
| 615 | |
| 616 | config_err: |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 617 | if (rtd->dai_link->ops->shutdown) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 618 | rtd->dai_link->ops->shutdown(substream); |
| 619 | |
| 620 | machine_err: |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 621 | i = rtd->num_codecs; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 622 | |
| 623 | codec_dai_err: |
Kuninori Morimoto | 6d11b12 | 2018-09-18 01:28:30 +0000 | [diff] [blame] | 624 | for_each_rtd_codec_dai_rollback(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 625 | if (codec_dai->driver->ops->shutdown) |
| 626 | codec_dai->driver->ops->shutdown(substream, codec_dai); |
| 627 | } |
| 628 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 629 | component_err: |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 630 | soc_pcm_components_close(substream, component); |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 631 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 632 | if (cpu_dai->driver->ops->shutdown) |
| 633 | cpu_dai->driver->ops->shutdown(substream, cpu_dai); |
| 634 | out: |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 635 | mutex_unlock(&rtd->pcm_mutex); |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 636 | |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 637 | for_each_rtdcom(rtd, rtdcom) { |
| 638 | component = rtdcom->component; |
| 639 | |
| 640 | pm_runtime_mark_last_busy(component->dev); |
| 641 | pm_runtime_put_autosuspend(component->dev); |
Sanyog Kale | 3f80978 | 2016-01-05 17:14:49 +0530 | [diff] [blame] | 642 | } |
| 643 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 644 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 645 | if (!codec_dai->active) |
| 646 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 647 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 648 | if (!cpu_dai->active) |
| 649 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 650 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 651 | return ret; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Power down the audio subsystem pmdown_time msecs after close is called. |
| 656 | * This is to ensure there are no pops or clicks in between any music tracks |
| 657 | * due to DAPM power cycling. |
| 658 | */ |
| 659 | static void close_delayed_work(struct work_struct *work) |
| 660 | { |
| 661 | struct snd_soc_pcm_runtime *rtd = |
| 662 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 663 | struct snd_soc_dai *codec_dai = rtd->codec_dais[0]; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 664 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 665 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 666 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 667 | dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n", |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 668 | codec_dai->driver->playback.stream_name, |
| 669 | codec_dai->playback_active ? "active" : "inactive", |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 670 | rtd->pop_wait ? "yes" : "no"); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 671 | |
| 672 | /* are we waiting on this codec DAI stream */ |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 673 | if (rtd->pop_wait == 1) { |
| 674 | rtd->pop_wait = 0; |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 675 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 676 | SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 679 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /* |
| 683 | * Called by ALSA when a PCM substream is closed. Private data can be |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 684 | * freed here. The cpu DAI, codec DAI, machine and components are also |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 685 | * shutdown. |
| 686 | */ |
Liam Girdwood | 91d5e6b | 2011-06-09 17:04:59 +0100 | [diff] [blame] | 687 | static int soc_pcm_close(struct snd_pcm_substream *substream) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 688 | { |
| 689 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 690 | struct snd_soc_component *component; |
| 691 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 692 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 693 | struct snd_soc_dai *codec_dai; |
| 694 | int i; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 695 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 696 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 697 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 698 | snd_soc_runtime_deactivate(rtd, substream->stream); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 699 | |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 700 | /* clear the corresponding DAIs rate when inactive */ |
| 701 | if (!cpu_dai->active) |
| 702 | cpu_dai->rate = 0; |
| 703 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 704 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 705 | if (!codec_dai->active) |
| 706 | codec_dai->rate = 0; |
| 707 | } |
Sascha Hauer | 25b7679 | 2011-08-17 09:20:01 +0200 | [diff] [blame] | 708 | |
Ramesh Babu | ae11601 | 2014-10-15 12:34:59 +0530 | [diff] [blame] | 709 | snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream); |
| 710 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 711 | if (cpu_dai->driver->ops->shutdown) |
| 712 | cpu_dai->driver->ops->shutdown(substream, cpu_dai); |
| 713 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 714 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 715 | if (codec_dai->driver->ops->shutdown) |
| 716 | codec_dai->driver->ops->shutdown(substream, codec_dai); |
| 717 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 718 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 719 | if (rtd->dai_link->ops->shutdown) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 720 | rtd->dai_link->ops->shutdown(substream); |
| 721 | |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 722 | soc_pcm_components_close(substream, NULL); |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 723 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 724 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 725 | if (snd_soc_runtime_ignore_pmdown_time(rtd)) { |
Peter Ujfalusi | 1d69c5c | 2011-10-14 14:43:33 +0300 | [diff] [blame] | 726 | /* powered down playback stream now */ |
| 727 | snd_soc_dapm_stream_event(rtd, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 728 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 729 | SND_SOC_DAPM_STREAM_STOP); |
Peter Ujfalusi | 1d69c5c | 2011-10-14 14:43:33 +0300 | [diff] [blame] | 730 | } else { |
| 731 | /* start delayed pop wq here for playback streams */ |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 732 | rtd->pop_wait = 1; |
Mark Brown | d4e1a73 | 2013-07-18 11:52:17 +0100 | [diff] [blame] | 733 | queue_delayed_work(system_power_efficient_wq, |
| 734 | &rtd->delayed_work, |
| 735 | msecs_to_jiffies(rtd->pmdown_time)); |
Peter Ujfalusi | 1d69c5c | 2011-10-14 14:43:33 +0300 | [diff] [blame] | 736 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 737 | } else { |
| 738 | /* capture streams can be powered down now */ |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 739 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 740 | SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 743 | mutex_unlock(&rtd->pcm_mutex); |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 744 | |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 745 | for_each_rtdcom(rtd, rtdcom) { |
| 746 | component = rtdcom->component; |
Sanyog Kale | 3f80978 | 2016-01-05 17:14:49 +0530 | [diff] [blame] | 747 | |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 748 | pm_runtime_mark_last_busy(component->dev); |
| 749 | pm_runtime_put_autosuspend(component->dev); |
Sanyog Kale | 3f80978 | 2016-01-05 17:14:49 +0530 | [diff] [blame] | 750 | } |
| 751 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 752 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 753 | if (!codec_dai->active) |
| 754 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 755 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 756 | if (!cpu_dai->active) |
| 757 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Mark Brown | d6652ef | 2011-12-03 20:14:31 +0000 | [diff] [blame] | 758 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | /* |
| 763 | * Called by ALSA when the PCM substream is prepared, can set format, sample |
| 764 | * rate, etc. This function is non atomic and can be called multiple times, |
| 765 | * it can refer to the runtime info. |
| 766 | */ |
| 767 | static int soc_pcm_prepare(struct snd_pcm_substream *substream) |
| 768 | { |
| 769 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 770 | struct snd_soc_component *component; |
| 771 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 772 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 773 | struct snd_soc_dai *codec_dai; |
| 774 | int i, ret = 0; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 775 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 776 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 777 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 778 | if (rtd->dai_link->ops->prepare) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 779 | ret = rtd->dai_link->ops->prepare(substream); |
| 780 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 781 | dev_err(rtd->card->dev, "ASoC: machine prepare error:" |
| 782 | " %d\n", ret); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 783 | goto out; |
| 784 | } |
| 785 | } |
| 786 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 787 | for_each_rtdcom(rtd, rtdcom) { |
| 788 | component = rtdcom->component; |
| 789 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 790 | if (!component->driver->ops || |
| 791 | !component->driver->ops->prepare) |
| 792 | continue; |
| 793 | |
| 794 | ret = component->driver->ops->prepare(substream); |
| 795 | if (ret < 0) { |
| 796 | dev_err(component->dev, |
| 797 | "ASoC: platform prepare error: %d\n", ret); |
| 798 | goto out; |
| 799 | } |
| 800 | } |
| 801 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 802 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 803 | if (codec_dai->driver->ops->prepare) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 804 | ret = codec_dai->driver->ops->prepare(substream, |
| 805 | codec_dai); |
| 806 | if (ret < 0) { |
| 807 | dev_err(codec_dai->dev, |
Jarkko Nikula | 90cc7f1 | 2014-12-23 11:04:41 +0200 | [diff] [blame] | 808 | "ASoC: codec DAI prepare error: %d\n", |
| 809 | ret); |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 810 | goto out; |
| 811 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 815 | if (cpu_dai->driver->ops->prepare) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 816 | ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); |
| 817 | if (ret < 0) { |
Jarkko Nikula | 90cc7f1 | 2014-12-23 11:04:41 +0200 | [diff] [blame] | 818 | dev_err(cpu_dai->dev, |
| 819 | "ASoC: cpu DAI prepare error: %d\n", ret); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 820 | goto out; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /* cancel any delayed stream shutdown that is pending */ |
| 825 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 826 | rtd->pop_wait) { |
| 827 | rtd->pop_wait = 0; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 828 | cancel_delayed_work(&rtd->delayed_work); |
| 829 | } |
| 830 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 831 | snd_soc_dapm_stream_event(rtd, substream->stream, |
| 832 | SND_SOC_DAPM_STREAM_START); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 833 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 834 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 835 | snd_soc_dai_digital_mute(codec_dai, 0, |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 836 | substream->stream); |
Ramesh Babu | ae11601 | 2014-10-15 12:34:59 +0530 | [diff] [blame] | 837 | snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 838 | |
| 839 | out: |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 840 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 841 | return ret; |
| 842 | } |
| 843 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 844 | static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, |
| 845 | unsigned int mask) |
| 846 | { |
| 847 | struct snd_interval *interval; |
| 848 | int channels = hweight_long(mask); |
| 849 | |
| 850 | interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 851 | interval->min = channels; |
| 852 | interval->max = channels; |
| 853 | } |
| 854 | |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 855 | int soc_dai_hw_params(struct snd_pcm_substream *substream, |
| 856 | struct snd_pcm_hw_params *params, |
| 857 | struct snd_soc_dai *dai) |
| 858 | { |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 859 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 860 | int ret; |
| 861 | |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 862 | /* perform any topology hw_params fixups before DAI */ |
| 863 | if (rtd->dai_link->be_hw_params_fixup) { |
| 864 | ret = rtd->dai_link->be_hw_params_fixup(rtd, params); |
| 865 | if (ret < 0) { |
| 866 | dev_err(rtd->dev, |
| 867 | "ASoC: hw_params topology fixup failed %d\n", |
| 868 | ret); |
| 869 | return ret; |
| 870 | } |
| 871 | } |
| 872 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 873 | if (dai->driver->ops->hw_params) { |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 874 | ret = dai->driver->ops->hw_params(substream, params, dai); |
| 875 | if (ret < 0) { |
| 876 | dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n", |
| 877 | dai->name, ret); |
| 878 | return ret; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 885 | static int soc_pcm_components_hw_free(struct snd_pcm_substream *substream, |
| 886 | struct snd_soc_component *last) |
| 887 | { |
| 888 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 889 | struct snd_soc_rtdcom_list *rtdcom; |
| 890 | struct snd_soc_component *component; |
| 891 | |
| 892 | for_each_rtdcom(rtd, rtdcom) { |
| 893 | component = rtdcom->component; |
| 894 | |
| 895 | if (component == last) |
| 896 | break; |
| 897 | |
| 898 | if (!component->driver->ops || |
| 899 | !component->driver->ops->hw_free) |
| 900 | continue; |
| 901 | |
| 902 | component->driver->ops->hw_free(substream); |
| 903 | } |
| 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 908 | /* |
| 909 | * Called by ALSA when the hardware params are set by application. This |
| 910 | * function can also be called multiple times and can allocate buffers |
| 911 | * (using snd_pcm_lib_* ). It's non-atomic. |
| 912 | */ |
| 913 | static int soc_pcm_hw_params(struct snd_pcm_substream *substream, |
| 914 | struct snd_pcm_hw_params *params) |
| 915 | { |
| 916 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 917 | struct snd_soc_component *component; |
| 918 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 919 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 920 | struct snd_soc_dai *codec_dai; |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 921 | int i, ret = 0; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 922 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 923 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 924 | if (rtd->dai_link->ops->hw_params) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 925 | ret = rtd->dai_link->ops->hw_params(substream, params); |
| 926 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 927 | dev_err(rtd->card->dev, "ASoC: machine hw_params" |
| 928 | " failed: %d\n", ret); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 929 | goto out; |
| 930 | } |
| 931 | } |
| 932 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 933 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 934 | struct snd_pcm_hw_params codec_params; |
| 935 | |
Ricard Wanderlof | cde7903 | 2015-08-24 14:16:51 +0200 | [diff] [blame] | 936 | /* |
| 937 | * Skip CODECs which don't support the current stream type, |
| 938 | * the idea being that if a CODEC is not used for the currently |
| 939 | * set up transfer direction, it should not need to be |
| 940 | * configured, especially since the configuration used might |
| 941 | * not even be supported by that CODEC. There may be cases |
| 942 | * however where a CODEC needs to be set up although it is |
| 943 | * actually not being used for the transfer, e.g. if a |
| 944 | * capture-only CODEC is acting as an LRCLK and/or BCLK master |
| 945 | * for the DAI link including a playback-only CODEC. |
| 946 | * If this becomes necessary, we will have to augment the |
| 947 | * machine driver setup with information on how to act, so |
| 948 | * we can do the right thing here. |
| 949 | */ |
| 950 | if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) |
| 951 | continue; |
| 952 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 953 | /* copy params for each codec */ |
| 954 | codec_params = *params; |
| 955 | |
| 956 | /* fixup params based on TDM slot masks */ |
| 957 | if (codec_dai->tx_mask) |
| 958 | soc_pcm_codec_params_fixup(&codec_params, |
| 959 | codec_dai->tx_mask); |
| 960 | if (codec_dai->rx_mask) |
| 961 | soc_pcm_codec_params_fixup(&codec_params, |
| 962 | codec_dai->rx_mask); |
| 963 | |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 964 | ret = soc_dai_hw_params(substream, &codec_params, codec_dai); |
| 965 | if(ret < 0) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 966 | goto codec_err; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 967 | |
| 968 | codec_dai->rate = params_rate(&codec_params); |
| 969 | codec_dai->channels = params_channels(&codec_params); |
| 970 | codec_dai->sample_bits = snd_pcm_format_physical_width( |
| 971 | params_format(&codec_params)); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 972 | } |
| 973 | |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 974 | ret = soc_dai_hw_params(substream, params, cpu_dai); |
| 975 | if (ret < 0) |
| 976 | goto interface_err; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 977 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 978 | for_each_rtdcom(rtd, rtdcom) { |
| 979 | component = rtdcom->component; |
| 980 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 981 | if (!component->driver->ops || |
| 982 | !component->driver->ops->hw_params) |
| 983 | continue; |
| 984 | |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 985 | ret = component->driver->ops->hw_params(substream, params); |
| 986 | if (ret < 0) { |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 987 | dev_err(component->dev, |
| 988 | "ASoC: %s hw params failed: %d\n", |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 989 | component->name, ret); |
| 990 | goto component_err; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 991 | } |
| 992 | } |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 993 | component = NULL; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 994 | |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 995 | /* store the parameters for each DAIs */ |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 996 | cpu_dai->rate = params_rate(params); |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 997 | cpu_dai->channels = params_channels(params); |
| 998 | cpu_dai->sample_bits = |
| 999 | snd_pcm_format_physical_width(params_format(params)); |
| 1000 | |
jiada wang | 957ce0c | 2017-09-20 15:25:30 +0900 | [diff] [blame] | 1001 | ret = soc_pcm_params_symmetry(substream, params); |
| 1002 | if (ret) |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1003 | goto component_err; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1004 | out: |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1005 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1006 | return ret; |
| 1007 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1008 | component_err: |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 1009 | soc_pcm_components_hw_free(substream, component); |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1010 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1011 | if (cpu_dai->driver->ops->hw_free) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1012 | cpu_dai->driver->ops->hw_free(substream, cpu_dai); |
| 1013 | |
| 1014 | interface_err: |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1015 | i = rtd->num_codecs; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1016 | |
| 1017 | codec_err: |
Kuninori Morimoto | 6d11b12 | 2018-09-18 01:28:30 +0000 | [diff] [blame] | 1018 | for_each_rtd_codec_dai_rollback(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1019 | if (codec_dai->driver->ops->hw_free) |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1020 | codec_dai->driver->ops->hw_free(substream, codec_dai); |
| 1021 | codec_dai->rate = 0; |
| 1022 | } |
| 1023 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 1024 | if (rtd->dai_link->ops->hw_free) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1025 | rtd->dai_link->ops->hw_free(substream); |
| 1026 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1027 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1028 | return ret; |
| 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * Frees resources allocated by hw_params, can be called multiple times |
| 1033 | */ |
| 1034 | static int soc_pcm_hw_free(struct snd_pcm_substream *substream) |
| 1035 | { |
| 1036 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1037 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1038 | struct snd_soc_dai *codec_dai; |
Nicolin Chen | 7f62b6e | 2013-12-04 11:18:36 +0800 | [diff] [blame] | 1039 | bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1040 | int i; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1041 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1042 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1043 | |
Nicolin Chen | d338342 | 2013-11-20 18:37:09 +0800 | [diff] [blame] | 1044 | /* clear the corresponding DAIs parameters when going to be inactive */ |
| 1045 | if (cpu_dai->active == 1) { |
| 1046 | cpu_dai->rate = 0; |
| 1047 | cpu_dai->channels = 0; |
| 1048 | cpu_dai->sample_bits = 0; |
| 1049 | } |
| 1050 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1051 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1052 | if (codec_dai->active == 1) { |
| 1053 | codec_dai->rate = 0; |
| 1054 | codec_dai->channels = 0; |
| 1055 | codec_dai->sample_bits = 0; |
| 1056 | } |
Nicolin Chen | d338342 | 2013-11-20 18:37:09 +0800 | [diff] [blame] | 1057 | } |
| 1058 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1059 | /* apply codec digital mute */ |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1060 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 1061 | if ((playback && codec_dai->playback_active == 1) || |
| 1062 | (!playback && codec_dai->capture_active == 1)) |
| 1063 | snd_soc_dai_digital_mute(codec_dai, 1, |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1064 | substream->stream); |
| 1065 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1066 | |
| 1067 | /* free any machine hw params */ |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 1068 | if (rtd->dai_link->ops->hw_free) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1069 | rtd->dai_link->ops->hw_free(substream); |
| 1070 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1071 | /* free any component resources */ |
Charles Keepax | 244e293 | 2018-06-19 16:22:09 +0100 | [diff] [blame] | 1072 | soc_pcm_components_hw_free(substream, NULL); |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1073 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1074 | /* now free hw params for the DAIs */ |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1075 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1076 | if (codec_dai->driver->ops->hw_free) |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1077 | codec_dai->driver->ops->hw_free(substream, codec_dai); |
| 1078 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1079 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1080 | if (cpu_dai->driver->ops->hw_free) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1081 | cpu_dai->driver->ops->hw_free(substream, cpu_dai); |
| 1082 | |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1083 | mutex_unlock(&rtd->pcm_mutex); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 1088 | { |
| 1089 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1090 | struct snd_soc_component *component; |
| 1091 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1092 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1093 | struct snd_soc_dai *codec_dai; |
| 1094 | int i, ret; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1095 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1096 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1097 | if (codec_dai->driver->ops->trigger) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1098 | ret = codec_dai->driver->ops->trigger(substream, |
| 1099 | cmd, codec_dai); |
| 1100 | if (ret < 0) |
| 1101 | return ret; |
| 1102 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1105 | for_each_rtdcom(rtd, rtdcom) { |
| 1106 | component = rtdcom->component; |
| 1107 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1108 | if (!component->driver->ops || |
| 1109 | !component->driver->ops->trigger) |
| 1110 | continue; |
| 1111 | |
| 1112 | ret = component->driver->ops->trigger(substream, cmd); |
| 1113 | if (ret < 0) |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1117 | if (cpu_dai->driver->ops->trigger) { |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1118 | ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai); |
| 1119 | if (ret < 0) |
| 1120 | return ret; |
| 1121 | } |
Jarkko Nikula | 4792b0d | 2014-04-28 14:17:52 +0200 | [diff] [blame] | 1122 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 1123 | if (rtd->dai_link->ops->trigger) { |
Jarkko Nikula | 4792b0d | 2014-04-28 14:17:52 +0200 | [diff] [blame] | 1124 | ret = rtd->dai_link->ops->trigger(substream, cmd); |
| 1125 | if (ret < 0) |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
| 1131 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 1132 | static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, |
| 1133 | int cmd) |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 1134 | { |
| 1135 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 1136 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1137 | struct snd_soc_dai *codec_dai; |
| 1138 | int i, ret; |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 1139 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1140 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1141 | if (codec_dai->driver->ops->bespoke_trigger) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1142 | ret = codec_dai->driver->ops->bespoke_trigger(substream, |
| 1143 | cmd, codec_dai); |
| 1144 | if (ret < 0) |
| 1145 | return ret; |
| 1146 | } |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1149 | if (cpu_dai->driver->ops->bespoke_trigger) { |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 1150 | ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); |
| 1151 | if (ret < 0) |
| 1152 | return ret; |
| 1153 | } |
| 1154 | return 0; |
| 1155 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1156 | /* |
| 1157 | * soc level wrapper for pointer callback |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 1158 | * If cpu_dai, codec_dai, component driver has the delay callback, then |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1159 | * the runtime->delay will be updated accordingly. |
| 1160 | */ |
| 1161 | static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) |
| 1162 | { |
| 1163 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1164 | struct snd_soc_component *component; |
| 1165 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1166 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1167 | struct snd_soc_dai *codec_dai; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1168 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1169 | snd_pcm_uframes_t offset = 0; |
| 1170 | snd_pcm_sframes_t delay = 0; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1171 | snd_pcm_sframes_t codec_delay = 0; |
| 1172 | int i; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1173 | |
Akshu Agrawal | 9fb4c2bf | 2018-08-01 15:37:33 +0530 | [diff] [blame] | 1174 | /* clearing the previous total delay */ |
| 1175 | runtime->delay = 0; |
| 1176 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1177 | for_each_rtdcom(rtd, rtdcom) { |
| 1178 | component = rtdcom->component; |
| 1179 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1180 | if (!component->driver->ops || |
| 1181 | !component->driver->ops->pointer) |
| 1182 | continue; |
| 1183 | |
| 1184 | /* FIXME: use 1st pointer */ |
| 1185 | offset = component->driver->ops->pointer(substream); |
| 1186 | break; |
| 1187 | } |
Akshu Agrawal | 9fb4c2bf | 2018-08-01 15:37:33 +0530 | [diff] [blame] | 1188 | /* base delay if assigned in pointer callback */ |
| 1189 | delay = runtime->delay; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 1190 | |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1191 | if (cpu_dai->driver->ops->delay) |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1192 | delay += cpu_dai->driver->ops->delay(substream, cpu_dai); |
| 1193 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1194 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Kuninori Morimoto | 9900a42 | 2017-09-25 01:38:54 +0000 | [diff] [blame] | 1195 | if (codec_dai->driver->ops->delay) |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1196 | codec_delay = max(codec_delay, |
| 1197 | codec_dai->driver->ops->delay(substream, |
| 1198 | codec_dai)); |
| 1199 | } |
| 1200 | delay += codec_delay; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1201 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 1202 | runtime->delay = delay; |
| 1203 | |
| 1204 | return offset; |
| 1205 | } |
| 1206 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1207 | /* connect a FE and BE */ |
| 1208 | static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, |
| 1209 | struct snd_soc_pcm_runtime *be, int stream) |
| 1210 | { |
| 1211 | struct snd_soc_dpcm *dpcm; |
| 1212 | |
| 1213 | /* only add new dpcms */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1214 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1215 | if (dpcm->be == be && dpcm->fe == fe) |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL); |
| 1220 | if (!dpcm) |
| 1221 | return -ENOMEM; |
| 1222 | |
| 1223 | dpcm->be = be; |
| 1224 | dpcm->fe = fe; |
| 1225 | be->dpcm[stream].runtime = fe->dpcm[stream].runtime; |
| 1226 | dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW; |
| 1227 | list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients); |
| 1228 | list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients); |
| 1229 | |
Jarkko Nikula | 7cc302d | 2013-09-30 17:08:15 +0300 | [diff] [blame] | 1230 | dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1231 | stream ? "capture" : "playback", fe->dai_link->name, |
| 1232 | stream ? "<-" : "->", be->dai_link->name); |
| 1233 | |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1234 | #ifdef CONFIG_DEBUG_FS |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 1235 | if (fe->debugfs_dpcm_root) |
| 1236 | dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644, |
| 1237 | fe->debugfs_dpcm_root, &dpcm->state); |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1238 | #endif |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1239 | return 1; |
| 1240 | } |
| 1241 | |
| 1242 | /* reparent a BE onto another FE */ |
| 1243 | static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe, |
| 1244 | struct snd_soc_pcm_runtime *be, int stream) |
| 1245 | { |
| 1246 | struct snd_soc_dpcm *dpcm; |
| 1247 | struct snd_pcm_substream *fe_substream, *be_substream; |
| 1248 | |
| 1249 | /* reparent if BE is connected to other FEs */ |
| 1250 | if (!be->dpcm[stream].users) |
| 1251 | return; |
| 1252 | |
| 1253 | be_substream = snd_soc_dpcm_get_substream(be, stream); |
| 1254 | |
Kuninori Morimoto | d2e24d6 | 2018-09-18 01:30:54 +0000 | [diff] [blame] | 1255 | for_each_dpcm_fe(be, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1256 | if (dpcm->fe == fe) |
| 1257 | continue; |
| 1258 | |
Jarkko Nikula | 7cc302d | 2013-09-30 17:08:15 +0300 | [diff] [blame] | 1259 | dev_dbg(fe->dev, "reparent %s path %s %s %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1260 | stream ? "capture" : "playback", |
| 1261 | dpcm->fe->dai_link->name, |
| 1262 | stream ? "<-" : "->", dpcm->be->dai_link->name); |
| 1263 | |
| 1264 | fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream); |
| 1265 | be_substream->runtime = fe_substream->runtime; |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /* disconnect a BE and FE */ |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1271 | void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1272 | { |
| 1273 | struct snd_soc_dpcm *dpcm, *d; |
| 1274 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1275 | for_each_dpcm_be_safe(fe, stream, dpcm, d) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1276 | dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1277 | stream ? "capture" : "playback", |
| 1278 | dpcm->be->dai_link->name); |
| 1279 | |
| 1280 | if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE) |
| 1281 | continue; |
| 1282 | |
Jarkko Nikula | 7cc302d | 2013-09-30 17:08:15 +0300 | [diff] [blame] | 1283 | dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1284 | stream ? "capture" : "playback", fe->dai_link->name, |
| 1285 | stream ? "<-" : "->", dpcm->be->dai_link->name); |
| 1286 | |
| 1287 | /* BEs still alive need new FE */ |
| 1288 | dpcm_be_reparent(fe, dpcm->be, stream); |
| 1289 | |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 1290 | #ifdef CONFIG_DEBUG_FS |
| 1291 | debugfs_remove(dpcm->debugfs_state); |
| 1292 | #endif |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1293 | list_del(&dpcm->list_be); |
| 1294 | list_del(&dpcm->list_fe); |
| 1295 | kfree(dpcm); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | /* get BE for DAI widget and stream */ |
| 1300 | static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, |
| 1301 | struct snd_soc_dapm_widget *widget, int stream) |
| 1302 | { |
| 1303 | struct snd_soc_pcm_runtime *be; |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1304 | struct snd_soc_dai *dai; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1305 | int i; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1306 | |
Liam Girdwood | 3c14646 | 2018-03-14 20:43:51 +0000 | [diff] [blame] | 1307 | dev_dbg(card->dev, "ASoC: find BE for widget %s\n", widget->name); |
| 1308 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1309 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 1310 | for_each_card_rtds(card, be) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1311 | |
Liam Girdwood | 35ea065 | 2012-06-05 19:26:59 +0100 | [diff] [blame] | 1312 | if (!be->dai_link->no_pcm) |
| 1313 | continue; |
| 1314 | |
Liam Girdwood | 3c14646 | 2018-03-14 20:43:51 +0000 | [diff] [blame] | 1315 | dev_dbg(card->dev, "ASoC: try BE : %s\n", |
| 1316 | be->cpu_dai->playback_widget ? |
| 1317 | be->cpu_dai->playback_widget->name : "(not set)"); |
| 1318 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1319 | if (be->cpu_dai->playback_widget == widget) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1320 | return be; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1321 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1322 | for_each_rtd_codec_dai(be, i, dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1323 | if (dai->playback_widget == widget) |
| 1324 | return be; |
| 1325 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1326 | } |
| 1327 | } else { |
| 1328 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 1329 | for_each_card_rtds(card, be) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1330 | |
Liam Girdwood | 35ea065 | 2012-06-05 19:26:59 +0100 | [diff] [blame] | 1331 | if (!be->dai_link->no_pcm) |
| 1332 | continue; |
| 1333 | |
Liam Girdwood | 3c14646 | 2018-03-14 20:43:51 +0000 | [diff] [blame] | 1334 | dev_dbg(card->dev, "ASoC: try BE %s\n", |
| 1335 | be->cpu_dai->capture_widget ? |
| 1336 | be->cpu_dai->capture_widget->name : "(not set)"); |
| 1337 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1338 | if (be->cpu_dai->capture_widget == widget) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1339 | return be; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1340 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1341 | for_each_rtd_codec_dai(be, i, dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1342 | if (dai->capture_widget == widget) |
| 1343 | return be; |
| 1344 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
Liam Girdwood | 3c14646 | 2018-03-14 20:43:51 +0000 | [diff] [blame] | 1348 | /* dai link name and stream name set correctly ? */ |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1349 | dev_err(card->dev, "ASoC: can't get %s BE for %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1350 | stream ? "capture" : "playback", widget->name); |
| 1351 | return NULL; |
| 1352 | } |
| 1353 | |
| 1354 | static inline struct snd_soc_dapm_widget * |
Benoit Cousson | 3701861 | 2014-04-24 14:01:45 +0200 | [diff] [blame] | 1355 | dai_get_widget(struct snd_soc_dai *dai, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1356 | { |
| 1357 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
Benoit Cousson | 3701861 | 2014-04-24 14:01:45 +0200 | [diff] [blame] | 1358 | return dai->playback_widget; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1359 | else |
Benoit Cousson | 3701861 | 2014-04-24 14:01:45 +0200 | [diff] [blame] | 1360 | return dai->capture_widget; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static int widget_in_list(struct snd_soc_dapm_widget_list *list, |
| 1364 | struct snd_soc_dapm_widget *widget) |
| 1365 | { |
| 1366 | int i; |
| 1367 | |
| 1368 | for (i = 0; i < list->num_widgets; i++) { |
| 1369 | if (widget == list->widgets[i]) |
| 1370 | return 1; |
| 1371 | } |
| 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1376 | static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, |
| 1377 | enum snd_soc_dapm_direction dir) |
| 1378 | { |
| 1379 | struct snd_soc_card *card = widget->dapm->card; |
| 1380 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1381 | struct snd_soc_dai *dai; |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1382 | int i; |
| 1383 | |
| 1384 | if (dir == SND_SOC_DAPM_DIR_OUT) { |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 1385 | for_each_card_rtds(card, rtd) { |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1386 | if (!rtd->dai_link->no_pcm) |
| 1387 | continue; |
| 1388 | |
| 1389 | if (rtd->cpu_dai->playback_widget == widget) |
| 1390 | return true; |
| 1391 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1392 | for_each_rtd_codec_dai(rtd, i, dai) { |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1393 | if (dai->playback_widget == widget) |
| 1394 | return true; |
| 1395 | } |
| 1396 | } |
| 1397 | } else { /* SND_SOC_DAPM_DIR_IN */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 1398 | for_each_card_rtds(card, rtd) { |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1399 | if (!rtd->dai_link->no_pcm) |
| 1400 | continue; |
| 1401 | |
| 1402 | if (rtd->cpu_dai->capture_widget == widget) |
| 1403 | return true; |
| 1404 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1405 | for_each_rtd_codec_dai(rtd, i, dai) { |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1406 | if (dai->capture_widget == widget) |
| 1407 | return true; |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1415 | int dpcm_path_get(struct snd_soc_pcm_runtime *fe, |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1416 | int stream, struct snd_soc_dapm_widget_list **list) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1417 | { |
| 1418 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1419 | int paths; |
| 1420 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1421 | /* get number of valid DAI paths and their widgets */ |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1422 | paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list, |
Piotr Stankiewicz | 5fdd022 | 2016-05-13 17:03:56 +0100 | [diff] [blame] | 1423 | dpcm_end_walk_at_be); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1424 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1425 | dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths, |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1426 | stream ? "capture" : "playback"); |
| 1427 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1428 | return paths; |
| 1429 | } |
| 1430 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1431 | static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, |
| 1432 | struct snd_soc_dapm_widget_list **list_) |
| 1433 | { |
| 1434 | struct snd_soc_dpcm *dpcm; |
| 1435 | struct snd_soc_dapm_widget_list *list = *list_; |
| 1436 | struct snd_soc_dapm_widget *widget; |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1437 | struct snd_soc_dai *dai; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1438 | int prune = 0; |
| 1439 | |
| 1440 | /* Destroy any old FE <--> BE connections */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1441 | for_each_dpcm_be(fe, stream, dpcm) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1442 | unsigned int i; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1443 | |
| 1444 | /* is there a valid CPU DAI widget for this BE */ |
Benoit Cousson | 3701861 | 2014-04-24 14:01:45 +0200 | [diff] [blame] | 1445 | widget = dai_get_widget(dpcm->be->cpu_dai, stream); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1446 | |
| 1447 | /* prune the BE if it's no longer in our active list */ |
| 1448 | if (widget && widget_in_list(list, widget)) |
| 1449 | continue; |
| 1450 | |
| 1451 | /* is there a valid CODEC DAI widget for this BE */ |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1452 | for_each_rtd_codec_dai(dpcm->be, i, dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1453 | widget = dai_get_widget(dai, stream); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1454 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 1455 | /* prune the BE if it's no longer in our active list */ |
| 1456 | if (widget && widget_in_list(list, widget)) |
| 1457 | continue; |
| 1458 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1459 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1460 | dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1461 | stream ? "capture" : "playback", |
| 1462 | dpcm->be->dai_link->name, fe->dai_link->name); |
| 1463 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 1464 | dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; |
| 1465 | prune++; |
| 1466 | } |
| 1467 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1468 | dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1469 | return prune; |
| 1470 | } |
| 1471 | |
| 1472 | static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream, |
| 1473 | struct snd_soc_dapm_widget_list **list_) |
| 1474 | { |
| 1475 | struct snd_soc_card *card = fe->card; |
| 1476 | struct snd_soc_dapm_widget_list *list = *list_; |
| 1477 | struct snd_soc_pcm_runtime *be; |
| 1478 | int i, new = 0, err; |
| 1479 | |
| 1480 | /* Create any new FE <--> BE connections */ |
| 1481 | for (i = 0; i < list->num_widgets; i++) { |
| 1482 | |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 1483 | switch (list->widgets[i]->id) { |
| 1484 | case snd_soc_dapm_dai_in: |
Koro Chen | c5b8540 | 2015-07-06 10:02:10 +0800 | [diff] [blame] | 1485 | if (stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 1486 | continue; |
| 1487 | break; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 1488 | case snd_soc_dapm_dai_out: |
Koro Chen | c5b8540 | 2015-07-06 10:02:10 +0800 | [diff] [blame] | 1489 | if (stream != SNDRV_PCM_STREAM_CAPTURE) |
| 1490 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 1491 | break; |
| 1492 | default: |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1493 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 1494 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1495 | |
| 1496 | /* is there a valid BE rtd for this widget */ |
| 1497 | be = dpcm_get_be(card, list->widgets[i], stream); |
| 1498 | if (!be) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1499 | dev_err(fe->dev, "ASoC: no BE found for %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1500 | list->widgets[i]->name); |
| 1501 | continue; |
| 1502 | } |
| 1503 | |
| 1504 | /* make sure BE is a real BE */ |
| 1505 | if (!be->dai_link->no_pcm) |
| 1506 | continue; |
| 1507 | |
| 1508 | /* don't connect if FE is not running */ |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1509 | if (!fe->dpcm[stream].runtime && !fe->fe_compr) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1510 | continue; |
| 1511 | |
| 1512 | /* newly connected FE and BE */ |
| 1513 | err = dpcm_be_connect(fe, be, stream); |
| 1514 | if (err < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1515 | dev_err(fe->dev, "ASoC: can't connect %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1516 | list->widgets[i]->name); |
| 1517 | break; |
| 1518 | } else if (err == 0) /* already connected */ |
| 1519 | continue; |
| 1520 | |
| 1521 | /* new */ |
| 1522 | be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; |
| 1523 | new++; |
| 1524 | } |
| 1525 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1526 | dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1527 | return new; |
| 1528 | } |
| 1529 | |
| 1530 | /* |
| 1531 | * Find the corresponding BE DAIs that source or sink audio to this |
| 1532 | * FE substream. |
| 1533 | */ |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1534 | int dpcm_process_paths(struct snd_soc_pcm_runtime *fe, |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1535 | int stream, struct snd_soc_dapm_widget_list **list, int new) |
| 1536 | { |
| 1537 | if (new) |
| 1538 | return dpcm_add_paths(fe, stream, list); |
| 1539 | else |
| 1540 | return dpcm_prune_paths(fe, stream, list); |
| 1541 | } |
| 1542 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1543 | void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1544 | { |
| 1545 | struct snd_soc_dpcm *dpcm; |
| 1546 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1547 | for_each_dpcm_be(fe, stream, dpcm) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1548 | dpcm->be->dpcm[stream].runtime_update = |
| 1549 | SND_SOC_DPCM_UPDATE_NO; |
| 1550 | } |
| 1551 | |
| 1552 | static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe, |
| 1553 | int stream) |
| 1554 | { |
| 1555 | struct snd_soc_dpcm *dpcm; |
| 1556 | |
| 1557 | /* disable any enabled and non active backends */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1558 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1559 | |
| 1560 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1561 | struct snd_pcm_substream *be_substream = |
| 1562 | snd_soc_dpcm_get_substream(be, stream); |
| 1563 | |
| 1564 | if (be->dpcm[stream].users == 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1565 | dev_err(be->dev, "ASoC: no users %s at close - state %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1566 | stream ? "capture" : "playback", |
| 1567 | be->dpcm[stream].state); |
| 1568 | |
| 1569 | if (--be->dpcm[stream].users != 0) |
| 1570 | continue; |
| 1571 | |
| 1572 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) |
| 1573 | continue; |
| 1574 | |
| 1575 | soc_pcm_close(be_substream); |
| 1576 | be_substream->runtime = NULL; |
| 1577 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 1578 | } |
| 1579 | } |
| 1580 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1581 | int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1582 | { |
| 1583 | struct snd_soc_dpcm *dpcm; |
| 1584 | int err, count = 0; |
| 1585 | |
| 1586 | /* only startup BE DAIs that are either sinks or sources to this FE DAI */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1587 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1588 | |
| 1589 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1590 | struct snd_pcm_substream *be_substream = |
| 1591 | snd_soc_dpcm_get_substream(be, stream); |
| 1592 | |
Russell King - ARM Linux | 2062b4c | 2013-10-31 15:09:20 +0000 | [diff] [blame] | 1593 | if (!be_substream) { |
| 1594 | dev_err(be->dev, "ASoC: no backend %s stream\n", |
| 1595 | stream ? "capture" : "playback"); |
| 1596 | continue; |
| 1597 | } |
| 1598 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1599 | /* is this op for this BE ? */ |
| 1600 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 1601 | continue; |
| 1602 | |
| 1603 | /* first time the dpcm is open ? */ |
| 1604 | if (be->dpcm[stream].users == DPCM_MAX_BE_USERS) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1605 | dev_err(be->dev, "ASoC: too many users %s at open %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1606 | stream ? "capture" : "playback", |
| 1607 | be->dpcm[stream].state); |
| 1608 | |
| 1609 | if (be->dpcm[stream].users++ != 0) |
| 1610 | continue; |
| 1611 | |
| 1612 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) && |
| 1613 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE)) |
| 1614 | continue; |
| 1615 | |
Russell King - ARM Linux | 2062b4c | 2013-10-31 15:09:20 +0000 | [diff] [blame] | 1616 | dev_dbg(be->dev, "ASoC: open %s BE %s\n", |
| 1617 | stream ? "capture" : "playback", be->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1618 | |
| 1619 | be_substream->runtime = be->dpcm[stream].runtime; |
| 1620 | err = soc_pcm_open(be_substream); |
| 1621 | if (err < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1622 | dev_err(be->dev, "ASoC: BE open failed %d\n", err); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1623 | be->dpcm[stream].users--; |
| 1624 | if (be->dpcm[stream].users < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1625 | dev_err(be->dev, "ASoC: no users %s at unwind %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1626 | stream ? "capture" : "playback", |
| 1627 | be->dpcm[stream].state); |
| 1628 | |
| 1629 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 1630 | goto unwind; |
| 1631 | } |
| 1632 | |
| 1633 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 1634 | count++; |
| 1635 | } |
| 1636 | |
| 1637 | return count; |
| 1638 | |
| 1639 | unwind: |
| 1640 | /* disable any enabled and non active backends */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1641 | for_each_dpcm_be_rollback(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1642 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1643 | struct snd_pcm_substream *be_substream = |
| 1644 | snd_soc_dpcm_get_substream(be, stream); |
| 1645 | |
| 1646 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 1647 | continue; |
| 1648 | |
| 1649 | if (be->dpcm[stream].users == 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1650 | dev_err(be->dev, "ASoC: no users %s at close %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1651 | stream ? "capture" : "playback", |
| 1652 | be->dpcm[stream].state); |
| 1653 | |
| 1654 | if (--be->dpcm[stream].users != 0) |
| 1655 | continue; |
| 1656 | |
| 1657 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) |
| 1658 | continue; |
| 1659 | |
| 1660 | soc_pcm_close(be_substream); |
| 1661 | be_substream->runtime = NULL; |
| 1662 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 1663 | } |
| 1664 | |
| 1665 | return err; |
| 1666 | } |
| 1667 | |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1668 | static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime, |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1669 | struct snd_soc_pcm_stream *stream) |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1670 | { |
| 1671 | runtime->hw.rate_min = stream->rate_min; |
Charles Keepax | e33ffbd9c | 2018-08-27 14:26:47 +0100 | [diff] [blame] | 1672 | runtime->hw.rate_max = min_not_zero(stream->rate_max, UINT_MAX); |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1673 | runtime->hw.channels_min = stream->channels_min; |
| 1674 | runtime->hw.channels_max = stream->channels_max; |
Lars-Peter Clausen | 002220a | 2014-01-06 14:19:07 +0100 | [diff] [blame] | 1675 | if (runtime->hw.formats) |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1676 | runtime->hw.formats &= stream->formats; |
Lars-Peter Clausen | 002220a | 2014-01-06 14:19:07 +0100 | [diff] [blame] | 1677 | else |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1678 | runtime->hw.formats = stream->formats; |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1679 | runtime->hw.rates = stream->rates; |
| 1680 | } |
| 1681 | |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1682 | static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream, |
| 1683 | u64 *formats) |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1684 | { |
| 1685 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 1686 | struct snd_soc_dpcm *dpcm; |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1687 | struct snd_soc_dai *dai; |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1688 | int stream = substream->stream; |
| 1689 | |
| 1690 | if (!fe->dai_link->dpcm_merged_format) |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1691 | return; |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1692 | |
| 1693 | /* |
| 1694 | * It returns merged BE codec format |
| 1695 | * if FE want to use it (= dpcm_merged_format) |
| 1696 | */ |
| 1697 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1698 | for_each_dpcm_be(fe, stream, dpcm) { |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1699 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1700 | struct snd_soc_dai_driver *codec_dai_drv; |
| 1701 | struct snd_soc_pcm_stream *codec_stream; |
| 1702 | int i; |
| 1703 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1704 | for_each_rtd_codec_dai(be, i, dai) { |
Jerome Brunet | 4febced | 2018-06-27 17:36:38 +0200 | [diff] [blame] | 1705 | /* |
| 1706 | * Skip CODECs which don't support the current stream |
| 1707 | * type. See soc_pcm_init_runtime_hw() for more details |
| 1708 | */ |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1709 | if (!snd_soc_dai_stream_valid(dai, stream)) |
Jerome Brunet | 4febced | 2018-06-27 17:36:38 +0200 | [diff] [blame] | 1710 | continue; |
| 1711 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1712 | codec_dai_drv = dai->driver; |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1713 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1714 | codec_stream = &codec_dai_drv->playback; |
| 1715 | else |
| 1716 | codec_stream = &codec_dai_drv->capture; |
| 1717 | |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1718 | *formats &= codec_stream->formats; |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1719 | } |
| 1720 | } |
Kuninori Morimoto | b073ed4 | 2015-05-12 02:03:33 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1723 | static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream, |
| 1724 | unsigned int *channels_min, |
| 1725 | unsigned int *channels_max) |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1726 | { |
| 1727 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 1728 | struct snd_soc_dpcm *dpcm; |
| 1729 | int stream = substream->stream; |
| 1730 | |
| 1731 | if (!fe->dai_link->dpcm_merged_chan) |
| 1732 | return; |
| 1733 | |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1734 | /* |
| 1735 | * It returns merged BE codec channel; |
| 1736 | * if FE want to use it (= dpcm_merged_chan) |
| 1737 | */ |
| 1738 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1739 | for_each_dpcm_be(fe, stream, dpcm) { |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1740 | struct snd_soc_pcm_runtime *be = dpcm->be; |
Jerome Brunet | 4f2bd18 | 2018-06-27 11:48:18 +0200 | [diff] [blame] | 1741 | struct snd_soc_dai_driver *cpu_dai_drv = be->cpu_dai->driver; |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1742 | struct snd_soc_dai_driver *codec_dai_drv; |
| 1743 | struct snd_soc_pcm_stream *codec_stream; |
Jerome Brunet | 4f2bd18 | 2018-06-27 11:48:18 +0200 | [diff] [blame] | 1744 | struct snd_soc_pcm_stream *cpu_stream; |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1745 | |
Jerome Brunet | 4f2bd18 | 2018-06-27 11:48:18 +0200 | [diff] [blame] | 1746 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1747 | cpu_stream = &cpu_dai_drv->playback; |
| 1748 | else |
| 1749 | cpu_stream = &cpu_dai_drv->capture; |
| 1750 | |
| 1751 | *channels_min = max(*channels_min, cpu_stream->channels_min); |
| 1752 | *channels_max = min(*channels_max, cpu_stream->channels_max); |
| 1753 | |
| 1754 | /* |
| 1755 | * chan min/max cannot be enforced if there are multiple CODEC |
| 1756 | * DAIs connected to a single CPU DAI, use CPU DAI's directly |
| 1757 | */ |
| 1758 | if (be->num_codecs == 1) { |
| 1759 | codec_dai_drv = be->codec_dais[0]->driver; |
| 1760 | |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1761 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1762 | codec_stream = &codec_dai_drv->playback; |
| 1763 | else |
| 1764 | codec_stream = &codec_dai_drv->capture; |
| 1765 | |
| 1766 | *channels_min = max(*channels_min, |
| 1767 | codec_stream->channels_min); |
| 1768 | *channels_max = min(*channels_max, |
| 1769 | codec_stream->channels_max); |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1774 | static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream, |
| 1775 | unsigned int *rates, |
| 1776 | unsigned int *rate_min, |
| 1777 | unsigned int *rate_max) |
| 1778 | { |
| 1779 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 1780 | struct snd_soc_dpcm *dpcm; |
| 1781 | int stream = substream->stream; |
| 1782 | |
| 1783 | if (!fe->dai_link->dpcm_merged_rate) |
| 1784 | return; |
| 1785 | |
| 1786 | /* |
| 1787 | * It returns merged BE codec channel; |
| 1788 | * if FE want to use it (= dpcm_merged_chan) |
| 1789 | */ |
| 1790 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1791 | for_each_dpcm_be(fe, stream, dpcm) { |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1792 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1793 | struct snd_soc_dai_driver *cpu_dai_drv = be->cpu_dai->driver; |
| 1794 | struct snd_soc_dai_driver *codec_dai_drv; |
| 1795 | struct snd_soc_pcm_stream *codec_stream; |
| 1796 | struct snd_soc_pcm_stream *cpu_stream; |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1797 | struct snd_soc_dai *dai; |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1798 | int i; |
| 1799 | |
| 1800 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1801 | cpu_stream = &cpu_dai_drv->playback; |
| 1802 | else |
| 1803 | cpu_stream = &cpu_dai_drv->capture; |
| 1804 | |
| 1805 | *rate_min = max(*rate_min, cpu_stream->rate_min); |
| 1806 | *rate_max = min_not_zero(*rate_max, cpu_stream->rate_max); |
| 1807 | *rates = snd_pcm_rate_mask_intersect(*rates, cpu_stream->rates); |
| 1808 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1809 | for_each_rtd_codec_dai(be, i, dai) { |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1810 | /* |
| 1811 | * Skip CODECs which don't support the current stream |
| 1812 | * type. See soc_pcm_init_runtime_hw() for more details |
| 1813 | */ |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1814 | if (!snd_soc_dai_stream_valid(dai, stream)) |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1815 | continue; |
| 1816 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 1817 | codec_dai_drv = dai->driver; |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1818 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1819 | codec_stream = &codec_dai_drv->playback; |
| 1820 | else |
| 1821 | codec_stream = &codec_dai_drv->capture; |
| 1822 | |
| 1823 | *rate_min = max(*rate_min, codec_stream->rate_min); |
| 1824 | *rate_max = min_not_zero(*rate_max, |
| 1825 | codec_stream->rate_max); |
| 1826 | *rates = snd_pcm_rate_mask_intersect(*rates, |
| 1827 | codec_stream->rates); |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 1832 | static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1833 | { |
| 1834 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1835 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1836 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1837 | struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver; |
| 1838 | |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1839 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1840 | dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback); |
Lars-Peter Clausen | 08ae9b4 | 2014-01-06 14:19:06 +0100 | [diff] [blame] | 1841 | else |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1842 | dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture); |
Jiada Wang | f4c277b | 2018-06-20 18:25:20 +0900 | [diff] [blame] | 1843 | |
Jerome Brunet | 435ffb7 | 2018-07-05 12:13:48 +0200 | [diff] [blame] | 1844 | dpcm_runtime_merge_format(substream, &runtime->hw.formats); |
| 1845 | dpcm_runtime_merge_chan(substream, &runtime->hw.channels_min, |
| 1846 | &runtime->hw.channels_max); |
Jerome Brunet | baacd8d | 2018-07-05 12:13:49 +0200 | [diff] [blame] | 1847 | dpcm_runtime_merge_rate(substream, &runtime->hw.rates, |
| 1848 | &runtime->hw.rate_min, &runtime->hw.rate_max); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 1851 | static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd); |
| 1852 | |
| 1853 | /* Set FE's runtime_update state; the state is protected via PCM stream lock |
| 1854 | * for avoiding the race with trigger callback. |
| 1855 | * If the state is unset and a trigger is pending while the previous operation, |
| 1856 | * process the pending trigger action here. |
| 1857 | */ |
| 1858 | static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe, |
| 1859 | int stream, enum snd_soc_dpcm_update state) |
| 1860 | { |
| 1861 | struct snd_pcm_substream *substream = |
| 1862 | snd_soc_dpcm_get_substream(fe, stream); |
| 1863 | |
| 1864 | snd_pcm_stream_lock_irq(substream); |
| 1865 | if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) { |
| 1866 | dpcm_fe_dai_do_trigger(substream, |
| 1867 | fe->dpcm[stream].trigger_pending - 1); |
| 1868 | fe->dpcm[stream].trigger_pending = 0; |
| 1869 | } |
| 1870 | fe->dpcm[stream].runtime_update = state; |
| 1871 | snd_pcm_stream_unlock_irq(substream); |
| 1872 | } |
| 1873 | |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1874 | static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, |
| 1875 | int stream) |
| 1876 | { |
| 1877 | struct snd_soc_dpcm *dpcm; |
| 1878 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; |
| 1879 | struct snd_soc_dai *fe_cpu_dai = fe->cpu_dai; |
| 1880 | int err; |
| 1881 | |
| 1882 | /* apply symmetry for FE */ |
| 1883 | if (soc_pcm_has_symmetry(fe_substream)) |
| 1884 | fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1885 | |
| 1886 | /* Symmetry only applies if we've got an active stream. */ |
| 1887 | if (fe_cpu_dai->active) { |
| 1888 | err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai); |
| 1889 | if (err < 0) |
| 1890 | return err; |
| 1891 | } |
| 1892 | |
| 1893 | /* apply symmetry for BE */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1894 | for_each_dpcm_be(fe, stream, dpcm) { |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1895 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1896 | struct snd_pcm_substream *be_substream = |
| 1897 | snd_soc_dpcm_get_substream(be, stream); |
| 1898 | struct snd_soc_pcm_runtime *rtd = be_substream->private_data; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1899 | struct snd_soc_dai *codec_dai; |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1900 | int i; |
| 1901 | |
Jeeja KP | f117661 | 2016-09-06 14:17:55 +0530 | [diff] [blame] | 1902 | if (rtd->dai_link->be_hw_params_fixup) |
| 1903 | continue; |
| 1904 | |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1905 | if (soc_pcm_has_symmetry(be_substream)) |
| 1906 | be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1907 | |
| 1908 | /* Symmetry only applies if we've got an active stream. */ |
| 1909 | if (rtd->cpu_dai->active) { |
Kai Chieh Chuang | 99bcedb | 2018-05-28 10:18:19 +0800 | [diff] [blame] | 1910 | err = soc_pcm_apply_symmetry(fe_substream, |
| 1911 | rtd->cpu_dai); |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1912 | if (err < 0) |
| 1913 | return err; |
| 1914 | } |
| 1915 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1916 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 1917 | if (codec_dai->active) { |
Kai Chieh Chuang | 99bcedb | 2018-05-28 10:18:19 +0800 | [diff] [blame] | 1918 | err = soc_pcm_apply_symmetry(fe_substream, |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1919 | codec_dai); |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1920 | if (err < 0) |
| 1921 | return err; |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1929 | static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream) |
| 1930 | { |
| 1931 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; |
| 1932 | struct snd_pcm_runtime *runtime = fe_substream->runtime; |
| 1933 | int stream = fe_substream->stream, ret = 0; |
| 1934 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 1935 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1936 | |
| 1937 | ret = dpcm_be_dai_startup(fe, fe_substream->stream); |
| 1938 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1939 | dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1940 | goto be_err; |
| 1941 | } |
| 1942 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1943 | dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1944 | |
| 1945 | /* start the DAI frontend */ |
| 1946 | ret = soc_pcm_open(fe_substream); |
| 1947 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1948 | dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1949 | goto unwind; |
| 1950 | } |
| 1951 | |
| 1952 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 1953 | |
| 1954 | dpcm_set_fe_runtime(fe_substream); |
| 1955 | snd_pcm_limit_hw_rates(runtime); |
| 1956 | |
PC Liao | 906c7d6 | 2015-12-11 11:33:51 +0800 | [diff] [blame] | 1957 | ret = dpcm_apply_symmetry(fe_substream, stream); |
| 1958 | if (ret < 0) { |
| 1959 | dev_err(fe->dev, "ASoC: failed to apply dpcm symmetry %d\n", |
| 1960 | ret); |
| 1961 | goto unwind; |
| 1962 | } |
| 1963 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 1964 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1965 | return 0; |
| 1966 | |
| 1967 | unwind: |
| 1968 | dpcm_be_dai_startup_unwind(fe, fe_substream->stream); |
| 1969 | be_err: |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 1970 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1971 | return ret; |
| 1972 | } |
| 1973 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 1974 | int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1975 | { |
| 1976 | struct snd_soc_dpcm *dpcm; |
| 1977 | |
| 1978 | /* only shutdown BEs that are either sinks or sources to this FE DAI */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 1979 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1980 | |
| 1981 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 1982 | struct snd_pcm_substream *be_substream = |
| 1983 | snd_soc_dpcm_get_substream(be, stream); |
| 1984 | |
| 1985 | /* is this op for this BE ? */ |
| 1986 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 1987 | continue; |
| 1988 | |
| 1989 | if (be->dpcm[stream].users == 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 1990 | dev_err(be->dev, "ASoC: no users %s at close - state %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1991 | stream ? "capture" : "playback", |
| 1992 | be->dpcm[stream].state); |
| 1993 | |
| 1994 | if (--be->dpcm[stream].users != 0) |
| 1995 | continue; |
| 1996 | |
| 1997 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && |
Kai Chieh Chuang | 9c0ac70 | 2018-05-28 10:18:18 +0800 | [diff] [blame] | 1998 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)) { |
| 1999 | soc_pcm_hw_free(be_substream); |
| 2000 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; |
| 2001 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2002 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2003 | dev_dbg(be->dev, "ASoC: close BE %s\n", |
å½ä¸œæž— | 94d215c | 2016-09-26 08:29:31 +0000 | [diff] [blame] | 2004 | be->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2005 | |
| 2006 | soc_pcm_close(be_substream); |
| 2007 | be_substream->runtime = NULL; |
| 2008 | |
| 2009 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 2010 | } |
| 2011 | return 0; |
| 2012 | } |
| 2013 | |
| 2014 | static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream) |
| 2015 | { |
| 2016 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2017 | int stream = substream->stream; |
| 2018 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2019 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2020 | |
| 2021 | /* shutdown the BEs */ |
| 2022 | dpcm_be_dai_shutdown(fe, substream->stream); |
| 2023 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2024 | dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2025 | |
| 2026 | /* now shutdown the frontend */ |
| 2027 | soc_pcm_close(substream); |
| 2028 | |
| 2029 | /* run the stream event for each BE */ |
| 2030 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
| 2031 | |
| 2032 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2033 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2034 | return 0; |
| 2035 | } |
| 2036 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 2037 | int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2038 | { |
| 2039 | struct snd_soc_dpcm *dpcm; |
| 2040 | |
| 2041 | /* only hw_params backends that are either sinks or sources |
| 2042 | * to this frontend DAI */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2043 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2044 | |
| 2045 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2046 | struct snd_pcm_substream *be_substream = |
| 2047 | snd_soc_dpcm_get_substream(be, stream); |
| 2048 | |
| 2049 | /* is this op for this BE ? */ |
| 2050 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 2051 | continue; |
| 2052 | |
| 2053 | /* only free hw when no longer used - check all FEs */ |
| 2054 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) |
| 2055 | continue; |
| 2056 | |
Qiao Zhou | 36fba62 | 2014-12-03 10:13:43 +0800 | [diff] [blame] | 2057 | /* do not free hw if this BE is used by other FE */ |
| 2058 | if (be->dpcm[stream].users > 1) |
| 2059 | continue; |
| 2060 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2061 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && |
| 2062 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && |
| 2063 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && |
Patrick Lai | 08b2784 | 2012-12-19 19:36:02 -0800 | [diff] [blame] | 2064 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) && |
Vinod Koul | 5e82d2b | 2016-02-01 22:26:40 +0530 | [diff] [blame] | 2065 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && |
| 2066 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND)) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2067 | continue; |
| 2068 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2069 | dev_dbg(be->dev, "ASoC: hw_free BE %s\n", |
å½ä¸œæž— | 94d215c | 2016-09-26 08:29:31 +0000 | [diff] [blame] | 2070 | be->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2071 | |
| 2072 | soc_pcm_hw_free(be_substream); |
| 2073 | |
| 2074 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; |
| 2075 | } |
| 2076 | |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2080 | static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2081 | { |
| 2082 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2083 | int err, stream = substream->stream; |
| 2084 | |
| 2085 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2086 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2087 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2088 | dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2089 | |
| 2090 | /* call hw_free on the frontend */ |
| 2091 | err = soc_pcm_hw_free(substream); |
| 2092 | if (err < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2093 | dev_err(fe->dev,"ASoC: hw_free FE %s failed\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2094 | fe->dai_link->name); |
| 2095 | |
| 2096 | /* only hw_params backends that are either sinks or sources |
| 2097 | * to this frontend DAI */ |
| 2098 | err = dpcm_be_dai_hw_free(fe, stream); |
| 2099 | |
| 2100 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2101 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2102 | |
| 2103 | mutex_unlock(&fe->card->mutex); |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 2107 | int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2108 | { |
| 2109 | struct snd_soc_dpcm *dpcm; |
| 2110 | int ret; |
| 2111 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2112 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2113 | |
| 2114 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2115 | struct snd_pcm_substream *be_substream = |
| 2116 | snd_soc_dpcm_get_substream(be, stream); |
| 2117 | |
| 2118 | /* is this op for this BE ? */ |
| 2119 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 2120 | continue; |
| 2121 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2122 | /* copy params for each dpcm */ |
| 2123 | memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params, |
| 2124 | sizeof(struct snd_pcm_hw_params)); |
| 2125 | |
| 2126 | /* perform any hw_params fixups */ |
| 2127 | if (be->dai_link->be_hw_params_fixup) { |
| 2128 | ret = be->dai_link->be_hw_params_fixup(be, |
| 2129 | &dpcm->hw_params); |
| 2130 | if (ret < 0) { |
| 2131 | dev_err(be->dev, |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2132 | "ASoC: hw_params BE fixup failed %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2133 | ret); |
| 2134 | goto unwind; |
| 2135 | } |
| 2136 | } |
| 2137 | |
Kuninori Morimoto | b0639bd | 2016-01-21 01:47:12 +0000 | [diff] [blame] | 2138 | /* only allow hw_params() if no connected FEs are running */ |
| 2139 | if (!snd_soc_dpcm_can_be_params(fe, be, stream)) |
| 2140 | continue; |
| 2141 | |
| 2142 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) && |
| 2143 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && |
| 2144 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE)) |
| 2145 | continue; |
| 2146 | |
| 2147 | dev_dbg(be->dev, "ASoC: hw_params BE %s\n", |
å½ä¸œæž— | 94d215c | 2016-09-26 08:29:31 +0000 | [diff] [blame] | 2148 | be->dai_link->name); |
Kuninori Morimoto | b0639bd | 2016-01-21 01:47:12 +0000 | [diff] [blame] | 2149 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2150 | ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params); |
| 2151 | if (ret < 0) { |
| 2152 | dev_err(dpcm->be->dev, |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2153 | "ASoC: hw_params BE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2154 | goto unwind; |
| 2155 | } |
| 2156 | |
| 2157 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; |
| 2158 | } |
| 2159 | return 0; |
| 2160 | |
| 2161 | unwind: |
| 2162 | /* disable any enabled and non active backends */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2163 | for_each_dpcm_be_rollback(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2164 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2165 | struct snd_pcm_substream *be_substream = |
| 2166 | snd_soc_dpcm_get_substream(be, stream); |
| 2167 | |
| 2168 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 2169 | continue; |
| 2170 | |
| 2171 | /* only allow hw_free() if no connected FEs are running */ |
| 2172 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) |
| 2173 | continue; |
| 2174 | |
| 2175 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) && |
| 2176 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && |
| 2177 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && |
| 2178 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) |
| 2179 | continue; |
| 2180 | |
| 2181 | soc_pcm_hw_free(be_substream); |
| 2182 | } |
| 2183 | |
| 2184 | return ret; |
| 2185 | } |
| 2186 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2187 | static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream, |
| 2188 | struct snd_pcm_hw_params *params) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2189 | { |
| 2190 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2191 | int ret, stream = substream->stream; |
| 2192 | |
| 2193 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2194 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2195 | |
| 2196 | memcpy(&fe->dpcm[substream->stream].hw_params, params, |
| 2197 | sizeof(struct snd_pcm_hw_params)); |
| 2198 | ret = dpcm_be_dai_hw_params(fe, substream->stream); |
| 2199 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2200 | dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2201 | goto out; |
| 2202 | } |
| 2203 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2204 | dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2205 | fe->dai_link->name, params_rate(params), |
| 2206 | params_channels(params), params_format(params)); |
| 2207 | |
| 2208 | /* call hw_params on the frontend */ |
| 2209 | ret = soc_pcm_hw_params(substream, params); |
| 2210 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2211 | dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2212 | dpcm_be_dai_hw_free(fe, stream); |
| 2213 | } else |
| 2214 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; |
| 2215 | |
| 2216 | out: |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2217 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2218 | mutex_unlock(&fe->card->mutex); |
| 2219 | return ret; |
| 2220 | } |
| 2221 | |
| 2222 | static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm, |
| 2223 | struct snd_pcm_substream *substream, int cmd) |
| 2224 | { |
| 2225 | int ret; |
| 2226 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2227 | dev_dbg(dpcm->be->dev, "ASoC: trigger BE %s cmd %d\n", |
å½ä¸œæž— | 94d215c | 2016-09-26 08:29:31 +0000 | [diff] [blame] | 2228 | dpcm->be->dai_link->name, cmd); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2229 | |
| 2230 | ret = soc_pcm_trigger(substream, cmd); |
| 2231 | if (ret < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2232 | dev_err(dpcm->be->dev,"ASoC: trigger BE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2233 | |
| 2234 | return ret; |
| 2235 | } |
| 2236 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 2237 | int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2238 | int cmd) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2239 | { |
| 2240 | struct snd_soc_dpcm *dpcm; |
| 2241 | int ret = 0; |
| 2242 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2243 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2244 | |
| 2245 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2246 | struct snd_pcm_substream *be_substream = |
| 2247 | snd_soc_dpcm_get_substream(be, stream); |
| 2248 | |
| 2249 | /* is this op for this BE ? */ |
| 2250 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 2251 | continue; |
| 2252 | |
| 2253 | switch (cmd) { |
| 2254 | case SNDRV_PCM_TRIGGER_START: |
| 2255 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && |
| 2256 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) |
| 2257 | continue; |
| 2258 | |
| 2259 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2260 | if (ret) |
| 2261 | return ret; |
| 2262 | |
| 2263 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 2264 | break; |
| 2265 | case SNDRV_PCM_TRIGGER_RESUME: |
| 2266 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND)) |
| 2267 | continue; |
| 2268 | |
| 2269 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2270 | if (ret) |
| 2271 | return ret; |
| 2272 | |
| 2273 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 2274 | break; |
| 2275 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 2276 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) |
| 2277 | continue; |
| 2278 | |
| 2279 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2280 | if (ret) |
| 2281 | return ret; |
| 2282 | |
| 2283 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 2284 | break; |
| 2285 | case SNDRV_PCM_TRIGGER_STOP: |
| 2286 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) |
| 2287 | continue; |
| 2288 | |
| 2289 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) |
| 2290 | continue; |
| 2291 | |
| 2292 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2293 | if (ret) |
| 2294 | return ret; |
| 2295 | |
| 2296 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 2297 | break; |
| 2298 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Nicolin Chen | 868a6ca | 2014-05-12 20:12:05 +0800 | [diff] [blame] | 2299 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2300 | continue; |
| 2301 | |
| 2302 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) |
| 2303 | continue; |
| 2304 | |
| 2305 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2306 | if (ret) |
| 2307 | return ret; |
| 2308 | |
| 2309 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND; |
| 2310 | break; |
| 2311 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 2312 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) |
| 2313 | continue; |
| 2314 | |
| 2315 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) |
| 2316 | continue; |
| 2317 | |
| 2318 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); |
| 2319 | if (ret) |
| 2320 | return ret; |
| 2321 | |
| 2322 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 2323 | break; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | return ret; |
| 2328 | } |
| 2329 | EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger); |
| 2330 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2331 | static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2332 | { |
| 2333 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2334 | int stream = substream->stream, ret; |
| 2335 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; |
| 2336 | |
| 2337 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 2338 | |
| 2339 | switch (trigger) { |
| 2340 | case SND_SOC_DPCM_TRIGGER_PRE: |
| 2341 | /* call trigger on the frontend before the backend. */ |
| 2342 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2343 | dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2344 | fe->dai_link->name, cmd); |
| 2345 | |
| 2346 | ret = soc_pcm_trigger(substream, cmd); |
| 2347 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2348 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2349 | goto out; |
| 2350 | } |
| 2351 | |
| 2352 | ret = dpcm_be_dai_trigger(fe, substream->stream, cmd); |
| 2353 | break; |
| 2354 | case SND_SOC_DPCM_TRIGGER_POST: |
| 2355 | /* call trigger on the frontend after the backend. */ |
| 2356 | |
| 2357 | ret = dpcm_be_dai_trigger(fe, substream->stream, cmd); |
| 2358 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2359 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2360 | goto out; |
| 2361 | } |
| 2362 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2363 | dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2364 | fe->dai_link->name, cmd); |
| 2365 | |
| 2366 | ret = soc_pcm_trigger(substream, cmd); |
| 2367 | break; |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2368 | case SND_SOC_DPCM_TRIGGER_BESPOKE: |
| 2369 | /* bespoke trigger() - handles both FE and BEs */ |
| 2370 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2371 | dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n", |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2372 | fe->dai_link->name, cmd); |
| 2373 | |
| 2374 | ret = soc_pcm_bespoke_trigger(substream, cmd); |
| 2375 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2376 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2377 | goto out; |
| 2378 | } |
| 2379 | break; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2380 | default: |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2381 | dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd, |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2382 | fe->dai_link->name); |
| 2383 | ret = -EINVAL; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | |
| 2387 | switch (cmd) { |
| 2388 | case SNDRV_PCM_TRIGGER_START: |
| 2389 | case SNDRV_PCM_TRIGGER_RESUME: |
| 2390 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 2391 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 2392 | break; |
| 2393 | case SNDRV_PCM_TRIGGER_STOP: |
| 2394 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2395 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 2396 | break; |
Patrick Lai | 9f169b9 | 2016-12-31 22:44:39 -0800 | [diff] [blame] | 2397 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 2398 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 2399 | break; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | out: |
| 2403 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 2404 | return ret; |
| 2405 | } |
| 2406 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2407 | static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd) |
| 2408 | { |
| 2409 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2410 | int stream = substream->stream; |
| 2411 | |
| 2412 | /* if FE's runtime_update is already set, we're in race; |
| 2413 | * process this trigger later at exit |
| 2414 | */ |
| 2415 | if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) { |
| 2416 | fe->dpcm[stream].trigger_pending = cmd + 1; |
| 2417 | return 0; /* delayed, assuming it's successful */ |
| 2418 | } |
| 2419 | |
| 2420 | /* we're alone, let's trigger */ |
| 2421 | return dpcm_fe_dai_do_trigger(substream, cmd); |
| 2422 | } |
| 2423 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 2424 | int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2425 | { |
| 2426 | struct snd_soc_dpcm *dpcm; |
| 2427 | int ret = 0; |
| 2428 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2429 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2430 | |
| 2431 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2432 | struct snd_pcm_substream *be_substream = |
| 2433 | snd_soc_dpcm_get_substream(be, stream); |
| 2434 | |
| 2435 | /* is this op for this BE ? */ |
| 2436 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) |
| 2437 | continue; |
| 2438 | |
| 2439 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && |
Koro Chen | 95f444d | 2015-10-28 10:15:34 +0800 | [diff] [blame] | 2440 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && |
| 2441 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND)) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2442 | continue; |
| 2443 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2444 | dev_dbg(be->dev, "ASoC: prepare BE %s\n", |
å½ä¸œæž— | 94d215c | 2016-09-26 08:29:31 +0000 | [diff] [blame] | 2445 | be->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2446 | |
| 2447 | ret = soc_pcm_prepare(be_substream); |
| 2448 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2449 | dev_err(be->dev, "ASoC: backend prepare failed %d\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2450 | ret); |
| 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 2455 | } |
| 2456 | return ret; |
| 2457 | } |
| 2458 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2459 | static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2460 | { |
| 2461 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 2462 | int stream = substream->stream, ret = 0; |
| 2463 | |
| 2464 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 2465 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2466 | dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2467 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2468 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2469 | |
| 2470 | /* there is no point preparing this FE if there are no BEs */ |
| 2471 | if (list_empty(&fe->dpcm[stream].be_clients)) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2472 | dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2473 | fe->dai_link->name); |
| 2474 | ret = -EINVAL; |
| 2475 | goto out; |
| 2476 | } |
| 2477 | |
| 2478 | ret = dpcm_be_dai_prepare(fe, substream->stream); |
| 2479 | if (ret < 0) |
| 2480 | goto out; |
| 2481 | |
| 2482 | /* call prepare on the frontend */ |
| 2483 | ret = soc_pcm_prepare(substream); |
| 2484 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2485 | dev_err(fe->dev,"ASoC: prepare FE %s failed\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2486 | fe->dai_link->name); |
| 2487 | goto out; |
| 2488 | } |
| 2489 | |
| 2490 | /* run the stream event for each BE */ |
| 2491 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
| 2492 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 2493 | |
| 2494 | out: |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2495 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2496 | mutex_unlock(&fe->card->mutex); |
| 2497 | |
| 2498 | return ret; |
| 2499 | } |
| 2500 | |
Liam Girdwood | be3f3f2 | 2012-04-26 16:16:10 +0100 | [diff] [blame] | 2501 | static int soc_pcm_ioctl(struct snd_pcm_substream *substream, |
| 2502 | unsigned int cmd, void *arg) |
| 2503 | { |
| 2504 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 2505 | struct snd_soc_component *component; |
| 2506 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | be3f3f2 | 2012-04-26 16:16:10 +0100 | [diff] [blame] | 2507 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 2508 | for_each_rtdcom(rtd, rtdcom) { |
| 2509 | component = rtdcom->component; |
| 2510 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 2511 | if (!component->driver->ops || |
| 2512 | !component->driver->ops->ioctl) |
| 2513 | continue; |
| 2514 | |
| 2515 | /* FIXME: use 1st ioctl */ |
| 2516 | return component->driver->ops->ioctl(substream, cmd, arg); |
| 2517 | } |
| 2518 | |
Liam Girdwood | be3f3f2 | 2012-04-26 16:16:10 +0100 | [diff] [blame] | 2519 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 2520 | } |
| 2521 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2522 | static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream) |
| 2523 | { |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2524 | struct snd_pcm_substream *substream = |
| 2525 | snd_soc_dpcm_get_substream(fe, stream); |
| 2526 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2527 | int err; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2528 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2529 | dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n", |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2530 | stream ? "capture" : "playback", fe->dai_link->name); |
| 2531 | |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2532 | if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) { |
| 2533 | /* call bespoke trigger - FE takes care of all BE triggers */ |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2534 | dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n", |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2535 | fe->dai_link->name); |
| 2536 | |
| 2537 | err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP); |
| 2538 | if (err < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2539 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2540 | } else { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2541 | dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n", |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2542 | fe->dai_link->name); |
| 2543 | |
| 2544 | err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP); |
| 2545 | if (err < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2546 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2547 | } |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2548 | |
| 2549 | err = dpcm_be_dai_hw_free(fe, stream); |
| 2550 | if (err < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2551 | dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2552 | |
| 2553 | err = dpcm_be_dai_shutdown(fe, stream); |
| 2554 | if (err < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2555 | dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2556 | |
| 2557 | /* run the stream event for each BE */ |
| 2558 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP); |
| 2559 | |
| 2560 | return 0; |
| 2561 | } |
| 2562 | |
| 2563 | static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream) |
| 2564 | { |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2565 | struct snd_pcm_substream *substream = |
| 2566 | snd_soc_dpcm_get_substream(fe, stream); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2567 | struct snd_soc_dpcm *dpcm; |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2568 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2569 | int ret; |
| 2570 | |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2571 | dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n", |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2572 | stream ? "capture" : "playback", fe->dai_link->name); |
| 2573 | |
| 2574 | /* Only start the BE if the FE is ready */ |
| 2575 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE || |
| 2576 | fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) |
| 2577 | return -EINVAL; |
| 2578 | |
| 2579 | /* startup must always be called for new BEs */ |
| 2580 | ret = dpcm_be_dai_startup(fe, stream); |
Dan Carpenter | fffc0ca | 2013-01-10 11:59:57 +0300 | [diff] [blame] | 2581 | if (ret < 0) |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2582 | goto disconnect; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2583 | |
| 2584 | /* keep going if FE state is > open */ |
| 2585 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN) |
| 2586 | return 0; |
| 2587 | |
| 2588 | ret = dpcm_be_dai_hw_params(fe, stream); |
Dan Carpenter | fffc0ca | 2013-01-10 11:59:57 +0300 | [diff] [blame] | 2589 | if (ret < 0) |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2590 | goto close; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2591 | |
| 2592 | /* keep going if FE state is > hw_params */ |
| 2593 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS) |
| 2594 | return 0; |
| 2595 | |
| 2596 | |
| 2597 | ret = dpcm_be_dai_prepare(fe, stream); |
Dan Carpenter | fffc0ca | 2013-01-10 11:59:57 +0300 | [diff] [blame] | 2598 | if (ret < 0) |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2599 | goto hw_free; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2600 | |
| 2601 | /* run the stream event for each BE */ |
| 2602 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP); |
| 2603 | |
| 2604 | /* keep going if FE state is > prepare */ |
| 2605 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE || |
| 2606 | fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP) |
| 2607 | return 0; |
| 2608 | |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2609 | if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) { |
| 2610 | /* call trigger on the frontend - FE takes care of all BE triggers */ |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2611 | dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n", |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2612 | fe->dai_link->name); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2613 | |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2614 | ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START); |
| 2615 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2616 | dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2617 | goto hw_free; |
| 2618 | } |
| 2619 | } else { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2620 | dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n", |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2621 | fe->dai_link->name); |
| 2622 | |
| 2623 | ret = dpcm_be_dai_trigger(fe, stream, |
| 2624 | SNDRV_PCM_TRIGGER_START); |
| 2625 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2626 | dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 2627 | goto hw_free; |
| 2628 | } |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | return 0; |
| 2632 | |
| 2633 | hw_free: |
| 2634 | dpcm_be_dai_hw_free(fe, stream); |
| 2635 | close: |
| 2636 | dpcm_be_dai_shutdown(fe, stream); |
| 2637 | disconnect: |
| 2638 | /* disconnect any non started BEs */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2639 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2640 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 2641 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) |
| 2642 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 2643 | } |
| 2644 | |
| 2645 | return ret; |
| 2646 | } |
| 2647 | |
| 2648 | static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream) |
| 2649 | { |
| 2650 | int ret; |
| 2651 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2652 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2653 | ret = dpcm_run_update_startup(fe, stream); |
| 2654 | if (ret < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2655 | dev_err(fe->dev, "ASoC: failed to startup some BEs\n"); |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2656 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2657 | |
| 2658 | return ret; |
| 2659 | } |
| 2660 | |
| 2661 | static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream) |
| 2662 | { |
| 2663 | int ret; |
| 2664 | |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2665 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2666 | ret = dpcm_run_update_shutdown(fe, stream); |
| 2667 | if (ret < 0) |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2668 | dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n"); |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 2669 | dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2670 | |
| 2671 | return ret; |
| 2672 | } |
| 2673 | |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2674 | static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new) |
| 2675 | { |
| 2676 | struct snd_soc_dapm_widget_list *list; |
| 2677 | int count, paths; |
| 2678 | |
| 2679 | if (!fe->dai_link->dynamic) |
| 2680 | return 0; |
| 2681 | |
| 2682 | /* only check active links */ |
| 2683 | if (!fe->cpu_dai->active) |
| 2684 | return 0; |
| 2685 | |
| 2686 | /* DAPM sync will call this to update DSP paths */ |
| 2687 | dev_dbg(fe->dev, "ASoC: DPCM %s runtime update for FE %s\n", |
| 2688 | new ? "new" : "old", fe->dai_link->name); |
| 2689 | |
| 2690 | /* skip if FE doesn't have playback capability */ |
| 2691 | if (!fe->cpu_dai->driver->playback.channels_min || |
| 2692 | !fe->codec_dai->driver->playback.channels_min) |
| 2693 | goto capture; |
| 2694 | |
| 2695 | /* skip if FE isn't currently playing */ |
| 2696 | if (!fe->cpu_dai->playback_active || !fe->codec_dai->playback_active) |
| 2697 | goto capture; |
| 2698 | |
| 2699 | paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); |
| 2700 | if (paths < 0) { |
| 2701 | dev_warn(fe->dev, "ASoC: %s no valid %s path\n", |
| 2702 | fe->dai_link->name, "playback"); |
| 2703 | return paths; |
| 2704 | } |
| 2705 | |
| 2706 | /* update any playback paths */ |
| 2707 | count = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, new); |
| 2708 | if (count) { |
| 2709 | if (new) |
| 2710 | dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK); |
| 2711 | else |
| 2712 | dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK); |
| 2713 | |
| 2714 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); |
| 2715 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); |
| 2716 | } |
| 2717 | |
| 2718 | dpcm_path_put(&list); |
| 2719 | |
| 2720 | capture: |
| 2721 | /* skip if FE doesn't have capture capability */ |
| 2722 | if (!fe->cpu_dai->driver->capture.channels_min || |
| 2723 | !fe->codec_dai->driver->capture.channels_min) |
| 2724 | return 0; |
| 2725 | |
| 2726 | /* skip if FE isn't currently capturing */ |
| 2727 | if (!fe->cpu_dai->capture_active || !fe->codec_dai->capture_active) |
| 2728 | return 0; |
| 2729 | |
| 2730 | paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); |
| 2731 | if (paths < 0) { |
| 2732 | dev_warn(fe->dev, "ASoC: %s no valid %s path\n", |
| 2733 | fe->dai_link->name, "capture"); |
| 2734 | return paths; |
| 2735 | } |
| 2736 | |
| 2737 | /* update any old capture paths */ |
| 2738 | count = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, new); |
| 2739 | if (count) { |
| 2740 | if (new) |
| 2741 | dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE); |
| 2742 | else |
| 2743 | dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE); |
| 2744 | |
| 2745 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); |
| 2746 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); |
| 2747 | } |
| 2748 | |
| 2749 | dpcm_path_put(&list); |
| 2750 | |
| 2751 | return 0; |
| 2752 | } |
| 2753 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2754 | /* Called by DAPM mixer/mux changes to update audio routing between PCMs and |
| 2755 | * any DAI links. |
| 2756 | */ |
Lars-Peter Clausen | c3f48ae | 2013-07-24 15:27:36 +0200 | [diff] [blame] | 2757 | int soc_dpcm_runtime_update(struct snd_soc_card *card) |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2758 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 2759 | struct snd_soc_pcm_runtime *fe; |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2760 | int ret = 0; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2761 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2762 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2763 | /* shutdown all old paths first */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 2764 | for_each_card_rtds(card, fe) { |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2765 | ret = soc_dpcm_fe_runtime_update(fe, 0); |
| 2766 | if (ret) |
| 2767 | goto out; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2768 | } |
| 2769 | |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2770 | /* bring new paths up */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 2771 | for_each_card_rtds(card, fe) { |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2772 | ret = soc_dpcm_fe_runtime_update(fe, 1); |
| 2773 | if (ret) |
| 2774 | goto out; |
| 2775 | } |
| 2776 | |
| 2777 | out: |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2778 | mutex_unlock(&card->mutex); |
Jerome Brunet | de15d7ff | 2018-06-26 12:07:25 +0200 | [diff] [blame] | 2779 | return ret; |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2780 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2781 | int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute) |
| 2782 | { |
| 2783 | struct snd_soc_dpcm *dpcm; |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 2784 | struct snd_soc_dai *dai; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2785 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2786 | for_each_dpcm_be(fe, SNDRV_PCM_STREAM_PLAYBACK, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2787 | |
| 2788 | struct snd_soc_pcm_runtime *be = dpcm->be; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 2789 | int i; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2790 | |
| 2791 | if (be->dai_link->ignore_suspend) |
| 2792 | continue; |
| 2793 | |
Kuninori Morimoto | 7afecb3 | 2018-09-18 01:28:04 +0000 | [diff] [blame] | 2794 | for_each_rtd_codec_dai(be, i, dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 2795 | struct snd_soc_dai_driver *drv = dai->driver; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2796 | |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 2797 | dev_dbg(be->dev, "ASoC: BE digital mute %s\n", |
| 2798 | be->dai_link->name); |
| 2799 | |
| 2800 | if (drv->ops && drv->ops->digital_mute && |
| 2801 | dai->playback_active) |
| 2802 | drv->ops->digital_mute(dai, mute); |
| 2803 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | return 0; |
| 2807 | } |
| 2808 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2809 | static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2810 | { |
| 2811 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; |
| 2812 | struct snd_soc_dpcm *dpcm; |
| 2813 | struct snd_soc_dapm_widget_list *list; |
| 2814 | int ret; |
| 2815 | int stream = fe_substream->stream; |
| 2816 | |
| 2817 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 2818 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 2819 | |
Qiao Zhou | 8f70e51 | 2014-09-10 17:54:07 +0800 | [diff] [blame] | 2820 | ret = dpcm_path_get(fe, stream, &list); |
| 2821 | if (ret < 0) { |
| 2822 | mutex_unlock(&fe->card->mutex); |
| 2823 | return ret; |
| 2824 | } else if (ret == 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 2825 | dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2826 | fe->dai_link->name, stream ? "capture" : "playback"); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | /* calculate valid and active FE <-> BE dpcms */ |
| 2830 | dpcm_process_paths(fe, stream, &list, 1); |
| 2831 | |
| 2832 | ret = dpcm_fe_dai_startup(fe_substream); |
| 2833 | if (ret < 0) { |
| 2834 | /* clean up all links */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2835 | for_each_dpcm_be(fe, stream, dpcm) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2836 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 2837 | |
| 2838 | dpcm_be_disconnect(fe, stream); |
| 2839 | fe->dpcm[stream].runtime = NULL; |
| 2840 | } |
| 2841 | |
| 2842 | dpcm_clear_pending_state(fe, stream); |
| 2843 | dpcm_path_put(&list); |
| 2844 | mutex_unlock(&fe->card->mutex); |
| 2845 | return ret; |
| 2846 | } |
| 2847 | |
Mark Brown | 45c0a18 | 2012-05-09 21:46:27 +0100 | [diff] [blame] | 2848 | static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2849 | { |
| 2850 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; |
| 2851 | struct snd_soc_dpcm *dpcm; |
| 2852 | int stream = fe_substream->stream, ret; |
| 2853 | |
| 2854 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 2855 | ret = dpcm_fe_dai_shutdown(fe_substream); |
| 2856 | |
| 2857 | /* mark FE's links ready to prune */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 2858 | for_each_dpcm_be(fe, stream, dpcm) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 2859 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 2860 | |
| 2861 | dpcm_be_disconnect(fe, stream); |
| 2862 | |
| 2863 | fe->dpcm[stream].runtime = NULL; |
| 2864 | mutex_unlock(&fe->card->mutex); |
| 2865 | return ret; |
| 2866 | } |
| 2867 | |
Takashi Iwai | 5d61f0b | 2017-08-25 12:04:07 +0200 | [diff] [blame] | 2868 | static void soc_pcm_private_free(struct snd_pcm *pcm) |
| 2869 | { |
| 2870 | struct snd_soc_pcm_runtime *rtd = pcm->private_data; |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 2871 | struct snd_soc_rtdcom_list *rtdcom; |
| 2872 | struct snd_soc_component *component; |
Takashi Iwai | 5d61f0b | 2017-08-25 12:04:07 +0200 | [diff] [blame] | 2873 | |
Kuninori Morimoto | f30a4c3 | 2018-01-24 05:18:46 +0000 | [diff] [blame] | 2874 | /* need to sync the delayed work before releasing resources */ |
| 2875 | flush_delayed_work(&rtd->delayed_work); |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 2876 | for_each_rtdcom(rtd, rtdcom) { |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 2877 | component = rtdcom->component; |
| 2878 | |
Kuninori Morimoto | 11fb14f | 2018-05-08 03:19:49 +0000 | [diff] [blame] | 2879 | if (component->driver->pcm_free) |
| 2880 | component->driver->pcm_free(pcm); |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 2881 | } |
Takashi Iwai | 5d61f0b | 2017-08-25 12:04:07 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 2884 | static int soc_rtdcom_ack(struct snd_pcm_substream *substream) |
| 2885 | { |
| 2886 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2887 | struct snd_soc_rtdcom_list *rtdcom; |
| 2888 | struct snd_soc_component *component; |
| 2889 | |
| 2890 | for_each_rtdcom(rtd, rtdcom) { |
| 2891 | component = rtdcom->component; |
| 2892 | |
| 2893 | if (!component->driver->ops || |
| 2894 | !component->driver->ops->ack) |
| 2895 | continue; |
| 2896 | |
| 2897 | /* FIXME. it returns 1st ask now */ |
| 2898 | return component->driver->ops->ack(substream); |
| 2899 | } |
| 2900 | |
| 2901 | return -EINVAL; |
| 2902 | } |
| 2903 | |
| 2904 | static int soc_rtdcom_copy_user(struct snd_pcm_substream *substream, int channel, |
| 2905 | unsigned long pos, void __user *buf, |
| 2906 | unsigned long bytes) |
| 2907 | { |
| 2908 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2909 | struct snd_soc_rtdcom_list *rtdcom; |
| 2910 | struct snd_soc_component *component; |
| 2911 | |
| 2912 | for_each_rtdcom(rtd, rtdcom) { |
| 2913 | component = rtdcom->component; |
| 2914 | |
| 2915 | if (!component->driver->ops || |
| 2916 | !component->driver->ops->copy_user) |
| 2917 | continue; |
| 2918 | |
| 2919 | /* FIXME. it returns 1st copy now */ |
| 2920 | return component->driver->ops->copy_user(substream, channel, |
| 2921 | pos, buf, bytes); |
| 2922 | } |
| 2923 | |
| 2924 | return -EINVAL; |
| 2925 | } |
| 2926 | |
| 2927 | static int soc_rtdcom_copy_kernel(struct snd_pcm_substream *substream, int channel, |
| 2928 | unsigned long pos, void *buf, unsigned long bytes) |
| 2929 | { |
| 2930 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2931 | struct snd_soc_rtdcom_list *rtdcom; |
| 2932 | struct snd_soc_component *component; |
| 2933 | |
| 2934 | for_each_rtdcom(rtd, rtdcom) { |
| 2935 | component = rtdcom->component; |
| 2936 | |
| 2937 | if (!component->driver->ops || |
| 2938 | !component->driver->ops->copy_kernel) |
| 2939 | continue; |
| 2940 | |
| 2941 | /* FIXME. it returns 1st copy now */ |
| 2942 | return component->driver->ops->copy_kernel(substream, channel, |
| 2943 | pos, buf, bytes); |
| 2944 | } |
| 2945 | |
| 2946 | return -EINVAL; |
| 2947 | } |
| 2948 | |
| 2949 | static int soc_rtdcom_fill_silence(struct snd_pcm_substream *substream, int channel, |
| 2950 | unsigned long pos, unsigned long bytes) |
| 2951 | { |
| 2952 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2953 | struct snd_soc_rtdcom_list *rtdcom; |
| 2954 | struct snd_soc_component *component; |
| 2955 | |
| 2956 | for_each_rtdcom(rtd, rtdcom) { |
| 2957 | component = rtdcom->component; |
| 2958 | |
| 2959 | if (!component->driver->ops || |
| 2960 | !component->driver->ops->fill_silence) |
| 2961 | continue; |
| 2962 | |
| 2963 | /* FIXME. it returns 1st silence now */ |
| 2964 | return component->driver->ops->fill_silence(substream, channel, |
| 2965 | pos, bytes); |
| 2966 | } |
| 2967 | |
| 2968 | return -EINVAL; |
| 2969 | } |
| 2970 | |
| 2971 | static struct page *soc_rtdcom_page(struct snd_pcm_substream *substream, |
| 2972 | unsigned long offset) |
| 2973 | { |
| 2974 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2975 | struct snd_soc_rtdcom_list *rtdcom; |
| 2976 | struct snd_soc_component *component; |
| 2977 | struct page *page; |
| 2978 | |
| 2979 | for_each_rtdcom(rtd, rtdcom) { |
| 2980 | component = rtdcom->component; |
| 2981 | |
| 2982 | if (!component->driver->ops || |
| 2983 | !component->driver->ops->page) |
| 2984 | continue; |
| 2985 | |
| 2986 | /* FIXME. it returns 1st page now */ |
| 2987 | page = component->driver->ops->page(substream, offset); |
| 2988 | if (page) |
| 2989 | return page; |
| 2990 | } |
| 2991 | |
| 2992 | return NULL; |
| 2993 | } |
| 2994 | |
| 2995 | static int soc_rtdcom_mmap(struct snd_pcm_substream *substream, |
| 2996 | struct vm_area_struct *vma) |
| 2997 | { |
| 2998 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 2999 | struct snd_soc_rtdcom_list *rtdcom; |
| 3000 | struct snd_soc_component *component; |
| 3001 | |
| 3002 | for_each_rtdcom(rtd, rtdcom) { |
| 3003 | component = rtdcom->component; |
| 3004 | |
| 3005 | if (!component->driver->ops || |
| 3006 | !component->driver->ops->mmap) |
| 3007 | continue; |
| 3008 | |
| 3009 | /* FIXME. it returns 1st mmap now */ |
| 3010 | return component->driver->ops->mmap(substream, vma); |
| 3011 | } |
| 3012 | |
| 3013 | return -EINVAL; |
| 3014 | } |
| 3015 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3016 | /* create a new pcm */ |
| 3017 | int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) |
| 3018 | { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 3019 | struct snd_soc_dai *codec_dai; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3020 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 3021 | struct snd_soc_component *component; |
| 3022 | struct snd_soc_rtdcom_list *rtdcom; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3023 | struct snd_pcm *pcm; |
| 3024 | char new_name[64]; |
| 3025 | int ret = 0, playback = 0, capture = 0; |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 3026 | int i; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3027 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3028 | if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { |
Liam Girdwood | 1e9de42 | 2014-01-07 17:51:42 +0000 | [diff] [blame] | 3029 | playback = rtd->dai_link->dpcm_playback; |
| 3030 | capture = rtd->dai_link->dpcm_capture; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3031 | } else { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 3032 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 3033 | if (codec_dai->driver->playback.channels_min) |
| 3034 | playback = 1; |
| 3035 | if (codec_dai->driver->capture.channels_min) |
| 3036 | capture = 1; |
| 3037 | } |
| 3038 | |
| 3039 | capture = capture && cpu_dai->driver->capture.channels_min; |
| 3040 | playback = playback && cpu_dai->driver->playback.channels_min; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3041 | } |
Sangsu Park | a500231 | 2012-01-02 17:15:10 +0900 | [diff] [blame] | 3042 | |
Fabio Estevam | d6bead0 | 2013-08-29 10:32:13 -0300 | [diff] [blame] | 3043 | if (rtd->dai_link->playback_only) { |
| 3044 | playback = 1; |
| 3045 | capture = 0; |
| 3046 | } |
| 3047 | |
| 3048 | if (rtd->dai_link->capture_only) { |
| 3049 | playback = 0; |
| 3050 | capture = 1; |
| 3051 | } |
| 3052 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3053 | /* create the PCM */ |
| 3054 | if (rtd->dai_link->no_pcm) { |
| 3055 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 3056 | rtd->dai_link->stream_name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3057 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3058 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
| 3059 | playback, capture, &pcm); |
| 3060 | } else { |
| 3061 | if (rtd->dai_link->dynamic) |
| 3062 | snprintf(new_name, sizeof(new_name), "%s (*)", |
| 3063 | rtd->dai_link->stream_name); |
| 3064 | else |
| 3065 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 3066 | rtd->dai_link->stream_name, |
| 3067 | (rtd->num_codecs > 1) ? |
| 3068 | "multicodec" : rtd->codec_dai->name, num); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3069 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3070 | ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback, |
| 3071 | capture, &pcm); |
| 3072 | } |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3073 | if (ret < 0) { |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 3074 | dev_err(rtd->card->dev, "ASoC: can't create pcm for %s\n", |
Liam Girdwood | 5cb9b74 | 2012-07-06 16:54:52 +0100 | [diff] [blame] | 3075 | rtd->dai_link->name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3076 | return ret; |
| 3077 | } |
Liam Girdwood | 103d84a | 2012-11-19 14:39:15 +0000 | [diff] [blame] | 3078 | dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3079 | |
| 3080 | /* DAPM dai link stream work */ |
| 3081 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 3082 | |
Vinod Koul | 48c7699 | 2015-02-12 09:59:53 +0530 | [diff] [blame] | 3083 | pcm->nonatomic = rtd->dai_link->nonatomic; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3084 | rtd->pcm = pcm; |
| 3085 | pcm->private_data = rtd; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3086 | |
| 3087 | if (rtd->dai_link->no_pcm) { |
| 3088 | if (playback) |
| 3089 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 3090 | if (capture) |
| 3091 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
| 3092 | goto out; |
| 3093 | } |
| 3094 | |
| 3095 | /* ASoC PCM operations */ |
| 3096 | if (rtd->dai_link->dynamic) { |
| 3097 | rtd->ops.open = dpcm_fe_dai_open; |
| 3098 | rtd->ops.hw_params = dpcm_fe_dai_hw_params; |
| 3099 | rtd->ops.prepare = dpcm_fe_dai_prepare; |
| 3100 | rtd->ops.trigger = dpcm_fe_dai_trigger; |
| 3101 | rtd->ops.hw_free = dpcm_fe_dai_hw_free; |
| 3102 | rtd->ops.close = dpcm_fe_dai_close; |
| 3103 | rtd->ops.pointer = soc_pcm_pointer; |
Liam Girdwood | be3f3f2 | 2012-04-26 16:16:10 +0100 | [diff] [blame] | 3104 | rtd->ops.ioctl = soc_pcm_ioctl; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3105 | } else { |
| 3106 | rtd->ops.open = soc_pcm_open; |
| 3107 | rtd->ops.hw_params = soc_pcm_hw_params; |
| 3108 | rtd->ops.prepare = soc_pcm_prepare; |
| 3109 | rtd->ops.trigger = soc_pcm_trigger; |
| 3110 | rtd->ops.hw_free = soc_pcm_hw_free; |
| 3111 | rtd->ops.close = soc_pcm_close; |
| 3112 | rtd->ops.pointer = soc_pcm_pointer; |
Liam Girdwood | be3f3f2 | 2012-04-26 16:16:10 +0100 | [diff] [blame] | 3113 | rtd->ops.ioctl = soc_pcm_ioctl; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3114 | } |
| 3115 | |
Kuninori Morimoto | b813586 | 2017-10-11 01:37:23 +0000 | [diff] [blame] | 3116 | for_each_rtdcom(rtd, rtdcom) { |
| 3117 | const struct snd_pcm_ops *ops = rtdcom->component->driver->ops; |
| 3118 | |
| 3119 | if (!ops) |
| 3120 | continue; |
| 3121 | |
| 3122 | if (ops->ack) |
| 3123 | rtd->ops.ack = soc_rtdcom_ack; |
| 3124 | if (ops->copy_user) |
| 3125 | rtd->ops.copy_user = soc_rtdcom_copy_user; |
| 3126 | if (ops->copy_kernel) |
| 3127 | rtd->ops.copy_kernel = soc_rtdcom_copy_kernel; |
| 3128 | if (ops->fill_silence) |
| 3129 | rtd->ops.fill_silence = soc_rtdcom_fill_silence; |
| 3130 | if (ops->page) |
| 3131 | rtd->ops.page = soc_rtdcom_page; |
| 3132 | if (ops->mmap) |
| 3133 | rtd->ops.mmap = soc_rtdcom_mmap; |
| 3134 | } |
| 3135 | |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3136 | if (playback) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3137 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3138 | |
| 3139 | if (capture) |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3140 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3141 | |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 3142 | for_each_rtdcom(rtd, rtdcom) { |
| 3143 | component = rtdcom->component; |
| 3144 | |
Kuninori Morimoto | 11fb14f | 2018-05-08 03:19:49 +0000 | [diff] [blame] | 3145 | if (!component->driver->pcm_new) |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 3146 | continue; |
| 3147 | |
Kuninori Morimoto | 11fb14f | 2018-05-08 03:19:49 +0000 | [diff] [blame] | 3148 | ret = component->driver->pcm_new(rtd); |
Johan Hovold | c641e5b | 2017-07-12 17:55:29 +0200 | [diff] [blame] | 3149 | if (ret < 0) { |
Kuninori Morimoto | f523ace | 2017-09-26 01:00:53 +0000 | [diff] [blame] | 3150 | dev_err(component->dev, |
Johan Hovold | c641e5b | 2017-07-12 17:55:29 +0200 | [diff] [blame] | 3151 | "ASoC: pcm constructor failed: %d\n", |
| 3152 | ret); |
| 3153 | return ret; |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3154 | } |
| 3155 | } |
Johan Hovold | c641e5b | 2017-07-12 17:55:29 +0200 | [diff] [blame] | 3156 | |
Takashi Iwai | 5d61f0b | 2017-08-25 12:04:07 +0200 | [diff] [blame] | 3157 | pcm->private_free = soc_pcm_private_free; |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3158 | out: |
Benoit Cousson | 2e5894d | 2014-07-08 23:19:35 +0200 | [diff] [blame] | 3159 | dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", |
| 3160 | (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name, |
| 3161 | cpu_dai->name); |
Liam Girdwood | ddee627 | 2011-06-09 14:45:53 +0100 | [diff] [blame] | 3162 | return ret; |
| 3163 | } |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3164 | |
| 3165 | /* is the current PCM operation for this FE ? */ |
| 3166 | int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream) |
| 3167 | { |
| 3168 | if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) |
| 3169 | return 1; |
| 3170 | return 0; |
| 3171 | } |
| 3172 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update); |
| 3173 | |
| 3174 | /* is the current PCM operation for this BE ? */ |
| 3175 | int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe, |
| 3176 | struct snd_soc_pcm_runtime *be, int stream) |
| 3177 | { |
| 3178 | if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) || |
| 3179 | ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) && |
| 3180 | be->dpcm[stream].runtime_update)) |
| 3181 | return 1; |
| 3182 | return 0; |
| 3183 | } |
| 3184 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update); |
| 3185 | |
| 3186 | /* get the substream for this BE */ |
| 3187 | struct snd_pcm_substream * |
| 3188 | snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream) |
| 3189 | { |
| 3190 | return be->pcm->streams[stream].substream; |
| 3191 | } |
| 3192 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream); |
| 3193 | |
| 3194 | /* get the BE runtime state */ |
| 3195 | enum snd_soc_dpcm_state |
| 3196 | snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream) |
| 3197 | { |
| 3198 | return be->dpcm[stream].state; |
| 3199 | } |
| 3200 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state); |
| 3201 | |
| 3202 | /* set the BE runtime state */ |
| 3203 | void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, |
| 3204 | int stream, enum snd_soc_dpcm_state state) |
| 3205 | { |
| 3206 | be->dpcm[stream].state = state; |
| 3207 | } |
| 3208 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state); |
| 3209 | |
| 3210 | /* |
| 3211 | * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE |
| 3212 | * are not running, paused or suspended for the specified stream direction. |
| 3213 | */ |
| 3214 | int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, |
| 3215 | struct snd_soc_pcm_runtime *be, int stream) |
| 3216 | { |
| 3217 | struct snd_soc_dpcm *dpcm; |
| 3218 | int state; |
| 3219 | |
Kuninori Morimoto | d2e24d6 | 2018-09-18 01:30:54 +0000 | [diff] [blame] | 3220 | for_each_dpcm_fe(be, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3221 | |
| 3222 | if (dpcm->fe == fe) |
| 3223 | continue; |
| 3224 | |
| 3225 | state = dpcm->fe->dpcm[stream].state; |
| 3226 | if (state == SND_SOC_DPCM_STATE_START || |
| 3227 | state == SND_SOC_DPCM_STATE_PAUSED || |
| 3228 | state == SND_SOC_DPCM_STATE_SUSPEND) |
| 3229 | return 0; |
| 3230 | } |
| 3231 | |
| 3232 | /* it's safe to free/stop this BE DAI */ |
| 3233 | return 1; |
| 3234 | } |
| 3235 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop); |
| 3236 | |
| 3237 | /* |
| 3238 | * We can only change hw params a BE DAI if any of it's FE are not prepared, |
| 3239 | * running, paused or suspended for the specified stream direction. |
| 3240 | */ |
| 3241 | int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, |
| 3242 | struct snd_soc_pcm_runtime *be, int stream) |
| 3243 | { |
| 3244 | struct snd_soc_dpcm *dpcm; |
| 3245 | int state; |
| 3246 | |
Kuninori Morimoto | d2e24d6 | 2018-09-18 01:30:54 +0000 | [diff] [blame] | 3247 | for_each_dpcm_fe(be, stream, dpcm) { |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3248 | |
| 3249 | if (dpcm->fe == fe) |
| 3250 | continue; |
| 3251 | |
| 3252 | state = dpcm->fe->dpcm[stream].state; |
| 3253 | if (state == SND_SOC_DPCM_STATE_START || |
| 3254 | state == SND_SOC_DPCM_STATE_PAUSED || |
| 3255 | state == SND_SOC_DPCM_STATE_SUSPEND || |
| 3256 | state == SND_SOC_DPCM_STATE_PREPARE) |
| 3257 | return 0; |
| 3258 | } |
| 3259 | |
| 3260 | /* it's safe to change hw_params */ |
| 3261 | return 1; |
| 3262 | } |
| 3263 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params); |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3264 | |
| 3265 | #ifdef CONFIG_DEBUG_FS |
Lars-Peter Clausen | 85280141 | 2016-11-22 11:29:14 +0100 | [diff] [blame] | 3266 | static const char *dpcm_state_string(enum snd_soc_dpcm_state state) |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3267 | { |
| 3268 | switch (state) { |
| 3269 | case SND_SOC_DPCM_STATE_NEW: |
| 3270 | return "new"; |
| 3271 | case SND_SOC_DPCM_STATE_OPEN: |
| 3272 | return "open"; |
| 3273 | case SND_SOC_DPCM_STATE_HW_PARAMS: |
| 3274 | return "hw_params"; |
| 3275 | case SND_SOC_DPCM_STATE_PREPARE: |
| 3276 | return "prepare"; |
| 3277 | case SND_SOC_DPCM_STATE_START: |
| 3278 | return "start"; |
| 3279 | case SND_SOC_DPCM_STATE_STOP: |
| 3280 | return "stop"; |
| 3281 | case SND_SOC_DPCM_STATE_SUSPEND: |
| 3282 | return "suspend"; |
| 3283 | case SND_SOC_DPCM_STATE_PAUSED: |
| 3284 | return "paused"; |
| 3285 | case SND_SOC_DPCM_STATE_HW_FREE: |
| 3286 | return "hw_free"; |
| 3287 | case SND_SOC_DPCM_STATE_CLOSE: |
| 3288 | return "close"; |
| 3289 | } |
| 3290 | |
| 3291 | return "unknown"; |
| 3292 | } |
| 3293 | |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3294 | static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe, |
| 3295 | int stream, char *buf, size_t size) |
| 3296 | { |
| 3297 | struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params; |
| 3298 | struct snd_soc_dpcm *dpcm; |
| 3299 | ssize_t offset = 0; |
| 3300 | |
| 3301 | /* FE state */ |
| 3302 | offset += snprintf(buf + offset, size - offset, |
| 3303 | "[%s - %s]\n", fe->dai_link->name, |
| 3304 | stream ? "Capture" : "Playback"); |
| 3305 | |
| 3306 | offset += snprintf(buf + offset, size - offset, "State: %s\n", |
| 3307 | dpcm_state_string(fe->dpcm[stream].state)); |
| 3308 | |
| 3309 | if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) && |
| 3310 | (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP)) |
| 3311 | offset += snprintf(buf + offset, size - offset, |
| 3312 | "Hardware Params: " |
| 3313 | "Format = %s, Channels = %d, Rate = %d\n", |
| 3314 | snd_pcm_format_name(params_format(params)), |
| 3315 | params_channels(params), |
| 3316 | params_rate(params)); |
| 3317 | |
| 3318 | /* BEs state */ |
| 3319 | offset += snprintf(buf + offset, size - offset, "Backends:\n"); |
| 3320 | |
| 3321 | if (list_empty(&fe->dpcm[stream].be_clients)) { |
| 3322 | offset += snprintf(buf + offset, size - offset, |
| 3323 | " No active DSP links\n"); |
| 3324 | goto out; |
| 3325 | } |
| 3326 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 3327 | for_each_dpcm_be(fe, stream, dpcm) { |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3328 | struct snd_soc_pcm_runtime *be = dpcm->be; |
| 3329 | params = &dpcm->hw_params; |
| 3330 | |
| 3331 | offset += snprintf(buf + offset, size - offset, |
| 3332 | "- %s\n", be->dai_link->name); |
| 3333 | |
| 3334 | offset += snprintf(buf + offset, size - offset, |
| 3335 | " State: %s\n", |
| 3336 | dpcm_state_string(be->dpcm[stream].state)); |
| 3337 | |
| 3338 | if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) && |
| 3339 | (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP)) |
| 3340 | offset += snprintf(buf + offset, size - offset, |
| 3341 | " Hardware Params: " |
| 3342 | "Format = %s, Channels = %d, Rate = %d\n", |
| 3343 | snd_pcm_format_name(params_format(params)), |
| 3344 | params_channels(params), |
| 3345 | params_rate(params)); |
| 3346 | } |
| 3347 | |
| 3348 | out: |
| 3349 | return offset; |
| 3350 | } |
| 3351 | |
| 3352 | static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf, |
| 3353 | size_t count, loff_t *ppos) |
| 3354 | { |
| 3355 | struct snd_soc_pcm_runtime *fe = file->private_data; |
| 3356 | ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0; |
| 3357 | char *buf; |
| 3358 | |
| 3359 | buf = kmalloc(out_count, GFP_KERNEL); |
| 3360 | if (!buf) |
| 3361 | return -ENOMEM; |
| 3362 | |
| 3363 | if (fe->cpu_dai->driver->playback.channels_min) |
| 3364 | offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK, |
| 3365 | buf + offset, out_count - offset); |
| 3366 | |
| 3367 | if (fe->cpu_dai->driver->capture.channels_min) |
| 3368 | offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE, |
| 3369 | buf + offset, out_count - offset); |
| 3370 | |
Liam Girdwood | f57b848 | 2012-04-27 11:33:46 +0100 | [diff] [blame] | 3371 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset); |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3372 | |
Liam Girdwood | f57b848 | 2012-04-27 11:33:46 +0100 | [diff] [blame] | 3373 | kfree(buf); |
| 3374 | return ret; |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | static const struct file_operations dpcm_state_fops = { |
Liam Girdwood | f57b848 | 2012-04-27 11:33:46 +0100 | [diff] [blame] | 3378 | .open = simple_open, |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3379 | .read = dpcm_state_read_file, |
| 3380 | .llseek = default_llseek, |
| 3381 | }; |
| 3382 | |
Lars-Peter Clausen | 2e55b90 | 2015-04-09 10:52:37 +0200 | [diff] [blame] | 3383 | void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3384 | { |
Mark Brown | b3bba9a | 2012-05-08 10:33:47 +0100 | [diff] [blame] | 3385 | if (!rtd->dai_link) |
Lars-Peter Clausen | 2e55b90 | 2015-04-09 10:52:37 +0200 | [diff] [blame] | 3386 | return; |
Mark Brown | b3bba9a | 2012-05-08 10:33:47 +0100 | [diff] [blame] | 3387 | |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 3388 | if (!rtd->card->debugfs_card_root) |
| 3389 | return; |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3390 | |
| 3391 | rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name, |
| 3392 | rtd->card->debugfs_card_root); |
| 3393 | if (!rtd->debugfs_dpcm_root) { |
| 3394 | dev_dbg(rtd->dev, |
| 3395 | "ASoC: Failed to create dpcm debugfs directory %s\n", |
| 3396 | rtd->dai_link->name); |
Lars-Peter Clausen | 2e55b90 | 2015-04-09 10:52:37 +0200 | [diff] [blame] | 3397 | return; |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3398 | } |
| 3399 | |
Fabio Estevam | f1e3f40 | 2017-07-29 11:40:55 -0300 | [diff] [blame] | 3400 | debugfs_create_file("state", 0444, rtd->debugfs_dpcm_root, |
| 3401 | rtd, &dpcm_state_fops); |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 3402 | } |
| 3403 | #endif |