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> |
| 27 | |
| 28 | static int soc_compr_open(struct snd_compr_stream *cstream) |
| 29 | { |
| 30 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 31 | struct snd_soc_platform *platform = rtd->platform; |
| 32 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 33 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 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 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 38 | if (platform->driver->compr_ops && platform->driver->compr_ops->open) { |
| 39 | ret = platform->driver->compr_ops->open(cstream); |
| 40 | if (ret < 0) { |
| 41 | pr_err("compress asoc: can't open platform %s\n", platform->name); |
| 42 | goto out; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { |
| 47 | ret = rtd->dai_link->compr_ops->startup(cstream); |
| 48 | if (ret < 0) { |
| 49 | pr_err("compress asoc: %s startup failed\n", rtd->dai_link->name); |
| 50 | goto machine_err; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 55 | cpu_dai->playback_active++; |
| 56 | codec_dai->playback_active++; |
| 57 | } else { |
| 58 | cpu_dai->capture_active++; |
| 59 | codec_dai->capture_active++; |
| 60 | } |
| 61 | |
| 62 | cpu_dai->active++; |
| 63 | codec_dai->active++; |
| 64 | rtd->codec->active++; |
| 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); |
| 73 | out: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 74 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 75 | return ret; |
| 76 | } |
| 77 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Power down the audio subsystem pmdown_time msecs after close is called. |
| 80 | * This is to ensure there are no pops or clicks in between any music tracks |
| 81 | * due to DAPM power cycling. |
| 82 | */ |
| 83 | static void close_delayed_work(struct work_struct *work) |
| 84 | { |
| 85 | struct snd_soc_pcm_runtime *rtd = |
| 86 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
| 87 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 88 | |
| 89 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 90 | |
| 91 | dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n", |
| 92 | codec_dai->driver->playback.stream_name, |
| 93 | codec_dai->playback_active ? "active" : "inactive", |
| 94 | rtd->pop_wait ? "yes" : "no"); |
| 95 | |
| 96 | /* are we waiting on this codec DAI stream */ |
| 97 | if (rtd->pop_wait == 1) { |
| 98 | rtd->pop_wait = 0; |
| 99 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 100 | SND_SOC_DAPM_STREAM_STOP); |
| 101 | } |
| 102 | |
| 103 | mutex_unlock(&rtd->pcm_mutex); |
| 104 | } |
| 105 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 106 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 107 | { |
| 108 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 109 | struct snd_soc_platform *platform = rtd->platform; |
| 110 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 111 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 112 | struct snd_soc_codec *codec = rtd->codec; |
| 113 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 114 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 115 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 116 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 117 | cpu_dai->playback_active--; |
| 118 | codec_dai->playback_active--; |
| 119 | } else { |
| 120 | cpu_dai->capture_active--; |
| 121 | codec_dai->capture_active--; |
| 122 | } |
| 123 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 124 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 125 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 126 | cpu_dai->active--; |
| 127 | codec_dai->active--; |
| 128 | codec->active--; |
| 129 | |
| 130 | if (!cpu_dai->active) |
| 131 | cpu_dai->rate = 0; |
| 132 | |
| 133 | if (!codec_dai->active) |
| 134 | codec_dai->rate = 0; |
| 135 | |
| 136 | |
| 137 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) |
| 138 | rtd->dai_link->compr_ops->shutdown(cstream); |
| 139 | |
| 140 | if (platform->driver->compr_ops && platform->driver->compr_ops->free) |
| 141 | platform->driver->compr_ops->free(cstream); |
Vinod Koul | 9d2667a | 2012-08-21 12:15:02 +0530 | [diff] [blame] | 142 | cpu_dai->runtime = NULL; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 143 | |
| 144 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
| 145 | if (!rtd->pmdown_time || codec->ignore_pmdown_time || |
| 146 | rtd->dai_link->ignore_pmdown_time) { |
| 147 | snd_soc_dapm_stream_event(rtd, |
| 148 | SNDRV_PCM_STREAM_PLAYBACK, |
| 149 | SND_SOC_DAPM_STREAM_STOP); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 150 | } else { |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 151 | rtd->pop_wait = 1; |
Mark Brown | 3d24cfe | 2013-08-09 18:12:29 +0100 | [diff] [blame] | 152 | queue_delayed_work(system_power_efficient_wq, |
| 153 | &rtd->delayed_work, |
| 154 | msecs_to_jiffies(rtd->pmdown_time)); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 155 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 156 | } else { |
| 157 | /* capture streams can be powered down now */ |
| 158 | snd_soc_dapm_stream_event(rtd, |
| 159 | SNDRV_PCM_STREAM_CAPTURE, |
| 160 | SND_SOC_DAPM_STREAM_STOP); |
| 161 | } |
| 162 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 163 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 168 | { |
| 169 | |
| 170 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 171 | struct snd_soc_platform *platform = rtd->platform; |
| 172 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 173 | int ret = 0; |
| 174 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 175 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 176 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 177 | if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { |
| 178 | ret = platform->driver->compr_ops->trigger(cstream, cmd); |
| 179 | if (ret < 0) |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 180 | goto out; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 181 | } |
| 182 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 183 | switch (cmd) { |
| 184 | case SNDRV_PCM_TRIGGER_START: |
| 185 | snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); |
| 186 | break; |
| 187 | case SNDRV_PCM_TRIGGER_STOP: |
| 188 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 189 | break; |
Mark Brown | e38b9b7 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 190 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 191 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 192 | out: |
| 193 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 198 | struct snd_compr_params *params) |
| 199 | { |
| 200 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 201 | struct snd_soc_platform *platform = rtd->platform; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 202 | int ret = 0; |
| 203 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 204 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 205 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 206 | /* first we call set_params for the platform driver |
| 207 | * this should configure the soc side |
| 208 | * if the machine has compressed ops then we call that as well |
| 209 | * expectation is that platform and machine will configure everything |
| 210 | * for this compress path, like configuring pcm port for codec |
| 211 | */ |
| 212 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { |
| 213 | ret = platform->driver->compr_ops->set_params(cstream, params); |
| 214 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 215 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { |
| 219 | ret = rtd->dai_link->compr_ops->set_params(cstream); |
| 220 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 221 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 222 | } |
| 223 | |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 224 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 225 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 226 | SND_SOC_DAPM_STREAM_START); |
| 227 | else |
| 228 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
| 229 | SND_SOC_DAPM_STREAM_START); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 230 | |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 231 | /* cancel any delayed stream shutdown that is pending */ |
| 232 | rtd->pop_wait = 0; |
| 233 | mutex_unlock(&rtd->pcm_mutex); |
| 234 | |
| 235 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 236 | |
| 237 | return ret; |
| 238 | |
| 239 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 240 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
| 245 | struct snd_codec *params) |
| 246 | { |
| 247 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 248 | struct snd_soc_platform *platform = rtd->platform; |
| 249 | int ret = 0; |
| 250 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 251 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 252 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 253 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_params) |
| 254 | ret = platform->driver->compr_ops->get_params(cstream, params); |
| 255 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 256 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
| 261 | struct snd_compr_caps *caps) |
| 262 | { |
| 263 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 264 | struct snd_soc_platform *platform = rtd->platform; |
| 265 | int ret = 0; |
| 266 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 267 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 268 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 269 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps) |
| 270 | ret = platform->driver->compr_ops->get_caps(cstream, caps); |
| 271 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 272 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
| 277 | struct snd_compr_codec_caps *codec) |
| 278 | { |
| 279 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 280 | struct snd_soc_platform *platform = rtd->platform; |
| 281 | int ret = 0; |
| 282 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 283 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 284 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 285 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) |
| 286 | ret = platform->driver->compr_ops->get_codec_caps(cstream, codec); |
| 287 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 288 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 293 | { |
| 294 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 295 | struct snd_soc_platform *platform = rtd->platform; |
| 296 | int ret = 0; |
| 297 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 298 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 299 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 300 | if (platform->driver->compr_ops && platform->driver->compr_ops->ack) |
| 301 | ret = platform->driver->compr_ops->ack(cstream, bytes); |
| 302 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 303 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
| 308 | struct snd_compr_tstamp *tstamp) |
| 309 | { |
| 310 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 311 | struct snd_soc_platform *platform = rtd->platform; |
| 312 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 313 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 314 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 315 | if (platform->driver->compr_ops && platform->driver->compr_ops->pointer) |
| 316 | platform->driver->compr_ops->pointer(cstream, tstamp); |
| 317 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 318 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 322 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 4daf891 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 323 | char __user *buf, size_t count) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 324 | { |
| 325 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 326 | struct snd_soc_platform *platform = rtd->platform; |
| 327 | int ret = 0; |
| 328 | |
| 329 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 330 | |
| 331 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) |
| 332 | ret = platform->driver->compr_ops->copy(cstream, buf, count); |
| 333 | |
| 334 | mutex_unlock(&rtd->pcm_mutex); |
| 335 | return ret; |
| 336 | } |
| 337 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 338 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 339 | struct snd_compr_metadata *metadata) |
| 340 | { |
| 341 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 342 | struct snd_soc_platform *platform = rtd->platform; |
| 343 | int ret = 0; |
| 344 | |
| 345 | if (platform->driver->compr_ops && platform->driver->compr_ops->set_metadata) |
| 346 | ret = platform->driver->compr_ops->set_metadata(cstream, metadata); |
| 347 | |
| 348 | return ret; |
| 349 | } |
| 350 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 351 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 352 | struct snd_compr_metadata *metadata) |
| 353 | { |
| 354 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 355 | struct snd_soc_platform *platform = rtd->platform; |
| 356 | int ret = 0; |
| 357 | |
| 358 | if (platform->driver->compr_ops && platform->driver->compr_ops->get_metadata) |
| 359 | ret = platform->driver->compr_ops->get_metadata(cstream, metadata); |
| 360 | |
| 361 | return ret; |
| 362 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 363 | /* ASoC Compress operations */ |
| 364 | static struct snd_compr_ops soc_compr_ops = { |
| 365 | .open = soc_compr_open, |
| 366 | .free = soc_compr_free, |
| 367 | .set_params = soc_compr_set_params, |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 368 | .set_metadata = soc_compr_set_metadata, |
| 369 | .get_metadata = soc_compr_get_metadata, |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 370 | .get_params = soc_compr_get_params, |
| 371 | .trigger = soc_compr_trigger, |
| 372 | .pointer = soc_compr_pointer, |
| 373 | .ack = soc_compr_ack, |
| 374 | .get_caps = soc_compr_get_caps, |
| 375 | .get_codec_caps = soc_compr_get_codec_caps |
| 376 | }; |
| 377 | |
| 378 | /* create a new compress */ |
| 379 | int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
| 380 | { |
| 381 | struct snd_soc_codec *codec = rtd->codec; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 382 | struct snd_soc_platform *platform = rtd->platform; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 383 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 384 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 385 | struct snd_compr *compr; |
| 386 | char new_name[64]; |
| 387 | int ret = 0, direction = 0; |
| 388 | |
| 389 | /* check client and interface hw capabilities */ |
| 390 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 391 | rtd->dai_link->stream_name, codec_dai->name, num); |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 392 | |
| 393 | if (codec_dai->driver->playback.channels_min) |
| 394 | direction = SND_COMPRESS_PLAYBACK; |
| 395 | else if (codec_dai->driver->capture.channels_min) |
| 396 | direction = SND_COMPRESS_CAPTURE; |
| 397 | else |
| 398 | return -EINVAL; |
| 399 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 400 | compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
| 401 | if (compr == NULL) { |
| 402 | snd_printk(KERN_ERR "Cannot allocate compr\n"); |
| 403 | return -ENOMEM; |
| 404 | } |
| 405 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 406 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 407 | GFP_KERNEL); |
| 408 | if (compr->ops == NULL) { |
| 409 | dev_err(rtd->card->dev, "Cannot allocate compressed ops\n"); |
| 410 | ret = -ENOMEM; |
| 411 | goto compr_err; |
| 412 | } |
| 413 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
| 414 | |
| 415 | /* Add copy callback for not memory mapped DSPs */ |
| 416 | if (platform->driver->compr_ops && platform->driver->compr_ops->copy) |
| 417 | compr->ops->copy = soc_compr_copy; |
| 418 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 419 | mutex_init(&compr->lock); |
| 420 | ret = snd_compress_new(rtd->card->snd_card, num, direction, compr); |
| 421 | if (ret < 0) { |
| 422 | pr_err("compress asoc: can't create compress for codec %s\n", |
| 423 | codec->name); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 424 | goto compr_err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 425 | } |
| 426 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 427 | /* DAPM dai link stream work */ |
| 428 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 429 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 430 | rtd->compr = compr; |
| 431 | compr->private_data = rtd; |
| 432 | |
| 433 | printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 434 | cpu_dai->name); |
| 435 | return ret; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 436 | |
| 437 | compr_err: |
| 438 | kfree(compr); |
| 439 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 440 | } |