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