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