blob: 2e9d30cbdfbcd974dd6aa96f466094b529d23c34 [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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
59static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
60static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
61
62static u16 voice_get_mvm_handle(struct voice_data *v)
63{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064 if (v == NULL) {
65 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070066 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068
Neema Shetty2c07eb52011-08-21 20:33:52 -070069 pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070
Neema Shetty2c07eb52011-08-21 20:33:52 -070071 return v->mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072}
73
74static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
75{
76 pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
77 if (v == NULL) {
78 pr_err("%s: v is NULL\n", __func__);
79 return;
80 }
81
Neema Shetty2c07eb52011-08-21 20:33:52 -070082 v->mvm_handle = mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070083}
84
85static u16 voice_get_cvs_handle(struct voice_data *v)
86{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087 if (v == NULL) {
88 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070089 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091
Neema Shetty2c07eb52011-08-21 20:33:52 -070092 pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093
Neema Shetty2c07eb52011-08-21 20:33:52 -070094 return v->cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095}
96
97static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
98{
99 pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
100 if (v == NULL) {
101 pr_err("%s: v is NULL\n", __func__);
102 return;
103 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700104
105 v->cvs_handle = cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700106}
107
108static u16 voice_get_cvp_handle(struct voice_data *v)
109{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700110 if (v == NULL) {
111 pr_err("%s: v is NULL\n", __func__);
112 return 0;
113 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114
Neema Shetty2c07eb52011-08-21 20:33:52 -0700115 pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116
Neema Shetty2c07eb52011-08-21 20:33:52 -0700117 return v->cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118}
119
120static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
121{
122 pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
123 if (v == NULL) {
124 pr_err("%s: v is NULL\n", __func__);
125 return;
126 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700127
128 v->cvp_handle = cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129}
130
Neema Shetty2c07eb52011-08-21 20:33:52 -0700131uint16_t voc_get_session_id(char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700133 u16 session_id = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134
Neema Shetty2c07eb52011-08-21 20:33:52 -0700135 if (name != NULL) {
136 if (!strncmp(name, "Voice session", 13))
137 session_id = common.voice[VOC_PATH_PASSIVE].session_id;
138 else
139 session_id = common.voice[VOC_PATH_FULL].session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141
Neema Shetty2c07eb52011-08-21 20:33:52 -0700142 pr_debug("%s: %s has session id 0x%x\n", __func__, name, session_id);
143
144 return session_id;
145}
146
147static struct voice_data *voice_get_session(u16 session_id)
148{
149 struct voice_data *v = NULL;
150
151 if ((session_id >= SESSION_ID_BASE) &&
152 (session_id < SESSION_ID_BASE + MAX_VOC_SESSIONS)) {
153 v = &common.voice[session_id - SESSION_ID_BASE];
154 }
155
156 pr_debug("%s: session_id 0x%x session handle 0x%x\n",
157 __func__, session_id, (unsigned int)v);
158
159 return v;
160}
161
162static bool is_voice_session(u16 session_id)
163{
164 return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
165}
166
167static bool is_voip_session(u16 session_id)
168{
169 return (session_id == common.voice[VOC_PATH_FULL].session_id);
170}
171
172static int voice_apr_register(void)
173{
174 pr_debug("%s\n", __func__);
175
176 mutex_lock(&common.common_lock);
177
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 /* register callback to APR */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700179 if (common.apr_q6_mvm == NULL) {
180 pr_debug("%s: Start to register MVM callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181
Neema Shetty2c07eb52011-08-21 20:33:52 -0700182 common.apr_q6_mvm = apr_register("ADSP", "MVM",
183 qdsp_mvm_callback,
184 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185
Neema Shetty2c07eb52011-08-21 20:33:52 -0700186 if (common.apr_q6_mvm == NULL) {
187 pr_err("%s: Unable to register MVM\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188 goto err;
189 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 }
191
Neema Shetty2c07eb52011-08-21 20:33:52 -0700192 if (common.apr_q6_cvs == NULL) {
193 pr_debug("%s: Start to register CVS callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194
Neema Shetty2c07eb52011-08-21 20:33:52 -0700195 common.apr_q6_cvs = apr_register("ADSP", "CVS",
196 qdsp_cvs_callback,
197 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198
Neema Shetty2c07eb52011-08-21 20:33:52 -0700199 if (common.apr_q6_cvs == NULL) {
200 pr_err("%s: Unable to register CVS\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201 goto err;
202 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700203
Neema Shetty2c07eb52011-08-21 20:33:52 -0700204 rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 }
206
Neema Shetty2c07eb52011-08-21 20:33:52 -0700207 if (common.apr_q6_cvp == NULL) {
208 pr_debug("%s: Start to register CVP callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209
Neema Shetty2c07eb52011-08-21 20:33:52 -0700210 common.apr_q6_cvp = apr_register("ADSP", "CVP",
211 qdsp_cvp_callback,
212 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213
Neema Shetty2c07eb52011-08-21 20:33:52 -0700214 if (common.apr_q6_cvp == NULL) {
215 pr_err("%s: Unable to register CVP\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216 goto err;
217 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700218
Neema Shetty2c07eb52011-08-21 20:33:52 -0700219 rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700221
222 mutex_unlock(&common.common_lock);
223
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224 return 0;
225
226err:
Neema Shetty2c07eb52011-08-21 20:33:52 -0700227 if (common.apr_q6_cvs != NULL) {
228 apr_deregister(common.apr_q6_cvs);
229 common.apr_q6_cvs = NULL;
Ben Romberger13b74ab2011-07-18 17:36:32 -0700230 rtac_set_voice_handle(RTAC_CVS, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700231 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700232 if (common.apr_q6_mvm != NULL) {
233 apr_deregister(common.apr_q6_mvm);
234 common.apr_q6_mvm = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235 }
236
Neema Shetty2c07eb52011-08-21 20:33:52 -0700237 mutex_unlock(&common.common_lock);
238
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239 return -ENODEV;
240}
241
242static int voice_create_mvm_cvs_session(struct voice_data *v)
243{
244 int ret = 0;
Helen Zeng69b00962011-07-08 11:38:36 -0700245 struct mvm_create_ctl_session_cmd mvm_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700246 struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700247 struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
248 struct mvm_attach_stream_cmd attach_stream_cmd;
249 void *apr_mvm, *apr_cvs, *apr_cvp;
250 u16 mvm_handle, cvs_handle, cvp_handle;
251
252 if (v == NULL) {
253 pr_err("%s: v is NULL\n", __func__);
254 return -EINVAL;
255 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700256 apr_mvm = common.apr_q6_mvm;
257 apr_cvs = common.apr_q6_cvs;
258 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700259
260 if (!apr_mvm || !apr_cvs || !apr_cvp) {
261 pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
262 return -EINVAL;
263 }
264 mvm_handle = voice_get_mvm_handle(v);
265 cvs_handle = voice_get_cvs_handle(v);
266 cvp_handle = voice_get_cvp_handle(v);
267
268 pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
269 mvm_handle, cvs_handle);
270 /* send cmd to create mvm session and wait for response */
271
272 if (!mvm_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700273 if (is_voice_session(v->session_id)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700274 mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
275 APR_MSG_TYPE_SEQ_CMD,
276 APR_HDR_LEN(APR_HDR_SIZE),
277 APR_PKT_VER);
278 mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
279 APR_HDR_SIZE,
280 sizeof(mvm_session_cmd) -
281 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700282 pr_debug("%s: send mvm create session pkt size = %d\n",
283 __func__, mvm_session_cmd.hdr.pkt_size);
284 mvm_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700285 mvm_session_cmd.hdr.dest_port = 0;
286 mvm_session_cmd.hdr.token = 0;
287 mvm_session_cmd.hdr.opcode =
288 VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
Helen Zeng69b00962011-07-08 11:38:36 -0700289 strncpy(mvm_session_cmd.mvm_session.name,
290 "default modem voice", SESSION_NAME_LEN);
291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292 v->mvm_state = CMD_STATUS_FAIL;
293
294 ret = apr_send_pkt(apr_mvm,
295 (uint32_t *) &mvm_session_cmd);
296 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700297 pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
298 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 goto fail;
300 }
301 ret = wait_event_timeout(v->mvm_wait,
302 (v->mvm_state == CMD_STATUS_SUCCESS),
303 msecs_to_jiffies(TIMEOUT_MS));
304 if (!ret) {
305 pr_err("%s: wait_event timeout\n", __func__);
306 goto fail;
307 }
308 } else {
309 pr_debug("%s: creating MVM full ctrl\n", __func__);
Helen Zeng69b00962011-07-08 11:38:36 -0700310 mvm_session_cmd.hdr.hdr_field =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700311 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
312 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
Helen Zeng69b00962011-07-08 11:38:36 -0700313 mvm_session_cmd.hdr.pkt_size =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700314 APR_PKT_SIZE(APR_HDR_SIZE,
Helen Zeng69b00962011-07-08 11:38:36 -0700315 sizeof(mvm_session_cmd) -
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700317 mvm_session_cmd.hdr.src_port = v->session_id;
Helen Zeng69b00962011-07-08 11:38:36 -0700318 mvm_session_cmd.hdr.dest_port = 0;
319 mvm_session_cmd.hdr.token = 0;
320 mvm_session_cmd.hdr.opcode =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700321 VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
Helen Zeng69b00962011-07-08 11:38:36 -0700322 strncpy(mvm_session_cmd.mvm_session.name,
323 "default voip", SESSION_NAME_LEN);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324
325 v->mvm_state = CMD_STATUS_FAIL;
326
327 ret = apr_send_pkt(apr_mvm,
Helen Zeng69b00962011-07-08 11:38:36 -0700328 (uint32_t *) &mvm_session_cmd);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700329 if (ret < 0) {
330 pr_err("Fail in sending MVM_CONTROL_SESSION\n");
331 goto fail;
332 }
333 ret = wait_event_timeout(v->mvm_wait,
334 (v->mvm_state == CMD_STATUS_SUCCESS),
335 msecs_to_jiffies(TIMEOUT_MS));
336 if (!ret) {
337 pr_err("%s: wait_event timeout\n", __func__);
338 goto fail;
339 }
340 }
341 /* Get the created MVM handle. */
342 mvm_handle = voice_get_mvm_handle(v);
343 }
344 /* send cmd to create cvs session */
345 if (!cvs_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700346 if (is_voice_session(v->session_id)) {
347 pr_debug("%s: creating CVS passive session\n",
348 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349
350 cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
351 APR_MSG_TYPE_SEQ_CMD,
352 APR_HDR_LEN(APR_HDR_SIZE),
353 APR_PKT_VER);
354 cvs_session_cmd.hdr.pkt_size =
355 APR_PKT_SIZE(APR_HDR_SIZE,
356 sizeof(cvs_session_cmd) -
357 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700358 cvs_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700359 cvs_session_cmd.hdr.dest_port = 0;
360 cvs_session_cmd.hdr.token = 0;
361 cvs_session_cmd.hdr.opcode =
362 VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
363 strncpy(cvs_session_cmd.cvs_session.name,
Helen Zeng69b00962011-07-08 11:38:36 -0700364 "default modem voice", SESSION_NAME_LEN);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700365
366 v->cvs_state = CMD_STATUS_FAIL;
367
368 ret = apr_send_pkt(apr_cvs,
369 (uint32_t *) &cvs_session_cmd);
370 if (ret < 0) {
371 pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
372 goto fail;
373 }
374 ret = wait_event_timeout(v->cvs_wait,
375 (v->cvs_state == CMD_STATUS_SUCCESS),
376 msecs_to_jiffies(TIMEOUT_MS));
377 if (!ret) {
378 pr_err("%s: wait_event timeout\n", __func__);
379 goto fail;
380 }
381 /* Get the created CVS handle. */
382 cvs_handle = voice_get_cvs_handle(v);
383
384 } else {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700385 pr_debug("%s: creating CVS full session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700386
387 cvs_full_ctl_cmd.hdr.hdr_field =
388 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
389 APR_HDR_LEN(APR_HDR_SIZE),
390 APR_PKT_VER);
391
392 cvs_full_ctl_cmd.hdr.pkt_size =
393 APR_PKT_SIZE(APR_HDR_SIZE,
394 sizeof(cvs_full_ctl_cmd) -
395 APR_HDR_SIZE);
396
Neema Shetty2c07eb52011-08-21 20:33:52 -0700397 cvs_full_ctl_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398 cvs_full_ctl_cmd.hdr.dest_port = 0;
399 cvs_full_ctl_cmd.hdr.token = 0;
400 cvs_full_ctl_cmd.hdr.opcode =
401 VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
402 cvs_full_ctl_cmd.cvs_session.direction = 2;
403 cvs_full_ctl_cmd.cvs_session.enc_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700404 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700405 cvs_full_ctl_cmd.cvs_session.dec_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700406 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700407 cvs_full_ctl_cmd.cvs_session.network_id =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700408 common.mvs_info.network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700409 strncpy(cvs_full_ctl_cmd.cvs_session.name,
410 "default q6 voice", 16);
411
412 v->cvs_state = CMD_STATUS_FAIL;
413
414 ret = apr_send_pkt(apr_cvs,
415 (uint32_t *) &cvs_full_ctl_cmd);
416
417 if (ret < 0) {
418 pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
419 __func__, ret);
420 goto fail;
421 }
422 ret = wait_event_timeout(v->cvs_wait,
423 (v->cvs_state == CMD_STATUS_SUCCESS),
424 msecs_to_jiffies(TIMEOUT_MS));
425 if (!ret) {
426 pr_err("%s: wait_event timeout\n", __func__);
427 goto fail;
428 }
429 /* Get the created CVS handle. */
430 cvs_handle = voice_get_cvs_handle(v);
431
432 /* Attach MVM to CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700433 pr_debug("%s: Attach MVM to stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700434
435 attach_stream_cmd.hdr.hdr_field =
436 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
437 APR_HDR_LEN(APR_HDR_SIZE),
438 APR_PKT_VER);
439 attach_stream_cmd.hdr.pkt_size =
440 APR_PKT_SIZE(APR_HDR_SIZE,
441 sizeof(attach_stream_cmd) -
442 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700443 attach_stream_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700444 attach_stream_cmd.hdr.dest_port = mvm_handle;
445 attach_stream_cmd.hdr.token = 0;
446 attach_stream_cmd.hdr.opcode =
447 VSS_IMVM_CMD_ATTACH_STREAM;
448 attach_stream_cmd.attach_stream.handle = cvs_handle;
449
450 v->mvm_state = CMD_STATUS_FAIL;
451 ret = apr_send_pkt(apr_mvm,
452 (uint32_t *) &attach_stream_cmd);
453 if (ret < 0) {
454 pr_err("%s: Error %d sending ATTACH_STREAM\n",
455 __func__, ret);
456 goto fail;
457 }
458 ret = wait_event_timeout(v->mvm_wait,
459 (v->mvm_state == CMD_STATUS_SUCCESS),
460 msecs_to_jiffies(TIMEOUT_MS));
461 if (!ret) {
462 pr_err("%s: wait_event timeout\n", __func__);
463 goto fail;
464 }
465 }
466 }
467 return 0;
468
469fail:
470 return -EINVAL;
471}
472
473static int voice_destroy_mvm_cvs_session(struct voice_data *v)
474{
475 int ret = 0;
476 struct mvm_detach_stream_cmd detach_stream;
477 struct apr_hdr mvm_destroy;
478 struct apr_hdr cvs_destroy;
479 void *apr_mvm, *apr_cvs;
480 u16 mvm_handle, cvs_handle;
481
482 if (v == NULL) {
483 pr_err("%s: v is NULL\n", __func__);
484 return -EINVAL;
485 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700486 apr_mvm = common.apr_q6_mvm;
487 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488
489 if (!apr_mvm || !apr_cvs) {
490 pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
491 return -EINVAL;
492 }
493 mvm_handle = voice_get_mvm_handle(v);
494 cvs_handle = voice_get_cvs_handle(v);
495
496 /* MVM, CVS sessions are destroyed only for Full control sessions. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700497 if (is_voip_session(v->session_id)) {
498 pr_debug("%s: MVM detach stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499
500 /* Detach voice stream. */
501 detach_stream.hdr.hdr_field =
502 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
503 APR_HDR_LEN(APR_HDR_SIZE),
504 APR_PKT_VER);
505 detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
506 sizeof(detach_stream) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700507 detach_stream.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508 detach_stream.hdr.dest_port = mvm_handle;
509 detach_stream.hdr.token = 0;
510 detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
511 detach_stream.detach_stream.handle = cvs_handle;
512
513 v->mvm_state = CMD_STATUS_FAIL;
514
515 ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
516 if (ret < 0) {
517 pr_err("%s: Error %d sending DETACH_STREAM\n",
518 __func__, ret);
519 goto fail;
520 }
521 ret = wait_event_timeout(v->mvm_wait,
522 (v->mvm_state == CMD_STATUS_SUCCESS),
523 msecs_to_jiffies(TIMEOUT_MS));
524 if (!ret) {
525 pr_err("%s: wait event timeout\n", __func__);
526 goto fail;
527 }
528 /* Destroy CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700529 pr_debug("%s: CVS destroy session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700530
531 cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
532 APR_HDR_LEN(APR_HDR_SIZE),
533 APR_PKT_VER);
534 cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
535 sizeof(cvs_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700536 cvs_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537 cvs_destroy.dest_port = cvs_handle;
538 cvs_destroy.token = 0;
539 cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
540
541 v->cvs_state = CMD_STATUS_FAIL;
542
543 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
544 if (ret < 0) {
545 pr_err("%s: Error %d sending CVS DESTROY\n",
546 __func__, ret);
547 goto fail;
548 }
549 ret = wait_event_timeout(v->cvs_wait,
550 (v->cvs_state == CMD_STATUS_SUCCESS),
551 msecs_to_jiffies(TIMEOUT_MS));
552 if (!ret) {
553 pr_err("%s: wait event timeout\n", __func__);
554
555 goto fail;
556 }
557 cvs_handle = 0;
558 voice_set_cvs_handle(v, cvs_handle);
559
560 /* Destroy MVM. */
561 pr_debug("MVM destroy session\n");
562
563 mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
564 APR_HDR_LEN(APR_HDR_SIZE),
565 APR_PKT_VER);
566 mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
567 sizeof(mvm_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700568 mvm_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569 mvm_destroy.dest_port = mvm_handle;
570 mvm_destroy.token = 0;
571 mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
572
573 v->mvm_state = CMD_STATUS_FAIL;
574
575 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
576 if (ret < 0) {
577 pr_err("%s: Error %d sending MVM DESTROY\n",
578 __func__, ret);
579
580 goto fail;
581 }
582 ret = wait_event_timeout(v->mvm_wait,
583 (v->mvm_state == CMD_STATUS_SUCCESS),
584 msecs_to_jiffies(TIMEOUT_MS));
585 if (!ret) {
586 pr_err("%s: wait event timeout\n", __func__);
587
588 goto fail;
589 }
590 mvm_handle = 0;
591 voice_set_mvm_handle(v, mvm_handle);
592 }
593 return 0;
594fail:
595 return -EINVAL;
596}
597
598static int voice_send_tty_mode_cmd(struct voice_data *v)
599{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700600 int ret = 0;
601 struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
602 void *apr_mvm;
603 u16 mvm_handle;
604
605 if (v == NULL) {
606 pr_err("%s: v is NULL\n", __func__);
607 return -EINVAL;
608 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700609 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610
611 if (!apr_mvm) {
612 pr_err("%s: apr_mvm is NULL.\n", __func__);
613 return -EINVAL;
614 }
615 mvm_handle = voice_get_mvm_handle(v);
616
Helen Zengcc65b5b2011-07-06 19:14:48 -0700617 if (v->tty_mode) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700618 /* send tty mode cmd to mvm */
619 mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
620 APR_MSG_TYPE_SEQ_CMD,
621 APR_HDR_LEN(APR_HDR_SIZE),
622 APR_PKT_VER);
623 mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
624 sizeof(mvm_tty_mode_cmd) -
625 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700626 pr_debug("%s: pkt size = %d\n",
627 __func__, mvm_tty_mode_cmd.hdr.pkt_size);
628 mvm_tty_mode_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700629 mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
630 mvm_tty_mode_cmd.hdr.token = 0;
631 mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
Helen Zengcc65b5b2011-07-06 19:14:48 -0700632 mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633 pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
634
635 v->mvm_state = CMD_STATUS_FAIL;
636 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
637 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700638 pr_err("%s: Error %d sending SET_TTY_MODE\n",
639 __func__, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 goto fail;
641 }
642 ret = wait_event_timeout(v->mvm_wait,
643 (v->mvm_state == CMD_STATUS_SUCCESS),
644 msecs_to_jiffies(TIMEOUT_MS));
645 if (!ret) {
646 pr_err("%s: wait_event timeout\n", __func__);
647 goto fail;
648 }
649 }
650 return 0;
651fail:
652 return -EINVAL;
653}
654
655static int voice_config_cvs_vocoder(struct voice_data *v)
656{
657 int ret = 0;
658 void *apr_cvs;
659 u16 cvs_handle;
660 /* Set media type. */
661 struct cvs_set_media_type_cmd cvs_set_media_cmd;
662
663 if (v == NULL) {
664 pr_err("%s: v is NULL\n", __func__);
665 return -EINVAL;
666 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700667 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700668
669 if (!apr_cvs) {
670 pr_err("%s: apr_cvs is NULL.\n", __func__);
671 return -EINVAL;
672 }
673
674 cvs_handle = voice_get_cvs_handle(v);
675
676 cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
677 APR_HDR_LEN(APR_HDR_SIZE),
678 APR_PKT_VER);
679 cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
680 sizeof(cvs_set_media_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700681 cvs_set_media_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682 cvs_set_media_cmd.hdr.dest_port = cvs_handle;
683 cvs_set_media_cmd.hdr.token = 0;
684 cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700685 cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
686 cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700687
688 v->cvs_state = CMD_STATUS_FAIL;
689
690 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
691 if (ret < 0) {
692 pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
693 __func__, ret);
694
695 goto fail;
696 }
697 ret = wait_event_timeout(v->cvs_wait,
698 (v->cvs_state == CMD_STATUS_SUCCESS),
699 msecs_to_jiffies(TIMEOUT_MS));
700 if (!ret) {
701 pr_err("%s: wait_event timeout\n", __func__);
702
703 goto fail;
704 }
705 /* Set encoder properties. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700706 switch (common.mvs_info.media_type) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700707 case VSS_MEDIA_ID_EVRC_MODEM: {
708 struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
709
710 pr_debug("Setting EVRC min-max rate\n");
711
712 cvs_set_cdma_rate.hdr.hdr_field =
713 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
714 APR_HDR_LEN(APR_HDR_SIZE),
715 APR_PKT_VER);
716 cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
717 sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700718 cvs_set_cdma_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700719 cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
720 cvs_set_cdma_rate.hdr.token = 0;
721 cvs_set_cdma_rate.hdr.opcode =
722 VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700723 cvs_set_cdma_rate.cdma_rate.min_rate = common.mvs_info.rate;
724 cvs_set_cdma_rate.cdma_rate.max_rate = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700725
726 v->cvs_state = CMD_STATUS_FAIL;
727
728 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
729 if (ret < 0) {
730 pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
731 __func__, ret);
732 goto fail;
733 }
734 ret = wait_event_timeout(v->cvs_wait,
735 (v->cvs_state == CMD_STATUS_SUCCESS),
736 msecs_to_jiffies(TIMEOUT_MS));
737 if (!ret) {
738 pr_err("%s: wait_event timeout\n", __func__);
739
740 goto fail;
741 }
742 break;
743 }
744 case VSS_MEDIA_ID_AMR_NB_MODEM: {
745 struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
746 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
747
748 pr_debug("Setting AMR rate\n");
749
750 cvs_set_amr_rate.hdr.hdr_field =
751 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
752 APR_HDR_LEN(APR_HDR_SIZE),
753 APR_PKT_VER);
754 cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
755 sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700756 cvs_set_amr_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757 cvs_set_amr_rate.hdr.dest_port = cvs_handle;
758 cvs_set_amr_rate.hdr.token = 0;
759 cvs_set_amr_rate.hdr.opcode =
760 VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700761 cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762
763 v->cvs_state = CMD_STATUS_FAIL;
764
765 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
766 if (ret < 0) {
767 pr_err("%s: Error %d sending SET_AMR_RATE\n",
768 __func__, ret);
769 goto fail;
770 }
771 ret = wait_event_timeout(v->cvs_wait,
772 (v->cvs_state == CMD_STATUS_SUCCESS),
773 msecs_to_jiffies(TIMEOUT_MS));
774 if (!ret) {
775 pr_err("%s: wait_event timeout\n", __func__);
776 goto fail;
777 }
778 /* Disable DTX */
779 pr_debug("Disabling DTX\n");
780
781 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
782 APR_HDR_LEN(APR_HDR_SIZE),
783 APR_PKT_VER);
784 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
785 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700786 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 cvs_set_dtx.hdr.dest_port = cvs_handle;
788 cvs_set_dtx.hdr.token = 0;
789 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
790 cvs_set_dtx.dtx_mode.enable = 0;
791
792 v->cvs_state = CMD_STATUS_FAIL;
793
794 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
795 if (ret < 0) {
796 pr_err("%s: Error %d sending SET_DTX\n",
797 __func__, ret);
798 goto fail;
799 }
800 ret = wait_event_timeout(v->cvs_wait,
801 (v->cvs_state == CMD_STATUS_SUCCESS),
802 msecs_to_jiffies(TIMEOUT_MS));
803 if (!ret) {
804 pr_err("%s: wait_event timeout\n", __func__);
805 goto fail;
806 }
807 break;
808 }
809 case VSS_MEDIA_ID_AMR_WB_MODEM: {
810 struct cvs_set_amrwb_enc_rate_cmd cvs_set_amrwb_rate;
811 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
812
813 pr_debug("Setting AMR WB rate\n");
814
815 cvs_set_amrwb_rate.hdr.hdr_field =
816 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
817 APR_HDR_LEN(APR_HDR_SIZE),
818 APR_PKT_VER);
819 cvs_set_amrwb_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
820 sizeof(cvs_set_amrwb_rate) -
821 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700822 cvs_set_amrwb_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 cvs_set_amrwb_rate.hdr.dest_port = cvs_handle;
824 cvs_set_amrwb_rate.hdr.token = 0;
825 cvs_set_amrwb_rate.hdr.opcode =
826 VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700827 cvs_set_amrwb_rate.amrwb_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828
829 v->cvs_state = CMD_STATUS_FAIL;
830
831 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amrwb_rate);
832 if (ret < 0) {
833 pr_err("%s: Error %d sending SET_AMRWB_RATE\n",
834 __func__, ret);
835 goto fail;
836 }
837 ret = wait_event_timeout(v->cvs_wait,
838 (v->cvs_state == CMD_STATUS_SUCCESS),
839 msecs_to_jiffies(TIMEOUT_MS));
840 if (!ret) {
841 pr_err("%s: wait_event timeout\n", __func__);
842 goto fail;
843 }
844 /* Disable DTX */
845 pr_debug("Disabling DTX\n");
846
847 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
848 APR_HDR_LEN(APR_HDR_SIZE),
849 APR_PKT_VER);
850 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
851 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700852 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853 cvs_set_dtx.hdr.dest_port = cvs_handle;
854 cvs_set_dtx.hdr.token = 0;
855 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
856 cvs_set_dtx.dtx_mode.enable = 0;
857
858 v->cvs_state = CMD_STATUS_FAIL;
859
860 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
861 if (ret < 0) {
862 pr_err("%s: Error %d sending SET_DTX\n",
863 __func__, ret);
864 goto fail;
865 }
866 ret = wait_event_timeout(v->cvs_wait,
867 (v->cvs_state == CMD_STATUS_SUCCESS),
868 msecs_to_jiffies(TIMEOUT_MS));
869 if (!ret) {
870 pr_err("%s: wait_event timeout\n", __func__);
871 goto fail;
872 }
873 break;
874 }
875 case VSS_MEDIA_ID_G729:
876 case VSS_MEDIA_ID_G711_ALAW:
877 case VSS_MEDIA_ID_G711_MULAW: {
878 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
879 /* Disable DTX */
880 pr_debug("Disabling DTX\n");
881
882 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
883 APR_HDR_LEN(APR_HDR_SIZE),
884 APR_PKT_VER);
885 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
886 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700887 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888 cvs_set_dtx.hdr.dest_port = cvs_handle;
889 cvs_set_dtx.hdr.token = 0;
890 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
891 cvs_set_dtx.dtx_mode.enable = 0;
892
893 v->cvs_state = CMD_STATUS_FAIL;
894
895 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
896 if (ret < 0) {
897 pr_err("%s: Error %d sending SET_DTX\n",
898 __func__, ret);
899 goto fail;
900 }
901 ret = wait_event_timeout(v->cvs_wait,
902 (v->cvs_state == CMD_STATUS_SUCCESS),
903 msecs_to_jiffies(TIMEOUT_MS));
904 if (!ret) {
905 pr_err("%s: wait_event timeout\n", __func__);
906 goto fail;
907 }
908 break;
909 }
910 default:
911 /* Do nothing. */
912 break;
913 }
914 return 0;
915
916fail:
917 return -EINVAL;
918}
919
920static int voice_send_start_voice_cmd(struct voice_data *v)
921{
922 struct apr_hdr mvm_start_voice_cmd;
923 int ret = 0;
924 void *apr_mvm;
925 u16 mvm_handle;
926
927 if (v == NULL) {
928 pr_err("%s: v is NULL\n", __func__);
929 return -EINVAL;
930 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700931 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932
933 if (!apr_mvm) {
934 pr_err("%s: apr_mvm is NULL.\n", __func__);
935 return -EINVAL;
936 }
937 mvm_handle = voice_get_mvm_handle(v);
938
939 mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
940 APR_HDR_LEN(APR_HDR_SIZE),
941 APR_PKT_VER);
942 mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
943 sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
944 pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
945 mvm_start_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700946 mvm_start_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700947 mvm_start_voice_cmd.dest_port = mvm_handle;
948 mvm_start_voice_cmd.token = 0;
949 mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
950
951 v->mvm_state = CMD_STATUS_FAIL;
952 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
953 if (ret < 0) {
954 pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
955 goto fail;
956 }
957 ret = wait_event_timeout(v->mvm_wait,
958 (v->mvm_state == CMD_STATUS_SUCCESS),
959 msecs_to_jiffies(TIMEOUT_MS));
960 if (!ret) {
961 pr_err("%s: wait_event timeout\n", __func__);
962 goto fail;
963 }
964 return 0;
965fail:
966 return -EINVAL;
967}
968
969static int voice_send_disable_vocproc_cmd(struct voice_data *v)
970{
971 struct apr_hdr cvp_disable_cmd;
972 int ret = 0;
973 void *apr_cvp;
974 u16 cvp_handle;
975
976 if (v == NULL) {
977 pr_err("%s: v is NULL\n", __func__);
978 return -EINVAL;
979 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700980 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700981
982 if (!apr_cvp) {
983 pr_err("%s: apr regist failed\n", __func__);
984 return -EINVAL;
985 }
986 cvp_handle = voice_get_cvp_handle(v);
987
988 /* disable vocproc and wait for respose */
989 cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
990 APR_HDR_LEN(APR_HDR_SIZE),
991 APR_PKT_VER);
992 cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
993 sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
994 pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
995 cvp_disable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700996 cvp_disable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997 cvp_disable_cmd.dest_port = cvp_handle;
998 cvp_disable_cmd.token = 0;
999 cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
1000
1001 v->cvp_state = CMD_STATUS_FAIL;
1002 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
1003 if (ret < 0) {
1004 pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
1005 goto fail;
1006 }
1007 ret = wait_event_timeout(v->cvp_wait,
1008 (v->cvp_state == CMD_STATUS_SUCCESS),
1009 msecs_to_jiffies(TIMEOUT_MS));
1010 if (!ret) {
1011 pr_err("%s: wait_event timeout\n", __func__);
1012 goto fail;
1013 }
1014
1015 return 0;
1016fail:
1017 return -EINVAL;
1018}
1019
1020static int voice_send_set_device_cmd(struct voice_data *v)
1021{
1022 struct cvp_set_device_cmd cvp_setdev_cmd;
1023 int ret = 0;
1024 void *apr_cvp;
1025 u16 cvp_handle;
1026
1027 if (v == NULL) {
1028 pr_err("%s: v is NULL\n", __func__);
1029 return -EINVAL;
1030 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001031 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032
1033 if (!apr_cvp) {
1034 pr_err("%s: apr_cvp is NULL.\n", __func__);
1035 return -EINVAL;
1036 }
1037 cvp_handle = voice_get_cvp_handle(v);
1038
1039 /* set device and wait for response */
1040 cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1041 APR_HDR_LEN(APR_HDR_SIZE),
1042 APR_PKT_VER);
1043 cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1044 sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
1045 pr_debug(" send create cvp setdev, pkt size = %d\n",
1046 cvp_setdev_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001047 cvp_setdev_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001048 cvp_setdev_cmd.hdr.dest_port = cvp_handle;
1049 cvp_setdev_cmd.hdr.token = 0;
1050 cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE;
1051
1052 /* Use default topology if invalid value in ACDB */
1053 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1054 get_voice_tx_topology();
1055 if (cvp_setdev_cmd.cvp_set_device.tx_topology_id == 0)
1056 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1057 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1058
1059 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1060 get_voice_rx_topology();
1061 if (cvp_setdev_cmd.cvp_set_device.rx_topology_id == 0)
1062 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1063 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1064 cvp_setdev_cmd.cvp_set_device.tx_port_id = v->dev_tx.port_id;
1065 cvp_setdev_cmd.cvp_set_device.rx_port_id = v->dev_rx.port_id;
1066 pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
1067 cvp_setdev_cmd.cvp_set_device.tx_topology_id,
1068 cvp_setdev_cmd.cvp_set_device.tx_port_id,
1069 cvp_setdev_cmd.cvp_set_device.rx_port_id);
1070
1071 v->cvp_state = CMD_STATUS_FAIL;
1072 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
1073 if (ret < 0) {
1074 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1075 goto fail;
1076 }
1077 pr_debug("wait for cvp create session event\n");
1078 ret = wait_event_timeout(v->cvp_wait,
1079 (v->cvp_state == CMD_STATUS_SUCCESS),
1080 msecs_to_jiffies(TIMEOUT_MS));
1081 if (!ret) {
1082 pr_err("%s: wait_event timeout\n", __func__);
1083 goto fail;
1084 }
1085
1086 return 0;
1087fail:
1088 return -EINVAL;
1089}
1090
1091static int voice_send_stop_voice_cmd(struct voice_data *v)
1092{
1093 struct apr_hdr mvm_stop_voice_cmd;
1094 int ret = 0;
1095 void *apr_mvm;
1096 u16 mvm_handle;
1097
1098 if (v == NULL) {
1099 pr_err("%s: v is NULL\n", __func__);
1100 return -EINVAL;
1101 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001102 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001103
1104 if (!apr_mvm) {
1105 pr_err("%s: apr_mvm is NULL.\n", __func__);
1106 return -EINVAL;
1107 }
1108 mvm_handle = voice_get_mvm_handle(v);
1109
1110 mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1111 APR_HDR_LEN(APR_HDR_SIZE),
1112 APR_PKT_VER);
1113 mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1114 sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
1115 pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
1116 mvm_stop_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001117 mvm_stop_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001118 mvm_stop_voice_cmd.dest_port = mvm_handle;
1119 mvm_stop_voice_cmd.token = 0;
1120 mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
1121
1122 v->mvm_state = CMD_STATUS_FAIL;
1123 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
1124 if (ret < 0) {
1125 pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
1126 goto fail;
1127 }
1128 ret = wait_event_timeout(v->mvm_wait,
1129 (v->mvm_state == CMD_STATUS_SUCCESS),
1130 msecs_to_jiffies(TIMEOUT_MS));
1131 if (!ret) {
1132 pr_err("%s: wait_event timeout\n", __func__);
1133 goto fail;
1134 }
1135
1136 return 0;
1137fail:
1138 return -EINVAL;
1139}
1140
Helen Zeng29eb7442011-06-20 11:06:29 -07001141static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
1142{
1143 struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
1144 struct acdb_cal_block cal_block;
1145 int ret = 0;
1146 void *apr_cvs;
1147 u16 cvs_handle;
1148
1149 /* get the cvs cal data */
1150 get_all_vocstrm_cal(&cal_block);
1151 if (cal_block.cal_size == 0)
1152 goto fail;
1153
1154 if (v == NULL) {
1155 pr_err("%s: v is NULL\n", __func__);
1156 return -EINVAL;
1157 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001158 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001159
1160 if (!apr_cvs) {
1161 pr_err("%s: apr_cvs is NULL.\n", __func__);
1162 return -EINVAL;
1163 }
1164 cvs_handle = voice_get_cvs_handle(v);
1165
1166 /* fill in the header */
1167 cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1168 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1169 cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1170 sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001171 cvs_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001172 cvs_reg_cal_cmd.hdr.dest_port = cvs_handle;
1173 cvs_reg_cal_cmd.hdr.token = 0;
1174 cvs_reg_cal_cmd.hdr.opcode = VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA;
1175
1176 cvs_reg_cal_cmd.cvs_cal_data.phys_addr = cal_block.cal_paddr;
1177 cvs_reg_cal_cmd.cvs_cal_data.mem_size = cal_block.cal_size;
1178
1179 v->cvs_state = CMD_STATUS_FAIL;
1180 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_reg_cal_cmd);
1181 if (ret < 0) {
1182 pr_err("Fail: sending cvs cal,\n");
1183 goto fail;
1184 }
1185 ret = wait_event_timeout(v->cvs_wait,
1186 (v->cvs_state == CMD_STATUS_SUCCESS),
1187 msecs_to_jiffies(TIMEOUT_MS));
1188 if (!ret) {
1189 pr_err("%s: wait_event timeout\n", __func__);
1190 goto fail;
1191 }
1192 return 0;
1193fail:
1194 return -EINVAL;
1195
1196}
1197
1198static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
1199{
1200 struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
1201 struct acdb_cal_block cal_block;
1202 int ret = 0;
1203 void *apr_cvs;
1204 u16 cvs_handle;
1205
1206 get_all_vocstrm_cal(&cal_block);
1207 if (cal_block.cal_size == 0)
1208 return 0;
1209
1210 if (v == NULL) {
1211 pr_err("%s: v is NULL\n", __func__);
1212 return -EINVAL;
1213 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001214 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001215
1216 if (!apr_cvs) {
1217 pr_err("%s: apr_cvs is NULL.\n", __func__);
1218 return -EINVAL;
1219 }
1220 cvs_handle = voice_get_cvs_handle(v);
1221
1222 /* fill in the header */
1223 cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1224 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1225 cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1226 sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001227 cvs_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001228 cvs_dereg_cal_cmd.hdr.dest_port = cvs_handle;
1229 cvs_dereg_cal_cmd.hdr.token = 0;
1230 cvs_dereg_cal_cmd.hdr.opcode =
1231 VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
1232
1233 v->cvs_state = CMD_STATUS_FAIL;
1234 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
1235 if (ret < 0) {
1236 pr_err("Fail: sending cvs cal,\n");
1237 goto fail;
1238 }
1239 ret = wait_event_timeout(v->cvs_wait,
1240 (v->cvs_state == CMD_STATUS_SUCCESS),
1241 msecs_to_jiffies(TIMEOUT_MS));
1242 if (!ret) {
1243 pr_err("%s: wait_event timeout\n", __func__);
1244 goto fail;
1245 }
1246 return 0;
1247fail:
1248 return -EINVAL;
1249
1250}
1251
1252static int voice_send_cvp_map_memory_cmd(struct voice_data *v)
1253{
1254 struct vss_map_memory_cmd cvp_map_mem_cmd;
1255 struct acdb_cal_block cal_block;
1256 int ret = 0;
1257 void *apr_cvp;
1258 u16 cvp_handle;
1259
1260 /* get all cvp cal data */
1261 get_all_cvp_cal(&cal_block);
1262 if (cal_block.cal_size == 0)
1263 goto fail;
1264
1265 if (v == NULL) {
1266 pr_err("%s: v is NULL\n", __func__);
1267 return -EINVAL;
1268 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001269 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001270
1271 if (!apr_cvp) {
1272 pr_err("%s: apr_cvp is NULL.\n", __func__);
1273 return -EINVAL;
1274 }
1275 cvp_handle = voice_get_cvp_handle(v);
1276
1277 /* fill in the header */
1278 cvp_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1279 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1280 cvp_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1281 sizeof(cvp_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001282 cvp_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001283 cvp_map_mem_cmd.hdr.dest_port = cvp_handle;
1284 cvp_map_mem_cmd.hdr.token = 0;
1285 cvp_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1286
1287 pr_debug("%s, phy_addr:%d, mem_size:%d\n", __func__,
1288 cal_block.cal_paddr, cal_block.cal_size);
1289 cvp_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1290 cvp_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1291 cvp_map_mem_cmd.vss_map_mem.mem_pool_id =
1292 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1293
1294 v->cvp_state = CMD_STATUS_FAIL;
1295 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_map_mem_cmd);
1296 if (ret < 0) {
1297 pr_err("Fail: sending cvp cal,\n");
1298 goto fail;
1299 }
1300 ret = wait_event_timeout(v->cvp_wait,
1301 (v->cvp_state == CMD_STATUS_SUCCESS),
1302 msecs_to_jiffies(TIMEOUT_MS));
1303 if (!ret) {
1304 pr_err("%s: wait_event timeout\n", __func__);
1305 goto fail;
1306 }
1307 return 0;
1308fail:
1309 return -EINVAL;
1310
1311}
1312
1313static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v)
1314{
1315 struct vss_unmap_memory_cmd cvp_unmap_mem_cmd;
1316 struct acdb_cal_block cal_block;
1317 int ret = 0;
1318 void *apr_cvp;
1319 u16 cvp_handle;
1320
1321 get_all_cvp_cal(&cal_block);
1322 if (cal_block.cal_size == 0)
1323 return 0;
1324
1325 if (v == NULL) {
1326 pr_err("%s: v is NULL\n", __func__);
1327 return -EINVAL;
1328 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001329 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001330
1331 if (!apr_cvp) {
1332 pr_err("%s: apr_cvp is NULL.\n", __func__);
1333 return -EINVAL;
1334 }
1335 cvp_handle = voice_get_cvp_handle(v);
1336
1337 /* fill in the header */
1338 cvp_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1339 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1340 cvp_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1341 sizeof(cvp_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001342 cvp_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001343 cvp_unmap_mem_cmd.hdr.dest_port = cvp_handle;
1344 cvp_unmap_mem_cmd.hdr.token = 0;
1345 cvp_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1346
1347 cvp_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1348
1349 v->cvp_state = CMD_STATUS_FAIL;
1350 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_unmap_mem_cmd);
1351 if (ret < 0) {
1352 pr_err("Fail: sending cvp cal,\n");
1353 goto fail;
1354 }
1355 ret = wait_event_timeout(v->cvp_wait,
1356 (v->cvp_state == CMD_STATUS_SUCCESS),
1357 msecs_to_jiffies(TIMEOUT_MS));
1358 if (!ret) {
1359 pr_err("%s: wait_event timeout\n", __func__);
1360 goto fail;
1361 }
1362 return 0;
1363fail:
1364 return -EINVAL;
1365
1366}
1367
1368static int voice_send_cvs_map_memory_cmd(struct voice_data *v)
1369{
1370 struct vss_map_memory_cmd cvs_map_mem_cmd;
1371 struct acdb_cal_block cal_block;
1372 int ret = 0;
1373 void *apr_cvs;
1374 u16 cvs_handle;
1375
1376 /* get all cvs cal data */
1377 get_all_vocstrm_cal(&cal_block);
1378 if (cal_block.cal_size == 0)
1379 goto fail;
1380
1381 if (v == NULL) {
1382 pr_err("%s: v is NULL\n", __func__);
1383 return -EINVAL;
1384 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001385 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001386
1387 if (!apr_cvs) {
1388 pr_err("%s: apr_cvs is NULL.\n", __func__);
1389 return -EINVAL;
1390 }
1391 cvs_handle = voice_get_cvs_handle(v);
1392
1393 /* fill in the header */
1394 cvs_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1395 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1396 cvs_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1397 sizeof(cvs_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001398 cvs_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001399 cvs_map_mem_cmd.hdr.dest_port = cvs_handle;
1400 cvs_map_mem_cmd.hdr.token = 0;
1401 cvs_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1402
1403 pr_debug("%s, phys_addr: %d, mem_size: %d\n", __func__,
1404 cal_block.cal_paddr, cal_block.cal_size);
1405 cvs_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1406 cvs_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1407 cvs_map_mem_cmd.vss_map_mem.mem_pool_id =
1408 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1409
1410 v->cvs_state = CMD_STATUS_FAIL;
1411 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_map_mem_cmd);
1412 if (ret < 0) {
1413 pr_err("Fail: sending cvs cal,\n");
1414 goto fail;
1415 }
1416 ret = wait_event_timeout(v->cvs_wait,
1417 (v->cvs_state == CMD_STATUS_SUCCESS),
1418 msecs_to_jiffies(TIMEOUT_MS));
1419 if (!ret) {
1420 pr_err("%s: wait_event timeout\n", __func__);
1421 goto fail;
1422 }
1423 return 0;
1424fail:
1425 return -EINVAL;
1426
1427}
1428
1429static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v)
1430{
1431 struct vss_unmap_memory_cmd cvs_unmap_mem_cmd;
1432 struct acdb_cal_block cal_block;
1433 int ret = 0;
1434 void *apr_cvs;
1435 u16 cvs_handle;
1436
1437 get_all_vocstrm_cal(&cal_block);
1438 if (cal_block.cal_size == 0)
1439 return 0;
1440
1441 if (v == NULL) {
1442 pr_err("%s: v is NULL\n", __func__);
1443 return -EINVAL;
1444 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001445 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001446
1447 if (!apr_cvs) {
1448 pr_err("%s: apr_cvs is NULL.\n", __func__);
1449 return -EINVAL;
1450 }
1451 cvs_handle = voice_get_cvs_handle(v);
1452
1453 /* fill in the header */
1454 cvs_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1455 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1456 cvs_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1457 sizeof(cvs_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001458 cvs_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001459 cvs_unmap_mem_cmd.hdr.dest_port = cvs_handle;
1460 cvs_unmap_mem_cmd.hdr.token = 0;
1461 cvs_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1462
1463 cvs_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1464
1465 v->cvs_state = CMD_STATUS_FAIL;
1466 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_unmap_mem_cmd);
1467 if (ret < 0) {
1468 pr_err("Fail: sending cvs cal,\n");
1469 goto fail;
1470 }
1471 ret = wait_event_timeout(v->cvs_wait,
1472 (v->cvs_state == CMD_STATUS_SUCCESS),
1473 msecs_to_jiffies(TIMEOUT_MS));
1474 if (!ret) {
1475 pr_err("%s: wait_event timeout\n", __func__);
1476 goto fail;
1477 }
1478 return 0;
1479fail:
1480 return -EINVAL;
1481
1482}
1483
1484static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
1485{
1486 struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
1487 struct acdb_cal_block cal_block;
1488 int ret = 0;
1489 void *apr_cvp;
1490 u16 cvp_handle;
1491
1492 /* get the cvp cal data */
1493 get_all_vocproc_cal(&cal_block);
1494 if (cal_block.cal_size == 0)
1495 goto fail;
1496
1497 if (v == NULL) {
1498 pr_err("%s: v is NULL\n", __func__);
1499 return -EINVAL;
1500 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001501 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001502
1503 if (!apr_cvp) {
1504 pr_err("%s: apr_cvp is NULL.\n", __func__);
1505 return -EINVAL;
1506 }
1507 cvp_handle = voice_get_cvp_handle(v);
1508
1509 /* fill in the header */
1510 cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1511 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1512 cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1513 sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001514 cvp_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001515 cvp_reg_cal_cmd.hdr.dest_port = cvp_handle;
1516 cvp_reg_cal_cmd.hdr.token = 0;
1517 cvp_reg_cal_cmd.hdr.opcode = VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA;
1518
1519 cvp_reg_cal_cmd.cvp_cal_data.phys_addr = cal_block.cal_paddr;
1520 cvp_reg_cal_cmd.cvp_cal_data.mem_size = cal_block.cal_size;
1521
1522 v->cvp_state = CMD_STATUS_FAIL;
1523 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_cmd);
1524 if (ret < 0) {
1525 pr_err("Fail: sending cvp cal,\n");
1526 goto fail;
1527 }
1528 ret = wait_event_timeout(v->cvp_wait,
1529 (v->cvp_state == CMD_STATUS_SUCCESS),
1530 msecs_to_jiffies(TIMEOUT_MS));
1531 if (!ret) {
1532 pr_err("%s: wait_event timeout\n", __func__);
1533 goto fail;
1534 }
1535 return 0;
1536fail:
1537 return -EINVAL;
1538
1539}
1540
1541static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
1542{
1543 struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
1544 struct acdb_cal_block cal_block;
1545 int ret = 0;
1546 void *apr_cvp;
1547 u16 cvp_handle;
1548
1549 get_all_vocproc_cal(&cal_block);
1550 if (cal_block.cal_size == 0)
1551 return 0;
1552
1553 if (v == NULL) {
1554 pr_err("%s: v is NULL\n", __func__);
1555 return -EINVAL;
1556 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001557 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001558
1559 if (!apr_cvp) {
1560 pr_err("%s: apr_cvp is NULL.\n", __func__);
1561 return -EINVAL;
1562 }
1563 cvp_handle = voice_get_cvp_handle(v);
1564
1565 /* fill in the header */
1566 cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1567 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1568 cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1569 sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001570 cvp_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001571 cvp_dereg_cal_cmd.hdr.dest_port = cvp_handle;
1572 cvp_dereg_cal_cmd.hdr.token = 0;
1573 cvp_dereg_cal_cmd.hdr.opcode =
1574 VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
1575
1576 v->cvp_state = CMD_STATUS_FAIL;
1577 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
1578 if (ret < 0) {
1579 pr_err("Fail: sending cvp cal,\n");
1580 goto fail;
1581 }
1582 ret = wait_event_timeout(v->cvp_wait,
1583 (v->cvp_state == CMD_STATUS_SUCCESS),
1584 msecs_to_jiffies(TIMEOUT_MS));
1585 if (!ret) {
1586 pr_err("%s: wait_event timeout\n", __func__);
1587 goto fail;
1588 }
1589 return 0;
1590fail:
1591 return -EINVAL;
1592
1593}
1594
1595static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v)
1596{
1597 struct cvp_register_vol_cal_table_cmd cvp_reg_cal_tbl_cmd;
1598 struct acdb_cal_block cal_block;
1599 int ret = 0;
1600 void *apr_cvp;
1601 u16 cvp_handle;
1602
1603 /* get the cvp vol cal data */
1604 get_all_vocvol_cal(&cal_block);
1605 if (cal_block.cal_size == 0)
1606 goto fail;
1607
1608 if (v == NULL) {
1609 pr_err("%s: v is NULL\n", __func__);
1610 return -EINVAL;
1611 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001612 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001613
1614 if (!apr_cvp) {
1615 pr_err("%s: apr_cvp is NULL.\n", __func__);
1616 return -EINVAL;
1617 }
1618 cvp_handle = voice_get_cvp_handle(v);
1619
1620 /* fill in the header */
1621 cvp_reg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1622 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1623 cvp_reg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1624 sizeof(cvp_reg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001625 cvp_reg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001626 cvp_reg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1627 cvp_reg_cal_tbl_cmd.hdr.token = 0;
1628 cvp_reg_cal_tbl_cmd.hdr.opcode =
1629 VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE;
1630
1631 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.phys_addr = cal_block.cal_paddr;
1632 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.mem_size = cal_block.cal_size;
1633
1634 v->cvp_state = CMD_STATUS_FAIL;
1635 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_tbl_cmd);
1636 if (ret < 0) {
1637 pr_err("Fail: sending cvp cal table,\n");
1638 goto fail;
1639 }
1640 ret = wait_event_timeout(v->cvp_wait,
1641 (v->cvp_state == CMD_STATUS_SUCCESS),
1642 msecs_to_jiffies(TIMEOUT_MS));
1643 if (!ret) {
1644 pr_err("%s: wait_event timeout\n", __func__);
1645 goto fail;
1646 }
1647 return 0;
1648fail:
1649 return -EINVAL;
1650
1651}
1652
1653static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v)
1654{
1655 struct cvp_deregister_vol_cal_table_cmd cvp_dereg_cal_tbl_cmd;
1656 struct acdb_cal_block cal_block;
1657 int ret = 0;
1658 void *apr_cvp;
1659 u16 cvp_handle;
1660
1661 get_all_vocvol_cal(&cal_block);
1662 if (cal_block.cal_size == 0)
1663 return 0;
1664
1665 if (v == NULL) {
1666 pr_err("%s: v is NULL\n", __func__);
1667 return -EINVAL;
1668 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001669 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001670
1671 if (!apr_cvp) {
1672 pr_err("%s: apr_cvp is NULL.\n", __func__);
1673 return -EINVAL;
1674 }
1675 cvp_handle = voice_get_cvp_handle(v);
1676
1677 /* fill in the header */
1678 cvp_dereg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(
1679 APR_MSG_TYPE_SEQ_CMD,
1680 APR_HDR_LEN(APR_HDR_SIZE),
1681 APR_PKT_VER);
1682 cvp_dereg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1683 sizeof(cvp_dereg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001684 cvp_dereg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001685 cvp_dereg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1686 cvp_dereg_cal_tbl_cmd.hdr.token = 0;
1687 cvp_dereg_cal_tbl_cmd.hdr.opcode =
1688 VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE;
1689
1690 v->cvp_state = CMD_STATUS_FAIL;
1691 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_tbl_cmd);
1692 if (ret < 0) {
1693 pr_err("Fail: sending cvp cal table,\n");
1694 goto fail;
1695 }
1696 ret = wait_event_timeout(v->cvp_wait,
1697 (v->cvp_state == CMD_STATUS_SUCCESS),
1698 msecs_to_jiffies(TIMEOUT_MS));
1699 if (!ret) {
1700 pr_err("%s: wait_event timeout\n", __func__);
1701 goto fail;
1702 }
1703 return 0;
1704fail:
1705 return -EINVAL;
1706
1707}
Neema Shetty2c07eb52011-08-21 20:33:52 -07001708
Helen Zeng44d4d272011-08-10 14:49:20 -07001709static int voice_send_set_widevoice_enable_cmd(struct voice_data *v)
1710{
1711 struct mvm_set_widevoice_enable_cmd mvm_set_wv_cmd;
1712 int ret = 0;
1713 void *apr_mvm;
1714 u16 mvm_handle;
1715
1716 if (v == NULL) {
1717 pr_err("%s: v is NULL\n", __func__);
1718 return -EINVAL;
1719 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001720 apr_mvm = common.apr_q6_mvm;
Helen Zeng44d4d272011-08-10 14:49:20 -07001721
1722 if (!apr_mvm) {
1723 pr_err("%s: apr_mvm is NULL.\n", __func__);
1724 return -EINVAL;
1725 }
1726 mvm_handle = voice_get_mvm_handle(v);
1727
1728 /* fill in the header */
1729 mvm_set_wv_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1730 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1731 mvm_set_wv_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1732 sizeof(mvm_set_wv_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001733 mvm_set_wv_cmd.hdr.src_port = v->session_id;
Helen Zeng44d4d272011-08-10 14:49:20 -07001734 mvm_set_wv_cmd.hdr.dest_port = mvm_handle;
1735 mvm_set_wv_cmd.hdr.token = 0;
1736 mvm_set_wv_cmd.hdr.opcode = VSS_IWIDEVOICE_CMD_SET_WIDEVOICE;
1737
1738 mvm_set_wv_cmd.vss_set_wv.enable = v->wv_enable;
1739
1740 v->mvm_state = CMD_STATUS_FAIL;
1741 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_wv_cmd);
1742 if (ret < 0) {
1743 pr_err("Fail: sending mvm set widevoice enable,\n");
1744 goto fail;
1745 }
1746 ret = wait_event_timeout(v->mvm_wait,
1747 (v->mvm_state == CMD_STATUS_SUCCESS),
1748 msecs_to_jiffies(TIMEOUT_MS));
1749 if (!ret) {
1750 pr_err("%s: wait_event timeout\n", __func__);
1751 goto fail;
1752 }
1753 return 0;
1754fail:
1755 return -EINVAL;
1756}
1757
Helen Zengbb49c702011-09-06 14:09:13 -07001758static int voice_send_set_slowtalk_enable_cmd(struct voice_data *v)
1759{
1760 struct cvs_set_slowtalk_enable_cmd cvs_set_st_cmd;
1761 int ret = 0;
1762 void *apr_cvs;
1763 u16 cvs_handle;
1764
1765 if (v == NULL) {
1766 pr_err("%s: v is NULL\n", __func__);
1767 return -EINVAL;
1768 }
1769 apr_cvs = common.apr_q6_cvs;
1770
1771 if (!apr_cvs) {
1772 pr_err("%s: apr_cvs is NULL.\n", __func__);
1773 return -EINVAL;
1774 }
1775 cvs_handle = voice_get_cvs_handle(v);
1776
1777 /* fill in the header */
1778 cvs_set_st_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1779 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1780 cvs_set_st_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1781 sizeof(cvs_set_st_cmd) - APR_HDR_SIZE);
1782 cvs_set_st_cmd.hdr.src_port = v->session_id;
1783 cvs_set_st_cmd.hdr.dest_port = cvs_handle;
1784 cvs_set_st_cmd.hdr.token = 0;
1785 cvs_set_st_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
1786
1787 cvs_set_st_cmd.vss_set_st.module_id = MODULE_ID_VOICE_MODULE_ST;
1788 cvs_set_st_cmd.vss_set_st.param_id = VOICE_PARAM_MOD_ENABLE;
1789 cvs_set_st_cmd.vss_set_st.param_size = MOD_ENABLE_PARAM_LEN;
1790 cvs_set_st_cmd.vss_set_st.reserved = 0;
1791 cvs_set_st_cmd.vss_set_st.enable = v->st_enable;
1792 cvs_set_st_cmd.vss_set_st.reserved_field = 0;
1793
1794 v->cvs_state = CMD_STATUS_FAIL;
1795 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_st_cmd);
1796 if (ret < 0) {
1797 pr_err("Fail: sending cvs set slowtalk enable,\n");
1798 goto fail;
1799 }
1800 ret = wait_event_timeout(v->cvs_wait,
1801 (v->cvs_state == CMD_STATUS_SUCCESS),
1802 msecs_to_jiffies(TIMEOUT_MS));
1803 if (!ret) {
1804 pr_err("%s: wait_event timeout\n", __func__);
1805 goto fail;
1806 }
1807 return 0;
1808fail:
1809 return -EINVAL;
1810}
1811
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001812static int voice_setup_vocproc(struct voice_data *v)
1813{
1814 struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
1815 int ret = 0;
1816 void *apr_cvp;
1817 if (v == NULL) {
1818 pr_err("%s: v is NULL\n", __func__);
1819 return -EINVAL;
1820 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001821 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001822
1823 if (!apr_cvp) {
1824 pr_err("%s: apr_cvp is NULL.\n", __func__);
1825 return -EINVAL;
1826 }
1827
1828 /* create cvp session and wait for response */
1829 cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1830 APR_HDR_LEN(APR_HDR_SIZE),
1831 APR_PKT_VER);
1832 cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1833 sizeof(cvp_session_cmd) - APR_HDR_SIZE);
1834 pr_debug(" send create cvp session, pkt size = %d\n",
1835 cvp_session_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001836 cvp_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001837 cvp_session_cmd.hdr.dest_port = 0;
1838 cvp_session_cmd.hdr.token = 0;
1839 cvp_session_cmd.hdr.opcode =
1840 VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION;
1841
1842 /* Use default topology if invalid value in ACDB */
1843 cvp_session_cmd.cvp_session.tx_topology_id =
1844 get_voice_tx_topology();
1845 if (cvp_session_cmd.cvp_session.tx_topology_id == 0)
1846 cvp_session_cmd.cvp_session.tx_topology_id =
1847 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1848
1849 cvp_session_cmd.cvp_session.rx_topology_id =
1850 get_voice_rx_topology();
1851 if (cvp_session_cmd.cvp_session.rx_topology_id == 0)
1852 cvp_session_cmd.cvp_session.rx_topology_id =
1853 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1854
1855 cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
1856 cvp_session_cmd.cvp_session.network_id = VSS_NETWORK_ID_DEFAULT;
1857 cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
1858 cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
1859
1860 pr_debug("topology=%d net_id=%d, dir=%d tx_port_id=%d, rx_port_id=%d\n",
1861 cvp_session_cmd.cvp_session.tx_topology_id,
1862 cvp_session_cmd.cvp_session.network_id,
1863 cvp_session_cmd.cvp_session.direction,
1864 cvp_session_cmd.cvp_session.tx_port_id,
1865 cvp_session_cmd.cvp_session.rx_port_id);
1866
1867 v->cvp_state = CMD_STATUS_FAIL;
1868 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
1869 if (ret < 0) {
1870 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1871 goto fail;
1872 }
1873 ret = wait_event_timeout(v->cvp_wait,
1874 (v->cvp_state == CMD_STATUS_SUCCESS),
1875 msecs_to_jiffies(TIMEOUT_MS));
1876 if (!ret) {
1877 pr_err("%s: wait_event timeout\n", __func__);
1878 goto fail;
1879 }
1880
Helen Zeng29eb7442011-06-20 11:06:29 -07001881 /* send cvs cal */
1882 ret = voice_send_cvs_map_memory_cmd(v);
1883 if (!ret)
1884 voice_send_cvs_register_cal_cmd(v);
1885
1886 /* send cvp and vol cal */
1887 ret = voice_send_cvp_map_memory_cmd(v);
1888 if (!ret) {
1889 voice_send_cvp_register_cal_cmd(v);
1890 voice_send_cvp_register_vol_cal_table_cmd(v);
1891 }
1892
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001893 /* enable vocproc */
1894 ret = voice_send_enable_vocproc_cmd(v);
1895 if (ret < 0)
1896 goto fail;
1897
1898 /* attach vocproc */
1899 ret = voice_send_attach_vocproc_cmd(v);
1900 if (ret < 0)
1901 goto fail;
1902
1903 /* send tty mode if tty device is used */
1904 voice_send_tty_mode_cmd(v);
1905
Helen Zeng44d4d272011-08-10 14:49:20 -07001906 /* enable widevoice if wv_enable is set */
1907 if (v->wv_enable)
1908 voice_send_set_widevoice_enable_cmd(v);
1909
Helen Zengbb49c702011-09-06 14:09:13 -07001910 /* enable slowtalk if st_enable is set */
1911 if (v->st_enable)
1912 voice_send_set_slowtalk_enable_cmd(v);
1913
Neema Shetty2c07eb52011-08-21 20:33:52 -07001914 if (is_voip_session(v->session_id))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001915 voice_send_netid_timing_cmd(v);
1916
Ben Romberger13b74ab2011-07-18 17:36:32 -07001917 rtac_add_voice(voice_get_cvs_handle(v),
1918 voice_get_cvp_handle(v),
Ben Rombergerc5d6a372011-09-22 18:01:49 -07001919 v->dev_rx.port_id, v->dev_tx.port_id,
1920 v->session_id);
Ben Romberger13b74ab2011-07-18 17:36:32 -07001921
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001922 return 0;
1923
1924fail:
1925 return -EINVAL;
1926}
1927
1928static int voice_send_enable_vocproc_cmd(struct voice_data *v)
1929{
1930 int ret = 0;
1931 struct apr_hdr cvp_enable_cmd;
1932 void *apr_cvp;
1933 u16 cvp_handle;
1934
1935 if (v == NULL) {
1936 pr_err("%s: v is NULL\n", __func__);
1937 return -EINVAL;
1938 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001939 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001940
1941 if (!apr_cvp) {
1942 pr_err("%s: apr_cvp is NULL.\n", __func__);
1943 return -EINVAL;
1944 }
1945 cvp_handle = voice_get_cvp_handle(v);
1946
1947 /* enable vocproc and wait for respose */
1948 cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1949 APR_HDR_LEN(APR_HDR_SIZE),
1950 APR_PKT_VER);
1951 cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1952 sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
1953 pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
1954 cvp_enable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001955 cvp_enable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001956 cvp_enable_cmd.dest_port = cvp_handle;
1957 cvp_enable_cmd.token = 0;
1958 cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
1959
1960 v->cvp_state = CMD_STATUS_FAIL;
1961 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
1962 if (ret < 0) {
1963 pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
1964 goto fail;
1965 }
1966 ret = wait_event_timeout(v->cvp_wait,
1967 (v->cvp_state == CMD_STATUS_SUCCESS),
1968 msecs_to_jiffies(TIMEOUT_MS));
1969 if (!ret) {
1970 pr_err("%s: wait_event timeout\n", __func__);
1971 goto fail;
1972 }
1973
1974 return 0;
1975fail:
1976 return -EINVAL;
1977}
1978
1979static int voice_send_netid_timing_cmd(struct voice_data *v)
1980{
1981 int ret = 0;
1982 void *apr_mvm;
1983 u16 mvm_handle;
1984 struct mvm_set_network_cmd mvm_set_network;
1985 struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
1986
1987 if (v == NULL) {
1988 pr_err("%s: v is NULL\n", __func__);
1989 return -EINVAL;
1990 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001991 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992
1993 if (!apr_mvm) {
1994 pr_err("%s: apr_mvm is NULL.\n", __func__);
1995 return -EINVAL;
1996 }
1997 mvm_handle = voice_get_mvm_handle(v);
1998
1999 ret = voice_config_cvs_vocoder(v);
2000 if (ret < 0) {
2001 pr_err("%s: Error %d configuring CVS voc",
2002 __func__, ret);
2003 goto fail;
2004 }
2005 /* Set network ID. */
2006 pr_debug("Setting network ID\n");
2007
2008 mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2009 APR_HDR_LEN(APR_HDR_SIZE),
2010 APR_PKT_VER);
2011 mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2012 sizeof(mvm_set_network) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002013 mvm_set_network.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002014 mvm_set_network.hdr.dest_port = mvm_handle;
2015 mvm_set_network.hdr.token = 0;
2016 mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
Neema Shetty2c07eb52011-08-21 20:33:52 -07002017 mvm_set_network.network.network_id = common.mvs_info.network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002018
2019 v->mvm_state = CMD_STATUS_FAIL;
2020 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
2021 if (ret < 0) {
2022 pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
2023 goto fail;
2024 }
2025
2026 ret = wait_event_timeout(v->mvm_wait,
2027 (v->mvm_state == CMD_STATUS_SUCCESS),
2028 msecs_to_jiffies(TIMEOUT_MS));
2029 if (!ret) {
2030 pr_err("%s: wait_event timeout\n", __func__);
2031 goto fail;
2032 }
2033
2034 /* Set voice timing. */
2035 pr_debug("Setting voice timing\n");
2036
2037 mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2038 APR_HDR_LEN(APR_HDR_SIZE),
2039 APR_PKT_VER);
2040 mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2041 sizeof(mvm_set_voice_timing) -
2042 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002043 mvm_set_voice_timing.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002044 mvm_set_voice_timing.hdr.dest_port = mvm_handle;
2045 mvm_set_voice_timing.hdr.token = 0;
2046 mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
2047 mvm_set_voice_timing.timing.mode = 0;
2048 mvm_set_voice_timing.timing.enc_offset = 8000;
2049 mvm_set_voice_timing.timing.dec_req_offset = 3300;
2050 mvm_set_voice_timing.timing.dec_offset = 8300;
2051
2052 v->mvm_state = CMD_STATUS_FAIL;
2053
2054 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
2055 if (ret < 0) {
2056 pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
2057 goto fail;
2058 }
2059
2060 ret = wait_event_timeout(v->mvm_wait,
2061 (v->mvm_state == CMD_STATUS_SUCCESS),
2062 msecs_to_jiffies(TIMEOUT_MS));
2063 if (!ret) {
2064 pr_err("%s: wait_event timeout\n", __func__);
2065 goto fail;
2066 }
2067
2068 return 0;
2069fail:
2070 return -EINVAL;
2071}
2072
2073static int voice_send_attach_vocproc_cmd(struct voice_data *v)
2074{
2075 int ret = 0;
2076 struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
2077 void *apr_mvm;
2078 u16 mvm_handle, cvp_handle;
2079
2080 if (v == NULL) {
2081 pr_err("%s: v is NULL\n", __func__);
2082 return -EINVAL;
2083 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002084 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002085
2086 if (!apr_mvm) {
2087 pr_err("%s: apr_mvm is NULL.\n", __func__);
2088 return -EINVAL;
2089 }
2090 mvm_handle = voice_get_mvm_handle(v);
2091 cvp_handle = voice_get_cvp_handle(v);
2092
2093 /* attach vocproc and wait for response */
2094 mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2095 APR_HDR_LEN(APR_HDR_SIZE),
2096 APR_PKT_VER);
2097 mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2098 sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
2099 pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
2100 mvm_a_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002101 mvm_a_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002102 mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
2103 mvm_a_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002104 mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002105 mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
2106
2107 v->mvm_state = CMD_STATUS_FAIL;
2108 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
2109 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002110 pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002111 goto fail;
2112 }
2113 ret = wait_event_timeout(v->mvm_wait,
2114 (v->mvm_state == CMD_STATUS_SUCCESS),
2115 msecs_to_jiffies(TIMEOUT_MS));
2116 if (!ret) {
2117 pr_err("%s: wait_event timeout\n", __func__);
2118 goto fail;
2119 }
2120
2121 return 0;
2122fail:
2123 return -EINVAL;
2124}
2125
2126static int voice_destroy_vocproc(struct voice_data *v)
2127{
2128 struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
2129 struct apr_hdr cvp_destroy_session_cmd;
2130 int ret = 0;
2131 void *apr_mvm, *apr_cvp;
2132 u16 mvm_handle, cvp_handle;
2133
2134 if (v == NULL) {
2135 pr_err("%s: v is NULL\n", __func__);
2136 return -EINVAL;
2137 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002138 apr_mvm = common.apr_q6_mvm;
2139 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002140
2141 if (!apr_mvm || !apr_cvp) {
2142 pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
2143 return -EINVAL;
2144 }
2145 mvm_handle = voice_get_mvm_handle(v);
2146 cvp_handle = voice_get_cvp_handle(v);
2147
2148 /* send stop voice cmd */
2149 voice_send_stop_voice_cmd(v);
2150
2151 /* detach VOCPROC and wait for response from mvm */
2152 mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2153 APR_HDR_LEN(APR_HDR_SIZE),
2154 APR_PKT_VER);
2155 mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2156 sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
2157 pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
2158 mvm_d_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002159 mvm_d_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002160 mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
2161 mvm_d_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002162 mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002163 mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
2164
2165 v->mvm_state = CMD_STATUS_FAIL;
2166 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
2167 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002168 pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002169 goto fail;
2170 }
2171 ret = wait_event_timeout(v->mvm_wait,
2172 (v->mvm_state == CMD_STATUS_SUCCESS),
2173 msecs_to_jiffies(TIMEOUT_MS));
2174 if (!ret) {
2175 pr_err("%s: wait_event timeout\n", __func__);
2176 goto fail;
2177 }
2178
Helen Zeng29eb7442011-06-20 11:06:29 -07002179 /* deregister cvp and vol cal */
2180 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2181 voice_send_cvp_deregister_cal_cmd(v);
2182 voice_send_cvp_unmap_memory_cmd(v);
2183
2184 /* deregister cvs cal */
2185 voice_send_cvs_deregister_cal_cmd(v);
2186 voice_send_cvs_unmap_memory_cmd(v);
2187
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002188 /* destrop cvp session */
2189 cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2190 APR_HDR_LEN(APR_HDR_SIZE),
2191 APR_PKT_VER);
2192 cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2193 sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
2194 pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
2195 cvp_destroy_session_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002196 cvp_destroy_session_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002197 cvp_destroy_session_cmd.dest_port = cvp_handle;
2198 cvp_destroy_session_cmd.token = 0;
2199 cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
2200
2201 v->cvp_state = CMD_STATUS_FAIL;
2202 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
2203 if (ret < 0) {
2204 pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
2205 goto fail;
2206 }
2207 ret = wait_event_timeout(v->cvp_wait,
2208 (v->cvp_state == CMD_STATUS_SUCCESS),
2209 msecs_to_jiffies(TIMEOUT_MS));
2210 if (!ret) {
2211 pr_err("%s: wait_event timeout\n", __func__);
2212 goto fail;
2213 }
2214
Ben Romberger13b74ab2011-07-18 17:36:32 -07002215 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002216 cvp_handle = 0;
2217 voice_set_cvp_handle(v, cvp_handle);
2218
2219 return 0;
2220
2221fail:
2222 return -EINVAL;
2223}
2224
2225static int voice_send_mute_cmd(struct voice_data *v)
2226{
2227 struct cvs_set_mute_cmd cvs_mute_cmd;
2228 int ret = 0;
2229 void *apr_cvs;
2230 u16 cvs_handle;
2231
2232 if (v == NULL) {
2233 pr_err("%s: v is NULL\n", __func__);
2234 return -EINVAL;
2235 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002236 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002237
2238 if (!apr_cvs) {
2239 pr_err("%s: apr_cvs is NULL.\n", __func__);
2240 return -EINVAL;
2241 }
2242 cvs_handle = voice_get_cvs_handle(v);
2243
2244 /* send mute/unmute to cvs */
2245 cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2246 APR_HDR_LEN(APR_HDR_SIZE),
2247 APR_PKT_VER);
2248 cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2249 sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002250 cvs_mute_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002251 cvs_mute_cmd.hdr.dest_port = cvs_handle;
2252 cvs_mute_cmd.hdr.token = 0;
2253 cvs_mute_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MUTE;
2254 cvs_mute_cmd.cvs_set_mute.direction = 0; /*tx*/
2255 cvs_mute_cmd.cvs_set_mute.mute_flag = v->dev_tx.mute;
2256
2257 pr_info(" mute value =%d\n", cvs_mute_cmd.cvs_set_mute.mute_flag);
2258 v->cvs_state = CMD_STATUS_FAIL;
2259 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_mute_cmd);
2260 if (ret < 0) {
2261 pr_err("Fail: send STREAM SET MUTE\n");
2262 goto fail;
2263 }
2264 ret = wait_event_timeout(v->cvs_wait,
2265 (v->cvs_state == CMD_STATUS_SUCCESS),
2266 msecs_to_jiffies(TIMEOUT_MS));
2267 if (!ret)
2268 pr_err("%s: wait_event timeout\n", __func__);
2269
2270 return 0;
2271fail:
2272 return -EINVAL;
2273}
2274
2275static int voice_send_vol_index_cmd(struct voice_data *v)
2276{
2277 struct cvp_set_rx_volume_index_cmd cvp_vol_cmd;
2278 int ret = 0;
2279 void *apr_cvp;
2280 u16 cvp_handle;
2281 if (v == NULL) {
2282 pr_err("%s: v is NULL\n", __func__);
2283 return -EINVAL;
2284 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002285 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002286
2287 if (!apr_cvp) {
2288 pr_err("%s: apr_cvp is NULL.\n", __func__);
2289 return -EINVAL;
2290 }
2291 cvp_handle = voice_get_cvp_handle(v);
2292
2293 /* send volume index to cvp */
2294 cvp_vol_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2295 APR_HDR_LEN(APR_HDR_SIZE),
2296 APR_PKT_VER);
2297 cvp_vol_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2298 sizeof(cvp_vol_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002299 cvp_vol_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002300 cvp_vol_cmd.hdr.dest_port = cvp_handle;
2301 cvp_vol_cmd.hdr.token = 0;
2302 cvp_vol_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX;
2303 cvp_vol_cmd.cvp_set_vol_idx.vol_index = v->dev_rx.volume;
2304 v->cvp_state = CMD_STATUS_FAIL;
2305 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_cmd);
2306 if (ret < 0) {
2307 pr_err("Fail in sending RX VOL INDEX\n");
2308 return -EINVAL;
2309 }
2310 ret = wait_event_timeout(v->cvp_wait,
2311 (v->cvp_state == CMD_STATUS_SUCCESS),
2312 msecs_to_jiffies(TIMEOUT_MS));
2313 if (!ret) {
2314 pr_err("%s: wait_event timeout\n", __func__);
2315 return -EINVAL;
2316 }
2317 return 0;
2318}
2319
Neema Shetty2c07eb52011-08-21 20:33:52 -07002320int voc_disable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002321{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002322 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002323 int ret = 0;
2324
Neema Shetty2c07eb52011-08-21 20:33:52 -07002325 if (v == NULL) {
2326 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2327
2328 return -EINVAL;
2329 }
2330
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002331 mutex_lock(&v->lock);
2332
2333 if (v->voc_state == VOC_RUN) {
2334 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0);
Ben Romberger13b74ab2011-07-18 17:36:32 -07002335
2336 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002337 /* send cmd to dsp to disable vocproc */
2338 ret = voice_send_disable_vocproc_cmd(v);
2339 if (ret < 0) {
2340 pr_err("%s: disable vocproc failed\n", __func__);
2341 goto fail;
2342 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002343
2344 /* deregister cvp and vol cal */
2345 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2346 voice_send_cvp_deregister_cal_cmd(v);
2347 voice_send_cvp_unmap_memory_cmd(v);
2348
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002349 v->voc_state = VOC_CHANGE;
2350 }
2351
2352fail: mutex_unlock(&v->lock);
2353
2354 return ret;
2355}
2356
Neema Shetty2c07eb52011-08-21 20:33:52 -07002357int voc_enable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002358{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002359 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002360 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002361 int ret = 0;
2362
Neema Shetty2c07eb52011-08-21 20:33:52 -07002363 if (v == NULL) {
2364 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2365
2366 return -EINVAL;
2367 }
2368
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002369 mutex_lock(&v->lock);
2370
2371 if (v->voc_state == VOC_CHANGE) {
2372 ret = voice_send_set_device_cmd(v);
2373 if (ret < 0) {
2374 pr_err("%s: set device failed\n", __func__);
2375 goto fail;
2376 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002377 /* send cvp and vol cal */
2378 ret = voice_send_cvp_map_memory_cmd(v);
2379 if (!ret) {
2380 voice_send_cvp_register_cal_cmd(v);
2381 voice_send_cvp_register_vol_cal_table_cmd(v);
2382 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002383 ret = voice_send_enable_vocproc_cmd(v);
2384 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002385 pr_err("%s: enable vocproc failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002386 goto fail;
Helen Zengcc65b5b2011-07-06 19:14:48 -07002387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002388 }
Helen Zengcc65b5b2011-07-06 19:14:48 -07002389 /* send tty mode if tty device is used */
2390 voice_send_tty_mode_cmd(v);
2391
Helen Zeng44d4d272011-08-10 14:49:20 -07002392 /* enable widevoice if wv_enable is set */
2393 if (v->wv_enable)
2394 voice_send_set_widevoice_enable_cmd(v);
2395
Helen Zengbb49c702011-09-06 14:09:13 -07002396 /* enable slowtalk */
2397 if (v->st_enable)
2398 voice_send_set_slowtalk_enable_cmd(v);
2399
Helen Zengbd58e2c2011-07-01 16:24:31 -07002400 get_sidetone_cal(&sidetone_cal_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002401 ret = afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
Helen Zengbd58e2c2011-07-01 16:24:31 -07002402 sidetone_cal_data.enable,
2403 sidetone_cal_data.gain);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002404
2405 if (ret < 0)
Neema Shetty2c07eb52011-08-21 20:33:52 -07002406 pr_err("%s: AFE command sidetone failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002407
Ben Romberger13b74ab2011-07-18 17:36:32 -07002408 rtac_add_voice(voice_get_cvs_handle(v),
2409 voice_get_cvp_handle(v),
Ben Rombergerc5d6a372011-09-22 18:01:49 -07002410 v->dev_rx.port_id, v->dev_tx.port_id,
2411 v->session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002412 v->voc_state = VOC_RUN;
2413 }
2414
2415fail:
2416 mutex_unlock(&v->lock);
2417
2418 return ret;
2419}
2420
Neema Shetty2c07eb52011-08-21 20:33:52 -07002421int voc_set_tx_mute(uint16_t session_id, uint32_t dir, uint32_t mute)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002422{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002423 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002424 int ret = 0;
2425
Neema Shetty2c07eb52011-08-21 20:33:52 -07002426 if (v == NULL) {
2427 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2428
2429 return -EINVAL;
2430 }
2431
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002432 mutex_lock(&v->lock);
2433
2434 v->dev_tx.mute = mute;
2435
2436 if (v->voc_state == VOC_RUN)
2437 ret = voice_send_mute_cmd(v);
2438
2439 mutex_unlock(&v->lock);
2440
2441 return ret;
2442}
2443
Neema Shetty2c07eb52011-08-21 20:33:52 -07002444int voc_set_tty_mode(uint16_t session_id, uint8_t tty_mode)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002445{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002446 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002447 int ret = 0;
2448
Neema Shetty2c07eb52011-08-21 20:33:52 -07002449 if (v == NULL) {
2450 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2451
2452 return -EINVAL;
2453 }
2454
Helen Zengcc65b5b2011-07-06 19:14:48 -07002455 mutex_lock(&v->lock);
2456
2457 v->tty_mode = tty_mode;
2458
2459 mutex_unlock(&v->lock);
2460
2461 return ret;
2462}
2463
Neema Shetty2c07eb52011-08-21 20:33:52 -07002464uint8_t voc_get_tty_mode(uint16_t session_id)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002465{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002466 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002467 int ret = 0;
2468
Neema Shetty2c07eb52011-08-21 20:33:52 -07002469 if (v == NULL) {
2470 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2471
2472 return -EINVAL;
2473 }
2474
Helen Zengcc65b5b2011-07-06 19:14:48 -07002475 mutex_lock(&v->lock);
2476
2477 ret = v->tty_mode;
2478
2479 mutex_unlock(&v->lock);
2480
2481 return ret;
2482}
2483
Neema Shetty2c07eb52011-08-21 20:33:52 -07002484int voc_set_widevoice_enable(uint16_t session_id, uint32_t wv_enable)
Helen Zeng44d4d272011-08-10 14:49:20 -07002485{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002486 struct voice_data *v = voice_get_session(session_id);
Helen Zeng44d4d272011-08-10 14:49:20 -07002487 int ret = 0;
2488
Neema Shetty2c07eb52011-08-21 20:33:52 -07002489 if (v == NULL) {
2490 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2491
2492 return -EINVAL;
2493 }
2494
Helen Zeng44d4d272011-08-10 14:49:20 -07002495 mutex_lock(&v->lock);
2496
2497 v->wv_enable = wv_enable;
2498
2499 mutex_unlock(&v->lock);
2500
2501 return ret;
2502}
2503
Neema Shetty2c07eb52011-08-21 20:33:52 -07002504uint32_t voc_get_widevoice_enable(uint16_t session_id)
Helen Zeng44d4d272011-08-10 14:49:20 -07002505{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002506 struct voice_data *v = voice_get_session(session_id);
Helen Zeng44d4d272011-08-10 14:49:20 -07002507 int ret = 0;
2508
Neema Shetty2c07eb52011-08-21 20:33:52 -07002509 if (v == NULL) {
2510 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2511
2512 return -EINVAL;
2513 }
2514
Helen Zeng44d4d272011-08-10 14:49:20 -07002515 mutex_lock(&v->lock);
2516
2517 ret = v->wv_enable;
2518
2519 mutex_unlock(&v->lock);
2520
2521 return ret;
2522}
2523
Helen Zengbb49c702011-09-06 14:09:13 -07002524int voc_set_slowtalk_enable(uint16_t session_id, uint32_t st_enable)
2525{
2526 struct voice_data *v = voice_get_session(session_id);
2527 int ret = 0;
2528
2529 if (v == NULL) {
2530 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2531
2532 return -EINVAL;
2533 }
2534
2535 mutex_lock(&v->lock);
2536
2537 v->st_enable = st_enable;
2538
2539 if (v->voc_state == VOC_RUN)
2540 ret = voice_send_set_slowtalk_enable_cmd(v);
2541
2542 mutex_unlock(&v->lock);
2543
2544 return ret;
2545}
2546
2547uint32_t voc_get_slowtalk_enable(uint16_t session_id)
2548{
2549 struct voice_data *v = voice_get_session(session_id);
2550 int ret = 0;
2551
2552 if (v == NULL) {
2553 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2554
2555 return -EINVAL;
2556 }
2557
2558 mutex_lock(&v->lock);
2559
2560 ret = v->st_enable;
2561
2562 mutex_unlock(&v->lock);
2563
2564 return ret;
2565}
2566
Neema Shetty2c07eb52011-08-21 20:33:52 -07002567int voc_set_rx_vol_index(uint16_t session_id, uint32_t dir, uint32_t vol_idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002568{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002569 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002570 int ret = 0;
2571
Neema Shetty2c07eb52011-08-21 20:33:52 -07002572 if (v == NULL) {
2573 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2574
2575 return -EINVAL;
2576 }
2577
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002578 mutex_lock(&v->lock);
2579
2580 v->dev_rx.volume = vol_idx;
2581
2582 if (v->voc_state == VOC_RUN)
2583 ret = voice_send_vol_index_cmd(v);
2584
2585 mutex_unlock(&v->lock);
2586
2587 return ret;
2588}
2589
Neema Shetty2c07eb52011-08-21 20:33:52 -07002590int voc_set_rxtx_port(uint16_t session_id, uint32_t port_id, uint32_t dev_type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002591{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002592 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002593
Neema Shetty2c07eb52011-08-21 20:33:52 -07002594 if (v == NULL) {
2595 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2596
2597 return -EINVAL;
2598 }
2599
2600 pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002601
2602 mutex_lock(&v->lock);
2603
2604 if (dev_type == DEV_RX)
2605 v->dev_rx.port_id = port_id;
2606 else
2607 v->dev_tx.port_id = port_id;
2608
2609 mutex_unlock(&v->lock);
2610
Neema Shetty2c07eb52011-08-21 20:33:52 -07002611 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002612}
2613
Neema Shetty2c07eb52011-08-21 20:33:52 -07002614int voc_set_route_flag(uint16_t session_id, uint8_t path_dir, uint8_t set)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002615{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002616 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002617
Neema Shetty2c07eb52011-08-21 20:33:52 -07002618 if (v == NULL) {
2619 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2620
2621 return -EINVAL;
2622 }
2623
2624 pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002625
2626 mutex_lock(&v->lock);
2627
2628 if (path_dir == RX_PATH)
2629 v->voc_route_state.rx_route_flag = set;
2630 else
2631 v->voc_route_state.tx_route_flag = set;
2632
2633 mutex_unlock(&v->lock);
2634
Neema Shetty2c07eb52011-08-21 20:33:52 -07002635 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002636}
2637
Neema Shetty2c07eb52011-08-21 20:33:52 -07002638uint8_t voc_get_route_flag(uint16_t session_id, uint8_t path_dir)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002639{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002640 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002641 int ret = 0;
2642
Neema Shetty2c07eb52011-08-21 20:33:52 -07002643 if (v == NULL) {
2644 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2645
2646 return 0;
2647 }
2648
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002649 mutex_lock(&v->lock);
2650
2651 if (path_dir == RX_PATH)
2652 ret = v->voc_route_state.rx_route_flag;
2653 else
2654 ret = v->voc_route_state.tx_route_flag;
2655
2656 mutex_unlock(&v->lock);
2657
2658 return ret;
2659}
2660
Neema Shetty2c07eb52011-08-21 20:33:52 -07002661int voc_end_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002662{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002663 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002664 int ret = 0;
2665
Neema Shetty2c07eb52011-08-21 20:33:52 -07002666 if (v == NULL) {
2667 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2668
2669 return -EINVAL;
2670 }
2671
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002672 mutex_lock(&v->lock);
2673
2674 if (v->voc_state == VOC_RUN) {
Helen Zengbd58e2c2011-07-01 16:24:31 -07002675 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002676 ret = voice_destroy_vocproc(v);
2677 if (ret < 0)
2678 pr_err("%s: destroy voice failed\n", __func__);
2679 voice_destroy_mvm_cvs_session(v);
2680
2681 v->voc_state = VOC_RELEASE;
2682 }
2683 mutex_unlock(&v->lock);
2684 return ret;
2685}
2686
Neema Shetty2c07eb52011-08-21 20:33:52 -07002687int voc_start_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002688{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002689 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002690 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002691 int ret = 0;
2692
Neema Shetty2c07eb52011-08-21 20:33:52 -07002693 if (v == NULL) {
2694 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2695
2696 return -EINVAL;
2697 }
2698
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002699 mutex_lock(&v->lock);
2700
2701 if ((v->voc_state == VOC_INIT) ||
2702 (v->voc_state == VOC_RELEASE)) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002703 ret = voice_apr_register();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002704 if (ret < 0) {
2705 pr_err("%s: apr register failed\n", __func__);
2706 goto fail;
2707 }
2708 ret = voice_create_mvm_cvs_session(v);
2709 if (ret < 0) {
2710 pr_err("create mvm and cvs failed\n");
2711 goto fail;
2712 }
2713 ret = voice_setup_vocproc(v);
2714 if (ret < 0) {
2715 pr_err("setup voice failed\n");
2716 goto fail;
2717 }
2718 ret = voice_send_start_voice_cmd(v);
2719 if (ret < 0) {
2720 pr_err("start voice failed\n");
2721 goto fail;
2722 }
Helen Zengbd58e2c2011-07-01 16:24:31 -07002723 get_sidetone_cal(&sidetone_cal_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002724 ret = afe_sidetone(v->dev_tx.port_id,
Helen Zengbd58e2c2011-07-01 16:24:31 -07002725 v->dev_rx.port_id,
2726 sidetone_cal_data.enable,
2727 sidetone_cal_data.gain);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002728 if (ret < 0)
2729 pr_err("AFE command sidetone failed\n");
2730
2731 v->voc_state = VOC_RUN;
2732 }
2733
2734fail: mutex_unlock(&v->lock);
2735 return ret;
2736}
2737
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002738void voc_register_mvs_cb(ul_cb_fn ul_cb,
2739 dl_cb_fn dl_cb,
2740 void *private_data)
2741{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002742 common.mvs_info.ul_cb = ul_cb;
2743 common.mvs_info.dl_cb = dl_cb;
2744 common.mvs_info.private_data = private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002745}
2746
2747void voc_config_vocoder(uint32_t media_type,
2748 uint32_t rate,
2749 uint32_t network_type)
2750{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002751 common.mvs_info.media_type = media_type;
2752 common.mvs_info.rate = rate;
2753 common.mvs_info.network_type = network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002754}
2755
2756static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
2757{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002758 uint32_t *ptr = NULL;
2759 struct common_data *c = NULL;
2760 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002761 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002762
2763 if ((data == NULL) || (priv == NULL)) {
2764 pr_err("%s: data or priv is NULL\n", __func__);
2765 return -EINVAL;
2766 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002767
2768 c = priv;
2769
2770 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
2771
2772 v = voice_get_session(data->dest_port);
2773 if (v == NULL) {
2774 pr_err("%s: v is NULL\n", __func__);
2775
2776 return -EINVAL;
2777 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002778
2779 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2780 data->payload_size, data->opcode);
2781
Neema Shetty07477582011-09-02 17:35:44 -07002782 if (data->opcode == RESET_EVENTS) {
2783 pr_debug("%s: Reset event received in Voice service\n",
2784 __func__);
2785
2786 apr_reset(c->apr_q6_mvm);
2787 c->apr_q6_mvm = NULL;
2788
2789 /* Sub-system restart is applicable to all sessions. */
2790 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2791 c->voice[i].mvm_handle = 0;
2792
2793 return 0;
2794 }
2795
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002796 if (data->opcode == APR_BASIC_RSP_RESULT) {
2797 if (data->payload_size) {
2798 ptr = data->payload;
2799
2800 pr_info("%x %x\n", ptr[0], ptr[1]);
2801 /* ping mvm service ACK */
2802 switch (ptr[0]) {
2803 case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
2804 case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
2805 /* Passive session is used for CS call
2806 * Full session is used for VoIP call. */
2807 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2808 if (!ptr[1]) {
2809 pr_debug("%s: MVM handle is %d\n",
2810 __func__, data->src_port);
2811 voice_set_mvm_handle(v, data->src_port);
2812 } else
2813 pr_err("got NACK for sending \
2814 MVM create session \n");
2815 v->mvm_state = CMD_STATUS_SUCCESS;
2816 wake_up(&v->mvm_wait);
2817 break;
2818 case VSS_IMVM_CMD_START_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07002819 case VSS_IMVM_CMD_ATTACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002820 case VSS_IMVM_CMD_STOP_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07002821 case VSS_IMVM_CMD_DETACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002822 case VSS_ISTREAM_CMD_SET_TTY_MODE:
2823 case APRV2_IBASIC_CMD_DESTROY_SESSION:
2824 case VSS_IMVM_CMD_ATTACH_STREAM:
2825 case VSS_IMVM_CMD_DETACH_STREAM:
2826 case VSS_ICOMMON_CMD_SET_NETWORK:
2827 case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
Helen Zeng44d4d272011-08-10 14:49:20 -07002828 case VSS_IWIDEVOICE_CMD_SET_WIDEVOICE:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002829 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2830 v->mvm_state = CMD_STATUS_SUCCESS;
2831 wake_up(&v->mvm_wait);
2832 break;
2833 default:
2834 pr_debug("%s: not match cmd = 0x%x\n",
2835 __func__, ptr[0]);
2836 break;
2837 }
2838 }
2839 }
2840
2841 return 0;
2842}
2843
2844static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
2845{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002846 uint32_t *ptr = NULL;
2847 struct common_data *c = NULL;
2848 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002849 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002850
2851 if ((data == NULL) || (priv == NULL)) {
2852 pr_err("%s: data or priv is NULL\n", __func__);
2853 return -EINVAL;
2854 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002855
2856 c = priv;
2857
2858 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
2859
2860 v = voice_get_session(data->dest_port);
2861 if (v == NULL) {
2862 pr_err("%s: v is NULL\n", __func__);
2863
2864 return -EINVAL;
2865 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002866
2867 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2868 data->payload_size, data->opcode);
2869
Neema Shetty07477582011-09-02 17:35:44 -07002870 if (data->opcode == RESET_EVENTS) {
2871 pr_debug("%s: Reset event received in Voice service\n",
2872 __func__);
2873
2874 apr_reset(c->apr_q6_cvs);
2875 c->apr_q6_cvs = NULL;
2876
2877 /* Sub-system restart is applicable to all sessions. */
2878 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2879 c->voice[i].cvs_handle = 0;
2880
2881 return 0;
2882 }
2883
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002884 if (data->opcode == APR_BASIC_RSP_RESULT) {
2885 if (data->payload_size) {
2886 ptr = data->payload;
2887
2888 pr_info("%x %x\n", ptr[0], ptr[1]);
2889 /*response from CVS */
2890 switch (ptr[0]) {
2891 case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
2892 case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
2893 if (!ptr[1]) {
2894 pr_debug("%s: CVS handle is %d\n",
2895 __func__, data->src_port);
2896 voice_set_cvs_handle(v, data->src_port);
2897 } else
2898 pr_err("got NACK for sending \
2899 CVS create session \n");
2900 v->cvs_state = CMD_STATUS_SUCCESS;
2901 wake_up(&v->cvs_wait);
2902 break;
2903 case VSS_ISTREAM_CMD_SET_MUTE:
2904 case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
2905 case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
2906 case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
2907 case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
2908 case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
2909 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07002910 case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA:
2911 case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
2912 case VSS_ICOMMON_CMD_MAP_MEMORY:
2913 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Helen Zengbb49c702011-09-06 14:09:13 -07002914 case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002915 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2916 v->cvs_state = CMD_STATUS_SUCCESS;
2917 wake_up(&v->cvs_wait);
2918 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07002919 case VOICE_CMD_SET_PARAM:
2920 rtac_make_voice_callback(RTAC_CVS, ptr,
2921 data->payload_size);
2922 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002923 default:
2924 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2925 break;
2926 }
2927 }
2928 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
2929 uint32_t *voc_pkt = data->payload;
2930 uint32_t pkt_len = data->payload_size;
2931
Neema Shetty2c07eb52011-08-21 20:33:52 -07002932 if (voc_pkt != NULL && c->mvs_info.ul_cb != NULL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002933 pr_debug("%s: Media type is 0x%x\n",
2934 __func__, voc_pkt[0]);
2935
2936 /* Remove media ID from payload. */
2937 voc_pkt++;
2938 pkt_len = pkt_len - 4;
2939
Neema Shetty2c07eb52011-08-21 20:33:52 -07002940 c->mvs_info.ul_cb((uint8_t *)voc_pkt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002941 pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002942 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002943 } else
2944 pr_err("%s: voc_pkt is 0x%x ul_cb is 0x%x\n",
2945 __func__, (unsigned int)voc_pkt,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002946 (unsigned int) c->mvs_info.ul_cb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002947 } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
2948 struct cvs_send_dec_buf_cmd send_dec_buf;
2949 int ret = 0;
2950 uint32_t pkt_len = 0;
2951
Neema Shetty2c07eb52011-08-21 20:33:52 -07002952 if (c->mvs_info.dl_cb != NULL) {
2953 send_dec_buf.dec_buf.media_id = c->mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002954
Neema Shetty2c07eb52011-08-21 20:33:52 -07002955 c->mvs_info.dl_cb(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002956 (uint8_t *)&send_dec_buf.dec_buf.packet_data,
2957 &pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002958 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002959
2960 send_dec_buf.hdr.hdr_field =
2961 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2962 APR_HDR_LEN(APR_HDR_SIZE),
2963 APR_PKT_VER);
2964 send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2965 sizeof(send_dec_buf.dec_buf.media_id) + pkt_len);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002966 send_dec_buf.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002967 send_dec_buf.hdr.dest_port = voice_get_cvs_handle(v);
2968 send_dec_buf.hdr.token = 0;
2969 send_dec_buf.hdr.opcode =
2970 VSS_ISTREAM_EVT_SEND_DEC_BUFFER;
2971
Neema Shetty2c07eb52011-08-21 20:33:52 -07002972 ret = apr_send_pkt(c->apr_q6_cvs,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002973 (uint32_t *) &send_dec_buf);
2974 if (ret < 0) {
2975 pr_err("%s: Error %d sending DEC_BUF\n",
2976 __func__, ret);
2977 goto fail;
2978 }
2979 } else
2980 pr_debug("%s: dl_cb is NULL\n", __func__);
Ben Romberger13b74ab2011-07-18 17:36:32 -07002981 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002982 pr_debug("Send dec buf resp\n");
Ben Romberger13b74ab2011-07-18 17:36:32 -07002983 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
2984 rtac_make_voice_callback(RTAC_CVS, data->payload,
2985 data->payload_size);
2986 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002987 pr_debug("Unknown opcode 0x%x\n", data->opcode);
2988
2989fail:
2990 return 0;
2991}
2992
2993static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
2994{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002995 uint32_t *ptr = NULL;
2996 struct common_data *c = NULL;
2997 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002998 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002999
3000 if ((data == NULL) || (priv == NULL)) {
3001 pr_err("%s: data or priv is NULL\n", __func__);
3002 return -EINVAL;
3003 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07003004
3005 c = priv;
3006
3007 v = voice_get_session(data->dest_port);
3008 if (v == NULL) {
3009 pr_err("%s: v is NULL\n", __func__);
3010
3011 return -EINVAL;
3012 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003013
3014 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
3015 data->payload_size, data->opcode);
3016
Neema Shetty07477582011-09-02 17:35:44 -07003017 if (data->opcode == RESET_EVENTS) {
3018 pr_debug("%s: Reset event received in Voice service\n",
3019 __func__);
3020
3021 apr_reset(c->apr_q6_cvp);
3022 c->apr_q6_cvp = NULL;
3023
3024 /* Sub-system restart is applicable to all sessions. */
3025 for (i = 0; i < MAX_VOC_SESSIONS; i++)
3026 c->voice[i].cvp_handle = 0;
3027
3028 return 0;
3029 }
3030
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003031 if (data->opcode == APR_BASIC_RSP_RESULT) {
3032 if (data->payload_size) {
3033 ptr = data->payload;
3034
3035 pr_info("%x %x\n", ptr[0], ptr[1]);
3036
3037 switch (ptr[0]) {
3038 case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION:
3039 /*response from CVP */
3040 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
3041 if (!ptr[1]) {
3042 voice_set_cvp_handle(v, data->src_port);
3043 pr_debug("cvphdl=%d\n", data->src_port);
3044 } else
3045 pr_err("got NACK from CVP create \
3046 session response\n");
3047 v->cvp_state = CMD_STATUS_SUCCESS;
3048 wake_up(&v->cvp_wait);
3049 break;
3050 case VSS_IVOCPROC_CMD_SET_DEVICE:
3051 case VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX:
3052 case VSS_IVOCPROC_CMD_ENABLE:
3053 case VSS_IVOCPROC_CMD_DISABLE:
3054 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07003055 case VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE:
3056 case VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE:
3057 case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA:
3058 case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
3059 case VSS_ICOMMON_CMD_MAP_MEMORY:
3060 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003061 v->cvp_state = CMD_STATUS_SUCCESS;
3062 wake_up(&v->cvp_wait);
3063 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07003064 case VOICE_CMD_SET_PARAM:
3065 rtac_make_voice_callback(RTAC_CVP, ptr,
3066 data->payload_size);
3067 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003068 default:
3069 pr_debug("%s: not match cmd = 0x%x\n",
3070 __func__, ptr[0]);
3071 break;
3072 }
3073 }
Ben Romberger13b74ab2011-07-18 17:36:32 -07003074 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
3075 rtac_make_voice_callback(RTAC_CVP, data->payload,
3076 data->payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003077 }
3078 return 0;
3079}
3080
3081
3082static int __init voice_init(void)
3083{
Neema Shetty2c07eb52011-08-21 20:33:52 -07003084 int rc = 0, i = 0;
3085
3086 memset(&common, 0, sizeof(struct common_data));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003087
3088 /* set default value */
Neema Shetty2c07eb52011-08-21 20:33:52 -07003089 common.default_mute_val = 1; /* default is mute */
3090 common.default_vol_val = 0;
3091 common.default_sample_val = 8000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003092
3093 /* Initialize MVS info. */
Neema Shetty2c07eb52011-08-21 20:33:52 -07003094 common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
3095
3096 mutex_init(&common.common_lock);
3097
3098 for (i = 0; i < MAX_VOC_SESSIONS; i++) {
3099 common.voice[i].session_id = SESSION_ID_BASE + i;
3100
3101 /* initialize dev_rx and dev_tx */
3102 common.voice[i].dev_rx.volume = common.default_vol_val;
3103 common.voice[i].dev_tx.mute = common.default_mute_val;
3104
3105 common.voice[i].dev_tx.port_id = 1;
3106 common.voice[i].dev_rx.port_id = 0;
3107 common.voice[i].sidetone_gain = 0x512;
3108
3109 common.voice[i].voc_state = VOC_INIT;
3110
3111 init_waitqueue_head(&common.voice[i].mvm_wait);
3112 init_waitqueue_head(&common.voice[i].cvs_wait);
3113 init_waitqueue_head(&common.voice[i].cvp_wait);
3114
3115 mutex_init(&common.voice[i].lock);
3116 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003117
3118 return rc;
3119}
3120
3121device_initcall(voice_init);