Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 1 | /* |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 2 | * sst_mfld_platform.c - Intel MID Platform driver |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 3 | * |
Vinod Koul | 0cd5751 | 2013-03-29 23:41:42 +0530 | [diff] [blame] | 4 | * Copyright (C) 2010-2013 Intel Corp |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 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 | * |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 19 | */ |
| 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/io.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | #include <sound/soc.h> |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 29 | #include <sound/compress_driver.h> |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 30 | #include "sst-mfld-platform.h" |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 31 | |
Vinod Koul | 4b68b4e | 2014-05-05 14:27:50 +0530 | [diff] [blame] | 32 | struct sst_device *sst; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 33 | static DEFINE_MUTEX(sst_lock); |
Vinod Koul | 4b68b4e | 2014-05-05 14:27:50 +0530 | [diff] [blame] | 34 | extern struct snd_compr_ops sst_platform_compr_ops; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 35 | |
| 36 | int sst_register_dsp(struct sst_device *dev) |
| 37 | { |
Takashi Iwai | 656a22a | 2013-11-05 18:40:01 +0100 | [diff] [blame] | 38 | if (WARN_ON(!dev)) |
| 39 | return -EINVAL; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 40 | if (!try_module_get(dev->dev->driver->owner)) |
| 41 | return -ENODEV; |
| 42 | mutex_lock(&sst_lock); |
| 43 | if (sst) { |
| 44 | pr_err("we already have a device %s\n", sst->name); |
| 45 | module_put(dev->dev->driver->owner); |
| 46 | mutex_unlock(&sst_lock); |
| 47 | return -EEXIST; |
| 48 | } |
| 49 | pr_debug("registering device %s\n", dev->name); |
| 50 | sst = dev; |
| 51 | mutex_unlock(&sst_lock); |
| 52 | return 0; |
| 53 | } |
| 54 | EXPORT_SYMBOL_GPL(sst_register_dsp); |
| 55 | |
| 56 | int sst_unregister_dsp(struct sst_device *dev) |
| 57 | { |
Takashi Iwai | 656a22a | 2013-11-05 18:40:01 +0100 | [diff] [blame] | 58 | if (WARN_ON(!dev)) |
| 59 | return -EINVAL; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 60 | if (dev != sst) |
| 61 | return -EINVAL; |
| 62 | |
| 63 | mutex_lock(&sst_lock); |
| 64 | |
| 65 | if (!sst) { |
| 66 | mutex_unlock(&sst_lock); |
| 67 | return -EIO; |
| 68 | } |
| 69 | |
| 70 | module_put(sst->dev->driver->owner); |
| 71 | pr_debug("unreg %s\n", sst->name); |
| 72 | sst = NULL; |
| 73 | mutex_unlock(&sst_lock); |
| 74 | return 0; |
| 75 | } |
| 76 | EXPORT_SYMBOL_GPL(sst_unregister_dsp); |
| 77 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 78 | static struct snd_pcm_hardware sst_platform_pcm_hw = { |
| 79 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 80 | SNDRV_PCM_INFO_DOUBLE | |
| 81 | SNDRV_PCM_INFO_PAUSE | |
| 82 | SNDRV_PCM_INFO_RESUME | |
| 83 | SNDRV_PCM_INFO_MMAP| |
| 84 | SNDRV_PCM_INFO_MMAP_VALID | |
| 85 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 86 | SNDRV_PCM_INFO_SYNC_START), |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 87 | .buffer_bytes_max = SST_MAX_BUFFER, |
| 88 | .period_bytes_min = SST_MIN_PERIOD_BYTES, |
| 89 | .period_bytes_max = SST_MAX_PERIOD_BYTES, |
| 90 | .periods_min = SST_MIN_PERIODS, |
| 91 | .periods_max = SST_MAX_PERIODS, |
| 92 | .fifo_size = SST_FIFO_SIZE, |
| 93 | }; |
| 94 | |
| 95 | /* MFLD - MSIC */ |
Axel Lin | d1b7328 | 2011-09-27 10:38:50 +0800 | [diff] [blame] | 96 | static struct snd_soc_dai_driver sst_platform_dai[] = { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 97 | { |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 98 | .name = "Headset-cpu-dai", |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 99 | .id = 0, |
| 100 | .playback = { |
| 101 | .channels_min = SST_STEREO, |
| 102 | .channels_max = SST_STEREO, |
| 103 | .rates = SNDRV_PCM_RATE_48000, |
| 104 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 105 | }, |
Harsha Priya | a7bffdf | 2011-01-28 22:27:26 +0530 | [diff] [blame] | 106 | .capture = { |
| 107 | .channels_min = 1, |
| 108 | .channels_max = 5, |
| 109 | .rates = SNDRV_PCM_RATE_48000, |
| 110 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 111 | }, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 112 | }, |
| 113 | { |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 114 | .name = "Compress-cpu-dai", |
| 115 | .compress_dai = 1, |
| 116 | .playback = { |
| 117 | .channels_min = SST_STEREO, |
| 118 | .channels_max = SST_STEREO, |
| 119 | .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000, |
| 120 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 121 | }, |
| 122 | }, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 123 | }; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 124 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 125 | /* helper functions */ |
Vinod Koul | 4496ffa | 2014-05-05 14:27:49 +0530 | [diff] [blame] | 126 | void sst_set_stream_status(struct sst_runtime_stream *stream, |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 127 | int state) |
| 128 | { |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 129 | unsigned long flags; |
| 130 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 131 | stream->stream_status = state; |
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 | } |
| 134 | |
| 135 | static inline int sst_get_stream_status(struct sst_runtime_stream *stream) |
| 136 | { |
| 137 | int state; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 138 | unsigned long flags; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 139 | |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 140 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 141 | state = stream->stream_status; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 142 | spin_unlock_irqrestore(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 143 | return state; |
| 144 | } |
| 145 | |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 146 | static void sst_fill_alloc_params(struct snd_pcm_substream *substream, |
| 147 | struct snd_sst_alloc_params_ext *alloc_param) |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 148 | { |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 149 | unsigned int channels; |
| 150 | snd_pcm_uframes_t period_size; |
| 151 | ssize_t periodbytes; |
| 152 | ssize_t buffer_bytes = snd_pcm_lib_buffer_bytes(substream); |
| 153 | u32 buffer_addr = virt_to_phys(substream->dma_buffer.area); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 154 | |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 155 | channels = substream->runtime->channels; |
| 156 | period_size = substream->runtime->period_size; |
| 157 | periodbytes = samples_to_bytes(substream->runtime, period_size); |
| 158 | alloc_param->ring_buf_info[0].addr = buffer_addr; |
| 159 | alloc_param->ring_buf_info[0].size = buffer_bytes; |
| 160 | alloc_param->sg_count = 1; |
| 161 | alloc_param->reserved = 0; |
| 162 | alloc_param->frag_size = periodbytes * channels; |
| 163 | |
| 164 | } |
| 165 | static void sst_fill_pcm_params(struct snd_pcm_substream *substream, |
| 166 | struct snd_sst_stream_params *param) |
| 167 | { |
| 168 | param->uc.pcm_params.num_chan = (u8) substream->runtime->channels; |
| 169 | param->uc.pcm_params.pcm_wd_sz = substream->runtime->sample_bits; |
| 170 | param->uc.pcm_params.sfreq = substream->runtime->rate; |
| 171 | |
| 172 | /* PCM stream via ALSA interface */ |
| 173 | param->uc.pcm_params.use_offload_path = 0; |
| 174 | param->uc.pcm_params.reserved2 = 0; |
| 175 | memset(param->uc.pcm_params.channel_map, 0, sizeof(u8)); |
| 176 | |
| 177 | } |
| 178 | int sst_fill_stream_params(void *substream, |
| 179 | struct snd_sst_params *str_params, bool is_compress) |
| 180 | { |
| 181 | struct snd_pcm_substream *pstream = NULL; |
| 182 | struct snd_compr_stream *cstream = NULL; |
| 183 | |
| 184 | if (is_compress == true) |
| 185 | cstream = (struct snd_compr_stream *)substream; |
| 186 | else |
| 187 | pstream = (struct snd_pcm_substream *)substream; |
| 188 | |
| 189 | str_params->stream_type = SST_STREAM_TYPE_MUSIC; |
| 190 | |
| 191 | /* For pcm streams */ |
| 192 | if (pstream) |
| 193 | str_params->ops = (u8)pstream->stream; |
| 194 | if (cstream) |
| 195 | str_params->ops = (u8)cstream->direction; |
| 196 | |
| 197 | return 0; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 198 | } |
| 199 | |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 200 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream, |
| 201 | struct snd_soc_platform *platform) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 202 | { |
| 203 | struct sst_runtime_stream *stream = |
| 204 | substream->runtime->private_data; |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 205 | struct snd_sst_stream_params param = {{{0,},},}; |
| 206 | struct snd_sst_params str_params = {0}; |
| 207 | struct snd_sst_alloc_params_ext alloc_params = {0}; |
| 208 | int ret_val = 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 209 | |
| 210 | /* set codec params and inform SST driver the same */ |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 211 | sst_fill_pcm_params(substream, ¶m); |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 212 | sst_fill_alloc_params(substream, &alloc_params); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 213 | substream->runtime->dma_area = substream->dma_buffer.area; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 214 | str_params.sparams = param; |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 215 | str_params.aparams = alloc_params; |
| 216 | str_params.codec = SST_CODEC_TYPE_PCM; |
| 217 | |
| 218 | /* fill the device type and stream id to pass to SST driver */ |
| 219 | ret_val = sst_fill_stream_params(substream, &str_params, false); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 220 | if (ret_val < 0) |
| 221 | return ret_val; |
| 222 | |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 223 | stream->stream_info.str_id = str_params.stream_id; |
| 224 | |
| 225 | ret_val = stream->ops->open(&str_params); |
| 226 | if (ret_val <= 0) |
| 227 | return ret_val; |
| 228 | |
| 229 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 230 | return ret_val; |
| 231 | } |
| 232 | |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 233 | static void sst_period_elapsed(void *arg) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 234 | { |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 235 | struct snd_pcm_substream *substream = arg; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 236 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 237 | int status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 238 | |
| 239 | if (!substream || !substream->runtime) |
| 240 | return; |
| 241 | stream = substream->runtime->private_data; |
| 242 | if (!stream) |
| 243 | return; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 244 | status = sst_get_stream_status(stream); |
| 245 | if (status != SST_PLATFORM_RUNNING) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 246 | return; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 247 | snd_pcm_period_elapsed(substream); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static int sst_platform_init_stream(struct snd_pcm_substream *substream) |
| 251 | { |
| 252 | struct sst_runtime_stream *stream = |
| 253 | substream->runtime->private_data; |
| 254 | int ret_val; |
| 255 | |
| 256 | pr_debug("setting buffer ptr param\n"); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 257 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 258 | stream->stream_info.period_elapsed = sst_period_elapsed; |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 259 | stream->stream_info.arg = substream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 260 | stream->stream_info.buffer_ptr = 0; |
| 261 | stream->stream_info.sfreq = substream->runtime->rate; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 262 | ret_val = stream->ops->device_control( |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 263 | SST_SND_STREAM_INIT, &stream->stream_info); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 264 | if (ret_val) |
| 265 | pr_err("control_set ret error %d\n", ret_val); |
| 266 | return ret_val; |
| 267 | |
| 268 | } |
| 269 | /* end -- helper functions */ |
| 270 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 271 | static int sst_media_open(struct snd_pcm_substream *substream, |
| 272 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 273 | { |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 274 | int ret_val = 0; |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 275 | struct snd_pcm_runtime *runtime = substream->runtime; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 276 | struct sst_runtime_stream *stream; |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 277 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 278 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
| 279 | if (!stream) |
| 280 | return -ENOMEM; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 281 | spin_lock_init(&stream->status_lock); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 282 | |
| 283 | /* get the sst ops */ |
| 284 | mutex_lock(&sst_lock); |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 285 | if (!sst || |
| 286 | !try_module_get(sst->dev->driver->owner)) { |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 287 | pr_err("no device available to run\n"); |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 288 | ret_val = -ENODEV; |
| 289 | goto out_ops; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 290 | } |
| 291 | stream->ops = sst->ops; |
| 292 | mutex_unlock(&sst_lock); |
| 293 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 294 | stream->stream_info.str_id = 0; |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 295 | |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 296 | stream->stream_info.arg = substream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 297 | /* allocate memory for SST API set */ |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 298 | runtime->private_data = stream; |
Lu Guanqun | 283e42e | 2011-09-06 15:21:43 +0800 | [diff] [blame] | 299 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 300 | /* Make sure, that the period size is always even */ |
| 301 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 302 | SNDRV_PCM_HW_PARAM_PERIODS, 2); |
| 303 | |
| 304 | return snd_pcm_hw_constraint_integer(runtime, |
| 305 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 306 | out_ops: |
| 307 | kfree(stream); |
| 308 | mutex_unlock(&sst_lock); |
| 309 | return ret_val; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 312 | static void sst_media_close(struct snd_pcm_substream *substream, |
| 313 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 314 | { |
| 315 | struct sst_runtime_stream *stream; |
| 316 | int ret_val = 0, str_id; |
| 317 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 318 | stream = substream->runtime->private_data; |
| 319 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 320 | if (str_id) |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 321 | ret_val = stream->ops->close(str_id); |
| 322 | module_put(sst->dev->driver->owner); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 323 | kfree(stream); |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 324 | return; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 327 | static int sst_media_prepare(struct snd_pcm_substream *substream, |
| 328 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 329 | { |
| 330 | struct sst_runtime_stream *stream; |
| 331 | int ret_val = 0, str_id; |
| 332 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 333 | stream = substream->runtime->private_data; |
| 334 | str_id = stream->stream_info.str_id; |
| 335 | if (stream->stream_info.str_id) { |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 336 | ret_val = stream->ops->device_control( |
| 337 | SST_SND_DROP, &str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 338 | return ret_val; |
| 339 | } |
| 340 | |
Vinod Koul | a870cdc | 2014-06-13 18:03:55 +0530 | [diff] [blame^] | 341 | ret_val = sst_platform_alloc_stream(substream, dai->platform); |
| 342 | if (ret_val <= 0) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 343 | return ret_val; |
| 344 | snprintf(substream->pcm->id, sizeof(substream->pcm->id), |
| 345 | "%d", stream->stream_info.str_id); |
| 346 | |
| 347 | ret_val = sst_platform_init_stream(substream); |
| 348 | if (ret_val) |
| 349 | return ret_val; |
| 350 | substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER; |
| 351 | return ret_val; |
| 352 | } |
| 353 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 354 | static int sst_media_hw_params(struct snd_pcm_substream *substream, |
| 355 | struct snd_pcm_hw_params *params, |
| 356 | struct snd_soc_dai *dai) |
| 357 | { |
| 358 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 359 | memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | static int sst_media_hw_free(struct snd_pcm_substream *substream, |
| 364 | struct snd_soc_dai *dai) |
| 365 | { |
| 366 | return snd_pcm_lib_free_pages(substream); |
| 367 | } |
| 368 | |
| 369 | static struct snd_soc_dai_ops sst_media_dai_ops = { |
| 370 | .startup = sst_media_open, |
| 371 | .shutdown = sst_media_close, |
| 372 | .prepare = sst_media_prepare, |
| 373 | .hw_params = sst_media_hw_params, |
| 374 | .hw_free = sst_media_hw_free, |
| 375 | }; |
| 376 | |
| 377 | static int sst_platform_open(struct snd_pcm_substream *substream) |
| 378 | { |
| 379 | struct snd_pcm_runtime *runtime; |
| 380 | |
| 381 | if (substream->pcm->internal) |
| 382 | return 0; |
| 383 | |
| 384 | runtime = substream->runtime; |
| 385 | runtime->hw = sst_platform_pcm_hw; |
| 386 | return 0; |
| 387 | } |
| 388 | |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 389 | static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 390 | int cmd) |
| 391 | { |
| 392 | int ret_val = 0, str_id; |
| 393 | struct sst_runtime_stream *stream; |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 394 | int str_cmd, status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 395 | |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 396 | pr_debug("sst_platform_pcm_trigger called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 397 | stream = substream->runtime->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 398 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 399 | switch (cmd) { |
| 400 | case SNDRV_PCM_TRIGGER_START: |
| 401 | pr_debug("sst: Trigger Start\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 402 | str_cmd = SST_SND_START; |
| 403 | status = SST_PLATFORM_RUNNING; |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 404 | stream->stream_info.arg = substream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 405 | break; |
| 406 | case SNDRV_PCM_TRIGGER_STOP: |
| 407 | pr_debug("sst: in stop\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 408 | str_cmd = SST_SND_DROP; |
| 409 | status = SST_PLATFORM_DROPPED; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 410 | break; |
| 411 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 412 | pr_debug("sst: in pause\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 413 | str_cmd = SST_SND_PAUSE; |
| 414 | status = SST_PLATFORM_PAUSED; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 415 | break; |
| 416 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 417 | pr_debug("sst: in pause release\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 418 | str_cmd = SST_SND_RESUME; |
| 419 | status = SST_PLATFORM_RUNNING; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 420 | break; |
| 421 | default: |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 422 | return -EINVAL; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 423 | } |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 424 | ret_val = stream->ops->device_control(str_cmd, &str_id); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 425 | if (!ret_val) |
| 426 | sst_set_stream_status(stream, status); |
| 427 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 428 | return ret_val; |
| 429 | } |
| 430 | |
| 431 | |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 432 | static snd_pcm_uframes_t sst_platform_pcm_pointer |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 433 | (struct snd_pcm_substream *substream) |
| 434 | { |
| 435 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 436 | int ret_val, status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 437 | struct pcm_stream_info *str_info; |
| 438 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 439 | stream = substream->runtime->private_data; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 440 | status = sst_get_stream_status(stream); |
| 441 | if (status == SST_PLATFORM_INIT) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 442 | return 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 443 | str_info = &stream->stream_info; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 444 | ret_val = stream->ops->device_control( |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 445 | SST_SND_BUFFER_POINTER, str_info); |
| 446 | if (ret_val) { |
| 447 | pr_err("sst: error code = %d\n", ret_val); |
| 448 | return ret_val; |
| 449 | } |
Vinod Koul | 2a63582 | 2014-06-13 18:03:53 +0530 | [diff] [blame] | 450 | substream->runtime->delay = str_info->pcm_delay; |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 451 | return str_info->buffer_ptr; |
xingchao | 9ab8843 | 2011-04-27 16:58:54 -0400 | [diff] [blame] | 452 | } |
| 453 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 454 | static struct snd_pcm_ops sst_platform_ops = { |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 455 | .open = sst_platform_open, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 456 | .ioctl = snd_pcm_lib_ioctl, |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 457 | .trigger = sst_platform_pcm_trigger, |
| 458 | .pointer = sst_platform_pcm_pointer, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | static void sst_pcm_free(struct snd_pcm *pcm) |
| 462 | { |
| 463 | pr_debug("sst_pcm_free called\n"); |
| 464 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 465 | } |
| 466 | |
Axel Lin | 8faa8c1 | 2011-12-13 17:13:45 +0800 | [diff] [blame] | 467 | static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 468 | { |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 469 | struct snd_soc_dai *dai = rtd->cpu_dai; |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 470 | struct snd_pcm *pcm = rtd->pcm; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 471 | int retval = 0; |
| 472 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 473 | if (dai->driver->playback.channels_min || |
| 474 | dai->driver->capture.channels_min) { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 475 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 476 | SNDRV_DMA_TYPE_CONTINUOUS, |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 477 | snd_dma_continuous_data(GFP_DMA), |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 478 | SST_MIN_BUFFER, SST_MAX_BUFFER); |
| 479 | if (retval) { |
| 480 | pr_err("dma buffer allocationf fail\n"); |
| 481 | return retval; |
| 482 | } |
| 483 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 484 | return retval; |
| 485 | } |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 486 | |
Axel Lin | 8faa8c1 | 2011-12-13 17:13:45 +0800 | [diff] [blame] | 487 | static struct snd_soc_platform_driver sst_soc_platform_drv = { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 488 | .ops = &sst_platform_ops, |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 489 | .compr_ops = &sst_platform_compr_ops, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 490 | .pcm_new = sst_pcm_new, |
| 491 | .pcm_free = sst_pcm_free, |
| 492 | }; |
| 493 | |
Vinod Koul | 2b4c78d | 2014-05-05 22:19:25 +0530 | [diff] [blame] | 494 | static const struct snd_soc_component_driver sst_component = { |
| 495 | .name = "sst", |
| 496 | }; |
| 497 | |
| 498 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 499 | static int sst_platform_probe(struct platform_device *pdev) |
| 500 | { |
| 501 | int ret; |
| 502 | |
| 503 | pr_debug("sst_platform_probe called\n"); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 504 | sst = NULL; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 505 | ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv); |
| 506 | if (ret) { |
| 507 | pr_err("registering soc platform failed\n"); |
| 508 | return ret; |
| 509 | } |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 510 | |
Kuninori Morimoto | b1c3686 | 2013-03-21 03:32:50 -0700 | [diff] [blame] | 511 | ret = snd_soc_register_component(&pdev->dev, &sst_component, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 512 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); |
| 513 | if (ret) { |
| 514 | pr_err("registering cpu dais failed\n"); |
| 515 | snd_soc_unregister_platform(&pdev->dev); |
| 516 | } |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | static int sst_platform_remove(struct platform_device *pdev) |
| 521 | { |
| 522 | |
Kuninori Morimoto | b1c3686 | 2013-03-21 03:32:50 -0700 | [diff] [blame] | 523 | snd_soc_unregister_component(&pdev->dev); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 524 | snd_soc_unregister_platform(&pdev->dev); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 525 | pr_debug("sst_platform_remove success\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static struct platform_driver sst_platform_driver = { |
| 530 | .driver = { |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 531 | .name = "sst-mfld-platform", |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 532 | .owner = THIS_MODULE, |
| 533 | }, |
| 534 | .probe = sst_platform_probe, |
| 535 | .remove = sst_platform_remove, |
| 536 | }; |
| 537 | |
Axel Lin | 29515d6 | 2011-11-24 11:51:56 +0800 | [diff] [blame] | 538 | module_platform_driver(sst_platform_driver); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 539 | |
| 540 | MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver"); |
| 541 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); |
| 542 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); |
| 543 | MODULE_LICENSE("GPL v2"); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 544 | MODULE_ALIAS("platform:sst-mfld-platform"); |