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