blob: ad4fc6f6100286859940c5a852ea92d2ef938081 [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_aio.h"
25
26void q6_audio_cb(uint32_t opcode, uint32_t token,
27 uint32_t *payload, void *priv)
28{
29 struct q6audio_aio *audio = (struct q6audio_aio *)priv;
30
31 pr_debug("%s:opcode = %x token = 0x%x\n", __func__, opcode, token);
32 switch (opcode) {
33 case ASM_DATA_EVENT_WRITE_DONE_V2:
34 case ASM_DATA_EVENT_READ_DONE_V2:
35 case ASM_DATA_EVENT_RENDERED_EOS:
36 case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
37 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
38 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
39 case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
40 audio_aio_cb(opcode, token, payload, audio);
41 break;
42 default:
43 pr_debug("%s:Unhandled event = 0x%8x\n", __func__, opcode);
44 break;
45 }
46}
47
48void audio_aio_cb(uint32_t opcode, uint32_t token,
49 uint32_t *payload, void *priv/*struct q6audio_aio *audio*/)
50{
51 struct q6audio_aio *audio = (struct q6audio_aio *)priv;
52 union msm_audio_event_payload e_payload;
53
54 switch (opcode) {
55 case ASM_DATA_EVENT_WRITE_DONE_V2:
56 pr_debug("%s[%p]:ASM_DATA_EVENT_WRITE_DONE token = 0x%x\n",
57 __func__, audio, token);
58 audio_aio_async_write_ack(audio, token, payload);
59 break;
60 case ASM_DATA_EVENT_READ_DONE_V2:
61 pr_debug("%s[%p]:ASM_DATA_EVENT_READ_DONE token = 0x%x\n",
62 __func__, audio, token);
63 audio_aio_async_read_ack(audio, token, payload);
64 break;
65 case ASM_DATA_EVENT_RENDERED_EOS:
66 /* EOS Handle */
67 pr_debug("%s[%p]:ASM_DATA_CMDRSP_EOS\n", __func__, audio);
68 if (audio->feedback) { /* Non-Tunnel mode */
69 audio->eos_rsp = 1;
70 /* propagate input EOS i/p buffer,
71 after receiving DSP acknowledgement */
72 if (audio->eos_flag &&
73 (audio->eos_write_payload.aio_buf.buf_addr)) {
74 audio_aio_post_event(audio,
75 AUDIO_EVENT_WRITE_DONE,
76 audio->eos_write_payload);
77 memset(&audio->eos_write_payload , 0,
78 sizeof(union msm_audio_event_payload));
79 audio->eos_flag = 0;
80 }
81 } else { /* Tunnel mode */
82 audio->eos_rsp = 1;
83 wake_up(&audio->write_wait);
84 wake_up(&audio->cmd_wait);
85 }
86 break;
87 case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
88 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
89 pr_debug("%s[%p]:payload0[%x] payloa1d[%x]opcode= 0x%x\n",
90 __func__, audio, payload[0], payload[1], opcode);
91 break;
92 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
93 case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -070094 pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0]-sr = %d, payload[1]-chl = %d, payload[2] = %d, payload[3] = %d\n",
95 __func__, audio, payload[0],
96 payload[1], payload[2], payload[3]);
97
98 pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, sr(prev) = %d, chl(prev) = %d,",
Harmandeep Singheaf59b42012-06-05 21:46:02 -070099 __func__, audio, audio->pcm_cfg.sample_rate,
100 audio->pcm_cfg.channel_count);
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700101
102 audio->pcm_cfg.sample_rate = payload[0];
103 audio->pcm_cfg.channel_count = payload[1] & 0xFFFF;
104 e_payload.stream_info.chan_info = audio->pcm_cfg.channel_count;
105 e_payload.stream_info.sample_rate = audio->pcm_cfg.sample_rate;
106 audio_aio_post_event(audio, AUDIO_EVENT_STREAM_INFO, e_payload);
107 break;
108 default:
109 break;
110 }
111}
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700112
113/* Read buffer from DSP / Handle Ack from DSP */
114void audio_aio_async_read_ack(struct q6audio_aio *audio, uint32_t token,
115 uint32_t *payload)
116{
117 unsigned long flags;
118 union msm_audio_event_payload event_payload;
119 struct audio_aio_buffer_node *filled_buf;
120 pr_debug("%s\n", __func__);
121
122 /* No active flush in progress */
123 if (audio->rflush)
124 return;
125
126 /* Statistics of read */
127 atomic_add(payload[4], &audio->in_bytes);
128 atomic_add(payload[9], &audio->in_samples);
129
130 spin_lock_irqsave(&audio->dsp_lock, flags);
131 BUG_ON(list_empty(&audio->in_queue));
132 filled_buf = list_first_entry(&audio->in_queue,
133 struct audio_aio_buffer_node, list);
134
135 pr_debug("%s token: 0x[%d], filled_buf->token: 0x[%lu]",
136 __func__, token, filled_buf->token);
137 if (token == (filled_buf->token)) {
138 list_del(&filled_buf->list);
139 spin_unlock_irqrestore(&audio->dsp_lock, flags);
140 event_payload.aio_buf = filled_buf->buf;
141 /* Read done Buffer due to flush/normal condition
142 after EOS event, so append EOS buffer */
143 if (audio->eos_rsp == 0x1) {
144 event_payload.aio_buf.data_len =
145 insert_eos_buf(audio, filled_buf);
146 /* Reset flag back to indicate eos intimated */
147 audio->eos_rsp = 0;
148 } else {
149 filled_buf->meta_info.meta_out.num_of_frames\
150 = payload[9];
151 event_payload.aio_buf.data_len = payload[4]\
152 + payload[5] + sizeof(struct dec_meta_out);
153 pr_debug("%s[%p]:nr of frames 0x%8x len=%d\n",
154 __func__, audio,
155 filled_buf->meta_info.meta_out.num_of_frames,
156 event_payload.aio_buf.data_len);
157 extract_meta_out_info(audio, filled_buf, 0);
158 audio->eos_rsp = 0;
159 }
160 pr_debug("%s, posting read done to the app here\n", __func__);
161 audio_aio_post_event(audio, AUDIO_EVENT_READ_DONE,
162 event_payload);
163 kfree(filled_buf);
164 } else {
165 pr_err("%s[%p]:expected=%lx ret=%x\n",
166 __func__, audio, filled_buf->token, token);
167 spin_unlock_irqrestore(&audio->dsp_lock, flags);
168 }
169}