Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1 | /* |
| 2 | * soc-compress.c -- ALSA SoC Compress |
| 3 | * |
| 4 | * Copyright (C) 2012 Intel Corp. |
| 5 | * |
| 6 | * Authors: Namarta Kohli <namartax.kohli@intel.com> |
| 7 | * Ramesh Babu K V <ramesh.babu@linux.intel.com> |
| 8 | * Vinod Koul <vinod.koul@linux.intel.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/workqueue.h> |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/compress_params.h> |
| 24 | #include <sound/compress_driver.h> |
| 25 | #include <sound/soc.h> |
| 26 | #include <sound/initval.h> |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 27 | #include <sound/soc-dpcm.h> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 28 | |
| 29 | static int soc_compr_open(struct snd_compr_stream *cstream) |
| 30 | { |
| 31 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 32 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 33 | struct snd_soc_component *component; |
| 34 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 35 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 36 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 37 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 38 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 39 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 40 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 41 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 42 | if (ret < 0) { |
| 43 | dev_err(cpu_dai->dev, "Compress ASoC: can't open interface %s: %d\n", |
| 44 | cpu_dai->name, ret); |
| 45 | goto out; |
| 46 | } |
| 47 | } |
| 48 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 49 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 50 | ret = platform->driver->compr_ops->open(cstream); |
| 51 | if (ret < 0) { |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 52 | pr_err("compress asoc: can't open platform %s\n", |
| 53 | platform->component.name); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 54 | goto plat_err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 58 | for_each_rtdcom(rtd, rtdcom) { |
| 59 | component = rtdcom->component; |
| 60 | |
| 61 | /* ignore duplication for now */ |
| 62 | if (platform && (component == &platform->component)) |
| 63 | continue; |
| 64 | |
| 65 | if (!component->driver->compr_ops || |
| 66 | !component->driver->compr_ops->open) |
| 67 | continue; |
| 68 | |
| 69 | __ret = component->driver->compr_ops->open(cstream); |
| 70 | if (__ret < 0) { |
| 71 | pr_err("compress asoc: can't open platform %s\n", |
| 72 | component->name); |
| 73 | ret = __ret; |
| 74 | } |
| 75 | } |
| 76 | if (ret < 0) |
| 77 | goto machine_err; |
| 78 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 79 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { |
| 80 | ret = rtd->dai_link->compr_ops->startup(cstream); |
| 81 | if (ret < 0) { |
| 82 | pr_err("compress asoc: %s startup failed\n", rtd->dai_link->name); |
| 83 | goto machine_err; |
| 84 | } |
| 85 | } |
| 86 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 87 | snd_soc_runtime_activate(rtd, cstream->direction); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 88 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 89 | mutex_unlock(&rtd->pcm_mutex); |
| 90 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 91 | return 0; |
| 92 | |
| 93 | machine_err: |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 94 | for_each_rtdcom(rtd, rtdcom) { |
| 95 | component = rtdcom->component; |
| 96 | |
| 97 | /* ignore duplication for now */ |
| 98 | if (platform && (component == &platform->component)) |
| 99 | continue; |
| 100 | |
| 101 | if (!component->driver->compr_ops || |
| 102 | !component->driver->compr_ops->free) |
| 103 | continue; |
| 104 | |
| 105 | component->driver->compr_ops->free(cstream); |
| 106 | } |
| 107 | |
| 108 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 109 | platform->driver->compr_ops->free(cstream); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 110 | plat_err: |
| 111 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 112 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 113 | out: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 114 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 115 | return ret; |
| 116 | } |
| 117 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 118 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) |
| 119 | { |
| 120 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 121 | struct snd_pcm_substream *fe_substream = |
| 122 | fe->pcm->streams[cstream->direction].substream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 123 | struct snd_soc_platform *platform = fe->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 124 | struct snd_soc_component *component; |
| 125 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 126 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 127 | struct snd_soc_dpcm *dpcm; |
| 128 | struct snd_soc_dapm_widget_list *list; |
| 129 | int stream; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 130 | int ret = 0, __ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 131 | |
| 132 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 133 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 134 | else |
| 135 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 136 | |
| 137 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 138 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 139 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 140 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 141 | if (ret < 0) { |
| 142 | dev_err(cpu_dai->dev, "Compress ASoC: can't open interface %s: %d\n", |
| 143 | cpu_dai->name, ret); |
| 144 | goto out; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 149 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) { |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 150 | ret = platform->driver->compr_ops->open(cstream); |
| 151 | if (ret < 0) { |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 152 | pr_err("compress asoc: can't open platform %s\n", |
| 153 | platform->component.name); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 154 | goto plat_err; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 158 | for_each_rtdcom(fe, rtdcom) { |
| 159 | component = rtdcom->component; |
| 160 | |
| 161 | /* ignore duplication for now */ |
| 162 | if (platform && (component == &platform->component)) |
| 163 | continue; |
| 164 | |
| 165 | if (!component->driver->compr_ops || |
| 166 | !component->driver->compr_ops->open) |
| 167 | continue; |
| 168 | |
| 169 | __ret = component->driver->compr_ops->open(cstream); |
| 170 | if (__ret < 0) { |
| 171 | pr_err("compress asoc: can't open platform %s\n", |
| 172 | component->name); |
| 173 | ret = __ret; |
| 174 | } |
| 175 | } |
| 176 | if (ret < 0) |
| 177 | goto machine_err; |
| 178 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 179 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { |
| 180 | ret = fe->dai_link->compr_ops->startup(cstream); |
| 181 | if (ret < 0) { |
| 182 | pr_err("compress asoc: %s startup failed\n", fe->dai_link->name); |
| 183 | goto machine_err; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 188 | |
Qiao Zhou | 8f70e51 | 2014-09-10 17:54:07 +0800 | [diff] [blame] | 189 | ret = dpcm_path_get(fe, stream, &list); |
Qiao Zhou | 2e4ec1c | 2014-09-12 09:41:31 +0800 | [diff] [blame] | 190 | if (ret < 0) |
Qiao Zhou | 8f70e51 | 2014-09-10 17:54:07 +0800 | [diff] [blame] | 191 | goto fe_err; |
Qiao Zhou | 2e4ec1c | 2014-09-12 09:41:31 +0800 | [diff] [blame] | 192 | else if (ret == 0) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 193 | dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", |
| 194 | fe->dai_link->name, stream ? "capture" : "playback"); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 195 | |
| 196 | /* calculate valid and active FE <-> BE dpcms */ |
| 197 | dpcm_process_paths(fe, stream, &list, 1); |
| 198 | |
| 199 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 200 | |
| 201 | ret = dpcm_be_dai_startup(fe, stream); |
| 202 | if (ret < 0) { |
| 203 | /* clean up all links */ |
| 204 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 205 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 206 | |
| 207 | dpcm_be_disconnect(fe, stream); |
| 208 | fe->dpcm[stream].runtime = NULL; |
Charles Keepax | b0f12c6 | 2016-08-16 11:24:46 +0100 | [diff] [blame] | 209 | goto path_err; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | dpcm_clear_pending_state(fe, stream); |
| 213 | dpcm_path_put(&list); |
| 214 | |
| 215 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 216 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 217 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 218 | snd_soc_runtime_activate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 219 | |
| 220 | mutex_unlock(&fe->card->mutex); |
| 221 | |
| 222 | return 0; |
| 223 | |
Charles Keepax | b0f12c6 | 2016-08-16 11:24:46 +0100 | [diff] [blame] | 224 | path_err: |
| 225 | dpcm_path_put(&list); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 226 | fe_err: |
| 227 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 228 | fe->dai_link->compr_ops->shutdown(cstream); |
| 229 | machine_err: |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 230 | for_each_rtdcom(fe, rtdcom) { |
| 231 | component = rtdcom->component; |
| 232 | |
| 233 | /* ignore duplication for now */ |
| 234 | if (platform && (component == &platform->component)) |
| 235 | continue; |
| 236 | |
| 237 | if (!component->driver->compr_ops || |
| 238 | !component->driver->compr_ops->free) |
| 239 | continue; |
| 240 | |
| 241 | component->driver->compr_ops->free(cstream); |
| 242 | } |
| 243 | |
| 244 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 245 | platform->driver->compr_ops->free(cstream); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 246 | plat_err: |
| 247 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 248 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 249 | out: |
| 250 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 251 | mutex_unlock(&fe->card->mutex); |
| 252 | return ret; |
| 253 | } |
| 254 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 255 | /* |
| 256 | * Power down the audio subsystem pmdown_time msecs after close is called. |
| 257 | * This is to ensure there are no pops or clicks in between any music tracks |
| 258 | * due to DAPM power cycling. |
| 259 | */ |
| 260 | static void close_delayed_work(struct work_struct *work) |
| 261 | { |
| 262 | struct snd_soc_pcm_runtime *rtd = |
| 263 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
| 264 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 265 | |
| 266 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 267 | |
| 268 | dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n", |
| 269 | codec_dai->driver->playback.stream_name, |
| 270 | codec_dai->playback_active ? "active" : "inactive", |
| 271 | rtd->pop_wait ? "yes" : "no"); |
| 272 | |
| 273 | /* are we waiting on this codec DAI stream */ |
| 274 | if (rtd->pop_wait == 1) { |
| 275 | rtd->pop_wait = 0; |
| 276 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 277 | SND_SOC_DAPM_STREAM_STOP); |
| 278 | } |
| 279 | |
| 280 | mutex_unlock(&rtd->pcm_mutex); |
| 281 | } |
| 282 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 283 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 284 | { |
| 285 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 286 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 287 | struct snd_soc_component *component; |
| 288 | struct snd_soc_rtdcom_list *rtdcom; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 289 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 290 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 291 | int stream; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 292 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 293 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 294 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 295 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 296 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 297 | else |
| 298 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 299 | |
| 300 | snd_soc_runtime_deactivate(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 301 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 302 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 303 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 304 | if (!cpu_dai->active) |
| 305 | cpu_dai->rate = 0; |
| 306 | |
| 307 | if (!codec_dai->active) |
| 308 | codec_dai->rate = 0; |
| 309 | |
| 310 | |
| 311 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) |
| 312 | rtd->dai_link->compr_ops->shutdown(cstream); |
| 313 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 314 | for_each_rtdcom(rtd, rtdcom) { |
| 315 | component = rtdcom->component; |
| 316 | |
| 317 | /* ignore duplication for now */ |
| 318 | if (platform && (component == &platform->component)) |
| 319 | continue; |
| 320 | |
| 321 | if (!component->driver->compr_ops || |
| 322 | !component->driver->compr_ops->free) |
| 323 | continue; |
| 324 | |
| 325 | component->driver->compr_ops->free(cstream); |
| 326 | } |
| 327 | |
| 328 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 329 | platform->driver->compr_ops->free(cstream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 330 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 331 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 332 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 333 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 334 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 335 | if (snd_soc_runtime_ignore_pmdown_time(rtd)) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 336 | snd_soc_dapm_stream_event(rtd, |
| 337 | SNDRV_PCM_STREAM_PLAYBACK, |
| 338 | SND_SOC_DAPM_STREAM_STOP); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 339 | } else { |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 340 | rtd->pop_wait = 1; |
Mark Brown | 3d24cfe | 2013-08-09 18:12:29 +0100 | [diff] [blame] | 341 | queue_delayed_work(system_power_efficient_wq, |
| 342 | &rtd->delayed_work, |
| 343 | msecs_to_jiffies(rtd->pmdown_time)); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 344 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 345 | } else { |
| 346 | /* capture streams can be powered down now */ |
| 347 | snd_soc_dapm_stream_event(rtd, |
| 348 | SNDRV_PCM_STREAM_CAPTURE, |
| 349 | SND_SOC_DAPM_STREAM_STOP); |
| 350 | } |
| 351 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 352 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 356 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
| 357 | { |
| 358 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 359 | struct snd_soc_platform *platform = fe->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 360 | struct snd_soc_component *component; |
| 361 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 362 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 363 | struct snd_soc_dpcm *dpcm; |
| 364 | int stream, ret; |
| 365 | |
| 366 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 367 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 368 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 369 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 370 | else |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 371 | stream = SNDRV_PCM_STREAM_CAPTURE; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 372 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 373 | snd_soc_runtime_deactivate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 374 | |
| 375 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 376 | |
| 377 | ret = dpcm_be_dai_hw_free(fe, stream); |
| 378 | if (ret < 0) |
| 379 | dev_err(fe->dev, "compressed hw_free failed %d\n", ret); |
| 380 | |
| 381 | ret = dpcm_be_dai_shutdown(fe, stream); |
| 382 | |
| 383 | /* mark FE's links ready to prune */ |
| 384 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 385 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 386 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 387 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 388 | |
| 389 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 390 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 391 | |
| 392 | dpcm_be_disconnect(fe, stream); |
| 393 | |
| 394 | fe->dpcm[stream].runtime = NULL; |
| 395 | |
| 396 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 397 | fe->dai_link->compr_ops->shutdown(cstream); |
| 398 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 399 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 400 | platform->driver->compr_ops->free(cstream); |
| 401 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 402 | for_each_rtdcom(fe, rtdcom) { |
| 403 | component = rtdcom->component; |
| 404 | |
| 405 | /* ignore duplication for now */ |
| 406 | if (platform && (component == &platform->component)) |
| 407 | continue; |
| 408 | |
| 409 | if (!component->driver->compr_ops || |
| 410 | !component->driver->compr_ops->free) |
| 411 | continue; |
| 412 | |
| 413 | component->driver->compr_ops->free(cstream); |
| 414 | } |
| 415 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 416 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 417 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 418 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 419 | mutex_unlock(&fe->card->mutex); |
| 420 | return 0; |
| 421 | } |
| 422 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 423 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 424 | { |
| 425 | |
| 426 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 427 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 428 | struct snd_soc_component *component; |
| 429 | struct snd_soc_rtdcom_list *rtdcom; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 430 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 431 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 432 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 433 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 434 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 435 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 436 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->trigger) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 437 | ret = platform->driver->compr_ops->trigger(cstream, cmd); |
| 438 | if (ret < 0) |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 439 | goto out; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 440 | } |
| 441 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 442 | for_each_rtdcom(rtd, rtdcom) { |
| 443 | component = rtdcom->component; |
| 444 | |
| 445 | /* ignore duplication for now */ |
| 446 | if (platform && (component == &platform->component)) |
| 447 | continue; |
| 448 | |
| 449 | if (!component->driver->compr_ops || |
| 450 | !component->driver->compr_ops->trigger) |
| 451 | continue; |
| 452 | |
| 453 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 454 | if (__ret < 0) |
| 455 | ret = __ret; |
| 456 | } |
| 457 | if (ret < 0) |
| 458 | goto out; |
| 459 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 460 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) |
| 461 | cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 462 | |
| 463 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 464 | switch (cmd) { |
| 465 | case SNDRV_PCM_TRIGGER_START: |
| 466 | snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); |
| 467 | break; |
| 468 | case SNDRV_PCM_TRIGGER_STOP: |
| 469 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 470 | break; |
Mark Brown | e38b9b7 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 471 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 472 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 473 | out: |
| 474 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 478 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
| 479 | { |
| 480 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 481 | struct snd_soc_platform *platform = fe->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 482 | struct snd_soc_component *component; |
| 483 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 484 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 485 | int ret = 0, __ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 486 | |
| 487 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
| 488 | cmd == SND_COMPR_TRIGGER_DRAIN) { |
| 489 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 490 | if (platform && |
| 491 | platform->driver->compr_ops && |
Dan Carpenter | 15b8e94 | 2014-05-14 17:23:08 +0300 | [diff] [blame] | 492 | platform->driver->compr_ops->trigger) |
| 493 | return platform->driver->compr_ops->trigger(cstream, |
| 494 | cmd); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 495 | |
| 496 | for_each_rtdcom(fe, rtdcom) { |
| 497 | component = rtdcom->component; |
| 498 | |
| 499 | /* ignore duplication for now */ |
| 500 | if (platform && (component == &platform->component)) |
| 501 | continue; |
| 502 | |
| 503 | if (!component->driver->compr_ops || |
| 504 | !component->driver->compr_ops->trigger) |
| 505 | continue; |
| 506 | |
| 507 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 508 | if (__ret < 0) |
| 509 | ret = __ret; |
| 510 | } |
| 511 | return ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 515 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 516 | else |
| 517 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 518 | |
| 519 | |
| 520 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 521 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 522 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) { |
| 523 | ret = cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 524 | if (ret < 0) |
| 525 | goto out; |
| 526 | } |
| 527 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 528 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->trigger) { |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 529 | ret = platform->driver->compr_ops->trigger(cstream, cmd); |
| 530 | if (ret < 0) |
| 531 | goto out; |
| 532 | } |
| 533 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 534 | for_each_rtdcom(fe, rtdcom) { |
| 535 | component = rtdcom->component; |
| 536 | |
| 537 | /* ignore duplication for now */ |
| 538 | if (platform && (component == &platform->component)) |
| 539 | continue; |
| 540 | |
| 541 | if (!component->driver->compr_ops || |
| 542 | !component->driver->compr_ops->trigger) |
| 543 | continue; |
| 544 | |
| 545 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 546 | if (__ret < 0) |
| 547 | ret = __ret; |
| 548 | } |
| 549 | if (ret < 0) |
| 550 | goto out; |
| 551 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 552 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 553 | |
| 554 | ret = dpcm_be_dai_trigger(fe, stream, cmd); |
| 555 | |
| 556 | switch (cmd) { |
| 557 | case SNDRV_PCM_TRIGGER_START: |
| 558 | case SNDRV_PCM_TRIGGER_RESUME: |
| 559 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 560 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 561 | break; |
| 562 | case SNDRV_PCM_TRIGGER_STOP: |
| 563 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 564 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 565 | break; |
| 566 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 567 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | out: |
| 572 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 573 | mutex_unlock(&fe->card->mutex); |
| 574 | return ret; |
| 575 | } |
| 576 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 577 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 578 | struct snd_compr_params *params) |
| 579 | { |
| 580 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 581 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 582 | struct snd_soc_component *component; |
| 583 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 584 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 585 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 586 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 587 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 588 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 589 | /* first we call set_params for the platform driver |
| 590 | * this should configure the soc side |
| 591 | * if the machine has compressed ops then we call that as well |
| 592 | * expectation is that platform and machine will configure everything |
| 593 | * for this compress path, like configuring pcm port for codec |
| 594 | */ |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 595 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 596 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 597 | if (ret < 0) |
| 598 | goto err; |
| 599 | } |
| 600 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 601 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_params) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 602 | ret = platform->driver->compr_ops->set_params(cstream, params); |
| 603 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 604 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 605 | } |
| 606 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 607 | for_each_rtdcom(rtd, rtdcom) { |
| 608 | component = rtdcom->component; |
| 609 | |
| 610 | /* ignore duplication for now */ |
| 611 | if (platform && (component == &platform->component)) |
| 612 | continue; |
| 613 | |
| 614 | if (!component->driver->compr_ops || |
| 615 | !component->driver->compr_ops->set_params) |
| 616 | continue; |
| 617 | |
| 618 | __ret = component->driver->compr_ops->set_params(cstream, params); |
| 619 | if (__ret < 0) |
| 620 | ret = __ret; |
| 621 | } |
| 622 | if (ret < 0) |
| 623 | goto err; |
| 624 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 625 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { |
| 626 | ret = rtd->dai_link->compr_ops->set_params(cstream); |
| 627 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 628 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 629 | } |
| 630 | |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 631 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 632 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 633 | SND_SOC_DAPM_STREAM_START); |
| 634 | else |
| 635 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
| 636 | SND_SOC_DAPM_STREAM_START); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 637 | |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 638 | /* cancel any delayed stream shutdown that is pending */ |
| 639 | rtd->pop_wait = 0; |
| 640 | mutex_unlock(&rtd->pcm_mutex); |
| 641 | |
| 642 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 643 | |
| 644 | return ret; |
| 645 | |
| 646 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 647 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 648 | return ret; |
| 649 | } |
| 650 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 651 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, |
| 652 | struct snd_compr_params *params) |
| 653 | { |
| 654 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 655 | struct snd_pcm_substream *fe_substream = |
| 656 | fe->pcm->streams[cstream->direction].substream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 657 | struct snd_soc_platform *platform = fe->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 658 | struct snd_soc_component *component; |
| 659 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 660 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 661 | int ret = 0, __ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 662 | |
| 663 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 664 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 665 | else |
| 666 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 667 | |
| 668 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 669 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 670 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 671 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 672 | if (ret < 0) |
| 673 | goto out; |
| 674 | } |
| 675 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 676 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_params) { |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 677 | ret = platform->driver->compr_ops->set_params(cstream, params); |
| 678 | if (ret < 0) |
| 679 | goto out; |
| 680 | } |
| 681 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 682 | for_each_rtdcom(fe, rtdcom) { |
| 683 | component = rtdcom->component; |
| 684 | |
| 685 | /* ignore duplication for now */ |
| 686 | if (platform && (component == &platform->component)) |
| 687 | continue; |
| 688 | |
| 689 | if (!component->driver->compr_ops || |
| 690 | !component->driver->compr_ops->set_params) |
| 691 | continue; |
| 692 | |
| 693 | __ret = component->driver->compr_ops->set_params(cstream, params); |
| 694 | if (__ret < 0) |
| 695 | ret = __ret; |
| 696 | } |
| 697 | if (ret < 0) |
| 698 | goto out; |
| 699 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 700 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { |
| 701 | ret = fe->dai_link->compr_ops->set_params(cstream); |
| 702 | if (ret < 0) |
| 703 | goto out; |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Create an empty hw_params for the BE as the machine driver must |
| 708 | * fix this up to match DSP decoder and ASRC configuration. |
| 709 | * I.e. machine driver fixup for compressed BE is mandatory. |
| 710 | */ |
| 711 | memset(&fe->dpcm[fe_substream->stream].hw_params, 0, |
| 712 | sizeof(struct snd_pcm_hw_params)); |
| 713 | |
| 714 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 715 | |
| 716 | ret = dpcm_be_dai_hw_params(fe, stream); |
| 717 | if (ret < 0) |
| 718 | goto out; |
| 719 | |
| 720 | ret = dpcm_be_dai_prepare(fe, stream); |
| 721 | if (ret < 0) |
| 722 | goto out; |
| 723 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 724 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 725 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 726 | |
| 727 | out: |
| 728 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 729 | mutex_unlock(&fe->card->mutex); |
| 730 | return ret; |
| 731 | } |
| 732 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 733 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
| 734 | struct snd_codec *params) |
| 735 | { |
| 736 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 737 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 738 | struct snd_soc_component *component; |
| 739 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 740 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 741 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 742 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 743 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 744 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 745 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_params) { |
| 746 | ret = cpu_dai->driver->cops->get_params(cstream, params, cpu_dai); |
| 747 | if (ret < 0) |
| 748 | goto err; |
| 749 | } |
| 750 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 751 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_params) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 752 | ret = platform->driver->compr_ops->get_params(cstream, params); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 753 | if (ret < 0) |
| 754 | goto err; |
| 755 | } |
| 756 | |
| 757 | for_each_rtdcom(rtd, rtdcom) { |
| 758 | component = rtdcom->component; |
| 759 | |
| 760 | /* ignore duplication for now */ |
| 761 | if (platform && (component == &platform->component)) |
| 762 | continue; |
| 763 | |
| 764 | if (!component->driver->compr_ops || |
| 765 | !component->driver->compr_ops->get_params) |
| 766 | continue; |
| 767 | |
| 768 | __ret = component->driver->compr_ops->get_params(cstream, params); |
| 769 | if (__ret < 0) |
| 770 | ret = __ret; |
| 771 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 772 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 773 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 774 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 775 | return ret; |
| 776 | } |
| 777 | |
| 778 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
| 779 | struct snd_compr_caps *caps) |
| 780 | { |
| 781 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 782 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 783 | struct snd_soc_component *component; |
| 784 | struct snd_soc_rtdcom_list *rtdcom; |
| 785 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 786 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 787 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 788 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 789 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_caps) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 790 | ret = platform->driver->compr_ops->get_caps(cstream, caps); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 791 | if (ret < 0) |
| 792 | goto err; |
| 793 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 794 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 795 | for_each_rtdcom(rtd, rtdcom) { |
| 796 | component = rtdcom->component; |
| 797 | |
| 798 | /* ignore duplication for now */ |
| 799 | if (platform && (component == &platform->component)) |
| 800 | continue; |
| 801 | |
| 802 | if (!component->driver->compr_ops || |
| 803 | !component->driver->compr_ops->get_caps) |
| 804 | continue; |
| 805 | |
| 806 | __ret = component->driver->compr_ops->get_caps(cstream, caps); |
| 807 | if (__ret < 0) |
| 808 | ret = __ret; |
| 809 | } |
| 810 | |
| 811 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 812 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 813 | return ret; |
| 814 | } |
| 815 | |
| 816 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
| 817 | struct snd_compr_codec_caps *codec) |
| 818 | { |
| 819 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 820 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 821 | struct snd_soc_component *component; |
| 822 | struct snd_soc_rtdcom_list *rtdcom; |
| 823 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 824 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 825 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 826 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 827 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 828 | ret = platform->driver->compr_ops->get_codec_caps(cstream, codec); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 829 | if (ret < 0) |
| 830 | goto err; |
| 831 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 832 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 833 | for_each_rtdcom(rtd, rtdcom) { |
| 834 | component = rtdcom->component; |
| 835 | |
| 836 | /* ignore duplication for now */ |
| 837 | if (platform && (component == &platform->component)) |
| 838 | continue; |
| 839 | |
| 840 | if (!component->driver->compr_ops || |
| 841 | !component->driver->compr_ops->get_codec_caps) |
| 842 | continue; |
| 843 | |
| 844 | __ret = component->driver->compr_ops->get_codec_caps(cstream, codec); |
| 845 | if (__ret < 0) |
| 846 | ret = __ret; |
| 847 | } |
| 848 | |
| 849 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 850 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 855 | { |
| 856 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 857 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 858 | struct snd_soc_component *component; |
| 859 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 860 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 861 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 862 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 863 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 864 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 865 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->ack) { |
| 866 | ret = cpu_dai->driver->cops->ack(cstream, bytes, cpu_dai); |
| 867 | if (ret < 0) |
| 868 | goto err; |
| 869 | } |
| 870 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 871 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->ack) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 872 | ret = platform->driver->compr_ops->ack(cstream, bytes); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 873 | if (ret < 0) |
| 874 | goto err; |
| 875 | } |
| 876 | |
| 877 | for_each_rtdcom(rtd, rtdcom) { |
| 878 | component = rtdcom->component; |
| 879 | |
| 880 | /* ignore duplication for now */ |
| 881 | if (platform && (component == &platform->component)) |
| 882 | continue; |
| 883 | |
| 884 | if (!component->driver->compr_ops || |
| 885 | !component->driver->compr_ops->ack) |
| 886 | continue; |
| 887 | |
| 888 | __ret = component->driver->compr_ops->ack(cstream, bytes); |
| 889 | if (__ret < 0) |
| 890 | ret = __ret; |
| 891 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 892 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 893 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 894 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 895 | return ret; |
| 896 | } |
| 897 | |
| 898 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
| 899 | struct snd_compr_tstamp *tstamp) |
| 900 | { |
| 901 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 902 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 903 | struct snd_soc_component *component; |
| 904 | struct snd_soc_rtdcom_list *rtdcom; |
| 905 | int ret = 0, __ret; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 906 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 907 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 908 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 909 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 910 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer) |
| 911 | cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai); |
| 912 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 913 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->pointer) { |
Charles Keepax | 7c9190f | 2016-06-20 09:51:32 +0100 | [diff] [blame] | 914 | ret = platform->driver->compr_ops->pointer(cstream, tstamp); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 915 | if (ret < 0) |
| 916 | goto err; |
| 917 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 918 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 919 | for_each_rtdcom(rtd, rtdcom) { |
| 920 | component = rtdcom->component; |
| 921 | |
| 922 | /* ignore duplication for now */ |
| 923 | if (platform && (component == &platform->component)) |
| 924 | continue; |
| 925 | |
| 926 | if (!component->driver->compr_ops || |
| 927 | !component->driver->compr_ops->pointer) |
| 928 | continue; |
| 929 | |
| 930 | __ret = component->driver->compr_ops->pointer(cstream, tstamp); |
| 931 | if (__ret < 0) |
| 932 | ret = __ret; |
| 933 | } |
| 934 | |
| 935 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 936 | mutex_unlock(&rtd->pcm_mutex); |
Charles Keepax | 7c9190f | 2016-06-20 09:51:32 +0100 | [diff] [blame] | 937 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 938 | } |
| 939 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 940 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 4daf891 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 941 | char __user *buf, size_t count) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 942 | { |
| 943 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 944 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 945 | struct snd_soc_component *component; |
| 946 | struct snd_soc_rtdcom_list *rtdcom; |
| 947 | int ret = 0, __ret; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 948 | |
| 949 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 950 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 951 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->copy) { |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 952 | ret = platform->driver->compr_ops->copy(cstream, buf, count); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 953 | if (ret < 0) |
| 954 | goto err; |
| 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 | |
| 960 | /* ignore duplication for now */ |
| 961 | if (platform && (component == &platform->component)) |
| 962 | continue; |
| 963 | |
| 964 | if (!component->driver->compr_ops || |
| 965 | !component->driver->compr_ops->copy) |
| 966 | continue; |
| 967 | |
| 968 | __ret = component->driver->compr_ops->copy(cstream, buf, count); |
| 969 | if (__ret < 0) |
| 970 | ret = __ret; |
| 971 | } |
| 972 | err: |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 973 | mutex_unlock(&rtd->pcm_mutex); |
| 974 | return ret; |
| 975 | } |
| 976 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 977 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 978 | struct snd_compr_metadata *metadata) |
| 979 | { |
| 980 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 981 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 982 | struct snd_soc_component *component; |
| 983 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 984 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 985 | int ret = 0, __ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 986 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 987 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) { |
| 988 | ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai); |
| 989 | if (ret < 0) |
| 990 | return ret; |
| 991 | } |
| 992 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 993 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_metadata) { |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 994 | ret = platform->driver->compr_ops->set_metadata(cstream, metadata); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 995 | if (ret < 0) |
| 996 | return ret; |
| 997 | } |
| 998 | |
| 999 | for_each_rtdcom(rtd, rtdcom) { |
| 1000 | component = rtdcom->component; |
| 1001 | |
| 1002 | /* ignore duplication for now */ |
| 1003 | if (platform && (component == &platform->component)) |
| 1004 | continue; |
| 1005 | |
| 1006 | if (!component->driver->compr_ops || |
| 1007 | !component->driver->compr_ops->set_metadata) |
| 1008 | continue; |
| 1009 | |
| 1010 | __ret = component->driver->compr_ops->set_metadata(cstream, metadata); |
| 1011 | if (__ret < 0) |
| 1012 | ret = __ret; |
| 1013 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 1014 | |
| 1015 | return ret; |
| 1016 | } |
| 1017 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 1018 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 1019 | struct snd_compr_metadata *metadata) |
| 1020 | { |
| 1021 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 1022 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1023 | struct snd_soc_component *component; |
| 1024 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 1025 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1026 | int ret = 0, __ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 1027 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 1028 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) { |
| 1029 | ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai); |
| 1030 | if (ret < 0) |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1034 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_metadata) { |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 1035 | ret = platform->driver->compr_ops->get_metadata(cstream, metadata); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1036 | if (ret < 0) |
| 1037 | return ret; |
| 1038 | } |
| 1039 | |
| 1040 | for_each_rtdcom(rtd, rtdcom) { |
| 1041 | component = rtdcom->component; |
| 1042 | |
| 1043 | /* ignore duplication for now */ |
| 1044 | if (platform && (component == &platform->component)) |
| 1045 | continue; |
| 1046 | |
| 1047 | if (!component->driver->compr_ops || |
| 1048 | !component->driver->compr_ops->get_metadata) |
| 1049 | continue; |
| 1050 | |
| 1051 | __ret = component->driver->compr_ops->get_metadata(cstream, metadata); |
| 1052 | if (__ret < 0) |
| 1053 | ret = __ret; |
| 1054 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 1055 | |
| 1056 | return ret; |
| 1057 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1058 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1059 | /* ASoC Compress operations */ |
| 1060 | static struct snd_compr_ops soc_compr_ops = { |
| 1061 | .open = soc_compr_open, |
| 1062 | .free = soc_compr_free, |
| 1063 | .set_params = soc_compr_set_params, |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 1064 | .set_metadata = soc_compr_set_metadata, |
| 1065 | .get_metadata = soc_compr_get_metadata, |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1066 | .get_params = soc_compr_get_params, |
| 1067 | .trigger = soc_compr_trigger, |
| 1068 | .pointer = soc_compr_pointer, |
| 1069 | .ack = soc_compr_ack, |
| 1070 | .get_caps = soc_compr_get_caps, |
| 1071 | .get_codec_caps = soc_compr_get_codec_caps |
| 1072 | }; |
| 1073 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1074 | /* ASoC Dynamic Compress operations */ |
| 1075 | static struct snd_compr_ops soc_compr_dyn_ops = { |
| 1076 | .open = soc_compr_open_fe, |
| 1077 | .free = soc_compr_free_fe, |
| 1078 | .set_params = soc_compr_set_params_fe, |
| 1079 | .get_params = soc_compr_get_params, |
| 1080 | .set_metadata = soc_compr_set_metadata, |
| 1081 | .get_metadata = soc_compr_get_metadata, |
| 1082 | .trigger = soc_compr_trigger_fe, |
| 1083 | .pointer = soc_compr_pointer, |
| 1084 | .ack = soc_compr_ack, |
| 1085 | .get_caps = soc_compr_get_caps, |
| 1086 | .get_codec_caps = soc_compr_get_codec_caps |
| 1087 | }; |
| 1088 | |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 1089 | /** |
| 1090 | * snd_soc_new_compress - create a new compress. |
| 1091 | * |
| 1092 | * @rtd: The runtime for which we will create compress |
| 1093 | * @num: the device index number (zero based - shared with normal PCMs) |
| 1094 | * |
| 1095 | * Return: 0 for success, else error. |
| 1096 | */ |
| 1097 | 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] | 1098 | { |
| 1099 | struct snd_soc_codec *codec = rtd->codec; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1100 | struct snd_soc_platform *platform = rtd->platform; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1101 | struct snd_soc_component *component; |
| 1102 | struct snd_soc_rtdcom_list *rtdcom; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1103 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1104 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1105 | struct snd_compr *compr; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1106 | struct snd_pcm *be_pcm; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1107 | char new_name[64]; |
| 1108 | int ret = 0, direction = 0; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 1109 | int playback = 0, capture = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1110 | |
Benoit Cousson | 8151d5e | 2014-07-08 23:19:37 +0200 | [diff] [blame] | 1111 | if (rtd->num_codecs > 1) { |
| 1112 | dev_err(rtd->card->dev, "Multicodec not supported for compressed stream\n"); |
| 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1116 | /* check client and interface hw capabilities */ |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 1117 | if (codec_dai->driver->playback.channels_min) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 1118 | playback = 1; |
| 1119 | if (codec_dai->driver->capture.channels_min) |
| 1120 | capture = 1; |
| 1121 | |
| 1122 | capture = capture && cpu_dai->driver->capture.channels_min; |
| 1123 | playback = playback && cpu_dai->driver->playback.channels_min; |
| 1124 | |
| 1125 | /* |
| 1126 | * Compress devices are unidirectional so only one of the directions |
| 1127 | * should be set, check for that (xor) |
| 1128 | */ |
| 1129 | if (playback + capture != 1) { |
| 1130 | dev_err(rtd->card->dev, "Invalid direction for compress P %d, C %d\n", |
| 1131 | playback, capture); |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 1132 | return -EINVAL; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 1133 | } |
| 1134 | |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 1135 | if (playback) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 1136 | direction = SND_COMPRESS_PLAYBACK; |
| 1137 | else |
| 1138 | direction = SND_COMPRESS_CAPTURE; |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 1139 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1140 | compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 1141 | if (!compr) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1142 | return -ENOMEM; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1143 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1144 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 1145 | GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 1146 | if (!compr->ops) { |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1147 | ret = -ENOMEM; |
| 1148 | goto compr_err; |
| 1149 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1150 | |
| 1151 | if (rtd->dai_link->dynamic) { |
| 1152 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 1153 | rtd->dai_link->stream_name); |
| 1154 | |
| 1155 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 1156 | rtd->dai_link->dpcm_playback, |
| 1157 | rtd->dai_link->dpcm_capture, &be_pcm); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1158 | if (ret < 0) { |
| 1159 | dev_err(rtd->card->dev, "ASoC: can't create compressed for %s\n", |
| 1160 | rtd->dai_link->name); |
| 1161 | goto compr_err; |
| 1162 | } |
| 1163 | |
| 1164 | rtd->pcm = be_pcm; |
| 1165 | rtd->fe_compr = 1; |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 1166 | if (rtd->dai_link->dpcm_playback) |
| 1167 | be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 1168 | else if (rtd->dai_link->dpcm_capture) |
| 1169 | be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1170 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 1171 | } else { |
| 1172 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 1173 | rtd->dai_link->stream_name, codec_dai->name, num); |
| 1174 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 1175 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 1176 | } |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1177 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1178 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1179 | /* Add copy callback for not memory mapped DSPs */ |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1180 | if (platform && platform->driver->compr_ops && platform->driver->compr_ops->copy) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1181 | compr->ops->copy = soc_compr_copy; |
| 1182 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame^] | 1183 | for_each_rtdcom(rtd, rtdcom) { |
| 1184 | component = rtdcom->component; |
| 1185 | |
| 1186 | /* ignore duplication for now */ |
| 1187 | if (platform && (component == &platform->component)) |
| 1188 | continue; |
| 1189 | |
| 1190 | if (!component->driver->compr_ops || |
| 1191 | !component->driver->compr_ops->copy) |
| 1192 | continue; |
| 1193 | |
| 1194 | compr->ops->copy = soc_compr_copy; |
| 1195 | } |
| 1196 | |
| 1197 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1198 | mutex_init(&compr->lock); |
Richard Fitzgerald | e5241a8 | 2015-11-25 13:00:24 +0000 | [diff] [blame] | 1199 | ret = snd_compress_new(rtd->card->snd_card, num, direction, |
| 1200 | new_name, compr); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1201 | if (ret < 0) { |
| 1202 | pr_err("compress asoc: can't create compress for codec %s\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 1203 | codec->component.name); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1204 | goto compr_err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1205 | } |
| 1206 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 1207 | /* DAPM dai link stream work */ |
| 1208 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 1209 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1210 | rtd->compr = compr; |
| 1211 | compr->private_data = rtd; |
| 1212 | |
| 1213 | printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 1214 | cpu_dai->name); |
| 1215 | return ret; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 1216 | |
| 1217 | compr_err: |
| 1218 | kfree(compr); |
| 1219 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1220 | } |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 1221 | EXPORT_SYMBOL_GPL(snd_soc_new_compress); |