blob: 7786fc01bcfd47a99929e77a24af73a305c717a7 [file] [log] [blame]
Phani Kumar Uppalapati4e3c5db2013-01-08 10:54:14 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -07002 *
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>
Phani Kumar Uppalapati4e3c5db2013-01-08 10:54:14 -080022#include <linux/atomic.h>
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -070023#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;
Phani Kumar Uppalapati4e3c5db2013-01-08 10:54:14 -080054 case RESET_EVENTS:
55 pr_debug("%s:received RESET EVENTS\n", __func__);
56 audio->enabled = 0;
57 audio->stopped = 1;
58 audio->event_abort = 1;
59 wake_up(&audio->read_wait);
60 wake_up(&audio->write_wait);
61 break;
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -070062 default:
63 pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
64 audio->ac->session, opcode);
65 break;
66 }
67 spin_unlock_irqrestore(&audio->dsp_lock, flags);
68}
69
70void audio_in_get_dsp_frames(void *priv,
71 uint32_t token, uint32_t *payload)
72{
73 struct q6audio_in *audio = (struct q6audio_in *)priv;
74 uint32_t index;
75
76 index = token;
77 pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
78 __func__, audio->ac->session, token, payload[9],
79 payload[5]);
80 pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
81 audio->ac->session, payload[7], payload[6]);
82 pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
83 audio->ac->session, payload[8], payload[10]);
84 pr_debug("%s:session id %d: enc_framesotal_size=0x%8x\n", __func__,
85 audio->ac->session, payload[4]);
86
87 audio->out_frame_info[index][0] = payload[9];
88 audio->out_frame_info[index][1] = payload[5];
89
90 /* statistics of read */
91 atomic_add(payload[4], &audio->in_bytes);
92 atomic_add(payload[9], &audio->in_samples);
93
94 if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
95 atomic_inc(&audio->out_count);
96 wake_up(&audio->read_wait);
97 }
98}