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