Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 1 | /* |
| 2 | * sst_platform.c - Intel MID Platform driver |
| 3 | * |
| 4 | * Copyright (C) 2010 Intel Corp |
| 5 | * Author: Vinod Koul <vinod.koul@intel.com> |
| 6 | * Author: Harsha Priya <priya.harsha@intel.com> |
| 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 21 | * |
| 22 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 23 | * |
| 24 | * |
| 25 | */ |
| 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/io.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 31 | #include <sound/core.h> |
| 32 | #include <sound/pcm.h> |
| 33 | #include <sound/pcm_params.h> |
| 34 | #include <sound/soc.h> |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 35 | #include "sst_platform.h" |
| 36 | |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 37 | static struct sst_device *sst; |
| 38 | static DEFINE_MUTEX(sst_lock); |
| 39 | |
| 40 | int sst_register_dsp(struct sst_device *dev) |
| 41 | { |
| 42 | BUG_ON(!dev); |
| 43 | if (!try_module_get(dev->dev->driver->owner)) |
| 44 | return -ENODEV; |
| 45 | mutex_lock(&sst_lock); |
| 46 | if (sst) { |
| 47 | pr_err("we already have a device %s\n", sst->name); |
| 48 | module_put(dev->dev->driver->owner); |
| 49 | mutex_unlock(&sst_lock); |
| 50 | return -EEXIST; |
| 51 | } |
| 52 | pr_debug("registering device %s\n", dev->name); |
| 53 | sst = dev; |
| 54 | mutex_unlock(&sst_lock); |
| 55 | return 0; |
| 56 | } |
| 57 | EXPORT_SYMBOL_GPL(sst_register_dsp); |
| 58 | |
| 59 | int sst_unregister_dsp(struct sst_device *dev) |
| 60 | { |
| 61 | BUG_ON(!dev); |
| 62 | if (dev != sst) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | mutex_lock(&sst_lock); |
| 66 | |
| 67 | if (!sst) { |
| 68 | mutex_unlock(&sst_lock); |
| 69 | return -EIO; |
| 70 | } |
| 71 | |
| 72 | module_put(sst->dev->driver->owner); |
| 73 | pr_debug("unreg %s\n", sst->name); |
| 74 | sst = NULL; |
| 75 | mutex_unlock(&sst_lock); |
| 76 | return 0; |
| 77 | } |
| 78 | EXPORT_SYMBOL_GPL(sst_unregister_dsp); |
| 79 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 80 | static struct snd_pcm_hardware sst_platform_pcm_hw = { |
| 81 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 82 | SNDRV_PCM_INFO_DOUBLE | |
| 83 | SNDRV_PCM_INFO_PAUSE | |
| 84 | SNDRV_PCM_INFO_RESUME | |
| 85 | SNDRV_PCM_INFO_MMAP| |
| 86 | SNDRV_PCM_INFO_MMAP_VALID | |
| 87 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 88 | SNDRV_PCM_INFO_SYNC_START), |
| 89 | .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 | |
| 90 | SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 | |
| 91 | SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32), |
| 92 | .rates = (SNDRV_PCM_RATE_8000| |
| 93 | SNDRV_PCM_RATE_44100 | |
| 94 | SNDRV_PCM_RATE_48000), |
| 95 | .rate_min = SST_MIN_RATE, |
| 96 | .rate_max = SST_MAX_RATE, |
| 97 | .channels_min = SST_MIN_CHANNEL, |
| 98 | .channels_max = SST_MAX_CHANNEL, |
| 99 | .buffer_bytes_max = SST_MAX_BUFFER, |
| 100 | .period_bytes_min = SST_MIN_PERIOD_BYTES, |
| 101 | .period_bytes_max = SST_MAX_PERIOD_BYTES, |
| 102 | .periods_min = SST_MIN_PERIODS, |
| 103 | .periods_max = SST_MAX_PERIODS, |
| 104 | .fifo_size = SST_FIFO_SIZE, |
| 105 | }; |
| 106 | |
| 107 | /* MFLD - MSIC */ |
Axel Lin | d1b7328 | 2011-09-27 10:38:50 +0800 | [diff] [blame] | 108 | static struct snd_soc_dai_driver sst_platform_dai[] = { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 109 | { |
| 110 | .name = "Headset-cpu-dai", |
| 111 | .id = 0, |
| 112 | .playback = { |
| 113 | .channels_min = SST_STEREO, |
| 114 | .channels_max = SST_STEREO, |
| 115 | .rates = SNDRV_PCM_RATE_48000, |
| 116 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 117 | }, |
Harsha Priya | a7bffdf | 2011-01-28 22:27:26 +0530 | [diff] [blame] | 118 | .capture = { |
| 119 | .channels_min = 1, |
| 120 | .channels_max = 5, |
| 121 | .rates = SNDRV_PCM_RATE_48000, |
| 122 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 123 | }, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 124 | }, |
| 125 | { |
| 126 | .name = "Speaker-cpu-dai", |
| 127 | .id = 1, |
| 128 | .playback = { |
| 129 | .channels_min = SST_MONO, |
| 130 | .channels_max = SST_STEREO, |
| 131 | .rates = SNDRV_PCM_RATE_48000, |
| 132 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 133 | }, |
| 134 | }, |
| 135 | { |
| 136 | .name = "Vibra1-cpu-dai", |
| 137 | .id = 2, |
| 138 | .playback = { |
| 139 | .channels_min = SST_MONO, |
| 140 | .channels_max = SST_MONO, |
| 141 | .rates = SNDRV_PCM_RATE_48000, |
| 142 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 143 | }, |
| 144 | }, |
| 145 | { |
| 146 | .name = "Vibra2-cpu-dai", |
| 147 | .id = 3, |
| 148 | .playback = { |
| 149 | .channels_min = SST_MONO, |
| 150 | .channels_max = SST_STEREO, |
| 151 | .rates = SNDRV_PCM_RATE_48000, |
| 152 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 153 | }, |
| 154 | }, |
| 155 | }; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 156 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 157 | /* helper functions */ |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 158 | static inline void sst_set_stream_status(struct sst_runtime_stream *stream, |
| 159 | int state) |
| 160 | { |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 161 | unsigned long flags; |
| 162 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 163 | stream->stream_status = state; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 164 | spin_unlock_irqrestore(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static inline int sst_get_stream_status(struct sst_runtime_stream *stream) |
| 168 | { |
| 169 | int state; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 170 | unsigned long flags; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 171 | |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 172 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 173 | state = stream->stream_status; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 174 | spin_unlock_irqrestore(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 175 | return state; |
| 176 | } |
| 177 | |
| 178 | static void sst_fill_pcm_params(struct snd_pcm_substream *substream, |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 179 | struct sst_pcm_params *param) |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 180 | { |
| 181 | |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 182 | param->codec = SST_CODEC_TYPE_PCM; |
| 183 | param->num_chan = (u8) substream->runtime->channels; |
| 184 | param->pcm_wd_sz = substream->runtime->sample_bits; |
| 185 | param->reserved = 0; |
| 186 | param->sfreq = substream->runtime->rate; |
| 187 | param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream); |
| 188 | param->period_count = substream->runtime->period_size; |
| 189 | param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area); |
| 190 | pr_debug("period_cnt = %d\n", param->period_count); |
| 191 | pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 192 | } |
| 193 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 194 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) |
| 195 | { |
| 196 | struct sst_runtime_stream *stream = |
| 197 | substream->runtime->private_data; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 198 | struct sst_pcm_params param = {0}; |
| 199 | struct sst_stream_params str_params = {0}; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 200 | int ret_val; |
| 201 | |
| 202 | /* set codec params and inform SST driver the same */ |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 203 | sst_fill_pcm_params(substream, ¶m); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 204 | substream->runtime->dma_area = substream->dma_buffer.area; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 205 | str_params.sparams = param; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 206 | str_params.codec = param.codec; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 207 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 208 | str_params.ops = STREAM_OPS_PLAYBACK; |
| 209 | str_params.device_type = substream->pcm->device + 1; |
| 210 | pr_debug("Playbck stream,Device %d\n", |
| 211 | substream->pcm->device); |
| 212 | } else { |
| 213 | str_params.ops = STREAM_OPS_CAPTURE; |
| 214 | str_params.device_type = SND_SST_DEVICE_CAPTURE; |
| 215 | pr_debug("Capture stream,Device %d\n", |
| 216 | substream->pcm->device); |
| 217 | } |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 218 | ret_val = stream->ops->open(&str_params); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 219 | pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val); |
| 220 | if (ret_val < 0) |
| 221 | return ret_val; |
| 222 | |
| 223 | stream->stream_info.str_id = ret_val; |
| 224 | pr_debug("str id : %d\n", stream->stream_info.str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 225 | return ret_val; |
| 226 | } |
| 227 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 228 | static void sst_period_elapsed(void *mad_substream) |
| 229 | { |
| 230 | struct snd_pcm_substream *substream = mad_substream; |
| 231 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 232 | int status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 233 | |
| 234 | if (!substream || !substream->runtime) |
| 235 | return; |
| 236 | stream = substream->runtime->private_data; |
| 237 | if (!stream) |
| 238 | return; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 239 | status = sst_get_stream_status(stream); |
| 240 | if (status != SST_PLATFORM_RUNNING) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 241 | return; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 242 | snd_pcm_period_elapsed(substream); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static int sst_platform_init_stream(struct snd_pcm_substream *substream) |
| 246 | { |
| 247 | struct sst_runtime_stream *stream = |
| 248 | substream->runtime->private_data; |
| 249 | int ret_val; |
| 250 | |
| 251 | pr_debug("setting buffer ptr param\n"); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 252 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 253 | stream->stream_info.period_elapsed = sst_period_elapsed; |
| 254 | stream->stream_info.mad_substream = substream; |
| 255 | stream->stream_info.buffer_ptr = 0; |
| 256 | stream->stream_info.sfreq = substream->runtime->rate; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 257 | ret_val = stream->ops->device_control( |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 258 | SST_SND_STREAM_INIT, &stream->stream_info); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 259 | if (ret_val) |
| 260 | pr_err("control_set ret error %d\n", ret_val); |
| 261 | return ret_val; |
| 262 | |
| 263 | } |
| 264 | /* end -- helper functions */ |
| 265 | |
| 266 | static int sst_platform_open(struct snd_pcm_substream *substream) |
| 267 | { |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 268 | struct snd_pcm_runtime *runtime = substream->runtime; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 269 | struct sst_runtime_stream *stream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 270 | |
| 271 | pr_debug("sst_platform_open called\n"); |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 272 | |
| 273 | snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw); |
Lu Guanqun | 283e42e | 2011-09-06 15:21:43 +0800 | [diff] [blame] | 274 | ret_val = snd_pcm_hw_constraint_integer(runtime, |
| 275 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 276 | if (ret_val < 0) |
| 277 | return ret_val; |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 278 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 279 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
| 280 | if (!stream) |
| 281 | return -ENOMEM; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 282 | spin_lock_init(&stream->status_lock); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 283 | |
| 284 | /* get the sst ops */ |
| 285 | mutex_lock(&sst_lock); |
| 286 | if (!sst) { |
| 287 | pr_err("no device available to run\n"); |
| 288 | mutex_unlock(&sst_lock); |
| 289 | kfree(stream); |
| 290 | return -ENODEV; |
| 291 | } |
| 292 | if (!try_module_get(sst->dev->driver->owner)) { |
| 293 | mutex_unlock(&sst_lock); |
| 294 | kfree(stream); |
| 295 | return -ENODEV; |
| 296 | } |
| 297 | stream->ops = sst->ops; |
| 298 | mutex_unlock(&sst_lock); |
| 299 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 300 | stream->stream_info.str_id = 0; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 301 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 302 | stream->stream_info.mad_substream = substream; |
| 303 | /* allocate memory for SST API set */ |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 304 | runtime->private_data = stream; |
Lu Guanqun | 283e42e | 2011-09-06 15:21:43 +0800 | [diff] [blame] | 305 | |
| 306 | return 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static int sst_platform_close(struct snd_pcm_substream *substream) |
| 310 | { |
| 311 | struct sst_runtime_stream *stream; |
| 312 | int ret_val = 0, str_id; |
| 313 | |
| 314 | pr_debug("sst_platform_close called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 315 | stream = substream->runtime->private_data; |
| 316 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 317 | if (str_id) |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 318 | ret_val = stream->ops->close(str_id); |
| 319 | module_put(sst->dev->driver->owner); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 320 | kfree(stream); |
| 321 | return ret_val; |
| 322 | } |
| 323 | |
| 324 | static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream) |
| 325 | { |
| 326 | struct sst_runtime_stream *stream; |
| 327 | int ret_val = 0, str_id; |
| 328 | |
| 329 | pr_debug("sst_platform_pcm_prepare called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 330 | stream = substream->runtime->private_data; |
| 331 | str_id = stream->stream_info.str_id; |
| 332 | if (stream->stream_info.str_id) { |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 333 | ret_val = stream->ops->device_control( |
| 334 | SST_SND_DROP, &str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 335 | return ret_val; |
| 336 | } |
| 337 | |
| 338 | ret_val = sst_platform_alloc_stream(substream); |
| 339 | if (ret_val < 0) |
| 340 | return ret_val; |
| 341 | snprintf(substream->pcm->id, sizeof(substream->pcm->id), |
| 342 | "%d", stream->stream_info.str_id); |
| 343 | |
| 344 | ret_val = sst_platform_init_stream(substream); |
| 345 | if (ret_val) |
| 346 | return ret_val; |
| 347 | substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER; |
| 348 | return ret_val; |
| 349 | } |
| 350 | |
| 351 | static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, |
| 352 | int cmd) |
| 353 | { |
| 354 | int ret_val = 0, str_id; |
| 355 | struct sst_runtime_stream *stream; |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 356 | int str_cmd, status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 357 | |
| 358 | pr_debug("sst_platform_pcm_trigger called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 359 | stream = substream->runtime->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 360 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 361 | switch (cmd) { |
| 362 | case SNDRV_PCM_TRIGGER_START: |
| 363 | pr_debug("sst: Trigger Start\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 364 | str_cmd = SST_SND_START; |
| 365 | status = SST_PLATFORM_RUNNING; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 366 | stream->stream_info.mad_substream = substream; |
| 367 | break; |
| 368 | case SNDRV_PCM_TRIGGER_STOP: |
| 369 | pr_debug("sst: in stop\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 370 | str_cmd = SST_SND_DROP; |
| 371 | status = SST_PLATFORM_DROPPED; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 372 | break; |
| 373 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 374 | pr_debug("sst: in pause\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 375 | str_cmd = SST_SND_PAUSE; |
| 376 | status = SST_PLATFORM_PAUSED; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 377 | break; |
| 378 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 379 | pr_debug("sst: in pause release\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 380 | str_cmd = SST_SND_RESUME; |
| 381 | status = SST_PLATFORM_RUNNING; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 382 | break; |
| 383 | default: |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 384 | return -EINVAL; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 385 | } |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 386 | ret_val = stream->ops->device_control(str_cmd, &str_id); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 387 | if (!ret_val) |
| 388 | sst_set_stream_status(stream, status); |
| 389 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 390 | return ret_val; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | static snd_pcm_uframes_t sst_platform_pcm_pointer |
| 395 | (struct snd_pcm_substream *substream) |
| 396 | { |
| 397 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 398 | int ret_val, status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 399 | struct pcm_stream_info *str_info; |
| 400 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 401 | stream = substream->runtime->private_data; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 402 | status = sst_get_stream_status(stream); |
| 403 | if (status == SST_PLATFORM_INIT) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 404 | return 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 405 | str_info = &stream->stream_info; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 406 | ret_val = stream->ops->device_control( |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 407 | SST_SND_BUFFER_POINTER, str_info); |
| 408 | if (ret_val) { |
| 409 | pr_err("sst: error code = %d\n", ret_val); |
| 410 | return ret_val; |
| 411 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 412 | return stream->stream_info.buffer_ptr; |
| 413 | } |
| 414 | |
Vinod Koul | 5b499f8 | 2011-02-15 18:28:54 +0530 | [diff] [blame] | 415 | static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream, |
| 416 | struct snd_pcm_hw_params *params) |
| 417 | { |
| 418 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 419 | memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); |
| 420 | |
| 421 | return 0; |
| 422 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 423 | |
xingchao | 9ab8843 | 2011-04-27 16:58:54 -0400 | [diff] [blame] | 424 | static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream) |
| 425 | { |
| 426 | return snd_pcm_lib_free_pages(substream); |
| 427 | } |
| 428 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 429 | static struct snd_pcm_ops sst_platform_ops = { |
| 430 | .open = sst_platform_open, |
| 431 | .close = sst_platform_close, |
| 432 | .ioctl = snd_pcm_lib_ioctl, |
| 433 | .prepare = sst_platform_pcm_prepare, |
| 434 | .trigger = sst_platform_pcm_trigger, |
| 435 | .pointer = sst_platform_pcm_pointer, |
Vinod Koul | 5b499f8 | 2011-02-15 18:28:54 +0530 | [diff] [blame] | 436 | .hw_params = sst_platform_pcm_hw_params, |
xingchao | 9ab8843 | 2011-04-27 16:58:54 -0400 | [diff] [blame] | 437 | .hw_free = sst_platform_pcm_hw_free, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | static void sst_pcm_free(struct snd_pcm *pcm) |
| 441 | { |
| 442 | pr_debug("sst_pcm_free called\n"); |
| 443 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 444 | } |
| 445 | |
Axel Lin | 8faa8c1 | 2011-12-13 17:13:45 +0800 | [diff] [blame^] | 446 | static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 447 | { |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 448 | struct snd_soc_dai *dai = rtd->cpu_dai; |
| 449 | struct snd_pcm *pcm = rtd->pcm; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 450 | int retval = 0; |
| 451 | |
| 452 | pr_debug("sst_pcm_new called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 453 | if (dai->driver->playback.channels_min || |
| 454 | dai->driver->capture.channels_min) { |
| 455 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 456 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 457 | snd_dma_continuous_data(GFP_KERNEL), |
| 458 | SST_MIN_BUFFER, SST_MAX_BUFFER); |
| 459 | if (retval) { |
| 460 | pr_err("dma buffer allocationf fail\n"); |
| 461 | return retval; |
| 462 | } |
| 463 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 464 | return retval; |
| 465 | } |
Axel Lin | 8faa8c1 | 2011-12-13 17:13:45 +0800 | [diff] [blame^] | 466 | static struct snd_soc_platform_driver sst_soc_platform_drv = { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 467 | .ops = &sst_platform_ops, |
| 468 | .pcm_new = sst_pcm_new, |
| 469 | .pcm_free = sst_pcm_free, |
| 470 | }; |
| 471 | |
| 472 | static int sst_platform_probe(struct platform_device *pdev) |
| 473 | { |
| 474 | int ret; |
| 475 | |
| 476 | pr_debug("sst_platform_probe called\n"); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 477 | sst = NULL; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 478 | ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv); |
| 479 | if (ret) { |
| 480 | pr_err("registering soc platform failed\n"); |
| 481 | return ret; |
| 482 | } |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 483 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 484 | ret = snd_soc_register_dais(&pdev->dev, |
| 485 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); |
| 486 | if (ret) { |
| 487 | pr_err("registering cpu dais failed\n"); |
| 488 | snd_soc_unregister_platform(&pdev->dev); |
| 489 | } |
| 490 | return ret; |
| 491 | } |
| 492 | |
| 493 | static int sst_platform_remove(struct platform_device *pdev) |
| 494 | { |
| 495 | |
| 496 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sst_platform_dai)); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 497 | snd_soc_unregister_platform(&pdev->dev); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 498 | pr_debug("sst_platform_remove success\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | static struct platform_driver sst_platform_driver = { |
| 503 | .driver = { |
| 504 | .name = "sst-platform", |
| 505 | .owner = THIS_MODULE, |
| 506 | }, |
| 507 | .probe = sst_platform_probe, |
| 508 | .remove = sst_platform_remove, |
| 509 | }; |
| 510 | |
Axel Lin | 29515d6 | 2011-11-24 11:51:56 +0800 | [diff] [blame] | 511 | module_platform_driver(sst_platform_driver); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 512 | |
| 513 | MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver"); |
| 514 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); |
| 515 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); |
| 516 | MODULE_LICENSE("GPL v2"); |
Vinod Koul | f5c6b2a | 2011-01-07 16:20:56 +0530 | [diff] [blame] | 517 | MODULE_ALIAS("platform:sst-platform"); |