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