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