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