blob: 0db1ef40d9ffcfbdfe56cb995e2598fc85a47089 [file] [log] [blame]
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -07001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
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/module.h>
15#include <linux/fs.h>
16#include <linux/miscdevice.h>
17#include <linux/uaccess.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
20#include <linux/dma-mapping.h>
21#include <linux/slab.h>
22#include <asm/atomic.h>
23#include <asm/ioctls.h>
24#include "audio_utils.h"
25
26void q6asm_in_cb(uint32_t opcode, uint32_t token,
27 uint32_t *payload, void *priv)
28{
29 struct q6audio_in *audio = (struct q6audio_in *)priv;
30 unsigned long flags;
31
32 pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
33 audio->ac->session, opcode);
34
35 spin_lock_irqsave(&audio->dsp_lock, flags);
36 switch (opcode) {
37 case ASM_DATA_EVENT_READ_DONE_V2:
38 audio_in_get_dsp_frames(audio, token, payload);
39 break;
40 case ASM_DATA_EVENT_WRITE_DONE_V2:
41 atomic_inc(&audio->in_count);
42 wake_up(&audio->write_wait);
43 break;
44 case ASM_DATA_EVENT_RENDERED_EOS:
45 audio->eos_rsp = 1;
46 wake_up(&audio->read_wait);
47 break;
48 case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
49 break;
50 case ASM_SESSION_EVENTX_OVERFLOW:
51 pr_err("%s:session id %d: ASM_SESSION_EVENT_TX_OVERFLOW\n",
52 __func__, audio->ac->session);
53 break;
54 default:
55 pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
56 audio->ac->session, opcode);
57 break;
58 }
59 spin_unlock_irqrestore(&audio->dsp_lock, flags);
60}
61
62void audio_in_get_dsp_frames(void *priv,
63 uint32_t token, uint32_t *payload)
64{
65 struct q6audio_in *audio = (struct q6audio_in *)priv;
66 uint32_t index;
67
68 index = token;
69 pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
70 __func__, audio->ac->session, token, payload[9],
71 payload[5]);
72 pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
73 audio->ac->session, payload[7], payload[6]);
74 pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
75 audio->ac->session, payload[8], payload[10]);
76 pr_debug("%s:session id %d: enc_framesotal_size=0x%8x\n", __func__,
77 audio->ac->session, payload[4]);
78
79 audio->out_frame_info[index][0] = payload[9];
80 audio->out_frame_info[index][1] = payload[5];
81
82 /* statistics of read */
83 atomic_add(payload[4], &audio->in_bytes);
84 atomic_add(payload[9], &audio->in_samples);
85
86 if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
87 atomic_inc(&audio->out_count);
88 wake_up(&audio->read_wait);
89 }
90}