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