blob: 7d99322217a4ff4eff4c557001a10ff98fc47bae [file] [log] [blame]
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13
14#include <linux/init.h>
15#include <linux/err.h>
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/time.h>
19#include <linux/wait.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22#include <sound/core.h>
23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25#include <sound/pcm.h>
26#include <sound/initval.h>
27#include <sound/control.h>
28#include <asm/dma.h>
29#include <linux/dma-mapping.h>
30#include <linux/android_pmem.h>
31
32#include "msm-compr-q6.h"
33#include "msm-pcm-routing.h"
34
35static struct audio_locks the_locks;
36
37static struct snd_pcm_hardware msm_compr_hardware_playback = {
38 .info = (SNDRV_PCM_INFO_MMAP |
39 SNDRV_PCM_INFO_BLOCK_TRANSFER |
40 SNDRV_PCM_INFO_MMAP_VALID |
41 SNDRV_PCM_INFO_INTERLEAVED |
42 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
43 .formats = SNDRV_PCM_FMTBIT_S16_LE,
44 .rates = SNDRV_PCM_RATE_8000_48000,
45 .rate_min = 8000,
46 .rate_max = 48000,
47 .channels_min = 1,
48 .channels_max = 2,
49 .buffer_bytes_max = 1200 * 1024 * 2,
Krishnankutty Kolathappillya966f452012-01-12 12:28:36 -080050 .period_bytes_min = 4800,
Asish Bhattacharya305d1752011-11-01 20:38:26 +053051 .period_bytes_max = 1200 * 1024,
52 .periods_min = 2,
Krishnankutty Kolathappillya966f452012-01-12 12:28:36 -080053 .periods_max = 512,
Asish Bhattacharya305d1752011-11-01 20:38:26 +053054 .fifo_size = 0,
55};
56
57/* Conventional and unconventional sample rate supported */
58static unsigned int supported_sample_rates[] = {
59 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
60};
61
62static struct snd_pcm_hw_constraint_list constraints_sample_rates = {
63 .count = ARRAY_SIZE(supported_sample_rates),
64 .list = supported_sample_rates,
65 .mask = 0,
66};
67
68static void compr_event_handler(uint32_t opcode,
69 uint32_t token, uint32_t *payload, void *priv)
70{
71 struct compr_audio *compr = priv;
72 struct msm_audio *prtd = &compr->prtd;
73 struct snd_pcm_substream *substream = prtd->substream;
74 struct snd_pcm_runtime *runtime = substream->runtime;
75 struct audio_aio_write_param param;
76 struct audio_buffer *buf = NULL;
77 int i = 0;
78
79 pr_debug("%s opcode =%08x\n", __func__, opcode);
80 switch (opcode) {
81 case ASM_DATA_EVENT_WRITE_DONE: {
82 uint32_t *ptrmem = (uint32_t *)&param;
83 pr_debug("ASM_DATA_EVENT_WRITE_DONE\n");
84 pr_debug("Buffer Consumed = 0x%08x\n", *ptrmem);
85 prtd->pcm_irq_pos += prtd->pcm_count;
86 if (atomic_read(&prtd->start))
87 snd_pcm_period_elapsed(substream);
88 atomic_inc(&prtd->out_count);
89 wake_up(&the_locks.write_wait);
90 if (!atomic_read(&prtd->start)) {
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +053091 atomic_set(&prtd->pending_buffer, 1);
Asish Bhattacharya305d1752011-11-01 20:38:26 +053092 break;
93 } else
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +053094 atomic_set(&prtd->pending_buffer, 0);
Asish Bhattacharya305d1752011-11-01 20:38:26 +053095
96 if (runtime->status->hw_ptr >= runtime->control->appl_ptr)
97 break;
98 buf = prtd->audio_client->port[IN].buf;
99 pr_debug("%s:writing %d bytes of buffer[%d] to dsp 2\n",
100 __func__, prtd->pcm_count, prtd->out_head);
101 pr_debug("%s:writing buffer[%d] from 0x%08x\n",
102 __func__, prtd->out_head,
103 ((unsigned int)buf[0].phys
104 + (prtd->out_head * prtd->pcm_count)));
105
106 param.paddr = (unsigned long)buf[0].phys
107 + (prtd->out_head * prtd->pcm_count);
108 param.len = prtd->pcm_count;
109 param.msw_ts = 0;
110 param.lsw_ts = 0;
111 param.flags = NO_TIMESTAMP;
112 param.uid = (unsigned long)buf[0].phys
113 + (prtd->out_head * prtd->pcm_count);
114 for (i = 0; i < sizeof(struct audio_aio_write_param)/4;
115 i++, ++ptrmem)
116 pr_debug("cmd[%d]=0x%08x\n", i, *ptrmem);
117 if (q6asm_async_write(prtd->audio_client,
118 &param) < 0)
119 pr_err("%s:q6asm_async_write failed\n",
120 __func__);
121 else
122 prtd->out_head =
123 (prtd->out_head + 1) & (runtime->periods - 1);
124 break;
125 }
126 case ASM_DATA_CMDRSP_EOS:
127 pr_debug("ASM_DATA_CMDRSP_EOS\n");
128 prtd->cmd_ack = 1;
129 wake_up(&the_locks.eos_wait);
130 break;
131 case APR_BASIC_RSP_RESULT: {
132 switch (payload[0]) {
133 case ASM_SESSION_CMD_RUN: {
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +0530134 if (!atomic_read(&prtd->pending_buffer))
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530135 break;
136 pr_debug("%s:writing %d bytes"
137 " of buffer[%d] to dsp\n",
138 __func__, prtd->pcm_count, prtd->out_head);
139 buf = prtd->audio_client->port[IN].buf;
140 pr_debug("%s:writing buffer[%d] from 0x%08x\n",
141 __func__, prtd->out_head,
142 ((unsigned int)buf[0].phys
143 + (prtd->out_head * prtd->pcm_count)));
144 param.paddr = (unsigned long)buf[prtd->out_head].phys;
145 param.len = prtd->pcm_count;
146 param.msw_ts = 0;
147 param.lsw_ts = 0;
148 param.flags = NO_TIMESTAMP;
149 param.uid = (unsigned long)buf[prtd->out_head].phys;
150 if (q6asm_async_write(prtd->audio_client,
151 &param) < 0)
152 pr_err("%s:q6asm_async_write failed\n",
153 __func__);
154 else
155 prtd->out_head =
156 (prtd->out_head + 1)
157 & (runtime->periods - 1);
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +0530158 atomic_set(&prtd->pending_buffer, 0);
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530159 }
160 break;
161 case ASM_STREAM_CMD_FLUSH:
162 pr_debug("ASM_STREAM_CMD_FLUSH\n");
163 prtd->cmd_ack = 1;
164 wake_up(&the_locks.eos_wait);
165 break;
166 default:
167 break;
168 }
169 break;
170 }
171 default:
172 pr_debug("Not Supported Event opcode[0x%x]\n", opcode);
173 break;
174 }
175}
176
177static int msm_compr_playback_prepare(struct snd_pcm_substream *substream)
178{
179 struct snd_pcm_runtime *runtime = substream->runtime;
180 struct compr_audio *compr = runtime->private_data;
181 struct msm_audio *prtd = &compr->prtd;
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -0800182 struct asm_aac_cfg aac_cfg;
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530183 int ret;
184
185 pr_debug("%s\n", __func__);
186 prtd->pcm_size = snd_pcm_lib_buffer_bytes(substream);
187 prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
188 prtd->pcm_irq_pos = 0;
189 /* rate and channels are sent to audio driver */
190 prtd->samp_rate = runtime->rate;
191 prtd->channel_mode = runtime->channels;
192 prtd->out_head = 0;
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -0800193 atomic_set(&prtd->out_count, runtime->periods);
194
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530195 if (prtd->enabled)
196 return 0;
197
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -0800198 switch (compr->info.codec_param.codec.id) {
199 case SND_AUDIOCODEC_MP3:
200 ret = q6asm_media_format_block(prtd->audio_client,
201 compr->codec);
202 if (ret < 0)
203 pr_info("%s: CMD Format block failed\n", __func__);
204 break;
205 case SND_AUDIOCODEC_AAC:
206 pr_debug("SND_AUDIOCODEC_AAC\n");
207 memset(&aac_cfg, 0x0, sizeof(struct asm_aac_cfg));
208 aac_cfg.aot = AAC_ENC_MODE_EAAC_P;
209 aac_cfg.format = 0x03;
210 aac_cfg.ch_cfg = runtime->channels;
211 aac_cfg.sample_rate = runtime->rate;
212 ret = q6asm_media_format_block_aac(prtd->audio_client,
213 &aac_cfg);
214 if (ret < 0)
215 pr_err("%s: CMD Format block failed\n", __func__);
216 break;
217 default:
218 return -EINVAL;
219 }
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530220
221 prtd->enabled = 1;
222 prtd->cmd_ack = 0;
223
224 return 0;
225}
226
227static int msm_compr_trigger(struct snd_pcm_substream *substream, int cmd)
228{
229 int ret = 0;
230 struct snd_pcm_runtime *runtime = substream->runtime;
231 struct compr_audio *compr = runtime->private_data;
232 struct msm_audio *prtd = &compr->prtd;
233
234 pr_debug("%s\n", __func__);
235 switch (cmd) {
236 case SNDRV_PCM_TRIGGER_START:
237 prtd->pcm_irq_pos = 0;
238 case SNDRV_PCM_TRIGGER_RESUME:
239 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
240 pr_debug("%s: Trigger start\n", __func__);
241 q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
242 atomic_set(&prtd->start, 1);
243 break;
244 case SNDRV_PCM_TRIGGER_STOP:
245 pr_debug("SNDRV_PCM_TRIGGER_STOP\n");
246 atomic_set(&prtd->start, 0);
247 break;
248 case SNDRV_PCM_TRIGGER_SUSPEND:
249 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
250 pr_debug("SNDRV_PCM_TRIGGER_PAUSE\n");
251 q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
252 atomic_set(&prtd->start, 0);
253 break;
254 default:
255 ret = -EINVAL;
256 break;
257 }
258
259 return ret;
260}
261
262static void populate_codec_list(struct compr_audio *compr,
263 struct snd_pcm_runtime *runtime)
264{
265 pr_debug("%s\n", __func__);
266 /* MP3 Block */
267 compr->info.compr_cap.num_codecs = 1;
268 compr->info.compr_cap.min_fragment_size = runtime->hw.period_bytes_min;
269 compr->info.compr_cap.max_fragment_size = runtime->hw.period_bytes_max;
270 compr->info.compr_cap.min_fragments = runtime->hw.periods_min;
271 compr->info.compr_cap.max_fragments = runtime->hw.periods_max;
272 compr->info.compr_cap.codecs[0] = SND_AUDIOCODEC_MP3;
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -0800273 compr->info.compr_cap.codecs[1] = SND_AUDIOCODEC_AAC;
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530274 /* Add new codecs here */
275}
276
277static int msm_compr_open(struct snd_pcm_substream *substream)
278{
279 struct snd_pcm_runtime *runtime = substream->runtime;
280 struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
281 struct compr_audio *compr;
282 struct msm_audio *prtd;
283 int ret = 0;
284
285 /* Capture path */
286 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
287 return -EINVAL;
288
289 pr_debug("%s\n", __func__);
290 compr = kzalloc(sizeof(struct compr_audio), GFP_KERNEL);
291 if (compr == NULL) {
292 pr_err("Failed to allocate memory for msm_audio\n");
293 return -ENOMEM;
294 }
295 prtd = &compr->prtd;
296 prtd->substream = substream;
297 prtd->audio_client = q6asm_audio_client_alloc(
298 (app_cb)compr_event_handler, compr);
299 if (!prtd->audio_client) {
300 pr_info("%s: Could not allocate memory\n", __func__);
301 kfree(prtd);
302 return -ENOMEM;
303 }
304 runtime->hw = msm_compr_hardware_playback;
305
306 pr_info("%s: session ID %d\n", __func__, prtd->audio_client->session);
307
308 prtd->session_id = prtd->audio_client->session;
309 msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->be_id,
310 prtd->session_id, substream->stream);
311
312 prtd->cmd_ack = 1;
313
314 ret = snd_pcm_hw_constraint_list(runtime, 0,
315 SNDRV_PCM_HW_PARAM_RATE,
316 &constraints_sample_rates);
317 if (ret < 0)
318 pr_info("snd_pcm_hw_constraint_list failed\n");
319 /* Ensure that buffer size is a multiple of period size */
320 ret = snd_pcm_hw_constraint_integer(runtime,
321 SNDRV_PCM_HW_PARAM_PERIODS);
322 if (ret < 0)
323 pr_info("snd_pcm_hw_constraint_integer failed\n");
324
325 prtd->dsp_cnt = 0;
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +0530326 atomic_set(&prtd->pending_buffer, 1);
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530327 compr->codec = FORMAT_MP3;
328 populate_codec_list(compr, runtime);
329 runtime->private_data = compr;
330
331 return 0;
332}
333
334static int msm_compr_playback_close(struct snd_pcm_substream *substream)
335{
336 struct snd_pcm_runtime *runtime = substream->runtime;
337 struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
338 struct compr_audio *compr = runtime->private_data;
339 struct msm_audio *prtd = &compr->prtd;
340 int dir = 0;
341
342 pr_debug("%s\n", __func__);
343
344 dir = IN;
Asish Bhattacharya31bd80d2012-01-04 02:30:13 +0530345 atomic_set(&prtd->pending_buffer, 0);
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530346 q6asm_cmd(prtd->audio_client, CMD_CLOSE);
347 q6asm_audio_client_buf_free_contiguous(dir,
348 prtd->audio_client);
349
350 msm_pcm_routing_dereg_phy_stream(soc_prtd->dai_link->be_id,
351 SNDRV_PCM_STREAM_PLAYBACK);
352 q6asm_audio_client_free(prtd->audio_client);
353 kfree(prtd);
354 return 0;
355}
356
357static int msm_compr_close(struct snd_pcm_substream *substream)
358{
359 int ret = 0;
360
361 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
362 ret = msm_compr_playback_close(substream);
363 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
364 ret = EINVAL;
365 return ret;
366}
367static int msm_compr_prepare(struct snd_pcm_substream *substream)
368{
369 int ret = 0;
370
371 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
372 ret = msm_compr_playback_prepare(substream);
373 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
374 ret = EINVAL;
375 return ret;
376}
377
378static snd_pcm_uframes_t msm_compr_pointer(struct snd_pcm_substream *substream)
379{
380
381 struct snd_pcm_runtime *runtime = substream->runtime;
382 struct compr_audio *compr = runtime->private_data;
383 struct msm_audio *prtd = &compr->prtd;
384
385 if (prtd->pcm_irq_pos >= prtd->pcm_size)
386 prtd->pcm_irq_pos = 0;
387
388 pr_debug("pcm_irq_pos = %d\n", prtd->pcm_irq_pos);
389 return bytes_to_frames(runtime, (prtd->pcm_irq_pos));
390}
391
392static int msm_compr_mmap(struct snd_pcm_substream *substream,
393 struct vm_area_struct *vma)
394{
395 int result = 0;
396 struct snd_pcm_runtime *runtime = substream->runtime;
397 struct compr_audio *compr = runtime->private_data;
398 struct msm_audio *prtd = &compr->prtd;
399
400 pr_debug("%s\n", __func__);
401 prtd->mmap_flag = 1;
402 if (runtime->dma_addr && runtime->dma_bytes) {
403 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
404 result = remap_pfn_range(vma, vma->vm_start,
405 runtime->dma_addr >> PAGE_SHIFT,
406 runtime->dma_bytes,
407 vma->vm_page_prot);
408 } else {
409 pr_err("Physical address or size of buf is NULL");
410 return -EINVAL;
411 }
412 return result;
413}
414
415static int msm_compr_hw_params(struct snd_pcm_substream *substream,
416 struct snd_pcm_hw_params *params)
417{
418 struct snd_pcm_runtime *runtime = substream->runtime;
419 struct compr_audio *compr = runtime->private_data;
420 struct msm_audio *prtd = &compr->prtd;
421 struct snd_dma_buffer *dma_buf = &substream->dma_buffer;
422 struct audio_buffer *buf;
423 int dir, ret;
424
425 pr_debug("%s\n", __func__);
426 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
427 dir = IN;
428 else
429 return -EINVAL;
430
431 ret = q6asm_open_write(prtd->audio_client, compr->codec);
432 if (ret < 0) {
433 pr_err("%s: Session out open failed\n", __func__);
434 return -ENOMEM;
435 }
436 ret = q6asm_set_io_mode(prtd->audio_client, ASYNC_IO_MODE);
437 if (ret < 0) {
438 pr_err("%s: Set IO mode failed\n", __func__);
439 return -ENOMEM;
440 }
441
442 ret = q6asm_audio_client_buf_alloc_contiguous(dir,
443 prtd->audio_client,
444 runtime->hw.period_bytes_min,
445 runtime->hw.periods_max);
446 if (ret < 0) {
447 pr_err("Audio Start: Buffer Allocation failed "
448 "rc = %d\n", ret);
449 return -ENOMEM;
450 }
451 buf = prtd->audio_client->port[dir].buf;
452
453 pr_debug("%s:buf = %p\n", __func__, buf);
454 dma_buf->dev.type = SNDRV_DMA_TYPE_DEV;
455 dma_buf->dev.dev = substream->pcm->card->dev;
456 dma_buf->private_data = NULL;
457 dma_buf->area = buf[0].data;
458 dma_buf->addr = buf[0].phys;
459 dma_buf->bytes = runtime->hw.buffer_bytes_max;
460 if (!dma_buf->area)
461 return -ENOMEM;
462
463 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
464 return 0;
465}
466
467static int msm_compr_ioctl(struct snd_pcm_substream *substream,
468 unsigned int cmd, void *arg)
469{
470 int rc = 0;
471 struct snd_pcm_runtime *runtime = substream->runtime;
472 struct compr_audio *compr = runtime->private_data;
473 struct msm_audio *prtd = &compr->prtd;
Asish Bhattacharya8664b252011-12-30 05:43:23 +0530474 uint64_t timestamp;
475 uint64_t temp;
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530476
477 switch (cmd) {
Asish Bhattacharya8664b252011-12-30 05:43:23 +0530478 case SNDRV_COMPRESS_TSTAMP: {
479 struct snd_compr_tstamp tstamp;
480 pr_debug("SNDRV_COMPRESS_TSTAMP\n");
481
482 memset(&tstamp, 0x0, sizeof(struct snd_compr_tstamp));
483 timestamp = q6asm_get_session_time(prtd->audio_client);
484 if (timestamp < 0) {
485 pr_err("%s: Get Session Time return value =%lld\n",
486 __func__, timestamp);
487 return -EAGAIN;
488 }
489 temp = (timestamp * 2 * runtime->channels);
490 temp = temp * (runtime->rate/1000);
491 temp = div_u64(temp, 1000);
492 tstamp.sampling_rate = runtime->rate;
493 tstamp.rendered = (size_t)(temp & 0xFFFFFFFF);
494 tstamp.decoded = (size_t)((temp >> 32) & 0xFFFFFFFF);
495 tstamp.timestamp = timestamp;
496 pr_debug("%s: bytes_consumed:lsb = %d, msb = %d,"
497 "timestamp = %lld,\n",
498 __func__, tstamp.rendered, tstamp.decoded,
499 tstamp.timestamp);
500 if (copy_to_user((void *) arg, &tstamp,
501 sizeof(struct snd_compr_tstamp)))
502 return -EFAULT;
503 return 0;
504 }
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530505 case SNDRV_COMPRESS_GET_CAPS:
506 pr_debug("SNDRV_COMPRESS_GET_CAPS\n");
507 if (copy_to_user((void *) arg, &compr->info.compr_cap,
508 sizeof(struct snd_compr_caps))) {
509 rc = -EFAULT;
510 pr_err("%s: ERROR: copy to user\n", __func__);
511 return rc;
512 }
513 return 0;
514 case SNDRV_COMPRESS_SET_PARAMS:
515 pr_debug("SNDRV_COMPRESS_SET_PARAMS: ");
516 if (copy_from_user(&compr->info.codec_param, (void *) arg,
517 sizeof(struct snd_compr_params))) {
518 rc = -EFAULT;
519 pr_err("%s: ERROR: copy from user\n", __func__);
520 return rc;
521 }
522 switch (compr->info.codec_param.codec.id) {
523 case SND_AUDIOCODEC_MP3:
524 /* For MP3 we dont need any other parameter */
525 pr_debug("SND_AUDIOCODEC_MP3\n");
526 compr->codec = FORMAT_MP3;
527 break;
Krishnankutty Kolathappilly46dded22012-01-12 12:03:34 -0800528 case SND_AUDIOCODEC_AAC:
529 pr_debug("SND_AUDIOCODEC_AAC\n");
530 compr->codec = FORMAT_MPEG4_AAC;
531 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +0530532 default:
533 pr_debug("FORMAT_LINEAR_PCM\n");
534 compr->codec = FORMAT_LINEAR_PCM;
535 break;
536 }
537 return 0;
538 case SNDRV_PCM_IOCTL1_RESET:
539 prtd->cmd_ack = 0;
540 rc = q6asm_cmd(prtd->audio_client, CMD_FLUSH);
541 if (rc < 0)
542 pr_err("%s: flush cmd failed rc=%d\n", __func__, rc);
543 rc = wait_event_timeout(the_locks.eos_wait,
544 prtd->cmd_ack, 5 * HZ);
545 if (rc < 0)
546 pr_err("Flush cmd timeout\n");
547 prtd->pcm_irq_pos = 0;
548 break;
549 default:
550 break;
551 }
552 return snd_pcm_lib_ioctl(substream, cmd, arg);
553}
554
555static struct snd_pcm_ops msm_compr_ops = {
556 .open = msm_compr_open,
557 .hw_params = msm_compr_hw_params,
558 .close = msm_compr_close,
559 .ioctl = msm_compr_ioctl,
560 .prepare = msm_compr_prepare,
561 .trigger = msm_compr_trigger,
562 .pointer = msm_compr_pointer,
563 .mmap = msm_compr_mmap,
564};
565
566static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd)
567{
568 struct snd_card *card = rtd->card->snd_card;
569 int ret = 0;
570
571 if (!card->dev->coherent_dma_mask)
572 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
573 return ret;
574}
575
576static struct snd_soc_platform_driver msm_soc_platform = {
577 .ops = &msm_compr_ops,
578 .pcm_new = msm_asoc_pcm_new,
579};
580
581static __devinit int msm_compr_probe(struct platform_device *pdev)
582{
583 pr_info("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
584 return snd_soc_register_platform(&pdev->dev,
585 &msm_soc_platform);
586}
587
588static int msm_compr_remove(struct platform_device *pdev)
589{
590 snd_soc_unregister_platform(&pdev->dev);
591 return 0;
592}
593
594static struct platform_driver msm_compr_driver = {
595 .driver = {
596 .name = "msm-compr-dsp",
597 .owner = THIS_MODULE,
598 },
599 .probe = msm_compr_probe,
600 .remove = __devexit_p(msm_compr_remove),
601};
602
603static int __init msm_soc_platform_init(void)
604{
605 init_waitqueue_head(&the_locks.enable_wait);
606 init_waitqueue_head(&the_locks.eos_wait);
607 init_waitqueue_head(&the_locks.write_wait);
608 init_waitqueue_head(&the_locks.read_wait);
609
610 return platform_driver_register(&msm_compr_driver);
611}
612module_init(msm_soc_platform_init);
613
614static void __exit msm_soc_platform_exit(void)
615{
616 platform_driver_unregister(&msm_compr_driver);
617}
618module_exit(msm_soc_platform_exit);
619
620MODULE_DESCRIPTION("PCM module platform driver");
621MODULE_LICENSE("GPL v2");