Kuninori Morimoto | b3ed4c8 | 2018-07-02 06:24:57 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // soc-compress.c -- ALSA SoC Compress |
| 4 | // |
| 5 | // Copyright (C) 2012 Intel Corp. |
| 6 | // |
| 7 | // Authors: Namarta Kohli <namartax.kohli@intel.com> |
| 8 | // Ramesh Babu K V <ramesh.babu@linux.intel.com> |
| 9 | // Vinod Koul <vinod.koul@linux.intel.com> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/workqueue.h> |
| 16 | #include <sound/core.h> |
| 17 | #include <sound/compress_params.h> |
| 18 | #include <sound/compress_driver.h> |
| 19 | #include <sound/soc.h> |
| 20 | #include <sound/initval.h> |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 21 | #include <sound/soc-dpcm.h> |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 22 | #include <linux/pm_runtime.h> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 23 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 24 | static int soc_compr_components_open(struct snd_compr_stream *cstream, |
| 25 | struct snd_soc_component **last) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 26 | { |
| 27 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 28 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 29 | int i, ret; |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 30 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 31 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 32 | if (!component->driver->compress_ops || |
| 33 | !component->driver->compress_ops->open) |
| 34 | continue; |
| 35 | |
| 36 | ret = component->driver->compress_ops->open(component, cstream); |
| 37 | if (ret < 0) { |
| 38 | dev_err(component->dev, |
| 39 | "Compress ASoC: can't open platform %s: %d\n", |
| 40 | component->name, ret); |
| 41 | |
| 42 | *last = component; |
| 43 | return ret; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /* remvoe me */ |
| 48 | for_each_rtd_components(rtd, i, component) { |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 49 | if (!component->driver->compr_ops || |
| 50 | !component->driver->compr_ops->open) |
| 51 | continue; |
| 52 | |
| 53 | ret = component->driver->compr_ops->open(cstream); |
| 54 | if (ret < 0) { |
| 55 | dev_err(component->dev, |
| 56 | "Compress ASoC: can't open platform %s: %d\n", |
| 57 | component->name, ret); |
| 58 | |
| 59 | *last = component; |
| 60 | return ret; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | *last = NULL; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int soc_compr_components_free(struct snd_compr_stream *cstream, |
| 69 | struct snd_soc_component *last) |
| 70 | { |
| 71 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 72 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 73 | int i; |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 74 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 75 | for_each_rtd_components(rtd, i, component) { |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 76 | if (component == last) |
| 77 | break; |
| 78 | |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 79 | if (!component->driver->compress_ops || |
| 80 | !component->driver->compress_ops->free) |
| 81 | continue; |
| 82 | |
| 83 | component->driver->compress_ops->free(component, cstream); |
| 84 | } |
| 85 | |
| 86 | /* remove me */ |
| 87 | for_each_rtd_components(rtd, i, component) { |
| 88 | if (component == last) |
| 89 | break; |
| 90 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 91 | if (!component->driver->compr_ops || |
| 92 | !component->driver->compr_ops->free) |
| 93 | continue; |
| 94 | |
| 95 | component->driver->compr_ops->free(cstream); |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static int soc_compr_open(struct snd_compr_stream *cstream) |
| 102 | { |
| 103 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 104 | struct snd_soc_component *component, *save = NULL; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 105 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 106 | int ret, i; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 107 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 108 | for_each_rtd_components(rtd, i, component) { |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 109 | ret = pm_runtime_get_sync(component->dev); |
| 110 | if (ret < 0 && ret != -EACCES) { |
| 111 | pm_runtime_put_noidle(component->dev); |
| 112 | save = component; |
| 113 | goto pm_err; |
| 114 | } |
| 115 | } |
| 116 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 117 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 118 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 119 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 120 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 121 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 122 | dev_err(cpu_dai->dev, |
| 123 | "Compress ASoC: can't open interface %s: %d\n", |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 124 | cpu_dai->name, ret); |
| 125 | goto out; |
| 126 | } |
| 127 | } |
| 128 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 129 | ret = soc_compr_components_open(cstream, &component); |
| 130 | if (ret < 0) |
| 131 | goto machine_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 132 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 133 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { |
| 134 | ret = rtd->dai_link->compr_ops->startup(cstream); |
| 135 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 136 | dev_err(rtd->dev, |
| 137 | "Compress ASoC: %s startup failed: %d\n", |
| 138 | rtd->dai_link->name, ret); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 139 | goto machine_err; |
| 140 | } |
| 141 | } |
| 142 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 143 | snd_soc_runtime_activate(rtd, cstream->direction); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 144 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 145 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 146 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 147 | return 0; |
| 148 | |
| 149 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 150 | soc_compr_components_free(cstream, component); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 151 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 152 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 153 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 154 | out: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 155 | mutex_unlock(&rtd->card->pcm_mutex); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 156 | pm_err: |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 157 | for_each_rtd_components(rtd, i, component) { |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 158 | if (component == save) |
| 159 | break; |
| 160 | pm_runtime_mark_last_busy(component->dev); |
| 161 | pm_runtime_put_autosuspend(component->dev); |
| 162 | } |
| 163 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 164 | return ret; |
| 165 | } |
| 166 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 167 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) |
| 168 | { |
| 169 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 170 | struct snd_pcm_substream *fe_substream = |
| 171 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 172 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 173 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 174 | struct snd_soc_dpcm *dpcm; |
| 175 | struct snd_soc_dapm_widget_list *list; |
| 176 | int stream; |
Charles Keepax | 572e6c8 | 2018-04-24 16:39:01 +0100 | [diff] [blame] | 177 | int ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 178 | |
| 179 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 180 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 181 | else |
| 182 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 183 | |
| 184 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 185 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 186 | |
| 187 | ret = dpcm_path_get(fe, stream, &list); |
| 188 | if (ret < 0) |
| 189 | goto be_err; |
| 190 | else if (ret == 0) |
| 191 | dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n", |
| 192 | fe->dai_link->name, stream ? "capture" : "playback"); |
| 193 | /* calculate valid and active FE <-> BE dpcms */ |
| 194 | dpcm_process_paths(fe, stream, &list, 1); |
| 195 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 196 | |
| 197 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 198 | |
| 199 | ret = dpcm_be_dai_startup(fe, stream); |
| 200 | if (ret < 0) { |
| 201 | /* clean up all links */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 202 | for_each_dpcm_be(fe, stream, dpcm) |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 203 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 204 | |
| 205 | dpcm_be_disconnect(fe, stream); |
| 206 | fe->dpcm[stream].runtime = NULL; |
| 207 | goto out; |
| 208 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 209 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 210 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 211 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 212 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 213 | dev_err(cpu_dai->dev, |
| 214 | "Compress ASoC: can't open interface %s: %d\n", |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 215 | cpu_dai->name, ret); |
| 216 | goto out; |
| 217 | } |
| 218 | } |
| 219 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 220 | ret = soc_compr_components_open(cstream, &component); |
| 221 | if (ret < 0) |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 222 | goto open_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 223 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 224 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { |
| 225 | ret = fe->dai_link->compr_ops->startup(cstream); |
| 226 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 227 | pr_err("Compress ASoC: %s startup failed: %d\n", |
| 228 | fe->dai_link->name, ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 229 | goto machine_err; |
| 230 | } |
| 231 | } |
| 232 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 233 | dpcm_clear_pending_state(fe, stream); |
| 234 | dpcm_path_put(&list); |
| 235 | |
| 236 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 237 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 238 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 239 | snd_soc_runtime_activate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 240 | |
| 241 | mutex_unlock(&fe->card->mutex); |
| 242 | |
| 243 | return 0; |
| 244 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 245 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 246 | soc_compr_components_free(cstream, component); |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 247 | open_err: |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 248 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 249 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 250 | out: |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 251 | dpcm_path_put(&list); |
| 252 | be_err: |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 253 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 254 | mutex_unlock(&fe->card->mutex); |
| 255 | return ret; |
| 256 | } |
| 257 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 258 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 259 | { |
| 260 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 261 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 262 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
| 263 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 264 | int stream, i; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 265 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 266 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 267 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 268 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 269 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 270 | else |
| 271 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 272 | |
| 273 | snd_soc_runtime_deactivate(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 274 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 275 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 276 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 277 | if (!cpu_dai->active) |
| 278 | cpu_dai->rate = 0; |
| 279 | |
| 280 | if (!codec_dai->active) |
| 281 | codec_dai->rate = 0; |
| 282 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 283 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) |
| 284 | rtd->dai_link->compr_ops->shutdown(cstream); |
| 285 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 286 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 287 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 288 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 289 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 290 | |
Kuninori Morimoto | 3f4cf79 | 2020-01-10 11:36:23 +0900 | [diff] [blame] | 291 | snd_soc_dapm_stream_stop(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 292 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 293 | mutex_unlock(&rtd->card->pcm_mutex); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 294 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 295 | for_each_rtd_components(rtd, i, component) { |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 296 | pm_runtime_mark_last_busy(component->dev); |
| 297 | pm_runtime_put_autosuspend(component->dev); |
| 298 | } |
| 299 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 303 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
| 304 | { |
| 305 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 306 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 307 | struct snd_soc_dpcm *dpcm; |
| 308 | int stream, ret; |
| 309 | |
| 310 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 311 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 312 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 313 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 314 | else |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 315 | stream = SNDRV_PCM_STREAM_CAPTURE; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 316 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 317 | snd_soc_runtime_deactivate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 318 | |
| 319 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 320 | |
| 321 | ret = dpcm_be_dai_hw_free(fe, stream); |
| 322 | if (ret < 0) |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 323 | dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 324 | |
| 325 | ret = dpcm_be_dai_shutdown(fe, stream); |
| 326 | |
| 327 | /* mark FE's links ready to prune */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 328 | for_each_dpcm_be(fe, stream, dpcm) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 329 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 330 | |
Kuninori Morimoto | 1c53123 | 2020-02-21 10:25:18 +0900 | [diff] [blame] | 331 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 332 | |
| 333 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 334 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 335 | |
| 336 | dpcm_be_disconnect(fe, stream); |
| 337 | |
| 338 | fe->dpcm[stream].runtime = NULL; |
| 339 | |
| 340 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 341 | fe->dai_link->compr_ops->shutdown(cstream); |
| 342 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 343 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 344 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 345 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 346 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 347 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 348 | mutex_unlock(&fe->card->mutex); |
| 349 | return 0; |
| 350 | } |
| 351 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 352 | static int soc_compr_components_trigger(struct snd_compr_stream *cstream, |
| 353 | int cmd) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 354 | { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 355 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 356 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 357 | int i, ret; |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 358 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 359 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 360 | if (!component->driver->compress_ops || |
| 361 | !component->driver->compress_ops->trigger) |
| 362 | continue; |
| 363 | |
| 364 | ret = component->driver->compress_ops->trigger( |
| 365 | component, cstream, cmd); |
| 366 | if (ret < 0) |
| 367 | return ret; |
| 368 | } |
| 369 | |
| 370 | /* remove me */ |
| 371 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 372 | if (!component->driver->compr_ops || |
| 373 | !component->driver->compr_ops->trigger) |
| 374 | continue; |
| 375 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 376 | ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 377 | if (ret < 0) |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 378 | return ret; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 379 | } |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 380 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 385 | { |
| 386 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 387 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 388 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 389 | int ret; |
| 390 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 391 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 392 | |
| 393 | ret = soc_compr_components_trigger(cstream, cmd); |
| 394 | if (ret < 0) |
| 395 | goto out; |
| 396 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 397 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) |
| 398 | cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 399 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 400 | switch (cmd) { |
| 401 | case SNDRV_PCM_TRIGGER_START: |
| 402 | snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); |
| 403 | break; |
| 404 | case SNDRV_PCM_TRIGGER_STOP: |
| 405 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 406 | break; |
Mark Brown | e38b9b7 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 407 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 408 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 409 | out: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 410 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 411 | return ret; |
| 412 | } |
| 413 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 414 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
| 415 | { |
| 416 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 417 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 418 | int ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 419 | |
| 420 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 421 | cmd == SND_COMPR_TRIGGER_DRAIN) |
| 422 | return soc_compr_components_trigger(cstream, cmd); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 423 | |
| 424 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 425 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 426 | else |
| 427 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 428 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 429 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 430 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 431 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) { |
| 432 | ret = cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 433 | if (ret < 0) |
| 434 | goto out; |
| 435 | } |
| 436 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 437 | ret = soc_compr_components_trigger(cstream, cmd); |
| 438 | if (ret < 0) |
| 439 | goto out; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 440 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 441 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 442 | |
| 443 | ret = dpcm_be_dai_trigger(fe, stream, cmd); |
| 444 | |
| 445 | switch (cmd) { |
| 446 | case SNDRV_PCM_TRIGGER_START: |
| 447 | case SNDRV_PCM_TRIGGER_RESUME: |
| 448 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 449 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 450 | break; |
| 451 | case SNDRV_PCM_TRIGGER_STOP: |
| 452 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 453 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 454 | break; |
| 455 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 456 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | out: |
| 461 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 462 | mutex_unlock(&fe->card->mutex); |
| 463 | return ret; |
| 464 | } |
| 465 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 466 | static int soc_compr_components_set_params(struct snd_compr_stream *cstream, |
| 467 | struct snd_compr_params *params) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 468 | { |
| 469 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 470 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 471 | int i, ret; |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 472 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 473 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 474 | if (!component->driver->compress_ops || |
| 475 | !component->driver->compress_ops->set_params) |
| 476 | continue; |
| 477 | |
| 478 | ret = component->driver->compress_ops->set_params( |
| 479 | component, cstream, params); |
| 480 | if (ret < 0) |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | /* remove me */ |
| 485 | for_each_rtd_components(rtd, i, component) { |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 486 | if (!component->driver->compr_ops || |
| 487 | !component->driver->compr_ops->set_params) |
| 488 | continue; |
| 489 | |
| 490 | ret = component->driver->compr_ops->set_params(cstream, params); |
| 491 | if (ret < 0) |
| 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 499 | struct snd_compr_params *params) |
| 500 | { |
| 501 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 502 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 503 | int ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 504 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 505 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 506 | |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 507 | /* |
| 508 | * First we call set_params for the CPU DAI, then the component |
| 509 | * driver this should configure the SoC side. If the machine has |
| 510 | * compressed ops then we call that as well. The expectation is |
| 511 | * that these callbacks will configure everything for this compress |
| 512 | * path, like configuring a PCM port for a CODEC. |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 513 | */ |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 514 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 515 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 516 | if (ret < 0) |
| 517 | goto err; |
| 518 | } |
| 519 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 520 | ret = soc_compr_components_set_params(cstream, params); |
| 521 | if (ret < 0) |
| 522 | goto err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 523 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 524 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { |
| 525 | ret = rtd->dai_link->compr_ops->set_params(cstream); |
| 526 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 527 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 528 | } |
| 529 | |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 530 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 531 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 532 | SND_SOC_DAPM_STREAM_START); |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 533 | else |
| 534 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 535 | SND_SOC_DAPM_STREAM_START); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 536 | |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 537 | /* cancel any delayed stream shutdown that is pending */ |
| 538 | rtd->pop_wait = 0; |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 539 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 540 | |
| 541 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 542 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 543 | return 0; |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 544 | |
| 545 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 546 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 547 | return ret; |
| 548 | } |
| 549 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 550 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 551 | struct snd_compr_params *params) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 552 | { |
| 553 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 554 | struct snd_pcm_substream *fe_substream = |
| 555 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 556 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 557 | int ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 558 | |
| 559 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 560 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 561 | else |
| 562 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 563 | |
| 564 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 565 | |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 566 | /* |
| 567 | * Create an empty hw_params for the BE as the machine driver must |
| 568 | * fix this up to match DSP decoder and ASRC configuration. |
| 569 | * I.e. machine driver fixup for compressed BE is mandatory. |
| 570 | */ |
| 571 | memset(&fe->dpcm[fe_substream->stream].hw_params, 0, |
| 572 | sizeof(struct snd_pcm_hw_params)); |
| 573 | |
| 574 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 575 | |
| 576 | ret = dpcm_be_dai_hw_params(fe, stream); |
| 577 | if (ret < 0) |
| 578 | goto out; |
| 579 | |
| 580 | ret = dpcm_be_dai_prepare(fe, stream); |
| 581 | if (ret < 0) |
| 582 | goto out; |
| 583 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 584 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 585 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 586 | if (ret < 0) |
| 587 | goto out; |
| 588 | } |
| 589 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 590 | ret = soc_compr_components_set_params(cstream, params); |
| 591 | if (ret < 0) |
| 592 | goto out; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 593 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 594 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { |
| 595 | ret = fe->dai_link->compr_ops->set_params(cstream); |
| 596 | if (ret < 0) |
| 597 | goto out; |
| 598 | } |
| 599 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 600 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 601 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 602 | |
| 603 | out: |
| 604 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 605 | mutex_unlock(&fe->card->mutex); |
| 606 | return ret; |
| 607 | } |
| 608 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 609 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 610 | struct snd_codec *params) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 611 | { |
| 612 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 613 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 614 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 615 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 616 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 617 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 618 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 619 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_params) { |
| 620 | ret = cpu_dai->driver->cops->get_params(cstream, params, cpu_dai); |
| 621 | if (ret < 0) |
| 622 | goto err; |
| 623 | } |
| 624 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 625 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 626 | if (!component->driver->compress_ops || |
| 627 | !component->driver->compress_ops->get_params) |
| 628 | continue; |
| 629 | |
| 630 | ret = component->driver->compress_ops->get_params( |
| 631 | component, cstream, params); |
| 632 | break; |
| 633 | } |
| 634 | |
| 635 | /* remove me */ |
| 636 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 637 | if (!component->driver->compr_ops || |
| 638 | !component->driver->compr_ops->get_params) |
| 639 | continue; |
| 640 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 641 | ret = component->driver->compr_ops->get_params(cstream, params); |
| 642 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 643 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 644 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 645 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 646 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 651 | struct snd_compr_caps *caps) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 652 | { |
| 653 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 654 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 655 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 656 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 657 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 658 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 659 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 660 | if (!component->driver->compress_ops || |
| 661 | !component->driver->compress_ops->get_caps) |
| 662 | continue; |
| 663 | |
| 664 | ret = component->driver->compress_ops->get_caps( |
| 665 | component, cstream, caps); |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | /* remove me */ |
| 670 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 671 | if (!component->driver->compr_ops || |
| 672 | !component->driver->compr_ops->get_caps) |
| 673 | continue; |
| 674 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 675 | ret = component->driver->compr_ops->get_caps(cstream, caps); |
| 676 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 679 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 680 | return ret; |
| 681 | } |
| 682 | |
| 683 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 684 | struct snd_compr_codec_caps *codec) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 685 | { |
| 686 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [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; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 689 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 690 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 691 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 692 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 693 | if (!component->driver->compress_ops || |
| 694 | !component->driver->compress_ops->get_codec_caps) |
| 695 | continue; |
| 696 | |
| 697 | ret = component->driver->compress_ops->get_codec_caps( |
| 698 | component, cstream, codec); |
| 699 | break; |
| 700 | } |
| 701 | |
| 702 | /* remove me */ |
| 703 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 704 | if (!component->driver->compr_ops || |
| 705 | !component->driver->compr_ops->get_codec_caps) |
| 706 | continue; |
| 707 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 708 | ret = component->driver->compr_ops->get_codec_caps(cstream, |
| 709 | codec); |
| 710 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 713 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 714 | return ret; |
| 715 | } |
| 716 | |
| 717 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 718 | { |
| 719 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 720 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 721 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 722 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 723 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 724 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 725 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 726 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->ack) { |
| 727 | ret = cpu_dai->driver->cops->ack(cstream, bytes, cpu_dai); |
| 728 | if (ret < 0) |
| 729 | goto err; |
| 730 | } |
| 731 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 732 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 733 | if (!component->driver->compress_ops || |
| 734 | !component->driver->compress_ops->ack) |
| 735 | continue; |
| 736 | |
| 737 | ret = component->driver->compress_ops->ack( |
| 738 | component, cstream, bytes); |
| 739 | if (ret < 0) |
| 740 | goto err; |
| 741 | } |
| 742 | |
| 743 | /* remove me */ |
| 744 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 745 | if (!component->driver->compr_ops || |
| 746 | !component->driver->compr_ops->ack) |
| 747 | continue; |
| 748 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 749 | ret = component->driver->compr_ops->ack(cstream, bytes); |
| 750 | if (ret < 0) |
| 751 | goto err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 752 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 753 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 754 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 755 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 756 | return ret; |
| 757 | } |
| 758 | |
| 759 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 760 | struct snd_compr_tstamp *tstamp) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 761 | { |
| 762 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 763 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 764 | int i, ret = 0; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 765 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 766 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 767 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 768 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 769 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer) |
| 770 | cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai); |
| 771 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 772 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 773 | if (!component->driver->compress_ops || |
| 774 | !component->driver->compress_ops->pointer) |
| 775 | continue; |
| 776 | |
| 777 | ret = component->driver->compress_ops->pointer( |
| 778 | component, cstream, tstamp); |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | /* remove me */ |
| 783 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 784 | if (!component->driver->compr_ops || |
| 785 | !component->driver->compr_ops->pointer) |
| 786 | continue; |
| 787 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 788 | ret = component->driver->compr_ops->pointer(cstream, tstamp); |
| 789 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 792 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 7c9190f | 2016-06-20 09:51:32 +0100 | [diff] [blame] | 793 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 794 | } |
| 795 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 796 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 4daf891 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 797 | char __user *buf, size_t count) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 798 | { |
| 799 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 800 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 801 | int i, ret = 0; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 802 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 803 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 804 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 805 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 806 | if (!component->driver->compress_ops || |
| 807 | !component->driver->compress_ops->copy) |
| 808 | continue; |
| 809 | |
| 810 | ret = component->driver->compress_ops->copy( |
| 811 | component, cstream, buf, count); |
| 812 | break; |
| 813 | } |
| 814 | |
| 815 | /* remove me */ |
| 816 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 817 | if (!component->driver->compr_ops || |
| 818 | !component->driver->compr_ops->copy) |
| 819 | continue; |
| 820 | |
Charles Keepax | 290df4d3 | 2018-01-26 13:08:43 +0000 | [diff] [blame] | 821 | ret = component->driver->compr_ops->copy(cstream, buf, count); |
| 822 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 823 | } |
Charles Keepax | 290df4d3 | 2018-01-26 13:08:43 +0000 | [diff] [blame] | 824 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 825 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 826 | return ret; |
| 827 | } |
| 828 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 829 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 830 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 831 | { |
| 832 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 833 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 834 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 835 | int i, ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 836 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 837 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) { |
| 838 | ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai); |
| 839 | if (ret < 0) |
| 840 | return ret; |
| 841 | } |
| 842 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 843 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 844 | if (!component->driver->compress_ops || |
| 845 | !component->driver->compress_ops->set_metadata) |
| 846 | continue; |
| 847 | |
| 848 | ret = component->driver->compress_ops->set_metadata( |
| 849 | component, cstream, metadata); |
| 850 | if (ret < 0) |
| 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | /* remove me */ |
| 855 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 856 | if (!component->driver->compr_ops || |
| 857 | !component->driver->compr_ops->set_metadata) |
| 858 | continue; |
| 859 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 860 | ret = component->driver->compr_ops->set_metadata(cstream, |
| 861 | metadata); |
| 862 | if (ret < 0) |
| 863 | return ret; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 864 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 865 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 866 | return 0; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 867 | } |
| 868 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 869 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 870 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 871 | { |
| 872 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 873 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 874 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 875 | int i, ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 876 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 877 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) { |
| 878 | ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai); |
| 879 | if (ret < 0) |
| 880 | return ret; |
| 881 | } |
| 882 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 883 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 884 | if (!component->driver->compress_ops || |
| 885 | !component->driver->compress_ops->get_metadata) |
| 886 | continue; |
| 887 | |
| 888 | return component->driver->compress_ops->get_metadata( |
| 889 | component, cstream, metadata); |
| 890 | } |
| 891 | |
| 892 | /* remove me */ |
| 893 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 894 | if (!component->driver->compr_ops || |
| 895 | !component->driver->compr_ops->get_metadata) |
| 896 | continue; |
| 897 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 898 | return component->driver->compr_ops->get_metadata(cstream, |
| 899 | metadata); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 900 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 901 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 902 | return 0; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 903 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 904 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 905 | /* ASoC Compress operations */ |
| 906 | static struct snd_compr_ops soc_compr_ops = { |
| 907 | .open = soc_compr_open, |
| 908 | .free = soc_compr_free, |
| 909 | .set_params = soc_compr_set_params, |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 910 | .set_metadata = soc_compr_set_metadata, |
| 911 | .get_metadata = soc_compr_get_metadata, |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 912 | .get_params = soc_compr_get_params, |
| 913 | .trigger = soc_compr_trigger, |
| 914 | .pointer = soc_compr_pointer, |
| 915 | .ack = soc_compr_ack, |
| 916 | .get_caps = soc_compr_get_caps, |
| 917 | .get_codec_caps = soc_compr_get_codec_caps |
| 918 | }; |
| 919 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 920 | /* ASoC Dynamic Compress operations */ |
| 921 | static struct snd_compr_ops soc_compr_dyn_ops = { |
| 922 | .open = soc_compr_open_fe, |
| 923 | .free = soc_compr_free_fe, |
| 924 | .set_params = soc_compr_set_params_fe, |
| 925 | .get_params = soc_compr_get_params, |
| 926 | .set_metadata = soc_compr_set_metadata, |
| 927 | .get_metadata = soc_compr_get_metadata, |
| 928 | .trigger = soc_compr_trigger_fe, |
| 929 | .pointer = soc_compr_pointer, |
| 930 | .ack = soc_compr_ack, |
| 931 | .get_caps = soc_compr_get_caps, |
| 932 | .get_codec_caps = soc_compr_get_codec_caps |
| 933 | }; |
| 934 | |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 935 | /** |
| 936 | * snd_soc_new_compress - create a new compress. |
| 937 | * |
| 938 | * @rtd: The runtime for which we will create compress |
| 939 | * @num: the device index number (zero based - shared with normal PCMs) |
| 940 | * |
| 941 | * Return: 0 for success, else error. |
| 942 | */ |
| 943 | int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 944 | { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 945 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 946 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 947 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 948 | struct snd_compr *compr; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 949 | struct snd_pcm *be_pcm; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 950 | char new_name[64]; |
| 951 | int ret = 0, direction = 0; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 952 | int playback = 0, capture = 0; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 953 | int i; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 954 | |
Bard Liao | 6e1276a | 2020-02-25 21:39:16 +0800 | [diff] [blame] | 955 | if (rtd->num_cpus > 1 || |
| 956 | rtd->num_codecs > 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 957 | dev_err(rtd->card->dev, |
Bard Liao | 6e1276a | 2020-02-25 21:39:16 +0800 | [diff] [blame] | 958 | "Compress ASoC: Multi CPU/Codec not supported\n"); |
Benoit Cousson | 8151d5e | 2014-07-08 23:19:37 +0200 | [diff] [blame] | 959 | return -EINVAL; |
| 960 | } |
| 961 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 962 | /* check client and interface hw capabilities */ |
Kuninori Morimoto | 467fece | 2019-07-22 10:36:16 +0900 | [diff] [blame] | 963 | if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && |
| 964 | snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK)) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 965 | playback = 1; |
Kuninori Morimoto | 467fece | 2019-07-22 10:36:16 +0900 | [diff] [blame] | 966 | if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && |
| 967 | snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 968 | capture = 1; |
| 969 | |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 970 | /* |
| 971 | * Compress devices are unidirectional so only one of the directions |
| 972 | * should be set, check for that (xor) |
| 973 | */ |
| 974 | if (playback + capture != 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 975 | dev_err(rtd->card->dev, |
| 976 | "Compress ASoC: Invalid direction for P %d, C %d\n", |
| 977 | playback, capture); |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 978 | return -EINVAL; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 979 | } |
| 980 | |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 981 | if (playback) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 982 | direction = SND_COMPRESS_PLAYBACK; |
| 983 | else |
| 984 | direction = SND_COMPRESS_CAPTURE; |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 985 | |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 986 | compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 987 | if (!compr) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 988 | return -ENOMEM; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 989 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 990 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 991 | GFP_KERNEL); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 992 | if (!compr->ops) |
| 993 | return -ENOMEM; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 994 | |
| 995 | if (rtd->dai_link->dynamic) { |
| 996 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 997 | rtd->dai_link->stream_name); |
| 998 | |
| 999 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 1000 | rtd->dai_link->dpcm_playback, |
| 1001 | rtd->dai_link->dpcm_capture, &be_pcm); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1002 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 1003 | dev_err(rtd->card->dev, |
| 1004 | "Compress ASoC: can't create compressed for %s: %d\n", |
| 1005 | rtd->dai_link->name, ret); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 1006 | return ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | rtd->pcm = be_pcm; |
| 1010 | rtd->fe_compr = 1; |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 1011 | if (rtd->dai_link->dpcm_playback) |
| 1012 | be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 1013 | else if (rtd->dai_link->dpcm_capture) |
| 1014 | be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1015 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 1016 | } else { |
| 1017 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 1018 | rtd->dai_link->stream_name, codec_dai->name, num); |
| 1019 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1020 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 1021 | } |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1022 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1023 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame^] | 1024 | if (!component->driver->compress_ops || |
| 1025 | !component->driver->compress_ops->copy) |
| 1026 | continue; |
| 1027 | |
| 1028 | compr->ops->copy = soc_compr_copy; |
| 1029 | break; |
| 1030 | } |
| 1031 | |
| 1032 | /* remove me */ |
| 1033 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 1034 | if (!component->driver->compr_ops || |
| 1035 | !component->driver->compr_ops->copy) |
| 1036 | continue; |
| 1037 | |
| 1038 | compr->ops->copy = soc_compr_copy; |
Charles Keepax | ca76db6 | 2018-04-26 17:30:04 +0100 | [diff] [blame] | 1039 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1042 | mutex_init(&compr->lock); |
Richard Fitzgerald | e5241a8 | 2015-11-25 13:00:24 +0000 | [diff] [blame] | 1043 | ret = snd_compress_new(rtd->card->snd_card, num, direction, |
| 1044 | new_name, compr); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1045 | if (ret < 0) { |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 1046 | component = asoc_rtd_to_codec(rtd, 0)->component; |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 1047 | dev_err(component->dev, |
| 1048 | "Compress ASoC: can't create compress for codec %s: %d\n", |
| 1049 | component->name, ret); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 1050 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1051 | } |
| 1052 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 1053 | /* DAPM dai link stream work */ |
Kuninori Morimoto | 83f94a2 | 2020-01-10 11:36:17 +0900 | [diff] [blame] | 1054 | rtd->close_delayed_work_func = snd_soc_close_delayed_work; |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 1055 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1056 | rtd->compr = compr; |
| 1057 | compr->private_data = rtd; |
| 1058 | |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 1059 | dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", |
| 1060 | codec_dai->name, cpu_dai->name); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1061 | |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 1062 | return 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1063 | } |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 1064 | EXPORT_SYMBOL_GPL(snd_soc_new_compress); |