blob: 96f823f90ffeaf7fff52e9635dcf5760c6f28b51 [file] [log] [blame]
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -07001/*
2 * Copyright (c) 2012 Code Aurora Forum. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
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 Uppalapati784ff992012-08-29 14:26:18 -070022#include <linux/atomic.h>
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -070023#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:
34 case ASM_DATA_EVENT_READ_DONE:
35 case ASM_DATA_CMDRSP_EOS:
36 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
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_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)
50{
51 union msm_audio_event_payload e_payload;
52 struct q6audio_aio *audio = (struct q6audio_aio *)priv;
53
54 switch (opcode) {
55 case ASM_DATA_EVENT_WRITE_DONE:
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:
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_CMDRSP_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_FORMAT_UPDATE:
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_NOTIFY:
94 pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, "
95
96 "payload[0]-sr = %d, payload[1]-chl = %d, "
97 "payload[2] = %d, payload[3] = %d\n", __func__,
98 audio, payload[0], payload[1], payload[2],
99 payload[3]);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700100 pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, sr(prev) = %d, chl(prev) = %d,",
101 __func__, audio, audio->pcm_cfg.sample_rate,
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -0700102 audio->pcm_cfg.channel_count);
103 audio->pcm_cfg.sample_rate = payload[0];
104 audio->pcm_cfg.channel_count = payload[1] & 0xFFFF;
105 e_payload.stream_info.chan_info = audio->pcm_cfg.channel_count;
106 e_payload.stream_info.sample_rate = audio->pcm_cfg.sample_rate;
107 audio_aio_post_event(audio, AUDIO_EVENT_STREAM_INFO, e_payload);
108 break;
109 default:
110 break;
111 }
112}
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700113
Phani Kumar Uppalapati784ff992012-08-29 14:26:18 -0700114void extract_meta_out_info(struct q6audio_aio *audio,
115 struct audio_aio_buffer_node *buf_node, int dir)
116{
117 struct dec_meta_out *meta_data = buf_node->kvaddr;
118 if (dir) { /* input buffer - Write */
119 if (audio->buf_cfg.meta_info_enable)
120 memcpy(&buf_node->meta_info.meta_in,
121 (char *)buf_node->kvaddr, sizeof(struct dec_meta_in));
122 else
123 memset(&buf_node->meta_info.meta_in,
124 0, sizeof(struct dec_meta_in));
125 pr_debug("%s[%p]:i/p: msw_ts 0x%lx lsw_ts 0x%lx nflags 0x%8x\n",
126 __func__, audio,
127 buf_node->meta_info.meta_in.ntimestamp.highpart,
128 buf_node->meta_info.meta_in.ntimestamp.lowpart,
129 buf_node->meta_info.meta_in.nflags);
130 } else { /* output buffer - Read */
131 memcpy((char *)buf_node->kvaddr,
132 &buf_node->meta_info.meta_out,
133 sizeof(struct dec_meta_out));
134 meta_data->meta_out_dsp[0].nflags = 0x00000000;
135 pr_debug("%s[%p]:o/p: msw_ts 0x%8x lsw_ts 0x%8x nflags 0x%8x, num_frames = %d\n",
136 __func__, audio,
137 ((struct dec_meta_out *)buf_node->kvaddr)->\
138 meta_out_dsp[0].msw_ts,
139 ((struct dec_meta_out *)buf_node->kvaddr)->\
140 meta_out_dsp[0].lsw_ts,
141 ((struct dec_meta_out *)buf_node->kvaddr)->\
142 meta_out_dsp[0].nflags,
143 ((struct dec_meta_out *)buf_node->kvaddr)->num_of_frames);
144 }
145}
146
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700147/* Read buffer from DSP / Handle Ack from DSP */
148void audio_aio_async_read_ack(struct q6audio_aio *audio, uint32_t token,
149 uint32_t *payload)
150{
151 unsigned long flags;
152 union msm_audio_event_payload event_payload;
153 struct audio_aio_buffer_node *filled_buf;
154
155 /* No active flush in progress */
156 if (audio->rflush)
157 return;
158
159 /* Statistics of read */
160 atomic_add(payload[2], &audio->in_bytes);
161 atomic_add(payload[7], &audio->in_samples);
162
163 spin_lock_irqsave(&audio->dsp_lock, flags);
164 BUG_ON(list_empty(&audio->in_queue));
165 filled_buf = list_first_entry(&audio->in_queue,
166 struct audio_aio_buffer_node, list);
167 if (token == (filled_buf->token)) {
168 list_del(&filled_buf->list);
169 spin_unlock_irqrestore(&audio->dsp_lock, flags);
170 event_payload.aio_buf = filled_buf->buf;
171 /* Read done Buffer due to flush/normal condition
172 after EOS event, so append EOS buffer */
173 if (audio->eos_rsp == 0x1) {
174 event_payload.aio_buf.data_len =
175 insert_eos_buf(audio, filled_buf);
176 /* Reset flag back to indicate eos intimated */
177 audio->eos_rsp = 0;
178 } else {
179 filled_buf->meta_info.meta_out.num_of_frames =
180 payload[7];
181 event_payload.aio_buf.data_len = payload[2] + \
182 payload[3] + \
183 sizeof(struct dec_meta_out);
184 pr_debug("%s[%p]:nr of frames 0x%8x len=%d\n",
185 __func__, audio,
186 filled_buf->meta_info.meta_out.num_of_frames,
187 event_payload.aio_buf.data_len);
188 extract_meta_out_info(audio, filled_buf, 0);
189 audio->eos_rsp = 0;
190 }
191 audio_aio_post_event(audio, AUDIO_EVENT_READ_DONE,
192 event_payload);
193 kfree(filled_buf);
194 } else {
195 pr_err("%s[%p]:expected=%lx ret=%x\n",
196 __func__, audio, filled_buf->token, token);
197 spin_unlock_irqrestore(&audio->dsp_lock, flags);
198 }
199}