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