blob: 8808375132a97ddb9f9300ea6f3e66a10a473e16 [file] [log] [blame]
Mingming Yinc09967e2012-04-27 15:09:43 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -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/fs.h>
15#include <linux/module.h>
16#include <linux/miscdevice.h>
17#include <linux/slab.h>
18#include <linux/uaccess.h>
19#include <linux/mutex.h>
20#include <linux/sched.h>
21#include <linux/msm_audio_acdb.h>
22#include <asm/atomic.h>
Ben Romberger974a40d2011-07-18 15:08:21 -070023#include <mach/qdsp6v2/audio_acdb.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include <mach/qdsp6v2/rtac.h>
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -070025#include "q6audio_common.h"
26#include <sound/q6afe.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027
Ben Romberger45b351c2011-07-20 22:37:27 -070028#ifndef CONFIG_RTAC
Ben Rombergerfce8f512011-07-18 16:46:09 -070029
30void rtac_add_adm_device(u32 port_id, u32 copp_id, u32 path_id, u32 popp_id) {}
Ben Romberger93d4d2d2011-10-19 23:04:02 -070031void rtac_remove_adm_device(u32 port_id) {}
32void rtac_remove_popp_from_adm_devices(u32 popp_id) {}
Ben Rombergerfce8f512011-07-18 16:46:09 -070033void rtac_set_adm_handle(void *handle) {}
34bool rtac_make_adm_callback(uint32_t *payload, u32 payload_size)
35 {return false; }
36void rtac_set_asm_handle(u32 session_id, void *handle) {}
37bool rtac_make_asm_callback(u32 session_id, uint32_t *payload,
38 u32 payload_size) {return false; }
39void rtac_add_voice(u32 cvs_handle, u32 cvp_handle, u32 rx_afe_port,
Ben Rombergerc5d6a372011-09-22 18:01:49 -070040 u32 tx_afe_port, u32 session_id) {}
Ben Rombergerfce8f512011-07-18 16:46:09 -070041void rtac_remove_voice(u32 cvs_handle) {}
42void rtac_set_voice_handle(u32 mode, void *handle) {}
43bool rtac_make_voice_callback(u32 mode, uint32_t *payload,
44 u32 payload_size) {return false; }
45
46#else
47
48#define VOICE_CMD_SET_PARAM 0x00011006
49#define VOICE_CMD_GET_PARAM 0x00011007
50#define VOICE_EVT_GET_PARAM_ACK 0x00011008
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
52/* Max size of payload (buf size - apr header) */
53#define MAX_PAYLOAD_SIZE 4076
54#define RTAC_MAX_ACTIVE_DEVICES 4
55#define RTAC_MAX_ACTIVE_VOICE_COMBOS 2
56#define RTAC_MAX_ACTIVE_POPP 8
57#define RTAC_BUF_SIZE 4096
58
59#define TIMEOUT_MS 1000
60
61/* APR data */
62struct rtac_apr_data {
63 void *apr_handle;
64 atomic_t cmd_state;
65 wait_queue_head_t cmd_wait;
66};
67
68static struct rtac_apr_data rtac_adm_apr_data;
69static struct rtac_apr_data rtac_asm_apr_data[SESSION_MAX+1];
70static struct rtac_apr_data rtac_voice_apr_data[RTAC_VOICE_MODES];
71
72
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073/* ADM info & APR */
74struct rtac_adm_data {
Ben Romberger974a40d2011-07-18 15:08:21 -070075 uint32_t topology_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076 uint32_t afe_port;
77 uint32_t copp;
78 uint32_t num_of_popp;
79 uint32_t popp[RTAC_MAX_ACTIVE_POPP];
80};
81
82struct rtac_adm {
83 uint32_t num_of_dev;
84 struct rtac_adm_data device[RTAC_MAX_ACTIVE_DEVICES];
85};
86static struct rtac_adm rtac_adm_data;
87static u32 rtac_adm_payload_size;
88static u32 rtac_adm_user_buf_size;
89static u8 *rtac_adm_buffer;
90
91
92/* ASM APR */
93static u32 rtac_asm_payload_size;
94static u32 rtac_asm_user_buf_size;
95static u8 *rtac_asm_buffer;
96
97
98/* Voice info & APR */
99struct rtac_voice_data {
Ben Romberger974a40d2011-07-18 15:08:21 -0700100 uint32_t tx_topology_id;
101 uint32_t rx_topology_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700102 uint32_t tx_afe_port;
103 uint32_t rx_afe_port;
104 uint16_t cvs_handle;
105 uint16_t cvp_handle;
106};
107
108struct rtac_voice {
109 uint32_t num_of_voice_combos;
110 struct rtac_voice_data voice[RTAC_MAX_ACTIVE_VOICE_COMBOS];
111};
112
113static struct rtac_voice rtac_voice_data;
114static u32 rtac_voice_payload_size;
115static u32 rtac_voice_user_buf_size;
116static u8 *rtac_voice_buffer;
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700117static u32 voice_session_id[RTAC_MAX_ACTIVE_VOICE_COMBOS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118
119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120struct mutex rtac_adm_mutex;
121struct mutex rtac_adm_apr_mutex;
122struct mutex rtac_asm_apr_mutex;
123struct mutex rtac_voice_mutex;
124struct mutex rtac_voice_apr_mutex;
125
126static int rtac_open(struct inode *inode, struct file *f)
127{
128 pr_debug("%s\n", __func__);
129 return 0;
130}
131
132static int rtac_release(struct inode *inode, struct file *f)
133{
134 pr_debug("%s\n", __func__);
135 return 0;
136}
137
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138/* ADM Info */
139void add_popp(u32 dev_idx, u32 port_id, u32 popp_id)
140{
141 u32 i = 0;
142
143 for (; i < rtac_adm_data.device[dev_idx].num_of_popp; i++)
144 if (rtac_adm_data.device[dev_idx].popp[i] == popp_id)
145 goto done;
146
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 if (rtac_adm_data.device[dev_idx].num_of_popp ==
148 RTAC_MAX_ACTIVE_POPP) {
149 pr_err("%s, Max POPP!\n", __func__);
150 goto done;
151 }
152 rtac_adm_data.device[dev_idx].popp[
153 rtac_adm_data.device[dev_idx].num_of_popp++] = popp_id;
154done:
155 return;
156}
157
Ben Romberger974a40d2011-07-18 15:08:21 -0700158void rtac_add_adm_device(u32 port_id, u32 copp_id, u32 path_id, u32 popp_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159{
160 u32 i = 0;
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700161 pr_debug("%s: port_id = %d, popp_id = %d\n", __func__, port_id,
162 popp_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163
164 mutex_lock(&rtac_adm_mutex);
165 if (rtac_adm_data.num_of_dev == RTAC_MAX_ACTIVE_DEVICES) {
166 pr_err("%s, Can't add anymore RTAC devices!\n", __func__);
167 goto done;
168 }
169
170 /* Check if device already added */
171 if (rtac_adm_data.num_of_dev != 0) {
172 for (; i < rtac_adm_data.num_of_dev; i++) {
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700173 if (rtac_adm_data.device[i].afe_port == port_id) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 add_popp(i, port_id, popp_id);
175 goto done;
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700176 }
177 if (rtac_adm_data.device[i].num_of_popp ==
178 RTAC_MAX_ACTIVE_POPP) {
179 pr_err("%s, Max POPP!\n", __func__);
180 goto done;
181 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700182 }
183 }
184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 /* Add device */
186 rtac_adm_data.num_of_dev++;
Ben Romberger974a40d2011-07-18 15:08:21 -0700187
188 if (path_id == ADM_PATH_PLAYBACK)
189 rtac_adm_data.device[i].topology_id =
190 get_adm_rx_topology();
191 else
192 rtac_adm_data.device[i].topology_id =
193 get_adm_tx_topology();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194 rtac_adm_data.device[i].afe_port = port_id;
Ben Romberger974a40d2011-07-18 15:08:21 -0700195 rtac_adm_data.device[i].copp = copp_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700196 rtac_adm_data.device[i].popp[
197 rtac_adm_data.device[i].num_of_popp++] = popp_id;
198done:
199 mutex_unlock(&rtac_adm_mutex);
200 return;
201}
202
Ben Romberger974a40d2011-07-18 15:08:21 -0700203static void shift_adm_devices(u32 dev_idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204{
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700205 for (; dev_idx < rtac_adm_data.num_of_dev; dev_idx++) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206 memcpy(&rtac_adm_data.device[dev_idx],
207 &rtac_adm_data.device[dev_idx + 1],
208 sizeof(rtac_adm_data.device[dev_idx]));
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700209 memset(&rtac_adm_data.device[dev_idx + 1], 0,
210 sizeof(rtac_adm_data.device[dev_idx]));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 }
212}
213
Ben Romberger974a40d2011-07-18 15:08:21 -0700214static void shift_popp(u32 copp_idx, u32 popp_idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215{
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700216 for (; popp_idx < rtac_adm_data.device[copp_idx].num_of_popp;
217 popp_idx++) {
218 memcpy(&rtac_adm_data.device[copp_idx].popp[popp_idx],
219 &rtac_adm_data.device[copp_idx].popp[popp_idx + 1],
220 sizeof(uint32_t));
221 memset(&rtac_adm_data.device[copp_idx].popp[popp_idx + 1], 0,
222 sizeof(uint32_t));
223 }
224}
225
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700226void rtac_remove_adm_device(u32 port_id)
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700227{
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700228 s32 i;
229 pr_debug("%s: port_id = %d\n", __func__, port_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230
231 mutex_lock(&rtac_adm_mutex);
232 /* look for device */
233 for (i = 0; i < rtac_adm_data.num_of_dev; i++) {
234 if (rtac_adm_data.device[i].afe_port == port_id) {
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700235 memset(&rtac_adm_data.device[i], 0,
236 sizeof(rtac_adm_data.device[i]));
237 rtac_adm_data.num_of_dev--;
238
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700239 if (rtac_adm_data.num_of_dev >= 1) {
240 shift_adm_devices(i);
241 break;
242 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243 }
244 }
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700245
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700246 mutex_unlock(&rtac_adm_mutex);
247 return;
248}
249
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700250void rtac_remove_popp_from_adm_devices(u32 popp_id)
251{
252 s32 i, j;
253 pr_debug("%s: popp_id = %d\n", __func__, popp_id);
254
255 mutex_lock(&rtac_adm_mutex);
256
257 for (i = 0; i < rtac_adm_data.num_of_dev; i++) {
258 for (j = 0; j < rtac_adm_data.device[i].num_of_popp; j++) {
259 if (rtac_adm_data.device[i].popp[j] == popp_id) {
260 rtac_adm_data.device[i].popp[j] = 0;
261 rtac_adm_data.device[i].num_of_popp--;
262 shift_popp(i, j);
263 }
264 }
265 }
266
267 mutex_unlock(&rtac_adm_mutex);
268}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269
270/* Voice Info */
Ben Rombergerfce8f512011-07-18 16:46:09 -0700271static void set_rtac_voice_data(int idx, u32 cvs_handle, u32 cvp_handle,
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700272 u32 rx_afe_port, u32 tx_afe_port,
273 u32 session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700274{
Ben Romberger974a40d2011-07-18 15:08:21 -0700275 rtac_voice_data.voice[idx].tx_topology_id = get_voice_tx_topology();
276 rtac_voice_data.voice[idx].rx_topology_id = get_voice_rx_topology();
Ben Rombergerfce8f512011-07-18 16:46:09 -0700277 rtac_voice_data.voice[idx].tx_afe_port = tx_afe_port;
278 rtac_voice_data.voice[idx].rx_afe_port = rx_afe_port;
279 rtac_voice_data.voice[idx].cvs_handle = cvs_handle;
280 rtac_voice_data.voice[idx].cvp_handle = cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700281
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700282 /* Store session ID for voice RTAC */
283 voice_session_id[idx] = session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284}
285
Ben Rombergerfce8f512011-07-18 16:46:09 -0700286void rtac_add_voice(u32 cvs_handle, u32 cvp_handle, u32 rx_afe_port,
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700287 u32 tx_afe_port, u32 session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288{
289 u32 i = 0;
290 pr_debug("%s\n", __func__);
291 mutex_lock(&rtac_voice_mutex);
292
293 if (rtac_voice_data.num_of_voice_combos ==
294 RTAC_MAX_ACTIVE_VOICE_COMBOS) {
295 pr_err("%s, Can't add anymore RTAC devices!\n", __func__);
296 goto done;
297 }
298
299 /* Check if device already added */
300 if (rtac_voice_data.num_of_voice_combos != 0) {
301 for (; i < rtac_voice_data.num_of_voice_combos; i++) {
Ben Rombergerfce8f512011-07-18 16:46:09 -0700302 if (rtac_voice_data.voice[i].cvs_handle ==
303 cvs_handle) {
304 set_rtac_voice_data(i, cvs_handle, cvp_handle,
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700305 rx_afe_port, tx_afe_port,
306 session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700307 goto done;
308 }
309 }
310 }
311
312 /* Add device */
313 rtac_voice_data.num_of_voice_combos++;
Ben Rombergerfce8f512011-07-18 16:46:09 -0700314 set_rtac_voice_data(i, cvs_handle, cvp_handle,
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700315 rx_afe_port, tx_afe_port,
316 session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700317done:
318 mutex_unlock(&rtac_voice_mutex);
319 return;
320}
321
Ben Romberger974a40d2011-07-18 15:08:21 -0700322static void shift_voice_devices(u32 idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323{
324 for (; idx < rtac_voice_data.num_of_voice_combos - 1; idx++) {
325 memcpy(&rtac_voice_data.voice[idx],
326 &rtac_voice_data.voice[idx + 1],
327 sizeof(rtac_voice_data.voice[idx]));
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700328 voice_session_id[idx] = voice_session_id[idx + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700329 }
330}
331
Ben Rombergerfce8f512011-07-18 16:46:09 -0700332void rtac_remove_voice(u32 cvs_handle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333{
334 u32 i = 0;
335 pr_debug("%s\n", __func__);
336
337 mutex_lock(&rtac_voice_mutex);
338 /* look for device */
339 for (i = 0; i < rtac_voice_data.num_of_voice_combos; i++) {
Ben Rombergerfce8f512011-07-18 16:46:09 -0700340 if (rtac_voice_data.voice[i].cvs_handle == cvs_handle) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341 shift_voice_devices(i);
342 rtac_voice_data.num_of_voice_combos--;
343 memset(&rtac_voice_data.voice[
344 rtac_voice_data.num_of_voice_combos], 0,
345 sizeof(rtac_voice_data.voice
346 [rtac_voice_data.num_of_voice_combos]));
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700347 voice_session_id[rtac_voice_data.num_of_voice_combos]
348 = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349 break;
350 }
351 }
352 mutex_unlock(&rtac_voice_mutex);
353 return;
354}
355
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700356static int get_voice_index(u32 cvs_handle)
357{
358 u32 i;
359
360 for (i = 0; i < rtac_voice_data.num_of_voice_combos; i++) {
361 if (rtac_voice_data.voice[i].cvs_handle == cvs_handle)
362 return i;
363 }
364
365 pr_err("%s: No voice index for CVS handle %d found returning 0\n",
366 __func__, cvs_handle);
367 return 0;
368}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369
370
371/* ADM APR */
372void rtac_set_adm_handle(void *handle)
373{
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700374 pr_debug("%s: handle = %d\n", __func__, (unsigned int)handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700375
376 mutex_lock(&rtac_adm_apr_mutex);
377 rtac_adm_apr_data.apr_handle = handle;
378 mutex_unlock(&rtac_adm_apr_mutex);
379}
380
381bool rtac_make_adm_callback(uint32_t *payload, u32 payload_size)
382{
Swaminathan Sathappan88163a72011-08-01 16:01:14 -0700383 pr_debug("%s:cmd_state = %d\n", __func__,
384 atomic_read(&rtac_adm_apr_data.cmd_state));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700385 if (atomic_read(&rtac_adm_apr_data.cmd_state) != 1)
386 return false;
387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700388 /* Offset data for in-band payload */
389 rtac_copy_adm_payload_to_user(payload, payload_size);
390 atomic_set(&rtac_adm_apr_data.cmd_state, 0);
391 wake_up(&rtac_adm_apr_data.cmd_wait);
392 return true;
393}
394
395void rtac_copy_adm_payload_to_user(void *payload, u32 payload_size)
396{
397 pr_debug("%s\n", __func__);
398 rtac_adm_payload_size = payload_size;
399
400 memcpy(rtac_adm_buffer, &payload_size, sizeof(u32));
401 if (payload_size != 0) {
402 if (payload_size > rtac_adm_user_buf_size) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700403 pr_err("%s: Buffer set not big enough for returned data, buf size = %d,ret data = %d\n",
404 __func__, rtac_adm_user_buf_size, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700405 goto done;
406 }
407 memcpy(rtac_adm_buffer + sizeof(u32), payload, payload_size);
408 }
409done:
410 return;
411}
412
413u32 send_adm_apr(void *buf, u32 opcode)
414{
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700415 s32 result;
416 u32 count = 0;
417 u32 bytes_returned = 0;
418 u32 port_index = 0;
419 u32 copp_id;
420 u32 payload_size;
421 struct apr_hdr adm_params;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700422 pr_debug("%s\n", __func__);
423
424 if (copy_from_user(&count, (void *)buf, sizeof(count))) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700425 pr_err("%s: Copy to user failed! buf = 0x%x\n",
426 __func__, (unsigned int)buf);
427 result = -EFAULT;
428 goto done;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700429 }
430
431 if (count <= 0) {
432 pr_err("%s: Invalid buffer size = %d\n", __func__, count);
433 goto done;
434 }
435
436 if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) {
437 pr_err("%s: Could not copy payload size from user buffer\n",
438 __func__);
439 goto done;
440 }
441
442
Bharath Ramachandramurthy94ad7e22012-02-28 18:44:07 -0800443 if (payload_size > MAX_PAYLOAD_SIZE) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700444 pr_err("%s: Invalid payload size = %d\n",
445 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700446 goto done;
447 }
448
449 if (copy_from_user(&copp_id, buf + 2 * sizeof(u32), sizeof(u32))) {
450 pr_err("%s: Could not copy port id from user buffer\n",
451 __func__);
452 goto done;
453 }
454
Ben Romberger974a40d2011-07-18 15:08:21 -0700455 for (port_index = 0; port_index < AFE_MAX_PORTS; port_index++) {
456 if (adm_get_copp_id(port_index) == copp_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700457 break;
458 }
Ben Romberger974a40d2011-07-18 15:08:21 -0700459 if (port_index >= AFE_MAX_PORTS) {
460 pr_err("%s: Could not find port index for copp = %d\n",
461 __func__, copp_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700462 goto done;
463 }
464
465 mutex_lock(&rtac_adm_apr_mutex);
466 if (rtac_adm_apr_data.apr_handle == NULL) {
467 pr_err("%s: APR not initialized\n", __func__);
468 goto err;
469 }
470
471 /* Set globals for copy of returned payload */
472 rtac_adm_user_buf_size = count;
473 /* Copy buffer to in-band payload */
474 if (copy_from_user(rtac_adm_buffer + sizeof(adm_params),
475 buf + 3 * sizeof(u32), payload_size)) {
476 pr_err("%s: Could not copy payload from user buffer\n",
477 __func__);
478 goto err;
479 }
480
481 /* Pack header */
482 adm_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
483 APR_HDR_LEN(20), APR_PKT_VER);
484 adm_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
485 payload_size);
486 adm_params.src_svc = APR_SVC_ADM;
487 adm_params.src_domain = APR_DOMAIN_APPS;
Ben Romberger1dc9f8a2012-04-10 21:47:54 -0700488 adm_params.src_port = copp_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700489 adm_params.dest_svc = APR_SVC_ADM;
490 adm_params.dest_domain = APR_DOMAIN_ADSP;
Ben Romberger974a40d2011-07-18 15:08:21 -0700491 adm_params.dest_port = copp_id;
Ben Romberger1dc9f8a2012-04-10 21:47:54 -0700492 adm_params.token = copp_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493 adm_params.opcode = opcode;
494
495 memcpy(rtac_adm_buffer, &adm_params, sizeof(adm_params));
496 atomic_set(&rtac_adm_apr_data.cmd_state, 1);
497
498 pr_debug("%s: Sending RTAC command size = %d\n",
499 __func__, adm_params.pkt_size);
500
501 result = apr_send_pkt(rtac_adm_apr_data.apr_handle,
502 (uint32_t *)rtac_adm_buffer);
503 if (result < 0) {
Ben Romberger974a40d2011-07-18 15:08:21 -0700504 pr_err("%s: Set params failed port = %d, copp = %d\n",
505 __func__, port_index, copp_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506 goto err;
507 }
508 /* Wait for the callback */
509 result = wait_event_timeout(rtac_adm_apr_data.cmd_wait,
510 (atomic_read(&rtac_adm_apr_data.cmd_state) == 0),
511 msecs_to_jiffies(TIMEOUT_MS));
512 mutex_unlock(&rtac_adm_apr_mutex);
513 if (!result) {
Ben Romberger974a40d2011-07-18 15:08:21 -0700514 pr_err("%s: Set params timed out port = %d, copp = %d\n",
515 __func__, port_index, copp_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700516 goto done;
517 }
518
519 if (rtac_adm_payload_size != 0) {
520 if (copy_to_user(buf, rtac_adm_buffer,
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700521 rtac_adm_payload_size + sizeof(u32))) {
522 pr_err("%s: Could not copy buffer to user, size = %d\n",
523 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524 goto done;
525 }
526 }
527
528 /* Return data written for SET & data read for GET */
529 if (opcode == ADM_CMD_GET_PARAMS)
530 bytes_returned = rtac_adm_payload_size;
531 else
532 bytes_returned = payload_size;
533done:
534 return bytes_returned;
535err:
536 mutex_unlock(&rtac_adm_apr_mutex);
537 return bytes_returned;
538}
539
540
541/* ASM APR */
542void rtac_set_asm_handle(u32 session_id, void *handle)
543{
544 pr_debug("%s\n", __func__);
545
546 mutex_lock(&rtac_asm_apr_mutex);
547 rtac_asm_apr_data[session_id].apr_handle = handle;
548 mutex_unlock(&rtac_asm_apr_mutex);
549}
550
551bool rtac_make_asm_callback(u32 session_id, uint32_t *payload,
552 u32 payload_size)
553{
554 if (atomic_read(&rtac_asm_apr_data[session_id].cmd_state) != 1)
555 return false;
556
557 pr_debug("%s\n", __func__);
558 /* Offset data for in-band payload */
559 rtac_copy_asm_payload_to_user(payload, payload_size);
560 atomic_set(&rtac_asm_apr_data[session_id].cmd_state, 0);
561 wake_up(&rtac_asm_apr_data[session_id].cmd_wait);
562 return true;
563}
564
565void rtac_copy_asm_payload_to_user(void *payload, u32 payload_size)
566{
567 pr_debug("%s\n", __func__);
568 rtac_asm_payload_size = payload_size;
569
570 memcpy(rtac_asm_buffer, &payload_size, sizeof(u32));
571 if (payload_size) {
572 if (payload_size > rtac_asm_user_buf_size) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700573 pr_err("%s: Buffer set not big enough for returned data, buf size = %d, ret data = %d\n",
574 __func__, rtac_asm_user_buf_size, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 goto done;
576 }
577 memcpy(rtac_asm_buffer + sizeof(u32), payload, payload_size);
578 }
579done:
580 return;
581}
582
583u32 send_rtac_asm_apr(void *buf, u32 opcode)
584{
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700585 s32 result;
586 u32 count = 0;
587 u32 bytes_returned = 0;
588 u32 session_id = 0;
589 u32 payload_size;
590 struct apr_hdr asm_params;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591 pr_debug("%s\n", __func__);
592
593 if (copy_from_user(&count, (void *)buf, sizeof(count))) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700594 pr_err("%s: Copy to user failed! buf = 0x%x\n",
595 __func__, (unsigned int)buf);
596 result = -EFAULT;
597 goto done;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700598 }
599
600 if (count <= 0) {
601 pr_err("%s: Invalid buffer size = %d\n", __func__, count);
602 goto done;
603 }
604
605 if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) {
606 pr_err("%s: Could not copy payload size from user buffer\n",
607 __func__);
608 goto done;
609 }
610
Bharath Ramachandramurthy94ad7e22012-02-28 18:44:07 -0800611 if (payload_size > MAX_PAYLOAD_SIZE) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700612 pr_err("%s: Invalid payload size = %d\n",
613 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700614 goto done;
615 }
616
617 if (copy_from_user(&session_id, buf + 2 * sizeof(u32), sizeof(u32))) {
618 pr_err("%s: Could not copy session id from user buffer\n",
619 __func__);
620 goto done;
621 }
Mingming Yinc09967e2012-04-27 15:09:43 -0700622 if (session_id > (SESSION_MAX + 1)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623 pr_err("%s: Invalid Session = %d\n", __func__, session_id);
624 goto done;
625 }
626
627 mutex_lock(&rtac_asm_apr_mutex);
Mingming Yinc09967e2012-04-27 15:09:43 -0700628 if (session_id < SESSION_MAX+1) {
629 if (rtac_asm_apr_data[session_id].apr_handle == NULL) {
630 pr_err("%s: APR not initialized\n", __func__);
631 goto err;
632 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633 }
634
635 /* Set globals for copy of returned payload */
636 rtac_asm_user_buf_size = count;
637
638 /* Copy buffer to in-band payload */
639 if (copy_from_user(rtac_asm_buffer + sizeof(asm_params),
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700640 buf + 3 * sizeof(u32), payload_size)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700641 pr_err("%s: Could not copy payload from user buffer\n",
642 __func__);
643 goto err;
644 }
645
646 /* Pack header */
647 asm_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
648 APR_HDR_LEN(20), APR_PKT_VER);
649 asm_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
650 payload_size);
651 asm_params.src_svc = q6asm_get_apr_service_id(session_id);
652 asm_params.src_domain = APR_DOMAIN_APPS;
653 asm_params.src_port = (session_id << 8) | 0x0001;
654 asm_params.dest_svc = APR_SVC_ASM;
655 asm_params.dest_domain = APR_DOMAIN_ADSP;
656 asm_params.dest_port = (session_id << 8) | 0x0001;
657 asm_params.token = session_id;
658 asm_params.opcode = opcode;
659
660 memcpy(rtac_asm_buffer, &asm_params, sizeof(asm_params));
Bharath Ramachandramurthy94ad7e22012-02-28 18:44:07 -0800661 if (session_id < SESSION_MAX+1)
662 atomic_set(&rtac_asm_apr_data[session_id].cmd_state, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663
664 pr_debug("%s: Sending RTAC command size = %d, session_id=%d\n",
665 __func__, asm_params.pkt_size, session_id);
666
667 result = apr_send_pkt(rtac_asm_apr_data[session_id].apr_handle,
668 (uint32_t *)rtac_asm_buffer);
669 if (result < 0) {
670 pr_err("%s: Set params failed session = %d\n",
671 __func__, session_id);
672 goto err;
673 }
674
675 /* Wait for the callback */
676 result = wait_event_timeout(rtac_asm_apr_data[session_id].cmd_wait,
677 (atomic_read(&rtac_asm_apr_data[session_id].cmd_state) == 0),
678 5 * HZ);
679 mutex_unlock(&rtac_asm_apr_mutex);
680 if (!result) {
681 pr_err("%s: Set params timed out session = %d\n",
682 __func__, session_id);
683 goto done;
684 }
685
686 if (rtac_asm_payload_size != 0) {
687 if (copy_to_user(buf, rtac_asm_buffer,
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700688 rtac_asm_payload_size + sizeof(u32))) {
689 pr_err("%s: Could not copy buffer to user,size = %d\n",
690 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691 goto done;
692 }
693 }
694
695 /* Return data written for SET & data read for GET */
696 if (opcode == ASM_STREAM_CMD_GET_PP_PARAMS)
697 bytes_returned = rtac_asm_payload_size;
698 else
699 bytes_returned = payload_size;
700done:
701 return bytes_returned;
702err:
703 mutex_unlock(&rtac_asm_apr_mutex);
704 return bytes_returned;
705}
706
707
708/* Voice APR */
709void rtac_set_voice_handle(u32 mode, void *handle)
710{
711 pr_debug("%s\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700712 mutex_lock(&rtac_voice_apr_mutex);
713 rtac_voice_apr_data[mode].apr_handle = handle;
714 mutex_unlock(&rtac_voice_apr_mutex);
715}
716
717bool rtac_make_voice_callback(u32 mode, uint32_t *payload, u32 payload_size)
718{
719 if ((atomic_read(&rtac_voice_apr_data[mode].cmd_state) != 1) ||
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700720 (mode >= RTAC_VOICE_MODES))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 return false;
722
723 pr_debug("%s\n", __func__);
724 /* Offset data for in-band payload */
725 rtac_copy_voice_payload_to_user(payload, payload_size);
726 atomic_set(&rtac_voice_apr_data[mode].cmd_state, 0);
727 wake_up(&rtac_voice_apr_data[mode].cmd_wait);
728 return true;
729}
730
731void rtac_copy_voice_payload_to_user(void *payload, u32 payload_size)
732{
733 pr_debug("%s\n", __func__);
734 rtac_voice_payload_size = payload_size;
735
736 memcpy(rtac_voice_buffer, &payload_size, sizeof(u32));
737 if (payload_size) {
738 if (payload_size > rtac_voice_user_buf_size) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700739 pr_err("%s: Buffer set not big enough for returned data, buf size = %d, ret data = %d\n",
740 __func__, rtac_voice_user_buf_size, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700741 goto done;
742 }
743 memcpy(rtac_voice_buffer + sizeof(u32), payload, payload_size);
744 }
745done:
746 return;
747}
748
749u32 send_voice_apr(u32 mode, void *buf, u32 opcode)
750{
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700751 s32 result;
752 u32 count = 0;
753 u32 bytes_returned = 0;
754 u32 payload_size;
755 u16 dest_port;
756 struct apr_hdr voice_params;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757 pr_debug("%s\n", __func__);
758
759 if (copy_from_user(&count, (void *)buf, sizeof(count))) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700760 pr_err("%s: Copy to user failed! buf = 0x%x\n",
761 __func__, (unsigned int)buf);
762 result = -EFAULT;
763 goto done;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700764 }
765
766 if (count <= 0) {
767 pr_err("%s: Invalid buffer size = %d\n", __func__, count);
768 goto done;
769 }
770
771 if (copy_from_user(&payload_size, buf + sizeof(u32), sizeof(u32))) {
772 pr_err("%s: Could not copy payload size from user buffer\n",
773 __func__);
774 goto done;
775 }
776
Bharath Ramachandramurthy94ad7e22012-02-28 18:44:07 -0800777 if (payload_size > MAX_PAYLOAD_SIZE) {
778 pr_err("%s: Invalid payload size = %d\n",
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700779 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780 goto done;
781 }
782
783 if (copy_from_user(&dest_port, buf + 2 * sizeof(u32), sizeof(u32))) {
784 pr_err("%s: Could not copy port id from user buffer\n",
785 __func__);
786 goto done;
787 }
788
789 if ((mode != RTAC_CVP) && (mode != RTAC_CVS)) {
790 pr_err("%s: Invalid Mode for APR, mode = %d\n",
791 __func__, mode);
792 goto done;
793 }
794
795 mutex_lock(&rtac_voice_apr_mutex);
796 if (rtac_voice_apr_data[mode].apr_handle == NULL) {
797 pr_err("%s: APR not initialized\n", __func__);
798 goto err;
799 }
800
801 /* Set globals for copy of returned payload */
802 rtac_voice_user_buf_size = count;
803
804 /* Copy buffer to in-band payload */
805 if (copy_from_user(rtac_voice_buffer + sizeof(voice_params),
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700806 buf + 3 * sizeof(u32), payload_size)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700807 pr_err("%s: Could not copy payload from user buffer\n",
808 __func__);
809 goto err;
810 }
811
812 /* Pack header */
813 voice_params.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
814 APR_HDR_LEN(20), APR_PKT_VER);
815 voice_params.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
816 payload_size);
817 voice_params.src_svc = 0;
818 voice_params.src_domain = APR_DOMAIN_APPS;
Ben Rombergerc5d6a372011-09-22 18:01:49 -0700819 voice_params.src_port = voice_session_id[
820 get_voice_index(dest_port)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821 voice_params.dest_svc = 0;
822 voice_params.dest_domain = APR_DOMAIN_MODEM;
823 voice_params.dest_port = dest_port;
824 voice_params.token = 0;
825 voice_params.opcode = opcode;
826
827 memcpy(rtac_voice_buffer, &voice_params, sizeof(voice_params));
828 atomic_set(&rtac_voice_apr_data[mode].cmd_state, 1);
829
830 pr_debug("%s: Sending RTAC command size = %d, opcode = %x\n",
831 __func__, voice_params.pkt_size, opcode);
832
833 result = apr_send_pkt(rtac_voice_apr_data[mode].apr_handle,
834 (uint32_t *)rtac_voice_buffer);
835 if (result < 0) {
836 pr_err("%s: apr_send_pkt failed opcode = %x\n",
837 __func__, opcode);
838 goto err;
839 }
840 /* Wait for the callback */
841 result = wait_event_timeout(rtac_voice_apr_data[mode].cmd_wait,
842 (atomic_read(&rtac_voice_apr_data[mode].cmd_state) == 0),
843 msecs_to_jiffies(TIMEOUT_MS));
844 mutex_unlock(&rtac_voice_apr_mutex);
845 if (!result) {
846 pr_err("%s: apr_send_pkt timed out opcode = %x\n",
847 __func__, opcode);
848 goto done;
849 }
850
851 if (rtac_voice_payload_size != 0) {
852 if (copy_to_user(buf, rtac_voice_buffer,
853 rtac_voice_payload_size + sizeof(u32))) {
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700854 pr_err("%s: Could not copy buffer to user,size = %d\n",
855 __func__, payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856 goto done;
857 }
858 }
859
860 /* Return data written for SET & data read for GET */
861 if (opcode == VOICE_CMD_GET_PARAM)
862 bytes_returned = rtac_voice_payload_size;
863 else
864 bytes_returned = payload_size;
865done:
866 return bytes_returned;
867err:
868 mutex_unlock(&rtac_voice_apr_mutex);
869 return bytes_returned;
870}
871
872
873
Ben Romberger974a40d2011-07-18 15:08:21 -0700874static long rtac_ioctl(struct file *f,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 unsigned int cmd, unsigned long arg)
876{
877 s32 result = 0;
878 pr_debug("%s\n", __func__);
879
880 if (arg == 0) {
881 pr_err("%s: No data sent to driver!\n", __func__);
882 result = -EFAULT;
883 goto done;
884 }
885
886 switch (cmd) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 case AUDIO_GET_RTAC_ADM_INFO:
888 if (copy_to_user((void *)arg, &rtac_adm_data,
889 sizeof(rtac_adm_data)))
890 pr_err("%s: Could not copy to userspace!\n", __func__);
891 else
892 result = sizeof(rtac_adm_data);
893 break;
894 case AUDIO_GET_RTAC_VOICE_INFO:
895 if (copy_to_user((void *)arg, &rtac_voice_data,
896 sizeof(rtac_voice_data)))
897 pr_err("%s: Could not copy to userspace!\n", __func__);
898 else
899 result = sizeof(rtac_voice_data);
900 break;
901 case AUDIO_GET_RTAC_ADM_CAL:
902 result = send_adm_apr((void *)arg, ADM_CMD_GET_PARAMS);
903 break;
904 case AUDIO_SET_RTAC_ADM_CAL:
905 result = send_adm_apr((void *)arg, ADM_CMD_SET_PARAMS);
906 break;
907 case AUDIO_GET_RTAC_ASM_CAL:
908 result = send_rtac_asm_apr((void *)arg,
909 ASM_STREAM_CMD_GET_PP_PARAMS);
910 break;
911 case AUDIO_SET_RTAC_ASM_CAL:
912 result = send_rtac_asm_apr((void *)arg,
913 ASM_STREAM_CMD_SET_PP_PARAMS);
914 break;
915 case AUDIO_GET_RTAC_CVS_CAL:
916 result = send_voice_apr(RTAC_CVS, (void *)arg,
917 VOICE_CMD_GET_PARAM);
918 break;
919 case AUDIO_SET_RTAC_CVS_CAL:
920 result = send_voice_apr(RTAC_CVS, (void *)arg,
921 VOICE_CMD_SET_PARAM);
922 break;
923 case AUDIO_GET_RTAC_CVP_CAL:
924 result = send_voice_apr(RTAC_CVP, (void *)arg,
925 VOICE_CMD_GET_PARAM);
926 break;
927 case AUDIO_SET_RTAC_CVP_CAL:
928 result = send_voice_apr(RTAC_CVP, (void *)arg,
929 VOICE_CMD_SET_PARAM);
930 break;
931 default:
932 pr_err("%s: Invalid IOCTL, command = %d!\n",
933 __func__, cmd);
934 }
935done:
936 return result;
937}
938
939
940static const struct file_operations rtac_fops = {
941 .owner = THIS_MODULE,
942 .open = rtac_open,
943 .release = rtac_release,
Ben Romberger974a40d2011-07-18 15:08:21 -0700944 .unlocked_ioctl = rtac_ioctl,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700945};
946
947struct miscdevice rtac_misc = {
948 .minor = MISC_DYNAMIC_MINOR,
949 .name = "msm_rtac",
950 .fops = &rtac_fops,
951};
952
953static int __init rtac_init(void)
954{
955 int i = 0;
956 pr_debug("%s\n", __func__);
957
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700958 /* ADM */
959 memset(&rtac_adm_data, 0, sizeof(rtac_adm_data));
960 rtac_adm_apr_data.apr_handle = NULL;
961 atomic_set(&rtac_adm_apr_data.cmd_state, 0);
962 init_waitqueue_head(&rtac_adm_apr_data.cmd_wait);
963 mutex_init(&rtac_adm_mutex);
964 mutex_init(&rtac_adm_apr_mutex);
965
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700966 rtac_adm_buffer = kzalloc(RTAC_BUF_SIZE, GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 if (rtac_adm_buffer == NULL) {
968 pr_err("%s: Could not allocate payload of size = %d\n",
969 __func__, RTAC_BUF_SIZE);
970 goto nomem;
971 }
972
973 /* ASM */
974 for (i = 0; i < SESSION_MAX+1; i++) {
975 rtac_asm_apr_data[i].apr_handle = NULL;
976 atomic_set(&rtac_asm_apr_data[i].cmd_state, 0);
977 init_waitqueue_head(&rtac_asm_apr_data[i].cmd_wait);
978 }
979 mutex_init(&rtac_asm_apr_mutex);
980
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700981 rtac_asm_buffer = kzalloc(RTAC_BUF_SIZE, GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700982 if (rtac_asm_buffer == NULL) {
983 pr_err("%s: Could not allocate payload of size = %d\n",
984 __func__, RTAC_BUF_SIZE);
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700985 kzfree(rtac_adm_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700986 goto nomem;
987 }
988
989 /* Voice */
990 memset(&rtac_voice_data, 0, sizeof(rtac_voice_data));
991 for (i = 0; i < RTAC_VOICE_MODES; i++) {
992 rtac_voice_apr_data[i].apr_handle = NULL;
993 atomic_set(&rtac_voice_apr_data[i].cmd_state, 0);
994 init_waitqueue_head(&rtac_voice_apr_data[i].cmd_wait);
995 }
996 mutex_init(&rtac_voice_mutex);
997 mutex_init(&rtac_voice_apr_mutex);
998
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -0700999 rtac_voice_buffer = kzalloc(RTAC_BUF_SIZE, GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001000 if (rtac_voice_buffer == NULL) {
1001 pr_err("%s: Could not allocate payload of size = %d\n",
1002 __func__, RTAC_BUF_SIZE);
Harmandeep Singhe5ddfe32012-05-26 09:39:25 -07001003 kzfree(rtac_adm_buffer);
1004 kzfree(rtac_asm_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001005 goto nomem;
1006 }
1007
1008 return misc_register(&rtac_misc);
1009nomem:
1010 return -ENOMEM;
1011}
1012
1013module_init(rtac_init);
1014
1015MODULE_DESCRIPTION("MSM 8x60 Real-Time Audio Calibration driver");
1016MODULE_LICENSE("GPL v2");
Ben Rombergerfce8f512011-07-18 16:46:09 -07001017
1018#endif