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