Namarta Kohli | 9f052a7 | 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 | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 27 | #include <sound/soc-dpcm.h> |
Namarta Kohli | 9f052a7 | 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; |
| 33 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 34 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 35 | int ret = 0; |
| 36 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 37 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 38 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 39 | if (platform->driver->compr_ops && platform->driver->compr_ops->open) { |
| 40 | ret = platform->driver->compr_ops->open(cstream); |
| 41 | if (ret < 0) { |
| 42 | pr_err("compress asoc: can't open platform %s\n", platform->name); |
| 43 | goto out; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { |
| 48 | ret = rtd->dai_link->compr_ops->startup(cstream); |
| 49 | if (ret < 0) { |
| 50 | pr_err("compress asoc: %s startup failed\n", rtd->dai_link->name); |
| 51 | goto machine_err; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 56 | cpu_dai->playback_active++; |
| 57 | codec_dai->playback_active++; |
| 58 | } else { |
| 59 | cpu_dai->capture_active++; |
| 60 | codec_dai->capture_active++; |
| 61 | } |
| 62 | |
| 63 | cpu_dai->active++; |
| 64 | codec_dai->active++; |
| 65 | rtd->codec->active++; |
| 66 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 67 | mutex_unlock(&rtd->pcm_mutex); |
| 68 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 69 | return 0; |
| 70 | |
| 71 | machine_err: |
| 72 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) |
| 73 | platform->driver->compr_ops->free(cstream); |
| 74 | out: |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 75 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 76 | return ret; |
| 77 | } |
| 78 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 79 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) |
| 80 | { |
| 81 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 82 | struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream; |
| 83 | struct snd_soc_platform *platform = fe->platform; |
| 84 | struct snd_soc_dpcm_params *dpcm; |
| 85 | struct snd_soc_dapm_widget_list *list; |
Haynes Mathew George | 2b4c821 | 2013-07-26 13:38:01 -0700 | [diff] [blame] | 86 | |
| 87 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
| 88 | struct snd_soc_dai *codec_dai = fe->codec_dai; |
| 89 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 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 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 98 | mutex_lock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 99 | |
| 100 | if (platform->driver->compr_ops && platform->driver->compr_ops->open) { |
| 101 | ret = platform->driver->compr_ops->open(cstream); |
| 102 | if (ret < 0) { |
| 103 | pr_err("compress asoc: can't open platform %s\n", platform->name); |
| 104 | goto out; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { |
| 109 | ret = fe->dai_link->compr_ops->startup(cstream); |
| 110 | if (ret < 0) { |
| 111 | pr_err("compress asoc: %s startup failed\n", fe->dai_link->name); |
| 112 | goto machine_err; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 117 | |
| 118 | if (dpcm_path_get(fe, stream, &list) <= 0) { |
| 119 | dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", |
| 120 | fe->dai_link->name, stream ? "capture" : "playback"); |
| 121 | } |
| 122 | |
| 123 | /* calculate valid and active FE <-> BE dpcms */ |
| 124 | dpcm_process_paths(fe, stream, &list, 1); |
| 125 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 126 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 127 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 128 | ret = dpcm_be_dai_startup(fe, stream); |
| 129 | if (ret < 0) { |
| 130 | /* clean up all links */ |
| 131 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 132 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 133 | |
| 134 | dpcm_be_disconnect(fe, stream); |
| 135 | fe->dpcm[stream].runtime = NULL; |
| 136 | goto fe_err; |
| 137 | } |
| 138 | |
| 139 | dpcm_clear_pending_state(fe, stream); |
| 140 | dpcm_path_put(&list); |
| 141 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 142 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 143 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
Haynes Mathew George | 2b4c821 | 2013-07-26 13:38:01 -0700 | [diff] [blame] | 144 | |
| 145 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 146 | cpu_dai->playback_active++; |
| 147 | codec_dai->playback_active++; |
| 148 | } else { |
| 149 | cpu_dai->capture_active++; |
| 150 | codec_dai->capture_active++; |
| 151 | } |
| 152 | |
| 153 | cpu_dai->active++; |
| 154 | codec_dai->active++; |
| 155 | fe->codec->active++; |
| 156 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 157 | mutex_unlock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 158 | |
| 159 | return 0; |
| 160 | |
| 161 | fe_err: |
| 162 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 163 | fe->dai_link->compr_ops->shutdown(cstream); |
| 164 | machine_err: |
| 165 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) |
| 166 | platform->driver->compr_ops->free(cstream); |
| 167 | out: |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 168 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 169 | mutex_unlock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 170 | return ret; |
| 171 | } |
| 172 | |
Charles Keepax | 57f8e79 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 173 | /* |
| 174 | * Power down the audio subsystem pmdown_time msecs after close is called. |
| 175 | * This is to ensure there are no pops or clicks in between any music tracks |
| 176 | * due to DAPM power cycling. |
| 177 | */ |
| 178 | static void close_delayed_work(struct work_struct *work) |
| 179 | { |
| 180 | struct snd_soc_pcm_runtime *rtd = |
| 181 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
| 182 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 183 | |
| 184 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 185 | |
| 186 | dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n", |
| 187 | codec_dai->driver->playback.stream_name, |
| 188 | codec_dai->playback_active ? "active" : "inactive", |
Eric Laurent | 3359ca3 | 2013-04-08 16:07:19 -0700 | [diff] [blame] | 189 | codec_dai->pop_wait ? "yes" : "no"); |
Charles Keepax | 57f8e79 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 190 | |
| 191 | /* are we waiting on this codec DAI stream */ |
Eric Laurent | 3359ca3 | 2013-04-08 16:07:19 -0700 | [diff] [blame] | 192 | if (codec_dai->pop_wait == 1) { |
| 193 | codec_dai->pop_wait = 0; |
Charles Keepax | 57f8e79 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 194 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 195 | SND_SOC_DAPM_STREAM_STOP); |
| 196 | } |
| 197 | |
| 198 | mutex_unlock(&rtd->pcm_mutex); |
| 199 | } |
| 200 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 201 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 202 | { |
| 203 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 204 | struct snd_soc_platform *platform = rtd->platform; |
| 205 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 206 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 207 | struct snd_soc_codec *codec = rtd->codec; |
| 208 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 209 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 210 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 211 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 212 | cpu_dai->playback_active--; |
| 213 | codec_dai->playback_active--; |
Mark Brown | 12a6e63 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 214 | snd_soc_dai_digital_mute(codec_dai, 1); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 215 | } else { |
| 216 | cpu_dai->capture_active--; |
| 217 | codec_dai->capture_active--; |
| 218 | } |
| 219 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 220 | cpu_dai->active--; |
| 221 | codec_dai->active--; |
| 222 | codec->active--; |
| 223 | |
| 224 | if (!cpu_dai->active) |
| 225 | cpu_dai->rate = 0; |
| 226 | |
| 227 | if (!codec_dai->active) |
| 228 | codec_dai->rate = 0; |
| 229 | |
| 230 | |
| 231 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) |
| 232 | rtd->dai_link->compr_ops->shutdown(cstream); |
| 233 | |
| 234 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) |
| 235 | platform->driver->compr_ops->free(cstream); |
Vinod Koul | e3ee8fa | 2012-08-21 12:15:02 +0530 | [diff] [blame] | 236 | cpu_dai->runtime = NULL; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 237 | |
| 238 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 239 | if (!rtd->pmdown_time || codec->ignore_pmdown_time || |
| 240 | rtd->dai_link->ignore_pmdown_time) { |
| 241 | snd_soc_dapm_stream_event(rtd, |
Eric Laurent | f2615f7 | 2013-04-08 15:52:05 -0700 | [diff] [blame] | 242 | codec_dai->driver->playback.stream_name, |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 243 | SND_SOC_DAPM_STREAM_STOP); |
Charles Keepax | 808dc72 | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 244 | } else { |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 245 | codec_dai->pop_wait = 1; |
| 246 | schedule_delayed_work(&rtd->delayed_work, |
| 247 | msecs_to_jiffies(rtd->pmdown_time)); |
Charles Keepax | 808dc72 | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 248 | } |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 249 | } else { |
| 250 | /* capture streams can be powered down now */ |
| 251 | snd_soc_dapm_stream_event(rtd, |
Eric Laurent | f2615f7 | 2013-04-08 15:52:05 -0700 | [diff] [blame] | 252 | codec_dai->driver->capture.stream_name, |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 253 | SND_SOC_DAPM_STREAM_STOP); |
| 254 | } |
| 255 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 256 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 260 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
| 261 | { |
| 262 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 263 | struct snd_soc_platform *platform = fe->platform; |
| 264 | struct snd_soc_dpcm_params *dpcm; |
| 265 | int stream, ret; |
| 266 | |
Haynes Mathew George | 2b4c821 | 2013-07-26 13:38:01 -0700 | [diff] [blame] | 267 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
| 268 | struct snd_soc_dai *codec_dai = fe->codec_dai; |
| 269 | struct snd_soc_codec *codec = fe->codec; |
| 270 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 271 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 272 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 273 | else |
| 274 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 275 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 276 | mutex_lock(&fe->card->dpcm_mutex); |
Haynes Mathew George | 2b4c821 | 2013-07-26 13:38:01 -0700 | [diff] [blame] | 277 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 278 | cpu_dai->playback_active--; |
| 279 | codec_dai->playback_active--; |
| 280 | snd_soc_dai_digital_mute(codec_dai, 1); |
| 281 | } else { |
| 282 | cpu_dai->capture_active--; |
| 283 | codec_dai->capture_active--; |
| 284 | } |
| 285 | |
| 286 | cpu_dai->active--; |
| 287 | codec_dai->active--; |
| 288 | codec->active--; |
| 289 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 290 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 291 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 292 | ret = dpcm_be_dai_hw_free(fe, stream); |
| 293 | if (ret < 0) |
| 294 | dev_err(fe->dev, "compressed hw_free failed %d\n", ret); |
| 295 | |
| 296 | ret = dpcm_be_dai_shutdown(fe, stream); |
| 297 | |
| 298 | /* mark FE's links ready to prune */ |
| 299 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 300 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 301 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 302 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 303 | dpcm_dapm_stream_event(fe, stream, |
| 304 | fe->cpu_dai->driver->playback.stream_name, |
| 305 | SND_SOC_DAPM_STREAM_STOP); |
| 306 | else |
| 307 | dpcm_dapm_stream_event(fe, stream, |
| 308 | fe->cpu_dai->driver->capture.stream_name, |
| 309 | SND_SOC_DAPM_STREAM_STOP); |
| 310 | |
| 311 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 312 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 313 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 314 | dpcm_be_disconnect(fe, stream); |
| 315 | |
| 316 | fe->dpcm[stream].runtime = NULL; |
| 317 | |
| 318 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 319 | fe->dai_link->compr_ops->shutdown(cstream); |
| 320 | |
| 321 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) |
| 322 | platform->driver->compr_ops->free(cstream); |
| 323 | //cpu_dai->runtime = NULL; |
| 324 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 325 | mutex_unlock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 329 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 330 | { |
| 331 | |
| 332 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 333 | struct snd_soc_platform *platform = rtd->platform; |
| 334 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 335 | int ret = 0; |
| 336 | |
Eric Laurent | c0c29a0 | 2013-08-28 14:53:09 -0700 | [diff] [blame] | 337 | /* for partial drain and drain cmd, don't acquire lock while invoking DSP. |
| 338 | * These calls will be blocked till these operation can complete which |
| 339 | * will be a while. And during that time, app can invoke STOP, PAUSE etc |
| 340 | */ |
| 341 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
| 342 | cmd == SND_COMPR_TRIGGER_DRAIN) { |
| 343 | if (platform->driver->compr_ops && |
| 344 | platform->driver->compr_ops->trigger) |
| 345 | return platform->driver->compr_ops->trigger(cstream, cmd); |
| 346 | } |
| 347 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 348 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 349 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 350 | if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { |
| 351 | ret = platform->driver->compr_ops->trigger(cstream, cmd); |
| 352 | if (ret < 0) |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 353 | goto out; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 354 | } |
| 355 | |
Mark Brown | 12a6e63 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 356 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 357 | switch (cmd) { |
| 358 | case SNDRV_PCM_TRIGGER_START: |
| 359 | snd_soc_dai_digital_mute(codec_dai, 0); |
| 360 | break; |
| 361 | case SNDRV_PCM_TRIGGER_STOP: |
| 362 | snd_soc_dai_digital_mute(codec_dai, 1); |
| 363 | break; |
| 364 | } |
| 365 | } |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 366 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 367 | out: |
| 368 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 369 | return ret; |
| 370 | } |
| 371 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 372 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
| 373 | { |
| 374 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 375 | struct snd_soc_platform *platform = fe->platform; |
| 376 | int ret = 0, stream; |
| 377 | |
Eric Laurent | c0c29a0 | 2013-08-28 14:53:09 -0700 | [diff] [blame] | 378 | /* for partial drain and drain cmd, don't acquire lock while invoking DSP. |
| 379 | * These calls will be blocked till these operation can complete which |
| 380 | * will be a while. And during that time, app can invoke STOP, PAUSE etc |
| 381 | */ |
| 382 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
| 383 | cmd == SND_COMPR_TRIGGER_DRAIN) { |
| 384 | if (platform->driver->compr_ops && |
| 385 | platform->driver->compr_ops->trigger) |
| 386 | return platform->driver->compr_ops->trigger(cstream, cmd); |
| 387 | } |
| 388 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 389 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 390 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 391 | else |
| 392 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 393 | |
| 394 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 395 | mutex_lock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 396 | if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { |
| 397 | ret = platform->driver->compr_ops->trigger(cstream, cmd); |
| 398 | if (ret < 0) |
| 399 | goto out; |
| 400 | } |
| 401 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 402 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 403 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 404 | ret = dpcm_be_dai_trigger(fe, stream, cmd); |
| 405 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 406 | switch (cmd) { |
| 407 | case SNDRV_PCM_TRIGGER_START: |
| 408 | case SNDRV_PCM_TRIGGER_RESUME: |
| 409 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 410 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 411 | break; |
| 412 | case SNDRV_PCM_TRIGGER_STOP: |
| 413 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 414 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 415 | break; |
| 416 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 417 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 418 | break; |
| 419 | } |
| 420 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 421 | out: |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 422 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 423 | mutex_unlock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 424 | return ret; |
| 425 | } |
| 426 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 427 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 428 | struct snd_compr_params *params) |
| 429 | { |
| 430 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 431 | struct snd_soc_platform *platform = rtd->platform; |
| 432 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 433 | int ret = 0; |
| 434 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 435 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 436 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 437 | /* first we call set_params for the platform driver |
| 438 | * this should configure the soc side |
| 439 | * if the machine has compressed ops then we call that as well |
| 440 | * expectation is that platform and machine will configure everything |
| 441 | * for this compress path, like configuring pcm port for codec |
| 442 | */ |
| 443 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { |
| 444 | ret = platform->driver->compr_ops->set_params(cstream, params); |
| 445 | if (ret < 0) |
Charles Keepax | 32cfb4f | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 446 | goto err; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { |
| 450 | ret = rtd->dai_link->compr_ops->set_params(cstream); |
| 451 | if (ret < 0) |
Charles Keepax | 32cfb4f | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 452 | goto err; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 453 | } |
| 454 | |
Eric Laurent | f2615f7 | 2013-04-08 15:52:05 -0700 | [diff] [blame] | 455 | snd_soc_dapm_stream_event(rtd, |
| 456 | codec_dai->driver->playback.stream_name, |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 457 | SND_SOC_DAPM_STREAM_START); |
| 458 | |
Charles Keepax | 32cfb4f | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 459 | /* cancel any delayed stream shutdown that is pending */ |
Eric Laurent | 429c06f | 2013-05-17 14:40:59 -0700 | [diff] [blame] | 460 | codec_dai->pop_wait = 0; |
Charles Keepax | 32cfb4f | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 461 | mutex_unlock(&rtd->pcm_mutex); |
| 462 | |
| 463 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 464 | |
| 465 | return ret; |
| 466 | |
| 467 | err: |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 468 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 469 | return ret; |
| 470 | } |
| 471 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 472 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, |
| 473 | struct snd_compr_params *params) |
| 474 | { |
| 475 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
| 476 | struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream; |
| 477 | struct snd_soc_platform *platform = fe->platform; |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 478 | int ret = 0, stream; |
| 479 | |
| 480 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 481 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 482 | else |
| 483 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 484 | |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 485 | mutex_lock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 486 | /* first we call set_params for the platform driver |
| 487 | * this should configure the soc side |
| 488 | * if the machine has compressed ops then we call that as well |
| 489 | * expectation is that platform and machine will configure everything |
| 490 | * for this compress path, like configuring pcm port for codec |
| 491 | */ |
| 492 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { |
| 493 | ret = platform->driver->compr_ops->set_params(cstream, params); |
| 494 | if (ret < 0) |
| 495 | goto out; |
| 496 | } |
| 497 | |
| 498 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { |
| 499 | ret = fe->dai_link->compr_ops->set_params(cstream); |
| 500 | if (ret < 0) |
| 501 | goto out; |
| 502 | } |
| 503 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 504 | memcpy(&fe->dpcm[fe_substream->stream].hw_params, params, |
| 505 | sizeof(struct snd_pcm_hw_params)); |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 506 | |
| 507 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 508 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 509 | ret = dpcm_be_dai_hw_params(fe, stream); |
| 510 | if (ret < 0) |
| 511 | goto out; |
| 512 | |
| 513 | ret = dpcm_be_dai_prepare(fe, stream); |
| 514 | if (ret < 0) |
| 515 | goto out; |
| 516 | |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 517 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 518 | dpcm_dapm_stream_event(fe, stream, |
| 519 | fe->cpu_dai->driver->playback.stream_name, |
| 520 | SND_SOC_DAPM_STREAM_START); |
| 521 | else |
| 522 | dpcm_dapm_stream_event(fe, stream, |
| 523 | fe->cpu_dai->driver->capture.stream_name, |
| 524 | SND_SOC_DAPM_STREAM_START); |
| 525 | |
| 526 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 527 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 528 | out: |
Eric Laurent | db88f28 | 2013-07-15 10:00:45 -0700 | [diff] [blame] | 529 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
Gopikrishnaiah Anandan | ffad0dc | 2014-01-03 14:24:55 -0800 | [diff] [blame] | 530 | mutex_unlock(&fe->card->dpcm_mutex); |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 531 | return ret; |
| 532 | } |
| 533 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 534 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
| 535 | struct snd_codec *params) |
| 536 | { |
| 537 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 538 | struct snd_soc_platform *platform = rtd->platform; |
| 539 | int ret = 0; |
| 540 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 541 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 542 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 543 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_params) |
| 544 | ret = platform->driver->compr_ops->get_params(cstream, params); |
| 545 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 546 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
| 551 | struct snd_compr_caps *caps) |
| 552 | { |
| 553 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 554 | struct snd_soc_platform *platform = rtd->platform; |
| 555 | int ret = 0; |
| 556 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 557 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 558 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 559 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps) |
| 560 | ret = platform->driver->compr_ops->get_caps(cstream, caps); |
| 561 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 562 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
| 567 | struct snd_compr_codec_caps *codec) |
| 568 | { |
| 569 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 570 | struct snd_soc_platform *platform = rtd->platform; |
| 571 | int ret = 0; |
| 572 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 573 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 574 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 575 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) |
| 576 | ret = platform->driver->compr_ops->get_codec_caps(cstream, codec); |
| 577 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 578 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 583 | { |
| 584 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 585 | struct snd_soc_platform *platform = rtd->platform; |
| 586 | int ret = 0; |
| 587 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 588 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 589 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 590 | if (platform->driver->compr_ops && platform->driver->compr_ops->ack) |
| 591 | ret = platform->driver->compr_ops->ack(cstream, bytes); |
| 592 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 593 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 594 | return ret; |
| 595 | } |
| 596 | |
| 597 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
| 598 | struct snd_compr_tstamp *tstamp) |
| 599 | { |
| 600 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 601 | struct snd_soc_platform *platform = rtd->platform; |
| 602 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 603 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 604 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 605 | if (platform->driver->compr_ops && platform->driver->compr_ops->pointer) |
| 606 | platform->driver->compr_ops->pointer(cstream, tstamp); |
| 607 | |
Charles Keepax | ed87d16 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 608 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 612 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 416e1d5 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 613 | char __user *buf, size_t count) |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 614 | { |
| 615 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 616 | struct snd_soc_platform *platform = rtd->platform; |
| 617 | int ret = 0; |
| 618 | |
| 619 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 620 | |
| 621 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) |
| 622 | ret = platform->driver->compr_ops->copy(cstream, buf, count); |
| 623 | |
| 624 | mutex_unlock(&rtd->pcm_mutex); |
| 625 | return ret; |
| 626 | } |
| 627 | |
Jeeja KP | 1a1f143 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 628 | static int sst_compr_set_metadata(struct snd_compr_stream *cstream, |
| 629 | struct snd_compr_metadata *metadata) |
| 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 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_metadata) |
| 636 | ret = platform->driver->compr_ops->set_metadata(cstream, metadata); |
| 637 | |
| 638 | return ret; |
| 639 | } |
| 640 | |
| 641 | static int sst_compr_get_metadata(struct snd_compr_stream *cstream, |
| 642 | struct snd_compr_metadata *metadata) |
| 643 | { |
| 644 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 645 | struct snd_soc_platform *platform = rtd->platform; |
| 646 | int ret = 0; |
| 647 | |
| 648 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_metadata) |
| 649 | ret = platform->driver->compr_ops->get_metadata(cstream, metadata); |
| 650 | |
| 651 | return ret; |
| 652 | } |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 653 | /* ASoC Compress operations */ |
| 654 | static struct snd_compr_ops soc_compr_ops = { |
| 655 | .open = soc_compr_open, |
| 656 | .free = soc_compr_free, |
| 657 | .set_params = soc_compr_set_params, |
Jeeja KP | 1a1f143 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 658 | .set_metadata = sst_compr_set_metadata, |
| 659 | .get_metadata = sst_compr_get_metadata, |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 660 | .get_params = soc_compr_get_params, |
| 661 | .trigger = soc_compr_trigger, |
| 662 | .pointer = soc_compr_pointer, |
| 663 | .ack = soc_compr_ack, |
| 664 | .get_caps = soc_compr_get_caps, |
| 665 | .get_codec_caps = soc_compr_get_codec_caps |
| 666 | }; |
| 667 | |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 668 | /* ASoC Dynamic Compress operations */ |
| 669 | static struct snd_compr_ops soc_compr_dyn_ops = { |
| 670 | .open = soc_compr_open_fe, |
| 671 | .free = soc_compr_free_fe, |
| 672 | .set_params = soc_compr_set_params_fe, |
| 673 | .get_params = soc_compr_get_params, |
Eric Laurent | f932307 | 2013-09-04 08:43:05 -0700 | [diff] [blame] | 674 | .set_metadata = sst_compr_set_metadata, |
| 675 | .get_metadata = sst_compr_get_metadata, |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 676 | .trigger = soc_compr_trigger_fe, |
| 677 | .pointer = soc_compr_pointer, |
| 678 | .ack = soc_compr_ack, |
| 679 | .get_caps = soc_compr_get_caps, |
| 680 | .get_codec_caps = soc_compr_get_codec_caps |
| 681 | }; |
| 682 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 683 | /* create a new compress */ |
| 684 | int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
| 685 | { |
| 686 | struct snd_soc_codec *codec = rtd->codec; |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 687 | struct snd_soc_platform *platform = rtd->platform; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 688 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 689 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 690 | struct snd_compr *compr; |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 691 | struct snd_pcm *be_pcm; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 692 | char new_name[64]; |
| 693 | int ret = 0, direction = 0; |
| 694 | |
| 695 | /* check client and interface hw capabilities */ |
| 696 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 697 | rtd->dai_link->stream_name, codec_dai->name, num); |
| 698 | direction = SND_COMPRESS_PLAYBACK; |
| 699 | compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
| 700 | if (compr == NULL) { |
| 701 | snd_printk(KERN_ERR "Cannot allocate compr\n"); |
| 702 | return -ENOMEM; |
| 703 | } |
| 704 | |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 705 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 706 | GFP_KERNEL); |
| 707 | if (compr->ops == NULL) { |
| 708 | dev_err(rtd->card->dev, "Cannot allocate compressed ops\n"); |
| 709 | ret = -ENOMEM; |
| 710 | goto compr_err; |
| 711 | } |
Liam Girdwood | 660db5a | 2013-05-21 10:25:51 +0100 | [diff] [blame] | 712 | |
| 713 | if (rtd->dai_link->dynamic) { |
| 714 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 715 | rtd->dai_link->stream_name); |
| 716 | |
| 717 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
| 718 | 1, 0, &be_pcm); |
| 719 | if (ret < 0) { |
| 720 | dev_err(rtd->card->dev, "ASoC: can't create compressed for %s\n", |
| 721 | rtd->dai_link->name); |
| 722 | goto compr_err; |
| 723 | } |
| 724 | |
| 725 | rtd->pcm = be_pcm; |
| 726 | rtd->fe_compr = 1; |
| 727 | be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 728 | //be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
| 729 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
| 730 | } else |
| 731 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 732 | |
| 733 | /* Add copy callback for not memory mapped DSPs */ |
| 734 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) |
| 735 | compr->ops->copy = soc_compr_copy; |
| 736 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 737 | mutex_init(&compr->lock); |
| 738 | ret = snd_compress_new(rtd->card->snd_card, num, direction, compr); |
| 739 | if (ret < 0) { |
| 740 | pr_err("compress asoc: can't create compress for codec %s\n", |
| 741 | codec->name); |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 742 | goto compr_err; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 743 | } |
| 744 | |
Charles Keepax | 57f8e79 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 745 | /* DAPM dai link stream work */ |
| 746 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 747 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 748 | rtd->compr = compr; |
| 749 | compr->private_data = rtd; |
| 750 | |
Ravi Kumar Alamanda | eed5804 | 2013-11-25 10:38:40 -0800 | [diff] [blame] | 751 | if (platform->driver->pcm_new) { |
| 752 | ret = platform->driver->pcm_new(rtd); |
| 753 | if (ret < 0) { |
| 754 | pr_err("asoc: compress pcm constructor failed\n"); |
| 755 | goto compr_err; |
| 756 | } |
| 757 | } |
| 758 | |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 759 | printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 760 | cpu_dai->name); |
| 761 | return ret; |
Charles Keepax | 67f29ae | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 762 | |
| 763 | compr_err: |
| 764 | kfree(compr); |
| 765 | return ret; |
Namarta Kohli | 9f052a7 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 766 | } |