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 | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 4 | * Copyright (C) 2010-2014 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> |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 30 | #include <asm/platform_sst_audio.h> |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 31 | #include "sst-mfld-platform.h" |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 32 | #include "sst-atom-controls.h" |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 33 | |
Vinod Koul | 4b68b4e | 2014-05-05 14:27:50 +0530 | [diff] [blame] | 34 | struct sst_device *sst; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 35 | static DEFINE_MUTEX(sst_lock); |
Vinod Koul | 4b68b4e | 2014-05-05 14:27:50 +0530 | [diff] [blame] | 36 | extern struct snd_compr_ops sst_platform_compr_ops; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 37 | |
| 38 | int sst_register_dsp(struct sst_device *dev) |
| 39 | { |
Takashi Iwai | 656a22a | 2013-11-05 18:40:01 +0100 | [diff] [blame] | 40 | if (WARN_ON(!dev)) |
| 41 | return -EINVAL; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 42 | if (!try_module_get(dev->dev->driver->owner)) |
| 43 | return -ENODEV; |
| 44 | mutex_lock(&sst_lock); |
| 45 | if (sst) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 46 | dev_err(dev->dev, "we already have a device %s\n", sst->name); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 47 | module_put(dev->dev->driver->owner); |
| 48 | mutex_unlock(&sst_lock); |
| 49 | return -EEXIST; |
| 50 | } |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 51 | dev_dbg(dev->dev, "registering device %s\n", dev->name); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 52 | sst = dev; |
| 53 | mutex_unlock(&sst_lock); |
| 54 | return 0; |
| 55 | } |
| 56 | EXPORT_SYMBOL_GPL(sst_register_dsp); |
| 57 | |
| 58 | int sst_unregister_dsp(struct sst_device *dev) |
| 59 | { |
Takashi Iwai | 656a22a | 2013-11-05 18:40:01 +0100 | [diff] [blame] | 60 | if (WARN_ON(!dev)) |
| 61 | return -EINVAL; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 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); |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 73 | dev_dbg(dev->dev, "unreg %s\n", sst->name); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 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), |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 89 | .buffer_bytes_max = SST_MAX_BUFFER, |
| 90 | .period_bytes_min = SST_MIN_PERIOD_BYTES, |
| 91 | .period_bytes_max = SST_MAX_PERIOD_BYTES, |
| 92 | .periods_min = SST_MIN_PERIODS, |
| 93 | .periods_max = SST_MAX_PERIODS, |
| 94 | .fifo_size = SST_FIFO_SIZE, |
| 95 | }; |
| 96 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 97 | static struct sst_dev_stream_map dpcm_strm_map[] = { |
| 98 | {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, /* Reserved, not in use */ |
| 99 | {MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_PLAYBACK, PIPE_MEDIA1_IN, SST_TASK_ID_MEDIA, 0}, |
| 100 | {MERR_DPCM_COMPR, 0, SNDRV_PCM_STREAM_PLAYBACK, PIPE_MEDIA0_IN, SST_TASK_ID_MEDIA, 0}, |
| 101 | {MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_CAPTURE, PIPE_PCM1_OUT, SST_TASK_ID_MEDIA, 0}, |
| 102 | }; |
| 103 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 104 | /* MFLD - MSIC */ |
Axel Lin | d1b7328 | 2011-09-27 10:38:50 +0800 | [diff] [blame] | 105 | static struct snd_soc_dai_driver sst_platform_dai[] = { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 106 | { |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 107 | .name = "Headset-cpu-dai", |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 108 | .id = 0, |
| 109 | .playback = { |
| 110 | .channels_min = SST_STEREO, |
| 111 | .channels_max = SST_STEREO, |
| 112 | .rates = SNDRV_PCM_RATE_48000, |
| 113 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 114 | }, |
Harsha Priya | a7bffdf | 2011-01-28 22:27:26 +0530 | [diff] [blame] | 115 | .capture = { |
| 116 | .channels_min = 1, |
| 117 | .channels_max = 5, |
| 118 | .rates = SNDRV_PCM_RATE_48000, |
| 119 | .formats = SNDRV_PCM_FMTBIT_S24_LE, |
| 120 | }, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 121 | }, |
| 122 | { |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 123 | .name = "Compress-cpu-dai", |
| 124 | .compress_dai = 1, |
| 125 | .playback = { |
| 126 | .channels_min = SST_STEREO, |
| 127 | .channels_max = SST_STEREO, |
| 128 | .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000, |
| 129 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 130 | }, |
| 131 | }, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 132 | }; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 133 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 134 | /* helper functions */ |
Vinod Koul | 4496ffa | 2014-05-05 14:27:49 +0530 | [diff] [blame] | 135 | void sst_set_stream_status(struct sst_runtime_stream *stream, |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 136 | int state) |
| 137 | { |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 138 | unsigned long flags; |
| 139 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 140 | stream->stream_status = state; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 141 | spin_unlock_irqrestore(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static inline int sst_get_stream_status(struct sst_runtime_stream *stream) |
| 145 | { |
| 146 | int state; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 147 | unsigned long flags; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 148 | |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 149 | spin_lock_irqsave(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 150 | state = stream->stream_status; |
Lu Guanqun | d89b0a1 | 2011-04-08 15:38:48 +0800 | [diff] [blame] | 151 | spin_unlock_irqrestore(&stream->status_lock, flags); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 152 | return state; |
| 153 | } |
| 154 | |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 155 | static void sst_fill_alloc_params(struct snd_pcm_substream *substream, |
| 156 | struct snd_sst_alloc_params_ext *alloc_param) |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 157 | { |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 158 | unsigned int channels; |
| 159 | snd_pcm_uframes_t period_size; |
| 160 | ssize_t periodbytes; |
| 161 | ssize_t buffer_bytes = snd_pcm_lib_buffer_bytes(substream); |
| 162 | u32 buffer_addr = virt_to_phys(substream->dma_buffer.area); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 163 | |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 164 | channels = substream->runtime->channels; |
| 165 | period_size = substream->runtime->period_size; |
| 166 | periodbytes = samples_to_bytes(substream->runtime, period_size); |
| 167 | alloc_param->ring_buf_info[0].addr = buffer_addr; |
| 168 | alloc_param->ring_buf_info[0].size = buffer_bytes; |
| 169 | alloc_param->sg_count = 1; |
| 170 | alloc_param->reserved = 0; |
| 171 | alloc_param->frag_size = periodbytes * channels; |
| 172 | |
| 173 | } |
| 174 | static void sst_fill_pcm_params(struct snd_pcm_substream *substream, |
| 175 | struct snd_sst_stream_params *param) |
| 176 | { |
| 177 | param->uc.pcm_params.num_chan = (u8) substream->runtime->channels; |
| 178 | param->uc.pcm_params.pcm_wd_sz = substream->runtime->sample_bits; |
| 179 | param->uc.pcm_params.sfreq = substream->runtime->rate; |
| 180 | |
| 181 | /* PCM stream via ALSA interface */ |
| 182 | param->uc.pcm_params.use_offload_path = 0; |
| 183 | param->uc.pcm_params.reserved2 = 0; |
| 184 | memset(param->uc.pcm_params.channel_map, 0, sizeof(u8)); |
| 185 | |
| 186 | } |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 187 | |
| 188 | static int sst_get_stream_mapping(int dev, int sdev, int dir, |
| 189 | struct sst_dev_stream_map *map, int size) |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 190 | { |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 191 | int i; |
| 192 | |
| 193 | if (map == NULL) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | |
| 197 | /* index 0 is not used in stream map */ |
| 198 | for (i = 1; i < size; i++) { |
| 199 | if ((map[i].dev_num == dev) && (map[i].direction == dir)) |
| 200 | return i; |
| 201 | } |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | int sst_fill_stream_params(void *substream, |
| 206 | const struct sst_data *ctx, struct snd_sst_params *str_params, bool is_compress) |
| 207 | { |
| 208 | int map_size; |
| 209 | int index; |
| 210 | struct sst_dev_stream_map *map; |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 211 | struct snd_pcm_substream *pstream = NULL; |
| 212 | struct snd_compr_stream *cstream = NULL; |
| 213 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 214 | map = ctx->pdata->pdev_strm_map; |
| 215 | map_size = ctx->pdata->strm_map_size; |
| 216 | |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 217 | if (is_compress == true) |
| 218 | cstream = (struct snd_compr_stream *)substream; |
| 219 | else |
| 220 | pstream = (struct snd_pcm_substream *)substream; |
| 221 | |
| 222 | str_params->stream_type = SST_STREAM_TYPE_MUSIC; |
| 223 | |
| 224 | /* For pcm streams */ |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 225 | if (pstream) { |
| 226 | index = sst_get_stream_mapping(pstream->pcm->device, |
| 227 | pstream->number, pstream->stream, |
| 228 | map, map_size); |
| 229 | if (index <= 0) |
| 230 | return -EINVAL; |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 231 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 232 | str_params->stream_id = index; |
| 233 | str_params->device_type = map[index].device_id; |
| 234 | str_params->task = map[index].task_id; |
| 235 | |
| 236 | str_params->ops = (u8)pstream->stream; |
| 237 | } |
| 238 | |
| 239 | if (cstream) { |
| 240 | index = sst_get_stream_mapping(cstream->device->device, |
| 241 | 0, cstream->direction, |
| 242 | map, map_size); |
| 243 | if (index <= 0) |
| 244 | return -EINVAL; |
| 245 | str_params->stream_id = index; |
| 246 | str_params->device_type = map[index].device_id; |
| 247 | str_params->task = map[index].task_id; |
| 248 | |
| 249 | str_params->ops = (u8)cstream->direction; |
| 250 | } |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 251 | return 0; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 252 | } |
| 253 | |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 254 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream, |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 255 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 256 | { |
| 257 | struct sst_runtime_stream *stream = |
| 258 | substream->runtime->private_data; |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 259 | struct snd_sst_stream_params param = {{{0,},},}; |
| 260 | struct snd_sst_params str_params = {0}; |
| 261 | struct snd_sst_alloc_params_ext alloc_params = {0}; |
| 262 | int ret_val = 0; |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 263 | struct sst_data *ctx = snd_soc_dai_get_drvdata(dai); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 264 | |
| 265 | /* set codec params and inform SST driver the same */ |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 266 | sst_fill_pcm_params(substream, ¶m); |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 267 | sst_fill_alloc_params(substream, &alloc_params); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 268 | substream->runtime->dma_area = substream->dma_buffer.area; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 269 | str_params.sparams = param; |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 270 | str_params.aparams = alloc_params; |
| 271 | str_params.codec = SST_CODEC_TYPE_PCM; |
| 272 | |
| 273 | /* fill the device type and stream id to pass to SST driver */ |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 274 | ret_val = sst_fill_stream_params(substream, ctx, &str_params, false); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 275 | if (ret_val < 0) |
| 276 | return ret_val; |
| 277 | |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 278 | stream->stream_info.str_id = str_params.stream_id; |
| 279 | |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 280 | ret_val = stream->ops->open(sst->dev, &str_params); |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 281 | if (ret_val <= 0) |
| 282 | return ret_val; |
| 283 | |
| 284 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 285 | return ret_val; |
| 286 | } |
| 287 | |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 288 | static void sst_period_elapsed(void *arg) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 289 | { |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 290 | struct snd_pcm_substream *substream = arg; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 291 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 292 | int status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 293 | |
| 294 | if (!substream || !substream->runtime) |
| 295 | return; |
| 296 | stream = substream->runtime->private_data; |
| 297 | if (!stream) |
| 298 | return; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 299 | status = sst_get_stream_status(stream); |
| 300 | if (status != SST_PLATFORM_RUNNING) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 301 | return; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 302 | snd_pcm_period_elapsed(substream); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static int sst_platform_init_stream(struct snd_pcm_substream *substream) |
| 306 | { |
| 307 | struct sst_runtime_stream *stream = |
| 308 | substream->runtime->private_data; |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 309 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 310 | int ret_val; |
| 311 | |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 312 | dev_dbg(rtd->dev, "setting buffer ptr param\n"); |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 313 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 314 | stream->stream_info.period_elapsed = sst_period_elapsed; |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 315 | stream->stream_info.arg = substream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 316 | stream->stream_info.buffer_ptr = 0; |
| 317 | stream->stream_info.sfreq = substream->runtime->rate; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 318 | ret_val = stream->ops->stream_init(sst->dev, &stream->stream_info); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 319 | if (ret_val) |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 320 | dev_err(rtd->dev, "control_set ret error %d\n", ret_val); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 321 | return ret_val; |
| 322 | |
| 323 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 324 | |
Vinod Koul | 0121327 | 2014-09-19 16:46:03 +0530 | [diff] [blame^] | 325 | static int power_up_sst(struct sst_runtime_stream *stream) |
| 326 | { |
| 327 | return stream->ops->power(sst->dev, true); |
| 328 | } |
| 329 | |
| 330 | static void power_down_sst(struct sst_runtime_stream *stream) |
| 331 | { |
| 332 | stream->ops->power(sst->dev, false); |
| 333 | } |
| 334 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 335 | static int sst_media_open(struct snd_pcm_substream *substream, |
| 336 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 337 | { |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 338 | int ret_val = 0; |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 339 | struct snd_pcm_runtime *runtime = substream->runtime; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 340 | struct sst_runtime_stream *stream; |
Lu Guanqun | 22be504 | 2011-09-06 15:21:38 +0800 | [diff] [blame] | 341 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 342 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
| 343 | if (!stream) |
| 344 | return -ENOMEM; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 345 | spin_lock_init(&stream->status_lock); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 346 | |
| 347 | /* get the sst ops */ |
| 348 | mutex_lock(&sst_lock); |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 349 | if (!sst || |
| 350 | !try_module_get(sst->dev->driver->owner)) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 351 | dev_err(dai->dev, "no device available to run\n"); |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 352 | ret_val = -ENODEV; |
| 353 | goto out_ops; |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 354 | } |
| 355 | stream->ops = sst->ops; |
| 356 | mutex_unlock(&sst_lock); |
| 357 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 358 | stream->stream_info.str_id = 0; |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 359 | |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 360 | stream->stream_info.arg = substream; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 361 | /* allocate memory for SST API set */ |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 362 | runtime->private_data = stream; |
Lu Guanqun | 283e42e | 2011-09-06 15:21:43 +0800 | [diff] [blame] | 363 | |
Vinod Koul | 0121327 | 2014-09-19 16:46:03 +0530 | [diff] [blame^] | 364 | ret_val = power_up_sst(stream); |
| 365 | if (ret_val < 0) |
| 366 | return ret_val; |
| 367 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 368 | /* Make sure, that the period size is always even */ |
| 369 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 370 | SNDRV_PCM_HW_PARAM_PERIODS, 2); |
| 371 | |
| 372 | return snd_pcm_hw_constraint_integer(runtime, |
| 373 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 374 | out_ops: |
| 375 | kfree(stream); |
| 376 | mutex_unlock(&sst_lock); |
| 377 | return ret_val; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 378 | } |
| 379 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 380 | static void sst_media_close(struct snd_pcm_substream *substream, |
| 381 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 382 | { |
| 383 | struct sst_runtime_stream *stream; |
| 384 | int ret_val = 0, str_id; |
| 385 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 386 | stream = substream->runtime->private_data; |
Vinod Koul | 0121327 | 2014-09-19 16:46:03 +0530 | [diff] [blame^] | 387 | power_down_sst(stream); |
| 388 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 389 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 390 | if (str_id) |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 391 | ret_val = stream->ops->close(sst->dev, str_id); |
Vinod Koul | 03c3304 | 2011-12-05 19:13:41 +0530 | [diff] [blame] | 392 | module_put(sst->dev->driver->owner); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 393 | kfree(stream); |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 394 | } |
| 395 | |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 396 | static inline unsigned int get_current_pipe_id(struct snd_soc_dai *dai, |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 397 | struct snd_pcm_substream *substream) |
| 398 | { |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 399 | struct sst_data *sst = snd_soc_dai_get_drvdata(dai); |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 400 | struct sst_dev_stream_map *map = sst->pdata->pdev_strm_map; |
| 401 | struct sst_runtime_stream *stream = |
| 402 | substream->runtime->private_data; |
| 403 | u32 str_id = stream->stream_info.str_id; |
| 404 | unsigned int pipe_id; |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 405 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 406 | pipe_id = map[str_id].device_id; |
| 407 | |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 408 | dev_dbg(dai->dev, "got pipe_id = %#x for str_id = %d\n", |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 409 | pipe_id, str_id); |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 410 | return pipe_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 411 | } |
| 412 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 413 | static int sst_media_prepare(struct snd_pcm_substream *substream, |
| 414 | struct snd_soc_dai *dai) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 415 | { |
| 416 | struct sst_runtime_stream *stream; |
| 417 | int ret_val = 0, str_id; |
| 418 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 419 | stream = substream->runtime->private_data; |
| 420 | str_id = stream->stream_info.str_id; |
| 421 | if (stream->stream_info.str_id) { |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 422 | ret_val = stream->ops->stream_drop(sst->dev, str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 423 | return ret_val; |
| 424 | } |
| 425 | |
Subhransu S. Prusty | 6df5d76 | 2014-09-09 15:11:32 +0530 | [diff] [blame] | 426 | ret_val = sst_platform_alloc_stream(substream, dai); |
Vinod Koul | a870cdce | 2014-06-13 18:03:55 +0530 | [diff] [blame] | 427 | if (ret_val <= 0) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 428 | return ret_val; |
| 429 | snprintf(substream->pcm->id, sizeof(substream->pcm->id), |
| 430 | "%d", stream->stream_info.str_id); |
| 431 | |
| 432 | ret_val = sst_platform_init_stream(substream); |
| 433 | if (ret_val) |
| 434 | return ret_val; |
| 435 | substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER; |
| 436 | return ret_val; |
| 437 | } |
| 438 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 439 | static int sst_media_hw_params(struct snd_pcm_substream *substream, |
| 440 | struct snd_pcm_hw_params *params, |
| 441 | struct snd_soc_dai *dai) |
| 442 | { |
| 443 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 444 | memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int sst_media_hw_free(struct snd_pcm_substream *substream, |
| 449 | struct snd_soc_dai *dai) |
| 450 | { |
| 451 | return snd_pcm_lib_free_pages(substream); |
| 452 | } |
| 453 | |
| 454 | static struct snd_soc_dai_ops sst_media_dai_ops = { |
| 455 | .startup = sst_media_open, |
| 456 | .shutdown = sst_media_close, |
| 457 | .prepare = sst_media_prepare, |
| 458 | .hw_params = sst_media_hw_params, |
| 459 | .hw_free = sst_media_hw_free, |
| 460 | }; |
| 461 | |
| 462 | static int sst_platform_open(struct snd_pcm_substream *substream) |
| 463 | { |
| 464 | struct snd_pcm_runtime *runtime; |
| 465 | |
| 466 | if (substream->pcm->internal) |
| 467 | return 0; |
| 468 | |
| 469 | runtime = substream->runtime; |
| 470 | runtime->hw = sst_platform_pcm_hw; |
| 471 | return 0; |
| 472 | } |
| 473 | |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 474 | static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 475 | int cmd) |
| 476 | { |
| 477 | int ret_val = 0, str_id; |
| 478 | struct sst_runtime_stream *stream; |
Subhransu S. Prusty | 5981c2d | 2014-08-04 15:04:20 +0530 | [diff] [blame] | 479 | int status; |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 480 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 481 | |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 482 | dev_dbg(rtd->dev, "sst_platform_pcm_trigger called\n"); |
Vinod Koul | d2b16b8 | 2014-09-09 15:11:24 +0530 | [diff] [blame] | 483 | if (substream->pcm->internal) |
| 484 | return 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 485 | stream = substream->runtime->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 486 | str_id = stream->stream_info.str_id; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 487 | switch (cmd) { |
| 488 | case SNDRV_PCM_TRIGGER_START: |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 489 | dev_dbg(rtd->dev, "sst: Trigger Start\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 490 | status = SST_PLATFORM_RUNNING; |
Vinod Koul | 9daa5bd | 2014-06-13 18:03:52 +0530 | [diff] [blame] | 491 | stream->stream_info.arg = substream; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 492 | ret_val = stream->ops->stream_start(sst->dev, str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 493 | break; |
| 494 | case SNDRV_PCM_TRIGGER_STOP: |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 495 | dev_dbg(rtd->dev, "sst: in stop\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 496 | status = SST_PLATFORM_DROPPED; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 497 | ret_val = stream->ops->stream_drop(sst->dev, str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 498 | break; |
| 499 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 500 | dev_dbg(rtd->dev, "sst: in pause\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 501 | status = SST_PLATFORM_PAUSED; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 502 | ret_val = stream->ops->stream_pause(sst->dev, str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 503 | break; |
| 504 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 505 | dev_dbg(rtd->dev, "sst: in pause release\n"); |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 506 | status = SST_PLATFORM_RUNNING; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 507 | ret_val = stream->ops->stream_pause_release(sst->dev, str_id); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 508 | break; |
| 509 | default: |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 510 | return -EINVAL; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 511 | } |
Subhransu S. Prusty | 5981c2d | 2014-08-04 15:04:20 +0530 | [diff] [blame] | 512 | |
Harsha Priya | a211701 | 2011-01-11 14:50:59 +0530 | [diff] [blame] | 513 | if (!ret_val) |
| 514 | sst_set_stream_status(stream, status); |
| 515 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 516 | return ret_val; |
| 517 | } |
| 518 | |
| 519 | |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 520 | static snd_pcm_uframes_t sst_platform_pcm_pointer |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 521 | (struct snd_pcm_substream *substream) |
| 522 | { |
| 523 | struct sst_runtime_stream *stream; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 524 | int ret_val, status; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 525 | struct pcm_stream_info *str_info; |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 526 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 527 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 528 | stream = substream->runtime->private_data; |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 529 | status = sst_get_stream_status(stream); |
| 530 | if (status == SST_PLATFORM_INIT) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 531 | return 0; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 532 | str_info = &stream->stream_info; |
Subhransu S. Prusty | b12b087c | 2014-08-04 15:04:21 +0530 | [diff] [blame] | 533 | ret_val = stream->ops->stream_read_tstamp(sst->dev, str_info); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 534 | if (ret_val) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 535 | dev_err(rtd->dev, "sst: error code = %d\n", ret_val); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 536 | return ret_val; |
| 537 | } |
Vinod Koul | 2a63582 | 2014-06-13 18:03:53 +0530 | [diff] [blame] | 538 | substream->runtime->delay = str_info->pcm_delay; |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 539 | return str_info->buffer_ptr; |
xingchao | 9ab8843 | 2011-04-27 16:58:54 -0400 | [diff] [blame] | 540 | } |
| 541 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 542 | static struct snd_pcm_ops sst_platform_ops = { |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 543 | .open = sst_platform_open, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 544 | .ioctl = snd_pcm_lib_ioctl, |
Vinod Koul | 5106f5a | 2014-05-15 21:38:15 +0530 | [diff] [blame] | 545 | .trigger = sst_platform_pcm_trigger, |
| 546 | .pointer = sst_platform_pcm_pointer, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | static void sst_pcm_free(struct snd_pcm *pcm) |
| 550 | { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 551 | dev_dbg(pcm->dev, "sst_pcm_free called\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 552 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 553 | } |
| 554 | |
Axel Lin | 8faa8c1 | 2011-12-13 17:13:45 +0800 | [diff] [blame] | 555 | static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd) |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 556 | { |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 557 | struct snd_soc_dai *dai = rtd->cpu_dai; |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 558 | struct snd_pcm *pcm = rtd->pcm; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 559 | int retval = 0; |
| 560 | |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 561 | if (dai->driver->playback.channels_min || |
| 562 | dai->driver->capture.channels_min) { |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 563 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 564 | SNDRV_DMA_TYPE_CONTINUOUS, |
Vinod Koul | 6cc0f4e | 2014-06-13 18:03:51 +0530 | [diff] [blame] | 565 | snd_dma_continuous_data(GFP_DMA), |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 566 | SST_MIN_BUFFER, SST_MAX_BUFFER); |
| 567 | if (retval) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 568 | dev_err(rtd->dev, "dma buffer allocationf fail\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 569 | return retval; |
| 570 | } |
| 571 | } |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 572 | return retval; |
| 573 | } |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 574 | |
Vinod Koul | d8499c9 | 2014-08-04 15:15:55 +0530 | [diff] [blame] | 575 | static int sst_soc_probe(struct snd_soc_platform *platform) |
| 576 | { |
| 577 | return sst_dsp_init_v2_dpcm(platform); |
| 578 | } |
| 579 | |
| 580 | static struct snd_soc_platform_driver sst_soc_platform_drv = { |
| 581 | .probe = sst_soc_probe, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 582 | .ops = &sst_platform_ops, |
Vinod Koul | c514a91 | 2012-08-16 17:10:42 +0530 | [diff] [blame] | 583 | .compr_ops = &sst_platform_compr_ops, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 584 | .pcm_new = sst_pcm_new, |
| 585 | .pcm_free = sst_pcm_free, |
| 586 | }; |
| 587 | |
Vinod Koul | 2b4c78d | 2014-05-05 22:19:25 +0530 | [diff] [blame] | 588 | static const struct snd_soc_component_driver sst_component = { |
| 589 | .name = "sst", |
| 590 | }; |
| 591 | |
| 592 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 593 | static int sst_platform_probe(struct platform_device *pdev) |
| 594 | { |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 595 | struct sst_data *drv; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 596 | int ret; |
Subhransu S. Prusty | 2741d43 | 2014-07-30 18:39:05 +0530 | [diff] [blame] | 597 | struct sst_platform_data *pdata; |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 598 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 599 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
Subhransu S. Prusty | 19a23a5 | 2014-07-30 18:36:00 +0530 | [diff] [blame] | 600 | if (drv == NULL) { |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 601 | return -ENOMEM; |
| 602 | } |
| 603 | |
Subhransu S. Prusty | 2741d43 | 2014-07-30 18:39:05 +0530 | [diff] [blame] | 604 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 605 | if (pdata == NULL) { |
Subhransu S. Prusty | 2741d43 | 2014-07-30 18:39:05 +0530 | [diff] [blame] | 606 | return -ENOMEM; |
| 607 | } |
| 608 | |
Vinod Koul | 61b165c | 2014-06-13 18:03:56 +0530 | [diff] [blame] | 609 | pdata->pdev_strm_map = dpcm_strm_map; |
| 610 | pdata->strm_map_size = ARRAY_SIZE(dpcm_strm_map); |
| 611 | drv->pdata = pdata; |
| 612 | mutex_init(&drv->lock); |
| 613 | dev_set_drvdata(&pdev->dev, drv); |
| 614 | |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 615 | ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv); |
| 616 | if (ret) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 617 | dev_err(&pdev->dev, "registering soc platform failed\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 618 | return ret; |
| 619 | } |
Harsha Priya | 5c68536 | 2011-01-11 14:50:35 +0530 | [diff] [blame] | 620 | |
Kuninori Morimoto | b1c3686 | 2013-03-21 03:32:50 -0700 | [diff] [blame] | 621 | ret = snd_soc_register_component(&pdev->dev, &sst_component, |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 622 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); |
| 623 | if (ret) { |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 624 | dev_err(&pdev->dev, "registering cpu dais failed\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 625 | snd_soc_unregister_platform(&pdev->dev); |
| 626 | } |
| 627 | return ret; |
| 628 | } |
| 629 | |
| 630 | static int sst_platform_remove(struct platform_device *pdev) |
| 631 | { |
| 632 | |
Kuninori Morimoto | b1c3686 | 2013-03-21 03:32:50 -0700 | [diff] [blame] | 633 | snd_soc_unregister_component(&pdev->dev); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 634 | snd_soc_unregister_platform(&pdev->dev); |
Subhransu S. Prusty | 0202475 | 2014-09-02 18:05:56 +0530 | [diff] [blame] | 635 | dev_dbg(&pdev->dev, "sst_platform_remove success\n"); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | static struct platform_driver sst_platform_driver = { |
| 640 | .driver = { |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 641 | .name = "sst-mfld-platform", |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 642 | .owner = THIS_MODULE, |
| 643 | }, |
| 644 | .probe = sst_platform_probe, |
| 645 | .remove = sst_platform_remove, |
| 646 | }; |
| 647 | |
Axel Lin | 29515d6 | 2011-11-24 11:51:56 +0800 | [diff] [blame] | 648 | module_platform_driver(sst_platform_driver); |
Vinod Koul | d927fda | 2011-01-04 20:16:32 +0530 | [diff] [blame] | 649 | |
| 650 | MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver"); |
| 651 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); |
| 652 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); |
| 653 | MODULE_LICENSE("GPL v2"); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 654 | MODULE_ALIAS("platform:sst-mfld-platform"); |