blob: 2a5afccfe4b190dc53dd9d03050d4181a8b16ec1 [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 Zeng29eb7442011-06-20 11:06:29 -070055
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056
57static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
58static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
59static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
60
61static u16 voice_get_mvm_handle(struct voice_data *v)
62{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063 if (v == NULL) {
64 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070065 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067
Neema Shetty2c07eb52011-08-21 20:33:52 -070068 pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069
Neema Shetty2c07eb52011-08-21 20:33:52 -070070 return v->mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071}
72
73static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
74{
75 pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
76 if (v == NULL) {
77 pr_err("%s: v is NULL\n", __func__);
78 return;
79 }
80
Neema Shetty2c07eb52011-08-21 20:33:52 -070081 v->mvm_handle = mvm_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082}
83
84static u16 voice_get_cvs_handle(struct voice_data *v)
85{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 if (v == NULL) {
87 pr_err("%s: v is NULL\n", __func__);
Neema Shetty2c07eb52011-08-21 20:33:52 -070088 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090
Neema Shetty2c07eb52011-08-21 20:33:52 -070091 pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092
Neema Shetty2c07eb52011-08-21 20:33:52 -070093 return v->cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094}
95
96static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
97{
98 pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
99 if (v == NULL) {
100 pr_err("%s: v is NULL\n", __func__);
101 return;
102 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700103
104 v->cvs_handle = cvs_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105}
106
107static u16 voice_get_cvp_handle(struct voice_data *v)
108{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700109 if (v == NULL) {
110 pr_err("%s: v is NULL\n", __func__);
111 return 0;
112 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113
Neema Shetty2c07eb52011-08-21 20:33:52 -0700114 pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700115
Neema Shetty2c07eb52011-08-21 20:33:52 -0700116 return v->cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117}
118
119static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
120{
121 pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
122 if (v == NULL) {
123 pr_err("%s: v is NULL\n", __func__);
124 return;
125 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700126
127 v->cvp_handle = cvp_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128}
129
Neema Shetty2c07eb52011-08-21 20:33:52 -0700130uint16_t voc_get_session_id(char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131{
Neema Shetty2c07eb52011-08-21 20:33:52 -0700132 u16 session_id = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133
Neema Shetty2c07eb52011-08-21 20:33:52 -0700134 if (name != NULL) {
135 if (!strncmp(name, "Voice session", 13))
136 session_id = common.voice[VOC_PATH_PASSIVE].session_id;
137 else
138 session_id = common.voice[VOC_PATH_FULL].session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140
Neema Shetty2c07eb52011-08-21 20:33:52 -0700141 pr_debug("%s: %s has session id 0x%x\n", __func__, name, session_id);
142
143 return session_id;
144}
145
146static struct voice_data *voice_get_session(u16 session_id)
147{
148 struct voice_data *v = NULL;
149
150 if ((session_id >= SESSION_ID_BASE) &&
151 (session_id < SESSION_ID_BASE + MAX_VOC_SESSIONS)) {
152 v = &common.voice[session_id - SESSION_ID_BASE];
153 }
154
155 pr_debug("%s: session_id 0x%x session handle 0x%x\n",
156 __func__, session_id, (unsigned int)v);
157
158 return v;
159}
160
161static bool is_voice_session(u16 session_id)
162{
163 return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
164}
165
166static bool is_voip_session(u16 session_id)
167{
168 return (session_id == common.voice[VOC_PATH_FULL].session_id);
169}
170
171static int voice_apr_register(void)
172{
173 pr_debug("%s\n", __func__);
174
175 mutex_lock(&common.common_lock);
176
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 /* register callback to APR */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700178 if (common.apr_q6_mvm == NULL) {
179 pr_debug("%s: Start to register MVM callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180
Neema Shetty2c07eb52011-08-21 20:33:52 -0700181 common.apr_q6_mvm = apr_register("ADSP", "MVM",
182 qdsp_mvm_callback,
183 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184
Neema Shetty2c07eb52011-08-21 20:33:52 -0700185 if (common.apr_q6_mvm == NULL) {
186 pr_err("%s: Unable to register MVM\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 goto err;
188 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189 }
190
Neema Shetty2c07eb52011-08-21 20:33:52 -0700191 if (common.apr_q6_cvs == NULL) {
192 pr_debug("%s: Start to register CVS callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193
Neema Shetty2c07eb52011-08-21 20:33:52 -0700194 common.apr_q6_cvs = apr_register("ADSP", "CVS",
195 qdsp_cvs_callback,
196 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197
Neema Shetty2c07eb52011-08-21 20:33:52 -0700198 if (common.apr_q6_cvs == NULL) {
199 pr_err("%s: Unable to register CVS\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200 goto err;
201 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700202
Neema Shetty2c07eb52011-08-21 20:33:52 -0700203 rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 }
205
Neema Shetty2c07eb52011-08-21 20:33:52 -0700206 if (common.apr_q6_cvp == NULL) {
207 pr_debug("%s: Start to register CVP callback\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208
Neema Shetty2c07eb52011-08-21 20:33:52 -0700209 common.apr_q6_cvp = apr_register("ADSP", "CVP",
210 qdsp_cvp_callback,
211 0xFFFFFFFF, &common);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212
Neema Shetty2c07eb52011-08-21 20:33:52 -0700213 if (common.apr_q6_cvp == NULL) {
214 pr_err("%s: Unable to register CVP\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 goto err;
216 }
Ben Romberger13b74ab2011-07-18 17:36:32 -0700217
Neema Shetty2c07eb52011-08-21 20:33:52 -0700218 rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700220
221 mutex_unlock(&common.common_lock);
222
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700223 return 0;
224
225err:
Neema Shetty2c07eb52011-08-21 20:33:52 -0700226 if (common.apr_q6_cvs != NULL) {
227 apr_deregister(common.apr_q6_cvs);
228 common.apr_q6_cvs = NULL;
Ben Romberger13b74ab2011-07-18 17:36:32 -0700229 rtac_set_voice_handle(RTAC_CVS, NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700231 if (common.apr_q6_mvm != NULL) {
232 apr_deregister(common.apr_q6_mvm);
233 common.apr_q6_mvm = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 }
235
Neema Shetty2c07eb52011-08-21 20:33:52 -0700236 mutex_unlock(&common.common_lock);
237
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700238 return -ENODEV;
239}
240
241static int voice_create_mvm_cvs_session(struct voice_data *v)
242{
243 int ret = 0;
Helen Zeng69b00962011-07-08 11:38:36 -0700244 struct mvm_create_ctl_session_cmd mvm_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245 struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700246 struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
247 struct mvm_attach_stream_cmd attach_stream_cmd;
248 void *apr_mvm, *apr_cvs, *apr_cvp;
249 u16 mvm_handle, cvs_handle, cvp_handle;
250
251 if (v == NULL) {
252 pr_err("%s: v is NULL\n", __func__);
253 return -EINVAL;
254 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700255 apr_mvm = common.apr_q6_mvm;
256 apr_cvs = common.apr_q6_cvs;
257 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700258
259 if (!apr_mvm || !apr_cvs || !apr_cvp) {
260 pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
261 return -EINVAL;
262 }
263 mvm_handle = voice_get_mvm_handle(v);
264 cvs_handle = voice_get_cvs_handle(v);
265 cvp_handle = voice_get_cvp_handle(v);
266
267 pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
268 mvm_handle, cvs_handle);
269 /* send cmd to create mvm session and wait for response */
270
271 if (!mvm_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700272 if (is_voice_session(v->session_id)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
274 APR_MSG_TYPE_SEQ_CMD,
275 APR_HDR_LEN(APR_HDR_SIZE),
276 APR_PKT_VER);
277 mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
278 APR_HDR_SIZE,
279 sizeof(mvm_session_cmd) -
280 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700281 pr_debug("%s: send mvm create session pkt size = %d\n",
282 __func__, mvm_session_cmd.hdr.pkt_size);
283 mvm_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284 mvm_session_cmd.hdr.dest_port = 0;
285 mvm_session_cmd.hdr.token = 0;
286 mvm_session_cmd.hdr.opcode =
287 VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
Helen Zeng69b00962011-07-08 11:38:36 -0700288 strncpy(mvm_session_cmd.mvm_session.name,
289 "default modem voice", SESSION_NAME_LEN);
290
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 v->mvm_state = CMD_STATUS_FAIL;
292
293 ret = apr_send_pkt(apr_mvm,
294 (uint32_t *) &mvm_session_cmd);
295 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700296 pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
297 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 goto fail;
299 }
300 ret = wait_event_timeout(v->mvm_wait,
301 (v->mvm_state == CMD_STATUS_SUCCESS),
302 msecs_to_jiffies(TIMEOUT_MS));
303 if (!ret) {
304 pr_err("%s: wait_event timeout\n", __func__);
305 goto fail;
306 }
307 } else {
308 pr_debug("%s: creating MVM full ctrl\n", __func__);
Helen Zeng69b00962011-07-08 11:38:36 -0700309 mvm_session_cmd.hdr.hdr_field =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
311 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
Helen Zeng69b00962011-07-08 11:38:36 -0700312 mvm_session_cmd.hdr.pkt_size =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313 APR_PKT_SIZE(APR_HDR_SIZE,
Helen Zeng69b00962011-07-08 11:38:36 -0700314 sizeof(mvm_session_cmd) -
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700316 mvm_session_cmd.hdr.src_port = v->session_id;
Helen Zeng69b00962011-07-08 11:38:36 -0700317 mvm_session_cmd.hdr.dest_port = 0;
318 mvm_session_cmd.hdr.token = 0;
319 mvm_session_cmd.hdr.opcode =
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
Helen Zeng69b00962011-07-08 11:38:36 -0700321 strncpy(mvm_session_cmd.mvm_session.name,
322 "default voip", SESSION_NAME_LEN);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323
324 v->mvm_state = CMD_STATUS_FAIL;
325
326 ret = apr_send_pkt(apr_mvm,
Helen Zeng69b00962011-07-08 11:38:36 -0700327 (uint32_t *) &mvm_session_cmd);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700328 if (ret < 0) {
329 pr_err("Fail in sending MVM_CONTROL_SESSION\n");
330 goto fail;
331 }
332 ret = wait_event_timeout(v->mvm_wait,
333 (v->mvm_state == CMD_STATUS_SUCCESS),
334 msecs_to_jiffies(TIMEOUT_MS));
335 if (!ret) {
336 pr_err("%s: wait_event timeout\n", __func__);
337 goto fail;
338 }
339 }
340 /* Get the created MVM handle. */
341 mvm_handle = voice_get_mvm_handle(v);
342 }
343 /* send cmd to create cvs session */
344 if (!cvs_handle) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700345 if (is_voice_session(v->session_id)) {
346 pr_debug("%s: creating CVS passive session\n",
347 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700348
349 cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
350 APR_MSG_TYPE_SEQ_CMD,
351 APR_HDR_LEN(APR_HDR_SIZE),
352 APR_PKT_VER);
353 cvs_session_cmd.hdr.pkt_size =
354 APR_PKT_SIZE(APR_HDR_SIZE,
355 sizeof(cvs_session_cmd) -
356 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700357 cvs_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700358 cvs_session_cmd.hdr.dest_port = 0;
359 cvs_session_cmd.hdr.token = 0;
360 cvs_session_cmd.hdr.opcode =
361 VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
362 strncpy(cvs_session_cmd.cvs_session.name,
Helen Zeng69b00962011-07-08 11:38:36 -0700363 "default modem voice", SESSION_NAME_LEN);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364
365 v->cvs_state = CMD_STATUS_FAIL;
366
367 ret = apr_send_pkt(apr_cvs,
368 (uint32_t *) &cvs_session_cmd);
369 if (ret < 0) {
370 pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
371 goto fail;
372 }
373 ret = wait_event_timeout(v->cvs_wait,
374 (v->cvs_state == CMD_STATUS_SUCCESS),
375 msecs_to_jiffies(TIMEOUT_MS));
376 if (!ret) {
377 pr_err("%s: wait_event timeout\n", __func__);
378 goto fail;
379 }
380 /* Get the created CVS handle. */
381 cvs_handle = voice_get_cvs_handle(v);
382
383 } else {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700384 pr_debug("%s: creating CVS full session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700385
386 cvs_full_ctl_cmd.hdr.hdr_field =
387 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
388 APR_HDR_LEN(APR_HDR_SIZE),
389 APR_PKT_VER);
390
391 cvs_full_ctl_cmd.hdr.pkt_size =
392 APR_PKT_SIZE(APR_HDR_SIZE,
393 sizeof(cvs_full_ctl_cmd) -
394 APR_HDR_SIZE);
395
Neema Shetty2c07eb52011-08-21 20:33:52 -0700396 cvs_full_ctl_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397 cvs_full_ctl_cmd.hdr.dest_port = 0;
398 cvs_full_ctl_cmd.hdr.token = 0;
399 cvs_full_ctl_cmd.hdr.opcode =
400 VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
401 cvs_full_ctl_cmd.cvs_session.direction = 2;
402 cvs_full_ctl_cmd.cvs_session.enc_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700403 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 cvs_full_ctl_cmd.cvs_session.dec_media_type =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700405 common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700406 cvs_full_ctl_cmd.cvs_session.network_id =
Neema Shetty2c07eb52011-08-21 20:33:52 -0700407 common.mvs_info.network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700408 strncpy(cvs_full_ctl_cmd.cvs_session.name,
409 "default q6 voice", 16);
410
411 v->cvs_state = CMD_STATUS_FAIL;
412
413 ret = apr_send_pkt(apr_cvs,
414 (uint32_t *) &cvs_full_ctl_cmd);
415
416 if (ret < 0) {
417 pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
418 __func__, ret);
419 goto fail;
420 }
421 ret = wait_event_timeout(v->cvs_wait,
422 (v->cvs_state == CMD_STATUS_SUCCESS),
423 msecs_to_jiffies(TIMEOUT_MS));
424 if (!ret) {
425 pr_err("%s: wait_event timeout\n", __func__);
426 goto fail;
427 }
428 /* Get the created CVS handle. */
429 cvs_handle = voice_get_cvs_handle(v);
430
431 /* Attach MVM to CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700432 pr_debug("%s: Attach MVM to stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700433
434 attach_stream_cmd.hdr.hdr_field =
435 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
436 APR_HDR_LEN(APR_HDR_SIZE),
437 APR_PKT_VER);
438 attach_stream_cmd.hdr.pkt_size =
439 APR_PKT_SIZE(APR_HDR_SIZE,
440 sizeof(attach_stream_cmd) -
441 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700442 attach_stream_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700443 attach_stream_cmd.hdr.dest_port = mvm_handle;
444 attach_stream_cmd.hdr.token = 0;
445 attach_stream_cmd.hdr.opcode =
446 VSS_IMVM_CMD_ATTACH_STREAM;
447 attach_stream_cmd.attach_stream.handle = cvs_handle;
448
449 v->mvm_state = CMD_STATUS_FAIL;
450 ret = apr_send_pkt(apr_mvm,
451 (uint32_t *) &attach_stream_cmd);
452 if (ret < 0) {
453 pr_err("%s: Error %d sending ATTACH_STREAM\n",
454 __func__, ret);
455 goto fail;
456 }
457 ret = wait_event_timeout(v->mvm_wait,
458 (v->mvm_state == CMD_STATUS_SUCCESS),
459 msecs_to_jiffies(TIMEOUT_MS));
460 if (!ret) {
461 pr_err("%s: wait_event timeout\n", __func__);
462 goto fail;
463 }
464 }
465 }
466 return 0;
467
468fail:
469 return -EINVAL;
470}
471
472static int voice_destroy_mvm_cvs_session(struct voice_data *v)
473{
474 int ret = 0;
475 struct mvm_detach_stream_cmd detach_stream;
476 struct apr_hdr mvm_destroy;
477 struct apr_hdr cvs_destroy;
478 void *apr_mvm, *apr_cvs;
479 u16 mvm_handle, cvs_handle;
480
481 if (v == NULL) {
482 pr_err("%s: v is NULL\n", __func__);
483 return -EINVAL;
484 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700485 apr_mvm = common.apr_q6_mvm;
486 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487
488 if (!apr_mvm || !apr_cvs) {
489 pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
490 return -EINVAL;
491 }
492 mvm_handle = voice_get_mvm_handle(v);
493 cvs_handle = voice_get_cvs_handle(v);
494
495 /* MVM, CVS sessions are destroyed only for Full control sessions. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700496 if (is_voip_session(v->session_id)) {
497 pr_debug("%s: MVM detach stream\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498
499 /* Detach voice stream. */
500 detach_stream.hdr.hdr_field =
501 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
502 APR_HDR_LEN(APR_HDR_SIZE),
503 APR_PKT_VER);
504 detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
505 sizeof(detach_stream) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700506 detach_stream.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700507 detach_stream.hdr.dest_port = mvm_handle;
508 detach_stream.hdr.token = 0;
509 detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
510 detach_stream.detach_stream.handle = cvs_handle;
511
512 v->mvm_state = CMD_STATUS_FAIL;
513
514 ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
515 if (ret < 0) {
516 pr_err("%s: Error %d sending DETACH_STREAM\n",
517 __func__, ret);
518 goto fail;
519 }
520 ret = wait_event_timeout(v->mvm_wait,
521 (v->mvm_state == CMD_STATUS_SUCCESS),
522 msecs_to_jiffies(TIMEOUT_MS));
523 if (!ret) {
524 pr_err("%s: wait event timeout\n", __func__);
525 goto fail;
526 }
527 /* Destroy CVS. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700528 pr_debug("%s: CVS destroy session\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700529
530 cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
531 APR_HDR_LEN(APR_HDR_SIZE),
532 APR_PKT_VER);
533 cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
534 sizeof(cvs_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700535 cvs_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700536 cvs_destroy.dest_port = cvs_handle;
537 cvs_destroy.token = 0;
538 cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
539
540 v->cvs_state = CMD_STATUS_FAIL;
541
542 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
543 if (ret < 0) {
544 pr_err("%s: Error %d sending CVS DESTROY\n",
545 __func__, ret);
546 goto fail;
547 }
548 ret = wait_event_timeout(v->cvs_wait,
549 (v->cvs_state == CMD_STATUS_SUCCESS),
550 msecs_to_jiffies(TIMEOUT_MS));
551 if (!ret) {
552 pr_err("%s: wait event timeout\n", __func__);
553
554 goto fail;
555 }
556 cvs_handle = 0;
557 voice_set_cvs_handle(v, cvs_handle);
558
559 /* Destroy MVM. */
560 pr_debug("MVM destroy session\n");
561
562 mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
563 APR_HDR_LEN(APR_HDR_SIZE),
564 APR_PKT_VER);
565 mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
566 sizeof(mvm_destroy) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700567 mvm_destroy.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700568 mvm_destroy.dest_port = mvm_handle;
569 mvm_destroy.token = 0;
570 mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
571
572 v->mvm_state = CMD_STATUS_FAIL;
573
574 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
575 if (ret < 0) {
576 pr_err("%s: Error %d sending MVM DESTROY\n",
577 __func__, ret);
578
579 goto fail;
580 }
581 ret = wait_event_timeout(v->mvm_wait,
582 (v->mvm_state == CMD_STATUS_SUCCESS),
583 msecs_to_jiffies(TIMEOUT_MS));
584 if (!ret) {
585 pr_err("%s: wait event timeout\n", __func__);
586
587 goto fail;
588 }
589 mvm_handle = 0;
590 voice_set_mvm_handle(v, mvm_handle);
591 }
592 return 0;
593fail:
594 return -EINVAL;
595}
596
597static int voice_send_tty_mode_cmd(struct voice_data *v)
598{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 int ret = 0;
600 struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
601 void *apr_mvm;
602 u16 mvm_handle;
603
604 if (v == NULL) {
605 pr_err("%s: v is NULL\n", __func__);
606 return -EINVAL;
607 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700608 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700609
610 if (!apr_mvm) {
611 pr_err("%s: apr_mvm is NULL.\n", __func__);
612 return -EINVAL;
613 }
614 mvm_handle = voice_get_mvm_handle(v);
615
Helen Zengcc65b5b2011-07-06 19:14:48 -0700616 if (v->tty_mode) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700617 /* send tty mode cmd to mvm */
618 mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
619 APR_MSG_TYPE_SEQ_CMD,
620 APR_HDR_LEN(APR_HDR_SIZE),
621 APR_PKT_VER);
622 mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
623 sizeof(mvm_tty_mode_cmd) -
624 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700625 pr_debug("%s: pkt size = %d\n",
626 __func__, mvm_tty_mode_cmd.hdr.pkt_size);
627 mvm_tty_mode_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700628 mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
629 mvm_tty_mode_cmd.hdr.token = 0;
630 mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
Helen Zengcc65b5b2011-07-06 19:14:48 -0700631 mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700632 pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
633
634 v->mvm_state = CMD_STATUS_FAIL;
635 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
636 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -0700637 pr_err("%s: Error %d sending SET_TTY_MODE\n",
638 __func__, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 goto fail;
640 }
641 ret = wait_event_timeout(v->mvm_wait,
642 (v->mvm_state == CMD_STATUS_SUCCESS),
643 msecs_to_jiffies(TIMEOUT_MS));
644 if (!ret) {
645 pr_err("%s: wait_event timeout\n", __func__);
646 goto fail;
647 }
648 }
649 return 0;
650fail:
651 return -EINVAL;
652}
653
654static int voice_config_cvs_vocoder(struct voice_data *v)
655{
656 int ret = 0;
657 void *apr_cvs;
658 u16 cvs_handle;
659 /* Set media type. */
660 struct cvs_set_media_type_cmd cvs_set_media_cmd;
661
662 if (v == NULL) {
663 pr_err("%s: v is NULL\n", __func__);
664 return -EINVAL;
665 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700666 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700667
668 if (!apr_cvs) {
669 pr_err("%s: apr_cvs is NULL.\n", __func__);
670 return -EINVAL;
671 }
672
673 cvs_handle = voice_get_cvs_handle(v);
674
675 cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
676 APR_HDR_LEN(APR_HDR_SIZE),
677 APR_PKT_VER);
678 cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
679 sizeof(cvs_set_media_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700680 cvs_set_media_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700681 cvs_set_media_cmd.hdr.dest_port = cvs_handle;
682 cvs_set_media_cmd.hdr.token = 0;
683 cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700684 cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
685 cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686
687 v->cvs_state = CMD_STATUS_FAIL;
688
689 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
690 if (ret < 0) {
691 pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
692 __func__, ret);
693
694 goto fail;
695 }
696 ret = wait_event_timeout(v->cvs_wait,
697 (v->cvs_state == CMD_STATUS_SUCCESS),
698 msecs_to_jiffies(TIMEOUT_MS));
699 if (!ret) {
700 pr_err("%s: wait_event timeout\n", __func__);
701
702 goto fail;
703 }
704 /* Set encoder properties. */
Neema Shetty2c07eb52011-08-21 20:33:52 -0700705 switch (common.mvs_info.media_type) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700706 case VSS_MEDIA_ID_EVRC_MODEM: {
707 struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
708
709 pr_debug("Setting EVRC min-max rate\n");
710
711 cvs_set_cdma_rate.hdr.hdr_field =
712 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
713 APR_HDR_LEN(APR_HDR_SIZE),
714 APR_PKT_VER);
715 cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
716 sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700717 cvs_set_cdma_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
719 cvs_set_cdma_rate.hdr.token = 0;
720 cvs_set_cdma_rate.hdr.opcode =
721 VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700722 cvs_set_cdma_rate.cdma_rate.min_rate = common.mvs_info.rate;
723 cvs_set_cdma_rate.cdma_rate.max_rate = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724
725 v->cvs_state = CMD_STATUS_FAIL;
726
727 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
728 if (ret < 0) {
729 pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
730 __func__, ret);
731 goto fail;
732 }
733 ret = wait_event_timeout(v->cvs_wait,
734 (v->cvs_state == CMD_STATUS_SUCCESS),
735 msecs_to_jiffies(TIMEOUT_MS));
736 if (!ret) {
737 pr_err("%s: wait_event timeout\n", __func__);
738
739 goto fail;
740 }
741 break;
742 }
743 case VSS_MEDIA_ID_AMR_NB_MODEM: {
744 struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
745 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
746
747 pr_debug("Setting AMR rate\n");
748
749 cvs_set_amr_rate.hdr.hdr_field =
750 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
751 APR_HDR_LEN(APR_HDR_SIZE),
752 APR_PKT_VER);
753 cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
754 sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700755 cvs_set_amr_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 cvs_set_amr_rate.hdr.dest_port = cvs_handle;
757 cvs_set_amr_rate.hdr.token = 0;
758 cvs_set_amr_rate.hdr.opcode =
759 VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700760 cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700761
762 v->cvs_state = CMD_STATUS_FAIL;
763
764 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
765 if (ret < 0) {
766 pr_err("%s: Error %d sending SET_AMR_RATE\n",
767 __func__, ret);
768 goto fail;
769 }
770 ret = wait_event_timeout(v->cvs_wait,
771 (v->cvs_state == CMD_STATUS_SUCCESS),
772 msecs_to_jiffies(TIMEOUT_MS));
773 if (!ret) {
774 pr_err("%s: wait_event timeout\n", __func__);
775 goto fail;
776 }
777 /* Disable DTX */
778 pr_debug("Disabling DTX\n");
779
780 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
781 APR_HDR_LEN(APR_HDR_SIZE),
782 APR_PKT_VER);
783 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
784 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700785 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700786 cvs_set_dtx.hdr.dest_port = cvs_handle;
787 cvs_set_dtx.hdr.token = 0;
788 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
789 cvs_set_dtx.dtx_mode.enable = 0;
790
791 v->cvs_state = CMD_STATUS_FAIL;
792
793 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
794 if (ret < 0) {
795 pr_err("%s: Error %d sending SET_DTX\n",
796 __func__, ret);
797 goto fail;
798 }
799 ret = wait_event_timeout(v->cvs_wait,
800 (v->cvs_state == CMD_STATUS_SUCCESS),
801 msecs_to_jiffies(TIMEOUT_MS));
802 if (!ret) {
803 pr_err("%s: wait_event timeout\n", __func__);
804 goto fail;
805 }
806 break;
807 }
808 case VSS_MEDIA_ID_AMR_WB_MODEM: {
809 struct cvs_set_amrwb_enc_rate_cmd cvs_set_amrwb_rate;
810 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
811
812 pr_debug("Setting AMR WB rate\n");
813
814 cvs_set_amrwb_rate.hdr.hdr_field =
815 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
816 APR_HDR_LEN(APR_HDR_SIZE),
817 APR_PKT_VER);
818 cvs_set_amrwb_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
819 sizeof(cvs_set_amrwb_rate) -
820 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700821 cvs_set_amrwb_rate.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700822 cvs_set_amrwb_rate.hdr.dest_port = cvs_handle;
823 cvs_set_amrwb_rate.hdr.token = 0;
824 cvs_set_amrwb_rate.hdr.opcode =
825 VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
Neema Shetty2c07eb52011-08-21 20:33:52 -0700826 cvs_set_amrwb_rate.amrwb_rate.mode = common.mvs_info.rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827
828 v->cvs_state = CMD_STATUS_FAIL;
829
830 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amrwb_rate);
831 if (ret < 0) {
832 pr_err("%s: Error %d sending SET_AMRWB_RATE\n",
833 __func__, ret);
834 goto fail;
835 }
836 ret = wait_event_timeout(v->cvs_wait,
837 (v->cvs_state == CMD_STATUS_SUCCESS),
838 msecs_to_jiffies(TIMEOUT_MS));
839 if (!ret) {
840 pr_err("%s: wait_event timeout\n", __func__);
841 goto fail;
842 }
843 /* Disable DTX */
844 pr_debug("Disabling DTX\n");
845
846 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
847 APR_HDR_LEN(APR_HDR_SIZE),
848 APR_PKT_VER);
849 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
850 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700851 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 cvs_set_dtx.hdr.dest_port = cvs_handle;
853 cvs_set_dtx.hdr.token = 0;
854 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
855 cvs_set_dtx.dtx_mode.enable = 0;
856
857 v->cvs_state = CMD_STATUS_FAIL;
858
859 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
860 if (ret < 0) {
861 pr_err("%s: Error %d sending SET_DTX\n",
862 __func__, ret);
863 goto fail;
864 }
865 ret = wait_event_timeout(v->cvs_wait,
866 (v->cvs_state == CMD_STATUS_SUCCESS),
867 msecs_to_jiffies(TIMEOUT_MS));
868 if (!ret) {
869 pr_err("%s: wait_event timeout\n", __func__);
870 goto fail;
871 }
872 break;
873 }
874 case VSS_MEDIA_ID_G729:
875 case VSS_MEDIA_ID_G711_ALAW:
876 case VSS_MEDIA_ID_G711_MULAW: {
877 struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
878 /* Disable DTX */
879 pr_debug("Disabling DTX\n");
880
881 cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
882 APR_HDR_LEN(APR_HDR_SIZE),
883 APR_PKT_VER);
884 cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
885 sizeof(cvs_set_dtx) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700886 cvs_set_dtx.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 cvs_set_dtx.hdr.dest_port = cvs_handle;
888 cvs_set_dtx.hdr.token = 0;
889 cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
890 cvs_set_dtx.dtx_mode.enable = 0;
891
892 v->cvs_state = CMD_STATUS_FAIL;
893
894 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
895 if (ret < 0) {
896 pr_err("%s: Error %d sending SET_DTX\n",
897 __func__, ret);
898 goto fail;
899 }
900 ret = wait_event_timeout(v->cvs_wait,
901 (v->cvs_state == CMD_STATUS_SUCCESS),
902 msecs_to_jiffies(TIMEOUT_MS));
903 if (!ret) {
904 pr_err("%s: wait_event timeout\n", __func__);
905 goto fail;
906 }
907 break;
908 }
909 default:
910 /* Do nothing. */
911 break;
912 }
913 return 0;
914
915fail:
916 return -EINVAL;
917}
918
919static int voice_send_start_voice_cmd(struct voice_data *v)
920{
921 struct apr_hdr mvm_start_voice_cmd;
922 int ret = 0;
923 void *apr_mvm;
924 u16 mvm_handle;
925
926 if (v == NULL) {
927 pr_err("%s: v is NULL\n", __func__);
928 return -EINVAL;
929 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700930 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931
932 if (!apr_mvm) {
933 pr_err("%s: apr_mvm is NULL.\n", __func__);
934 return -EINVAL;
935 }
936 mvm_handle = voice_get_mvm_handle(v);
937
938 mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
939 APR_HDR_LEN(APR_HDR_SIZE),
940 APR_PKT_VER);
941 mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
942 sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
943 pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
944 mvm_start_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700945 mvm_start_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700946 mvm_start_voice_cmd.dest_port = mvm_handle;
947 mvm_start_voice_cmd.token = 0;
948 mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
949
950 v->mvm_state = CMD_STATUS_FAIL;
951 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
952 if (ret < 0) {
953 pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
954 goto fail;
955 }
956 ret = wait_event_timeout(v->mvm_wait,
957 (v->mvm_state == CMD_STATUS_SUCCESS),
958 msecs_to_jiffies(TIMEOUT_MS));
959 if (!ret) {
960 pr_err("%s: wait_event timeout\n", __func__);
961 goto fail;
962 }
963 return 0;
964fail:
965 return -EINVAL;
966}
967
968static int voice_send_disable_vocproc_cmd(struct voice_data *v)
969{
970 struct apr_hdr cvp_disable_cmd;
971 int ret = 0;
972 void *apr_cvp;
973 u16 cvp_handle;
974
975 if (v == NULL) {
976 pr_err("%s: v is NULL\n", __func__);
977 return -EINVAL;
978 }
Neema Shetty2c07eb52011-08-21 20:33:52 -0700979 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980
981 if (!apr_cvp) {
982 pr_err("%s: apr regist failed\n", __func__);
983 return -EINVAL;
984 }
985 cvp_handle = voice_get_cvp_handle(v);
986
987 /* disable vocproc and wait for respose */
988 cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
989 APR_HDR_LEN(APR_HDR_SIZE),
990 APR_PKT_VER);
991 cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
992 sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
993 pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
994 cvp_disable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -0700995 cvp_disable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996 cvp_disable_cmd.dest_port = cvp_handle;
997 cvp_disable_cmd.token = 0;
998 cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
999
1000 v->cvp_state = CMD_STATUS_FAIL;
1001 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
1002 if (ret < 0) {
1003 pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
1004 goto fail;
1005 }
1006 ret = wait_event_timeout(v->cvp_wait,
1007 (v->cvp_state == CMD_STATUS_SUCCESS),
1008 msecs_to_jiffies(TIMEOUT_MS));
1009 if (!ret) {
1010 pr_err("%s: wait_event timeout\n", __func__);
1011 goto fail;
1012 }
1013
1014 return 0;
1015fail:
1016 return -EINVAL;
1017}
1018
1019static int voice_send_set_device_cmd(struct voice_data *v)
1020{
1021 struct cvp_set_device_cmd cvp_setdev_cmd;
1022 int ret = 0;
1023 void *apr_cvp;
1024 u16 cvp_handle;
1025
1026 if (v == NULL) {
1027 pr_err("%s: v is NULL\n", __func__);
1028 return -EINVAL;
1029 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001030 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001031
1032 if (!apr_cvp) {
1033 pr_err("%s: apr_cvp is NULL.\n", __func__);
1034 return -EINVAL;
1035 }
1036 cvp_handle = voice_get_cvp_handle(v);
1037
1038 /* set device and wait for response */
1039 cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1040 APR_HDR_LEN(APR_HDR_SIZE),
1041 APR_PKT_VER);
1042 cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1043 sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
1044 pr_debug(" send create cvp setdev, pkt size = %d\n",
1045 cvp_setdev_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001046 cvp_setdev_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001047 cvp_setdev_cmd.hdr.dest_port = cvp_handle;
1048 cvp_setdev_cmd.hdr.token = 0;
1049 cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE;
1050
1051 /* Use default topology if invalid value in ACDB */
1052 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1053 get_voice_tx_topology();
1054 if (cvp_setdev_cmd.cvp_set_device.tx_topology_id == 0)
1055 cvp_setdev_cmd.cvp_set_device.tx_topology_id =
1056 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1057
1058 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1059 get_voice_rx_topology();
1060 if (cvp_setdev_cmd.cvp_set_device.rx_topology_id == 0)
1061 cvp_setdev_cmd.cvp_set_device.rx_topology_id =
1062 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1063 cvp_setdev_cmd.cvp_set_device.tx_port_id = v->dev_tx.port_id;
1064 cvp_setdev_cmd.cvp_set_device.rx_port_id = v->dev_rx.port_id;
1065 pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
1066 cvp_setdev_cmd.cvp_set_device.tx_topology_id,
1067 cvp_setdev_cmd.cvp_set_device.tx_port_id,
1068 cvp_setdev_cmd.cvp_set_device.rx_port_id);
1069
1070 v->cvp_state = CMD_STATUS_FAIL;
1071 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
1072 if (ret < 0) {
1073 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1074 goto fail;
1075 }
1076 pr_debug("wait for cvp create session event\n");
1077 ret = wait_event_timeout(v->cvp_wait,
1078 (v->cvp_state == CMD_STATUS_SUCCESS),
1079 msecs_to_jiffies(TIMEOUT_MS));
1080 if (!ret) {
1081 pr_err("%s: wait_event timeout\n", __func__);
1082 goto fail;
1083 }
1084
1085 return 0;
1086fail:
1087 return -EINVAL;
1088}
1089
1090static int voice_send_stop_voice_cmd(struct voice_data *v)
1091{
1092 struct apr_hdr mvm_stop_voice_cmd;
1093 int ret = 0;
1094 void *apr_mvm;
1095 u16 mvm_handle;
1096
1097 if (v == NULL) {
1098 pr_err("%s: v is NULL\n", __func__);
1099 return -EINVAL;
1100 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001101 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001102
1103 if (!apr_mvm) {
1104 pr_err("%s: apr_mvm is NULL.\n", __func__);
1105 return -EINVAL;
1106 }
1107 mvm_handle = voice_get_mvm_handle(v);
1108
1109 mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1110 APR_HDR_LEN(APR_HDR_SIZE),
1111 APR_PKT_VER);
1112 mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1113 sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
1114 pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
1115 mvm_stop_voice_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001116 mvm_stop_voice_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001117 mvm_stop_voice_cmd.dest_port = mvm_handle;
1118 mvm_stop_voice_cmd.token = 0;
1119 mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
1120
1121 v->mvm_state = CMD_STATUS_FAIL;
1122 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
1123 if (ret < 0) {
1124 pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
1125 goto fail;
1126 }
1127 ret = wait_event_timeout(v->mvm_wait,
1128 (v->mvm_state == CMD_STATUS_SUCCESS),
1129 msecs_to_jiffies(TIMEOUT_MS));
1130 if (!ret) {
1131 pr_err("%s: wait_event timeout\n", __func__);
1132 goto fail;
1133 }
1134
1135 return 0;
1136fail:
1137 return -EINVAL;
1138}
1139
Helen Zeng29eb7442011-06-20 11:06:29 -07001140static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
1141{
1142 struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
1143 struct acdb_cal_block cal_block;
1144 int ret = 0;
1145 void *apr_cvs;
1146 u16 cvs_handle;
1147
1148 /* get the cvs cal data */
1149 get_all_vocstrm_cal(&cal_block);
1150 if (cal_block.cal_size == 0)
1151 goto fail;
1152
1153 if (v == NULL) {
1154 pr_err("%s: v is NULL\n", __func__);
1155 return -EINVAL;
1156 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001157 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001158
1159 if (!apr_cvs) {
1160 pr_err("%s: apr_cvs is NULL.\n", __func__);
1161 return -EINVAL;
1162 }
1163 cvs_handle = voice_get_cvs_handle(v);
1164
1165 /* fill in the header */
1166 cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1167 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1168 cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1169 sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001170 cvs_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001171 cvs_reg_cal_cmd.hdr.dest_port = cvs_handle;
1172 cvs_reg_cal_cmd.hdr.token = 0;
1173 cvs_reg_cal_cmd.hdr.opcode = VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA;
1174
1175 cvs_reg_cal_cmd.cvs_cal_data.phys_addr = cal_block.cal_paddr;
1176 cvs_reg_cal_cmd.cvs_cal_data.mem_size = cal_block.cal_size;
1177
1178 v->cvs_state = CMD_STATUS_FAIL;
1179 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_reg_cal_cmd);
1180 if (ret < 0) {
1181 pr_err("Fail: sending cvs cal,\n");
1182 goto fail;
1183 }
1184 ret = wait_event_timeout(v->cvs_wait,
1185 (v->cvs_state == CMD_STATUS_SUCCESS),
1186 msecs_to_jiffies(TIMEOUT_MS));
1187 if (!ret) {
1188 pr_err("%s: wait_event timeout\n", __func__);
1189 goto fail;
1190 }
1191 return 0;
1192fail:
1193 return -EINVAL;
1194
1195}
1196
1197static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
1198{
1199 struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
1200 struct acdb_cal_block cal_block;
1201 int ret = 0;
1202 void *apr_cvs;
1203 u16 cvs_handle;
1204
1205 get_all_vocstrm_cal(&cal_block);
1206 if (cal_block.cal_size == 0)
1207 return 0;
1208
1209 if (v == NULL) {
1210 pr_err("%s: v is NULL\n", __func__);
1211 return -EINVAL;
1212 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001213 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001214
1215 if (!apr_cvs) {
1216 pr_err("%s: apr_cvs is NULL.\n", __func__);
1217 return -EINVAL;
1218 }
1219 cvs_handle = voice_get_cvs_handle(v);
1220
1221 /* fill in the header */
1222 cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1223 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1224 cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1225 sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001226 cvs_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001227 cvs_dereg_cal_cmd.hdr.dest_port = cvs_handle;
1228 cvs_dereg_cal_cmd.hdr.token = 0;
1229 cvs_dereg_cal_cmd.hdr.opcode =
1230 VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
1231
1232 v->cvs_state = CMD_STATUS_FAIL;
1233 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
1234 if (ret < 0) {
1235 pr_err("Fail: sending cvs cal,\n");
1236 goto fail;
1237 }
1238 ret = wait_event_timeout(v->cvs_wait,
1239 (v->cvs_state == CMD_STATUS_SUCCESS),
1240 msecs_to_jiffies(TIMEOUT_MS));
1241 if (!ret) {
1242 pr_err("%s: wait_event timeout\n", __func__);
1243 goto fail;
1244 }
1245 return 0;
1246fail:
1247 return -EINVAL;
1248
1249}
1250
1251static int voice_send_cvp_map_memory_cmd(struct voice_data *v)
1252{
1253 struct vss_map_memory_cmd cvp_map_mem_cmd;
1254 struct acdb_cal_block cal_block;
1255 int ret = 0;
1256 void *apr_cvp;
1257 u16 cvp_handle;
1258
1259 /* get all cvp cal data */
1260 get_all_cvp_cal(&cal_block);
1261 if (cal_block.cal_size == 0)
1262 goto fail;
1263
1264 if (v == NULL) {
1265 pr_err("%s: v is NULL\n", __func__);
1266 return -EINVAL;
1267 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001268 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001269
1270 if (!apr_cvp) {
1271 pr_err("%s: apr_cvp is NULL.\n", __func__);
1272 return -EINVAL;
1273 }
1274 cvp_handle = voice_get_cvp_handle(v);
1275
1276 /* fill in the header */
1277 cvp_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1278 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1279 cvp_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1280 sizeof(cvp_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001281 cvp_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001282 cvp_map_mem_cmd.hdr.dest_port = cvp_handle;
1283 cvp_map_mem_cmd.hdr.token = 0;
1284 cvp_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1285
1286 pr_debug("%s, phy_addr:%d, mem_size:%d\n", __func__,
1287 cal_block.cal_paddr, cal_block.cal_size);
1288 cvp_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1289 cvp_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1290 cvp_map_mem_cmd.vss_map_mem.mem_pool_id =
1291 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1292
1293 v->cvp_state = CMD_STATUS_FAIL;
1294 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_map_mem_cmd);
1295 if (ret < 0) {
1296 pr_err("Fail: sending cvp cal,\n");
1297 goto fail;
1298 }
1299 ret = wait_event_timeout(v->cvp_wait,
1300 (v->cvp_state == CMD_STATUS_SUCCESS),
1301 msecs_to_jiffies(TIMEOUT_MS));
1302 if (!ret) {
1303 pr_err("%s: wait_event timeout\n", __func__);
1304 goto fail;
1305 }
1306 return 0;
1307fail:
1308 return -EINVAL;
1309
1310}
1311
1312static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v)
1313{
1314 struct vss_unmap_memory_cmd cvp_unmap_mem_cmd;
1315 struct acdb_cal_block cal_block;
1316 int ret = 0;
1317 void *apr_cvp;
1318 u16 cvp_handle;
1319
1320 get_all_cvp_cal(&cal_block);
1321 if (cal_block.cal_size == 0)
1322 return 0;
1323
1324 if (v == NULL) {
1325 pr_err("%s: v is NULL\n", __func__);
1326 return -EINVAL;
1327 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001328 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001329
1330 if (!apr_cvp) {
1331 pr_err("%s: apr_cvp is NULL.\n", __func__);
1332 return -EINVAL;
1333 }
1334 cvp_handle = voice_get_cvp_handle(v);
1335
1336 /* fill in the header */
1337 cvp_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1338 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1339 cvp_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1340 sizeof(cvp_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001341 cvp_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001342 cvp_unmap_mem_cmd.hdr.dest_port = cvp_handle;
1343 cvp_unmap_mem_cmd.hdr.token = 0;
1344 cvp_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1345
1346 cvp_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1347
1348 v->cvp_state = CMD_STATUS_FAIL;
1349 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_unmap_mem_cmd);
1350 if (ret < 0) {
1351 pr_err("Fail: sending cvp cal,\n");
1352 goto fail;
1353 }
1354 ret = wait_event_timeout(v->cvp_wait,
1355 (v->cvp_state == CMD_STATUS_SUCCESS),
1356 msecs_to_jiffies(TIMEOUT_MS));
1357 if (!ret) {
1358 pr_err("%s: wait_event timeout\n", __func__);
1359 goto fail;
1360 }
1361 return 0;
1362fail:
1363 return -EINVAL;
1364
1365}
1366
1367static int voice_send_cvs_map_memory_cmd(struct voice_data *v)
1368{
1369 struct vss_map_memory_cmd cvs_map_mem_cmd;
1370 struct acdb_cal_block cal_block;
1371 int ret = 0;
1372 void *apr_cvs;
1373 u16 cvs_handle;
1374
1375 /* get all cvs cal data */
1376 get_all_vocstrm_cal(&cal_block);
1377 if (cal_block.cal_size == 0)
1378 goto fail;
1379
1380 if (v == NULL) {
1381 pr_err("%s: v is NULL\n", __func__);
1382 return -EINVAL;
1383 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001384 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001385
1386 if (!apr_cvs) {
1387 pr_err("%s: apr_cvs is NULL.\n", __func__);
1388 return -EINVAL;
1389 }
1390 cvs_handle = voice_get_cvs_handle(v);
1391
1392 /* fill in the header */
1393 cvs_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1394 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1395 cvs_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1396 sizeof(cvs_map_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001397 cvs_map_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001398 cvs_map_mem_cmd.hdr.dest_port = cvs_handle;
1399 cvs_map_mem_cmd.hdr.token = 0;
1400 cvs_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
1401
1402 pr_debug("%s, phys_addr: %d, mem_size: %d\n", __func__,
1403 cal_block.cal_paddr, cal_block.cal_size);
1404 cvs_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr;
1405 cvs_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
1406 cvs_map_mem_cmd.vss_map_mem.mem_pool_id =
1407 VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
1408
1409 v->cvs_state = CMD_STATUS_FAIL;
1410 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_map_mem_cmd);
1411 if (ret < 0) {
1412 pr_err("Fail: sending cvs cal,\n");
1413 goto fail;
1414 }
1415 ret = wait_event_timeout(v->cvs_wait,
1416 (v->cvs_state == CMD_STATUS_SUCCESS),
1417 msecs_to_jiffies(TIMEOUT_MS));
1418 if (!ret) {
1419 pr_err("%s: wait_event timeout\n", __func__);
1420 goto fail;
1421 }
1422 return 0;
1423fail:
1424 return -EINVAL;
1425
1426}
1427
1428static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v)
1429{
1430 struct vss_unmap_memory_cmd cvs_unmap_mem_cmd;
1431 struct acdb_cal_block cal_block;
1432 int ret = 0;
1433 void *apr_cvs;
1434 u16 cvs_handle;
1435
1436 get_all_vocstrm_cal(&cal_block);
1437 if (cal_block.cal_size == 0)
1438 return 0;
1439
1440 if (v == NULL) {
1441 pr_err("%s: v is NULL\n", __func__);
1442 return -EINVAL;
1443 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001444 apr_cvs = common.apr_q6_cvs;
Helen Zeng29eb7442011-06-20 11:06:29 -07001445
1446 if (!apr_cvs) {
1447 pr_err("%s: apr_cvs is NULL.\n", __func__);
1448 return -EINVAL;
1449 }
1450 cvs_handle = voice_get_cvs_handle(v);
1451
1452 /* fill in the header */
1453 cvs_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1454 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1455 cvs_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1456 sizeof(cvs_unmap_mem_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001457 cvs_unmap_mem_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001458 cvs_unmap_mem_cmd.hdr.dest_port = cvs_handle;
1459 cvs_unmap_mem_cmd.hdr.token = 0;
1460 cvs_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
1461
1462 cvs_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr;
1463
1464 v->cvs_state = CMD_STATUS_FAIL;
1465 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_unmap_mem_cmd);
1466 if (ret < 0) {
1467 pr_err("Fail: sending cvs cal,\n");
1468 goto fail;
1469 }
1470 ret = wait_event_timeout(v->cvs_wait,
1471 (v->cvs_state == CMD_STATUS_SUCCESS),
1472 msecs_to_jiffies(TIMEOUT_MS));
1473 if (!ret) {
1474 pr_err("%s: wait_event timeout\n", __func__);
1475 goto fail;
1476 }
1477 return 0;
1478fail:
1479 return -EINVAL;
1480
1481}
1482
1483static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
1484{
1485 struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
1486 struct acdb_cal_block cal_block;
1487 int ret = 0;
1488 void *apr_cvp;
1489 u16 cvp_handle;
1490
1491 /* get the cvp cal data */
1492 get_all_vocproc_cal(&cal_block);
1493 if (cal_block.cal_size == 0)
1494 goto fail;
1495
1496 if (v == NULL) {
1497 pr_err("%s: v is NULL\n", __func__);
1498 return -EINVAL;
1499 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001500 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001501
1502 if (!apr_cvp) {
1503 pr_err("%s: apr_cvp is NULL.\n", __func__);
1504 return -EINVAL;
1505 }
1506 cvp_handle = voice_get_cvp_handle(v);
1507
1508 /* fill in the header */
1509 cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1510 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1511 cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1512 sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001513 cvp_reg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001514 cvp_reg_cal_cmd.hdr.dest_port = cvp_handle;
1515 cvp_reg_cal_cmd.hdr.token = 0;
1516 cvp_reg_cal_cmd.hdr.opcode = VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA;
1517
1518 cvp_reg_cal_cmd.cvp_cal_data.phys_addr = cal_block.cal_paddr;
1519 cvp_reg_cal_cmd.cvp_cal_data.mem_size = cal_block.cal_size;
1520
1521 v->cvp_state = CMD_STATUS_FAIL;
1522 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_cmd);
1523 if (ret < 0) {
1524 pr_err("Fail: sending cvp cal,\n");
1525 goto fail;
1526 }
1527 ret = wait_event_timeout(v->cvp_wait,
1528 (v->cvp_state == CMD_STATUS_SUCCESS),
1529 msecs_to_jiffies(TIMEOUT_MS));
1530 if (!ret) {
1531 pr_err("%s: wait_event timeout\n", __func__);
1532 goto fail;
1533 }
1534 return 0;
1535fail:
1536 return -EINVAL;
1537
1538}
1539
1540static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
1541{
1542 struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
1543 struct acdb_cal_block cal_block;
1544 int ret = 0;
1545 void *apr_cvp;
1546 u16 cvp_handle;
1547
1548 get_all_vocproc_cal(&cal_block);
1549 if (cal_block.cal_size == 0)
1550 return 0;
1551
1552 if (v == NULL) {
1553 pr_err("%s: v is NULL\n", __func__);
1554 return -EINVAL;
1555 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001556 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001557
1558 if (!apr_cvp) {
1559 pr_err("%s: apr_cvp is NULL.\n", __func__);
1560 return -EINVAL;
1561 }
1562 cvp_handle = voice_get_cvp_handle(v);
1563
1564 /* fill in the header */
1565 cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1566 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1567 cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1568 sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001569 cvp_dereg_cal_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001570 cvp_dereg_cal_cmd.hdr.dest_port = cvp_handle;
1571 cvp_dereg_cal_cmd.hdr.token = 0;
1572 cvp_dereg_cal_cmd.hdr.opcode =
1573 VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
1574
1575 v->cvp_state = CMD_STATUS_FAIL;
1576 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
1577 if (ret < 0) {
1578 pr_err("Fail: sending cvp cal,\n");
1579 goto fail;
1580 }
1581 ret = wait_event_timeout(v->cvp_wait,
1582 (v->cvp_state == CMD_STATUS_SUCCESS),
1583 msecs_to_jiffies(TIMEOUT_MS));
1584 if (!ret) {
1585 pr_err("%s: wait_event timeout\n", __func__);
1586 goto fail;
1587 }
1588 return 0;
1589fail:
1590 return -EINVAL;
1591
1592}
1593
1594static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v)
1595{
1596 struct cvp_register_vol_cal_table_cmd cvp_reg_cal_tbl_cmd;
1597 struct acdb_cal_block cal_block;
1598 int ret = 0;
1599 void *apr_cvp;
1600 u16 cvp_handle;
1601
1602 /* get the cvp vol cal data */
1603 get_all_vocvol_cal(&cal_block);
1604 if (cal_block.cal_size == 0)
1605 goto fail;
1606
1607 if (v == NULL) {
1608 pr_err("%s: v is NULL\n", __func__);
1609 return -EINVAL;
1610 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001611 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001612
1613 if (!apr_cvp) {
1614 pr_err("%s: apr_cvp is NULL.\n", __func__);
1615 return -EINVAL;
1616 }
1617 cvp_handle = voice_get_cvp_handle(v);
1618
1619 /* fill in the header */
1620 cvp_reg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1621 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1622 cvp_reg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1623 sizeof(cvp_reg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001624 cvp_reg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001625 cvp_reg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1626 cvp_reg_cal_tbl_cmd.hdr.token = 0;
1627 cvp_reg_cal_tbl_cmd.hdr.opcode =
1628 VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE;
1629
1630 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.phys_addr = cal_block.cal_paddr;
1631 cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.mem_size = cal_block.cal_size;
1632
1633 v->cvp_state = CMD_STATUS_FAIL;
1634 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_tbl_cmd);
1635 if (ret < 0) {
1636 pr_err("Fail: sending cvp cal table,\n");
1637 goto fail;
1638 }
1639 ret = wait_event_timeout(v->cvp_wait,
1640 (v->cvp_state == CMD_STATUS_SUCCESS),
1641 msecs_to_jiffies(TIMEOUT_MS));
1642 if (!ret) {
1643 pr_err("%s: wait_event timeout\n", __func__);
1644 goto fail;
1645 }
1646 return 0;
1647fail:
1648 return -EINVAL;
1649
1650}
1651
1652static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v)
1653{
1654 struct cvp_deregister_vol_cal_table_cmd cvp_dereg_cal_tbl_cmd;
1655 struct acdb_cal_block cal_block;
1656 int ret = 0;
1657 void *apr_cvp;
1658 u16 cvp_handle;
1659
1660 get_all_vocvol_cal(&cal_block);
1661 if (cal_block.cal_size == 0)
1662 return 0;
1663
1664 if (v == NULL) {
1665 pr_err("%s: v is NULL\n", __func__);
1666 return -EINVAL;
1667 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001668 apr_cvp = common.apr_q6_cvp;
Helen Zeng29eb7442011-06-20 11:06:29 -07001669
1670 if (!apr_cvp) {
1671 pr_err("%s: apr_cvp is NULL.\n", __func__);
1672 return -EINVAL;
1673 }
1674 cvp_handle = voice_get_cvp_handle(v);
1675
1676 /* fill in the header */
1677 cvp_dereg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(
1678 APR_MSG_TYPE_SEQ_CMD,
1679 APR_HDR_LEN(APR_HDR_SIZE),
1680 APR_PKT_VER);
1681 cvp_dereg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1682 sizeof(cvp_dereg_cal_tbl_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001683 cvp_dereg_cal_tbl_cmd.hdr.src_port = v->session_id;
Helen Zeng29eb7442011-06-20 11:06:29 -07001684 cvp_dereg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
1685 cvp_dereg_cal_tbl_cmd.hdr.token = 0;
1686 cvp_dereg_cal_tbl_cmd.hdr.opcode =
1687 VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE;
1688
1689 v->cvp_state = CMD_STATUS_FAIL;
1690 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_tbl_cmd);
1691 if (ret < 0) {
1692 pr_err("Fail: sending cvp cal table,\n");
1693 goto fail;
1694 }
1695 ret = wait_event_timeout(v->cvp_wait,
1696 (v->cvp_state == CMD_STATUS_SUCCESS),
1697 msecs_to_jiffies(TIMEOUT_MS));
1698 if (!ret) {
1699 pr_err("%s: wait_event timeout\n", __func__);
1700 goto fail;
1701 }
1702 return 0;
1703fail:
1704 return -EINVAL;
1705
1706}
Neema Shetty2c07eb52011-08-21 20:33:52 -07001707
Helen Zeng44d4d272011-08-10 14:49:20 -07001708static int voice_send_set_widevoice_enable_cmd(struct voice_data *v)
1709{
1710 struct mvm_set_widevoice_enable_cmd mvm_set_wv_cmd;
1711 int ret = 0;
1712 void *apr_mvm;
1713 u16 mvm_handle;
1714
1715 if (v == NULL) {
1716 pr_err("%s: v is NULL\n", __func__);
1717 return -EINVAL;
1718 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001719 apr_mvm = common.apr_q6_mvm;
Helen Zeng44d4d272011-08-10 14:49:20 -07001720
1721 if (!apr_mvm) {
1722 pr_err("%s: apr_mvm is NULL.\n", __func__);
1723 return -EINVAL;
1724 }
1725 mvm_handle = voice_get_mvm_handle(v);
1726
1727 /* fill in the header */
1728 mvm_set_wv_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1729 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1730 mvm_set_wv_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1731 sizeof(mvm_set_wv_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001732 mvm_set_wv_cmd.hdr.src_port = v->session_id;
Helen Zeng44d4d272011-08-10 14:49:20 -07001733 mvm_set_wv_cmd.hdr.dest_port = mvm_handle;
1734 mvm_set_wv_cmd.hdr.token = 0;
1735 mvm_set_wv_cmd.hdr.opcode = VSS_IWIDEVOICE_CMD_SET_WIDEVOICE;
1736
1737 mvm_set_wv_cmd.vss_set_wv.enable = v->wv_enable;
1738
1739 v->mvm_state = CMD_STATUS_FAIL;
1740 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_wv_cmd);
1741 if (ret < 0) {
1742 pr_err("Fail: sending mvm set widevoice enable,\n");
1743 goto fail;
1744 }
1745 ret = wait_event_timeout(v->mvm_wait,
1746 (v->mvm_state == CMD_STATUS_SUCCESS),
1747 msecs_to_jiffies(TIMEOUT_MS));
1748 if (!ret) {
1749 pr_err("%s: wait_event timeout\n", __func__);
1750 goto fail;
1751 }
1752 return 0;
1753fail:
1754 return -EINVAL;
1755}
1756
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001757static int voice_setup_vocproc(struct voice_data *v)
1758{
1759 struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
1760 int ret = 0;
1761 void *apr_cvp;
1762 if (v == NULL) {
1763 pr_err("%s: v is NULL\n", __func__);
1764 return -EINVAL;
1765 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001766 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001767
1768 if (!apr_cvp) {
1769 pr_err("%s: apr_cvp is NULL.\n", __func__);
1770 return -EINVAL;
1771 }
1772
1773 /* create cvp session and wait for response */
1774 cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1775 APR_HDR_LEN(APR_HDR_SIZE),
1776 APR_PKT_VER);
1777 cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1778 sizeof(cvp_session_cmd) - APR_HDR_SIZE);
1779 pr_debug(" send create cvp session, pkt size = %d\n",
1780 cvp_session_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001781 cvp_session_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001782 cvp_session_cmd.hdr.dest_port = 0;
1783 cvp_session_cmd.hdr.token = 0;
1784 cvp_session_cmd.hdr.opcode =
1785 VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION;
1786
1787 /* Use default topology if invalid value in ACDB */
1788 cvp_session_cmd.cvp_session.tx_topology_id =
1789 get_voice_tx_topology();
1790 if (cvp_session_cmd.cvp_session.tx_topology_id == 0)
1791 cvp_session_cmd.cvp_session.tx_topology_id =
1792 VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
1793
1794 cvp_session_cmd.cvp_session.rx_topology_id =
1795 get_voice_rx_topology();
1796 if (cvp_session_cmd.cvp_session.rx_topology_id == 0)
1797 cvp_session_cmd.cvp_session.rx_topology_id =
1798 VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
1799
1800 cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
1801 cvp_session_cmd.cvp_session.network_id = VSS_NETWORK_ID_DEFAULT;
1802 cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
1803 cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
1804
1805 pr_debug("topology=%d net_id=%d, dir=%d tx_port_id=%d, rx_port_id=%d\n",
1806 cvp_session_cmd.cvp_session.tx_topology_id,
1807 cvp_session_cmd.cvp_session.network_id,
1808 cvp_session_cmd.cvp_session.direction,
1809 cvp_session_cmd.cvp_session.tx_port_id,
1810 cvp_session_cmd.cvp_session.rx_port_id);
1811
1812 v->cvp_state = CMD_STATUS_FAIL;
1813 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
1814 if (ret < 0) {
1815 pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
1816 goto fail;
1817 }
1818 ret = wait_event_timeout(v->cvp_wait,
1819 (v->cvp_state == CMD_STATUS_SUCCESS),
1820 msecs_to_jiffies(TIMEOUT_MS));
1821 if (!ret) {
1822 pr_err("%s: wait_event timeout\n", __func__);
1823 goto fail;
1824 }
1825
Helen Zeng29eb7442011-06-20 11:06:29 -07001826 /* send cvs cal */
1827 ret = voice_send_cvs_map_memory_cmd(v);
1828 if (!ret)
1829 voice_send_cvs_register_cal_cmd(v);
1830
1831 /* send cvp and vol cal */
1832 ret = voice_send_cvp_map_memory_cmd(v);
1833 if (!ret) {
1834 voice_send_cvp_register_cal_cmd(v);
1835 voice_send_cvp_register_vol_cal_table_cmd(v);
1836 }
1837
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001838 /* enable vocproc */
1839 ret = voice_send_enable_vocproc_cmd(v);
1840 if (ret < 0)
1841 goto fail;
1842
1843 /* attach vocproc */
1844 ret = voice_send_attach_vocproc_cmd(v);
1845 if (ret < 0)
1846 goto fail;
1847
1848 /* send tty mode if tty device is used */
1849 voice_send_tty_mode_cmd(v);
1850
Helen Zeng44d4d272011-08-10 14:49:20 -07001851 /* enable widevoice if wv_enable is set */
1852 if (v->wv_enable)
1853 voice_send_set_widevoice_enable_cmd(v);
1854
Neema Shetty2c07eb52011-08-21 20:33:52 -07001855 if (is_voip_session(v->session_id))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001856 voice_send_netid_timing_cmd(v);
1857
Ben Romberger13b74ab2011-07-18 17:36:32 -07001858 rtac_add_voice(voice_get_cvs_handle(v),
1859 voice_get_cvp_handle(v),
1860 v->dev_rx.port_id, v->dev_tx.port_id);
1861
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001862 return 0;
1863
1864fail:
1865 return -EINVAL;
1866}
1867
1868static int voice_send_enable_vocproc_cmd(struct voice_data *v)
1869{
1870 int ret = 0;
1871 struct apr_hdr cvp_enable_cmd;
1872 void *apr_cvp;
1873 u16 cvp_handle;
1874
1875 if (v == NULL) {
1876 pr_err("%s: v is NULL\n", __func__);
1877 return -EINVAL;
1878 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001879 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001880
1881 if (!apr_cvp) {
1882 pr_err("%s: apr_cvp is NULL.\n", __func__);
1883 return -EINVAL;
1884 }
1885 cvp_handle = voice_get_cvp_handle(v);
1886
1887 /* enable vocproc and wait for respose */
1888 cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1889 APR_HDR_LEN(APR_HDR_SIZE),
1890 APR_PKT_VER);
1891 cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1892 sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
1893 pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
1894 cvp_enable_cmd.pkt_size, cvp_handle);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001895 cvp_enable_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001896 cvp_enable_cmd.dest_port = cvp_handle;
1897 cvp_enable_cmd.token = 0;
1898 cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
1899
1900 v->cvp_state = CMD_STATUS_FAIL;
1901 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
1902 if (ret < 0) {
1903 pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
1904 goto fail;
1905 }
1906 ret = wait_event_timeout(v->cvp_wait,
1907 (v->cvp_state == CMD_STATUS_SUCCESS),
1908 msecs_to_jiffies(TIMEOUT_MS));
1909 if (!ret) {
1910 pr_err("%s: wait_event timeout\n", __func__);
1911 goto fail;
1912 }
1913
1914 return 0;
1915fail:
1916 return -EINVAL;
1917}
1918
1919static int voice_send_netid_timing_cmd(struct voice_data *v)
1920{
1921 int ret = 0;
1922 void *apr_mvm;
1923 u16 mvm_handle;
1924 struct mvm_set_network_cmd mvm_set_network;
1925 struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
1926
1927 if (v == NULL) {
1928 pr_err("%s: v is NULL\n", __func__);
1929 return -EINVAL;
1930 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07001931 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001932
1933 if (!apr_mvm) {
1934 pr_err("%s: apr_mvm is NULL.\n", __func__);
1935 return -EINVAL;
1936 }
1937 mvm_handle = voice_get_mvm_handle(v);
1938
1939 ret = voice_config_cvs_vocoder(v);
1940 if (ret < 0) {
1941 pr_err("%s: Error %d configuring CVS voc",
1942 __func__, ret);
1943 goto fail;
1944 }
1945 /* Set network ID. */
1946 pr_debug("Setting network ID\n");
1947
1948 mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1949 APR_HDR_LEN(APR_HDR_SIZE),
1950 APR_PKT_VER);
1951 mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1952 sizeof(mvm_set_network) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001953 mvm_set_network.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001954 mvm_set_network.hdr.dest_port = mvm_handle;
1955 mvm_set_network.hdr.token = 0;
1956 mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
Neema Shetty2c07eb52011-08-21 20:33:52 -07001957 mvm_set_network.network.network_id = common.mvs_info.network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001958
1959 v->mvm_state = CMD_STATUS_FAIL;
1960 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
1961 if (ret < 0) {
1962 pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
1963 goto fail;
1964 }
1965
1966 ret = wait_event_timeout(v->mvm_wait,
1967 (v->mvm_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 /* Set voice timing. */
1975 pr_debug("Setting voice timing\n");
1976
1977 mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1978 APR_HDR_LEN(APR_HDR_SIZE),
1979 APR_PKT_VER);
1980 mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
1981 sizeof(mvm_set_voice_timing) -
1982 APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07001983 mvm_set_voice_timing.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001984 mvm_set_voice_timing.hdr.dest_port = mvm_handle;
1985 mvm_set_voice_timing.hdr.token = 0;
1986 mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
1987 mvm_set_voice_timing.timing.mode = 0;
1988 mvm_set_voice_timing.timing.enc_offset = 8000;
1989 mvm_set_voice_timing.timing.dec_req_offset = 3300;
1990 mvm_set_voice_timing.timing.dec_offset = 8300;
1991
1992 v->mvm_state = CMD_STATUS_FAIL;
1993
1994 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
1995 if (ret < 0) {
1996 pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
1997 goto fail;
1998 }
1999
2000 ret = wait_event_timeout(v->mvm_wait,
2001 (v->mvm_state == CMD_STATUS_SUCCESS),
2002 msecs_to_jiffies(TIMEOUT_MS));
2003 if (!ret) {
2004 pr_err("%s: wait_event timeout\n", __func__);
2005 goto fail;
2006 }
2007
2008 return 0;
2009fail:
2010 return -EINVAL;
2011}
2012
2013static int voice_send_attach_vocproc_cmd(struct voice_data *v)
2014{
2015 int ret = 0;
2016 struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
2017 void *apr_mvm;
2018 u16 mvm_handle, cvp_handle;
2019
2020 if (v == NULL) {
2021 pr_err("%s: v is NULL\n", __func__);
2022 return -EINVAL;
2023 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002024 apr_mvm = common.apr_q6_mvm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002025
2026 if (!apr_mvm) {
2027 pr_err("%s: apr_mvm is NULL.\n", __func__);
2028 return -EINVAL;
2029 }
2030 mvm_handle = voice_get_mvm_handle(v);
2031 cvp_handle = voice_get_cvp_handle(v);
2032
2033 /* attach vocproc and wait for response */
2034 mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2035 APR_HDR_LEN(APR_HDR_SIZE),
2036 APR_PKT_VER);
2037 mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2038 sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
2039 pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
2040 mvm_a_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002041 mvm_a_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002042 mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
2043 mvm_a_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002044 mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002045 mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
2046
2047 v->mvm_state = CMD_STATUS_FAIL;
2048 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
2049 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002050 pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002051 goto fail;
2052 }
2053 ret = wait_event_timeout(v->mvm_wait,
2054 (v->mvm_state == CMD_STATUS_SUCCESS),
2055 msecs_to_jiffies(TIMEOUT_MS));
2056 if (!ret) {
2057 pr_err("%s: wait_event timeout\n", __func__);
2058 goto fail;
2059 }
2060
2061 return 0;
2062fail:
2063 return -EINVAL;
2064}
2065
2066static int voice_destroy_vocproc(struct voice_data *v)
2067{
2068 struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
2069 struct apr_hdr cvp_destroy_session_cmd;
2070 int ret = 0;
2071 void *apr_mvm, *apr_cvp;
2072 u16 mvm_handle, cvp_handle;
2073
2074 if (v == NULL) {
2075 pr_err("%s: v is NULL\n", __func__);
2076 return -EINVAL;
2077 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002078 apr_mvm = common.apr_q6_mvm;
2079 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002080
2081 if (!apr_mvm || !apr_cvp) {
2082 pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
2083 return -EINVAL;
2084 }
2085 mvm_handle = voice_get_mvm_handle(v);
2086 cvp_handle = voice_get_cvp_handle(v);
2087
2088 /* send stop voice cmd */
2089 voice_send_stop_voice_cmd(v);
2090
2091 /* detach VOCPROC and wait for response from mvm */
2092 mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2093 APR_HDR_LEN(APR_HDR_SIZE),
2094 APR_PKT_VER);
2095 mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2096 sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
2097 pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
2098 mvm_d_vocproc_cmd.hdr.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002099 mvm_d_vocproc_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002100 mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
2101 mvm_d_vocproc_cmd.hdr.token = 0;
Helen Zeng69b00962011-07-08 11:38:36 -07002102 mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002103 mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
2104
2105 v->mvm_state = CMD_STATUS_FAIL;
2106 ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
2107 if (ret < 0) {
Helen Zeng69b00962011-07-08 11:38:36 -07002108 pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002109 goto fail;
2110 }
2111 ret = wait_event_timeout(v->mvm_wait,
2112 (v->mvm_state == CMD_STATUS_SUCCESS),
2113 msecs_to_jiffies(TIMEOUT_MS));
2114 if (!ret) {
2115 pr_err("%s: wait_event timeout\n", __func__);
2116 goto fail;
2117 }
2118
Helen Zeng29eb7442011-06-20 11:06:29 -07002119 /* deregister cvp and vol cal */
2120 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2121 voice_send_cvp_deregister_cal_cmd(v);
2122 voice_send_cvp_unmap_memory_cmd(v);
2123
2124 /* deregister cvs cal */
2125 voice_send_cvs_deregister_cal_cmd(v);
2126 voice_send_cvs_unmap_memory_cmd(v);
2127
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002128 /* destrop cvp session */
2129 cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2130 APR_HDR_LEN(APR_HDR_SIZE),
2131 APR_PKT_VER);
2132 cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2133 sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
2134 pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
2135 cvp_destroy_session_cmd.pkt_size);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002136 cvp_destroy_session_cmd.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137 cvp_destroy_session_cmd.dest_port = cvp_handle;
2138 cvp_destroy_session_cmd.token = 0;
2139 cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
2140
2141 v->cvp_state = CMD_STATUS_FAIL;
2142 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
2143 if (ret < 0) {
2144 pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
2145 goto fail;
2146 }
2147 ret = wait_event_timeout(v->cvp_wait,
2148 (v->cvp_state == CMD_STATUS_SUCCESS),
2149 msecs_to_jiffies(TIMEOUT_MS));
2150 if (!ret) {
2151 pr_err("%s: wait_event timeout\n", __func__);
2152 goto fail;
2153 }
2154
Ben Romberger13b74ab2011-07-18 17:36:32 -07002155 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002156 cvp_handle = 0;
2157 voice_set_cvp_handle(v, cvp_handle);
2158
2159 return 0;
2160
2161fail:
2162 return -EINVAL;
2163}
2164
2165static int voice_send_mute_cmd(struct voice_data *v)
2166{
2167 struct cvs_set_mute_cmd cvs_mute_cmd;
2168 int ret = 0;
2169 void *apr_cvs;
2170 u16 cvs_handle;
2171
2172 if (v == NULL) {
2173 pr_err("%s: v is NULL\n", __func__);
2174 return -EINVAL;
2175 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002176 apr_cvs = common.apr_q6_cvs;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002177
2178 if (!apr_cvs) {
2179 pr_err("%s: apr_cvs is NULL.\n", __func__);
2180 return -EINVAL;
2181 }
2182 cvs_handle = voice_get_cvs_handle(v);
2183
2184 /* send mute/unmute to cvs */
2185 cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2186 APR_HDR_LEN(APR_HDR_SIZE),
2187 APR_PKT_VER);
2188 cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2189 sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002190 cvs_mute_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002191 cvs_mute_cmd.hdr.dest_port = cvs_handle;
2192 cvs_mute_cmd.hdr.token = 0;
2193 cvs_mute_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MUTE;
2194 cvs_mute_cmd.cvs_set_mute.direction = 0; /*tx*/
2195 cvs_mute_cmd.cvs_set_mute.mute_flag = v->dev_tx.mute;
2196
2197 pr_info(" mute value =%d\n", cvs_mute_cmd.cvs_set_mute.mute_flag);
2198 v->cvs_state = CMD_STATUS_FAIL;
2199 ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_mute_cmd);
2200 if (ret < 0) {
2201 pr_err("Fail: send STREAM SET MUTE\n");
2202 goto fail;
2203 }
2204 ret = wait_event_timeout(v->cvs_wait,
2205 (v->cvs_state == CMD_STATUS_SUCCESS),
2206 msecs_to_jiffies(TIMEOUT_MS));
2207 if (!ret)
2208 pr_err("%s: wait_event timeout\n", __func__);
2209
2210 return 0;
2211fail:
2212 return -EINVAL;
2213}
2214
2215static int voice_send_vol_index_cmd(struct voice_data *v)
2216{
2217 struct cvp_set_rx_volume_index_cmd cvp_vol_cmd;
2218 int ret = 0;
2219 void *apr_cvp;
2220 u16 cvp_handle;
2221 if (v == NULL) {
2222 pr_err("%s: v is NULL\n", __func__);
2223 return -EINVAL;
2224 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002225 apr_cvp = common.apr_q6_cvp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002226
2227 if (!apr_cvp) {
2228 pr_err("%s: apr_cvp is NULL.\n", __func__);
2229 return -EINVAL;
2230 }
2231 cvp_handle = voice_get_cvp_handle(v);
2232
2233 /* send volume index to cvp */
2234 cvp_vol_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2235 APR_HDR_LEN(APR_HDR_SIZE),
2236 APR_PKT_VER);
2237 cvp_vol_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2238 sizeof(cvp_vol_cmd) - APR_HDR_SIZE);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002239 cvp_vol_cmd.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002240 cvp_vol_cmd.hdr.dest_port = cvp_handle;
2241 cvp_vol_cmd.hdr.token = 0;
2242 cvp_vol_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX;
2243 cvp_vol_cmd.cvp_set_vol_idx.vol_index = v->dev_rx.volume;
2244 v->cvp_state = CMD_STATUS_FAIL;
2245 ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_cmd);
2246 if (ret < 0) {
2247 pr_err("Fail in sending RX VOL INDEX\n");
2248 return -EINVAL;
2249 }
2250 ret = wait_event_timeout(v->cvp_wait,
2251 (v->cvp_state == CMD_STATUS_SUCCESS),
2252 msecs_to_jiffies(TIMEOUT_MS));
2253 if (!ret) {
2254 pr_err("%s: wait_event timeout\n", __func__);
2255 return -EINVAL;
2256 }
2257 return 0;
2258}
2259
Neema Shetty2c07eb52011-08-21 20:33:52 -07002260int voc_disable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002261{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002262 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002263 int ret = 0;
2264
Neema Shetty2c07eb52011-08-21 20:33:52 -07002265 if (v == NULL) {
2266 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2267
2268 return -EINVAL;
2269 }
2270
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002271 mutex_lock(&v->lock);
2272
2273 if (v->voc_state == VOC_RUN) {
2274 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0);
Ben Romberger13b74ab2011-07-18 17:36:32 -07002275
2276 rtac_remove_voice(voice_get_cvs_handle(v));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002277 /* send cmd to dsp to disable vocproc */
2278 ret = voice_send_disable_vocproc_cmd(v);
2279 if (ret < 0) {
2280 pr_err("%s: disable vocproc failed\n", __func__);
2281 goto fail;
2282 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002283
2284 /* deregister cvp and vol cal */
2285 voice_send_cvp_deregister_vol_cal_table_cmd(v);
2286 voice_send_cvp_deregister_cal_cmd(v);
2287 voice_send_cvp_unmap_memory_cmd(v);
2288
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002289 v->voc_state = VOC_CHANGE;
2290 }
2291
2292fail: mutex_unlock(&v->lock);
2293
2294 return ret;
2295}
2296
Neema Shetty2c07eb52011-08-21 20:33:52 -07002297int voc_enable_cvp(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002298{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002299 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002300 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002301 int ret = 0;
2302
Neema Shetty2c07eb52011-08-21 20:33:52 -07002303 if (v == NULL) {
2304 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2305
2306 return -EINVAL;
2307 }
2308
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002309 mutex_lock(&v->lock);
2310
2311 if (v->voc_state == VOC_CHANGE) {
2312 ret = voice_send_set_device_cmd(v);
2313 if (ret < 0) {
2314 pr_err("%s: set device failed\n", __func__);
2315 goto fail;
2316 }
Helen Zeng29eb7442011-06-20 11:06:29 -07002317 /* send cvp and vol cal */
2318 ret = voice_send_cvp_map_memory_cmd(v);
2319 if (!ret) {
2320 voice_send_cvp_register_cal_cmd(v);
2321 voice_send_cvp_register_vol_cal_table_cmd(v);
2322 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002323 ret = voice_send_enable_vocproc_cmd(v);
2324 if (ret < 0) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002325 pr_err("%s: enable vocproc failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002326 goto fail;
Helen Zengcc65b5b2011-07-06 19:14:48 -07002327
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002328 }
Helen Zengcc65b5b2011-07-06 19:14:48 -07002329 /* send tty mode if tty device is used */
2330 voice_send_tty_mode_cmd(v);
2331
Helen Zeng44d4d272011-08-10 14:49:20 -07002332 /* enable widevoice if wv_enable is set */
2333 if (v->wv_enable)
2334 voice_send_set_widevoice_enable_cmd(v);
2335
Helen Zengbd58e2c2011-07-01 16:24:31 -07002336 get_sidetone_cal(&sidetone_cal_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002337 ret = afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
Helen Zengbd58e2c2011-07-01 16:24:31 -07002338 sidetone_cal_data.enable,
2339 sidetone_cal_data.gain);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002340
2341 if (ret < 0)
Neema Shetty2c07eb52011-08-21 20:33:52 -07002342 pr_err("%s: AFE command sidetone failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002343
Ben Romberger13b74ab2011-07-18 17:36:32 -07002344 rtac_add_voice(voice_get_cvs_handle(v),
2345 voice_get_cvp_handle(v),
2346 v->dev_rx.port_id, v->dev_tx.port_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002347 v->voc_state = VOC_RUN;
2348 }
2349
2350fail:
2351 mutex_unlock(&v->lock);
2352
2353 return ret;
2354}
2355
Neema Shetty2c07eb52011-08-21 20:33:52 -07002356int voc_set_tx_mute(uint16_t session_id, uint32_t dir, uint32_t mute)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002357{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002358 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002359 int ret = 0;
2360
Neema Shetty2c07eb52011-08-21 20:33:52 -07002361 if (v == NULL) {
2362 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2363
2364 return -EINVAL;
2365 }
2366
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002367 mutex_lock(&v->lock);
2368
2369 v->dev_tx.mute = mute;
2370
2371 if (v->voc_state == VOC_RUN)
2372 ret = voice_send_mute_cmd(v);
2373
2374 mutex_unlock(&v->lock);
2375
2376 return ret;
2377}
2378
Neema Shetty2c07eb52011-08-21 20:33:52 -07002379int voc_set_tty_mode(uint16_t session_id, uint8_t tty_mode)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002380{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002381 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002382 int ret = 0;
2383
Neema Shetty2c07eb52011-08-21 20:33:52 -07002384 if (v == NULL) {
2385 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2386
2387 return -EINVAL;
2388 }
2389
Helen Zengcc65b5b2011-07-06 19:14:48 -07002390 mutex_lock(&v->lock);
2391
2392 v->tty_mode = tty_mode;
2393
2394 mutex_unlock(&v->lock);
2395
2396 return ret;
2397}
2398
Neema Shetty2c07eb52011-08-21 20:33:52 -07002399uint8_t voc_get_tty_mode(uint16_t session_id)
Helen Zengcc65b5b2011-07-06 19:14:48 -07002400{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002401 struct voice_data *v = voice_get_session(session_id);
Helen Zengcc65b5b2011-07-06 19:14:48 -07002402 int ret = 0;
2403
Neema Shetty2c07eb52011-08-21 20:33:52 -07002404 if (v == NULL) {
2405 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2406
2407 return -EINVAL;
2408 }
2409
Helen Zengcc65b5b2011-07-06 19:14:48 -07002410 mutex_lock(&v->lock);
2411
2412 ret = v->tty_mode;
2413
2414 mutex_unlock(&v->lock);
2415
2416 return ret;
2417}
2418
Neema Shetty2c07eb52011-08-21 20:33:52 -07002419int voc_set_widevoice_enable(uint16_t session_id, uint32_t wv_enable)
Helen Zeng44d4d272011-08-10 14:49:20 -07002420{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002421 struct voice_data *v = voice_get_session(session_id);
Helen Zeng44d4d272011-08-10 14:49:20 -07002422 int ret = 0;
2423
Neema Shetty2c07eb52011-08-21 20:33:52 -07002424 if (v == NULL) {
2425 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2426
2427 return -EINVAL;
2428 }
2429
Helen Zeng44d4d272011-08-10 14:49:20 -07002430 mutex_lock(&v->lock);
2431
2432 v->wv_enable = wv_enable;
2433
2434 mutex_unlock(&v->lock);
2435
2436 return ret;
2437}
2438
Neema Shetty2c07eb52011-08-21 20:33:52 -07002439uint32_t voc_get_widevoice_enable(uint16_t session_id)
Helen Zeng44d4d272011-08-10 14:49:20 -07002440{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002441 struct voice_data *v = voice_get_session(session_id);
Helen Zeng44d4d272011-08-10 14:49:20 -07002442 int ret = 0;
2443
Neema Shetty2c07eb52011-08-21 20:33:52 -07002444 if (v == NULL) {
2445 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2446
2447 return -EINVAL;
2448 }
2449
Helen Zeng44d4d272011-08-10 14:49:20 -07002450 mutex_lock(&v->lock);
2451
2452 ret = v->wv_enable;
2453
2454 mutex_unlock(&v->lock);
2455
2456 return ret;
2457}
2458
Neema Shetty2c07eb52011-08-21 20:33:52 -07002459int voc_set_rx_vol_index(uint16_t session_id, uint32_t dir, uint32_t vol_idx)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002460{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002461 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002462 int ret = 0;
2463
Neema Shetty2c07eb52011-08-21 20:33:52 -07002464 if (v == NULL) {
2465 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2466
2467 return -EINVAL;
2468 }
2469
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002470 mutex_lock(&v->lock);
2471
2472 v->dev_rx.volume = vol_idx;
2473
2474 if (v->voc_state == VOC_RUN)
2475 ret = voice_send_vol_index_cmd(v);
2476
2477 mutex_unlock(&v->lock);
2478
2479 return ret;
2480}
2481
Neema Shetty2c07eb52011-08-21 20:33:52 -07002482int voc_set_rxtx_port(uint16_t session_id, uint32_t port_id, uint32_t dev_type)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002483{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002484 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002485
Neema Shetty2c07eb52011-08-21 20:33:52 -07002486 if (v == NULL) {
2487 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2488
2489 return -EINVAL;
2490 }
2491
2492 pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002493
2494 mutex_lock(&v->lock);
2495
2496 if (dev_type == DEV_RX)
2497 v->dev_rx.port_id = port_id;
2498 else
2499 v->dev_tx.port_id = port_id;
2500
2501 mutex_unlock(&v->lock);
2502
Neema Shetty2c07eb52011-08-21 20:33:52 -07002503 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002504}
2505
Neema Shetty2c07eb52011-08-21 20:33:52 -07002506int voc_set_route_flag(uint16_t session_id, uint8_t path_dir, uint8_t set)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002507{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002508 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002509
Neema Shetty2c07eb52011-08-21 20:33:52 -07002510 if (v == NULL) {
2511 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2512
2513 return -EINVAL;
2514 }
2515
2516 pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002517
2518 mutex_lock(&v->lock);
2519
2520 if (path_dir == RX_PATH)
2521 v->voc_route_state.rx_route_flag = set;
2522 else
2523 v->voc_route_state.tx_route_flag = set;
2524
2525 mutex_unlock(&v->lock);
2526
Neema Shetty2c07eb52011-08-21 20:33:52 -07002527 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002528}
2529
Neema Shetty2c07eb52011-08-21 20:33:52 -07002530uint8_t voc_get_route_flag(uint16_t session_id, uint8_t path_dir)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002531{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002532 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002533 int ret = 0;
2534
Neema Shetty2c07eb52011-08-21 20:33:52 -07002535 if (v == NULL) {
2536 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2537
2538 return 0;
2539 }
2540
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002541 mutex_lock(&v->lock);
2542
2543 if (path_dir == RX_PATH)
2544 ret = v->voc_route_state.rx_route_flag;
2545 else
2546 ret = v->voc_route_state.tx_route_flag;
2547
2548 mutex_unlock(&v->lock);
2549
2550 return ret;
2551}
2552
Neema Shetty2c07eb52011-08-21 20:33:52 -07002553int voc_end_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002554{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002555 struct voice_data *v = voice_get_session(session_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002556 int ret = 0;
2557
Neema Shetty2c07eb52011-08-21 20:33:52 -07002558 if (v == NULL) {
2559 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2560
2561 return -EINVAL;
2562 }
2563
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002564 mutex_lock(&v->lock);
2565
2566 if (v->voc_state == VOC_RUN) {
Helen Zengbd58e2c2011-07-01 16:24:31 -07002567 afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002568 ret = voice_destroy_vocproc(v);
2569 if (ret < 0)
2570 pr_err("%s: destroy voice failed\n", __func__);
2571 voice_destroy_mvm_cvs_session(v);
2572
2573 v->voc_state = VOC_RELEASE;
2574 }
2575 mutex_unlock(&v->lock);
2576 return ret;
2577}
2578
Neema Shetty2c07eb52011-08-21 20:33:52 -07002579int voc_start_voice_call(uint16_t session_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002580{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002581 struct voice_data *v = voice_get_session(session_id);
Helen Zengbd58e2c2011-07-01 16:24:31 -07002582 struct sidetone_cal sidetone_cal_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002583 int ret = 0;
2584
Neema Shetty2c07eb52011-08-21 20:33:52 -07002585 if (v == NULL) {
2586 pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
2587
2588 return -EINVAL;
2589 }
2590
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002591 mutex_lock(&v->lock);
2592
2593 if ((v->voc_state == VOC_INIT) ||
2594 (v->voc_state == VOC_RELEASE)) {
Neema Shetty2c07eb52011-08-21 20:33:52 -07002595 ret = voice_apr_register();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002596 if (ret < 0) {
2597 pr_err("%s: apr register failed\n", __func__);
2598 goto fail;
2599 }
2600 ret = voice_create_mvm_cvs_session(v);
2601 if (ret < 0) {
2602 pr_err("create mvm and cvs failed\n");
2603 goto fail;
2604 }
2605 ret = voice_setup_vocproc(v);
2606 if (ret < 0) {
2607 pr_err("setup voice failed\n");
2608 goto fail;
2609 }
2610 ret = voice_send_start_voice_cmd(v);
2611 if (ret < 0) {
2612 pr_err("start voice failed\n");
2613 goto fail;
2614 }
Helen Zengbd58e2c2011-07-01 16:24:31 -07002615 get_sidetone_cal(&sidetone_cal_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002616 ret = afe_sidetone(v->dev_tx.port_id,
Helen Zengbd58e2c2011-07-01 16:24:31 -07002617 v->dev_rx.port_id,
2618 sidetone_cal_data.enable,
2619 sidetone_cal_data.gain);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002620 if (ret < 0)
2621 pr_err("AFE command sidetone failed\n");
2622
2623 v->voc_state = VOC_RUN;
2624 }
2625
2626fail: mutex_unlock(&v->lock);
2627 return ret;
2628}
2629
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002630void voc_register_mvs_cb(ul_cb_fn ul_cb,
2631 dl_cb_fn dl_cb,
2632 void *private_data)
2633{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002634 common.mvs_info.ul_cb = ul_cb;
2635 common.mvs_info.dl_cb = dl_cb;
2636 common.mvs_info.private_data = private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002637}
2638
2639void voc_config_vocoder(uint32_t media_type,
2640 uint32_t rate,
2641 uint32_t network_type)
2642{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002643 common.mvs_info.media_type = media_type;
2644 common.mvs_info.rate = rate;
2645 common.mvs_info.network_type = network_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002646}
2647
2648static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
2649{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002650 uint32_t *ptr = NULL;
2651 struct common_data *c = NULL;
2652 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002653 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002654
2655 if ((data == NULL) || (priv == NULL)) {
2656 pr_err("%s: data or priv is NULL\n", __func__);
2657 return -EINVAL;
2658 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002659
2660 c = priv;
2661
2662 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
2663
2664 v = voice_get_session(data->dest_port);
2665 if (v == NULL) {
2666 pr_err("%s: v is NULL\n", __func__);
2667
2668 return -EINVAL;
2669 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002670
2671 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2672 data->payload_size, data->opcode);
2673
Neema Shetty07477582011-09-02 17:35:44 -07002674 if (data->opcode == RESET_EVENTS) {
2675 pr_debug("%s: Reset event received in Voice service\n",
2676 __func__);
2677
2678 apr_reset(c->apr_q6_mvm);
2679 c->apr_q6_mvm = NULL;
2680
2681 /* Sub-system restart is applicable to all sessions. */
2682 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2683 c->voice[i].mvm_handle = 0;
2684
2685 return 0;
2686 }
2687
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002688 if (data->opcode == APR_BASIC_RSP_RESULT) {
2689 if (data->payload_size) {
2690 ptr = data->payload;
2691
2692 pr_info("%x %x\n", ptr[0], ptr[1]);
2693 /* ping mvm service ACK */
2694 switch (ptr[0]) {
2695 case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
2696 case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
2697 /* Passive session is used for CS call
2698 * Full session is used for VoIP call. */
2699 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2700 if (!ptr[1]) {
2701 pr_debug("%s: MVM handle is %d\n",
2702 __func__, data->src_port);
2703 voice_set_mvm_handle(v, data->src_port);
2704 } else
2705 pr_err("got NACK for sending \
2706 MVM create session \n");
2707 v->mvm_state = CMD_STATUS_SUCCESS;
2708 wake_up(&v->mvm_wait);
2709 break;
2710 case VSS_IMVM_CMD_START_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07002711 case VSS_IMVM_CMD_ATTACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002712 case VSS_IMVM_CMD_STOP_VOICE:
Helen Zeng69b00962011-07-08 11:38:36 -07002713 case VSS_IMVM_CMD_DETACH_VOCPROC:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002714 case VSS_ISTREAM_CMD_SET_TTY_MODE:
2715 case APRV2_IBASIC_CMD_DESTROY_SESSION:
2716 case VSS_IMVM_CMD_ATTACH_STREAM:
2717 case VSS_IMVM_CMD_DETACH_STREAM:
2718 case VSS_ICOMMON_CMD_SET_NETWORK:
2719 case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
Helen Zeng44d4d272011-08-10 14:49:20 -07002720 case VSS_IWIDEVOICE_CMD_SET_WIDEVOICE:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002721 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2722 v->mvm_state = CMD_STATUS_SUCCESS;
2723 wake_up(&v->mvm_wait);
2724 break;
2725 default:
2726 pr_debug("%s: not match cmd = 0x%x\n",
2727 __func__, ptr[0]);
2728 break;
2729 }
2730 }
2731 }
2732
2733 return 0;
2734}
2735
2736static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
2737{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002738 uint32_t *ptr = NULL;
2739 struct common_data *c = NULL;
2740 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002741 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002742
2743 if ((data == NULL) || (priv == NULL)) {
2744 pr_err("%s: data or priv is NULL\n", __func__);
2745 return -EINVAL;
2746 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002747
2748 c = priv;
2749
2750 pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
2751
2752 v = voice_get_session(data->dest_port);
2753 if (v == NULL) {
2754 pr_err("%s: v is NULL\n", __func__);
2755
2756 return -EINVAL;
2757 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002758
2759 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2760 data->payload_size, data->opcode);
2761
Neema Shetty07477582011-09-02 17:35:44 -07002762 if (data->opcode == RESET_EVENTS) {
2763 pr_debug("%s: Reset event received in Voice service\n",
2764 __func__);
2765
2766 apr_reset(c->apr_q6_cvs);
2767 c->apr_q6_cvs = NULL;
2768
2769 /* Sub-system restart is applicable to all sessions. */
2770 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2771 c->voice[i].cvs_handle = 0;
2772
2773 return 0;
2774 }
2775
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002776 if (data->opcode == APR_BASIC_RSP_RESULT) {
2777 if (data->payload_size) {
2778 ptr = data->payload;
2779
2780 pr_info("%x %x\n", ptr[0], ptr[1]);
2781 /*response from CVS */
2782 switch (ptr[0]) {
2783 case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
2784 case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
2785 if (!ptr[1]) {
2786 pr_debug("%s: CVS handle is %d\n",
2787 __func__, data->src_port);
2788 voice_set_cvs_handle(v, data->src_port);
2789 } else
2790 pr_err("got NACK for sending \
2791 CVS create session \n");
2792 v->cvs_state = CMD_STATUS_SUCCESS;
2793 wake_up(&v->cvs_wait);
2794 break;
2795 case VSS_ISTREAM_CMD_SET_MUTE:
2796 case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
2797 case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
2798 case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
2799 case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
2800 case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
2801 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07002802 case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA:
2803 case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
2804 case VSS_ICOMMON_CMD_MAP_MEMORY:
2805 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002806 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2807 v->cvs_state = CMD_STATUS_SUCCESS;
2808 wake_up(&v->cvs_wait);
2809 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07002810 case VOICE_CMD_SET_PARAM:
2811 rtac_make_voice_callback(RTAC_CVS, ptr,
2812 data->payload_size);
2813 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002814 default:
2815 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2816 break;
2817 }
2818 }
2819 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
2820 uint32_t *voc_pkt = data->payload;
2821 uint32_t pkt_len = data->payload_size;
2822
Neema Shetty2c07eb52011-08-21 20:33:52 -07002823 if (voc_pkt != NULL && c->mvs_info.ul_cb != NULL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002824 pr_debug("%s: Media type is 0x%x\n",
2825 __func__, voc_pkt[0]);
2826
2827 /* Remove media ID from payload. */
2828 voc_pkt++;
2829 pkt_len = pkt_len - 4;
2830
Neema Shetty2c07eb52011-08-21 20:33:52 -07002831 c->mvs_info.ul_cb((uint8_t *)voc_pkt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002832 pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002833 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002834 } else
2835 pr_err("%s: voc_pkt is 0x%x ul_cb is 0x%x\n",
2836 __func__, (unsigned int)voc_pkt,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002837 (unsigned int) c->mvs_info.ul_cb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002838 } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
2839 struct cvs_send_dec_buf_cmd send_dec_buf;
2840 int ret = 0;
2841 uint32_t pkt_len = 0;
2842
Neema Shetty2c07eb52011-08-21 20:33:52 -07002843 if (c->mvs_info.dl_cb != NULL) {
2844 send_dec_buf.dec_buf.media_id = c->mvs_info.media_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002845
Neema Shetty2c07eb52011-08-21 20:33:52 -07002846 c->mvs_info.dl_cb(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002847 (uint8_t *)&send_dec_buf.dec_buf.packet_data,
2848 &pkt_len,
Neema Shetty2c07eb52011-08-21 20:33:52 -07002849 c->mvs_info.private_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002850
2851 send_dec_buf.hdr.hdr_field =
2852 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2853 APR_HDR_LEN(APR_HDR_SIZE),
2854 APR_PKT_VER);
2855 send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
2856 sizeof(send_dec_buf.dec_buf.media_id) + pkt_len);
Neema Shetty2c07eb52011-08-21 20:33:52 -07002857 send_dec_buf.hdr.src_port = v->session_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002858 send_dec_buf.hdr.dest_port = voice_get_cvs_handle(v);
2859 send_dec_buf.hdr.token = 0;
2860 send_dec_buf.hdr.opcode =
2861 VSS_ISTREAM_EVT_SEND_DEC_BUFFER;
2862
Neema Shetty2c07eb52011-08-21 20:33:52 -07002863 ret = apr_send_pkt(c->apr_q6_cvs,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002864 (uint32_t *) &send_dec_buf);
2865 if (ret < 0) {
2866 pr_err("%s: Error %d sending DEC_BUF\n",
2867 __func__, ret);
2868 goto fail;
2869 }
2870 } else
2871 pr_debug("%s: dl_cb is NULL\n", __func__);
Ben Romberger13b74ab2011-07-18 17:36:32 -07002872 } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002873 pr_debug("Send dec buf resp\n");
Ben Romberger13b74ab2011-07-18 17:36:32 -07002874 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
2875 rtac_make_voice_callback(RTAC_CVS, data->payload,
2876 data->payload_size);
2877 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002878 pr_debug("Unknown opcode 0x%x\n", data->opcode);
2879
2880fail:
2881 return 0;
2882}
2883
2884static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
2885{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002886 uint32_t *ptr = NULL;
2887 struct common_data *c = NULL;
2888 struct voice_data *v = NULL;
Neema Shetty07477582011-09-02 17:35:44 -07002889 int i = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002890
2891 if ((data == NULL) || (priv == NULL)) {
2892 pr_err("%s: data or priv is NULL\n", __func__);
2893 return -EINVAL;
2894 }
Neema Shetty2c07eb52011-08-21 20:33:52 -07002895
2896 c = priv;
2897
2898 v = voice_get_session(data->dest_port);
2899 if (v == NULL) {
2900 pr_err("%s: v is NULL\n", __func__);
2901
2902 return -EINVAL;
2903 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002904
2905 pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
2906 data->payload_size, data->opcode);
2907
Neema Shetty07477582011-09-02 17:35:44 -07002908 if (data->opcode == RESET_EVENTS) {
2909 pr_debug("%s: Reset event received in Voice service\n",
2910 __func__);
2911
2912 apr_reset(c->apr_q6_cvp);
2913 c->apr_q6_cvp = NULL;
2914
2915 /* Sub-system restart is applicable to all sessions. */
2916 for (i = 0; i < MAX_VOC_SESSIONS; i++)
2917 c->voice[i].cvp_handle = 0;
2918
2919 return 0;
2920 }
2921
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002922 if (data->opcode == APR_BASIC_RSP_RESULT) {
2923 if (data->payload_size) {
2924 ptr = data->payload;
2925
2926 pr_info("%x %x\n", ptr[0], ptr[1]);
2927
2928 switch (ptr[0]) {
2929 case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION:
2930 /*response from CVP */
2931 pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
2932 if (!ptr[1]) {
2933 voice_set_cvp_handle(v, data->src_port);
2934 pr_debug("cvphdl=%d\n", data->src_port);
2935 } else
2936 pr_err("got NACK from CVP create \
2937 session response\n");
2938 v->cvp_state = CMD_STATUS_SUCCESS;
2939 wake_up(&v->cvp_wait);
2940 break;
2941 case VSS_IVOCPROC_CMD_SET_DEVICE:
2942 case VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX:
2943 case VSS_IVOCPROC_CMD_ENABLE:
2944 case VSS_IVOCPROC_CMD_DISABLE:
2945 case APRV2_IBASIC_CMD_DESTROY_SESSION:
Helen Zeng29eb7442011-06-20 11:06:29 -07002946 case VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE:
2947 case VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE:
2948 case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA:
2949 case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
2950 case VSS_ICOMMON_CMD_MAP_MEMORY:
2951 case VSS_ICOMMON_CMD_UNMAP_MEMORY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002952 v->cvp_state = CMD_STATUS_SUCCESS;
2953 wake_up(&v->cvp_wait);
2954 break;
Ben Romberger13b74ab2011-07-18 17:36:32 -07002955 case VOICE_CMD_SET_PARAM:
2956 rtac_make_voice_callback(RTAC_CVP, ptr,
2957 data->payload_size);
2958 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002959 default:
2960 pr_debug("%s: not match cmd = 0x%x\n",
2961 __func__, ptr[0]);
2962 break;
2963 }
2964 }
Ben Romberger13b74ab2011-07-18 17:36:32 -07002965 } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
2966 rtac_make_voice_callback(RTAC_CVP, data->payload,
2967 data->payload_size);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002968 }
2969 return 0;
2970}
2971
2972
2973static int __init voice_init(void)
2974{
Neema Shetty2c07eb52011-08-21 20:33:52 -07002975 int rc = 0, i = 0;
2976
2977 memset(&common, 0, sizeof(struct common_data));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002978
2979 /* set default value */
Neema Shetty2c07eb52011-08-21 20:33:52 -07002980 common.default_mute_val = 1; /* default is mute */
2981 common.default_vol_val = 0;
2982 common.default_sample_val = 8000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002983
2984 /* Initialize MVS info. */
Neema Shetty2c07eb52011-08-21 20:33:52 -07002985 common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
2986
2987 mutex_init(&common.common_lock);
2988
2989 for (i = 0; i < MAX_VOC_SESSIONS; i++) {
2990 common.voice[i].session_id = SESSION_ID_BASE + i;
2991
2992 /* initialize dev_rx and dev_tx */
2993 common.voice[i].dev_rx.volume = common.default_vol_val;
2994 common.voice[i].dev_tx.mute = common.default_mute_val;
2995
2996 common.voice[i].dev_tx.port_id = 1;
2997 common.voice[i].dev_rx.port_id = 0;
2998 common.voice[i].sidetone_gain = 0x512;
2999
3000 common.voice[i].voc_state = VOC_INIT;
3001
3002 init_waitqueue_head(&common.voice[i].mvm_wait);
3003 init_waitqueue_head(&common.voice[i].cvs_wait);
3004 init_waitqueue_head(&common.voice[i].cvp_wait);
3005
3006 mutex_init(&common.voice[i].lock);
3007 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003008
3009 return rc;
3010}
3011
3012device_initcall(voice_init);