blob: 6676d4d1f3714447c802794d2a0574394adb30f5 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, 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#include <linux/slab.h>
13#include <linux/kthread.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/uaccess.h>
17#include <linux/wait.h>
18#include <linux/mutex.h>
Ben Romberger13b74ab2011-07-18 17:36:32 -070019
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020#include <mach/qdsp6v2/audio_acdb.h>
Ben Romberger13b74ab2011-07-18 17:36:32 -070021#include <mach/qdsp6v2/rtac.h>
22
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include "sound/apr_audio.h"
24#include "sound/q6afe.h"
Ben Romberger13b74ab2011-07-18 17:36:32 -070025
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include "q6voice.h"
27
28#define TIMEOUT_MS 3000
29
30#define CMD_STATUS_SUCCESS 0
31#define CMD_STATUS_FAIL 1
32
33#define VOC_PATH_PASSIVE 0
34#define VOC_PATH_FULL 1
35
Neema Shetty2c07eb52011-08-21 20:33:52 -070036static struct common_data common;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38static int voice_send_enable_vocproc_cmd(struct voice_data *v);
39static int voice_send_netid_timing_cmd(struct voice_data *v);
40static int voice_send_attach_vocproc_cmd(struct voice_data *v);
41static int voice_send_set_device_cmd(struct voice_data *v);
42static int voice_send_disable_vocproc_cmd(struct voice_data *v);
43static int voice_send_vol_index_cmd(struct voice_data *v);
Helen Zeng29eb7442011-06-20 11:06:29 -070044static int voice_send_cvp_map_memory_cmd(struct voice_data *v);
45static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v);
46static int voice_send_cvs_map_memory_cmd(struct voice_data *v);
47static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v);
48static int voice_send_cvs_register_cal_cmd(struct voice_data *v);
49static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v);
50static int voice_send_cvp_register_cal_cmd(struct voice_data *v);
51static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v);
52static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v);
53static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v);
Helen Zeng44d4d272011-08-10 14:49:20 -070054static int voice_send_set_widevoice_enable_cmd(struct voice_data *v);
Helen Zengbb49c702011-09-06 14:09:13 -070055static int voice_send_set_slowtalk_enable_cmd(struct voice_data *v);
Helen Zeng29eb7442011-06-20 11:06:29 -070056
Helen Zeng0705a5f2011-10-14 15:29:52 -070057static int voice_cvs_stop_playback(struct voice_data *v);
58static int voice_cvs_start_playback(struct voice_data *v);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059
60static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
61static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
62static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
63
64static u16 voice_get_mvm_handle(struct voice_data *v)
65{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 if (v == NULL) {
67 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070068 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070
Neema Shetty2c07eb52011-08-21 20:33:52 -070071 pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072
Neema Shetty2c07eb52011-08-21 20:33:52 -070073 return v->mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074}
75
76static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
77{
78 pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
79 if (v == NULL) {
80 pr_err("%s: v is NULL\n", __func__);
81 return;
82 }
83
Neema Shetty2c07eb52011-08-21 20:33:52 -070084 v->mvm_handle = mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085}
86
87static u16 voice_get_cvs_handle(struct voice_data *v)
88{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 if (v == NULL) {
90 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070091 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093
Neema Shetty2c07eb52011-08-21 20:33:52 -070094 pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095
Neema Shetty2c07eb52011-08-21 20:33:52 -070096 return v->cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097}
98
99static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
100{
101 pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
102 if (v == NULL) {
103 pr_err("%s: v is NULL\n", __func__);
104 return;
105 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700106
107 v->cvs_handle = cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108}
109
110static u16 voice_get_cvp_handle(struct voice_data *v)
111{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700112 if (v == NULL) {
113 pr_err("%s: v is NULL\n", __func__);
114 return 0;
115 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116
Neema Shetty2c07eb52011-08-21 20:33:52 -0700117 pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118
Neema Shetty2c07eb52011-08-21 20:33:52 -0700119 return v->cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120}
121
122static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
123{
124 pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
125 if (v == NULL) {
126 pr_err("%s: v is NULL\n", __func__);
127 return;
128 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700129
130 v->cvp_handle = cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131}
132
Neema Shetty2c07eb52011-08-21 20:33:52 -0700133uint16_t voc_get_session_id(char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700135 u16 session_id = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700136
Neema Shetty2c07eb52011-08-21 20:33:52 -0700137 if (name != NULL) {
138 if (!strncmp(name, "Voice session", 13))
139 session_id = common.voice[VOC_PATH_PASSIVE].session_id;
140 else
141 session_id = common.voice[VOC_PATH_FULL].session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142
Helen Zeng0f4c4e22011-09-29 14:25:43 -0700143 pr_debug("%s: %s has session id 0x%x\n", __func__, name,
144 session_id);
145 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700146
147 return session_id;
148}
149
150static struct voice_data *voice_get_session(u16 session_id)
151{
152 struct voice_data *v = NULL;
153
154 if ((session_id >= SESSION_ID_BASE) &&
155 (session_id < SESSION_ID_BASE + MAX_VOC_SESSIONS)) {
156 v = &common.voice[session_id - SESSION_ID_BASE];
157 }
158
159 pr_debug("%s: session_id 0x%x session handle 0x%x\n",
160 __func__, session_id, (unsigned int)v);
161
162 return v;
163}
164
165static bool is_voice_session(u16 session_id)
166{
167 return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
168}
169
170static bool is_voip_session(u16 session_id)
171{
172 return (session_id == common.voice[VOC_PATH_FULL].session_id);
173}
174
175static int voice_apr_register(void)
176{
177 pr_debug("%s\n", __func__);
178
179 mutex_lock(&common.common_lock);
180
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 /* register callback to APR */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700182 if (common.apr_q6_mvm == NULL) {
183 pr_debug("%s: Start to register MVM callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184
Neema Shetty2c07eb52011-08-21 20:33:52 -0700185 common.apr_q6_mvm = apr_register("ADSP", "MVM",
186 qdsp_mvm_callback,
187 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188
Neema Shetty2c07eb52011-08-21 20:33:52 -0700189 if (common.apr_q6_mvm == NULL) {
190 pr_err("%s: Unable to register MVM\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191 goto err;
192 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 }
194
Neema Shetty2c07eb52011-08-21 20:33:52 -0700195 if (common.apr_q6_cvs == NULL) {
196 pr_debug("%s: Start to register CVS callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197
Neema Shetty2c07eb52011-08-21 20:33:52 -0700198 common.apr_q6_cvs = apr_register("ADSP", "CVS",
199 qdsp_cvs_callback,
200 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201
Neema Shetty2c07eb52011-08-21 20:33:52 -0700202 if (common.apr_q6_cvs == NULL) {
203 pr_err("%s: Unable to register CVS\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 goto err;
205 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700206
Neema Shetty2c07eb52011-08-21 20:33:52 -0700207 rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208 }
209
Neema Shetty2c07eb52011-08-21 20:33:52 -0700210 if (common.apr_q6_cvp == NULL) {
211 pr_debug("%s: Start to register CVP callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212
Neema Shetty2c07eb52011-08-21 20:33:52 -0700213 common.apr_q6_cvp = apr_register("ADSP", "CVP",
214 qdsp_cvp_callback,
215 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216
Neema Shetty2c07eb52011-08-21 20:33:52 -0700217 if (common.apr_q6_cvp == NULL) {
218 pr_err("%s: Unable to register CVP\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219 goto err;
220 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700221
Neema Shetty2c07eb52011-08-21 20:33:52 -0700222 rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700223 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700224
225 mutex_unlock(&common.common_lock);
226
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 return 0;
228
229err:
Neema Shetty2c07eb52011-08-21 20:33:52 -0700230 if (common.apr_q6_cvs != NULL) {
231 apr_deregister(common.apr_q6_cvs);
232 common.apr_q6_cvs = NULL;
Ben Romberger13b74ab2011-07-18 17:36:32 -0700233 rtac_set_voice_handle(RTAC_CVS, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700235 if (common.apr_q6_mvm != NULL) {
236 apr_deregister(common.apr_q6_mvm);
237 common.apr_q6_mvm = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700238 }
239
Neema Shetty2c07eb52011-08-21 20:33:52 -0700240 mutex_unlock(&common.common_lock);
241
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700242 return -ENODEV;
243}
244
245static int voice_create_mvm_cvs_session(struct voice_data *v)
246{
247 int ret = 0;
Helen Zeng69b00962011-07-08 11:38:36 -0700248 struct mvm_create_ctl_session_cmd mvm_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700249 struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
251 struct mvm_attach_stream_cmd attach_stream_cmd;
252 void *apr_mvm, *apr_cvs, *apr_cvp;
253 u16 mvm_handle, cvs_handle, cvp_handle;
254
255 if (v == NULL) {
256 pr_err("%s: v is NULL\n", __func__);
257 return -EINVAL;
258 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700259 apr_mvm = common.apr_q6_mvm;
260 apr_cvs = common.apr_q6_cvs;
261 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700262
263 if (!apr_mvm || !apr_cvs || !apr_cvp) {
264 pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
265 return -EINVAL;
266 }
267 mvm_handle = voice_get_mvm_handle(v);
268 cvs_handle = voice_get_cvs_handle(v);
269 cvp_handle = voice_get_cvp_handle(v);
270
271 pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
272 mvm_handle, cvs_handle);
273 /* send cmd to create mvm session and wait for response */
274
275 if (!mvm_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700276 if (is_voice_session(v->session_id)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
278 APR_MSG_TYPE_SEQ_CMD,
279 APR_HDR_LEN(APR_HDR_SIZE),
280 APR_PKT_VER);
281 mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
282 APR_HDR_SIZE,
283 sizeof(mvm_session_cmd) -
284 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700285 pr_debug("%s: send mvm create session pkt size = %d\n",
286 __func__, mvm_session_cmd.hdr.pkt_size);
287 mvm_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 mvm_session_cmd.hdr.dest_port = 0;
289 mvm_session_cmd.hdr.token = 0;
290 mvm_session_cmd.hdr.opcode =
291 VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
Neema Shetty9ba987d2011-10-25 18:14:50 -0700292 strlcpy(mvm_session_cmd.mvm_session.name,
293 "default modem voice",
294 sizeof(mvm_session_cmd.mvm_session.name));
Helen Zeng69b00962011-07-08 11:38:36 -0700295
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296 v->mvm_state = CMD_STATUS_FAIL;
297
298 ret = apr_send_pkt(apr_mvm,
299 (uint32_t *) &mvm_session_cmd);
300 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700301 pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
302 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700303 goto fail;
304 }
305 ret = wait_event_timeout(v->mvm_wait,
306 (v->mvm_state == CMD_STATUS_SUCCESS),
307 msecs_to_jiffies(TIMEOUT_MS));
308 if (!ret) {
309 pr_err("%s: wait_event timeout\n", __func__);
310 goto fail;
311 }
312 } else {
313 pr_debug("%s: creating MVM full ctrl\n", __func__);
Helen Zeng69b00962011-07-08 11:38:36 -0700314 mvm_session_cmd.hdr.hdr_field =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
316 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
Helen Zeng69b00962011-07-08 11:38:36 -0700317 mvm_session_cmd.hdr.pkt_size =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700318 APR_PKT_SIZE(APR_HDR_SIZE,
Helen Zeng69b00962011-07-08 11:38:36 -0700319 sizeof(mvm_session_cmd) -
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700321 mvm_session_cmd.hdr.src_port = v->session_id;
Helen Zeng69b00962011-07-08 11:38:36 -0700322 mvm_session_cmd.hdr.dest_port = 0;
323 mvm_session_cmd.hdr.token = 0;
324 mvm_session_cmd.hdr.opcode =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700325 VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
Neema Shetty9ba987d2011-10-25 18:14:50 -0700326 strlcpy(mvm_session_cmd.mvm_session.name,
327 "default voip",
328 sizeof(mvm_session_cmd.mvm_session.name));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700329
330 v->mvm_state = CMD_STATUS_FAIL;
331
332 ret = apr_send_pkt(apr_mvm,
Helen Zeng69b00962011-07-08 11:38:36 -0700333 (uint32_t *) &mvm_session_cmd);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334 if (ret < 0) {
335 pr_err("Fail in sending MVM_CONTROL_SESSION\n");
336 goto fail;
337 }
338 ret = wait_event_timeout(v->mvm_wait,
339 (v->mvm_state == CMD_STATUS_SUCCESS),
340 msecs_to_jiffies(TIMEOUT_MS));
341 if (!ret) {
342 pr_err("%s: wait_event timeout\n", __func__);
343 goto fail;
344 }
345 }
346 /* Get the created MVM handle. */
347 mvm_handle = voice_get_mvm_handle(v);
348 }
349 /* send cmd to create cvs session */
350 if (!cvs_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700351 if (is_voice_session(v->session_id)) {
352 pr_debug("%s: creating CVS passive session\n",
353 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700354
355 cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
356 APR_MSG_TYPE_SEQ_CMD,
357 APR_HDR_LEN(APR_HDR_SIZE),
358 APR_PKT_VER);
359 cvs_session_cmd.hdr.pkt_size =
360 APR_PKT_SIZE(APR_HDR_SIZE,
361 sizeof(cvs_session_cmd) -
362 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700363 cvs_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364 cvs_session_cmd.hdr.dest_port = 0;
365 cvs_session_cmd.hdr.token = 0;
366 cvs_session_cmd.hdr.opcode =
367 VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
Neema Shetty9ba987d2011-10-25 18:14:50 -0700368 strlcpy(cvs_session_cmd.cvs_session.name,
369 "default modem voice",
370 sizeof(cvs_session_cmd.cvs_session.name));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371
372 v->cvs_state = CMD_STATUS_FAIL;
373
374 ret = apr_send_pkt(apr_cvs,
375 (uint32_t *) &cvs_session_cmd);
376 if (ret < 0) {
377 pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
378 goto fail;
379 }
380 ret = wait_event_timeout(v->cvs_wait,
381 (v->cvs_state == CMD_STATUS_SUCCESS),
382 msecs_to_jiffies(TIMEOUT_MS));
383 if (!ret) {
384 pr_err("%s: wait_event timeout\n", __func__);
385 goto fail;
386 }
387 /* Get the created CVS handle. */
388 cvs_handle = voice_get_cvs_handle(v);
389
390 } else {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700391 pr_debug("%s: creating CVS full session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700392
393 cvs_full_ctl_cmd.hdr.hdr_field =
394 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
395 APR_HDR_LEN(APR_HDR_SIZE),
396 APR_PKT_VER);
397
398 cvs_full_ctl_cmd.hdr.pkt_size =
399 APR_PKT_SIZE(APR_HDR_SIZE,
400 sizeof(cvs_full_ctl_cmd) -
401 APR_HDR_SIZE);
402
Neema Shetty2c07eb52011-08-21 20:33:52 -0700403 cvs_full_ctl_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 cvs_full_ctl_cmd.hdr.dest_port = 0;
405 cvs_full_ctl_cmd.hdr.token = 0;
406 cvs_full_ctl_cmd.hdr.opcode =
407 VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
408 cvs_full_ctl_cmd.cvs_session.direction = 2;
409 cvs_full_ctl_cmd.cvs_session.enc_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700410 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700411 cvs_full_ctl_cmd.cvs_session.dec_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700412 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700413 cvs_full_ctl_cmd.cvs_session.network_id =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700414 common.mvs_info.network_type;
Neema Shetty9ba987d2011-10-25 18:14:50 -0700415 strlcpy(cvs_full_ctl_cmd.cvs_session.name,
416 "default q6 voice",
417 sizeof(cvs_full_ctl_cmd.cvs_session.name));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700418
419 v->cvs_state = CMD_STATUS_FAIL;
420
421 ret = apr_send_pkt(apr_cvs,
422 (uint32_t *) &cvs_full_ctl_cmd);
423
424 if (ret < 0) {
425 pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
426 __func__, ret);
427 goto fail;
428 }
429 ret = wait_event_timeout(v->cvs_wait,
430 (v->cvs_state == CMD_STATUS_SUCCESS),
431 msecs_to_jiffies(TIMEOUT_MS));
432 if (!ret) {
433 pr_err("%s: wait_event timeout\n", __func__);
434 goto fail;
435 }
436 /* Get the created CVS handle. */
437 cvs_handle = voice_get_cvs_handle(v);
438
439 /* Attach MVM to CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700440 pr_debug("%s: Attach MVM to stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441
442 attach_stream_cmd.hdr.hdr_field =
443 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
444 APR_HDR_LEN(APR_HDR_SIZE),
445 APR_PKT_VER);
446 attach_stream_cmd.hdr.pkt_size =
447 APR_PKT_SIZE(APR_HDR_SIZE,
448 sizeof(attach_stream_cmd) -
449 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700450 attach_stream_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700451 attach_stream_cmd.hdr.dest_port = mvm_handle;
452 attach_stream_cmd.hdr.token = 0;
453 attach_stream_cmd.hdr.opcode =
454 VSS_IMVM_CMD_ATTACH_STREAM;
455 attach_stream_cmd.attach_stream.handle = cvs_handle;
456
457 v->mvm_state = CMD_STATUS_FAIL;
458 ret = apr_send_pkt(apr_mvm,
459 (uint32_t *) &attach_stream_cmd);
460 if (ret < 0) {
461 pr_err("%s: Error %d sending ATTACH_STREAM\n",
462 __func__, ret);
463 goto fail;
464 }
465 ret = wait_event_timeout(v->mvm_wait,
466 (v->mvm_state == CMD_STATUS_SUCCESS),
467 msecs_to_jiffies(TIMEOUT_MS));
468 if (!ret) {
469 pr_err("%s: wait_event timeout\n", __func__);
470 goto fail;
471 }
472 }
473 }
474 return 0;
475
476fail:
477 return -EINVAL;
478}
479
480static int voice_destroy_mvm_cvs_session(struct voice_data *v)
481{
482 int ret = 0;
483 struct mvm_detach_stream_cmd detach_stream;
484 struct apr_hdr mvm_destroy;
485 struct apr_hdr cvs_destroy;
486 void *apr_mvm, *apr_cvs;
487 u16 mvm_handle, cvs_handle;
488
489 if (v == NULL) {
490 pr_err("%s: v is NULL\n", __func__);
491 return -EINVAL;
492 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700493 apr_mvm = common.apr_q6_mvm;
494 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700495
496 if (!apr_mvm || !apr_cvs) {
497 pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
498 return -EINVAL;
499 }
500 mvm_handle = voice_get_mvm_handle(v);
501 cvs_handle = voice_get_cvs_handle(v);
502
503 /* MVM, CVS sessions are destroyed only for Full control sessions. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700504 if (is_voip_session(v->session_id)) {
505 pr_debug("%s: MVM detach stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506
507 /* Detach voice stream. */
508 detach_stream.hdr.hdr_field =
509 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
510 APR_HDR_LEN(APR_HDR_SIZE),
511 APR_PKT_VER);
512 detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
513 sizeof(detach_stream) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700514 detach_stream.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700515 detach_stream.hdr.dest_port = mvm_handle;
516 detach_stream.hdr.token = 0;
517 detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
518 detach_stream.detach_stream.handle = cvs_handle;
519
520 v->mvm_state = CMD_STATUS_FAIL;
521
522 ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
523 if (ret < 0) {
524 pr_err("%s: Error %d sending DETACH_STREAM\n",
525 __func__, ret);
526 goto fail;
527 }
528 ret = wait_event_timeout(v->mvm_wait,
529 (v->mvm_state == CMD_STATUS_SUCCESS),
530 msecs_to_jiffies(TIMEOUT_MS));
531 if (!ret) {
532 pr_err("%s: wait event timeout\n", __func__);
533 goto fail;
534 }
535 /* Destroy CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700536 pr_debug("%s: CVS destroy session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537
538 cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
539 APR_HDR_LEN(APR_HDR_SIZE),
540 APR_PKT_VER);
541 cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
542 sizeof(cvs_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700543 cvs_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544 cvs_destroy.dest_port = cvs_handle;
545 cvs_destroy.token = 0;
546 cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
547
548 v->cvs_state = CMD_STATUS_FAIL;
549
550 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
551 if (ret < 0) {
552 pr_err("%s: Error %d sending CVS DESTROY\n",
553 __func__, ret);
554 goto fail;
555 }
556 ret = wait_event_timeout(v->cvs_wait,
557 (v->cvs_state == CMD_STATUS_SUCCESS),
558 msecs_to_jiffies(TIMEOUT_MS));
559 if (!ret) {
560 pr_err("%s: wait event timeout\n", __func__);
561
562 goto fail;
563 }
564 cvs_handle = 0;
565 voice_set_cvs_handle(v, cvs_handle);
566
567 /* Destroy MVM. */
568 pr_debug("MVM destroy session\n");
569
570 mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
571 APR_HDR_LEN(APR_HDR_SIZE),
572 APR_PKT_VER);
573 mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
574 sizeof(mvm_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700575 mvm_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 mvm_destroy.dest_port = mvm_handle;
577 mvm_destroy.token = 0;
578 mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
579
580 v->mvm_state = CMD_STATUS_FAIL;
581
582 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
583 if (ret < 0) {
584 pr_err("%s: Error %d sending MVM DESTROY\n",
585 __func__, ret);
586
587 goto fail;
588 }
589 ret = wait_event_timeout(v->mvm_wait,
590 (v->mvm_state == CMD_STATUS_SUCCESS),
591 msecs_to_jiffies(TIMEOUT_MS));
592 if (!ret) {
593 pr_err("%s: wait event timeout\n", __func__);
594
595 goto fail;
596 }
597 mvm_handle = 0;
598 voice_set_mvm_handle(v, mvm_handle);
599 }
600 return 0;
601fail:
602 return -EINVAL;
603}
604
605static int voice_send_tty_mode_cmd(struct voice_data *v)
606{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700607 int ret = 0;
608 struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
609 void *apr_mvm;
610 u16 mvm_handle;
611
612 if (v == NULL) {
613 pr_err("%s: v is NULL\n", __func__);
614 return -EINVAL;
615 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700616 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700617
618 if (!apr_mvm) {
619 pr_err("%s: apr_mvm is NULL.\n", __func__);
620 return -EINVAL;
621 }
622 mvm_handle = voice_get_mvm_handle(v);
623
Helen Zengcc65b5b2011-07-06 19:14:48 -0700624 if (v->tty_mode) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700625 /* send tty mode cmd to mvm */
626 mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
627 APR_MSG_TYPE_SEQ_CMD,
628 APR_HDR_LEN(APR_HDR_SIZE),
629 APR_PKT_VER);
630 mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
631 sizeof(mvm_tty_mode_cmd) -
632 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700633 pr_debug("%s: pkt size = %d\n",
634 __func__, mvm_tty_mode_cmd.hdr.pkt_size);
635 mvm_tty_mode_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636 mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
637 mvm_tty_mode_cmd.hdr.token = 0;
638 mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
Helen Zengcc65b5b2011-07-06 19:14:48 -0700639 mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
641
642 v->mvm_state = CMD_STATUS_FAIL;
643 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
644 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700645 pr_err("%s: Error %d sending SET_TTY_MODE\n",
646 __func__, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700647 goto fail;
648 }
649 ret = wait_event_timeout(v->mvm_wait,
650 (v->mvm_state == CMD_STATUS_SUCCESS),
651 msecs_to_jiffies(TIMEOUT_MS));
652 if (!ret) {
653 pr_err("%s: wait_event timeout\n", __func__);
654 goto fail;
655 }
656 }
657 return 0;
658fail:
659 return -EINVAL;
660}
661
662static int voice_config_cvs_vocoder(struct voice_data *v)
663{
664 int ret = 0;
665 void *apr_cvs;
666 u16 cvs_handle;
667 /* Set media type. */
668 struct cvs_set_media_type_cmd cvs_set_media_cmd;
669
670 if (v == NULL) {
671 pr_err("%s: v is NULL\n", __func__);
672 return -EINVAL;
673 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700674 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675
676 if (!apr_cvs) {
677 pr_err("%s: apr_cvs is NULL.\n", __func__);
678 return -EINVAL;
679 }
680
681 cvs_handle = voice_get_cvs_handle(v);
682
683 cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
684 APR_HDR_LEN(APR_HDR_SIZE),
685 APR_PKT_VER);
686 cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
687 sizeof(cvs_set_media_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700688 cvs_set_media_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 cvs_set_media_cmd.hdr.dest_port = cvs_handle;
690 cvs_set_media_cmd.hdr.token = 0;
691 cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700692 cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
693 cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700694
695 v->cvs_state = CMD_STATUS_FAIL;
696
697 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
698 if (ret < 0) {
699 pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
700 __func__, ret);
701
702 goto fail;
703 }
704 ret = wait_event_timeout(v->cvs_wait,
705 (v->cvs_state == CMD_STATUS_SUCCESS),
706 msecs_to_jiffies(TIMEOUT_MS));
707 if (!ret) {
708 pr_err("%s: wait_event timeout\n", __func__);
709
710 goto fail;
711 }
712 /* Set encoder properties. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700713 switch (common.mvs_info.media_type) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700714 case VSS_MEDIA_ID_EVRC_MODEM: {
715 struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
716
717 pr_debug("Setting EVRC min-max rate\n");
718
719 cvs_set_cdma_rate.hdr.hdr_field =
720 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
721 APR_HDR_LEN(APR_HDR_SIZE),
722 APR_PKT_VER);
723 cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
724 sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700725 cvs_set_cdma_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726 cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
727 cvs_set_cdma_rate.hdr.token = 0;
728 cvs_set_cdma_rate.hdr.opcode =
729 VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700730 cvs_set_cdma_rate.cdma_rate.min_rate = common.mvs_info.rate;
731 cvs_set_cdma_rate.cdma_rate.max_rate = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700732
733 v->cvs_state = CMD_STATUS_FAIL;
734
735 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
736 if (ret < 0) {
737 pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
738 __func__, ret);
739 goto fail;
740 }
741 ret = wait_event_timeout(v->cvs_wait,
742 (v->cvs_state == CMD_STATUS_SUCCESS),
743 msecs_to_jiffies(TIMEOUT_MS));
744 if (!ret) {
745 pr_err("%s: wait_event timeout\n", __func__);
746
747 goto fail;
748 }
749 break;
750 }
751 case VSS_MEDIA_ID_AMR_NB_MODEM: {
752 struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
753 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
754
755 pr_debug("Setting AMR rate\n");
756
757 cvs_set_amr_rate.hdr.hdr_field =
758 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
759 APR_HDR_LEN(APR_HDR_SIZE),
760 APR_PKT_VER);
761 cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
762 sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700763 cvs_set_amr_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700764 cvs_set_amr_rate.hdr.dest_port = cvs_handle;
765 cvs_set_amr_rate.hdr.token = 0;
766 cvs_set_amr_rate.hdr.opcode =
767 VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700768 cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700769
770 v->cvs_state = CMD_STATUS_FAIL;
771
772 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
773 if (ret < 0) {
774 pr_err("%s: Error %d sending SET_AMR_RATE\n",
775 __func__, ret);
776 goto fail;
777 }
778 ret = wait_event_timeout(v->cvs_wait,
779 (v->cvs_state == CMD_STATUS_SUCCESS),
780 msecs_to_jiffies(TIMEOUT_MS));
781 if (!ret) {
782 pr_err("%s: wait_event timeout\n", __func__);
783 goto fail;
784 }
785 /* Disable DTX */
786 pr_debug("Disabling DTX\n");
787
788 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
789 APR_HDR_LEN(APR_HDR_SIZE),
790 APR_PKT_VER);
791 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
792 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700793 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700794 cvs_set_dtx.hdr.dest_port = cvs_handle;
795 cvs_set_dtx.hdr.token = 0;
796 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
797 cvs_set_dtx.dtx_mode.enable = 0;
798
799 v->cvs_state = CMD_STATUS_FAIL;
800
801 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
802 if (ret < 0) {
803 pr_err("%s: Error %d sending SET_DTX\n",
804 __func__, ret);
805 goto fail;
806 }
807 ret = wait_event_timeout(v->cvs_wait,
808 (v->cvs_state == CMD_STATUS_SUCCESS),
809 msecs_to_jiffies(TIMEOUT_MS));
810 if (!ret) {
811 pr_err("%s: wait_event timeout\n", __func__);
812 goto fail;
813 }
814 break;
815 }
816 case VSS_MEDIA_ID_AMR_WB_MODEM: {
817 struct cvs_set_amrwb_enc_rate_cmd cvs_set_amrwb_rate;
818 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
819
820 pr_debug("Setting AMR WB rate\n");
821
822 cvs_set_amrwb_rate.hdr.hdr_field =
823 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
824 APR_HDR_LEN(APR_HDR_SIZE),
825 APR_PKT_VER);
826 cvs_set_amrwb_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
827 sizeof(cvs_set_amrwb_rate) -
828 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700829 cvs_set_amrwb_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 cvs_set_amrwb_rate.hdr.dest_port = cvs_handle;
831 cvs_set_amrwb_rate.hdr.token = 0;
832 cvs_set_amrwb_rate.hdr.opcode =
833 VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700834 cvs_set_amrwb_rate.amrwb_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835
836 v->cvs_state = CMD_STATUS_FAIL;
837
838 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amrwb_rate);
839 if (ret < 0) {
840 pr_err("%s: Error %d sending SET_AMRWB_RATE\n",
841 __func__, ret);
842 goto fail;
843 }
844 ret = wait_event_timeout(v->cvs_wait,
845 (v->cvs_state == CMD_STATUS_SUCCESS),
846 msecs_to_jiffies(TIMEOUT_MS));
847 if (!ret) {
848 pr_err("%s: wait_event timeout\n", __func__);
849 goto fail;
850 }
851 /* Disable DTX */
852 pr_debug("Disabling DTX\n");
853
854 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
855 APR_HDR_LEN(APR_HDR_SIZE),
856 APR_PKT_VER);
857 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
858 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700859 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860 cvs_set_dtx.hdr.dest_port = cvs_handle;
861 cvs_set_dtx.hdr.token = 0;
862 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
863 cvs_set_dtx.dtx_mode.enable = 0;
864
865 v->cvs_state = CMD_STATUS_FAIL;
866
867 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
868 if (ret < 0) {
869 pr_err("%s: Error %d sending SET_DTX\n",
870 __func__, ret);
871 goto fail;
872 }
873 ret = wait_event_timeout(v->cvs_wait,
874 (v->cvs_state == CMD_STATUS_SUCCESS),
875 msecs_to_jiffies(TIMEOUT_MS));
876 if (!ret) {
877 pr_err("%s: wait_event timeout\n", __func__);
878 goto fail;
879 }
880 break;
881 }
882 case VSS_MEDIA_ID_G729:
883 case VSS_MEDIA_ID_G711_ALAW:
884 case VSS_MEDIA_ID_G711_MULAW: {
885 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
886 /* Disable DTX */
887 pr_debug("Disabling DTX\n");
888
889 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
890 APR_HDR_LEN(APR_HDR_SIZE),
891 APR_PKT_VER);
892 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
893 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700894 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 cvs_set_dtx.hdr.dest_port = cvs_handle;
896 cvs_set_dtx.hdr.token = 0;
897 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
898 cvs_set_dtx.dtx_mode.enable = 0;
899
900 v->cvs_state = CMD_STATUS_FAIL;
901
902 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
903 if (ret < 0) {
904 pr_err("%s: Error %d sending SET_DTX\n",
905 __func__, ret);
906 goto fail;
907 }
908 ret = wait_event_timeout(v->cvs_wait,
909 (v->cvs_state == CMD_STATUS_SUCCESS),
910 msecs_to_jiffies(TIMEOUT_MS));
911 if (!ret) {
912 pr_err("%s: wait_event timeout\n", __func__);
913 goto fail;
914 }
915 break;
916 }
917 default:
918 /* Do nothing. */
919 break;
920 }
921 return 0;
922
923fail:
924 return -EINVAL;
925}
926
927static int voice_send_start_voice_cmd(struct voice_data *v)
928{
929 struct apr_hdr mvm_start_voice_cmd;
930 int ret = 0;
931 void *apr_mvm;
932 u16 mvm_handle;
933
934 if (v == NULL) {
935 pr_err("%s: v is NULL\n", __func__);
936 return -EINVAL;
937 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700938 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939
940 if (!apr_mvm) {
941 pr_err("%s: apr_mvm is NULL.\n", __func__);
942 return -EINVAL;
943 }
944 mvm_handle = voice_get_mvm_handle(v);
945
946 mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
947 APR_HDR_LEN(APR_HDR_SIZE),
948 APR_PKT_VER);
949 mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
950 sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
951 pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
952 mvm_start_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700953 mvm_start_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700954 mvm_start_voice_cmd.dest_port = mvm_handle;
955 mvm_start_voice_cmd.token = 0;
956 mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
957
958 v->mvm_state = CMD_STATUS_FAIL;
959 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
960 if (ret < 0) {
961 pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
962 goto fail;
963 }
964 ret = wait_event_timeout(v->mvm_wait,
965 (v->mvm_state == CMD_STATUS_SUCCESS),
966 msecs_to_jiffies(TIMEOUT_MS));
967 if (!ret) {
968 pr_err("%s: wait_event timeout\n", __func__);
969 goto fail;
970 }
971 return 0;
972fail:
973 return -EINVAL;
974}
975
976static int voice_send_disable_vocproc_cmd(struct voice_data *v)
977{
978 struct apr_hdr cvp_disable_cmd;
979 int ret = 0;
980 void *apr_cvp;
981 u16 cvp_handle;
982
983 if (v == NULL) {
984 pr_err("%s: v is NULL\n", __func__);
985 return -EINVAL;
986 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700987 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988
989 if (!apr_cvp) {
990 pr_err("%s: apr regist failed\n", __func__);
991 return -EINVAL;
992 }
993 cvp_handle = voice_get_cvp_handle(v);
994
995 /* disable vocproc and wait for respose */
996 cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
997 APR_HDR_LEN(APR_HDR_SIZE),
998 APR_PKT_VER);
999 cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1000 sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
1001 pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
1002 cvp_disable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001003 cvp_disable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001004 cvp_disable_cmd.dest_port = cvp_handle;
1005 cvp_disable_cmd.token = 0;
1006 cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
1007
1008 v->cvp_state = CMD_STATUS_FAIL;
1009 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
1010 if (ret < 0) {
1011 pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
1012 goto fail;
1013 }
1014 ret = wait_event_timeout(v->cvp_wait,
1015 (v->cvp_state == CMD_STATUS_SUCCESS),
1016 msecs_to_jiffies(TIMEOUT_MS));
1017 if (!ret) {
1018 pr_err("%s: wait_event timeout\n", __func__);
1019 goto fail;
1020 }
1021
1022 return 0;
1023fail:
1024 return -EINVAL;
1025}
1026
1027static int voice_send_set_device_cmd(struct voice_data *v)
1028{
1029 struct cvp_set_device_cmd cvp_setdev_cmd;
1030 int ret = 0;
1031 void *apr_cvp;
1032 u16 cvp_handle;
1033
1034 if (v == NULL) {
1035 pr_err("%s: v is NULL\n", __func__);
1036 return -EINVAL;
1037 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001038 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039
1040 if (!apr_cvp) {
1041 pr_err("%s: apr_cvp is NULL.\n", __func__);
1042 return -EINVAL;
1043 }
1044 cvp_handle = voice_get_cvp_handle(v);
1045
1046 /* set device and wait for response */
1047 cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1048 APR_HDR_LEN(APR_HDR_SIZE),
1049 APR_PKT_VER);
1050 cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1051 sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
1052 pr_debug(" send create cvp setdev, pkt size = %d\n",
1053 cvp_setdev_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001054 cvp_setdev_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001055 cvp_setdev_cmd.hdr.dest_port = cvp_handle;
1056 cvp_setdev_cmd.hdr.token = 0;
1057 cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE;
1058
1059 /* Use default topology if invalid value in ACDB */
1060 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1061 get_voice_tx_topology();
1062 if (cvp_setdev_cmd.cvp_set_device.tx_topology_id == 0)
1063 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1064 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1065
1066 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1067 get_voice_rx_topology();
1068 if (cvp_setdev_cmd.cvp_set_device.rx_topology_id == 0)
1069 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1070 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1071 cvp_setdev_cmd.cvp_set_device.tx_port_id = v->dev_tx.port_id;
1072 cvp_setdev_cmd.cvp_set_device.rx_port_id = v->dev_rx.port_id;
1073 pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
1074 cvp_setdev_cmd.cvp_set_device.tx_topology_id,
1075 cvp_setdev_cmd.cvp_set_device.tx_port_id,
1076 cvp_setdev_cmd.cvp_set_device.rx_port_id);
1077
1078 v->cvp_state = CMD_STATUS_FAIL;
1079 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
1080 if (ret < 0) {
1081 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1082 goto fail;
1083 }
1084 pr_debug("wait for cvp create session event\n");
1085 ret = wait_event_timeout(v->cvp_wait,
1086 (v->cvp_state == CMD_STATUS_SUCCESS),
1087 msecs_to_jiffies(TIMEOUT_MS));
1088 if (!ret) {
1089 pr_err("%s: wait_event timeout\n", __func__);
1090 goto fail;
1091 }
1092
1093 return 0;
1094fail:
1095 return -EINVAL;
1096}
1097
1098static int voice_send_stop_voice_cmd(struct voice_data *v)
1099{
1100 struct apr_hdr mvm_stop_voice_cmd;
1101 int ret = 0;
1102 void *apr_mvm;
1103 u16 mvm_handle;
1104
1105 if (v == NULL) {
1106 pr_err("%s: v is NULL\n", __func__);
1107 return -EINVAL;
1108 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001109 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001110
1111 if (!apr_mvm) {
1112 pr_err("%s: apr_mvm is NULL.\n", __func__);
1113 return -EINVAL;
1114 }
1115 mvm_handle = voice_get_mvm_handle(v);
1116
1117 mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1118 APR_HDR_LEN(APR_HDR_SIZE),
1119 APR_PKT_VER);
1120 mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1121 sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
1122 pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
1123 mvm_stop_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001124 mvm_stop_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001125 mvm_stop_voice_cmd.dest_port = mvm_handle;
1126 mvm_stop_voice_cmd.token = 0;
1127 mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
1128
1129 v->mvm_state = CMD_STATUS_FAIL;
1130 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
1131 if (ret < 0) {
1132 pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
1133 goto fail;
1134 }
1135 ret = wait_event_timeout(v->mvm_wait,
1136 (v->mvm_state == CMD_STATUS_SUCCESS),
1137 msecs_to_jiffies(TIMEOUT_MS));
1138 if (!ret) {
1139 pr_err("%s: wait_event timeout\n", __func__);
1140 goto fail;
1141 }
1142
1143 return 0;
1144fail:
1145 return -EINVAL;
1146}
1147
Helen Zeng29eb7442011-06-20 11:06:29 -07001148static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
1149{
1150 struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
1151 struct acdb_cal_block cal_block;
1152 int ret = 0;
1153 void *apr_cvs;
1154 u16 cvs_handle;
1155
1156 /* get the cvs cal data */
1157 get_all_vocstrm_cal(&cal_block);
1158 if (cal_block.cal_size == 0)
1159 goto fail;
1160
1161 if (v == NULL) {
1162 pr_err("%s: v is NULL\n", __func__);
1163 return -EINVAL;
1164 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001165 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001166
1167 if (!apr_cvs) {
1168 pr_err("%s: apr_cvs is NULL.\n", __func__);
1169 return -EINVAL;
1170 }
1171 cvs_handle = voice_get_cvs_handle(v);
1172
1173 /* fill in the header */
1174 cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1175 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1176 cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1177 sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001178 cvs_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001179 cvs_reg_cal_cmd.hdr.dest_port = cvs_handle;
1180 cvs_reg_cal_cmd.hdr.token = 0;
1181 cvs_reg_cal_cmd.hdr.opcode = VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA;
1182
1183 cvs_reg_cal_cmd.cvs_cal_data.phys_addr = cal_block.cal_paddr;
1184 cvs_reg_cal_cmd.cvs_cal_data.mem_size = cal_block.cal_size;
1185
1186 v->cvs_state = CMD_STATUS_FAIL;
1187 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_reg_cal_cmd);
1188 if (ret < 0) {
1189 pr_err("Fail: sending cvs cal,\n");
1190 goto fail;
1191 }
1192 ret = wait_event_timeout(v->cvs_wait,
1193 (v->cvs_state == CMD_STATUS_SUCCESS),
1194 msecs_to_jiffies(TIMEOUT_MS));
1195 if (!ret) {
1196 pr_err("%s: wait_event timeout\n", __func__);
1197 goto fail;
1198 }
1199 return 0;
1200fail:
1201 return -EINVAL;
1202
1203}
1204
1205static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
1206{
1207 struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
1208 struct acdb_cal_block cal_block;
1209 int ret = 0;
1210 void *apr_cvs;
1211 u16 cvs_handle;
1212
1213 get_all_vocstrm_cal(&cal_block);
1214 if (cal_block.cal_size == 0)
1215 return 0;
1216
1217 if (v == NULL) {
1218 pr_err("%s: v is NULL\n", __func__);
1219 return -EINVAL;
1220 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001221 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001222
1223 if (!apr_cvs) {
1224 pr_err("%s: apr_cvs is NULL.\n", __func__);
1225 return -EINVAL;
1226 }
1227 cvs_handle = voice_get_cvs_handle(v);
1228
1229 /* fill in the header */
1230 cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1231 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1232 cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1233 sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001234 cvs_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001235 cvs_dereg_cal_cmd.hdr.dest_port = cvs_handle;
1236 cvs_dereg_cal_cmd.hdr.token = 0;
1237 cvs_dereg_cal_cmd.hdr.opcode =
1238 VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
1239
1240 v->cvs_state = CMD_STATUS_FAIL;
1241 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
1242 if (ret < 0) {
1243 pr_err("Fail: sending cvs cal,\n");
1244 goto fail;
1245 }
1246 ret = wait_event_timeout(v->cvs_wait,
1247 (v->cvs_state == CMD_STATUS_SUCCESS),
1248 msecs_to_jiffies(TIMEOUT_MS));
1249 if (!ret) {
1250 pr_err("%s: wait_event timeout\n", __func__);
1251 goto fail;
1252 }
1253 return 0;
1254fail:
1255 return -EINVAL;
1256
1257}
1258
1259static int voice_send_cvp_map_memory_cmd(struct voice_data *v)
1260{
1261 struct vss_map_memory_cmd cvp_map_mem_cmd;
1262 struct acdb_cal_block cal_block;
1263 int ret = 0;
1264 void *apr_cvp;
1265 u16 cvp_handle;
1266
1267 /* get all cvp cal data */
1268 get_all_cvp_cal(&cal_block);
1269 if (cal_block.cal_size == 0)
1270 goto fail;
1271
1272 if (v == NULL) {
1273 pr_err("%s: v is NULL\n", __func__);
1274 return -EINVAL;
1275 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001276 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001277
1278 if (!apr_cvp) {
1279 pr_err("%s: apr_cvp is NULL.\n", __func__);
1280 return -EINVAL;
1281 }
1282 cvp_handle = voice_get_cvp_handle(v);
1283
1284 /* fill in the header */
1285 cvp_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1286 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1287 cvp_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1288 sizeof(cvp_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001289 cvp_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001290 cvp_map_mem_cmd.hdr.dest_port = cvp_handle;
1291 cvp_map_mem_cmd.hdr.token = 0;
1292 cvp_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1293
1294 pr_debug("%s, phy_addr:%d, mem_size:%d\n", __func__,
1295 cal_block.cal_paddr, cal_block.cal_size);
1296 cvp_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1297 cvp_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1298 cvp_map_mem_cmd.vss_map_mem.mem_pool_id =
1299 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1300
1301 v->cvp_state = CMD_STATUS_FAIL;
1302 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_map_mem_cmd);
1303 if (ret < 0) {
1304 pr_err("Fail: sending cvp cal,\n");
1305 goto fail;
1306 }
1307 ret = wait_event_timeout(v->cvp_wait,
1308 (v->cvp_state == CMD_STATUS_SUCCESS),
1309 msecs_to_jiffies(TIMEOUT_MS));
1310 if (!ret) {
1311 pr_err("%s: wait_event timeout\n", __func__);
1312 goto fail;
1313 }
1314 return 0;
1315fail:
1316 return -EINVAL;
1317
1318}
1319
1320static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v)
1321{
1322 struct vss_unmap_memory_cmd cvp_unmap_mem_cmd;
1323 struct acdb_cal_block cal_block;
1324 int ret = 0;
1325 void *apr_cvp;
1326 u16 cvp_handle;
1327
1328 get_all_cvp_cal(&cal_block);
1329 if (cal_block.cal_size == 0)
1330 return 0;
1331
1332 if (v == NULL) {
1333 pr_err("%s: v is NULL\n", __func__);
1334 return -EINVAL;
1335 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001336 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001337
1338 if (!apr_cvp) {
1339 pr_err("%s: apr_cvp is NULL.\n", __func__);
1340 return -EINVAL;
1341 }
1342 cvp_handle = voice_get_cvp_handle(v);
1343
1344 /* fill in the header */
1345 cvp_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1346 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1347 cvp_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1348 sizeof(cvp_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001349 cvp_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001350 cvp_unmap_mem_cmd.hdr.dest_port = cvp_handle;
1351 cvp_unmap_mem_cmd.hdr.token = 0;
1352 cvp_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1353
1354 cvp_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1355
1356 v->cvp_state = CMD_STATUS_FAIL;
1357 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_unmap_mem_cmd);
1358 if (ret < 0) {
1359 pr_err("Fail: sending cvp cal,\n");
1360 goto fail;
1361 }
1362 ret = wait_event_timeout(v->cvp_wait,
1363 (v->cvp_state == CMD_STATUS_SUCCESS),
1364 msecs_to_jiffies(TIMEOUT_MS));
1365 if (!ret) {
1366 pr_err("%s: wait_event timeout\n", __func__);
1367 goto fail;
1368 }
1369 return 0;
1370fail:
1371 return -EINVAL;
1372
1373}
1374
1375static int voice_send_cvs_map_memory_cmd(struct voice_data *v)
1376{
1377 struct vss_map_memory_cmd cvs_map_mem_cmd;
1378 struct acdb_cal_block cal_block;
1379 int ret = 0;
1380 void *apr_cvs;
1381 u16 cvs_handle;
1382
1383 /* get all cvs cal data */
1384 get_all_vocstrm_cal(&cal_block);
1385 if (cal_block.cal_size == 0)
1386 goto fail;
1387
1388 if (v == NULL) {
1389 pr_err("%s: v is NULL\n", __func__);
1390 return -EINVAL;
1391 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001392 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001393
1394 if (!apr_cvs) {
1395 pr_err("%s: apr_cvs is NULL.\n", __func__);
1396 return -EINVAL;
1397 }
1398 cvs_handle = voice_get_cvs_handle(v);
1399
1400 /* fill in the header */
1401 cvs_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1402 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1403 cvs_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1404 sizeof(cvs_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001405 cvs_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001406 cvs_map_mem_cmd.hdr.dest_port = cvs_handle;
1407 cvs_map_mem_cmd.hdr.token = 0;
1408 cvs_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1409
1410 pr_debug("%s, phys_addr: %d, mem_size: %d\n", __func__,
1411 cal_block.cal_paddr, cal_block.cal_size);
1412 cvs_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1413 cvs_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1414 cvs_map_mem_cmd.vss_map_mem.mem_pool_id =
1415 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1416
1417 v->cvs_state = CMD_STATUS_FAIL;
1418 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_map_mem_cmd);
1419 if (ret < 0) {
1420 pr_err("Fail: sending cvs cal,\n");
1421 goto fail;
1422 }
1423 ret = wait_event_timeout(v->cvs_wait,
1424 (v->cvs_state == CMD_STATUS_SUCCESS),
1425 msecs_to_jiffies(TIMEOUT_MS));
1426 if (!ret) {
1427 pr_err("%s: wait_event timeout\n", __func__);
1428 goto fail;
1429 }
1430 return 0;
1431fail:
1432 return -EINVAL;
1433
1434}
1435
1436static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v)
1437{
1438 struct vss_unmap_memory_cmd cvs_unmap_mem_cmd;
1439 struct acdb_cal_block cal_block;
1440 int ret = 0;
1441 void *apr_cvs;
1442 u16 cvs_handle;
1443
1444 get_all_vocstrm_cal(&cal_block);
1445 if (cal_block.cal_size == 0)
1446 return 0;
1447
1448 if (v == NULL) {
1449 pr_err("%s: v is NULL\n", __func__);
1450 return -EINVAL;
1451 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001452 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001453
1454 if (!apr_cvs) {
1455 pr_err("%s: apr_cvs is NULL.\n", __func__);
1456 return -EINVAL;
1457 }
1458 cvs_handle = voice_get_cvs_handle(v);
1459
1460 /* fill in the header */
1461 cvs_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1462 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1463 cvs_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1464 sizeof(cvs_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001465 cvs_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001466 cvs_unmap_mem_cmd.hdr.dest_port = cvs_handle;
1467 cvs_unmap_mem_cmd.hdr.token = 0;
1468 cvs_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1469
1470 cvs_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1471
1472 v->cvs_state = CMD_STATUS_FAIL;
1473 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_unmap_mem_cmd);
1474 if (ret < 0) {
1475 pr_err("Fail: sending cvs cal,\n");
1476 goto fail;
1477 }
1478 ret = wait_event_timeout(v->cvs_wait,
1479 (v->cvs_state == CMD_STATUS_SUCCESS),
1480 msecs_to_jiffies(TIMEOUT_MS));
1481 if (!ret) {
1482 pr_err("%s: wait_event timeout\n", __func__);
1483 goto fail;
1484 }
1485 return 0;
1486fail:
1487 return -EINVAL;
1488
1489}
1490
1491static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
1492{
1493 struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
1494 struct acdb_cal_block cal_block;
1495 int ret = 0;
1496 void *apr_cvp;
1497 u16 cvp_handle;
1498
1499 /* get the cvp cal data */
1500 get_all_vocproc_cal(&cal_block);
1501 if (cal_block.cal_size == 0)
1502 goto fail;
1503
1504 if (v == NULL) {
1505 pr_err("%s: v is NULL\n", __func__);
1506 return -EINVAL;
1507 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001508 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001509
1510 if (!apr_cvp) {
1511 pr_err("%s: apr_cvp is NULL.\n", __func__);
1512 return -EINVAL;
1513 }
1514 cvp_handle = voice_get_cvp_handle(v);
1515
1516 /* fill in the header */
1517 cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1518 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1519 cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1520 sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001521 cvp_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001522 cvp_reg_cal_cmd.hdr.dest_port = cvp_handle;
1523 cvp_reg_cal_cmd.hdr.token = 0;
1524 cvp_reg_cal_cmd.hdr.opcode = VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA;
1525
1526 cvp_reg_cal_cmd.cvp_cal_data.phys_addr = cal_block.cal_paddr;
1527 cvp_reg_cal_cmd.cvp_cal_data.mem_size = cal_block.cal_size;
1528
1529 v->cvp_state = CMD_STATUS_FAIL;
1530 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_cmd);
1531 if (ret < 0) {
1532 pr_err("Fail: sending cvp cal,\n");
1533 goto fail;
1534 }
1535 ret = wait_event_timeout(v->cvp_wait,
1536 (v->cvp_state == CMD_STATUS_SUCCESS),
1537 msecs_to_jiffies(TIMEOUT_MS));
1538 if (!ret) {
1539 pr_err("%s: wait_event timeout\n", __func__);
1540 goto fail;
1541 }
1542 return 0;
1543fail:
1544 return -EINVAL;
1545
1546}
1547
1548static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
1549{
1550 struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
1551 struct acdb_cal_block cal_block;
1552 int ret = 0;
1553 void *apr_cvp;
1554 u16 cvp_handle;
1555
1556 get_all_vocproc_cal(&cal_block);
1557 if (cal_block.cal_size == 0)
1558 return 0;
1559
1560 if (v == NULL) {
1561 pr_err("%s: v is NULL\n", __func__);
1562 return -EINVAL;
1563 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001564 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001565
1566 if (!apr_cvp) {
1567 pr_err("%s: apr_cvp is NULL.\n", __func__);
1568 return -EINVAL;
1569 }
1570 cvp_handle = voice_get_cvp_handle(v);
1571
1572 /* fill in the header */
1573 cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1574 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1575 cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1576 sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001577 cvp_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001578 cvp_dereg_cal_cmd.hdr.dest_port = cvp_handle;
1579 cvp_dereg_cal_cmd.hdr.token = 0;
1580 cvp_dereg_cal_cmd.hdr.opcode =
1581 VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
1582
1583 v->cvp_state = CMD_STATUS_FAIL;
1584 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
1585 if (ret < 0) {
1586 pr_err("Fail: sending cvp cal,\n");
1587 goto fail;
1588 }
1589 ret = wait_event_timeout(v->cvp_wait,
1590 (v->cvp_state == CMD_STATUS_SUCCESS),
1591 msecs_to_jiffies(TIMEOUT_MS));
1592 if (!ret) {
1593 pr_err("%s: wait_event timeout\n", __func__);
1594 goto fail;
1595 }
1596 return 0;
1597fail:
1598 return -EINVAL;
1599
1600}
1601
1602static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v)
1603{
1604 struct cvp_register_vol_cal_table_cmd cvp_reg_cal_tbl_cmd;
1605 struct acdb_cal_block cal_block;
1606 int ret = 0;
1607 void *apr_cvp;
1608 u16 cvp_handle;
1609
1610 /* get the cvp vol cal data */
1611 get_all_vocvol_cal(&cal_block);
1612 if (cal_block.cal_size == 0)
1613 goto fail;
1614
1615 if (v == NULL) {
1616 pr_err("%s: v is NULL\n", __func__);
1617 return -EINVAL;
1618 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001619 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001620
1621 if (!apr_cvp) {
1622 pr_err("%s: apr_cvp is NULL.\n", __func__);
1623 return -EINVAL;
1624 }
1625 cvp_handle = voice_get_cvp_handle(v);
1626
1627 /* fill in the header */
1628 cvp_reg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1629 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1630 cvp_reg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1631 sizeof(cvp_reg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001632 cvp_reg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001633 cvp_reg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1634 cvp_reg_cal_tbl_cmd.hdr.token = 0;
1635 cvp_reg_cal_tbl_cmd.hdr.opcode =
1636 VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE;
1637
1638 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.phys_addr = cal_block.cal_paddr;
1639 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.mem_size = cal_block.cal_size;
1640
1641 v->cvp_state = CMD_STATUS_FAIL;
1642 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_tbl_cmd);
1643 if (ret < 0) {
1644 pr_err("Fail: sending cvp cal table,\n");
1645 goto fail;
1646 }
1647 ret = wait_event_timeout(v->cvp_wait,
1648 (v->cvp_state == CMD_STATUS_SUCCESS),
1649 msecs_to_jiffies(TIMEOUT_MS));
1650 if (!ret) {
1651 pr_err("%s: wait_event timeout\n", __func__);
1652 goto fail;
1653 }
1654 return 0;
1655fail:
1656 return -EINVAL;
1657
1658}
1659
1660static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v)
1661{
1662 struct cvp_deregister_vol_cal_table_cmd cvp_dereg_cal_tbl_cmd;
1663 struct acdb_cal_block cal_block;
1664 int ret = 0;
1665 void *apr_cvp;
1666 u16 cvp_handle;
1667
1668 get_all_vocvol_cal(&cal_block);
1669 if (cal_block.cal_size == 0)
1670 return 0;
1671
1672 if (v == NULL) {
1673 pr_err("%s: v is NULL\n", __func__);
1674 return -EINVAL;
1675 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001676 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001677
1678 if (!apr_cvp) {
1679 pr_err("%s: apr_cvp is NULL.\n", __func__);
1680 return -EINVAL;
1681 }
1682 cvp_handle = voice_get_cvp_handle(v);
1683
1684 /* fill in the header */
1685 cvp_dereg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(
1686 APR_MSG_TYPE_SEQ_CMD,
1687 APR_HDR_LEN(APR_HDR_SIZE),
1688 APR_PKT_VER);
1689 cvp_dereg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1690 sizeof(cvp_dereg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001691 cvp_dereg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001692 cvp_dereg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1693 cvp_dereg_cal_tbl_cmd.hdr.token = 0;
1694 cvp_dereg_cal_tbl_cmd.hdr.opcode =
1695 VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE;
1696
1697 v->cvp_state = CMD_STATUS_FAIL;
1698 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_tbl_cmd);
1699 if (ret < 0) {
1700 pr_err("Fail: sending cvp cal table,\n");
1701 goto fail;
1702 }
1703 ret = wait_event_timeout(v->cvp_wait,
1704 (v->cvp_state == CMD_STATUS_SUCCESS),
1705 msecs_to_jiffies(TIMEOUT_MS));
1706 if (!ret) {
1707 pr_err("%s: wait_event timeout\n", __func__);
1708 goto fail;
1709 }
1710 return 0;
1711fail:
1712 return -EINVAL;
1713
1714}
Neema Shetty2c07eb52011-08-21 20:33:52 -07001715
Helen Zeng44d4d272011-08-10 14:49:20 -07001716static int voice_send_set_widevoice_enable_cmd(struct voice_data *v)
1717{
1718 struct mvm_set_widevoice_enable_cmd mvm_set_wv_cmd;
1719 int ret = 0;
1720 void *apr_mvm;
1721 u16 mvm_handle;
1722
1723 if (v == NULL) {
1724 pr_err("%s: v is NULL\n", __func__);
1725 return -EINVAL;
1726 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001727 apr_mvm = common.apr_q6_mvm;
Helen Zeng44d4d272011-08-10 14:49:20 -07001728
1729 if (!apr_mvm) {
1730 pr_err("%s: apr_mvm is NULL.\n", __func__);
1731 return -EINVAL;
1732 }
1733 mvm_handle = voice_get_mvm_handle(v);
1734
1735 /* fill in the header */
1736 mvm_set_wv_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1737 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1738 mvm_set_wv_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1739 sizeof(mvm_set_wv_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001740 mvm_set_wv_cmd.hdr.src_port = v->session_id;
Helen Zeng44d4d272011-08-10 14:49:20 -07001741 mvm_set_wv_cmd.hdr.dest_port = mvm_handle;
1742 mvm_set_wv_cmd.hdr.token = 0;
1743 mvm_set_wv_cmd.hdr.opcode = VSS_IWIDEVOICE_CMD_SET_WIDEVOICE;
1744
1745 mvm_set_wv_cmd.vss_set_wv.enable = v->wv_enable;
1746
1747 v->mvm_state = CMD_STATUS_FAIL;
1748 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_wv_cmd);
1749 if (ret < 0) {
1750 pr_err("Fail: sending mvm set widevoice enable,\n");
1751 goto fail;
1752 }
1753 ret = wait_event_timeout(v->mvm_wait,
1754 (v->mvm_state == CMD_STATUS_SUCCESS),
1755 msecs_to_jiffies(TIMEOUT_MS));
1756 if (!ret) {
1757 pr_err("%s: wait_event timeout\n", __func__);
1758 goto fail;
1759 }
1760 return 0;
1761fail:
1762 return -EINVAL;
1763}
1764
Helen Zengbb49c702011-09-06 14:09:13 -07001765static int voice_send_set_slowtalk_enable_cmd(struct voice_data *v)
1766{
1767 struct cvs_set_slowtalk_enable_cmd cvs_set_st_cmd;
1768 int ret = 0;
1769 void *apr_cvs;
1770 u16 cvs_handle;
1771
1772 if (v == NULL) {
1773 pr_err("%s: v is NULL\n", __func__);
1774 return -EINVAL;
1775 }
1776 apr_cvs = common.apr_q6_cvs;
1777
1778 if (!apr_cvs) {
1779 pr_err("%s: apr_cvs is NULL.\n", __func__);
1780 return -EINVAL;
1781 }
1782 cvs_handle = voice_get_cvs_handle(v);
1783
1784 /* fill in the header */
1785 cvs_set_st_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1786 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1787 cvs_set_st_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1788 sizeof(cvs_set_st_cmd) - APR_HDR_SIZE);
1789 cvs_set_st_cmd.hdr.src_port = v->session_id;
1790 cvs_set_st_cmd.hdr.dest_port = cvs_handle;
1791 cvs_set_st_cmd.hdr.token = 0;
1792 cvs_set_st_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
1793
1794 cvs_set_st_cmd.vss_set_st.module_id = MODULE_ID_VOICE_MODULE_ST;
1795 cvs_set_st_cmd.vss_set_st.param_id = VOICE_PARAM_MOD_ENABLE;
1796 cvs_set_st_cmd.vss_set_st.param_size = MOD_ENABLE_PARAM_LEN;
1797 cvs_set_st_cmd.vss_set_st.reserved = 0;
1798 cvs_set_st_cmd.vss_set_st.enable = v->st_enable;
1799 cvs_set_st_cmd.vss_set_st.reserved_field = 0;
1800
1801 v->cvs_state = CMD_STATUS_FAIL;
1802 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_st_cmd);
1803 if (ret < 0) {
1804 pr_err("Fail: sending cvs set slowtalk enable,\n");
1805 goto fail;
1806 }
1807 ret = wait_event_timeout(v->cvs_wait,
1808 (v->cvs_state == CMD_STATUS_SUCCESS),
1809 msecs_to_jiffies(TIMEOUT_MS));
1810 if (!ret) {
1811 pr_err("%s: wait_event timeout\n", __func__);
1812 goto fail;
1813 }
1814 return 0;
1815fail:
1816 return -EINVAL;
1817}
1818
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001819static int voice_setup_vocproc(struct voice_data *v)
1820{
1821 struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
1822 int ret = 0;
1823 void *apr_cvp;
1824 if (v == NULL) {
1825 pr_err("%s: v is NULL\n", __func__);
1826 return -EINVAL;
1827 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001828 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001829
1830 if (!apr_cvp) {
1831 pr_err("%s: apr_cvp is NULL.\n", __func__);
1832 return -EINVAL;
1833 }
1834
1835 /* create cvp session and wait for response */
1836 cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1837 APR_HDR_LEN(APR_HDR_SIZE),
1838 APR_PKT_VER);
1839 cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1840 sizeof(cvp_session_cmd) - APR_HDR_SIZE);
1841 pr_debug(" send create cvp session, pkt size = %d\n",
1842 cvp_session_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001843 cvp_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001844 cvp_session_cmd.hdr.dest_port = 0;
1845 cvp_session_cmd.hdr.token = 0;
1846 cvp_session_cmd.hdr.opcode =
1847 VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION;
1848
1849 /* Use default topology if invalid value in ACDB */
1850 cvp_session_cmd.cvp_session.tx_topology_id =
1851 get_voice_tx_topology();
1852 if (cvp_session_cmd.cvp_session.tx_topology_id == 0)
1853 cvp_session_cmd.cvp_session.tx_topology_id =
1854 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1855
1856 cvp_session_cmd.cvp_session.rx_topology_id =
1857 get_voice_rx_topology();
1858 if (cvp_session_cmd.cvp_session.rx_topology_id == 0)
1859 cvp_session_cmd.cvp_session.rx_topology_id =
1860 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1861
1862 cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
1863 cvp_session_cmd.cvp_session.network_id = VSS_NETWORK_ID_DEFAULT;
1864 cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
1865 cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
1866
1867 pr_debug("topology=%d net_id=%d, dir=%d tx_port_id=%d, rx_port_id=%d\n",
1868 cvp_session_cmd.cvp_session.tx_topology_id,
1869 cvp_session_cmd.cvp_session.network_id,
1870 cvp_session_cmd.cvp_session.direction,
1871 cvp_session_cmd.cvp_session.tx_port_id,
1872 cvp_session_cmd.cvp_session.rx_port_id);
1873
1874 v->cvp_state = CMD_STATUS_FAIL;
1875 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
1876 if (ret < 0) {
1877 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1878 goto fail;
1879 }
1880 ret = wait_event_timeout(v->cvp_wait,
1881 (v->cvp_state == CMD_STATUS_SUCCESS),
1882 msecs_to_jiffies(TIMEOUT_MS));
1883 if (!ret) {
1884 pr_err("%s: wait_event timeout\n", __func__);
1885 goto fail;
1886 }
1887
Helen Zeng29eb7442011-06-20 11:06:29 -07001888 /* send cvs cal */
1889 ret = voice_send_cvs_map_memory_cmd(v);
1890 if (!ret)
1891 voice_send_cvs_register_cal_cmd(v);
1892
1893 /* send cvp and vol cal */
1894 ret = voice_send_cvp_map_memory_cmd(v);
1895 if (!ret) {
1896 voice_send_cvp_register_cal_cmd(v);
1897 voice_send_cvp_register_vol_cal_table_cmd(v);
1898 }
1899
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001900 /* enable vocproc */
1901 ret = voice_send_enable_vocproc_cmd(v);
1902 if (ret < 0)
1903 goto fail;
1904
1905 /* attach vocproc */
1906 ret = voice_send_attach_vocproc_cmd(v);
1907 if (ret < 0)
1908 goto fail;
1909
1910 /* send tty mode if tty device is used */
1911 voice_send_tty_mode_cmd(v);
1912
Helen Zeng44d4d272011-08-10 14:49:20 -07001913 /* enable widevoice if wv_enable is set */
1914 if (v->wv_enable)
1915 voice_send_set_widevoice_enable_cmd(v);
1916
Helen Zengbb49c702011-09-06 14:09:13 -07001917 /* enable slowtalk if st_enable is set */
1918 if (v->st_enable)
1919 voice_send_set_slowtalk_enable_cmd(v);
1920
Neema Shetty2c07eb52011-08-21 20:33:52 -07001921 if (is_voip_session(v->session_id))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001922 voice_send_netid_timing_cmd(v);
1923
Helen Zeng0705a5f2011-10-14 15:29:52 -07001924 /* Start in-call music delivery if it's enabled */
1925 if (v->music_info.play_enable)
1926 voice_cvs_start_playback(v);
1927
Ben Romberger13b74ab2011-07-18 17:36:32 -07001928 rtac_add_voice(voice_get_cvs_handle(v),
1929 voice_get_cvp_handle(v),
Ben Rombergerc5d6a372011-09-22 18:01:49 -07001930 v->dev_rx.port_id, v->dev_tx.port_id,
1931 v->session_id);
Ben Romberger13b74ab2011-07-18 17:36:32 -07001932
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001933 return 0;
1934
1935fail:
1936 return -EINVAL;
1937}
1938
1939static int voice_send_enable_vocproc_cmd(struct voice_data *v)
1940{
1941 int ret = 0;
1942 struct apr_hdr cvp_enable_cmd;
1943 void *apr_cvp;
1944 u16 cvp_handle;
1945
1946 if (v == NULL) {
1947 pr_err("%s: v is NULL\n", __func__);
1948 return -EINVAL;
1949 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001950 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001951
1952 if (!apr_cvp) {
1953 pr_err("%s: apr_cvp is NULL.\n", __func__);
1954 return -EINVAL;
1955 }
1956 cvp_handle = voice_get_cvp_handle(v);
1957
1958 /* enable vocproc and wait for respose */
1959 cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1960 APR_HDR_LEN(APR_HDR_SIZE),
1961 APR_PKT_VER);
1962 cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1963 sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
1964 pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
1965 cvp_enable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001966 cvp_enable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001967 cvp_enable_cmd.dest_port = cvp_handle;
1968 cvp_enable_cmd.token = 0;
1969 cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
1970
1971 v->cvp_state = CMD_STATUS_FAIL;
1972 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
1973 if (ret < 0) {
1974 pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
1975 goto fail;
1976 }
1977 ret = wait_event_timeout(v->cvp_wait,
1978 (v->cvp_state == CMD_STATUS_SUCCESS),
1979 msecs_to_jiffies(TIMEOUT_MS));
1980 if (!ret) {
1981 pr_err("%s: wait_event timeout\n", __func__);
1982 goto fail;
1983 }
1984
1985 return 0;
1986fail:
1987 return -EINVAL;
1988}
1989
1990static int voice_send_netid_timing_cmd(struct voice_data *v)
1991{
1992 int ret = 0;
1993 void *apr_mvm;
1994 u16 mvm_handle;
1995 struct mvm_set_network_cmd mvm_set_network;
1996 struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
1997
1998 if (v == NULL) {
1999 pr_err("%s: v is NULL\n", __func__);
2000 return -EINVAL;
2001 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002002 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002003
2004 if (!apr_mvm) {
2005 pr_err("%s: apr_mvm is NULL.\n", __func__);
2006 return -EINVAL;
2007 }
2008 mvm_handle = voice_get_mvm_handle(v);
2009
2010 ret = voice_config_cvs_vocoder(v);
2011 if (ret < 0) {
2012 pr_err("%s: Error %d configuring CVS voc",
2013 __func__, ret);
2014 goto fail;
2015 }
2016 /* Set network ID. */
2017 pr_debug("Setting network ID\n");
2018
2019 mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2020 APR_HDR_LEN(APR_HDR_SIZE),
2021 APR_PKT_VER);
2022 mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2023 sizeof(mvm_set_network) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002024 mvm_set_network.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002025 mvm_set_network.hdr.dest_port = mvm_handle;
2026 mvm_set_network.hdr.token = 0;
2027 mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
Neema Shetty2c07eb52011-08-21 20:33:52 -07002028 mvm_set_network.network.network_id = common.mvs_info.network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002029
2030 v->mvm_state = CMD_STATUS_FAIL;
2031 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
2032 if (ret < 0) {
2033 pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
2034 goto fail;
2035 }
2036
2037 ret = wait_event_timeout(v->mvm_wait,
2038 (v->mvm_state == CMD_STATUS_SUCCESS),
2039 msecs_to_jiffies(TIMEOUT_MS));
2040 if (!ret) {
2041 pr_err("%s: wait_event timeout\n", __func__);
2042 goto fail;
2043 }
2044
2045 /* Set voice timing. */
2046 pr_debug("Setting voice timing\n");
2047
2048 mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2049 APR_HDR_LEN(APR_HDR_SIZE),
2050 APR_PKT_VER);
2051 mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2052 sizeof(mvm_set_voice_timing) -
2053 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002054 mvm_set_voice_timing.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002055 mvm_set_voice_timing.hdr.dest_port = mvm_handle;
2056 mvm_set_voice_timing.hdr.token = 0;
2057 mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
2058 mvm_set_voice_timing.timing.mode = 0;
2059 mvm_set_voice_timing.timing.enc_offset = 8000;
2060 mvm_set_voice_timing.timing.dec_req_offset = 3300;
2061 mvm_set_voice_timing.timing.dec_offset = 8300;
2062
2063 v->mvm_state = CMD_STATUS_FAIL;
2064
2065 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
2066 if (ret < 0) {
2067 pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
2068 goto fail;
2069 }
2070
2071 ret = wait_event_timeout(v->mvm_wait,
2072 (v->mvm_state == CMD_STATUS_SUCCESS),
2073 msecs_to_jiffies(TIMEOUT_MS));
2074 if (!ret) {
2075 pr_err("%s: wait_event timeout\n", __func__);
2076 goto fail;
2077 }
2078
2079 return 0;
2080fail:
2081 return -EINVAL;
2082}
2083
2084static int voice_send_attach_vocproc_cmd(struct voice_data *v)
2085{
2086 int ret = 0;
2087 struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
2088 void *apr_mvm;
2089 u16 mvm_handle, cvp_handle;
2090
2091 if (v == NULL) {
2092 pr_err("%s: v is NULL\n", __func__);
2093 return -EINVAL;
2094 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002095 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002096
2097 if (!apr_mvm) {
2098 pr_err("%s: apr_mvm is NULL.\n", __func__);
2099 return -EINVAL;
2100 }
2101 mvm_handle = voice_get_mvm_handle(v);
2102 cvp_handle = voice_get_cvp_handle(v);
2103
2104 /* attach vocproc and wait for response */
2105 mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2106 APR_HDR_LEN(APR_HDR_SIZE),
2107 APR_PKT_VER);
2108 mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2109 sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
2110 pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
2111 mvm_a_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002112 mvm_a_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002113 mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
2114 mvm_a_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002115 mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002116 mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
2117
2118 v->mvm_state = CMD_STATUS_FAIL;
2119 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
2120 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002121 pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002122 goto fail;
2123 }
2124 ret = wait_event_timeout(v->mvm_wait,
2125 (v->mvm_state == CMD_STATUS_SUCCESS),
2126 msecs_to_jiffies(TIMEOUT_MS));
2127 if (!ret) {
2128 pr_err("%s: wait_event timeout\n", __func__);
2129 goto fail;
2130 }
2131
2132 return 0;
2133fail:
2134 return -EINVAL;
2135}
2136
2137static int voice_destroy_vocproc(struct voice_data *v)
2138{
2139 struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
2140 struct apr_hdr cvp_destroy_session_cmd;
2141 int ret = 0;
2142 void *apr_mvm, *apr_cvp;
2143 u16 mvm_handle, cvp_handle;
2144
2145 if (v == NULL) {
2146 pr_err("%s: v is NULL\n", __func__);
2147 return -EINVAL;
2148 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002149 apr_mvm = common.apr_q6_mvm;
2150 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002151
2152 if (!apr_mvm || !apr_cvp) {
2153 pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
2154 return -EINVAL;
2155 }
2156 mvm_handle = voice_get_mvm_handle(v);
2157 cvp_handle = voice_get_cvp_handle(v);
2158
Helen Zeng0705a5f2011-10-14 15:29:52 -07002159 /* stop playback */
2160 v->music_info.force = 1;
2161 voice_cvs_stop_playback(v);
2162
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002163 /* send stop voice cmd */
2164 voice_send_stop_voice_cmd(v);
2165
2166 /* detach VOCPROC and wait for response from mvm */
2167 mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2168 APR_HDR_LEN(APR_HDR_SIZE),
2169 APR_PKT_VER);
2170 mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2171 sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
2172 pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
2173 mvm_d_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002174 mvm_d_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002175 mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
2176 mvm_d_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002177 mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002178 mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
2179
2180 v->mvm_state = CMD_STATUS_FAIL;
2181 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
2182 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002183 pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002184 goto fail;
2185 }
2186 ret = wait_event_timeout(v->mvm_wait,
2187 (v->mvm_state == CMD_STATUS_SUCCESS),
2188 msecs_to_jiffies(TIMEOUT_MS));
2189 if (!ret) {
2190 pr_err("%s: wait_event timeout\n", __func__);
2191 goto fail;
2192 }
2193
Helen Zeng29eb7442011-06-20 11:06:29 -07002194 /* deregister cvp and vol cal */
2195 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2196 voice_send_cvp_deregister_cal_cmd(v);
2197 voice_send_cvp_unmap_memory_cmd(v);
2198
2199 /* deregister cvs cal */
2200 voice_send_cvs_deregister_cal_cmd(v);
2201 voice_send_cvs_unmap_memory_cmd(v);
2202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002203 /* destrop cvp session */
2204 cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2205 APR_HDR_LEN(APR_HDR_SIZE),
2206 APR_PKT_VER);
2207 cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2208 sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
2209 pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
2210 cvp_destroy_session_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002211 cvp_destroy_session_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002212 cvp_destroy_session_cmd.dest_port = cvp_handle;
2213 cvp_destroy_session_cmd.token = 0;
2214 cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
2215
2216 v->cvp_state = CMD_STATUS_FAIL;
2217 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
2218 if (ret < 0) {
2219 pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
2220 goto fail;
2221 }
2222 ret = wait_event_timeout(v->cvp_wait,
2223 (v->cvp_state == CMD_STATUS_SUCCESS),
2224 msecs_to_jiffies(TIMEOUT_MS));
2225 if (!ret) {
2226 pr_err("%s: wait_event timeout\n", __func__);
2227 goto fail;
2228 }
2229
Ben Romberger13b74ab2011-07-18 17:36:32 -07002230 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002231 cvp_handle = 0;
2232 voice_set_cvp_handle(v, cvp_handle);
2233
2234 return 0;
2235
2236fail:
2237 return -EINVAL;
2238}
2239
2240static int voice_send_mute_cmd(struct voice_data *v)
2241{
2242 struct cvs_set_mute_cmd cvs_mute_cmd;
2243 int ret = 0;
2244 void *apr_cvs;
2245 u16 cvs_handle;
2246
2247 if (v == NULL) {
2248 pr_err("%s: v is NULL\n", __func__);
2249 return -EINVAL;
2250 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002251 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002252
2253 if (!apr_cvs) {
2254 pr_err("%s: apr_cvs is NULL.\n", __func__);
2255 return -EINVAL;
2256 }
2257 cvs_handle = voice_get_cvs_handle(v);
2258
2259 /* send mute/unmute to cvs */
2260 cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2261 APR_HDR_LEN(APR_HDR_SIZE),
2262 APR_PKT_VER);
2263 cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2264 sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002265 cvs_mute_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002266 cvs_mute_cmd.hdr.dest_port = cvs_handle;
2267 cvs_mute_cmd.hdr.token = 0;
2268 cvs_mute_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MUTE;
2269 cvs_mute_cmd.cvs_set_mute.direction = 0; /*tx*/
2270 cvs_mute_cmd.cvs_set_mute.mute_flag = v->dev_tx.mute;
2271
2272 pr_info(" mute value =%d\n", cvs_mute_cmd.cvs_set_mute.mute_flag);
2273 v->cvs_state = CMD_STATUS_FAIL;
2274 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_mute_cmd);
2275 if (ret < 0) {
2276 pr_err("Fail: send STREAM SET MUTE\n");
2277 goto fail;
2278 }
2279 ret = wait_event_timeout(v->cvs_wait,
2280 (v->cvs_state == CMD_STATUS_SUCCESS),
2281 msecs_to_jiffies(TIMEOUT_MS));
2282 if (!ret)
2283 pr_err("%s: wait_event timeout\n", __func__);
2284
2285 return 0;
2286fail:
2287 return -EINVAL;
2288}
2289
2290static int voice_send_vol_index_cmd(struct voice_data *v)
2291{
2292 struct cvp_set_rx_volume_index_cmd cvp_vol_cmd;
2293 int ret = 0;
2294 void *apr_cvp;
2295 u16 cvp_handle;
2296 if (v == NULL) {
2297 pr_err("%s: v is NULL\n", __func__);
2298 return -EINVAL;
2299 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002300 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002301
2302 if (!apr_cvp) {
2303 pr_err("%s: apr_cvp is NULL.\n", __func__);
2304 return -EINVAL;
2305 }
2306 cvp_handle = voice_get_cvp_handle(v);
2307
2308 /* send volume index to cvp */
2309 cvp_vol_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2310 APR_HDR_LEN(APR_HDR_SIZE),
2311 APR_PKT_VER);
2312 cvp_vol_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2313 sizeof(cvp_vol_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002314 cvp_vol_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002315 cvp_vol_cmd.hdr.dest_port = cvp_handle;
2316 cvp_vol_cmd.hdr.token = 0;
2317 cvp_vol_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX;
2318 cvp_vol_cmd.cvp_set_vol_idx.vol_index = v->dev_rx.volume;
2319 v->cvp_state = CMD_STATUS_FAIL;
2320 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_cmd);
2321 if (ret < 0) {
2322 pr_err("Fail in sending RX VOL INDEX\n");
2323 return -EINVAL;
2324 }
2325 ret = wait_event_timeout(v->cvp_wait,
2326 (v->cvp_state == CMD_STATUS_SUCCESS),
2327 msecs_to_jiffies(TIMEOUT_MS));
2328 if (!ret) {
2329 pr_err("%s: wait_event timeout\n", __func__);
2330 return -EINVAL;
2331 }
2332 return 0;
2333}
2334
Helen Zeng0705a5f2011-10-14 15:29:52 -07002335static int voice_cvs_start_playback(struct voice_data *v)
2336{
2337 int ret = 0;
2338 struct apr_hdr cvs_start_playback;
2339 void *apr_cvs;
2340 u16 cvs_handle;
2341
2342 if (v == NULL) {
2343 pr_err("%s: v is NULL\n", __func__);
2344 return -EINVAL;
2345 }
2346 apr_cvs = common.apr_q6_cvs;
2347
2348 if (!apr_cvs) {
2349 pr_err("%s: apr_cvs is NULL.\n", __func__);
2350 return -EINVAL;
2351 }
2352
2353 cvs_handle = voice_get_cvs_handle(v);
2354
2355 if (!v->music_info.playing && v->music_info.count) {
2356 cvs_start_playback.hdr_field = APR_HDR_FIELD(
2357 APR_MSG_TYPE_SEQ_CMD,
2358 APR_HDR_LEN(APR_HDR_SIZE),
2359 APR_PKT_VER);
2360 cvs_start_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2361 sizeof(cvs_start_playback) - APR_HDR_SIZE);
2362 cvs_start_playback.src_port = v->session_id;
2363 cvs_start_playback.dest_port = cvs_handle;
2364 cvs_start_playback.token = 0;
2365 cvs_start_playback.opcode = VSS_ISTREAM_CMD_START_PLAYBACK;
2366
2367 v->cvs_state = CMD_STATUS_FAIL;
2368
2369 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
2370
2371 if (ret < 0) {
2372 pr_err("%s: Error %d sending START_PLAYBACK\n",
2373 __func__, ret);
2374
2375 goto fail;
2376 }
2377
2378 ret = wait_event_timeout(v->cvs_wait,
2379 (v->cvs_state == CMD_STATUS_SUCCESS),
2380 msecs_to_jiffies(TIMEOUT_MS));
2381 if (!ret) {
2382 pr_err("%s: wait_event timeout\n", __func__);
2383
2384 goto fail;
2385 }
2386
2387 v->music_info.playing = 1;
2388 } else {
2389 pr_debug("%s: Start playback already sent\n", __func__);
2390 }
2391
2392 return 0;
2393
2394fail:
2395 return ret;
2396}
2397
2398static int voice_cvs_stop_playback(struct voice_data *v)
2399{
2400 int ret = 0;
2401 struct apr_hdr cvs_stop_playback;
2402 void *apr_cvs;
2403 u16 cvs_handle;
2404
2405 if (v == NULL) {
2406 pr_err("%s: v is NULL\n", __func__);
2407 return -EINVAL;
2408 }
2409 apr_cvs = common.apr_q6_cvs;
2410
2411 if (!apr_cvs) {
2412 pr_err("%s: apr_cvs is NULL.\n", __func__);
2413 return -EINVAL;
2414 }
2415
2416 cvs_handle = voice_get_cvs_handle(v);
2417
2418 if (v->music_info.playing && ((!v->music_info.count) ||
2419 (v->music_info.force))) {
2420 cvs_stop_playback.hdr_field =
2421 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2422 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2423 cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2424 sizeof(cvs_stop_playback) - APR_HDR_SIZE);
2425 cvs_stop_playback.src_port = v->session_id;
2426 cvs_stop_playback.dest_port = cvs_handle;
2427 cvs_stop_playback.token = 0;
2428
2429 cvs_stop_playback.opcode = VSS_ISTREAM_CMD_STOP_PLAYBACK;
2430
2431 v->cvs_state = CMD_STATUS_FAIL;
2432
2433 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
2434 if (ret < 0) {
2435 pr_err("%s: Error %d sending STOP_PLAYBACK\n",
2436 __func__, ret);
2437
2438
2439 goto fail;
2440 }
2441
2442 ret = wait_event_timeout(v->cvs_wait,
2443 (v->cvs_state == CMD_STATUS_SUCCESS),
2444 msecs_to_jiffies(TIMEOUT_MS));
2445 if (!ret) {
2446 pr_err("%s: wait_event timeout\n", __func__);
2447
2448 goto fail;
2449 }
2450
2451 v->music_info.playing = 0;
2452 v->music_info.force = 0;
2453 } else {
2454 pr_debug("%s: Stop playback already sent\n", __func__);
2455 }
2456
2457 return 0;
2458
2459fail:
2460 return ret;
2461}
2462
2463int voc_start_playback(uint32_t set)
2464{
2465 int ret = 0;
2466 u16 cvs_handle;
2467 int i;
2468
2469
2470 for (i = 0; i < MAX_VOC_SESSIONS; i++) {
2471 struct voice_data *v = &common.voice[i];
2472
2473 mutex_lock(&v->lock);
2474 v->music_info.play_enable = set;
2475 if (set)
2476 v->music_info.count++;
2477 else
2478 v->music_info.count--;
2479 pr_debug("%s: music_info count =%d\n", __func__,
2480 v->music_info.count);
2481
2482 cvs_handle = voice_get_cvs_handle(v);
2483 if (cvs_handle != 0) {
2484 if (set)
2485 ret = voice_cvs_start_playback(v);
2486 else
2487 ret = voice_cvs_stop_playback(v);
2488 }
2489
2490 mutex_unlock(&v->lock);
2491 }
2492
2493 return ret;
2494}
2495
Neema Shetty2c07eb52011-08-21 20:33:52 -07002496int voc_disable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002497{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002498 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002499 int ret = 0;
2500
Neema Shetty2c07eb52011-08-21 20:33:52 -07002501 if (v == NULL) {
2502 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2503
2504 return -EINVAL;
2505 }
2506
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002507 mutex_lock(&v->lock);
2508
2509 if (v->voc_state == VOC_RUN) {
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302510 if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
2511 v->dev_rx.port_id != RT_PROXY_PORT_001_RX)
2512 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
2513 0, 0);
Ben Romberger13b74ab2011-07-18 17:36:32 -07002514
2515 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002516 /* send cmd to dsp to disable vocproc */
2517 ret = voice_send_disable_vocproc_cmd(v);
2518 if (ret < 0) {
2519 pr_err("%s: disable vocproc failed\n", __func__);
2520 goto fail;
2521 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002522
2523 /* deregister cvp and vol cal */
2524 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2525 voice_send_cvp_deregister_cal_cmd(v);
2526 voice_send_cvp_unmap_memory_cmd(v);
2527
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002528 v->voc_state = VOC_CHANGE;
2529 }
2530
2531fail: mutex_unlock(&v->lock);
2532
2533 return ret;
2534}
2535
Neema Shetty2c07eb52011-08-21 20:33:52 -07002536int voc_enable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002537{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002538 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002539 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002540 int ret = 0;
2541
Neema Shetty2c07eb52011-08-21 20:33:52 -07002542 if (v == NULL) {
2543 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2544
2545 return -EINVAL;
2546 }
2547
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002548 mutex_lock(&v->lock);
2549
2550 if (v->voc_state == VOC_CHANGE) {
2551 ret = voice_send_set_device_cmd(v);
2552 if (ret < 0) {
2553 pr_err("%s: set device failed\n", __func__);
2554 goto fail;
2555 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002556 /* send cvp and vol cal */
2557 ret = voice_send_cvp_map_memory_cmd(v);
2558 if (!ret) {
2559 voice_send_cvp_register_cal_cmd(v);
2560 voice_send_cvp_register_vol_cal_table_cmd(v);
2561 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002562 ret = voice_send_enable_vocproc_cmd(v);
2563 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002564 pr_err("%s: enable vocproc failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002565 goto fail;
Helen Zengcc65b5b2011-07-06 19:14:48 -07002566
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002567 }
Helen Zengcc65b5b2011-07-06 19:14:48 -07002568 /* send tty mode if tty device is used */
2569 voice_send_tty_mode_cmd(v);
2570
Helen Zeng44d4d272011-08-10 14:49:20 -07002571 /* enable widevoice if wv_enable is set */
2572 if (v->wv_enable)
2573 voice_send_set_widevoice_enable_cmd(v);
2574
Helen Zengbb49c702011-09-06 14:09:13 -07002575 /* enable slowtalk */
2576 if (v->st_enable)
2577 voice_send_set_slowtalk_enable_cmd(v);
2578
Helen Zengbd58e2c2011-07-01 16:24:31 -07002579 get_sidetone_cal(&sidetone_cal_data);
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302580 if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
2581 v->dev_rx.port_id != RT_PROXY_PORT_001_RX) {
2582 ret = afe_sidetone(v->dev_tx.port_id,
2583 v->dev_rx.port_id,
2584 sidetone_cal_data.enable,
2585 sidetone_cal_data.gain);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002586
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302587 if (ret < 0)
2588 pr_err("%s: AFE command sidetone failed\n",
2589 __func__);
2590 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002591
Ben Romberger13b74ab2011-07-18 17:36:32 -07002592 rtac_add_voice(voice_get_cvs_handle(v),
2593 voice_get_cvp_handle(v),
Ben Rombergerc5d6a372011-09-22 18:01:49 -07002594 v->dev_rx.port_id, v->dev_tx.port_id,
2595 v->session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002596 v->voc_state = VOC_RUN;
2597 }
2598
2599fail:
2600 mutex_unlock(&v->lock);
2601
2602 return ret;
2603}
2604
Neema Shetty2c07eb52011-08-21 20:33:52 -07002605int voc_set_tx_mute(uint16_t session_id, uint32_t dir, uint32_t mute)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002606{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002607 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002608 int ret = 0;
2609
Neema Shetty2c07eb52011-08-21 20:33:52 -07002610 if (v == NULL) {
2611 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2612
2613 return -EINVAL;
2614 }
2615
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002616 mutex_lock(&v->lock);
2617
2618 v->dev_tx.mute = mute;
2619
2620 if (v->voc_state == VOC_RUN)
2621 ret = voice_send_mute_cmd(v);
2622
2623 mutex_unlock(&v->lock);
2624
2625 return ret;
2626}
2627
Neema Shetty2c07eb52011-08-21 20:33:52 -07002628int voc_set_tty_mode(uint16_t session_id, uint8_t tty_mode)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002629{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002630 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002631 int ret = 0;
2632
Neema Shetty2c07eb52011-08-21 20:33:52 -07002633 if (v == NULL) {
2634 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2635
2636 return -EINVAL;
2637 }
2638
Helen Zengcc65b5b2011-07-06 19:14:48 -07002639 mutex_lock(&v->lock);
2640
2641 v->tty_mode = tty_mode;
2642
2643 mutex_unlock(&v->lock);
2644
2645 return ret;
2646}
2647
Neema Shetty2c07eb52011-08-21 20:33:52 -07002648uint8_t voc_get_tty_mode(uint16_t session_id)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002649{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002650 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002651 int ret = 0;
2652
Neema Shetty2c07eb52011-08-21 20:33:52 -07002653 if (v == NULL) {
2654 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2655
2656 return -EINVAL;
2657 }
2658
Helen Zengcc65b5b2011-07-06 19:14:48 -07002659 mutex_lock(&v->lock);
2660
2661 ret = v->tty_mode;
2662
2663 mutex_unlock(&v->lock);
2664
2665 return ret;
2666}
2667
Neema Shetty2c07eb52011-08-21 20:33:52 -07002668int voc_set_widevoice_enable(uint16_t session_id, uint32_t wv_enable)
Helen Zeng44d4d272011-08-10 14:49:20 -07002669{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002670 struct voice_data *v = voice_get_session(session_id);
Helen Zengb73acce2011-09-15 18:23:01 -07002671 u16 mvm_handle;
Helen Zeng44d4d272011-08-10 14:49:20 -07002672 int ret = 0;
2673
Neema Shetty2c07eb52011-08-21 20:33:52 -07002674 if (v == NULL) {
2675 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2676
2677 return -EINVAL;
2678 }
2679
Helen Zeng44d4d272011-08-10 14:49:20 -07002680 mutex_lock(&v->lock);
2681
2682 v->wv_enable = wv_enable;
2683
Helen Zengb73acce2011-09-15 18:23:01 -07002684 mvm_handle = voice_get_mvm_handle(v);
2685
2686 if (mvm_handle != 0)
2687 voice_send_set_widevoice_enable_cmd(v);
2688
Helen Zeng44d4d272011-08-10 14:49:20 -07002689 mutex_unlock(&v->lock);
2690
2691 return ret;
2692}
2693
Neema Shetty2c07eb52011-08-21 20:33:52 -07002694uint32_t voc_get_widevoice_enable(uint16_t session_id)
Helen Zeng44d4d272011-08-10 14:49:20 -07002695{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002696 struct voice_data *v = voice_get_session(session_id);
Helen Zeng44d4d272011-08-10 14:49:20 -07002697 int ret = 0;
2698
Neema Shetty2c07eb52011-08-21 20:33:52 -07002699 if (v == NULL) {
2700 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2701
2702 return -EINVAL;
2703 }
2704
Helen Zeng44d4d272011-08-10 14:49:20 -07002705 mutex_lock(&v->lock);
2706
2707 ret = v->wv_enable;
2708
2709 mutex_unlock(&v->lock);
2710
2711 return ret;
2712}
2713
Helen Zengbb49c702011-09-06 14:09:13 -07002714int voc_set_slowtalk_enable(uint16_t session_id, uint32_t st_enable)
2715{
2716 struct voice_data *v = voice_get_session(session_id);
2717 int ret = 0;
2718
2719 if (v == NULL) {
2720 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2721
2722 return -EINVAL;
2723 }
2724
2725 mutex_lock(&v->lock);
2726
2727 v->st_enable = st_enable;
2728
2729 if (v->voc_state == VOC_RUN)
2730 ret = voice_send_set_slowtalk_enable_cmd(v);
2731
2732 mutex_unlock(&v->lock);
2733
2734 return ret;
2735}
2736
2737uint32_t voc_get_slowtalk_enable(uint16_t session_id)
2738{
2739 struct voice_data *v = voice_get_session(session_id);
2740 int ret = 0;
2741
2742 if (v == NULL) {
2743 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2744
2745 return -EINVAL;
2746 }
2747
2748 mutex_lock(&v->lock);
2749
2750 ret = v->st_enable;
2751
2752 mutex_unlock(&v->lock);
2753
2754 return ret;
2755}
2756
Neema Shetty2c07eb52011-08-21 20:33:52 -07002757int voc_set_rx_vol_index(uint16_t session_id, uint32_t dir, uint32_t vol_idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002758{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002759 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002760 int ret = 0;
2761
Neema Shetty2c07eb52011-08-21 20:33:52 -07002762 if (v == NULL) {
2763 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2764
2765 return -EINVAL;
2766 }
2767
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002768 mutex_lock(&v->lock);
2769
2770 v->dev_rx.volume = vol_idx;
2771
2772 if (v->voc_state == VOC_RUN)
2773 ret = voice_send_vol_index_cmd(v);
2774
2775 mutex_unlock(&v->lock);
2776
2777 return ret;
2778}
2779
Neema Shetty2c07eb52011-08-21 20:33:52 -07002780int voc_set_rxtx_port(uint16_t session_id, uint32_t port_id, uint32_t dev_type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002781{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002782 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002783
Neema Shetty2c07eb52011-08-21 20:33:52 -07002784 if (v == NULL) {
2785 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2786
2787 return -EINVAL;
2788 }
2789
2790 pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002791
2792 mutex_lock(&v->lock);
2793
2794 if (dev_type == DEV_RX)
2795 v->dev_rx.port_id = port_id;
2796 else
2797 v->dev_tx.port_id = port_id;
2798
2799 mutex_unlock(&v->lock);
2800
Neema Shetty2c07eb52011-08-21 20:33:52 -07002801 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002802}
2803
Neema Shetty2c07eb52011-08-21 20:33:52 -07002804int voc_set_route_flag(uint16_t session_id, uint8_t path_dir, uint8_t set)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002805{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002806 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002807
Neema Shetty2c07eb52011-08-21 20:33:52 -07002808 if (v == NULL) {
2809 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2810
2811 return -EINVAL;
2812 }
2813
2814 pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002815
2816 mutex_lock(&v->lock);
2817
2818 if (path_dir == RX_PATH)
2819 v->voc_route_state.rx_route_flag = set;
2820 else
2821 v->voc_route_state.tx_route_flag = set;
2822
2823 mutex_unlock(&v->lock);
2824
Neema Shetty2c07eb52011-08-21 20:33:52 -07002825 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002826}
2827
Neema Shetty2c07eb52011-08-21 20:33:52 -07002828uint8_t voc_get_route_flag(uint16_t session_id, uint8_t path_dir)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002829{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002830 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002831 int ret = 0;
2832
Neema Shetty2c07eb52011-08-21 20:33:52 -07002833 if (v == NULL) {
2834 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2835
2836 return 0;
2837 }
2838
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002839 mutex_lock(&v->lock);
2840
2841 if (path_dir == RX_PATH)
2842 ret = v->voc_route_state.rx_route_flag;
2843 else
2844 ret = v->voc_route_state.tx_route_flag;
2845
2846 mutex_unlock(&v->lock);
2847
2848 return ret;
2849}
2850
Neema Shetty2c07eb52011-08-21 20:33:52 -07002851int voc_end_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002852{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002853 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002854 int ret = 0;
2855
Neema Shetty2c07eb52011-08-21 20:33:52 -07002856 if (v == NULL) {
2857 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2858
2859 return -EINVAL;
2860 }
2861
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002862 mutex_lock(&v->lock);
2863
2864 if (v->voc_state == VOC_RUN) {
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302865 if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
2866 v->dev_rx.port_id != RT_PROXY_PORT_001_RX)
2867 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
2868 0, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002869 ret = voice_destroy_vocproc(v);
2870 if (ret < 0)
2871 pr_err("%s: destroy voice failed\n", __func__);
2872 voice_destroy_mvm_cvs_session(v);
2873
2874 v->voc_state = VOC_RELEASE;
2875 }
2876 mutex_unlock(&v->lock);
2877 return ret;
2878}
2879
Neema Shetty2c07eb52011-08-21 20:33:52 -07002880int voc_start_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002881{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002882 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002883 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002884 int ret = 0;
2885
Neema Shetty2c07eb52011-08-21 20:33:52 -07002886 if (v == NULL) {
2887 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2888
2889 return -EINVAL;
2890 }
2891
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002892 mutex_lock(&v->lock);
2893
2894 if ((v->voc_state == VOC_INIT) ||
2895 (v->voc_state == VOC_RELEASE)) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002896 ret = voice_apr_register();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002897 if (ret < 0) {
2898 pr_err("%s: apr register failed\n", __func__);
2899 goto fail;
2900 }
2901 ret = voice_create_mvm_cvs_session(v);
2902 if (ret < 0) {
2903 pr_err("create mvm and cvs failed\n");
2904 goto fail;
2905 }
2906 ret = voice_setup_vocproc(v);
2907 if (ret < 0) {
2908 pr_err("setup voice failed\n");
2909 goto fail;
2910 }
2911 ret = voice_send_start_voice_cmd(v);
2912 if (ret < 0) {
2913 pr_err("start voice failed\n");
2914 goto fail;
2915 }
Helen Zengbd58e2c2011-07-01 16:24:31 -07002916 get_sidetone_cal(&sidetone_cal_data);
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302917 if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
2918 v->dev_rx.port_id != RT_PROXY_PORT_001_RX) {
2919 ret = afe_sidetone(v->dev_tx.port_id,
Helen Zengbd58e2c2011-07-01 16:24:31 -07002920 v->dev_rx.port_id,
2921 sidetone_cal_data.enable,
2922 sidetone_cal_data.gain);
Laxminath Kasam5b9cf0f2011-12-09 15:24:20 +05302923 if (ret < 0)
2924 pr_err("AFE command sidetone failed\n");
2925 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002926
2927 v->voc_state = VOC_RUN;
2928 }
2929
2930fail: mutex_unlock(&v->lock);
2931 return ret;
2932}
2933
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002934void voc_register_mvs_cb(ul_cb_fn ul_cb,
2935 dl_cb_fn dl_cb,
2936 void *private_data)
2937{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002938 common.mvs_info.ul_cb = ul_cb;
2939 common.mvs_info.dl_cb = dl_cb;
2940 common.mvs_info.private_data = private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002941}
2942
2943void voc_config_vocoder(uint32_t media_type,
2944 uint32_t rate,
2945 uint32_t network_type)
2946{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002947 common.mvs_info.media_type = media_type;
2948 common.mvs_info.rate = rate;
2949 common.mvs_info.network_type = network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002950}
2951
2952static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
2953{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002954 uint32_t *ptr = NULL;
2955 struct common_data *c = NULL;
2956 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002957 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002958
2959 if ((data == NULL) || (priv == NULL)) {
2960 pr_err("%s: data or priv is NULL\n", __func__);
2961 return -EINVAL;
2962 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002963
2964 c = priv;
2965
2966 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
2967
2968 v = voice_get_session(data->dest_port);
2969 if (v == NULL) {
2970 pr_err("%s: v is NULL\n", __func__);
2971
2972 return -EINVAL;
2973 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002974
2975 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2976 data->payload_size, data->opcode);
2977
Neema Shetty07477582011-09-02 17:35:44 -07002978 if (data->opcode == RESET_EVENTS) {
2979 pr_debug("%s: Reset event received in Voice service\n",
2980 __func__);
2981
2982 apr_reset(c->apr_q6_mvm);
2983 c->apr_q6_mvm = NULL;
2984
2985 /* Sub-system restart is applicable to all sessions. */
2986 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2987 c->voice[i].mvm_handle = 0;
2988
2989 return 0;
2990 }
2991
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002992 if (data->opcode == APR_BASIC_RSP_RESULT) {
2993 if (data->payload_size) {
2994 ptr = data->payload;
2995
2996 pr_info("%x %x\n", ptr[0], ptr[1]);
2997 /* ping mvm service ACK */
2998 switch (ptr[0]) {
2999 case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
3000 case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
3001 /* Passive session is used for CS call
3002 * Full session is used for VoIP call. */
3003 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3004 if (!ptr[1]) {
3005 pr_debug("%s: MVM handle is %d\n",
3006 __func__, data->src_port);
3007 voice_set_mvm_handle(v, data->src_port);
3008 } else
3009 pr_err("got NACK for sending \
3010 MVM create session \n");
3011 v->mvm_state = CMD_STATUS_SUCCESS;
3012 wake_up(&v->mvm_wait);
3013 break;
3014 case VSS_IMVM_CMD_START_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07003015 case VSS_IMVM_CMD_ATTACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003016 case VSS_IMVM_CMD_STOP_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07003017 case VSS_IMVM_CMD_DETACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003018 case VSS_ISTREAM_CMD_SET_TTY_MODE:
3019 case APRV2_IBASIC_CMD_DESTROY_SESSION:
3020 case VSS_IMVM_CMD_ATTACH_STREAM:
3021 case VSS_IMVM_CMD_DETACH_STREAM:
3022 case VSS_ICOMMON_CMD_SET_NETWORK:
3023 case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
Helen Zeng44d4d272011-08-10 14:49:20 -07003024 case VSS_IWIDEVOICE_CMD_SET_WIDEVOICE:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003025 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3026 v->mvm_state = CMD_STATUS_SUCCESS;
3027 wake_up(&v->mvm_wait);
3028 break;
3029 default:
3030 pr_debug("%s: not match cmd = 0x%x\n",
3031 __func__, ptr[0]);
3032 break;
3033 }
3034 }
3035 }
3036
3037 return 0;
3038}
3039
3040static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
3041{
Neema Shetty2c07eb52011-08-21 20:33:52 -07003042 uint32_t *ptr = NULL;
3043 struct common_data *c = NULL;
3044 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07003045 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003046
3047 if ((data == NULL) || (priv == NULL)) {
3048 pr_err("%s: data or priv is NULL\n", __func__);
3049 return -EINVAL;
3050 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07003051
3052 c = priv;
3053
3054 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
3055
3056 v = voice_get_session(data->dest_port);
3057 if (v == NULL) {
3058 pr_err("%s: v is NULL\n", __func__);
3059
3060 return -EINVAL;
3061 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003062
3063 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
3064 data->payload_size, data->opcode);
3065
Neema Shetty07477582011-09-02 17:35:44 -07003066 if (data->opcode == RESET_EVENTS) {
3067 pr_debug("%s: Reset event received in Voice service\n",
3068 __func__);
3069
3070 apr_reset(c->apr_q6_cvs);
3071 c->apr_q6_cvs = NULL;
3072
3073 /* Sub-system restart is applicable to all sessions. */
3074 for (i = 0; i < MAX_VOC_SESSIONS; i++)
3075 c->voice[i].cvs_handle = 0;
3076
3077 return 0;
3078 }
3079
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003080 if (data->opcode == APR_BASIC_RSP_RESULT) {
3081 if (data->payload_size) {
3082 ptr = data->payload;
3083
3084 pr_info("%x %x\n", ptr[0], ptr[1]);
3085 /*response from CVS */
3086 switch (ptr[0]) {
3087 case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
3088 case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
3089 if (!ptr[1]) {
3090 pr_debug("%s: CVS handle is %d\n",
3091 __func__, data->src_port);
3092 voice_set_cvs_handle(v, data->src_port);
3093 } else
3094 pr_err("got NACK for sending \
3095 CVS create session \n");
3096 v->cvs_state = CMD_STATUS_SUCCESS;
3097 wake_up(&v->cvs_wait);
3098 break;
3099 case VSS_ISTREAM_CMD_SET_MUTE:
3100 case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
3101 case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
3102 case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
3103 case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
3104 case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
3105 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07003106 case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA:
3107 case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
3108 case VSS_ICOMMON_CMD_MAP_MEMORY:
3109 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Helen Zengbb49c702011-09-06 14:09:13 -07003110 case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
Helen Zeng0705a5f2011-10-14 15:29:52 -07003111 case VSS_ISTREAM_CMD_START_PLAYBACK:
3112 case VSS_ISTREAM_CMD_STOP_PLAYBACK:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003113 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3114 v->cvs_state = CMD_STATUS_SUCCESS;
3115 wake_up(&v->cvs_wait);
3116 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07003117 case VOICE_CMD_SET_PARAM:
3118 rtac_make_voice_callback(RTAC_CVS, ptr,
3119 data->payload_size);
3120 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003121 default:
3122 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3123 break;
3124 }
3125 }
3126 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
3127 uint32_t *voc_pkt = data->payload;
3128 uint32_t pkt_len = data->payload_size;
3129
Neema Shetty2c07eb52011-08-21 20:33:52 -07003130 if (voc_pkt != NULL && c->mvs_info.ul_cb != NULL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003131 pr_debug("%s: Media type is 0x%x\n",
3132 __func__, voc_pkt[0]);
3133
3134 /* Remove media ID from payload. */
3135 voc_pkt++;
3136 pkt_len = pkt_len - 4;
3137
Neema Shetty2c07eb52011-08-21 20:33:52 -07003138 c->mvs_info.ul_cb((uint8_t *)voc_pkt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003139 pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07003140 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003141 } else
3142 pr_err("%s: voc_pkt is 0x%x ul_cb is 0x%x\n",
3143 __func__, (unsigned int)voc_pkt,
Neema Shetty2c07eb52011-08-21 20:33:52 -07003144 (unsigned int) c->mvs_info.ul_cb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003145 } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
3146 struct cvs_send_dec_buf_cmd send_dec_buf;
3147 int ret = 0;
3148 uint32_t pkt_len = 0;
3149
Neema Shetty2c07eb52011-08-21 20:33:52 -07003150 if (c->mvs_info.dl_cb != NULL) {
3151 send_dec_buf.dec_buf.media_id = c->mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003152
Neema Shetty2c07eb52011-08-21 20:33:52 -07003153 c->mvs_info.dl_cb(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003154 (uint8_t *)&send_dec_buf.dec_buf.packet_data,
3155 &pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07003156 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003157
3158 send_dec_buf.hdr.hdr_field =
3159 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3160 APR_HDR_LEN(APR_HDR_SIZE),
3161 APR_PKT_VER);
3162 send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
3163 sizeof(send_dec_buf.dec_buf.media_id) + pkt_len);
Neema Shetty2c07eb52011-08-21 20:33:52 -07003164 send_dec_buf.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003165 send_dec_buf.hdr.dest_port = voice_get_cvs_handle(v);
3166 send_dec_buf.hdr.token = 0;
3167 send_dec_buf.hdr.opcode =
3168 VSS_ISTREAM_EVT_SEND_DEC_BUFFER;
3169
Neema Shetty2c07eb52011-08-21 20:33:52 -07003170 ret = apr_send_pkt(c->apr_q6_cvs,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003171 (uint32_t *) &send_dec_buf);
3172 if (ret < 0) {
3173 pr_err("%s: Error %d sending DEC_BUF\n",
3174 __func__, ret);
3175 goto fail;
3176 }
3177 } else
3178 pr_debug("%s: dl_cb is NULL\n", __func__);
Ben Romberger13b74ab2011-07-18 17:36:32 -07003179 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003180 pr_debug("Send dec buf resp\n");
Ben Romberger13b74ab2011-07-18 17:36:32 -07003181 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
3182 rtac_make_voice_callback(RTAC_CVS, data->payload,
3183 data->payload_size);
3184 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003185 pr_debug("Unknown opcode 0x%x\n", data->opcode);
3186
3187fail:
3188 return 0;
3189}
3190
3191static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
3192{
Neema Shetty2c07eb52011-08-21 20:33:52 -07003193 uint32_t *ptr = NULL;
3194 struct common_data *c = NULL;
3195 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07003196 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003197
3198 if ((data == NULL) || (priv == NULL)) {
3199 pr_err("%s: data or priv is NULL\n", __func__);
3200 return -EINVAL;
3201 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07003202
3203 c = priv;
3204
3205 v = voice_get_session(data->dest_port);
3206 if (v == NULL) {
3207 pr_err("%s: v is NULL\n", __func__);
3208
3209 return -EINVAL;
3210 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003211
3212 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
3213 data->payload_size, data->opcode);
3214
Neema Shetty07477582011-09-02 17:35:44 -07003215 if (data->opcode == RESET_EVENTS) {
3216 pr_debug("%s: Reset event received in Voice service\n",
3217 __func__);
3218
3219 apr_reset(c->apr_q6_cvp);
3220 c->apr_q6_cvp = NULL;
3221
3222 /* Sub-system restart is applicable to all sessions. */
3223 for (i = 0; i < MAX_VOC_SESSIONS; i++)
3224 c->voice[i].cvp_handle = 0;
3225
3226 return 0;
3227 }
3228
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003229 if (data->opcode == APR_BASIC_RSP_RESULT) {
3230 if (data->payload_size) {
3231 ptr = data->payload;
3232
3233 pr_info("%x %x\n", ptr[0], ptr[1]);
3234
3235 switch (ptr[0]) {
3236 case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION:
3237 /*response from CVP */
3238 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3239 if (!ptr[1]) {
3240 voice_set_cvp_handle(v, data->src_port);
3241 pr_debug("cvphdl=%d\n", data->src_port);
3242 } else
3243 pr_err("got NACK from CVP create \
3244 session response\n");
3245 v->cvp_state = CMD_STATUS_SUCCESS;
3246 wake_up(&v->cvp_wait);
3247 break;
3248 case VSS_IVOCPROC_CMD_SET_DEVICE:
3249 case VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX:
3250 case VSS_IVOCPROC_CMD_ENABLE:
3251 case VSS_IVOCPROC_CMD_DISABLE:
3252 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07003253 case VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE:
3254 case VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE:
3255 case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA:
3256 case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
3257 case VSS_ICOMMON_CMD_MAP_MEMORY:
3258 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003259 v->cvp_state = CMD_STATUS_SUCCESS;
3260 wake_up(&v->cvp_wait);
3261 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07003262 case VOICE_CMD_SET_PARAM:
3263 rtac_make_voice_callback(RTAC_CVP, ptr,
3264 data->payload_size);
3265 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003266 default:
3267 pr_debug("%s: not match cmd = 0x%x\n",
3268 __func__, ptr[0]);
3269 break;
3270 }
3271 }
Ben Romberger13b74ab2011-07-18 17:36:32 -07003272 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
3273 rtac_make_voice_callback(RTAC_CVP, data->payload,
3274 data->payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003275 }
3276 return 0;
3277}
3278
3279
3280static int __init voice_init(void)
3281{
Neema Shetty2c07eb52011-08-21 20:33:52 -07003282 int rc = 0, i = 0;
3283
3284 memset(&common, 0, sizeof(struct common_data));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003285
3286 /* set default value */
Neema Shetty2c07eb52011-08-21 20:33:52 -07003287 common.default_mute_val = 1; /* default is mute */
3288 common.default_vol_val = 0;
3289 common.default_sample_val = 8000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003290
3291 /* Initialize MVS info. */
Neema Shetty2c07eb52011-08-21 20:33:52 -07003292 common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
3293
3294 mutex_init(&common.common_lock);
3295
3296 for (i = 0; i < MAX_VOC_SESSIONS; i++) {
3297 common.voice[i].session_id = SESSION_ID_BASE + i;
3298
3299 /* initialize dev_rx and dev_tx */
3300 common.voice[i].dev_rx.volume = common.default_vol_val;
3301 common.voice[i].dev_tx.mute = common.default_mute_val;
3302
3303 common.voice[i].dev_tx.port_id = 1;
3304 common.voice[i].dev_rx.port_id = 0;
3305 common.voice[i].sidetone_gain = 0x512;
3306
3307 common.voice[i].voc_state = VOC_INIT;
3308
3309 init_waitqueue_head(&common.voice[i].mvm_wait);
3310 init_waitqueue_head(&common.voice[i].cvs_wait);
3311 init_waitqueue_head(&common.voice[i].cvp_wait);
3312
3313 mutex_init(&common.voice[i].lock);
3314 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003315
3316 return rc;
3317}
3318
3319device_initcall(voice_init);