Commit | Line | Data |
---|---|---|
d927fdae | 1 | /* |
a4b12990 | 2 | * sst_mfld_platform.c - Intel MID Platform driver |
d927fdae | 3 | * |
0cd5751a | 4 | * Copyright (C) 2010-2013 Intel Corp |
d927fdae VK |
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 | * | |
d927fdae | 18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
d927fdae VK |
19 | */ |
20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
21 | ||
22 | #include <linux/slab.h> | |
23 | #include <linux/io.h> | |
da155d5b | 24 | #include <linux/module.h> |
d927fdae VK |
25 | #include <sound/core.h> |
26 | #include <sound/pcm.h> | |
27 | #include <sound/pcm_params.h> | |
28 | #include <sound/soc.h> | |
c514a911 | 29 | #include <sound/compress_driver.h> |
a4b12990 | 30 | #include "sst-mfld-platform.h" |
d927fdae | 31 | |
03c33042 VK |
32 | static struct sst_device *sst; |
33 | static DEFINE_MUTEX(sst_lock); | |
34 | ||
35 | int sst_register_dsp(struct sst_device *dev) | |
36 | { | |
656a22a1 TI |
37 | if (WARN_ON(!dev)) |
38 | return -EINVAL; | |
03c33042 VK |
39 | if (!try_module_get(dev->dev->driver->owner)) |
40 | return -ENODEV; | |
41 | mutex_lock(&sst_lock); | |
42 | if (sst) { | |
43 | pr_err("we already have a device %s\n", sst->name); | |
44 | module_put(dev->dev->driver->owner); | |
45 | mutex_unlock(&sst_lock); | |
46 | return -EEXIST; | |
47 | } | |
48 | pr_debug("registering device %s\n", dev->name); | |
49 | sst = dev; | |
50 | mutex_unlock(&sst_lock); | |
51 | return 0; | |
52 | } | |
53 | EXPORT_SYMBOL_GPL(sst_register_dsp); | |
54 | ||
55 | int sst_unregister_dsp(struct sst_device *dev) | |
56 | { | |
656a22a1 TI |
57 | if (WARN_ON(!dev)) |
58 | return -EINVAL; | |
03c33042 VK |
59 | if (dev != sst) |
60 | return -EINVAL; | |
61 | ||
62 | mutex_lock(&sst_lock); | |
63 | ||
64 | if (!sst) { | |
65 | mutex_unlock(&sst_lock); | |
66 | return -EIO; | |
67 | } | |
68 | ||
69 | module_put(sst->dev->driver->owner); | |
70 | pr_debug("unreg %s\n", sst->name); | |
71 | sst = NULL; | |
72 | mutex_unlock(&sst_lock); | |
73 | return 0; | |
74 | } | |
75 | EXPORT_SYMBOL_GPL(sst_unregister_dsp); | |
76 | ||
d927fdae VK |
77 | static struct snd_pcm_hardware sst_platform_pcm_hw = { |
78 | .info = (SNDRV_PCM_INFO_INTERLEAVED | | |
79 | SNDRV_PCM_INFO_DOUBLE | | |
80 | SNDRV_PCM_INFO_PAUSE | | |
81 | SNDRV_PCM_INFO_RESUME | | |
82 | SNDRV_PCM_INFO_MMAP| | |
83 | SNDRV_PCM_INFO_MMAP_VALID | | |
84 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | |
85 | SNDRV_PCM_INFO_SYNC_START), | |
d927fdae VK |
86 | .buffer_bytes_max = SST_MAX_BUFFER, |
87 | .period_bytes_min = SST_MIN_PERIOD_BYTES, | |
88 | .period_bytes_max = SST_MAX_PERIOD_BYTES, | |
89 | .periods_min = SST_MIN_PERIODS, | |
90 | .periods_max = SST_MAX_PERIODS, | |
91 | .fifo_size = SST_FIFO_SIZE, | |
92 | }; | |
93 | ||
94 | /* MFLD - MSIC */ | |
d1b73287 | 95 | static struct snd_soc_dai_driver sst_platform_dai[] = { |
d927fdae VK |
96 | { |
97 | .name = "Headset-cpu-dai", | |
98 | .id = 0, | |
99 | .playback = { | |
100 | .channels_min = SST_STEREO, | |
101 | .channels_max = SST_STEREO, | |
102 | .rates = SNDRV_PCM_RATE_48000, | |
103 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
104 | }, | |
a7bffdf7 HP |
105 | .capture = { |
106 | .channels_min = 1, | |
107 | .channels_max = 5, | |
108 | .rates = SNDRV_PCM_RATE_48000, | |
109 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
110 | }, | |
d927fdae VK |
111 | }, |
112 | { | |
113 | .name = "Speaker-cpu-dai", | |
114 | .id = 1, | |
115 | .playback = { | |
116 | .channels_min = SST_MONO, | |
117 | .channels_max = SST_STEREO, | |
118 | .rates = SNDRV_PCM_RATE_48000, | |
119 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
120 | }, | |
121 | }, | |
122 | { | |
123 | .name = "Vibra1-cpu-dai", | |
124 | .id = 2, | |
125 | .playback = { | |
126 | .channels_min = SST_MONO, | |
127 | .channels_max = SST_MONO, | |
128 | .rates = SNDRV_PCM_RATE_48000, | |
129 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
130 | }, | |
131 | }, | |
132 | { | |
133 | .name = "Vibra2-cpu-dai", | |
134 | .id = 3, | |
135 | .playback = { | |
136 | .channels_min = SST_MONO, | |
137 | .channels_max = SST_STEREO, | |
138 | .rates = SNDRV_PCM_RATE_48000, | |
139 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
140 | }, | |
141 | }, | |
c514a911 VK |
142 | { |
143 | .name = "Compress-cpu-dai", | |
144 | .compress_dai = 1, | |
145 | .playback = { | |
146 | .channels_min = SST_STEREO, | |
147 | .channels_max = SST_STEREO, | |
148 | .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000, | |
149 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
150 | }, | |
151 | }, | |
d927fdae | 152 | }; |
5c68536f | 153 | |
d927fdae | 154 | /* helper functions */ |
4496ffab | 155 | void sst_set_stream_status(struct sst_runtime_stream *stream, |
5c68536f HP |
156 | int state) |
157 | { | |
d89b0a13 LG |
158 | unsigned long flags; |
159 | spin_lock_irqsave(&stream->status_lock, flags); | |
5c68536f | 160 | stream->stream_status = state; |
d89b0a13 | 161 | spin_unlock_irqrestore(&stream->status_lock, flags); |
5c68536f HP |
162 | } |
163 | ||
164 | static inline int sst_get_stream_status(struct sst_runtime_stream *stream) | |
165 | { | |
166 | int state; | |
d89b0a13 | 167 | unsigned long flags; |
5c68536f | 168 | |
d89b0a13 | 169 | spin_lock_irqsave(&stream->status_lock, flags); |
5c68536f | 170 | state = stream->stream_status; |
d89b0a13 | 171 | spin_unlock_irqrestore(&stream->status_lock, flags); |
5c68536f HP |
172 | return state; |
173 | } | |
174 | ||
175 | static void sst_fill_pcm_params(struct snd_pcm_substream *substream, | |
03c33042 | 176 | struct sst_pcm_params *param) |
5c68536f HP |
177 | { |
178 | ||
03c33042 VK |
179 | param->codec = SST_CODEC_TYPE_PCM; |
180 | param->num_chan = (u8) substream->runtime->channels; | |
181 | param->pcm_wd_sz = substream->runtime->sample_bits; | |
182 | param->reserved = 0; | |
183 | param->sfreq = substream->runtime->rate; | |
184 | param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream); | |
185 | param->period_count = substream->runtime->period_size; | |
186 | param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area); | |
187 | pr_debug("period_cnt = %d\n", param->period_count); | |
188 | pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz); | |
5c68536f HP |
189 | } |
190 | ||
d927fdae VK |
191 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) |
192 | { | |
193 | struct sst_runtime_stream *stream = | |
194 | substream->runtime->private_data; | |
03c33042 VK |
195 | struct sst_pcm_params param = {0}; |
196 | struct sst_stream_params str_params = {0}; | |
d927fdae VK |
197 | int ret_val; |
198 | ||
199 | /* set codec params and inform SST driver the same */ | |
5c68536f | 200 | sst_fill_pcm_params(substream, ¶m); |
d927fdae | 201 | substream->runtime->dma_area = substream->dma_buffer.area; |
d927fdae | 202 | str_params.sparams = param; |
03c33042 | 203 | str_params.codec = param.codec; |
d927fdae VK |
204 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
205 | str_params.ops = STREAM_OPS_PLAYBACK; | |
206 | str_params.device_type = substream->pcm->device + 1; | |
207 | pr_debug("Playbck stream,Device %d\n", | |
208 | substream->pcm->device); | |
209 | } else { | |
210 | str_params.ops = STREAM_OPS_CAPTURE; | |
211 | str_params.device_type = SND_SST_DEVICE_CAPTURE; | |
212 | pr_debug("Capture stream,Device %d\n", | |
213 | substream->pcm->device); | |
214 | } | |
03c33042 | 215 | ret_val = stream->ops->open(&str_params); |
d927fdae VK |
216 | pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val); |
217 | if (ret_val < 0) | |
218 | return ret_val; | |
219 | ||
220 | stream->stream_info.str_id = ret_val; | |
221 | pr_debug("str id : %d\n", stream->stream_info.str_id); | |
d927fdae VK |
222 | return ret_val; |
223 | } | |
224 | ||
d927fdae VK |
225 | static void sst_period_elapsed(void *mad_substream) |
226 | { | |
227 | struct snd_pcm_substream *substream = mad_substream; | |
228 | struct sst_runtime_stream *stream; | |
5c68536f | 229 | int status; |
d927fdae VK |
230 | |
231 | if (!substream || !substream->runtime) | |
232 | return; | |
233 | stream = substream->runtime->private_data; | |
234 | if (!stream) | |
235 | return; | |
5c68536f HP |
236 | status = sst_get_stream_status(stream); |
237 | if (status != SST_PLATFORM_RUNNING) | |
d927fdae | 238 | return; |
d927fdae | 239 | snd_pcm_period_elapsed(substream); |
d927fdae VK |
240 | } |
241 | ||
242 | static int sst_platform_init_stream(struct snd_pcm_substream *substream) | |
243 | { | |
244 | struct sst_runtime_stream *stream = | |
245 | substream->runtime->private_data; | |
246 | int ret_val; | |
247 | ||
248 | pr_debug("setting buffer ptr param\n"); | |
5c68536f | 249 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
d927fdae VK |
250 | stream->stream_info.period_elapsed = sst_period_elapsed; |
251 | stream->stream_info.mad_substream = substream; | |
252 | stream->stream_info.buffer_ptr = 0; | |
253 | stream->stream_info.sfreq = substream->runtime->rate; | |
03c33042 | 254 | ret_val = stream->ops->device_control( |
a211701e | 255 | SST_SND_STREAM_INIT, &stream->stream_info); |
d927fdae VK |
256 | if (ret_val) |
257 | pr_err("control_set ret error %d\n", ret_val); | |
258 | return ret_val; | |
259 | ||
260 | } | |
261 | /* end -- helper functions */ | |
262 | ||
263 | static int sst_platform_open(struct snd_pcm_substream *substream) | |
264 | { | |
22be504a | 265 | struct snd_pcm_runtime *runtime = substream->runtime; |
d927fdae | 266 | struct sst_runtime_stream *stream; |
c45471ea | 267 | int ret_val; |
d927fdae VK |
268 | |
269 | pr_debug("sst_platform_open called\n"); | |
22be504a LG |
270 | |
271 | snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw); | |
283e42e0 LG |
272 | ret_val = snd_pcm_hw_constraint_integer(runtime, |
273 | SNDRV_PCM_HW_PARAM_PERIODS); | |
274 | if (ret_val < 0) | |
275 | return ret_val; | |
22be504a | 276 | |
d927fdae VK |
277 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
278 | if (!stream) | |
279 | return -ENOMEM; | |
d927fdae | 280 | spin_lock_init(&stream->status_lock); |
03c33042 VK |
281 | |
282 | /* get the sst ops */ | |
283 | mutex_lock(&sst_lock); | |
284 | if (!sst) { | |
285 | pr_err("no device available to run\n"); | |
286 | mutex_unlock(&sst_lock); | |
d927fdae | 287 | kfree(stream); |
03c33042 | 288 | return -ENODEV; |
d927fdae | 289 | } |
03c33042 VK |
290 | if (!try_module_get(sst->dev->driver->owner)) { |
291 | mutex_unlock(&sst_lock); | |
83a3fd3c | 292 | kfree(stream); |
03c33042 | 293 | return -ENODEV; |
d927fdae | 294 | } |
03c33042 VK |
295 | stream->ops = sst->ops; |
296 | mutex_unlock(&sst_lock); | |
297 | ||
298 | stream->stream_info.str_id = 0; | |
299 | sst_set_stream_status(stream, SST_PLATFORM_INIT); | |
300 | stream->stream_info.mad_substream = substream; | |
301 | /* allocate memory for SST API set */ | |
d927fdae | 302 | runtime->private_data = stream; |
283e42e0 LG |
303 | |
304 | return 0; | |
d927fdae VK |
305 | } |
306 | ||
307 | static int sst_platform_close(struct snd_pcm_substream *substream) | |
308 | { | |
309 | struct sst_runtime_stream *stream; | |
310 | int ret_val = 0, str_id; | |
311 | ||
312 | pr_debug("sst_platform_close called\n"); | |
d927fdae VK |
313 | stream = substream->runtime->private_data; |
314 | str_id = stream->stream_info.str_id; | |
d927fdae | 315 | if (str_id) |
03c33042 VK |
316 | ret_val = stream->ops->close(str_id); |
317 | module_put(sst->dev->driver->owner); | |
d927fdae VK |
318 | kfree(stream); |
319 | return ret_val; | |
320 | } | |
321 | ||
322 | static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream) | |
323 | { | |
324 | struct sst_runtime_stream *stream; | |
325 | int ret_val = 0, str_id; | |
326 | ||
327 | pr_debug("sst_platform_pcm_prepare called\n"); | |
d927fdae VK |
328 | stream = substream->runtime->private_data; |
329 | str_id = stream->stream_info.str_id; | |
330 | if (stream->stream_info.str_id) { | |
03c33042 VK |
331 | ret_val = stream->ops->device_control( |
332 | SST_SND_DROP, &str_id); | |
d927fdae VK |
333 | return ret_val; |
334 | } | |
335 | ||
336 | ret_val = sst_platform_alloc_stream(substream); | |
337 | if (ret_val < 0) | |
338 | return ret_val; | |
339 | snprintf(substream->pcm->id, sizeof(substream->pcm->id), | |
340 | "%d", stream->stream_info.str_id); | |
341 | ||
342 | ret_val = sst_platform_init_stream(substream); | |
343 | if (ret_val) | |
344 | return ret_val; | |
345 | substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER; | |
346 | return ret_val; | |
347 | } | |
348 | ||
349 | static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |
350 | int cmd) | |
351 | { | |
352 | int ret_val = 0, str_id; | |
353 | struct sst_runtime_stream *stream; | |
a211701e | 354 | int str_cmd, status; |
d927fdae VK |
355 | |
356 | pr_debug("sst_platform_pcm_trigger called\n"); | |
d927fdae | 357 | stream = substream->runtime->private_data; |
d927fdae | 358 | str_id = stream->stream_info.str_id; |
d927fdae VK |
359 | switch (cmd) { |
360 | case SNDRV_PCM_TRIGGER_START: | |
361 | pr_debug("sst: Trigger Start\n"); | |
a211701e HP |
362 | str_cmd = SST_SND_START; |
363 | status = SST_PLATFORM_RUNNING; | |
d927fdae VK |
364 | stream->stream_info.mad_substream = substream; |
365 | break; | |
366 | case SNDRV_PCM_TRIGGER_STOP: | |
367 | pr_debug("sst: in stop\n"); | |
a211701e HP |
368 | str_cmd = SST_SND_DROP; |
369 | status = SST_PLATFORM_DROPPED; | |
d927fdae VK |
370 | break; |
371 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | |
372 | pr_debug("sst: in pause\n"); | |
a211701e HP |
373 | str_cmd = SST_SND_PAUSE; |
374 | status = SST_PLATFORM_PAUSED; | |
d927fdae VK |
375 | break; |
376 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | |
377 | pr_debug("sst: in pause release\n"); | |
a211701e HP |
378 | str_cmd = SST_SND_RESUME; |
379 | status = SST_PLATFORM_RUNNING; | |
d927fdae VK |
380 | break; |
381 | default: | |
a211701e | 382 | return -EINVAL; |
d927fdae | 383 | } |
03c33042 | 384 | ret_val = stream->ops->device_control(str_cmd, &str_id); |
a211701e HP |
385 | if (!ret_val) |
386 | sst_set_stream_status(stream, status); | |
387 | ||
d927fdae VK |
388 | return ret_val; |
389 | } | |
390 | ||
391 | ||
392 | static snd_pcm_uframes_t sst_platform_pcm_pointer | |
393 | (struct snd_pcm_substream *substream) | |
394 | { | |
395 | struct sst_runtime_stream *stream; | |
5c68536f | 396 | int ret_val, status; |
d927fdae VK |
397 | struct pcm_stream_info *str_info; |
398 | ||
d927fdae | 399 | stream = substream->runtime->private_data; |
5c68536f HP |
400 | status = sst_get_stream_status(stream); |
401 | if (status == SST_PLATFORM_INIT) | |
d927fdae | 402 | return 0; |
d927fdae | 403 | str_info = &stream->stream_info; |
03c33042 | 404 | ret_val = stream->ops->device_control( |
d927fdae VK |
405 | SST_SND_BUFFER_POINTER, str_info); |
406 | if (ret_val) { | |
407 | pr_err("sst: error code = %d\n", ret_val); | |
408 | return ret_val; | |
409 | } | |
d927fdae VK |
410 | return stream->stream_info.buffer_ptr; |
411 | } | |
412 | ||
5b499f8b VK |
413 | static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream, |
414 | struct snd_pcm_hw_params *params) | |
415 | { | |
416 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); | |
417 | memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); | |
418 | ||
419 | return 0; | |
420 | } | |
d927fdae | 421 | |
9ab88434 | 422 | static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream) |
423 | { | |
424 | return snd_pcm_lib_free_pages(substream); | |
425 | } | |
426 | ||
d927fdae VK |
427 | static struct snd_pcm_ops sst_platform_ops = { |
428 | .open = sst_platform_open, | |
429 | .close = sst_platform_close, | |
430 | .ioctl = snd_pcm_lib_ioctl, | |
431 | .prepare = sst_platform_pcm_prepare, | |
432 | .trigger = sst_platform_pcm_trigger, | |
433 | .pointer = sst_platform_pcm_pointer, | |
5b499f8b | 434 | .hw_params = sst_platform_pcm_hw_params, |
9ab88434 | 435 | .hw_free = sst_platform_pcm_hw_free, |
d927fdae VK |
436 | }; |
437 | ||
438 | static void sst_pcm_free(struct snd_pcm *pcm) | |
439 | { | |
440 | pr_debug("sst_pcm_free called\n"); | |
441 | snd_pcm_lib_preallocate_free_for_all(pcm); | |
442 | } | |
443 | ||
8faa8c1a | 444 | static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd) |
d927fdae | 445 | { |
552d1ef6 | 446 | struct snd_pcm *pcm = rtd->pcm; |
d927fdae VK |
447 | int retval = 0; |
448 | ||
449 | pr_debug("sst_pcm_new called\n"); | |
25e9e756 JE |
450 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || |
451 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { | |
d927fdae VK |
452 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
453 | SNDRV_DMA_TYPE_CONTINUOUS, | |
454 | snd_dma_continuous_data(GFP_KERNEL), | |
455 | SST_MIN_BUFFER, SST_MAX_BUFFER); | |
456 | if (retval) { | |
457 | pr_err("dma buffer allocationf fail\n"); | |
458 | return retval; | |
459 | } | |
460 | } | |
d927fdae VK |
461 | return retval; |
462 | } | |
c514a911 VK |
463 | |
464 | /* compress stream operations */ | |
465 | static void sst_compr_fragment_elapsed(void *arg) | |
466 | { | |
467 | struct snd_compr_stream *cstream = (struct snd_compr_stream *)arg; | |
468 | ||
469 | pr_debug("fragment elapsed by driver\n"); | |
470 | if (cstream) | |
471 | snd_compr_fragment_elapsed(cstream); | |
472 | } | |
473 | ||
474 | static int sst_platform_compr_open(struct snd_compr_stream *cstream) | |
475 | { | |
476 | ||
477 | int ret_val = 0; | |
478 | struct snd_compr_runtime *runtime = cstream->runtime; | |
479 | struct sst_runtime_stream *stream; | |
480 | ||
481 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); | |
482 | if (!stream) | |
483 | return -ENOMEM; | |
484 | ||
485 | spin_lock_init(&stream->status_lock); | |
486 | ||
487 | /* get the sst ops */ | |
488 | if (!sst || !try_module_get(sst->dev->driver->owner)) { | |
489 | pr_err("no device available to run\n"); | |
490 | ret_val = -ENODEV; | |
491 | goto out_ops; | |
492 | } | |
493 | stream->compr_ops = sst->compr_ops; | |
494 | ||
495 | stream->id = 0; | |
496 | sst_set_stream_status(stream, SST_PLATFORM_INIT); | |
497 | runtime->private_data = stream; | |
498 | return 0; | |
499 | out_ops: | |
500 | kfree(stream); | |
501 | return ret_val; | |
502 | } | |
503 | ||
504 | static int sst_platform_compr_free(struct snd_compr_stream *cstream) | |
505 | { | |
506 | struct sst_runtime_stream *stream; | |
507 | int ret_val = 0, str_id; | |
508 | ||
509 | stream = cstream->runtime->private_data; | |
510 | /*need to check*/ | |
511 | str_id = stream->id; | |
512 | if (str_id) | |
513 | ret_val = stream->compr_ops->close(str_id); | |
514 | module_put(sst->dev->driver->owner); | |
515 | kfree(stream); | |
516 | pr_debug("%s: %d\n", __func__, ret_val); | |
517 | return 0; | |
518 | } | |
519 | ||
520 | static int sst_platform_compr_set_params(struct snd_compr_stream *cstream, | |
521 | struct snd_compr_params *params) | |
522 | { | |
523 | struct sst_runtime_stream *stream; | |
524 | int retval; | |
525 | struct snd_sst_params str_params; | |
526 | struct sst_compress_cb cb; | |
527 | ||
528 | stream = cstream->runtime->private_data; | |
529 | /* construct fw structure for this*/ | |
530 | memset(&str_params, 0, sizeof(str_params)); | |
531 | ||
532 | str_params.ops = STREAM_OPS_PLAYBACK; | |
533 | str_params.stream_type = SST_STREAM_TYPE_MUSIC; | |
534 | str_params.device_type = SND_SST_DEVICE_COMPRESS; | |
535 | ||
536 | switch (params->codec.id) { | |
537 | case SND_AUDIOCODEC_MP3: { | |
538 | str_params.codec = SST_CODEC_TYPE_MP3; | |
539 | str_params.sparams.uc.mp3_params.codec = SST_CODEC_TYPE_MP3; | |
540 | str_params.sparams.uc.mp3_params.num_chan = params->codec.ch_in; | |
541 | str_params.sparams.uc.mp3_params.pcm_wd_sz = 16; | |
542 | break; | |
543 | } | |
544 | ||
545 | case SND_AUDIOCODEC_AAC: { | |
546 | str_params.codec = SST_CODEC_TYPE_AAC; | |
547 | str_params.sparams.uc.aac_params.codec = SST_CODEC_TYPE_AAC; | |
548 | str_params.sparams.uc.aac_params.num_chan = params->codec.ch_in; | |
549 | str_params.sparams.uc.aac_params.pcm_wd_sz = 16; | |
550 | if (params->codec.format == SND_AUDIOSTREAMFORMAT_MP4ADTS) | |
551 | str_params.sparams.uc.aac_params.bs_format = | |
552 | AAC_BIT_STREAM_ADTS; | |
553 | else if (params->codec.format == SND_AUDIOSTREAMFORMAT_RAW) | |
554 | str_params.sparams.uc.aac_params.bs_format = | |
555 | AAC_BIT_STREAM_RAW; | |
556 | else { | |
557 | pr_err("Undefined format%d\n", params->codec.format); | |
558 | return -EINVAL; | |
559 | } | |
560 | str_params.sparams.uc.aac_params.externalsr = | |
561 | params->codec.sample_rate; | |
562 | break; | |
563 | } | |
564 | ||
565 | default: | |
566 | pr_err("codec not supported, id =%d\n", params->codec.id); | |
567 | return -EINVAL; | |
568 | } | |
569 | ||
570 | str_params.aparams.ring_buf_info[0].addr = | |
571 | virt_to_phys(cstream->runtime->buffer); | |
572 | str_params.aparams.ring_buf_info[0].size = | |
573 | cstream->runtime->buffer_size; | |
574 | str_params.aparams.sg_count = 1; | |
575 | str_params.aparams.frag_size = cstream->runtime->fragment_size; | |
576 | ||
577 | cb.param = cstream; | |
578 | cb.compr_cb = sst_compr_fragment_elapsed; | |
579 | ||
580 | retval = stream->compr_ops->open(&str_params, &cb); | |
581 | if (retval < 0) { | |
582 | pr_err("stream allocation failed %d\n", retval); | |
583 | return retval; | |
584 | } | |
585 | ||
586 | stream->id = retval; | |
587 | return 0; | |
588 | } | |
589 | ||
590 | static int sst_platform_compr_trigger(struct snd_compr_stream *cstream, int cmd) | |
591 | { | |
592 | struct sst_runtime_stream *stream = | |
593 | cstream->runtime->private_data; | |
594 | ||
595 | return stream->compr_ops->control(cmd, stream->id); | |
596 | } | |
597 | ||
598 | static int sst_platform_compr_pointer(struct snd_compr_stream *cstream, | |
599 | struct snd_compr_tstamp *tstamp) | |
600 | { | |
601 | struct sst_runtime_stream *stream; | |
602 | ||
603 | stream = cstream->runtime->private_data; | |
604 | stream->compr_ops->tstamp(stream->id, tstamp); | |
605 | tstamp->byte_offset = tstamp->copied_total % | |
606 | (u32)cstream->runtime->buffer_size; | |
607 | pr_debug("calc bytes offset/copied bytes as %d\n", tstamp->byte_offset); | |
608 | return 0; | |
609 | } | |
610 | ||
611 | static int sst_platform_compr_ack(struct snd_compr_stream *cstream, | |
612 | size_t bytes) | |
613 | { | |
614 | struct sst_runtime_stream *stream; | |
615 | ||
616 | stream = cstream->runtime->private_data; | |
617 | stream->compr_ops->ack(stream->id, (unsigned long)bytes); | |
618 | stream->bytes_written += bytes; | |
619 | ||
620 | return 0; | |
621 | } | |
622 | ||
623 | static int sst_platform_compr_get_caps(struct snd_compr_stream *cstream, | |
624 | struct snd_compr_caps *caps) | |
625 | { | |
626 | struct sst_runtime_stream *stream = | |
627 | cstream->runtime->private_data; | |
628 | ||
629 | return stream->compr_ops->get_caps(caps); | |
630 | } | |
631 | ||
632 | static int sst_platform_compr_get_codec_caps(struct snd_compr_stream *cstream, | |
633 | struct snd_compr_codec_caps *codec) | |
634 | { | |
635 | struct sst_runtime_stream *stream = | |
636 | cstream->runtime->private_data; | |
637 | ||
638 | return stream->compr_ops->get_codec_caps(codec); | |
639 | } | |
640 | ||
0cd5751a VK |
641 | static int sst_platform_compr_set_metadata(struct snd_compr_stream *cstream, |
642 | struct snd_compr_metadata *metadata) | |
643 | { | |
644 | struct sst_runtime_stream *stream = | |
645 | cstream->runtime->private_data; | |
646 | ||
647 | return stream->compr_ops->set_metadata(stream->id, metadata); | |
648 | } | |
649 | ||
c514a911 VK |
650 | static struct snd_compr_ops sst_platform_compr_ops = { |
651 | ||
652 | .open = sst_platform_compr_open, | |
653 | .free = sst_platform_compr_free, | |
654 | .set_params = sst_platform_compr_set_params, | |
0cd5751a | 655 | .set_metadata = sst_platform_compr_set_metadata, |
c514a911 VK |
656 | .trigger = sst_platform_compr_trigger, |
657 | .pointer = sst_platform_compr_pointer, | |
658 | .ack = sst_platform_compr_ack, | |
659 | .get_caps = sst_platform_compr_get_caps, | |
660 | .get_codec_caps = sst_platform_compr_get_codec_caps, | |
661 | }; | |
662 | ||
8faa8c1a | 663 | static struct snd_soc_platform_driver sst_soc_platform_drv = { |
d927fdae | 664 | .ops = &sst_platform_ops, |
c514a911 | 665 | .compr_ops = &sst_platform_compr_ops, |
d927fdae VK |
666 | .pcm_new = sst_pcm_new, |
667 | .pcm_free = sst_pcm_free, | |
668 | }; | |
669 | ||
2b4c78df VK |
670 | static const struct snd_soc_component_driver sst_component = { |
671 | .name = "sst", | |
672 | }; | |
673 | ||
674 | ||
d927fdae VK |
675 | static int sst_platform_probe(struct platform_device *pdev) |
676 | { | |
677 | int ret; | |
678 | ||
679 | pr_debug("sst_platform_probe called\n"); | |
03c33042 | 680 | sst = NULL; |
d927fdae VK |
681 | ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv); |
682 | if (ret) { | |
683 | pr_err("registering soc platform failed\n"); | |
684 | return ret; | |
685 | } | |
5c68536f | 686 | |
b1c36861 | 687 | ret = snd_soc_register_component(&pdev->dev, &sst_component, |
d927fdae VK |
688 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); |
689 | if (ret) { | |
690 | pr_err("registering cpu dais failed\n"); | |
691 | snd_soc_unregister_platform(&pdev->dev); | |
692 | } | |
693 | return ret; | |
694 | } | |
695 | ||
696 | static int sst_platform_remove(struct platform_device *pdev) | |
697 | { | |
698 | ||
b1c36861 | 699 | snd_soc_unregister_component(&pdev->dev); |
d927fdae | 700 | snd_soc_unregister_platform(&pdev->dev); |
25985edc | 701 | pr_debug("sst_platform_remove success\n"); |
d927fdae VK |
702 | return 0; |
703 | } | |
704 | ||
705 | static struct platform_driver sst_platform_driver = { | |
706 | .driver = { | |
a4b12990 | 707 | .name = "sst-mfld-platform", |
d927fdae VK |
708 | .owner = THIS_MODULE, |
709 | }, | |
710 | .probe = sst_platform_probe, | |
711 | .remove = sst_platform_remove, | |
712 | }; | |
713 | ||
29515d62 | 714 | module_platform_driver(sst_platform_driver); |
d927fdae VK |
715 | |
716 | MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver"); | |
717 | MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); | |
718 | MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); | |
719 | MODULE_LICENSE("GPL v2"); | |
a4b12990 | 720 | MODULE_ALIAS("platform:sst-mfld-platform"); |