blob: d0bc328538c9dc26dfa7cef03eacb5dbbd295173 [file] [log] [blame]
Vinod Kould927fda2011-01-04 20:16:32 +05301/*
Mark Browna4b12992014-03-12 23:04:35 +00002 * sst_mfld_platform.c - Intel MID Platform driver
Vinod Kould927fda2011-01-04 20:16:32 +05303 *
Vinod Koul0cd57512013-03-29 23:41:42 +05304 * Copyright (C) 2010-2013 Intel Corp
Vinod Kould927fda2011-01-04 20:16:32 +05305 * 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 Kould927fda2011-01-04 20:16:32 +053018 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vinod Kould927fda2011-01-04 20:16:32 +053019 */
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include <linux/slab.h>
23#include <linux/io.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040024#include <linux/module.h>
Vinod Kould927fda2011-01-04 20:16:32 +053025#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
Vinod Koulc514a912012-08-16 17:10:42 +053029#include <sound/compress_driver.h>
Mark Browna4b12992014-03-12 23:04:35 +000030#include "sst-mfld-platform.h"
Vinod Kould927fda2011-01-04 20:16:32 +053031
Vinod Koul4b68b4e2014-05-05 14:27:50 +053032struct sst_device *sst;
Vinod Koul03c33042011-12-05 19:13:41 +053033static DEFINE_MUTEX(sst_lock);
Vinod Koul4b68b4e2014-05-05 14:27:50 +053034extern struct snd_compr_ops sst_platform_compr_ops;
Vinod Koul03c33042011-12-05 19:13:41 +053035
36int sst_register_dsp(struct sst_device *dev)
37{
Takashi Iwai656a22a2013-11-05 18:40:01 +010038 if (WARN_ON(!dev))
39 return -EINVAL;
Vinod Koul03c33042011-12-05 19:13:41 +053040 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}
54EXPORT_SYMBOL_GPL(sst_register_dsp);
55
56int sst_unregister_dsp(struct sst_device *dev)
57{
Takashi Iwai656a22a2013-11-05 18:40:01 +010058 if (WARN_ON(!dev))
59 return -EINVAL;
Vinod Koul03c33042011-12-05 19:13:41 +053060 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}
76EXPORT_SYMBOL_GPL(sst_unregister_dsp);
77
Vinod Kould927fda2011-01-04 20:16:32 +053078static 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 Kould927fda2011-01-04 20:16:32 +053087 .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 Lind1b73282011-09-27 10:38:50 +080096static struct snd_soc_dai_driver sst_platform_dai[] = {
Vinod Kould927fda2011-01-04 20:16:32 +053097{
Vinod Koul5106f5a2014-05-15 21:38:15 +053098 .name = "Headset-cpu-dai",
Vinod Kould927fda2011-01-04 20:16:32 +053099 .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 Priyaa7bffdf2011-01-28 22:27:26 +0530106 .capture = {
107 .channels_min = 1,
108 .channels_max = 5,
109 .rates = SNDRV_PCM_RATE_48000,
110 .formats = SNDRV_PCM_FMTBIT_S24_LE,
111 },
Vinod Kould927fda2011-01-04 20:16:32 +0530112},
113{
Vinod Koulc514a912012-08-16 17:10:42 +0530114 .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 Kould927fda2011-01-04 20:16:32 +0530123};
Harsha Priya5c685362011-01-11 14:50:35 +0530124
Vinod Kould927fda2011-01-04 20:16:32 +0530125/* helper functions */
Vinod Koul4496ffa2014-05-05 14:27:49 +0530126void sst_set_stream_status(struct sst_runtime_stream *stream,
Harsha Priya5c685362011-01-11 14:50:35 +0530127 int state)
128{
Lu Guanqund89b0a12011-04-08 15:38:48 +0800129 unsigned long flags;
130 spin_lock_irqsave(&stream->status_lock, flags);
Harsha Priya5c685362011-01-11 14:50:35 +0530131 stream->stream_status = state;
Lu Guanqund89b0a12011-04-08 15:38:48 +0800132 spin_unlock_irqrestore(&stream->status_lock, flags);
Harsha Priya5c685362011-01-11 14:50:35 +0530133}
134
135static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
136{
137 int state;
Lu Guanqund89b0a12011-04-08 15:38:48 +0800138 unsigned long flags;
Harsha Priya5c685362011-01-11 14:50:35 +0530139
Lu Guanqund89b0a12011-04-08 15:38:48 +0800140 spin_lock_irqsave(&stream->status_lock, flags);
Harsha Priya5c685362011-01-11 14:50:35 +0530141 state = stream->stream_status;
Lu Guanqund89b0a12011-04-08 15:38:48 +0800142 spin_unlock_irqrestore(&stream->status_lock, flags);
Harsha Priya5c685362011-01-11 14:50:35 +0530143 return state;
144}
145
146static void sst_fill_pcm_params(struct snd_pcm_substream *substream,
Vinod Koul03c33042011-12-05 19:13:41 +0530147 struct sst_pcm_params *param)
Harsha Priya5c685362011-01-11 14:50:35 +0530148{
149
Vinod Koul03c33042011-12-05 19:13:41 +0530150 param->codec = SST_CODEC_TYPE_PCM;
151 param->num_chan = (u8) substream->runtime->channels;
152 param->pcm_wd_sz = substream->runtime->sample_bits;
153 param->reserved = 0;
154 param->sfreq = substream->runtime->rate;
155 param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream);
156 param->period_count = substream->runtime->period_size;
157 param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area);
158 pr_debug("period_cnt = %d\n", param->period_count);
159 pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz);
Harsha Priya5c685362011-01-11 14:50:35 +0530160}
161
Vinod Kould927fda2011-01-04 20:16:32 +0530162static int sst_platform_alloc_stream(struct snd_pcm_substream *substream)
163{
164 struct sst_runtime_stream *stream =
165 substream->runtime->private_data;
Vinod Koul03c33042011-12-05 19:13:41 +0530166 struct sst_pcm_params param = {0};
167 struct sst_stream_params str_params = {0};
Vinod Kould927fda2011-01-04 20:16:32 +0530168 int ret_val;
169
170 /* set codec params and inform SST driver the same */
Harsha Priya5c685362011-01-11 14:50:35 +0530171 sst_fill_pcm_params(substream, &param);
Vinod Kould927fda2011-01-04 20:16:32 +0530172 substream->runtime->dma_area = substream->dma_buffer.area;
Vinod Kould927fda2011-01-04 20:16:32 +0530173 str_params.sparams = param;
Vinod Koul03c33042011-12-05 19:13:41 +0530174 str_params.codec = param.codec;
Vinod Kould927fda2011-01-04 20:16:32 +0530175 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
176 str_params.ops = STREAM_OPS_PLAYBACK;
177 str_params.device_type = substream->pcm->device + 1;
178 pr_debug("Playbck stream,Device %d\n",
179 substream->pcm->device);
180 } else {
181 str_params.ops = STREAM_OPS_CAPTURE;
182 str_params.device_type = SND_SST_DEVICE_CAPTURE;
183 pr_debug("Capture stream,Device %d\n",
184 substream->pcm->device);
185 }
Vinod Koul03c33042011-12-05 19:13:41 +0530186 ret_val = stream->ops->open(&str_params);
Vinod Kould927fda2011-01-04 20:16:32 +0530187 pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
188 if (ret_val < 0)
189 return ret_val;
190
191 stream->stream_info.str_id = ret_val;
192 pr_debug("str id : %d\n", stream->stream_info.str_id);
Vinod Kould927fda2011-01-04 20:16:32 +0530193 return ret_val;
194}
195
Vinod Kould927fda2011-01-04 20:16:32 +0530196static void sst_period_elapsed(void *mad_substream)
197{
198 struct snd_pcm_substream *substream = mad_substream;
199 struct sst_runtime_stream *stream;
Harsha Priya5c685362011-01-11 14:50:35 +0530200 int status;
Vinod Kould927fda2011-01-04 20:16:32 +0530201
202 if (!substream || !substream->runtime)
203 return;
204 stream = substream->runtime->private_data;
205 if (!stream)
206 return;
Harsha Priya5c685362011-01-11 14:50:35 +0530207 status = sst_get_stream_status(stream);
208 if (status != SST_PLATFORM_RUNNING)
Vinod Kould927fda2011-01-04 20:16:32 +0530209 return;
Vinod Kould927fda2011-01-04 20:16:32 +0530210 snd_pcm_period_elapsed(substream);
Vinod Kould927fda2011-01-04 20:16:32 +0530211}
212
213static int sst_platform_init_stream(struct snd_pcm_substream *substream)
214{
215 struct sst_runtime_stream *stream =
216 substream->runtime->private_data;
217 int ret_val;
218
219 pr_debug("setting buffer ptr param\n");
Harsha Priya5c685362011-01-11 14:50:35 +0530220 sst_set_stream_status(stream, SST_PLATFORM_INIT);
Vinod Kould927fda2011-01-04 20:16:32 +0530221 stream->stream_info.period_elapsed = sst_period_elapsed;
222 stream->stream_info.mad_substream = substream;
223 stream->stream_info.buffer_ptr = 0;
224 stream->stream_info.sfreq = substream->runtime->rate;
Vinod Koul03c33042011-12-05 19:13:41 +0530225 ret_val = stream->ops->device_control(
Harsha Priyaa2117012011-01-11 14:50:59 +0530226 SST_SND_STREAM_INIT, &stream->stream_info);
Vinod Kould927fda2011-01-04 20:16:32 +0530227 if (ret_val)
228 pr_err("control_set ret error %d\n", ret_val);
229 return ret_val;
230
231}
232/* end -- helper functions */
233
Vinod Koul5106f5a2014-05-15 21:38:15 +0530234static int sst_platform_open(struct snd_pcm_substream *substream)
Vinod Kould927fda2011-01-04 20:16:32 +0530235{
Lu Guanqun22be5042011-09-06 15:21:38 +0800236 struct snd_pcm_runtime *runtime = substream->runtime;
Vinod Kould927fda2011-01-04 20:16:32 +0530237 struct sst_runtime_stream *stream;
Joerg Roedelc45471ea2011-12-15 18:24:54 +0100238 int ret_val;
Vinod Kould927fda2011-01-04 20:16:32 +0530239
Vinod Koul5106f5a2014-05-15 21:38:15 +0530240 pr_debug("sst_platform_open called\n");
Lu Guanqun22be5042011-09-06 15:21:38 +0800241
242 snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw);
Lu Guanqun283e42e2011-09-06 15:21:43 +0800243 ret_val = snd_pcm_hw_constraint_integer(runtime,
244 SNDRV_PCM_HW_PARAM_PERIODS);
245 if (ret_val < 0)
246 return ret_val;
Lu Guanqun22be5042011-09-06 15:21:38 +0800247
Vinod Kould927fda2011-01-04 20:16:32 +0530248 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
249 if (!stream)
250 return -ENOMEM;
Vinod Kould927fda2011-01-04 20:16:32 +0530251 spin_lock_init(&stream->status_lock);
Vinod Koul03c33042011-12-05 19:13:41 +0530252
253 /* get the sst ops */
254 mutex_lock(&sst_lock);
255 if (!sst) {
256 pr_err("no device available to run\n");
257 mutex_unlock(&sst_lock);
258 kfree(stream);
259 return -ENODEV;
260 }
261 if (!try_module_get(sst->dev->driver->owner)) {
262 mutex_unlock(&sst_lock);
263 kfree(stream);
264 return -ENODEV;
265 }
266 stream->ops = sst->ops;
267 mutex_unlock(&sst_lock);
268
Vinod Kould927fda2011-01-04 20:16:32 +0530269 stream->stream_info.str_id = 0;
Harsha Priya5c685362011-01-11 14:50:35 +0530270 sst_set_stream_status(stream, SST_PLATFORM_INIT);
Vinod Kould927fda2011-01-04 20:16:32 +0530271 stream->stream_info.mad_substream = substream;
272 /* allocate memory for SST API set */
Vinod Kould927fda2011-01-04 20:16:32 +0530273 runtime->private_data = stream;
Lu Guanqun283e42e2011-09-06 15:21:43 +0800274
275 return 0;
Vinod Kould927fda2011-01-04 20:16:32 +0530276}
277
Vinod Koul5106f5a2014-05-15 21:38:15 +0530278static int sst_platform_close(struct snd_pcm_substream *substream)
Vinod Kould927fda2011-01-04 20:16:32 +0530279{
280 struct sst_runtime_stream *stream;
281 int ret_val = 0, str_id;
282
Vinod Koul5106f5a2014-05-15 21:38:15 +0530283 pr_debug("sst_platform_close called\n");
Vinod Kould927fda2011-01-04 20:16:32 +0530284 stream = substream->runtime->private_data;
285 str_id = stream->stream_info.str_id;
Vinod Kould927fda2011-01-04 20:16:32 +0530286 if (str_id)
Vinod Koul03c33042011-12-05 19:13:41 +0530287 ret_val = stream->ops->close(str_id);
288 module_put(sst->dev->driver->owner);
Vinod Kould927fda2011-01-04 20:16:32 +0530289 kfree(stream);
290 return ret_val;
291}
292
Vinod Koul5106f5a2014-05-15 21:38:15 +0530293static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream)
Vinod Kould927fda2011-01-04 20:16:32 +0530294{
295 struct sst_runtime_stream *stream;
296 int ret_val = 0, str_id;
297
Vinod Koul5106f5a2014-05-15 21:38:15 +0530298 pr_debug("sst_platform_pcm_prepare called\n");
Vinod Kould927fda2011-01-04 20:16:32 +0530299 stream = substream->runtime->private_data;
300 str_id = stream->stream_info.str_id;
301 if (stream->stream_info.str_id) {
Vinod Koul03c33042011-12-05 19:13:41 +0530302 ret_val = stream->ops->device_control(
303 SST_SND_DROP, &str_id);
Vinod Kould927fda2011-01-04 20:16:32 +0530304 return ret_val;
305 }
306
307 ret_val = sst_platform_alloc_stream(substream);
308 if (ret_val < 0)
309 return ret_val;
310 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
311 "%d", stream->stream_info.str_id);
312
313 ret_val = sst_platform_init_stream(substream);
314 if (ret_val)
315 return ret_val;
316 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
317 return ret_val;
318}
319
Vinod Koul5106f5a2014-05-15 21:38:15 +0530320static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
Vinod Kould927fda2011-01-04 20:16:32 +0530321 int cmd)
322{
323 int ret_val = 0, str_id;
324 struct sst_runtime_stream *stream;
Harsha Priyaa2117012011-01-11 14:50:59 +0530325 int str_cmd, status;
Vinod Kould927fda2011-01-04 20:16:32 +0530326
Vinod Koul5106f5a2014-05-15 21:38:15 +0530327 pr_debug("sst_platform_pcm_trigger called\n");
Vinod Kould927fda2011-01-04 20:16:32 +0530328 stream = substream->runtime->private_data;
Vinod Kould927fda2011-01-04 20:16:32 +0530329 str_id = stream->stream_info.str_id;
Vinod Kould927fda2011-01-04 20:16:32 +0530330 switch (cmd) {
331 case SNDRV_PCM_TRIGGER_START:
332 pr_debug("sst: Trigger Start\n");
Harsha Priyaa2117012011-01-11 14:50:59 +0530333 str_cmd = SST_SND_START;
334 status = SST_PLATFORM_RUNNING;
Vinod Kould927fda2011-01-04 20:16:32 +0530335 stream->stream_info.mad_substream = substream;
336 break;
337 case SNDRV_PCM_TRIGGER_STOP:
338 pr_debug("sst: in stop\n");
Harsha Priyaa2117012011-01-11 14:50:59 +0530339 str_cmd = SST_SND_DROP;
340 status = SST_PLATFORM_DROPPED;
Vinod Kould927fda2011-01-04 20:16:32 +0530341 break;
342 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
343 pr_debug("sst: in pause\n");
Harsha Priyaa2117012011-01-11 14:50:59 +0530344 str_cmd = SST_SND_PAUSE;
345 status = SST_PLATFORM_PAUSED;
Vinod Kould927fda2011-01-04 20:16:32 +0530346 break;
347 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
348 pr_debug("sst: in pause release\n");
Harsha Priyaa2117012011-01-11 14:50:59 +0530349 str_cmd = SST_SND_RESUME;
350 status = SST_PLATFORM_RUNNING;
Vinod Kould927fda2011-01-04 20:16:32 +0530351 break;
352 default:
Harsha Priyaa2117012011-01-11 14:50:59 +0530353 return -EINVAL;
Vinod Kould927fda2011-01-04 20:16:32 +0530354 }
Vinod Koul03c33042011-12-05 19:13:41 +0530355 ret_val = stream->ops->device_control(str_cmd, &str_id);
Harsha Priyaa2117012011-01-11 14:50:59 +0530356 if (!ret_val)
357 sst_set_stream_status(stream, status);
358
Vinod Kould927fda2011-01-04 20:16:32 +0530359 return ret_val;
360}
361
362
Vinod Koul5106f5a2014-05-15 21:38:15 +0530363static snd_pcm_uframes_t sst_platform_pcm_pointer
Vinod Kould927fda2011-01-04 20:16:32 +0530364 (struct snd_pcm_substream *substream)
365{
366 struct sst_runtime_stream *stream;
Harsha Priya5c685362011-01-11 14:50:35 +0530367 int ret_val, status;
Vinod Kould927fda2011-01-04 20:16:32 +0530368 struct pcm_stream_info *str_info;
369
Vinod Kould927fda2011-01-04 20:16:32 +0530370 stream = substream->runtime->private_data;
Harsha Priya5c685362011-01-11 14:50:35 +0530371 status = sst_get_stream_status(stream);
372 if (status == SST_PLATFORM_INIT)
Vinod Kould927fda2011-01-04 20:16:32 +0530373 return 0;
Vinod Kould927fda2011-01-04 20:16:32 +0530374 str_info = &stream->stream_info;
Vinod Koul03c33042011-12-05 19:13:41 +0530375 ret_val = stream->ops->device_control(
Vinod Kould927fda2011-01-04 20:16:32 +0530376 SST_SND_BUFFER_POINTER, str_info);
377 if (ret_val) {
378 pr_err("sst: error code = %d\n", ret_val);
379 return ret_val;
380 }
Vinod Kould927fda2011-01-04 20:16:32 +0530381 return stream->stream_info.buffer_ptr;
382}
383
Vinod Koul5106f5a2014-05-15 21:38:15 +0530384static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream,
Vinod Koul5b499f82011-02-15 18:28:54 +0530385 struct snd_pcm_hw_params *params)
386{
387 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
388 memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
389
390 return 0;
391}
Vinod Kould927fda2011-01-04 20:16:32 +0530392
Vinod Koul5106f5a2014-05-15 21:38:15 +0530393static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream)
xingchao9ab88432011-04-27 16:58:54 -0400394{
395 return snd_pcm_lib_free_pages(substream);
396}
397
Vinod Kould927fda2011-01-04 20:16:32 +0530398static struct snd_pcm_ops sst_platform_ops = {
Vinod Koul5106f5a2014-05-15 21:38:15 +0530399 .open = sst_platform_open,
400 .close = sst_platform_close,
Vinod Kould927fda2011-01-04 20:16:32 +0530401 .ioctl = snd_pcm_lib_ioctl,
Vinod Koul5106f5a2014-05-15 21:38:15 +0530402 .prepare = sst_platform_pcm_prepare,
403 .trigger = sst_platform_pcm_trigger,
404 .pointer = sst_platform_pcm_pointer,
405 .hw_params = sst_platform_pcm_hw_params,
406 .hw_free = sst_platform_pcm_hw_free,
Vinod Kould927fda2011-01-04 20:16:32 +0530407};
408
409static void sst_pcm_free(struct snd_pcm *pcm)
410{
411 pr_debug("sst_pcm_free called\n");
412 snd_pcm_lib_preallocate_free_for_all(pcm);
413}
414
Axel Lin8faa8c12011-12-13 17:13:45 +0800415static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
Vinod Kould927fda2011-01-04 20:16:32 +0530416{
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100417 struct snd_pcm *pcm = rtd->pcm;
Vinod Kould927fda2011-01-04 20:16:32 +0530418 int retval = 0;
419
420 pr_debug("sst_pcm_new called\n");
Joachim Eastwood25e9e752012-01-01 01:58:44 +0100421 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
422 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
Vinod Kould927fda2011-01-04 20:16:32 +0530423 retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
424 SNDRV_DMA_TYPE_CONTINUOUS,
425 snd_dma_continuous_data(GFP_KERNEL),
426 SST_MIN_BUFFER, SST_MAX_BUFFER);
427 if (retval) {
428 pr_err("dma buffer allocationf fail\n");
429 return retval;
430 }
431 }
Vinod Kould927fda2011-01-04 20:16:32 +0530432 return retval;
433}
Vinod Koulc514a912012-08-16 17:10:42 +0530434
Axel Lin8faa8c12011-12-13 17:13:45 +0800435static struct snd_soc_platform_driver sst_soc_platform_drv = {
Vinod Kould927fda2011-01-04 20:16:32 +0530436 .ops = &sst_platform_ops,
Vinod Koulc514a912012-08-16 17:10:42 +0530437 .compr_ops = &sst_platform_compr_ops,
Vinod Kould927fda2011-01-04 20:16:32 +0530438 .pcm_new = sst_pcm_new,
439 .pcm_free = sst_pcm_free,
440};
441
Vinod Koul2b4c78d2014-05-05 22:19:25 +0530442static const struct snd_soc_component_driver sst_component = {
443 .name = "sst",
444};
445
446
Vinod Kould927fda2011-01-04 20:16:32 +0530447static int sst_platform_probe(struct platform_device *pdev)
448{
449 int ret;
450
451 pr_debug("sst_platform_probe called\n");
Vinod Koul03c33042011-12-05 19:13:41 +0530452 sst = NULL;
Vinod Kould927fda2011-01-04 20:16:32 +0530453 ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv);
454 if (ret) {
455 pr_err("registering soc platform failed\n");
456 return ret;
457 }
Harsha Priya5c685362011-01-11 14:50:35 +0530458
Kuninori Morimotob1c36862013-03-21 03:32:50 -0700459 ret = snd_soc_register_component(&pdev->dev, &sst_component,
Vinod Kould927fda2011-01-04 20:16:32 +0530460 sst_platform_dai, ARRAY_SIZE(sst_platform_dai));
461 if (ret) {
462 pr_err("registering cpu dais failed\n");
463 snd_soc_unregister_platform(&pdev->dev);
464 }
465 return ret;
466}
467
468static int sst_platform_remove(struct platform_device *pdev)
469{
470
Kuninori Morimotob1c36862013-03-21 03:32:50 -0700471 snd_soc_unregister_component(&pdev->dev);
Vinod Kould927fda2011-01-04 20:16:32 +0530472 snd_soc_unregister_platform(&pdev->dev);
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300473 pr_debug("sst_platform_remove success\n");
Vinod Kould927fda2011-01-04 20:16:32 +0530474 return 0;
475}
476
477static struct platform_driver sst_platform_driver = {
478 .driver = {
Mark Browna4b12992014-03-12 23:04:35 +0000479 .name = "sst-mfld-platform",
Vinod Kould927fda2011-01-04 20:16:32 +0530480 .owner = THIS_MODULE,
481 },
482 .probe = sst_platform_probe,
483 .remove = sst_platform_remove,
484};
485
Axel Lin29515d62011-11-24 11:51:56 +0800486module_platform_driver(sst_platform_driver);
Vinod Kould927fda2011-01-04 20:16:32 +0530487
488MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver");
489MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
490MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
491MODULE_LICENSE("GPL v2");
Mark Browna4b12992014-03-12 23:04:35 +0000492MODULE_ALIAS("platform:sst-mfld-platform");