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