blob: ea319857cdbbc3a871ee300cad16b0c7f0e329cd [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* sound/soc/msm/msm-pcm.c
2 *
3 * Copyright (C) 2008 Google, Inc.
4 * Copyright (C) 2008 HTC Corporation
Asish Bhattacharyac1c701f2012-02-22 10:55:59 +05305 * Copyright (c) 2008-2009, 2012 Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can find it at http://www.fsf.org.
18 */
19
20
21#include <linux/init.h>
22#include <linux/err.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/time.h>
26#include <linux/wait.h>
27#include <linux/platform_device.h>
28#include <sound/core.h>
29#include <sound/soc.h>
30#include <sound/pcm.h>
31#include <sound/initval.h>
32#include <asm/dma.h>
33#include <linux/dma-mapping.h>
34
35#include "msm-pcm.h"
36
37#define MAX_DATA_SIZE 496
38#define AUDPP_ALSA_DECODER (-1)
39
40#define DB_TABLE_INDEX (50)
41
42#define audio_send_queue_recbs(prtd, cmd, len) \
43 msm_adsp_write(prtd->audrec, QDSP_uPAudRecBitStreamQueue, cmd, len)
44#define audio_send_queue_rec(prtd, cmd, len) \
45 msm_adsp_write(prtd->audrec, QDSP_uPAudRecCmdQueue, cmd, len)
46
47int intcnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048
49struct audio_frame {
50 uint16_t count_low;
51 uint16_t count_high;
52 uint16_t bytes;
53 uint16_t unknown;
54 unsigned char samples[];
55} __attribute__ ((packed));
56
57/* Table contains dB to raw value mapping */
58static const unsigned decoder_db_table[] = {
59
60 31 , /* -50 dB */
61 35 , 39 , 44 , 50 , 56 ,
62 63 , 70 , 79 , 89 , 99 ,
63 112 , 125 , 141 , 158 , 177 ,
64 199 , 223 , 251 , 281 , 316 ,
65 354 , 398 , 446 , 501 , 562 ,
66 630 , 707 , 794 , 891 , 999 ,
67 1122 , 1258 , 1412 , 1584 , 1778 ,
68 1995 , 2238 , 2511 , 2818 , 3162 ,
69 3548 , 3981 , 4466 , 5011 , 5623 ,
70 6309 , 7079 , 7943 , 8912 , 10000 ,
71 11220 , 12589 , 14125 , 15848 , 17782 ,
72 19952 , 22387 , 25118 , 28183 , 31622 ,
73 35481 , 39810 , 44668 , 50118 , 56234 ,
74 63095 , 70794 , 79432 , 89125 , 100000 ,
75 112201 , 125892 , 141253 , 158489 , 177827 ,
76 199526 , 223872 , 251188 , 281838 , 316227 ,
77 354813 , 398107 , 446683 , 501187 , 562341 ,
78 630957 , 707945 , 794328 , 891250 , 1000000 ,
79 1122018 , 1258925 , 1412537 , 1584893 , 1778279 ,
80 1995262 , 2238721 , 2511886 , 2818382 , 3162277 ,
81 3548133 /* 51 dB */
82
83};
84
85static unsigned compute_db_raw(int db)
86{
87 unsigned reg_val = 0; /* Computed result for correspondent db */
88 /* Check if the given db is out of range */
89 if (db <= MIN_DB)
90 return 0;
91 else if (db > MAX_DB)
92 db = MAX_DB; /* If db is too high then set to max */
93 reg_val = decoder_db_table[DB_TABLE_INDEX+db];
94 return reg_val;
95}
96
97int msm_audio_volume_update(unsigned id,
98 int volume, int pan)
99{
100 unsigned vol_raw;
101
102 vol_raw = compute_db_raw(volume);
103 printk(KERN_INFO "volume: %8x vol_raw: %8x \n", volume, vol_raw);
104 return audpp_set_volume_and_pan(id, vol_raw, pan);
105}
106EXPORT_SYMBOL(msm_audio_volume_update);
107
108void alsa_dsp_event(void *data, unsigned id, uint16_t *msg)
109{
110 struct msm_audio *prtd = data;
111 struct buffer *frame;
112 unsigned long flag;
113
114 switch (id) {
115 case AUDPP_MSG_STATUS_MSG:
116 break;
117 case AUDPP_MSG_SPA_BANDS:
118 break;
119 case AUDPP_MSG_HOST_PCM_INTF_MSG:{
120 unsigned id = msg[2];
121 unsigned idx = msg[3] - 1;
122 if (id != AUDPP_MSG_HOSTPCM_ID_ARM_RX) {
123 printk(KERN_ERR "bogus id\n");
124 break;
125 }
126 if (idx > 1) {
127 printk(KERN_ERR "bogus buffer idx\n");
128 break;
129 }
130 /* Update with actual sent buffer size */
131 if (prtd->out[idx].used != BUF_INVALID_LEN)
132 prtd->pcm_irq_pos += prtd->out[idx].used;
133
134 if (prtd->pcm_irq_pos > prtd->pcm_size)
135 prtd->pcm_irq_pos = prtd->pcm_count;
136
137 if (prtd->ops->playback)
138 prtd->ops->playback(prtd);
139
Asish Bhattacharyac1c701f2012-02-22 10:55:59 +0530140 if (prtd->mmap_flag)
141 break;
142
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143 spin_lock_irqsave(&the_locks.write_dsp_lock, flag);
144 if (prtd->running) {
145 prtd->out[idx].used = 0;
146 frame = prtd->out + prtd->out_tail;
147 if (frame->used) {
Asish Bhattacharyac1c701f2012-02-22 10:55:59 +0530148 alsa_dsp_send_buffer(prtd,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149 prtd->out_tail,
150 frame->used);
151 prtd->out_tail ^= 1;
152 } else {
153 prtd->out_needed++;
154 }
155 wake_up(&the_locks.write_wait);
156 }
157 spin_unlock_irqrestore(&the_locks.write_dsp_lock, flag);
158 break;
159 }
160 case AUDPP_MSG_PCMDMAMISSED:
161 pr_info("alsa_dsp_event: PCMDMAMISSED %d\n", msg[0]);
162 prtd->eos_ack = 1;
163 wake_up(&the_locks.eos_wait);
164 break;
165 case AUDPP_MSG_CFG_MSG:
166 if (msg[0] == AUDPP_MSG_ENA_ENA) {
167 prtd->out_needed = 0;
168 prtd->running = 1;
169 audio_dsp_out_enable(prtd, 1);
170 } else if (msg[0] == AUDPP_MSG_ENA_DIS) {
171 prtd->running = 0;
172 } else {
173 printk(KERN_ERR "alsa_dsp_event:CFG_MSG=%d\n", msg[0]);
174 }
175 break;
176 case EVENT_MSG_ID:
177 printk(KERN_INFO"alsa_dsp_event: arm9 event\n");
178 break;
179 default:
180 printk(KERN_ERR "alsa_dsp_event: UNKNOWN (%d)\n", id);
181 }
182}
183
184void alsa_audpre_dsp_event(void *data, unsigned id, size_t len,
185 void (*getevent) (void *ptr, size_t len))
186{
187 uint16_t msg[MAX_DATA_SIZE/2];
188
189 if (len > MAX_DATA_SIZE) {
190 printk(KERN_ERR"audpre: event too large(%d bytes)\n", len);
191 return;
192 }
193 getevent(msg, len);
194
195 switch (id) {
196 case AUDPREPROC_MSG_CMD_CFG_DONE_MSG:
197 break;
198 case AUDPREPROC_MSG_ERROR_MSG_ID:
199 printk(KERN_ERR "audpre: err_index %d\n", msg[0]);
200 break;
201 case EVENT_MSG_ID:
202 printk(KERN_INFO"audpre: arm9 event\n");
203 break;
204 default:
205 printk(KERN_ERR "audpre: unknown event %d\n", id);
206 }
207}
208
209void audrec_dsp_event(void *data, unsigned id, size_t len,
210 void (*getevent) (void *ptr, size_t len))
211{
212 struct msm_audio *prtd = data;
213 unsigned long flag;
214 uint16_t msg[MAX_DATA_SIZE/2];
215
216 if (len > MAX_DATA_SIZE) {
217 printk(KERN_ERR"audrec: event/msg too large(%d bytes)\n", len);
218 return;
219 }
220 getevent(msg, len);
221
222 switch (id) {
223 case AUDREC_MSG_CMD_CFG_DONE_MSG:
224 if (msg[0] & AUDREC_MSG_CFG_DONE_TYPE_0_UPDATE) {
225 if (msg[0] & AUDREC_MSG_CFG_DONE_TYPE_0_ENA)
226 audrec_encoder_config(prtd);
227 else
228 prtd->running = 0;
229 }
230 break;
231 case AUDREC_MSG_CMD_AREC_PARAM_CFG_DONE_MSG:{
232 prtd->running = 1;
233 break;
234 }
235 case AUDREC_MSG_FATAL_ERR_MSG:
236 printk(KERN_ERR "audrec: ERROR %x\n", msg[0]);
237 break;
238 case AUDREC_MSG_PACKET_READY_MSG:
239 alsa_get_dsp_frames(prtd);
240 ++intcnt;
241 if (prtd->channel_mode == 1) {
242 spin_lock_irqsave(&the_locks.read_dsp_lock, flag);
243 prtd->pcm_irq_pos += prtd->pcm_count;
244 if (prtd->pcm_irq_pos >= prtd->pcm_size)
245 prtd->pcm_irq_pos = 0;
246 spin_unlock_irqrestore(&the_locks.read_dsp_lock, flag);
247
248 if (prtd->ops->capture)
249 prtd->ops->capture(prtd);
250 } else if ((prtd->channel_mode == 0) && (intcnt % 2 == 0)) {
251 spin_lock_irqsave(&the_locks.read_dsp_lock, flag);
252 prtd->pcm_irq_pos += prtd->pcm_count;
253 if (prtd->pcm_irq_pos >= prtd->pcm_size)
254 prtd->pcm_irq_pos = 0;
255 spin_unlock_irqrestore(&the_locks.read_dsp_lock, flag);
256 if (prtd->ops->capture)
257 prtd->ops->capture(prtd);
258 }
259 break;
260 case EVENT_MSG_ID:
261 printk(KERN_INFO"audrec: arm9 event\n");
262 break;
263 default:
264 printk(KERN_ERR "audrec: unknown event %d\n", id);
265 }
266}
267
268struct msm_adsp_ops aud_pre_adsp_ops = {
269 .event = alsa_audpre_dsp_event,
270};
271
272struct msm_adsp_ops aud_rec_adsp_ops = {
273 .event = audrec_dsp_event,
274};
275
276int alsa_adsp_configure(struct msm_audio *prtd)
277{
278 int ret, i;
279
280 if (prtd->dir == SNDRV_PCM_STREAM_PLAYBACK) {
281 prtd->data = prtd->playback_substream->dma_buffer.area;
282 prtd->phys = prtd->playback_substream->dma_buffer.addr;
283 }
284 if (prtd->dir == SNDRV_PCM_STREAM_CAPTURE) {
285 prtd->data = prtd->capture_substream->dma_buffer.area;
286 prtd->phys = prtd->capture_substream->dma_buffer.addr;
287 }
288 if (!prtd->data) {
289 ret = -ENOMEM;
290 goto err1;
291 }
292
293 ret = audmgr_open(&prtd->audmgr);
294 if (ret)
295 goto err2;
296 if (prtd->dir == SNDRV_PCM_STREAM_PLAYBACK) {
297 prtd->out_buffer_size = PLAYBACK_DMASZ;
298 prtd->out_sample_rate = 44100;
299 prtd->out_channel_mode = AUDPP_CMD_PCM_INTF_STEREO_V;
300 prtd->out_weight = 100;
301
302 prtd->out[0].data = prtd->data + 0;
303 prtd->out[0].addr = prtd->phys + 0;
304 prtd->out[0].size = BUFSZ;
305 prtd->out[1].data = prtd->data + BUFSZ;
306 prtd->out[1].addr = prtd->phys + BUFSZ;
307 prtd->out[1].size = BUFSZ;
308 }
309 if (prtd->dir == SNDRV_PCM_STREAM_CAPTURE) {
310 prtd->samp_rate = RPC_AUD_DEF_SAMPLE_RATE_44100;
311 prtd->samp_rate_index = AUDREC_CMD_SAMP_RATE_INDX_44100;
312 prtd->channel_mode = AUDREC_CMD_STEREO_MODE_STEREO;
313 prtd->buffer_size = STEREO_DATA_SIZE;
314 prtd->type = AUDREC_CMD_TYPE_0_INDEX_WAV;
315 prtd->tx_agc_cfg.cmd_id = AUDPREPROC_CMD_CFG_AGC_PARAMS;
316 prtd->ns_cfg.cmd_id = AUDPREPROC_CMD_CFG_NS_PARAMS;
317 prtd->iir_cfg.cmd_id =
318 AUDPREPROC_CMD_CFG_IIR_TUNING_FILTER_PARAMS;
319
320 ret = msm_adsp_get("AUDPREPROCTASK",
321 &prtd->audpre, &aud_pre_adsp_ops, prtd);
322 if (ret)
323 goto err3;
324 ret = msm_adsp_get("AUDRECTASK",
325 &prtd->audrec, &aud_rec_adsp_ops, prtd);
326 if (ret) {
327 msm_adsp_put(prtd->audpre);
328 goto err3;
329 }
330 prtd->dsp_cnt = 0;
331 prtd->in_head = 0;
332 prtd->in_tail = 0;
333 prtd->in_count = 0;
334 for (i = 0; i < FRAME_NUM; i++) {
335 prtd->in[i].size = 0;
336 prtd->in[i].read = 0;
337 }
338 }
339
340 return 0;
341
342err3:
343 audmgr_close(&prtd->audmgr);
344
345err2:
346 prtd->data = NULL;
347err1:
348 return ret;
349}
350EXPORT_SYMBOL(alsa_adsp_configure);
351
352int alsa_audio_configure(struct msm_audio *prtd)
353{
354 struct audmgr_config cfg;
355 int rc;
356
357 if (prtd->enabled)
358 return 0;
359
360 /* refuse to start if we're not ready with first buffer */
361 if (!prtd->out[0].used)
362 return -EIO;
363
364 cfg.tx_rate = 0;
365 cfg.rx_rate = RPC_AUD_DEF_SAMPLE_RATE_48000;
366 cfg.def_method = RPC_AUD_DEF_METHOD_HOST_PCM;
367 cfg.codec = RPC_AUD_DEF_CODEC_PCM;
368 cfg.snd_method = RPC_SND_METHOD_MIDI;
369 rc = audmgr_enable(&prtd->audmgr, &cfg);
370 if (rc < 0)
371 return rc;
372
373 if (audpp_enable(AUDPP_ALSA_DECODER, alsa_dsp_event, prtd)) {
374 printk(KERN_ERR "audio: audpp_enable() failed\n");
375 audmgr_disable(&prtd->audmgr);
376 return -ENODEV;
377 }
378
379 prtd->enabled = 1;
380 return 0;
381}
382EXPORT_SYMBOL(alsa_audio_configure);
383
384ssize_t alsa_send_buffer(struct msm_audio *prtd, const char __user *buf,
385 size_t count, loff_t *pos)
386{
387 unsigned long flag;
388 const char __user *start = buf;
389 struct buffer *frame;
390 size_t xfer;
391 int rc = 0;
392
393 mutex_lock(&the_locks.write_lock);
394 while (count > 0) {
395 frame = prtd->out + prtd->out_head;
396 rc = wait_event_interruptible(the_locks.write_wait,
397 (frame->used == 0)
398 || (prtd->stopped));
399 if (rc < 0)
400 break;
401 if (prtd->stopped) {
402 rc = -EBUSY;
403 break;
404 }
405 xfer = count > frame->size ? frame->size : count;
406 if (copy_from_user(frame->data, buf, xfer)) {
407 rc = -EFAULT;
408 break;
409 }
410 frame->used = xfer;
411 prtd->out_head ^= 1;
412 count -= xfer;
413 buf += xfer;
414
415 spin_lock_irqsave(&the_locks.write_dsp_lock, flag);
416 frame = prtd->out + prtd->out_tail;
417 if (frame->used && prtd->out_needed) {
Asish Bhattacharyac1c701f2012-02-22 10:55:59 +0530418 alsa_dsp_send_buffer(prtd, prtd->out_tail,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700419 frame->used);
420 prtd->out_tail ^= 1;
421 prtd->out_needed--;
422 }
423 spin_unlock_irqrestore(&the_locks.write_dsp_lock, flag);
424 }
425 mutex_unlock(&the_locks.write_lock);
426 if (buf > start)
427 return buf - start;
428 return rc;
429}
430EXPORT_SYMBOL(alsa_send_buffer);
431
432int alsa_audio_disable(struct msm_audio *prtd)
433{
434 if (prtd->enabled) {
435 mutex_lock(&the_locks.lock);
436 prtd->enabled = 0;
437 audio_dsp_out_enable(prtd, 0);
438 wake_up(&the_locks.write_wait);
439 audpp_disable(AUDPP_ALSA_DECODER, prtd);
440 audmgr_disable(&prtd->audmgr);
441 prtd->out_needed = 0;
442 mutex_unlock(&the_locks.lock);
443 }
444 return 0;
445}
446EXPORT_SYMBOL(alsa_audio_disable);
447
448int alsa_audrec_disable(struct msm_audio *prtd)
449{
450 if (prtd->enabled) {
451 mutex_lock(&the_locks.lock);
452 prtd->enabled = 0;
453 alsa_rec_dsp_enable(prtd, 0);
454 wake_up(&the_locks.read_wait);
455 msm_adsp_disable(prtd->audpre);
456 msm_adsp_disable(prtd->audrec);
457 audmgr_disable(&prtd->audmgr);
458 prtd->out_needed = 0;
459 prtd->opened = 0;
460 mutex_unlock(&the_locks.lock);
461 }
462 return 0;
463}
464EXPORT_SYMBOL(alsa_audrec_disable);
465
466static int audio_dsp_read_buffer(struct msm_audio *prtd, uint32_t read_cnt)
467{
468 audrec_cmd_packet_ext_ptr cmd;
469
470 memset(&cmd, 0, sizeof(cmd));
471 cmd.cmd_id = AUDREC_CMD_PACKET_EXT_PTR;
472 /* Both WAV and AAC use AUDREC_CMD_TYPE_0 */
473 cmd.type = AUDREC_CMD_TYPE_0;
474 cmd.curr_rec_count_msw = read_cnt >> 16;
475 cmd.curr_rec_count_lsw = read_cnt;
476
477 return audio_send_queue_recbs(prtd, &cmd, sizeof(cmd));
478}
479
480int audrec_encoder_config(struct msm_audio *prtd)
481{
482 audrec_cmd_arec0param_cfg cmd;
483 uint16_t *data = (void *)prtd->data;
484 unsigned n;
485
486 memset(&cmd, 0, sizeof(cmd));
487 cmd.cmd_id = AUDREC_CMD_AREC0PARAM_CFG;
488 cmd.ptr_to_extpkt_buffer_msw = prtd->phys >> 16;
489 cmd.ptr_to_extpkt_buffer_lsw = prtd->phys;
490 cmd.buf_len = FRAME_NUM; /* Both WAV and AAC use 8 frames */
491 cmd.samp_rate_index = prtd->samp_rate_index;
492 /* 0 for mono, 1 for stereo */
493 cmd.stereo_mode = prtd->channel_mode;
494 cmd.rec_quality = 0x1C00;
495
496 /* prepare buffer pointers:
497 * Mono: 1024 samples + 4 halfword header
498 * Stereo: 2048 samples + 4 halfword header
499 */
500
501 for (n = 0; n < FRAME_NUM; n++) {
502 prtd->in[n].data = data + 4;
503 data += (4 + (prtd->channel_mode ? 2048 : 1024));
504 }
505
506 return audio_send_queue_rec(prtd, &cmd, sizeof(cmd));
507}
508
509int audio_dsp_out_enable(struct msm_audio *prtd, int yes)
510{
511 audpp_cmd_pcm_intf cmd;
512 memset(&cmd, 0, sizeof(cmd));
513 cmd.cmd_id = AUDPP_CMD_PCM_INTF_2;
514 cmd.object_num = AUDPP_CMD_PCM_INTF_OBJECT_NUM;
515 cmd.config = AUDPP_CMD_PCM_INTF_CONFIG_CMD_V;
516 cmd.intf_type = AUDPP_CMD_PCM_INTF_RX_ENA_ARMTODSP_V;
517
518 if (yes) {
519 cmd.write_buf1LSW = prtd->out[0].addr;
520 cmd.write_buf1MSW = prtd->out[0].addr >> 16;
521 cmd.write_buf1_len = 0;
522 cmd.write_buf2LSW = prtd->out[1].addr;
523 cmd.write_buf2MSW = prtd->out[1].addr >> 16;
524 cmd.write_buf2_len = prtd->out[1].used;
525 cmd.arm_to_rx_flag = AUDPP_CMD_PCM_INTF_ENA_V;
526 cmd.weight_decoder_to_rx = prtd->out_weight;
527 cmd.weight_arm_to_rx = 1;
528 cmd.partition_number_arm_to_dsp = 0;
529 cmd.sample_rate = prtd->out_sample_rate;
530 cmd.channel_mode = prtd->out_channel_mode;
531 }
532 return audpp_send_queue2(&cmd, sizeof(cmd));
533}
534
535int alsa_buffer_read(struct msm_audio *prtd, void __user *buf,
536 size_t count, loff_t *pos)
537{
538 unsigned long flag;
539 void *data;
540 uint32_t index;
541 uint32_t size;
542 int rc = 0;
543
544 mutex_lock(&the_locks.read_lock);
545 while (count > 0) {
546 rc = wait_event_interruptible(the_locks.read_wait,
547 (prtd->in_count > 0)
548 || prtd->stopped);
549 if (rc < 0)
550 break;
551
552 if (prtd->stopped) {
553 rc = -EBUSY;
554 break;
555 }
556
557 index = prtd->in_tail;
558 data = (uint8_t *) prtd->in[index].data;
559 size = prtd->in[index].size;
560 if (count >= size) {
561 if (copy_to_user(buf, data, size)) {
562 rc = -EFAULT;
563 break;
564 }
565 spin_lock_irqsave(&the_locks.read_dsp_lock, flag);
566 if (index != prtd->in_tail) {
567 /* overrun: data is invalid, we need to retry */
568 spin_unlock_irqrestore(&the_locks.read_dsp_lock,
569 flag);
570 continue;
571 }
572 prtd->in[index].size = 0;
573 prtd->in_tail = (prtd->in_tail + 1) & (FRAME_NUM - 1);
574 prtd->in_count--;
575 spin_unlock_irqrestore(&the_locks.read_dsp_lock, flag);
576 count -= size;
577 buf += size;
578 } else {
579 break;
580 }
581 }
582 mutex_unlock(&the_locks.read_lock);
583 return rc;
584}
585EXPORT_SYMBOL(alsa_buffer_read);
586
Asish Bhattacharyac1c701f2012-02-22 10:55:59 +0530587int alsa_dsp_send_buffer(struct msm_audio *prtd,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588 unsigned idx, unsigned len)
589{
590 audpp_cmd_pcm_intf_send_buffer cmd;
591 cmd.cmd_id = AUDPP_CMD_PCM_INTF_2;
592 cmd.host_pcm_object = AUDPP_CMD_PCM_INTF_OBJECT_NUM;
593 cmd.config = AUDPP_CMD_PCM_INTF_BUFFER_CMD_V;
594 cmd.intf_type = AUDPP_CMD_PCM_INTF_RX_ENA_ARMTODSP_V;
595 cmd.dsp_to_arm_buf_id = 0;
596 cmd.arm_to_dsp_buf_id = idx + 1;
597 cmd.arm_to_dsp_buf_len = len;
598 return audpp_send_queue2(&cmd, sizeof(cmd));
599}
600
601int alsa_rec_dsp_enable(struct msm_audio *prtd, int enable)
602{
603 audrec_cmd_cfg cmd;
604
605 memset(&cmd, 0, sizeof(cmd));
606 cmd.cmd_id = AUDREC_CMD_CFG;
607 cmd.type_0 = enable ? AUDREC_CMD_TYPE_0_ENA : AUDREC_CMD_TYPE_0_DIS;
608 cmd.type_0 |= (AUDREC_CMD_TYPE_0_UPDATE | prtd->type);
609 cmd.type_1 = 0;
610
611 return audio_send_queue_rec(prtd, &cmd, sizeof(cmd));
612}
613EXPORT_SYMBOL(alsa_rec_dsp_enable);
614
615void alsa_get_dsp_frames(struct msm_audio *prtd)
616{
617 struct audio_frame *frame;
618 uint32_t index = 0;
619 unsigned long flag;
620
621 if (prtd->type == AUDREC_CMD_TYPE_0_INDEX_WAV) {
622 index = prtd->in_head;
623
624 frame =
625 (void *)(((char *)prtd->in[index].data) - sizeof(*frame));
626
627 spin_lock_irqsave(&the_locks.read_dsp_lock, flag);
628 prtd->in[index].size = frame->bytes;
629
630 prtd->in_head = (prtd->in_head + 1) & (FRAME_NUM - 1);
631
632 /* If overflow, move the tail index foward. */
633 if (prtd->in_head == prtd->in_tail)
634 prtd->in_tail = (prtd->in_tail + 1) & (FRAME_NUM - 1);
635 else
636 prtd->in_count++;
637
638 audio_dsp_read_buffer(prtd, prtd->dsp_cnt++);
639 spin_unlock_irqrestore(&the_locks.read_dsp_lock, flag);
640
641 wake_up(&the_locks.read_wait);
642 } else {
643 /* TODO AAC not supported yet. */
644 }
645}
646EXPORT_SYMBOL(alsa_get_dsp_frames);