Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* 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> |
| 19 | #include <mach/qdsp6v2/audio_acdb.h> |
| 20 | #include "sound/apr_audio.h" |
| 21 | #include "sound/q6afe.h" |
| 22 | #include "q6voice.h" |
| 23 | |
| 24 | #define TIMEOUT_MS 3000 |
| 25 | |
| 26 | #define CMD_STATUS_SUCCESS 0 |
| 27 | #define CMD_STATUS_FAIL 1 |
| 28 | |
| 29 | #define VOC_PATH_PASSIVE 0 |
| 30 | #define VOC_PATH_FULL 1 |
| 31 | |
| 32 | static struct voice_data voice; |
| 33 | |
| 34 | static int voice_send_enable_vocproc_cmd(struct voice_data *v); |
| 35 | static int voice_send_netid_timing_cmd(struct voice_data *v); |
| 36 | static int voice_send_attach_vocproc_cmd(struct voice_data *v); |
| 37 | static int voice_send_set_device_cmd(struct voice_data *v); |
| 38 | static int voice_send_disable_vocproc_cmd(struct voice_data *v); |
| 39 | static int voice_send_vol_index_cmd(struct voice_data *v); |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 40 | static int voice_send_cvp_map_memory_cmd(struct voice_data *v); |
| 41 | static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v); |
| 42 | static int voice_send_cvs_map_memory_cmd(struct voice_data *v); |
| 43 | static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v); |
| 44 | static int voice_send_cvs_register_cal_cmd(struct voice_data *v); |
| 45 | static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v); |
| 46 | static int voice_send_cvp_register_cal_cmd(struct voice_data *v); |
| 47 | static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v); |
| 48 | static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v); |
| 49 | static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v); |
| 50 | |
| 51 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | |
| 53 | static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv); |
| 54 | static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv); |
| 55 | static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv); |
| 56 | |
| 57 | static u16 voice_get_mvm_handle(struct voice_data *v) |
| 58 | { |
| 59 | u16 mvm_handle = 0; |
| 60 | |
| 61 | if (v == NULL) { |
| 62 | pr_err("%s: v is NULL\n", __func__); |
| 63 | return -EINVAL; |
| 64 | } |
| 65 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 66 | mvm_handle = v->mvm_passive_handle; |
| 67 | else |
| 68 | mvm_handle = v->mvm_full_handle; |
| 69 | |
| 70 | pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle); |
| 71 | |
| 72 | return mvm_handle; |
| 73 | } |
| 74 | |
| 75 | static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle) |
| 76 | { |
| 77 | pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle); |
| 78 | if (v == NULL) { |
| 79 | pr_err("%s: v is NULL\n", __func__); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 84 | v->mvm_passive_handle = mvm_handle; |
| 85 | else |
| 86 | v->mvm_full_handle = mvm_handle; |
| 87 | } |
| 88 | |
| 89 | static u16 voice_get_cvs_handle(struct voice_data *v) |
| 90 | { |
| 91 | u16 cvs_handle = 0; |
| 92 | |
| 93 | if (v == NULL) { |
| 94 | pr_err("%s: v is NULL\n", __func__); |
| 95 | return -EINVAL; |
| 96 | } |
| 97 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 98 | cvs_handle = v->cvs_passive_handle; |
| 99 | else |
| 100 | cvs_handle = v->cvs_full_handle; |
| 101 | |
| 102 | pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle); |
| 103 | |
| 104 | return cvs_handle; |
| 105 | } |
| 106 | |
| 107 | static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle) |
| 108 | { |
| 109 | pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle); |
| 110 | if (v == NULL) { |
| 111 | pr_err("%s: v is NULL\n", __func__); |
| 112 | return; |
| 113 | } |
| 114 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 115 | v->cvs_passive_handle = cvs_handle; |
| 116 | else |
| 117 | v->cvs_full_handle = cvs_handle; |
| 118 | } |
| 119 | |
| 120 | static u16 voice_get_cvp_handle(struct voice_data *v) |
| 121 | { |
| 122 | u16 cvp_handle = 0; |
| 123 | |
| 124 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 125 | cvp_handle = v->cvp_passive_handle; |
| 126 | else |
| 127 | cvp_handle = v->cvp_full_handle; |
| 128 | |
| 129 | pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle); |
| 130 | |
| 131 | return cvp_handle; |
| 132 | } |
| 133 | |
| 134 | static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle) |
| 135 | { |
| 136 | pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle); |
| 137 | if (v == NULL) { |
| 138 | pr_err("%s: v is NULL\n", __func__); |
| 139 | return; |
| 140 | } |
| 141 | if (v->voc_path == VOC_PATH_PASSIVE) |
| 142 | v->cvp_passive_handle = cvp_handle; |
| 143 | else |
| 144 | v->cvp_full_handle = cvp_handle; |
| 145 | } |
| 146 | |
| 147 | static int voice_apr_register(struct voice_data *v) |
| 148 | { |
| 149 | void *apr_mvm, *apr_cvs, *apr_cvp; |
| 150 | |
| 151 | if (v == NULL) { |
| 152 | pr_err("%s: v is NULL\n", __func__); |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | apr_mvm = v->apr_q6_mvm; |
| 156 | apr_cvs = v->apr_q6_cvs; |
| 157 | apr_cvp = v->apr_q6_cvp; |
| 158 | |
| 159 | pr_debug("into voice_apr_register_callback\n"); |
| 160 | /* register callback to APR */ |
| 161 | if (apr_mvm == NULL) { |
| 162 | pr_debug("start to register MVM callback\n"); |
| 163 | |
| 164 | apr_mvm = apr_register("ADSP", "MVM", |
| 165 | qdsp_mvm_callback, |
| 166 | 0xFFFFFFFF, v); |
| 167 | |
| 168 | if (apr_mvm == NULL) { |
| 169 | pr_err("Unable to register MVM\n"); |
| 170 | goto err; |
| 171 | } |
| 172 | v->apr_q6_mvm = apr_mvm; |
| 173 | } |
| 174 | |
| 175 | if (apr_cvs == NULL) { |
| 176 | pr_debug("start to register CVS callback\n"); |
| 177 | |
| 178 | apr_cvs = apr_register("ADSP", "CVS", |
| 179 | qdsp_cvs_callback, |
| 180 | 0xFFFFFFFF, v); |
| 181 | |
| 182 | if (apr_cvs == NULL) { |
| 183 | pr_err("Unable to register CVS\n"); |
| 184 | goto err; |
| 185 | } |
| 186 | v->apr_q6_cvs = apr_cvs; |
| 187 | } |
| 188 | |
| 189 | if (apr_cvp == NULL) { |
| 190 | pr_debug("start to register CVP callback\n"); |
| 191 | |
| 192 | apr_cvp = apr_register("ADSP", "CVP", |
| 193 | qdsp_cvp_callback, |
| 194 | 0xFFFFFFFF, v); |
| 195 | |
| 196 | if (apr_cvp == NULL) { |
| 197 | pr_err("Unable to register CVP\n"); |
| 198 | goto err; |
| 199 | } |
| 200 | v->apr_q6_cvp = apr_cvp; |
| 201 | } |
| 202 | return 0; |
| 203 | |
| 204 | err: |
| 205 | if (v->apr_q6_cvs != NULL) { |
| 206 | apr_deregister(apr_cvs); |
| 207 | v->apr_q6_cvs = NULL; |
| 208 | } |
| 209 | if (v->apr_q6_mvm != NULL) { |
| 210 | apr_deregister(apr_mvm); |
| 211 | v->apr_q6_mvm = NULL; |
| 212 | } |
| 213 | |
| 214 | return -ENODEV; |
| 215 | } |
| 216 | |
| 217 | static int voice_create_mvm_cvs_session(struct voice_data *v) |
| 218 | { |
| 219 | int ret = 0; |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 220 | struct mvm_create_ctl_session_cmd mvm_session_cmd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | struct cvs_create_passive_ctl_session_cmd cvs_session_cmd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 222 | struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd; |
| 223 | struct mvm_attach_stream_cmd attach_stream_cmd; |
| 224 | void *apr_mvm, *apr_cvs, *apr_cvp; |
| 225 | u16 mvm_handle, cvs_handle, cvp_handle; |
| 226 | |
| 227 | if (v == NULL) { |
| 228 | pr_err("%s: v is NULL\n", __func__); |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | apr_mvm = v->apr_q6_mvm; |
| 232 | apr_cvs = v->apr_q6_cvs; |
| 233 | apr_cvp = v->apr_q6_cvp; |
| 234 | |
| 235 | if (!apr_mvm || !apr_cvs || !apr_cvp) { |
| 236 | pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | mvm_handle = voice_get_mvm_handle(v); |
| 240 | cvs_handle = voice_get_cvs_handle(v); |
| 241 | cvp_handle = voice_get_cvp_handle(v); |
| 242 | |
| 243 | pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__, |
| 244 | mvm_handle, cvs_handle); |
| 245 | /* send cmd to create mvm session and wait for response */ |
| 246 | |
| 247 | if (!mvm_handle) { |
| 248 | if (v->voc_path == VOC_PATH_PASSIVE) { |
| 249 | mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD( |
| 250 | APR_MSG_TYPE_SEQ_CMD, |
| 251 | APR_HDR_LEN(APR_HDR_SIZE), |
| 252 | APR_PKT_VER); |
| 253 | mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE( |
| 254 | APR_HDR_SIZE, |
| 255 | sizeof(mvm_session_cmd) - |
| 256 | APR_HDR_SIZE); |
| 257 | pr_debug("send mvm create session pkt size = %d\n", |
| 258 | mvm_session_cmd.hdr.pkt_size); |
| 259 | mvm_session_cmd.hdr.src_port = 0; |
| 260 | mvm_session_cmd.hdr.dest_port = 0; |
| 261 | mvm_session_cmd.hdr.token = 0; |
| 262 | mvm_session_cmd.hdr.opcode = |
| 263 | VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION; |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 264 | strncpy(mvm_session_cmd.mvm_session.name, |
| 265 | "default modem voice", SESSION_NAME_LEN); |
| 266 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 267 | v->mvm_state = CMD_STATUS_FAIL; |
| 268 | |
| 269 | ret = apr_send_pkt(apr_mvm, |
| 270 | (uint32_t *) &mvm_session_cmd); |
| 271 | if (ret < 0) { |
| 272 | pr_err("Error sending MVM_CONTROL_SESSION\n"); |
| 273 | goto fail; |
| 274 | } |
| 275 | ret = wait_event_timeout(v->mvm_wait, |
| 276 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 277 | msecs_to_jiffies(TIMEOUT_MS)); |
| 278 | if (!ret) { |
| 279 | pr_err("%s: wait_event timeout\n", __func__); |
| 280 | goto fail; |
| 281 | } |
| 282 | } else { |
| 283 | pr_debug("%s: creating MVM full ctrl\n", __func__); |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 284 | mvm_session_cmd.hdr.hdr_field = |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 285 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 286 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 287 | mvm_session_cmd.hdr.pkt_size = |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 288 | APR_PKT_SIZE(APR_HDR_SIZE, |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 289 | sizeof(mvm_session_cmd) - |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 290 | APR_HDR_SIZE); |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 291 | mvm_session_cmd.hdr.src_port = 0; |
| 292 | mvm_session_cmd.hdr.dest_port = 0; |
| 293 | mvm_session_cmd.hdr.token = 0; |
| 294 | mvm_session_cmd.hdr.opcode = |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 295 | VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION; |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 296 | strncpy(mvm_session_cmd.mvm_session.name, |
| 297 | "default voip", SESSION_NAME_LEN); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 298 | |
| 299 | v->mvm_state = CMD_STATUS_FAIL; |
| 300 | |
| 301 | ret = apr_send_pkt(apr_mvm, |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 302 | (uint32_t *) &mvm_session_cmd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 303 | if (ret < 0) { |
| 304 | pr_err("Fail in sending MVM_CONTROL_SESSION\n"); |
| 305 | goto fail; |
| 306 | } |
| 307 | ret = wait_event_timeout(v->mvm_wait, |
| 308 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 309 | msecs_to_jiffies(TIMEOUT_MS)); |
| 310 | if (!ret) { |
| 311 | pr_err("%s: wait_event timeout\n", __func__); |
| 312 | goto fail; |
| 313 | } |
| 314 | } |
| 315 | /* Get the created MVM handle. */ |
| 316 | mvm_handle = voice_get_mvm_handle(v); |
| 317 | } |
| 318 | /* send cmd to create cvs session */ |
| 319 | if (!cvs_handle) { |
| 320 | if (v->voc_path == VOC_PATH_PASSIVE) { |
| 321 | pr_debug("creating CVS passive session\n"); |
| 322 | |
| 323 | cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD( |
| 324 | APR_MSG_TYPE_SEQ_CMD, |
| 325 | APR_HDR_LEN(APR_HDR_SIZE), |
| 326 | APR_PKT_VER); |
| 327 | cvs_session_cmd.hdr.pkt_size = |
| 328 | APR_PKT_SIZE(APR_HDR_SIZE, |
| 329 | sizeof(cvs_session_cmd) - |
| 330 | APR_HDR_SIZE); |
| 331 | cvs_session_cmd.hdr.src_port = 0; |
| 332 | cvs_session_cmd.hdr.dest_port = 0; |
| 333 | cvs_session_cmd.hdr.token = 0; |
| 334 | cvs_session_cmd.hdr.opcode = |
| 335 | VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION; |
| 336 | strncpy(cvs_session_cmd.cvs_session.name, |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 337 | "default modem voice", SESSION_NAME_LEN); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 338 | |
| 339 | v->cvs_state = CMD_STATUS_FAIL; |
| 340 | |
| 341 | ret = apr_send_pkt(apr_cvs, |
| 342 | (uint32_t *) &cvs_session_cmd); |
| 343 | if (ret < 0) { |
| 344 | pr_err("Fail in sending STREAM_CONTROL_SESSION\n"); |
| 345 | goto fail; |
| 346 | } |
| 347 | ret = wait_event_timeout(v->cvs_wait, |
| 348 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 349 | msecs_to_jiffies(TIMEOUT_MS)); |
| 350 | if (!ret) { |
| 351 | pr_err("%s: wait_event timeout\n", __func__); |
| 352 | goto fail; |
| 353 | } |
| 354 | /* Get the created CVS handle. */ |
| 355 | cvs_handle = voice_get_cvs_handle(v); |
| 356 | |
| 357 | } else { |
| 358 | pr_debug("creating CVS full session\n"); |
| 359 | |
| 360 | cvs_full_ctl_cmd.hdr.hdr_field = |
| 361 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 362 | APR_HDR_LEN(APR_HDR_SIZE), |
| 363 | APR_PKT_VER); |
| 364 | |
| 365 | cvs_full_ctl_cmd.hdr.pkt_size = |
| 366 | APR_PKT_SIZE(APR_HDR_SIZE, |
| 367 | sizeof(cvs_full_ctl_cmd) - |
| 368 | APR_HDR_SIZE); |
| 369 | |
| 370 | cvs_full_ctl_cmd.hdr.src_port = 0; |
| 371 | cvs_full_ctl_cmd.hdr.dest_port = 0; |
| 372 | cvs_full_ctl_cmd.hdr.token = 0; |
| 373 | cvs_full_ctl_cmd.hdr.opcode = |
| 374 | VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION; |
| 375 | cvs_full_ctl_cmd.cvs_session.direction = 2; |
| 376 | cvs_full_ctl_cmd.cvs_session.enc_media_type = |
| 377 | v->mvs_info.media_type; |
| 378 | cvs_full_ctl_cmd.cvs_session.dec_media_type = |
| 379 | v->mvs_info.media_type; |
| 380 | cvs_full_ctl_cmd.cvs_session.network_id = |
| 381 | v->mvs_info.network_type; |
| 382 | strncpy(cvs_full_ctl_cmd.cvs_session.name, |
| 383 | "default q6 voice", 16); |
| 384 | |
| 385 | v->cvs_state = CMD_STATUS_FAIL; |
| 386 | |
| 387 | ret = apr_send_pkt(apr_cvs, |
| 388 | (uint32_t *) &cvs_full_ctl_cmd); |
| 389 | |
| 390 | if (ret < 0) { |
| 391 | pr_err("%s: Err %d sending CREATE_FULL_CTRL\n", |
| 392 | __func__, ret); |
| 393 | goto fail; |
| 394 | } |
| 395 | ret = wait_event_timeout(v->cvs_wait, |
| 396 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 397 | msecs_to_jiffies(TIMEOUT_MS)); |
| 398 | if (!ret) { |
| 399 | pr_err("%s: wait_event timeout\n", __func__); |
| 400 | goto fail; |
| 401 | } |
| 402 | /* Get the created CVS handle. */ |
| 403 | cvs_handle = voice_get_cvs_handle(v); |
| 404 | |
| 405 | /* Attach MVM to CVS. */ |
| 406 | pr_debug("Attach MVM to stream\n"); |
| 407 | |
| 408 | attach_stream_cmd.hdr.hdr_field = |
| 409 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 410 | APR_HDR_LEN(APR_HDR_SIZE), |
| 411 | APR_PKT_VER); |
| 412 | attach_stream_cmd.hdr.pkt_size = |
| 413 | APR_PKT_SIZE(APR_HDR_SIZE, |
| 414 | sizeof(attach_stream_cmd) - |
| 415 | APR_HDR_SIZE); |
| 416 | attach_stream_cmd.hdr.src_port = 0; |
| 417 | attach_stream_cmd.hdr.dest_port = mvm_handle; |
| 418 | attach_stream_cmd.hdr.token = 0; |
| 419 | attach_stream_cmd.hdr.opcode = |
| 420 | VSS_IMVM_CMD_ATTACH_STREAM; |
| 421 | attach_stream_cmd.attach_stream.handle = cvs_handle; |
| 422 | |
| 423 | v->mvm_state = CMD_STATUS_FAIL; |
| 424 | ret = apr_send_pkt(apr_mvm, |
| 425 | (uint32_t *) &attach_stream_cmd); |
| 426 | if (ret < 0) { |
| 427 | pr_err("%s: Error %d sending ATTACH_STREAM\n", |
| 428 | __func__, ret); |
| 429 | goto fail; |
| 430 | } |
| 431 | ret = wait_event_timeout(v->mvm_wait, |
| 432 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 433 | msecs_to_jiffies(TIMEOUT_MS)); |
| 434 | if (!ret) { |
| 435 | pr_err("%s: wait_event timeout\n", __func__); |
| 436 | goto fail; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | return 0; |
| 441 | |
| 442 | fail: |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | static int voice_destroy_mvm_cvs_session(struct voice_data *v) |
| 447 | { |
| 448 | int ret = 0; |
| 449 | struct mvm_detach_stream_cmd detach_stream; |
| 450 | struct apr_hdr mvm_destroy; |
| 451 | struct apr_hdr cvs_destroy; |
| 452 | void *apr_mvm, *apr_cvs; |
| 453 | u16 mvm_handle, cvs_handle; |
| 454 | |
| 455 | if (v == NULL) { |
| 456 | pr_err("%s: v is NULL\n", __func__); |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | apr_mvm = v->apr_q6_mvm; |
| 460 | apr_cvs = v->apr_q6_cvs; |
| 461 | |
| 462 | if (!apr_mvm || !apr_cvs) { |
| 463 | pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__); |
| 464 | return -EINVAL; |
| 465 | } |
| 466 | mvm_handle = voice_get_mvm_handle(v); |
| 467 | cvs_handle = voice_get_cvs_handle(v); |
| 468 | |
| 469 | /* MVM, CVS sessions are destroyed only for Full control sessions. */ |
| 470 | if (v->voc_path == VOC_PATH_FULL) { |
| 471 | pr_debug("MVM detach stream\n"); |
| 472 | |
| 473 | /* Detach voice stream. */ |
| 474 | detach_stream.hdr.hdr_field = |
| 475 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 476 | APR_HDR_LEN(APR_HDR_SIZE), |
| 477 | APR_PKT_VER); |
| 478 | detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 479 | sizeof(detach_stream) - APR_HDR_SIZE); |
| 480 | detach_stream.hdr.src_port = 0; |
| 481 | detach_stream.hdr.dest_port = mvm_handle; |
| 482 | detach_stream.hdr.token = 0; |
| 483 | detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM; |
| 484 | detach_stream.detach_stream.handle = cvs_handle; |
| 485 | |
| 486 | v->mvm_state = CMD_STATUS_FAIL; |
| 487 | |
| 488 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream); |
| 489 | if (ret < 0) { |
| 490 | pr_err("%s: Error %d sending DETACH_STREAM\n", |
| 491 | __func__, ret); |
| 492 | goto fail; |
| 493 | } |
| 494 | ret = wait_event_timeout(v->mvm_wait, |
| 495 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 496 | msecs_to_jiffies(TIMEOUT_MS)); |
| 497 | if (!ret) { |
| 498 | pr_err("%s: wait event timeout\n", __func__); |
| 499 | goto fail; |
| 500 | } |
| 501 | /* Destroy CVS. */ |
| 502 | pr_debug("CVS destroy session\n"); |
| 503 | |
| 504 | cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 505 | APR_HDR_LEN(APR_HDR_SIZE), |
| 506 | APR_PKT_VER); |
| 507 | cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 508 | sizeof(cvs_destroy) - APR_HDR_SIZE); |
| 509 | cvs_destroy.src_port = 0; |
| 510 | cvs_destroy.dest_port = cvs_handle; |
| 511 | cvs_destroy.token = 0; |
| 512 | cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION; |
| 513 | |
| 514 | v->cvs_state = CMD_STATUS_FAIL; |
| 515 | |
| 516 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy); |
| 517 | if (ret < 0) { |
| 518 | pr_err("%s: Error %d sending CVS DESTROY\n", |
| 519 | __func__, ret); |
| 520 | goto fail; |
| 521 | } |
| 522 | ret = wait_event_timeout(v->cvs_wait, |
| 523 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 524 | msecs_to_jiffies(TIMEOUT_MS)); |
| 525 | if (!ret) { |
| 526 | pr_err("%s: wait event timeout\n", __func__); |
| 527 | |
| 528 | goto fail; |
| 529 | } |
| 530 | cvs_handle = 0; |
| 531 | voice_set_cvs_handle(v, cvs_handle); |
| 532 | |
| 533 | /* Destroy MVM. */ |
| 534 | pr_debug("MVM destroy session\n"); |
| 535 | |
| 536 | mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 537 | APR_HDR_LEN(APR_HDR_SIZE), |
| 538 | APR_PKT_VER); |
| 539 | mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 540 | sizeof(mvm_destroy) - APR_HDR_SIZE); |
| 541 | mvm_destroy.src_port = 0; |
| 542 | mvm_destroy.dest_port = mvm_handle; |
| 543 | mvm_destroy.token = 0; |
| 544 | mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION; |
| 545 | |
| 546 | v->mvm_state = CMD_STATUS_FAIL; |
| 547 | |
| 548 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy); |
| 549 | if (ret < 0) { |
| 550 | pr_err("%s: Error %d sending MVM DESTROY\n", |
| 551 | __func__, ret); |
| 552 | |
| 553 | goto fail; |
| 554 | } |
| 555 | ret = wait_event_timeout(v->mvm_wait, |
| 556 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 557 | msecs_to_jiffies(TIMEOUT_MS)); |
| 558 | if (!ret) { |
| 559 | pr_err("%s: wait event timeout\n", __func__); |
| 560 | |
| 561 | goto fail; |
| 562 | } |
| 563 | mvm_handle = 0; |
| 564 | voice_set_mvm_handle(v, mvm_handle); |
| 565 | } |
| 566 | return 0; |
| 567 | fail: |
| 568 | return -EINVAL; |
| 569 | } |
| 570 | |
| 571 | static int voice_send_tty_mode_cmd(struct voice_data *v) |
| 572 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 573 | int ret = 0; |
| 574 | struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd; |
| 575 | void *apr_mvm; |
| 576 | u16 mvm_handle; |
| 577 | |
| 578 | if (v == NULL) { |
| 579 | pr_err("%s: v is NULL\n", __func__); |
| 580 | return -EINVAL; |
| 581 | } |
| 582 | apr_mvm = v->apr_q6_mvm; |
| 583 | |
| 584 | if (!apr_mvm) { |
| 585 | pr_err("%s: apr_mvm is NULL.\n", __func__); |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | mvm_handle = voice_get_mvm_handle(v); |
| 589 | |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 590 | if (v->tty_mode) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 591 | /* send tty mode cmd to mvm */ |
| 592 | mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD( |
| 593 | APR_MSG_TYPE_SEQ_CMD, |
| 594 | APR_HDR_LEN(APR_HDR_SIZE), |
| 595 | APR_PKT_VER); |
| 596 | mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 597 | sizeof(mvm_tty_mode_cmd) - |
| 598 | APR_HDR_SIZE); |
| 599 | pr_debug("pkt size = %d\n", mvm_tty_mode_cmd.hdr.pkt_size); |
| 600 | mvm_tty_mode_cmd.hdr.src_port = 0; |
| 601 | mvm_tty_mode_cmd.hdr.dest_port = mvm_handle; |
| 602 | mvm_tty_mode_cmd.hdr.token = 0; |
| 603 | mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE; |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 604 | mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 605 | pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode); |
| 606 | |
| 607 | v->mvm_state = CMD_STATUS_FAIL; |
| 608 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd); |
| 609 | if (ret < 0) { |
| 610 | pr_err("Fail: sending VSS_ISTREAM_CMD_SET_TTY_MODE\n"); |
| 611 | goto fail; |
| 612 | } |
| 613 | ret = wait_event_timeout(v->mvm_wait, |
| 614 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 615 | msecs_to_jiffies(TIMEOUT_MS)); |
| 616 | if (!ret) { |
| 617 | pr_err("%s: wait_event timeout\n", __func__); |
| 618 | goto fail; |
| 619 | } |
| 620 | } |
| 621 | return 0; |
| 622 | fail: |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | |
| 626 | static int voice_config_cvs_vocoder(struct voice_data *v) |
| 627 | { |
| 628 | int ret = 0; |
| 629 | void *apr_cvs; |
| 630 | u16 cvs_handle; |
| 631 | /* Set media type. */ |
| 632 | struct cvs_set_media_type_cmd cvs_set_media_cmd; |
| 633 | |
| 634 | if (v == NULL) { |
| 635 | pr_err("%s: v is NULL\n", __func__); |
| 636 | return -EINVAL; |
| 637 | } |
| 638 | apr_cvs = v->apr_q6_cvs; |
| 639 | |
| 640 | if (!apr_cvs) { |
| 641 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 642 | return -EINVAL; |
| 643 | } |
| 644 | |
| 645 | cvs_handle = voice_get_cvs_handle(v); |
| 646 | |
| 647 | cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 648 | APR_HDR_LEN(APR_HDR_SIZE), |
| 649 | APR_PKT_VER); |
| 650 | cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 651 | sizeof(cvs_set_media_cmd) - APR_HDR_SIZE); |
| 652 | cvs_set_media_cmd.hdr.src_port = 0; |
| 653 | cvs_set_media_cmd.hdr.dest_port = cvs_handle; |
| 654 | cvs_set_media_cmd.hdr.token = 0; |
| 655 | cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE; |
| 656 | cvs_set_media_cmd.media_type.tx_media_id = v->mvs_info.media_type; |
| 657 | cvs_set_media_cmd.media_type.rx_media_id = v->mvs_info.media_type; |
| 658 | |
| 659 | v->cvs_state = CMD_STATUS_FAIL; |
| 660 | |
| 661 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd); |
| 662 | if (ret < 0) { |
| 663 | pr_err("%s: Error %d sending SET_MEDIA_TYPE\n", |
| 664 | __func__, ret); |
| 665 | |
| 666 | goto fail; |
| 667 | } |
| 668 | ret = wait_event_timeout(v->cvs_wait, |
| 669 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 670 | msecs_to_jiffies(TIMEOUT_MS)); |
| 671 | if (!ret) { |
| 672 | pr_err("%s: wait_event timeout\n", __func__); |
| 673 | |
| 674 | goto fail; |
| 675 | } |
| 676 | /* Set encoder properties. */ |
| 677 | switch (v->mvs_info.media_type) { |
| 678 | case VSS_MEDIA_ID_EVRC_MODEM: { |
| 679 | struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate; |
| 680 | |
| 681 | pr_debug("Setting EVRC min-max rate\n"); |
| 682 | |
| 683 | cvs_set_cdma_rate.hdr.hdr_field = |
| 684 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 685 | APR_HDR_LEN(APR_HDR_SIZE), |
| 686 | APR_PKT_VER); |
| 687 | cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 688 | sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE); |
| 689 | cvs_set_cdma_rate.hdr.src_port = 0; |
| 690 | cvs_set_cdma_rate.hdr.dest_port = cvs_handle; |
| 691 | cvs_set_cdma_rate.hdr.token = 0; |
| 692 | cvs_set_cdma_rate.hdr.opcode = |
| 693 | VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE; |
| 694 | cvs_set_cdma_rate.cdma_rate.min_rate = v->mvs_info.rate; |
| 695 | cvs_set_cdma_rate.cdma_rate.max_rate = v->mvs_info.rate; |
| 696 | |
| 697 | v->cvs_state = CMD_STATUS_FAIL; |
| 698 | |
| 699 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate); |
| 700 | if (ret < 0) { |
| 701 | pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n", |
| 702 | __func__, ret); |
| 703 | goto fail; |
| 704 | } |
| 705 | ret = wait_event_timeout(v->cvs_wait, |
| 706 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 707 | msecs_to_jiffies(TIMEOUT_MS)); |
| 708 | if (!ret) { |
| 709 | pr_err("%s: wait_event timeout\n", __func__); |
| 710 | |
| 711 | goto fail; |
| 712 | } |
| 713 | break; |
| 714 | } |
| 715 | case VSS_MEDIA_ID_AMR_NB_MODEM: { |
| 716 | struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate; |
| 717 | struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx; |
| 718 | |
| 719 | pr_debug("Setting AMR rate\n"); |
| 720 | |
| 721 | cvs_set_amr_rate.hdr.hdr_field = |
| 722 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 723 | APR_HDR_LEN(APR_HDR_SIZE), |
| 724 | APR_PKT_VER); |
| 725 | cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 726 | sizeof(cvs_set_amr_rate) - APR_HDR_SIZE); |
| 727 | cvs_set_amr_rate.hdr.src_port = 0; |
| 728 | cvs_set_amr_rate.hdr.dest_port = cvs_handle; |
| 729 | cvs_set_amr_rate.hdr.token = 0; |
| 730 | cvs_set_amr_rate.hdr.opcode = |
| 731 | VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE; |
| 732 | cvs_set_amr_rate.amr_rate.mode = v->mvs_info.rate; |
| 733 | |
| 734 | v->cvs_state = CMD_STATUS_FAIL; |
| 735 | |
| 736 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate); |
| 737 | if (ret < 0) { |
| 738 | pr_err("%s: Error %d sending SET_AMR_RATE\n", |
| 739 | __func__, ret); |
| 740 | goto fail; |
| 741 | } |
| 742 | ret = wait_event_timeout(v->cvs_wait, |
| 743 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 744 | msecs_to_jiffies(TIMEOUT_MS)); |
| 745 | if (!ret) { |
| 746 | pr_err("%s: wait_event timeout\n", __func__); |
| 747 | goto fail; |
| 748 | } |
| 749 | /* Disable DTX */ |
| 750 | pr_debug("Disabling DTX\n"); |
| 751 | |
| 752 | cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 753 | APR_HDR_LEN(APR_HDR_SIZE), |
| 754 | APR_PKT_VER); |
| 755 | cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 756 | sizeof(cvs_set_dtx) - APR_HDR_SIZE); |
| 757 | cvs_set_dtx.hdr.src_port = 0; |
| 758 | cvs_set_dtx.hdr.dest_port = cvs_handle; |
| 759 | cvs_set_dtx.hdr.token = 0; |
| 760 | cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE; |
| 761 | cvs_set_dtx.dtx_mode.enable = 0; |
| 762 | |
| 763 | v->cvs_state = CMD_STATUS_FAIL; |
| 764 | |
| 765 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx); |
| 766 | if (ret < 0) { |
| 767 | pr_err("%s: Error %d sending SET_DTX\n", |
| 768 | __func__, ret); |
| 769 | goto fail; |
| 770 | } |
| 771 | ret = wait_event_timeout(v->cvs_wait, |
| 772 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 773 | msecs_to_jiffies(TIMEOUT_MS)); |
| 774 | if (!ret) { |
| 775 | pr_err("%s: wait_event timeout\n", __func__); |
| 776 | goto fail; |
| 777 | } |
| 778 | break; |
| 779 | } |
| 780 | case VSS_MEDIA_ID_AMR_WB_MODEM: { |
| 781 | struct cvs_set_amrwb_enc_rate_cmd cvs_set_amrwb_rate; |
| 782 | struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx; |
| 783 | |
| 784 | pr_debug("Setting AMR WB rate\n"); |
| 785 | |
| 786 | cvs_set_amrwb_rate.hdr.hdr_field = |
| 787 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 788 | APR_HDR_LEN(APR_HDR_SIZE), |
| 789 | APR_PKT_VER); |
| 790 | cvs_set_amrwb_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 791 | sizeof(cvs_set_amrwb_rate) - |
| 792 | APR_HDR_SIZE); |
| 793 | cvs_set_amrwb_rate.hdr.src_port = 0; |
| 794 | cvs_set_amrwb_rate.hdr.dest_port = cvs_handle; |
| 795 | cvs_set_amrwb_rate.hdr.token = 0; |
| 796 | cvs_set_amrwb_rate.hdr.opcode = |
| 797 | VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE; |
| 798 | cvs_set_amrwb_rate.amrwb_rate.mode = v->mvs_info.rate; |
| 799 | |
| 800 | v->cvs_state = CMD_STATUS_FAIL; |
| 801 | |
| 802 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amrwb_rate); |
| 803 | if (ret < 0) { |
| 804 | pr_err("%s: Error %d sending SET_AMRWB_RATE\n", |
| 805 | __func__, ret); |
| 806 | goto fail; |
| 807 | } |
| 808 | ret = wait_event_timeout(v->cvs_wait, |
| 809 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 810 | msecs_to_jiffies(TIMEOUT_MS)); |
| 811 | if (!ret) { |
| 812 | pr_err("%s: wait_event timeout\n", __func__); |
| 813 | goto fail; |
| 814 | } |
| 815 | /* Disable DTX */ |
| 816 | pr_debug("Disabling DTX\n"); |
| 817 | |
| 818 | cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 819 | APR_HDR_LEN(APR_HDR_SIZE), |
| 820 | APR_PKT_VER); |
| 821 | cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 822 | sizeof(cvs_set_dtx) - APR_HDR_SIZE); |
| 823 | cvs_set_dtx.hdr.src_port = 0; |
| 824 | cvs_set_dtx.hdr.dest_port = cvs_handle; |
| 825 | cvs_set_dtx.hdr.token = 0; |
| 826 | cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE; |
| 827 | cvs_set_dtx.dtx_mode.enable = 0; |
| 828 | |
| 829 | v->cvs_state = CMD_STATUS_FAIL; |
| 830 | |
| 831 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx); |
| 832 | if (ret < 0) { |
| 833 | pr_err("%s: Error %d sending SET_DTX\n", |
| 834 | __func__, ret); |
| 835 | goto fail; |
| 836 | } |
| 837 | ret = wait_event_timeout(v->cvs_wait, |
| 838 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 839 | msecs_to_jiffies(TIMEOUT_MS)); |
| 840 | if (!ret) { |
| 841 | pr_err("%s: wait_event timeout\n", __func__); |
| 842 | goto fail; |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | case VSS_MEDIA_ID_G729: |
| 847 | case VSS_MEDIA_ID_G711_ALAW: |
| 848 | case VSS_MEDIA_ID_G711_MULAW: { |
| 849 | struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx; |
| 850 | /* Disable DTX */ |
| 851 | pr_debug("Disabling DTX\n"); |
| 852 | |
| 853 | cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 854 | APR_HDR_LEN(APR_HDR_SIZE), |
| 855 | APR_PKT_VER); |
| 856 | cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 857 | sizeof(cvs_set_dtx) - APR_HDR_SIZE); |
| 858 | cvs_set_dtx.hdr.src_port = 0; |
| 859 | cvs_set_dtx.hdr.dest_port = cvs_handle; |
| 860 | cvs_set_dtx.hdr.token = 0; |
| 861 | cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE; |
| 862 | cvs_set_dtx.dtx_mode.enable = 0; |
| 863 | |
| 864 | v->cvs_state = CMD_STATUS_FAIL; |
| 865 | |
| 866 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx); |
| 867 | if (ret < 0) { |
| 868 | pr_err("%s: Error %d sending SET_DTX\n", |
| 869 | __func__, ret); |
| 870 | goto fail; |
| 871 | } |
| 872 | ret = wait_event_timeout(v->cvs_wait, |
| 873 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 874 | msecs_to_jiffies(TIMEOUT_MS)); |
| 875 | if (!ret) { |
| 876 | pr_err("%s: wait_event timeout\n", __func__); |
| 877 | goto fail; |
| 878 | } |
| 879 | break; |
| 880 | } |
| 881 | default: |
| 882 | /* Do nothing. */ |
| 883 | break; |
| 884 | } |
| 885 | return 0; |
| 886 | |
| 887 | fail: |
| 888 | return -EINVAL; |
| 889 | } |
| 890 | |
| 891 | static int voice_send_start_voice_cmd(struct voice_data *v) |
| 892 | { |
| 893 | struct apr_hdr mvm_start_voice_cmd; |
| 894 | int ret = 0; |
| 895 | void *apr_mvm; |
| 896 | u16 mvm_handle; |
| 897 | |
| 898 | if (v == NULL) { |
| 899 | pr_err("%s: v is NULL\n", __func__); |
| 900 | return -EINVAL; |
| 901 | } |
| 902 | apr_mvm = v->apr_q6_mvm; |
| 903 | |
| 904 | if (!apr_mvm) { |
| 905 | pr_err("%s: apr_mvm is NULL.\n", __func__); |
| 906 | return -EINVAL; |
| 907 | } |
| 908 | mvm_handle = voice_get_mvm_handle(v); |
| 909 | |
| 910 | mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 911 | APR_HDR_LEN(APR_HDR_SIZE), |
| 912 | APR_PKT_VER); |
| 913 | mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 914 | sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE); |
| 915 | pr_debug("send mvm_start_voice_cmd pkt size = %d\n", |
| 916 | mvm_start_voice_cmd.pkt_size); |
| 917 | mvm_start_voice_cmd.src_port = 0; |
| 918 | mvm_start_voice_cmd.dest_port = mvm_handle; |
| 919 | mvm_start_voice_cmd.token = 0; |
| 920 | mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE; |
| 921 | |
| 922 | v->mvm_state = CMD_STATUS_FAIL; |
| 923 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd); |
| 924 | if (ret < 0) { |
| 925 | pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n"); |
| 926 | goto fail; |
| 927 | } |
| 928 | ret = wait_event_timeout(v->mvm_wait, |
| 929 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 930 | msecs_to_jiffies(TIMEOUT_MS)); |
| 931 | if (!ret) { |
| 932 | pr_err("%s: wait_event timeout\n", __func__); |
| 933 | goto fail; |
| 934 | } |
| 935 | return 0; |
| 936 | fail: |
| 937 | return -EINVAL; |
| 938 | } |
| 939 | |
| 940 | static int voice_send_disable_vocproc_cmd(struct voice_data *v) |
| 941 | { |
| 942 | struct apr_hdr cvp_disable_cmd; |
| 943 | int ret = 0; |
| 944 | void *apr_cvp; |
| 945 | u16 cvp_handle; |
| 946 | |
| 947 | if (v == NULL) { |
| 948 | pr_err("%s: v is NULL\n", __func__); |
| 949 | return -EINVAL; |
| 950 | } |
| 951 | apr_cvp = v->apr_q6_cvp; |
| 952 | |
| 953 | if (!apr_cvp) { |
| 954 | pr_err("%s: apr regist failed\n", __func__); |
| 955 | return -EINVAL; |
| 956 | } |
| 957 | cvp_handle = voice_get_cvp_handle(v); |
| 958 | |
| 959 | /* disable vocproc and wait for respose */ |
| 960 | cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 961 | APR_HDR_LEN(APR_HDR_SIZE), |
| 962 | APR_PKT_VER); |
| 963 | cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 964 | sizeof(cvp_disable_cmd) - APR_HDR_SIZE); |
| 965 | pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n", |
| 966 | cvp_disable_cmd.pkt_size, cvp_handle); |
| 967 | cvp_disable_cmd.src_port = 0; |
| 968 | cvp_disable_cmd.dest_port = cvp_handle; |
| 969 | cvp_disable_cmd.token = 0; |
| 970 | cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE; |
| 971 | |
| 972 | v->cvp_state = CMD_STATUS_FAIL; |
| 973 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd); |
| 974 | if (ret < 0) { |
| 975 | pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n"); |
| 976 | goto fail; |
| 977 | } |
| 978 | ret = wait_event_timeout(v->cvp_wait, |
| 979 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 980 | msecs_to_jiffies(TIMEOUT_MS)); |
| 981 | if (!ret) { |
| 982 | pr_err("%s: wait_event timeout\n", __func__); |
| 983 | goto fail; |
| 984 | } |
| 985 | |
| 986 | return 0; |
| 987 | fail: |
| 988 | return -EINVAL; |
| 989 | } |
| 990 | |
| 991 | static int voice_send_set_device_cmd(struct voice_data *v) |
| 992 | { |
| 993 | struct cvp_set_device_cmd cvp_setdev_cmd; |
| 994 | int ret = 0; |
| 995 | void *apr_cvp; |
| 996 | u16 cvp_handle; |
| 997 | |
| 998 | if (v == NULL) { |
| 999 | pr_err("%s: v is NULL\n", __func__); |
| 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | apr_cvp = v->apr_q6_cvp; |
| 1003 | |
| 1004 | if (!apr_cvp) { |
| 1005 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | cvp_handle = voice_get_cvp_handle(v); |
| 1009 | |
| 1010 | /* set device and wait for response */ |
| 1011 | cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1012 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1013 | APR_PKT_VER); |
| 1014 | cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1015 | sizeof(cvp_setdev_cmd) - APR_HDR_SIZE); |
| 1016 | pr_debug(" send create cvp setdev, pkt size = %d\n", |
| 1017 | cvp_setdev_cmd.hdr.pkt_size); |
| 1018 | cvp_setdev_cmd.hdr.src_port = 0; |
| 1019 | cvp_setdev_cmd.hdr.dest_port = cvp_handle; |
| 1020 | cvp_setdev_cmd.hdr.token = 0; |
| 1021 | cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE; |
| 1022 | |
| 1023 | /* Use default topology if invalid value in ACDB */ |
| 1024 | cvp_setdev_cmd.cvp_set_device.tx_topology_id = |
| 1025 | get_voice_tx_topology(); |
| 1026 | if (cvp_setdev_cmd.cvp_set_device.tx_topology_id == 0) |
| 1027 | cvp_setdev_cmd.cvp_set_device.tx_topology_id = |
| 1028 | VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS; |
| 1029 | |
| 1030 | cvp_setdev_cmd.cvp_set_device.rx_topology_id = |
| 1031 | get_voice_rx_topology(); |
| 1032 | if (cvp_setdev_cmd.cvp_set_device.rx_topology_id == 0) |
| 1033 | cvp_setdev_cmd.cvp_set_device.rx_topology_id = |
| 1034 | VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT; |
| 1035 | cvp_setdev_cmd.cvp_set_device.tx_port_id = v->dev_tx.port_id; |
| 1036 | cvp_setdev_cmd.cvp_set_device.rx_port_id = v->dev_rx.port_id; |
| 1037 | pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n", |
| 1038 | cvp_setdev_cmd.cvp_set_device.tx_topology_id, |
| 1039 | cvp_setdev_cmd.cvp_set_device.tx_port_id, |
| 1040 | cvp_setdev_cmd.cvp_set_device.rx_port_id); |
| 1041 | |
| 1042 | v->cvp_state = CMD_STATUS_FAIL; |
| 1043 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd); |
| 1044 | if (ret < 0) { |
| 1045 | pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n"); |
| 1046 | goto fail; |
| 1047 | } |
| 1048 | pr_debug("wait for cvp create session event\n"); |
| 1049 | ret = wait_event_timeout(v->cvp_wait, |
| 1050 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1051 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1052 | if (!ret) { |
| 1053 | pr_err("%s: wait_event timeout\n", __func__); |
| 1054 | goto fail; |
| 1055 | } |
| 1056 | |
| 1057 | return 0; |
| 1058 | fail: |
| 1059 | return -EINVAL; |
| 1060 | } |
| 1061 | |
| 1062 | static int voice_send_stop_voice_cmd(struct voice_data *v) |
| 1063 | { |
| 1064 | struct apr_hdr mvm_stop_voice_cmd; |
| 1065 | int ret = 0; |
| 1066 | void *apr_mvm; |
| 1067 | u16 mvm_handle; |
| 1068 | |
| 1069 | if (v == NULL) { |
| 1070 | pr_err("%s: v is NULL\n", __func__); |
| 1071 | return -EINVAL; |
| 1072 | } |
| 1073 | apr_mvm = v->apr_q6_mvm; |
| 1074 | |
| 1075 | if (!apr_mvm) { |
| 1076 | pr_err("%s: apr_mvm is NULL.\n", __func__); |
| 1077 | return -EINVAL; |
| 1078 | } |
| 1079 | mvm_handle = voice_get_mvm_handle(v); |
| 1080 | |
| 1081 | mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1082 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1083 | APR_PKT_VER); |
| 1084 | mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1085 | sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE); |
| 1086 | pr_debug("send mvm_stop_voice_cmd pkt size = %d\n", |
| 1087 | mvm_stop_voice_cmd.pkt_size); |
| 1088 | mvm_stop_voice_cmd.src_port = 0; |
| 1089 | mvm_stop_voice_cmd.dest_port = mvm_handle; |
| 1090 | mvm_stop_voice_cmd.token = 0; |
| 1091 | mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE; |
| 1092 | |
| 1093 | v->mvm_state = CMD_STATUS_FAIL; |
| 1094 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd); |
| 1095 | if (ret < 0) { |
| 1096 | pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n"); |
| 1097 | goto fail; |
| 1098 | } |
| 1099 | ret = wait_event_timeout(v->mvm_wait, |
| 1100 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 1101 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1102 | if (!ret) { |
| 1103 | pr_err("%s: wait_event timeout\n", __func__); |
| 1104 | goto fail; |
| 1105 | } |
| 1106 | |
| 1107 | return 0; |
| 1108 | fail: |
| 1109 | return -EINVAL; |
| 1110 | } |
| 1111 | |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 1112 | static int voice_send_cvs_register_cal_cmd(struct voice_data *v) |
| 1113 | { |
| 1114 | struct cvs_register_cal_data_cmd cvs_reg_cal_cmd; |
| 1115 | struct acdb_cal_block cal_block; |
| 1116 | int ret = 0; |
| 1117 | void *apr_cvs; |
| 1118 | u16 cvs_handle; |
| 1119 | |
| 1120 | /* get the cvs cal data */ |
| 1121 | get_all_vocstrm_cal(&cal_block); |
| 1122 | if (cal_block.cal_size == 0) |
| 1123 | goto fail; |
| 1124 | |
| 1125 | if (v == NULL) { |
| 1126 | pr_err("%s: v is NULL\n", __func__); |
| 1127 | return -EINVAL; |
| 1128 | } |
| 1129 | apr_cvs = v->apr_q6_cvs; |
| 1130 | |
| 1131 | if (!apr_cvs) { |
| 1132 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | cvs_handle = voice_get_cvs_handle(v); |
| 1136 | |
| 1137 | /* fill in the header */ |
| 1138 | cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1139 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1140 | cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1141 | sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE); |
| 1142 | cvs_reg_cal_cmd.hdr.src_port = 0; |
| 1143 | cvs_reg_cal_cmd.hdr.dest_port = cvs_handle; |
| 1144 | cvs_reg_cal_cmd.hdr.token = 0; |
| 1145 | cvs_reg_cal_cmd.hdr.opcode = VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA; |
| 1146 | |
| 1147 | cvs_reg_cal_cmd.cvs_cal_data.phys_addr = cal_block.cal_paddr; |
| 1148 | cvs_reg_cal_cmd.cvs_cal_data.mem_size = cal_block.cal_size; |
| 1149 | |
| 1150 | v->cvs_state = CMD_STATUS_FAIL; |
| 1151 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_reg_cal_cmd); |
| 1152 | if (ret < 0) { |
| 1153 | pr_err("Fail: sending cvs cal,\n"); |
| 1154 | goto fail; |
| 1155 | } |
| 1156 | ret = wait_event_timeout(v->cvs_wait, |
| 1157 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 1158 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1159 | if (!ret) { |
| 1160 | pr_err("%s: wait_event timeout\n", __func__); |
| 1161 | goto fail; |
| 1162 | } |
| 1163 | return 0; |
| 1164 | fail: |
| 1165 | return -EINVAL; |
| 1166 | |
| 1167 | } |
| 1168 | |
| 1169 | static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v) |
| 1170 | { |
| 1171 | struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd; |
| 1172 | struct acdb_cal_block cal_block; |
| 1173 | int ret = 0; |
| 1174 | void *apr_cvs; |
| 1175 | u16 cvs_handle; |
| 1176 | |
| 1177 | get_all_vocstrm_cal(&cal_block); |
| 1178 | if (cal_block.cal_size == 0) |
| 1179 | return 0; |
| 1180 | |
| 1181 | if (v == NULL) { |
| 1182 | pr_err("%s: v is NULL\n", __func__); |
| 1183 | return -EINVAL; |
| 1184 | } |
| 1185 | apr_cvs = v->apr_q6_cvs; |
| 1186 | |
| 1187 | if (!apr_cvs) { |
| 1188 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 1189 | return -EINVAL; |
| 1190 | } |
| 1191 | cvs_handle = voice_get_cvs_handle(v); |
| 1192 | |
| 1193 | /* fill in the header */ |
| 1194 | cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1195 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1196 | cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1197 | sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE); |
| 1198 | cvs_dereg_cal_cmd.hdr.src_port = 0; |
| 1199 | cvs_dereg_cal_cmd.hdr.dest_port = cvs_handle; |
| 1200 | cvs_dereg_cal_cmd.hdr.token = 0; |
| 1201 | cvs_dereg_cal_cmd.hdr.opcode = |
| 1202 | VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA; |
| 1203 | |
| 1204 | v->cvs_state = CMD_STATUS_FAIL; |
| 1205 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dereg_cal_cmd); |
| 1206 | if (ret < 0) { |
| 1207 | pr_err("Fail: sending cvs cal,\n"); |
| 1208 | goto fail; |
| 1209 | } |
| 1210 | ret = wait_event_timeout(v->cvs_wait, |
| 1211 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 1212 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1213 | if (!ret) { |
| 1214 | pr_err("%s: wait_event timeout\n", __func__); |
| 1215 | goto fail; |
| 1216 | } |
| 1217 | return 0; |
| 1218 | fail: |
| 1219 | return -EINVAL; |
| 1220 | |
| 1221 | } |
| 1222 | |
| 1223 | static int voice_send_cvp_map_memory_cmd(struct voice_data *v) |
| 1224 | { |
| 1225 | struct vss_map_memory_cmd cvp_map_mem_cmd; |
| 1226 | struct acdb_cal_block cal_block; |
| 1227 | int ret = 0; |
| 1228 | void *apr_cvp; |
| 1229 | u16 cvp_handle; |
| 1230 | |
| 1231 | /* get all cvp cal data */ |
| 1232 | get_all_cvp_cal(&cal_block); |
| 1233 | if (cal_block.cal_size == 0) |
| 1234 | goto fail; |
| 1235 | |
| 1236 | if (v == NULL) { |
| 1237 | pr_err("%s: v is NULL\n", __func__); |
| 1238 | return -EINVAL; |
| 1239 | } |
| 1240 | apr_cvp = v->apr_q6_cvp; |
| 1241 | |
| 1242 | if (!apr_cvp) { |
| 1243 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1244 | return -EINVAL; |
| 1245 | } |
| 1246 | cvp_handle = voice_get_cvp_handle(v); |
| 1247 | |
| 1248 | /* fill in the header */ |
| 1249 | cvp_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1250 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1251 | cvp_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1252 | sizeof(cvp_map_mem_cmd) - APR_HDR_SIZE); |
| 1253 | cvp_map_mem_cmd.hdr.src_port = 0; |
| 1254 | cvp_map_mem_cmd.hdr.dest_port = cvp_handle; |
| 1255 | cvp_map_mem_cmd.hdr.token = 0; |
| 1256 | cvp_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY; |
| 1257 | |
| 1258 | pr_debug("%s, phy_addr:%d, mem_size:%d\n", __func__, |
| 1259 | cal_block.cal_paddr, cal_block.cal_size); |
| 1260 | cvp_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr; |
| 1261 | cvp_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size; |
| 1262 | cvp_map_mem_cmd.vss_map_mem.mem_pool_id = |
| 1263 | VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL; |
| 1264 | |
| 1265 | v->cvp_state = CMD_STATUS_FAIL; |
| 1266 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_map_mem_cmd); |
| 1267 | if (ret < 0) { |
| 1268 | pr_err("Fail: sending cvp cal,\n"); |
| 1269 | goto fail; |
| 1270 | } |
| 1271 | ret = wait_event_timeout(v->cvp_wait, |
| 1272 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1273 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1274 | if (!ret) { |
| 1275 | pr_err("%s: wait_event timeout\n", __func__); |
| 1276 | goto fail; |
| 1277 | } |
| 1278 | return 0; |
| 1279 | fail: |
| 1280 | return -EINVAL; |
| 1281 | |
| 1282 | } |
| 1283 | |
| 1284 | static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v) |
| 1285 | { |
| 1286 | struct vss_unmap_memory_cmd cvp_unmap_mem_cmd; |
| 1287 | struct acdb_cal_block cal_block; |
| 1288 | int ret = 0; |
| 1289 | void *apr_cvp; |
| 1290 | u16 cvp_handle; |
| 1291 | |
| 1292 | get_all_cvp_cal(&cal_block); |
| 1293 | if (cal_block.cal_size == 0) |
| 1294 | return 0; |
| 1295 | |
| 1296 | if (v == NULL) { |
| 1297 | pr_err("%s: v is NULL\n", __func__); |
| 1298 | return -EINVAL; |
| 1299 | } |
| 1300 | apr_cvp = v->apr_q6_cvp; |
| 1301 | |
| 1302 | if (!apr_cvp) { |
| 1303 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1304 | return -EINVAL; |
| 1305 | } |
| 1306 | cvp_handle = voice_get_cvp_handle(v); |
| 1307 | |
| 1308 | /* fill in the header */ |
| 1309 | cvp_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1310 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1311 | cvp_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1312 | sizeof(cvp_unmap_mem_cmd) - APR_HDR_SIZE); |
| 1313 | cvp_unmap_mem_cmd.hdr.src_port = 0; |
| 1314 | cvp_unmap_mem_cmd.hdr.dest_port = cvp_handle; |
| 1315 | cvp_unmap_mem_cmd.hdr.token = 0; |
| 1316 | cvp_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY; |
| 1317 | |
| 1318 | cvp_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr; |
| 1319 | |
| 1320 | v->cvp_state = CMD_STATUS_FAIL; |
| 1321 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_unmap_mem_cmd); |
| 1322 | if (ret < 0) { |
| 1323 | pr_err("Fail: sending cvp cal,\n"); |
| 1324 | goto fail; |
| 1325 | } |
| 1326 | ret = wait_event_timeout(v->cvp_wait, |
| 1327 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1328 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1329 | if (!ret) { |
| 1330 | pr_err("%s: wait_event timeout\n", __func__); |
| 1331 | goto fail; |
| 1332 | } |
| 1333 | return 0; |
| 1334 | fail: |
| 1335 | return -EINVAL; |
| 1336 | |
| 1337 | } |
| 1338 | |
| 1339 | static int voice_send_cvs_map_memory_cmd(struct voice_data *v) |
| 1340 | { |
| 1341 | struct vss_map_memory_cmd cvs_map_mem_cmd; |
| 1342 | struct acdb_cal_block cal_block; |
| 1343 | int ret = 0; |
| 1344 | void *apr_cvs; |
| 1345 | u16 cvs_handle; |
| 1346 | |
| 1347 | /* get all cvs cal data */ |
| 1348 | get_all_vocstrm_cal(&cal_block); |
| 1349 | if (cal_block.cal_size == 0) |
| 1350 | goto fail; |
| 1351 | |
| 1352 | if (v == NULL) { |
| 1353 | pr_err("%s: v is NULL\n", __func__); |
| 1354 | return -EINVAL; |
| 1355 | } |
| 1356 | apr_cvs = v->apr_q6_cvs; |
| 1357 | |
| 1358 | if (!apr_cvs) { |
| 1359 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 1360 | return -EINVAL; |
| 1361 | } |
| 1362 | cvs_handle = voice_get_cvs_handle(v); |
| 1363 | |
| 1364 | /* fill in the header */ |
| 1365 | cvs_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1366 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1367 | cvs_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1368 | sizeof(cvs_map_mem_cmd) - APR_HDR_SIZE); |
| 1369 | cvs_map_mem_cmd.hdr.src_port = 0; |
| 1370 | cvs_map_mem_cmd.hdr.dest_port = cvs_handle; |
| 1371 | cvs_map_mem_cmd.hdr.token = 0; |
| 1372 | cvs_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY; |
| 1373 | |
| 1374 | pr_debug("%s, phys_addr: %d, mem_size: %d\n", __func__, |
| 1375 | cal_block.cal_paddr, cal_block.cal_size); |
| 1376 | cvs_map_mem_cmd.vss_map_mem.phys_addr = cal_block.cal_paddr; |
| 1377 | cvs_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size; |
| 1378 | cvs_map_mem_cmd.vss_map_mem.mem_pool_id = |
| 1379 | VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL; |
| 1380 | |
| 1381 | v->cvs_state = CMD_STATUS_FAIL; |
| 1382 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_map_mem_cmd); |
| 1383 | if (ret < 0) { |
| 1384 | pr_err("Fail: sending cvs cal,\n"); |
| 1385 | goto fail; |
| 1386 | } |
| 1387 | ret = wait_event_timeout(v->cvs_wait, |
| 1388 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 1389 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1390 | if (!ret) { |
| 1391 | pr_err("%s: wait_event timeout\n", __func__); |
| 1392 | goto fail; |
| 1393 | } |
| 1394 | return 0; |
| 1395 | fail: |
| 1396 | return -EINVAL; |
| 1397 | |
| 1398 | } |
| 1399 | |
| 1400 | static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v) |
| 1401 | { |
| 1402 | struct vss_unmap_memory_cmd cvs_unmap_mem_cmd; |
| 1403 | struct acdb_cal_block cal_block; |
| 1404 | int ret = 0; |
| 1405 | void *apr_cvs; |
| 1406 | u16 cvs_handle; |
| 1407 | |
| 1408 | get_all_vocstrm_cal(&cal_block); |
| 1409 | if (cal_block.cal_size == 0) |
| 1410 | return 0; |
| 1411 | |
| 1412 | if (v == NULL) { |
| 1413 | pr_err("%s: v is NULL\n", __func__); |
| 1414 | return -EINVAL; |
| 1415 | } |
| 1416 | apr_cvs = v->apr_q6_cvs; |
| 1417 | |
| 1418 | if (!apr_cvs) { |
| 1419 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 1420 | return -EINVAL; |
| 1421 | } |
| 1422 | cvs_handle = voice_get_cvs_handle(v); |
| 1423 | |
| 1424 | /* fill in the header */ |
| 1425 | cvs_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1426 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1427 | cvs_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1428 | sizeof(cvs_unmap_mem_cmd) - APR_HDR_SIZE); |
| 1429 | cvs_unmap_mem_cmd.hdr.src_port = 0; |
| 1430 | cvs_unmap_mem_cmd.hdr.dest_port = cvs_handle; |
| 1431 | cvs_unmap_mem_cmd.hdr.token = 0; |
| 1432 | cvs_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY; |
| 1433 | |
| 1434 | cvs_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_block.cal_paddr; |
| 1435 | |
| 1436 | v->cvs_state = CMD_STATUS_FAIL; |
| 1437 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_unmap_mem_cmd); |
| 1438 | if (ret < 0) { |
| 1439 | pr_err("Fail: sending cvs cal,\n"); |
| 1440 | goto fail; |
| 1441 | } |
| 1442 | ret = wait_event_timeout(v->cvs_wait, |
| 1443 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 1444 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1445 | if (!ret) { |
| 1446 | pr_err("%s: wait_event timeout\n", __func__); |
| 1447 | goto fail; |
| 1448 | } |
| 1449 | return 0; |
| 1450 | fail: |
| 1451 | return -EINVAL; |
| 1452 | |
| 1453 | } |
| 1454 | |
| 1455 | static int voice_send_cvp_register_cal_cmd(struct voice_data *v) |
| 1456 | { |
| 1457 | struct cvp_register_cal_data_cmd cvp_reg_cal_cmd; |
| 1458 | struct acdb_cal_block cal_block; |
| 1459 | int ret = 0; |
| 1460 | void *apr_cvp; |
| 1461 | u16 cvp_handle; |
| 1462 | |
| 1463 | /* get the cvp cal data */ |
| 1464 | get_all_vocproc_cal(&cal_block); |
| 1465 | if (cal_block.cal_size == 0) |
| 1466 | goto fail; |
| 1467 | |
| 1468 | if (v == NULL) { |
| 1469 | pr_err("%s: v is NULL\n", __func__); |
| 1470 | return -EINVAL; |
| 1471 | } |
| 1472 | apr_cvp = v->apr_q6_cvp; |
| 1473 | |
| 1474 | if (!apr_cvp) { |
| 1475 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1476 | return -EINVAL; |
| 1477 | } |
| 1478 | cvp_handle = voice_get_cvp_handle(v); |
| 1479 | |
| 1480 | /* fill in the header */ |
| 1481 | cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1482 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1483 | cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1484 | sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE); |
| 1485 | cvp_reg_cal_cmd.hdr.src_port = 0; |
| 1486 | cvp_reg_cal_cmd.hdr.dest_port = cvp_handle; |
| 1487 | cvp_reg_cal_cmd.hdr.token = 0; |
| 1488 | cvp_reg_cal_cmd.hdr.opcode = VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA; |
| 1489 | |
| 1490 | cvp_reg_cal_cmd.cvp_cal_data.phys_addr = cal_block.cal_paddr; |
| 1491 | cvp_reg_cal_cmd.cvp_cal_data.mem_size = cal_block.cal_size; |
| 1492 | |
| 1493 | v->cvp_state = CMD_STATUS_FAIL; |
| 1494 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_cmd); |
| 1495 | if (ret < 0) { |
| 1496 | pr_err("Fail: sending cvp cal,\n"); |
| 1497 | goto fail; |
| 1498 | } |
| 1499 | ret = wait_event_timeout(v->cvp_wait, |
| 1500 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1501 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1502 | if (!ret) { |
| 1503 | pr_err("%s: wait_event timeout\n", __func__); |
| 1504 | goto fail; |
| 1505 | } |
| 1506 | return 0; |
| 1507 | fail: |
| 1508 | return -EINVAL; |
| 1509 | |
| 1510 | } |
| 1511 | |
| 1512 | static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v) |
| 1513 | { |
| 1514 | struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd; |
| 1515 | struct acdb_cal_block cal_block; |
| 1516 | int ret = 0; |
| 1517 | void *apr_cvp; |
| 1518 | u16 cvp_handle; |
| 1519 | |
| 1520 | get_all_vocproc_cal(&cal_block); |
| 1521 | if (cal_block.cal_size == 0) |
| 1522 | return 0; |
| 1523 | |
| 1524 | if (v == NULL) { |
| 1525 | pr_err("%s: v is NULL\n", __func__); |
| 1526 | return -EINVAL; |
| 1527 | } |
| 1528 | apr_cvp = v->apr_q6_cvp; |
| 1529 | |
| 1530 | if (!apr_cvp) { |
| 1531 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1532 | return -EINVAL; |
| 1533 | } |
| 1534 | cvp_handle = voice_get_cvp_handle(v); |
| 1535 | |
| 1536 | /* fill in the header */ |
| 1537 | cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1538 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1539 | cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1540 | sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE); |
| 1541 | cvp_dereg_cal_cmd.hdr.src_port = 0; |
| 1542 | cvp_dereg_cal_cmd.hdr.dest_port = cvp_handle; |
| 1543 | cvp_dereg_cal_cmd.hdr.token = 0; |
| 1544 | cvp_dereg_cal_cmd.hdr.opcode = |
| 1545 | VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA; |
| 1546 | |
| 1547 | v->cvp_state = CMD_STATUS_FAIL; |
| 1548 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_cmd); |
| 1549 | if (ret < 0) { |
| 1550 | pr_err("Fail: sending cvp cal,\n"); |
| 1551 | goto fail; |
| 1552 | } |
| 1553 | ret = wait_event_timeout(v->cvp_wait, |
| 1554 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1555 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1556 | if (!ret) { |
| 1557 | pr_err("%s: wait_event timeout\n", __func__); |
| 1558 | goto fail; |
| 1559 | } |
| 1560 | return 0; |
| 1561 | fail: |
| 1562 | return -EINVAL; |
| 1563 | |
| 1564 | } |
| 1565 | |
| 1566 | static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v) |
| 1567 | { |
| 1568 | struct cvp_register_vol_cal_table_cmd cvp_reg_cal_tbl_cmd; |
| 1569 | struct acdb_cal_block cal_block; |
| 1570 | int ret = 0; |
| 1571 | void *apr_cvp; |
| 1572 | u16 cvp_handle; |
| 1573 | |
| 1574 | /* get the cvp vol cal data */ |
| 1575 | get_all_vocvol_cal(&cal_block); |
| 1576 | if (cal_block.cal_size == 0) |
| 1577 | goto fail; |
| 1578 | |
| 1579 | if (v == NULL) { |
| 1580 | pr_err("%s: v is NULL\n", __func__); |
| 1581 | return -EINVAL; |
| 1582 | } |
| 1583 | apr_cvp = v->apr_q6_cvp; |
| 1584 | |
| 1585 | if (!apr_cvp) { |
| 1586 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1587 | return -EINVAL; |
| 1588 | } |
| 1589 | cvp_handle = voice_get_cvp_handle(v); |
| 1590 | |
| 1591 | /* fill in the header */ |
| 1592 | cvp_reg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1593 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1594 | cvp_reg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1595 | sizeof(cvp_reg_cal_tbl_cmd) - APR_HDR_SIZE); |
| 1596 | cvp_reg_cal_tbl_cmd.hdr.src_port = 0; |
| 1597 | cvp_reg_cal_tbl_cmd.hdr.dest_port = cvp_handle; |
| 1598 | cvp_reg_cal_tbl_cmd.hdr.token = 0; |
| 1599 | cvp_reg_cal_tbl_cmd.hdr.opcode = |
| 1600 | VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE; |
| 1601 | |
| 1602 | cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.phys_addr = cal_block.cal_paddr; |
| 1603 | cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.mem_size = cal_block.cal_size; |
| 1604 | |
| 1605 | v->cvp_state = CMD_STATUS_FAIL; |
| 1606 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_tbl_cmd); |
| 1607 | if (ret < 0) { |
| 1608 | pr_err("Fail: sending cvp cal table,\n"); |
| 1609 | goto fail; |
| 1610 | } |
| 1611 | ret = wait_event_timeout(v->cvp_wait, |
| 1612 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1613 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1614 | if (!ret) { |
| 1615 | pr_err("%s: wait_event timeout\n", __func__); |
| 1616 | goto fail; |
| 1617 | } |
| 1618 | return 0; |
| 1619 | fail: |
| 1620 | return -EINVAL; |
| 1621 | |
| 1622 | } |
| 1623 | |
| 1624 | static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v) |
| 1625 | { |
| 1626 | struct cvp_deregister_vol_cal_table_cmd cvp_dereg_cal_tbl_cmd; |
| 1627 | struct acdb_cal_block cal_block; |
| 1628 | int ret = 0; |
| 1629 | void *apr_cvp; |
| 1630 | u16 cvp_handle; |
| 1631 | |
| 1632 | get_all_vocvol_cal(&cal_block); |
| 1633 | if (cal_block.cal_size == 0) |
| 1634 | return 0; |
| 1635 | |
| 1636 | if (v == NULL) { |
| 1637 | pr_err("%s: v is NULL\n", __func__); |
| 1638 | return -EINVAL; |
| 1639 | } |
| 1640 | apr_cvp = v->apr_q6_cvp; |
| 1641 | |
| 1642 | if (!apr_cvp) { |
| 1643 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | cvp_handle = voice_get_cvp_handle(v); |
| 1647 | |
| 1648 | /* fill in the header */ |
| 1649 | cvp_dereg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD( |
| 1650 | APR_MSG_TYPE_SEQ_CMD, |
| 1651 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1652 | APR_PKT_VER); |
| 1653 | cvp_dereg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1654 | sizeof(cvp_dereg_cal_tbl_cmd) - APR_HDR_SIZE); |
| 1655 | cvp_dereg_cal_tbl_cmd.hdr.src_port = 0; |
| 1656 | cvp_dereg_cal_tbl_cmd.hdr.dest_port = cvp_handle; |
| 1657 | cvp_dereg_cal_tbl_cmd.hdr.token = 0; |
| 1658 | cvp_dereg_cal_tbl_cmd.hdr.opcode = |
| 1659 | VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE; |
| 1660 | |
| 1661 | v->cvp_state = CMD_STATUS_FAIL; |
| 1662 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_tbl_cmd); |
| 1663 | if (ret < 0) { |
| 1664 | pr_err("Fail: sending cvp cal table,\n"); |
| 1665 | goto fail; |
| 1666 | } |
| 1667 | ret = wait_event_timeout(v->cvp_wait, |
| 1668 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1669 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1670 | if (!ret) { |
| 1671 | pr_err("%s: wait_event timeout\n", __func__); |
| 1672 | goto fail; |
| 1673 | } |
| 1674 | return 0; |
| 1675 | fail: |
| 1676 | return -EINVAL; |
| 1677 | |
| 1678 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1679 | static int voice_setup_vocproc(struct voice_data *v) |
| 1680 | { |
| 1681 | struct cvp_create_full_ctl_session_cmd cvp_session_cmd; |
| 1682 | int ret = 0; |
| 1683 | void *apr_cvp; |
| 1684 | if (v == NULL) { |
| 1685 | pr_err("%s: v is NULL\n", __func__); |
| 1686 | return -EINVAL; |
| 1687 | } |
| 1688 | apr_cvp = v->apr_q6_cvp; |
| 1689 | |
| 1690 | if (!apr_cvp) { |
| 1691 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1692 | return -EINVAL; |
| 1693 | } |
| 1694 | |
| 1695 | /* create cvp session and wait for response */ |
| 1696 | cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1697 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1698 | APR_PKT_VER); |
| 1699 | cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1700 | sizeof(cvp_session_cmd) - APR_HDR_SIZE); |
| 1701 | pr_debug(" send create cvp session, pkt size = %d\n", |
| 1702 | cvp_session_cmd.hdr.pkt_size); |
| 1703 | cvp_session_cmd.hdr.src_port = 0; |
| 1704 | cvp_session_cmd.hdr.dest_port = 0; |
| 1705 | cvp_session_cmd.hdr.token = 0; |
| 1706 | cvp_session_cmd.hdr.opcode = |
| 1707 | VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION; |
| 1708 | |
| 1709 | /* Use default topology if invalid value in ACDB */ |
| 1710 | cvp_session_cmd.cvp_session.tx_topology_id = |
| 1711 | get_voice_tx_topology(); |
| 1712 | if (cvp_session_cmd.cvp_session.tx_topology_id == 0) |
| 1713 | cvp_session_cmd.cvp_session.tx_topology_id = |
| 1714 | VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS; |
| 1715 | |
| 1716 | cvp_session_cmd.cvp_session.rx_topology_id = |
| 1717 | get_voice_rx_topology(); |
| 1718 | if (cvp_session_cmd.cvp_session.rx_topology_id == 0) |
| 1719 | cvp_session_cmd.cvp_session.rx_topology_id = |
| 1720 | VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT; |
| 1721 | |
| 1722 | cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/ |
| 1723 | cvp_session_cmd.cvp_session.network_id = VSS_NETWORK_ID_DEFAULT; |
| 1724 | cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id; |
| 1725 | cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id; |
| 1726 | |
| 1727 | pr_debug("topology=%d net_id=%d, dir=%d tx_port_id=%d, rx_port_id=%d\n", |
| 1728 | cvp_session_cmd.cvp_session.tx_topology_id, |
| 1729 | cvp_session_cmd.cvp_session.network_id, |
| 1730 | cvp_session_cmd.cvp_session.direction, |
| 1731 | cvp_session_cmd.cvp_session.tx_port_id, |
| 1732 | cvp_session_cmd.cvp_session.rx_port_id); |
| 1733 | |
| 1734 | v->cvp_state = CMD_STATUS_FAIL; |
| 1735 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd); |
| 1736 | if (ret < 0) { |
| 1737 | pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n"); |
| 1738 | goto fail; |
| 1739 | } |
| 1740 | ret = wait_event_timeout(v->cvp_wait, |
| 1741 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1742 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1743 | if (!ret) { |
| 1744 | pr_err("%s: wait_event timeout\n", __func__); |
| 1745 | goto fail; |
| 1746 | } |
| 1747 | |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 1748 | /* send cvs cal */ |
| 1749 | ret = voice_send_cvs_map_memory_cmd(v); |
| 1750 | if (!ret) |
| 1751 | voice_send_cvs_register_cal_cmd(v); |
| 1752 | |
| 1753 | /* send cvp and vol cal */ |
| 1754 | ret = voice_send_cvp_map_memory_cmd(v); |
| 1755 | if (!ret) { |
| 1756 | voice_send_cvp_register_cal_cmd(v); |
| 1757 | voice_send_cvp_register_vol_cal_table_cmd(v); |
| 1758 | } |
| 1759 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1760 | /* enable vocproc */ |
| 1761 | ret = voice_send_enable_vocproc_cmd(v); |
| 1762 | if (ret < 0) |
| 1763 | goto fail; |
| 1764 | |
| 1765 | /* attach vocproc */ |
| 1766 | ret = voice_send_attach_vocproc_cmd(v); |
| 1767 | if (ret < 0) |
| 1768 | goto fail; |
| 1769 | |
| 1770 | /* send tty mode if tty device is used */ |
| 1771 | voice_send_tty_mode_cmd(v); |
| 1772 | |
| 1773 | if (v->voc_path == VOC_PATH_FULL) |
| 1774 | voice_send_netid_timing_cmd(v); |
| 1775 | |
| 1776 | return 0; |
| 1777 | |
| 1778 | fail: |
| 1779 | return -EINVAL; |
| 1780 | } |
| 1781 | |
| 1782 | static int voice_send_enable_vocproc_cmd(struct voice_data *v) |
| 1783 | { |
| 1784 | int ret = 0; |
| 1785 | struct apr_hdr cvp_enable_cmd; |
| 1786 | void *apr_cvp; |
| 1787 | u16 cvp_handle; |
| 1788 | |
| 1789 | if (v == NULL) { |
| 1790 | pr_err("%s: v is NULL\n", __func__); |
| 1791 | return -EINVAL; |
| 1792 | } |
| 1793 | apr_cvp = v->apr_q6_cvp; |
| 1794 | |
| 1795 | if (!apr_cvp) { |
| 1796 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 1797 | return -EINVAL; |
| 1798 | } |
| 1799 | cvp_handle = voice_get_cvp_handle(v); |
| 1800 | |
| 1801 | /* enable vocproc and wait for respose */ |
| 1802 | cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1803 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1804 | APR_PKT_VER); |
| 1805 | cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1806 | sizeof(cvp_enable_cmd) - APR_HDR_SIZE); |
| 1807 | pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n", |
| 1808 | cvp_enable_cmd.pkt_size, cvp_handle); |
| 1809 | cvp_enable_cmd.src_port = 0; |
| 1810 | cvp_enable_cmd.dest_port = cvp_handle; |
| 1811 | cvp_enable_cmd.token = 0; |
| 1812 | cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE; |
| 1813 | |
| 1814 | v->cvp_state = CMD_STATUS_FAIL; |
| 1815 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd); |
| 1816 | if (ret < 0) { |
| 1817 | pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n"); |
| 1818 | goto fail; |
| 1819 | } |
| 1820 | ret = wait_event_timeout(v->cvp_wait, |
| 1821 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 1822 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1823 | if (!ret) { |
| 1824 | pr_err("%s: wait_event timeout\n", __func__); |
| 1825 | goto fail; |
| 1826 | } |
| 1827 | |
| 1828 | return 0; |
| 1829 | fail: |
| 1830 | return -EINVAL; |
| 1831 | } |
| 1832 | |
| 1833 | static int voice_send_netid_timing_cmd(struct voice_data *v) |
| 1834 | { |
| 1835 | int ret = 0; |
| 1836 | void *apr_mvm; |
| 1837 | u16 mvm_handle; |
| 1838 | struct mvm_set_network_cmd mvm_set_network; |
| 1839 | struct mvm_set_voice_timing_cmd mvm_set_voice_timing; |
| 1840 | |
| 1841 | if (v == NULL) { |
| 1842 | pr_err("%s: v is NULL\n", __func__); |
| 1843 | return -EINVAL; |
| 1844 | } |
| 1845 | apr_mvm = v->apr_q6_mvm; |
| 1846 | |
| 1847 | if (!apr_mvm) { |
| 1848 | pr_err("%s: apr_mvm is NULL.\n", __func__); |
| 1849 | return -EINVAL; |
| 1850 | } |
| 1851 | mvm_handle = voice_get_mvm_handle(v); |
| 1852 | |
| 1853 | ret = voice_config_cvs_vocoder(v); |
| 1854 | if (ret < 0) { |
| 1855 | pr_err("%s: Error %d configuring CVS voc", |
| 1856 | __func__, ret); |
| 1857 | goto fail; |
| 1858 | } |
| 1859 | /* Set network ID. */ |
| 1860 | pr_debug("Setting network ID\n"); |
| 1861 | |
| 1862 | mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1863 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1864 | APR_PKT_VER); |
| 1865 | mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1866 | sizeof(mvm_set_network) - APR_HDR_SIZE); |
| 1867 | mvm_set_network.hdr.src_port = 0; |
| 1868 | mvm_set_network.hdr.dest_port = mvm_handle; |
| 1869 | mvm_set_network.hdr.token = 0; |
| 1870 | mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK; |
| 1871 | mvm_set_network.network.network_id = v->mvs_info.network_type; |
| 1872 | |
| 1873 | v->mvm_state = CMD_STATUS_FAIL; |
| 1874 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network); |
| 1875 | if (ret < 0) { |
| 1876 | pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret); |
| 1877 | goto fail; |
| 1878 | } |
| 1879 | |
| 1880 | ret = wait_event_timeout(v->mvm_wait, |
| 1881 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 1882 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1883 | if (!ret) { |
| 1884 | pr_err("%s: wait_event timeout\n", __func__); |
| 1885 | goto fail; |
| 1886 | } |
| 1887 | |
| 1888 | /* Set voice timing. */ |
| 1889 | pr_debug("Setting voice timing\n"); |
| 1890 | |
| 1891 | mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1892 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1893 | APR_PKT_VER); |
| 1894 | mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1895 | sizeof(mvm_set_voice_timing) - |
| 1896 | APR_HDR_SIZE); |
| 1897 | mvm_set_voice_timing.hdr.src_port = 0; |
| 1898 | mvm_set_voice_timing.hdr.dest_port = mvm_handle; |
| 1899 | mvm_set_voice_timing.hdr.token = 0; |
| 1900 | mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING; |
| 1901 | mvm_set_voice_timing.timing.mode = 0; |
| 1902 | mvm_set_voice_timing.timing.enc_offset = 8000; |
| 1903 | mvm_set_voice_timing.timing.dec_req_offset = 3300; |
| 1904 | mvm_set_voice_timing.timing.dec_offset = 8300; |
| 1905 | |
| 1906 | v->mvm_state = CMD_STATUS_FAIL; |
| 1907 | |
| 1908 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing); |
| 1909 | if (ret < 0) { |
| 1910 | pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret); |
| 1911 | goto fail; |
| 1912 | } |
| 1913 | |
| 1914 | ret = wait_event_timeout(v->mvm_wait, |
| 1915 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 1916 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1917 | if (!ret) { |
| 1918 | pr_err("%s: wait_event timeout\n", __func__); |
| 1919 | goto fail; |
| 1920 | } |
| 1921 | |
| 1922 | return 0; |
| 1923 | fail: |
| 1924 | return -EINVAL; |
| 1925 | } |
| 1926 | |
| 1927 | static int voice_send_attach_vocproc_cmd(struct voice_data *v) |
| 1928 | { |
| 1929 | int ret = 0; |
| 1930 | struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd; |
| 1931 | void *apr_mvm; |
| 1932 | u16 mvm_handle, cvp_handle; |
| 1933 | |
| 1934 | if (v == NULL) { |
| 1935 | pr_err("%s: v is NULL\n", __func__); |
| 1936 | return -EINVAL; |
| 1937 | } |
| 1938 | apr_mvm = v->apr_q6_mvm; |
| 1939 | |
| 1940 | if (!apr_mvm) { |
| 1941 | pr_err("%s: apr_mvm is NULL.\n", __func__); |
| 1942 | return -EINVAL; |
| 1943 | } |
| 1944 | mvm_handle = voice_get_mvm_handle(v); |
| 1945 | cvp_handle = voice_get_cvp_handle(v); |
| 1946 | |
| 1947 | /* attach vocproc and wait for response */ |
| 1948 | mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1949 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1950 | APR_PKT_VER); |
| 1951 | mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 1952 | sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE); |
| 1953 | pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n", |
| 1954 | mvm_a_vocproc_cmd.hdr.pkt_size); |
| 1955 | mvm_a_vocproc_cmd.hdr.src_port = 0; |
| 1956 | mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle; |
| 1957 | mvm_a_vocproc_cmd.hdr.token = 0; |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 1958 | mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1959 | mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle; |
| 1960 | |
| 1961 | v->mvm_state = CMD_STATUS_FAIL; |
| 1962 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd); |
| 1963 | if (ret < 0) { |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 1964 | pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1965 | goto fail; |
| 1966 | } |
| 1967 | ret = wait_event_timeout(v->mvm_wait, |
| 1968 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 1969 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1970 | if (!ret) { |
| 1971 | pr_err("%s: wait_event timeout\n", __func__); |
| 1972 | goto fail; |
| 1973 | } |
| 1974 | |
| 1975 | return 0; |
| 1976 | fail: |
| 1977 | return -EINVAL; |
| 1978 | } |
| 1979 | |
| 1980 | static int voice_destroy_vocproc(struct voice_data *v) |
| 1981 | { |
| 1982 | struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd; |
| 1983 | struct apr_hdr cvp_destroy_session_cmd; |
| 1984 | int ret = 0; |
| 1985 | void *apr_mvm, *apr_cvp; |
| 1986 | u16 mvm_handle, cvp_handle; |
| 1987 | |
| 1988 | if (v == NULL) { |
| 1989 | pr_err("%s: v is NULL\n", __func__); |
| 1990 | return -EINVAL; |
| 1991 | } |
| 1992 | apr_mvm = v->apr_q6_mvm; |
| 1993 | apr_cvp = v->apr_q6_cvp; |
| 1994 | |
| 1995 | if (!apr_mvm || !apr_cvp) { |
| 1996 | pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__); |
| 1997 | return -EINVAL; |
| 1998 | } |
| 1999 | mvm_handle = voice_get_mvm_handle(v); |
| 2000 | cvp_handle = voice_get_cvp_handle(v); |
| 2001 | |
| 2002 | /* send stop voice cmd */ |
| 2003 | voice_send_stop_voice_cmd(v); |
| 2004 | |
| 2005 | /* detach VOCPROC and wait for response from mvm */ |
| 2006 | mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2007 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2008 | APR_PKT_VER); |
| 2009 | mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 2010 | sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE); |
| 2011 | pr_debug("mvm_d_vocproc_cmd pkt size = %d\n", |
| 2012 | mvm_d_vocproc_cmd.hdr.pkt_size); |
| 2013 | mvm_d_vocproc_cmd.hdr.src_port = 0; |
| 2014 | mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle; |
| 2015 | mvm_d_vocproc_cmd.hdr.token = 0; |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 2016 | mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2017 | mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle; |
| 2018 | |
| 2019 | v->mvm_state = CMD_STATUS_FAIL; |
| 2020 | ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd); |
| 2021 | if (ret < 0) { |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 2022 | pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2023 | goto fail; |
| 2024 | } |
| 2025 | ret = wait_event_timeout(v->mvm_wait, |
| 2026 | (v->mvm_state == CMD_STATUS_SUCCESS), |
| 2027 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2028 | if (!ret) { |
| 2029 | pr_err("%s: wait_event timeout\n", __func__); |
| 2030 | goto fail; |
| 2031 | } |
| 2032 | |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 2033 | /* deregister cvp and vol cal */ |
| 2034 | voice_send_cvp_deregister_vol_cal_table_cmd(v); |
| 2035 | voice_send_cvp_deregister_cal_cmd(v); |
| 2036 | voice_send_cvp_unmap_memory_cmd(v); |
| 2037 | |
| 2038 | /* deregister cvs cal */ |
| 2039 | voice_send_cvs_deregister_cal_cmd(v); |
| 2040 | voice_send_cvs_unmap_memory_cmd(v); |
| 2041 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2042 | /* destrop cvp session */ |
| 2043 | cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2044 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2045 | APR_PKT_VER); |
| 2046 | cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 2047 | sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE); |
| 2048 | pr_debug("cvp_destroy_session_cmd pkt size = %d\n", |
| 2049 | cvp_destroy_session_cmd.pkt_size); |
| 2050 | cvp_destroy_session_cmd.src_port = 0; |
| 2051 | cvp_destroy_session_cmd.dest_port = cvp_handle; |
| 2052 | cvp_destroy_session_cmd.token = 0; |
| 2053 | cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION; |
| 2054 | |
| 2055 | v->cvp_state = CMD_STATUS_FAIL; |
| 2056 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd); |
| 2057 | if (ret < 0) { |
| 2058 | pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n"); |
| 2059 | goto fail; |
| 2060 | } |
| 2061 | ret = wait_event_timeout(v->cvp_wait, |
| 2062 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 2063 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2064 | if (!ret) { |
| 2065 | pr_err("%s: wait_event timeout\n", __func__); |
| 2066 | goto fail; |
| 2067 | } |
| 2068 | |
| 2069 | cvp_handle = 0; |
| 2070 | voice_set_cvp_handle(v, cvp_handle); |
| 2071 | |
| 2072 | return 0; |
| 2073 | |
| 2074 | fail: |
| 2075 | return -EINVAL; |
| 2076 | } |
| 2077 | |
| 2078 | static int voice_send_mute_cmd(struct voice_data *v) |
| 2079 | { |
| 2080 | struct cvs_set_mute_cmd cvs_mute_cmd; |
| 2081 | int ret = 0; |
| 2082 | void *apr_cvs; |
| 2083 | u16 cvs_handle; |
| 2084 | |
| 2085 | if (v == NULL) { |
| 2086 | pr_err("%s: v is NULL\n", __func__); |
| 2087 | return -EINVAL; |
| 2088 | } |
| 2089 | apr_cvs = v->apr_q6_cvs; |
| 2090 | |
| 2091 | if (!apr_cvs) { |
| 2092 | pr_err("%s: apr_cvs is NULL.\n", __func__); |
| 2093 | return -EINVAL; |
| 2094 | } |
| 2095 | cvs_handle = voice_get_cvs_handle(v); |
| 2096 | |
| 2097 | /* send mute/unmute to cvs */ |
| 2098 | cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2099 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2100 | APR_PKT_VER); |
| 2101 | cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 2102 | sizeof(cvs_mute_cmd) - APR_HDR_SIZE); |
| 2103 | cvs_mute_cmd.hdr.src_port = 0; |
| 2104 | cvs_mute_cmd.hdr.dest_port = cvs_handle; |
| 2105 | cvs_mute_cmd.hdr.token = 0; |
| 2106 | cvs_mute_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MUTE; |
| 2107 | cvs_mute_cmd.cvs_set_mute.direction = 0; /*tx*/ |
| 2108 | cvs_mute_cmd.cvs_set_mute.mute_flag = v->dev_tx.mute; |
| 2109 | |
| 2110 | pr_info(" mute value =%d\n", cvs_mute_cmd.cvs_set_mute.mute_flag); |
| 2111 | v->cvs_state = CMD_STATUS_FAIL; |
| 2112 | ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_mute_cmd); |
| 2113 | if (ret < 0) { |
| 2114 | pr_err("Fail: send STREAM SET MUTE\n"); |
| 2115 | goto fail; |
| 2116 | } |
| 2117 | ret = wait_event_timeout(v->cvs_wait, |
| 2118 | (v->cvs_state == CMD_STATUS_SUCCESS), |
| 2119 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2120 | if (!ret) |
| 2121 | pr_err("%s: wait_event timeout\n", __func__); |
| 2122 | |
| 2123 | return 0; |
| 2124 | fail: |
| 2125 | return -EINVAL; |
| 2126 | } |
| 2127 | |
| 2128 | static int voice_send_vol_index_cmd(struct voice_data *v) |
| 2129 | { |
| 2130 | struct cvp_set_rx_volume_index_cmd cvp_vol_cmd; |
| 2131 | int ret = 0; |
| 2132 | void *apr_cvp; |
| 2133 | u16 cvp_handle; |
| 2134 | if (v == NULL) { |
| 2135 | pr_err("%s: v is NULL\n", __func__); |
| 2136 | return -EINVAL; |
| 2137 | } |
| 2138 | apr_cvp = v->apr_q6_cvp; |
| 2139 | |
| 2140 | if (!apr_cvp) { |
| 2141 | pr_err("%s: apr_cvp is NULL.\n", __func__); |
| 2142 | return -EINVAL; |
| 2143 | } |
| 2144 | cvp_handle = voice_get_cvp_handle(v); |
| 2145 | |
| 2146 | /* send volume index to cvp */ |
| 2147 | cvp_vol_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2148 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2149 | APR_PKT_VER); |
| 2150 | cvp_vol_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 2151 | sizeof(cvp_vol_cmd) - APR_HDR_SIZE); |
| 2152 | cvp_vol_cmd.hdr.src_port = 0; |
| 2153 | cvp_vol_cmd.hdr.dest_port = cvp_handle; |
| 2154 | cvp_vol_cmd.hdr.token = 0; |
| 2155 | cvp_vol_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX; |
| 2156 | cvp_vol_cmd.cvp_set_vol_idx.vol_index = v->dev_rx.volume; |
| 2157 | v->cvp_state = CMD_STATUS_FAIL; |
| 2158 | ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_cmd); |
| 2159 | if (ret < 0) { |
| 2160 | pr_err("Fail in sending RX VOL INDEX\n"); |
| 2161 | return -EINVAL; |
| 2162 | } |
| 2163 | ret = wait_event_timeout(v->cvp_wait, |
| 2164 | (v->cvp_state == CMD_STATUS_SUCCESS), |
| 2165 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2166 | if (!ret) { |
| 2167 | pr_err("%s: wait_event timeout\n", __func__); |
| 2168 | return -EINVAL; |
| 2169 | } |
| 2170 | return 0; |
| 2171 | } |
| 2172 | |
| 2173 | int voc_disable_cvp(void) |
| 2174 | { |
| 2175 | struct voice_data *v = &voice; |
| 2176 | int ret = 0; |
| 2177 | |
| 2178 | mutex_lock(&v->lock); |
| 2179 | |
| 2180 | if (v->voc_state == VOC_RUN) { |
| 2181 | afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0); |
| 2182 | /* send cmd to dsp to disable vocproc */ |
| 2183 | ret = voice_send_disable_vocproc_cmd(v); |
| 2184 | if (ret < 0) { |
| 2185 | pr_err("%s: disable vocproc failed\n", __func__); |
| 2186 | goto fail; |
| 2187 | } |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 2188 | |
| 2189 | /* deregister cvp and vol cal */ |
| 2190 | voice_send_cvp_deregister_vol_cal_table_cmd(v); |
| 2191 | voice_send_cvp_deregister_cal_cmd(v); |
| 2192 | voice_send_cvp_unmap_memory_cmd(v); |
| 2193 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2194 | v->voc_state = VOC_CHANGE; |
| 2195 | } |
| 2196 | |
| 2197 | fail: mutex_unlock(&v->lock); |
| 2198 | |
| 2199 | return ret; |
| 2200 | } |
| 2201 | |
| 2202 | int voc_enable_cvp(void) |
| 2203 | { |
| 2204 | struct voice_data *v = &voice; |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2205 | struct sidetone_cal sidetone_cal_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2206 | int ret = 0; |
| 2207 | |
| 2208 | mutex_lock(&v->lock); |
| 2209 | |
| 2210 | if (v->voc_state == VOC_CHANGE) { |
| 2211 | ret = voice_send_set_device_cmd(v); |
| 2212 | if (ret < 0) { |
| 2213 | pr_err("%s: set device failed\n", __func__); |
| 2214 | goto fail; |
| 2215 | } |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 2216 | /* send cvp and vol cal */ |
| 2217 | ret = voice_send_cvp_map_memory_cmd(v); |
| 2218 | if (!ret) { |
| 2219 | voice_send_cvp_register_cal_cmd(v); |
| 2220 | voice_send_cvp_register_vol_cal_table_cmd(v); |
| 2221 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2222 | ret = voice_send_enable_vocproc_cmd(v); |
| 2223 | if (ret < 0) { |
| 2224 | pr_err("enable vocproc failed\n"); |
| 2225 | goto fail; |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 2226 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2227 | } |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 2228 | /* send tty mode if tty device is used */ |
| 2229 | voice_send_tty_mode_cmd(v); |
| 2230 | |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2231 | get_sidetone_cal(&sidetone_cal_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2232 | ret = afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2233 | sidetone_cal_data.enable, |
| 2234 | sidetone_cal_data.gain); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2235 | |
| 2236 | if (ret < 0) |
| 2237 | pr_err("AFE command sidetone failed\n"); |
| 2238 | |
| 2239 | v->voc_state = VOC_RUN; |
| 2240 | } |
| 2241 | |
| 2242 | fail: |
| 2243 | mutex_unlock(&v->lock); |
| 2244 | |
| 2245 | return ret; |
| 2246 | } |
| 2247 | |
| 2248 | int voc_set_tx_mute(uint32_t dir, uint32_t mute) |
| 2249 | { |
| 2250 | struct voice_data *v = &voice; |
| 2251 | int ret = 0; |
| 2252 | |
| 2253 | mutex_lock(&v->lock); |
| 2254 | |
| 2255 | v->dev_tx.mute = mute; |
| 2256 | |
| 2257 | if (v->voc_state == VOC_RUN) |
| 2258 | ret = voice_send_mute_cmd(v); |
| 2259 | |
| 2260 | mutex_unlock(&v->lock); |
| 2261 | |
| 2262 | return ret; |
| 2263 | } |
| 2264 | |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 2265 | int voc_set_tty_mode(uint8_t tty_mode) |
| 2266 | { |
| 2267 | struct voice_data *v = &voice; |
| 2268 | int ret = 0; |
| 2269 | |
| 2270 | mutex_lock(&v->lock); |
| 2271 | |
| 2272 | v->tty_mode = tty_mode; |
| 2273 | |
| 2274 | mutex_unlock(&v->lock); |
| 2275 | |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
| 2279 | uint8_t voc_get_tty_mode(void) |
| 2280 | { |
| 2281 | struct voice_data *v = &voice; |
| 2282 | int ret = 0; |
| 2283 | |
| 2284 | mutex_lock(&v->lock); |
| 2285 | |
| 2286 | ret = v->tty_mode; |
| 2287 | |
| 2288 | mutex_unlock(&v->lock); |
| 2289 | |
| 2290 | return ret; |
| 2291 | } |
| 2292 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2293 | int voc_set_rx_vol_index(uint32_t dir, uint32_t vol_idx) |
| 2294 | { |
| 2295 | struct voice_data *v = &voice; |
| 2296 | int ret = 0; |
| 2297 | |
| 2298 | mutex_lock(&v->lock); |
| 2299 | |
| 2300 | v->dev_rx.volume = vol_idx; |
| 2301 | |
| 2302 | if (v->voc_state == VOC_RUN) |
| 2303 | ret = voice_send_vol_index_cmd(v); |
| 2304 | |
| 2305 | mutex_unlock(&v->lock); |
| 2306 | |
| 2307 | return ret; |
| 2308 | } |
| 2309 | |
| 2310 | void voc_set_rxtx_port(uint32_t port_id, uint32_t dev_type) |
| 2311 | { |
| 2312 | struct voice_data *v = &voice; |
| 2313 | |
| 2314 | pr_debug(" port_id=%d, type=%d\n", port_id, dev_type); |
| 2315 | |
| 2316 | mutex_lock(&v->lock); |
| 2317 | |
| 2318 | if (dev_type == DEV_RX) |
| 2319 | v->dev_rx.port_id = port_id; |
| 2320 | else |
| 2321 | v->dev_tx.port_id = port_id; |
| 2322 | |
| 2323 | mutex_unlock(&v->lock); |
| 2324 | |
| 2325 | return; |
| 2326 | } |
| 2327 | |
| 2328 | void voc_set_route_flag(uint8_t path_dir, uint8_t set) |
| 2329 | { |
| 2330 | struct voice_data *v = &voice; |
| 2331 | |
| 2332 | pr_debug("path_dir=%d, set=%d\n", path_dir, set); |
| 2333 | |
| 2334 | mutex_lock(&v->lock); |
| 2335 | |
| 2336 | if (path_dir == RX_PATH) |
| 2337 | v->voc_route_state.rx_route_flag = set; |
| 2338 | else |
| 2339 | v->voc_route_state.tx_route_flag = set; |
| 2340 | |
| 2341 | mutex_unlock(&v->lock); |
| 2342 | |
| 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | uint8_t voc_get_route_flag(uint8_t path_dir) |
| 2347 | { |
| 2348 | struct voice_data *v = &voice; |
| 2349 | int ret = 0; |
| 2350 | |
| 2351 | mutex_lock(&v->lock); |
| 2352 | |
| 2353 | if (path_dir == RX_PATH) |
| 2354 | ret = v->voc_route_state.rx_route_flag; |
| 2355 | else |
| 2356 | ret = v->voc_route_state.tx_route_flag; |
| 2357 | |
| 2358 | mutex_unlock(&v->lock); |
| 2359 | |
| 2360 | return ret; |
| 2361 | } |
| 2362 | |
| 2363 | int voc_end_voice_call(void) |
| 2364 | { |
| 2365 | struct voice_data *v = &voice; |
| 2366 | int ret = 0; |
| 2367 | |
| 2368 | mutex_lock(&v->lock); |
| 2369 | |
| 2370 | if (v->voc_state == VOC_RUN) { |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2371 | afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id, 0, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2372 | ret = voice_destroy_vocproc(v); |
| 2373 | if (ret < 0) |
| 2374 | pr_err("%s: destroy voice failed\n", __func__); |
| 2375 | voice_destroy_mvm_cvs_session(v); |
| 2376 | |
| 2377 | v->voc_state = VOC_RELEASE; |
| 2378 | } |
| 2379 | mutex_unlock(&v->lock); |
| 2380 | return ret; |
| 2381 | } |
| 2382 | |
| 2383 | int voc_start_voice_call(void) |
| 2384 | { |
| 2385 | struct voice_data *v = &voice; |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2386 | struct sidetone_cal sidetone_cal_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2387 | int ret = 0; |
| 2388 | |
| 2389 | mutex_lock(&v->lock); |
| 2390 | |
| 2391 | if ((v->voc_state == VOC_INIT) || |
| 2392 | (v->voc_state == VOC_RELEASE)) { |
| 2393 | ret = voice_apr_register(v); |
| 2394 | if (ret < 0) { |
| 2395 | pr_err("%s: apr register failed\n", __func__); |
| 2396 | goto fail; |
| 2397 | } |
| 2398 | ret = voice_create_mvm_cvs_session(v); |
| 2399 | if (ret < 0) { |
| 2400 | pr_err("create mvm and cvs failed\n"); |
| 2401 | goto fail; |
| 2402 | } |
| 2403 | ret = voice_setup_vocproc(v); |
| 2404 | if (ret < 0) { |
| 2405 | pr_err("setup voice failed\n"); |
| 2406 | goto fail; |
| 2407 | } |
| 2408 | ret = voice_send_start_voice_cmd(v); |
| 2409 | if (ret < 0) { |
| 2410 | pr_err("start voice failed\n"); |
| 2411 | goto fail; |
| 2412 | } |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2413 | get_sidetone_cal(&sidetone_cal_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2414 | ret = afe_sidetone(v->dev_tx.port_id, |
Helen Zeng | bd58e2c | 2011-07-01 16:24:31 -0700 | [diff] [blame] | 2415 | v->dev_rx.port_id, |
| 2416 | sidetone_cal_data.enable, |
| 2417 | sidetone_cal_data.gain); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2418 | if (ret < 0) |
| 2419 | pr_err("AFE command sidetone failed\n"); |
| 2420 | |
| 2421 | v->voc_state = VOC_RUN; |
| 2422 | } |
| 2423 | |
| 2424 | fail: mutex_unlock(&v->lock); |
| 2425 | return ret; |
| 2426 | } |
| 2427 | |
| 2428 | int voc_set_voc_path_full(uint32_t set) |
| 2429 | { |
| 2430 | int rc = 0; |
| 2431 | |
| 2432 | pr_debug("set voc path: %d\n", set); |
| 2433 | |
| 2434 | mutex_lock(&voice.lock); |
| 2435 | |
| 2436 | if (voice.voc_state == VOC_INIT || voice.voc_state == VOC_RELEASE) { |
| 2437 | if (set) |
| 2438 | voice.voc_path = VOC_PATH_FULL; |
| 2439 | else |
| 2440 | voice.voc_path = VOC_PATH_PASSIVE; |
| 2441 | } else { |
| 2442 | pr_err("%s: Invalid voc path set to %d, in state %d\n", |
| 2443 | __func__, set, voice.voc_state); |
| 2444 | rc = -EPERM; |
| 2445 | } |
| 2446 | |
| 2447 | mutex_unlock(&voice.lock); |
| 2448 | |
| 2449 | return rc; |
| 2450 | } |
| 2451 | EXPORT_SYMBOL(voc_set_voc_path_full); |
| 2452 | |
| 2453 | void voc_register_mvs_cb(ul_cb_fn ul_cb, |
| 2454 | dl_cb_fn dl_cb, |
| 2455 | void *private_data) |
| 2456 | { |
| 2457 | voice.mvs_info.ul_cb = ul_cb; |
| 2458 | voice.mvs_info.dl_cb = dl_cb; |
| 2459 | voice.mvs_info.private_data = private_data; |
| 2460 | } |
| 2461 | |
| 2462 | void voc_config_vocoder(uint32_t media_type, |
| 2463 | uint32_t rate, |
| 2464 | uint32_t network_type) |
| 2465 | { |
| 2466 | voice.mvs_info.media_type = media_type; |
| 2467 | voice.mvs_info.rate = rate; |
| 2468 | voice.mvs_info.network_type = network_type; |
| 2469 | } |
| 2470 | |
| 2471 | static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv) |
| 2472 | { |
| 2473 | uint32_t *ptr; |
| 2474 | struct voice_data *v; |
| 2475 | |
| 2476 | if ((data == NULL) || (priv == NULL)) { |
| 2477 | pr_err("%s: data or priv is NULL\n", __func__); |
| 2478 | return -EINVAL; |
| 2479 | } |
| 2480 | v = priv; |
| 2481 | |
| 2482 | pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__, |
| 2483 | data->payload_size, data->opcode); |
| 2484 | |
| 2485 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 2486 | if (data->payload_size) { |
| 2487 | ptr = data->payload; |
| 2488 | |
| 2489 | pr_info("%x %x\n", ptr[0], ptr[1]); |
| 2490 | /* ping mvm service ACK */ |
| 2491 | switch (ptr[0]) { |
| 2492 | case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION: |
| 2493 | case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION: |
| 2494 | /* Passive session is used for CS call |
| 2495 | * Full session is used for VoIP call. */ |
| 2496 | pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]); |
| 2497 | if (!ptr[1]) { |
| 2498 | pr_debug("%s: MVM handle is %d\n", |
| 2499 | __func__, data->src_port); |
| 2500 | voice_set_mvm_handle(v, data->src_port); |
| 2501 | } else |
| 2502 | pr_err("got NACK for sending \ |
| 2503 | MVM create session \n"); |
| 2504 | v->mvm_state = CMD_STATUS_SUCCESS; |
| 2505 | wake_up(&v->mvm_wait); |
| 2506 | break; |
| 2507 | case VSS_IMVM_CMD_START_VOICE: |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 2508 | case VSS_IMVM_CMD_ATTACH_VOCPROC: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2509 | case VSS_IMVM_CMD_STOP_VOICE: |
Helen Zeng | 69b0096 | 2011-07-08 11:38:36 -0700 | [diff] [blame] | 2510 | case VSS_IMVM_CMD_DETACH_VOCPROC: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2511 | case VSS_ISTREAM_CMD_SET_TTY_MODE: |
| 2512 | case APRV2_IBASIC_CMD_DESTROY_SESSION: |
| 2513 | case VSS_IMVM_CMD_ATTACH_STREAM: |
| 2514 | case VSS_IMVM_CMD_DETACH_STREAM: |
| 2515 | case VSS_ICOMMON_CMD_SET_NETWORK: |
| 2516 | case VSS_ICOMMON_CMD_SET_VOICE_TIMING: |
| 2517 | pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]); |
| 2518 | v->mvm_state = CMD_STATUS_SUCCESS; |
| 2519 | wake_up(&v->mvm_wait); |
| 2520 | break; |
| 2521 | default: |
| 2522 | pr_debug("%s: not match cmd = 0x%x\n", |
| 2523 | __func__, ptr[0]); |
| 2524 | break; |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | return 0; |
| 2530 | } |
| 2531 | |
| 2532 | static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv) |
| 2533 | { |
| 2534 | uint32_t *ptr; |
| 2535 | struct voice_data *v; |
| 2536 | |
| 2537 | if ((data == NULL) || (priv == NULL)) { |
| 2538 | pr_err("%s: data or priv is NULL\n", __func__); |
| 2539 | return -EINVAL; |
| 2540 | } |
| 2541 | v = priv; |
| 2542 | |
| 2543 | pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__, |
| 2544 | data->payload_size, data->opcode); |
| 2545 | |
| 2546 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 2547 | if (data->payload_size) { |
| 2548 | ptr = data->payload; |
| 2549 | |
| 2550 | pr_info("%x %x\n", ptr[0], ptr[1]); |
| 2551 | /*response from CVS */ |
| 2552 | switch (ptr[0]) { |
| 2553 | case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION: |
| 2554 | case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION: |
| 2555 | if (!ptr[1]) { |
| 2556 | pr_debug("%s: CVS handle is %d\n", |
| 2557 | __func__, data->src_port); |
| 2558 | voice_set_cvs_handle(v, data->src_port); |
| 2559 | } else |
| 2560 | pr_err("got NACK for sending \ |
| 2561 | CVS create session \n"); |
| 2562 | v->cvs_state = CMD_STATUS_SUCCESS; |
| 2563 | wake_up(&v->cvs_wait); |
| 2564 | break; |
| 2565 | case VSS_ISTREAM_CMD_SET_MUTE: |
| 2566 | case VSS_ISTREAM_CMD_SET_MEDIA_TYPE: |
| 2567 | case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE: |
| 2568 | case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE: |
| 2569 | case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE: |
| 2570 | case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE: |
| 2571 | case APRV2_IBASIC_CMD_DESTROY_SESSION: |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 2572 | case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA: |
| 2573 | case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA: |
| 2574 | case VSS_ICOMMON_CMD_MAP_MEMORY: |
| 2575 | case VSS_ICOMMON_CMD_UNMAP_MEMORY: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2576 | pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]); |
| 2577 | v->cvs_state = CMD_STATUS_SUCCESS; |
| 2578 | wake_up(&v->cvs_wait); |
| 2579 | break; |
| 2580 | default: |
| 2581 | pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]); |
| 2582 | break; |
| 2583 | } |
| 2584 | } |
| 2585 | } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) { |
| 2586 | uint32_t *voc_pkt = data->payload; |
| 2587 | uint32_t pkt_len = data->payload_size; |
| 2588 | |
| 2589 | if (voc_pkt != NULL && v->mvs_info.ul_cb != NULL) { |
| 2590 | pr_debug("%s: Media type is 0x%x\n", |
| 2591 | __func__, voc_pkt[0]); |
| 2592 | |
| 2593 | /* Remove media ID from payload. */ |
| 2594 | voc_pkt++; |
| 2595 | pkt_len = pkt_len - 4; |
| 2596 | |
| 2597 | v->mvs_info.ul_cb((uint8_t *)voc_pkt, |
| 2598 | pkt_len, |
| 2599 | v->mvs_info.private_data); |
| 2600 | } else |
| 2601 | pr_err("%s: voc_pkt is 0x%x ul_cb is 0x%x\n", |
| 2602 | __func__, (unsigned int)voc_pkt, |
| 2603 | (unsigned int) v->mvs_info.ul_cb); |
| 2604 | } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) { |
| 2605 | struct cvs_send_dec_buf_cmd send_dec_buf; |
| 2606 | int ret = 0; |
| 2607 | uint32_t pkt_len = 0; |
| 2608 | |
| 2609 | if (v->mvs_info.dl_cb != NULL) { |
| 2610 | send_dec_buf.dec_buf.media_id = v->mvs_info.media_type; |
| 2611 | |
| 2612 | v->mvs_info.dl_cb( |
| 2613 | (uint8_t *)&send_dec_buf.dec_buf.packet_data, |
| 2614 | &pkt_len, |
| 2615 | v->mvs_info.private_data); |
| 2616 | |
| 2617 | send_dec_buf.hdr.hdr_field = |
| 2618 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2619 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2620 | APR_PKT_VER); |
| 2621 | send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, |
| 2622 | sizeof(send_dec_buf.dec_buf.media_id) + pkt_len); |
| 2623 | send_dec_buf.hdr.src_port = 0; |
| 2624 | send_dec_buf.hdr.dest_port = voice_get_cvs_handle(v); |
| 2625 | send_dec_buf.hdr.token = 0; |
| 2626 | send_dec_buf.hdr.opcode = |
| 2627 | VSS_ISTREAM_EVT_SEND_DEC_BUFFER; |
| 2628 | |
| 2629 | ret = apr_send_pkt(v->apr_q6_cvs, |
| 2630 | (uint32_t *) &send_dec_buf); |
| 2631 | if (ret < 0) { |
| 2632 | pr_err("%s: Error %d sending DEC_BUF\n", |
| 2633 | __func__, ret); |
| 2634 | goto fail; |
| 2635 | } |
| 2636 | } else |
| 2637 | pr_debug("%s: dl_cb is NULL\n", __func__); |
| 2638 | } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) |
| 2639 | pr_debug("Send dec buf resp\n"); |
| 2640 | |
| 2641 | else |
| 2642 | pr_debug("Unknown opcode 0x%x\n", data->opcode); |
| 2643 | |
| 2644 | fail: |
| 2645 | return 0; |
| 2646 | } |
| 2647 | |
| 2648 | static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv) |
| 2649 | { |
| 2650 | uint32_t *ptr; |
| 2651 | struct voice_data *v; |
| 2652 | |
| 2653 | if ((data == NULL) || (priv == NULL)) { |
| 2654 | pr_err("%s: data or priv is NULL\n", __func__); |
| 2655 | return -EINVAL; |
| 2656 | } |
| 2657 | v = priv; |
| 2658 | |
| 2659 | pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__, |
| 2660 | data->payload_size, data->opcode); |
| 2661 | |
| 2662 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 2663 | if (data->payload_size) { |
| 2664 | ptr = data->payload; |
| 2665 | |
| 2666 | pr_info("%x %x\n", ptr[0], ptr[1]); |
| 2667 | |
| 2668 | switch (ptr[0]) { |
| 2669 | case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION: |
| 2670 | /*response from CVP */ |
| 2671 | pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]); |
| 2672 | if (!ptr[1]) { |
| 2673 | voice_set_cvp_handle(v, data->src_port); |
| 2674 | pr_debug("cvphdl=%d\n", data->src_port); |
| 2675 | } else |
| 2676 | pr_err("got NACK from CVP create \ |
| 2677 | session response\n"); |
| 2678 | v->cvp_state = CMD_STATUS_SUCCESS; |
| 2679 | wake_up(&v->cvp_wait); |
| 2680 | break; |
| 2681 | case VSS_IVOCPROC_CMD_SET_DEVICE: |
| 2682 | case VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX: |
| 2683 | case VSS_IVOCPROC_CMD_ENABLE: |
| 2684 | case VSS_IVOCPROC_CMD_DISABLE: |
| 2685 | case APRV2_IBASIC_CMD_DESTROY_SESSION: |
Helen Zeng | 29eb744 | 2011-06-20 11:06:29 -0700 | [diff] [blame^] | 2686 | case VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE: |
| 2687 | case VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE: |
| 2688 | case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA: |
| 2689 | case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA: |
| 2690 | case VSS_ICOMMON_CMD_MAP_MEMORY: |
| 2691 | case VSS_ICOMMON_CMD_UNMAP_MEMORY: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2692 | v->cvp_state = CMD_STATUS_SUCCESS; |
| 2693 | wake_up(&v->cvp_wait); |
| 2694 | break; |
| 2695 | default: |
| 2696 | pr_debug("%s: not match cmd = 0x%x\n", |
| 2697 | __func__, ptr[0]); |
| 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | return 0; |
| 2703 | } |
| 2704 | |
| 2705 | |
| 2706 | static int __init voice_init(void) |
| 2707 | { |
| 2708 | int rc = 0; |
| 2709 | struct voice_data *v = &voice; |
| 2710 | |
| 2711 | /* set default value */ |
| 2712 | v->default_mute_val = 1; /* default is mute */ |
| 2713 | v->default_vol_val = 0; |
| 2714 | v->default_sample_val = 8000; |
| 2715 | v->sidetone_gain = 0x512; |
| 2716 | |
| 2717 | /* initialize dev_rx and dev_tx */ |
| 2718 | memset(&v->dev_tx, 0, sizeof(struct device_data)); |
| 2719 | memset(&v->dev_rx, 0, sizeof(struct device_data)); |
| 2720 | v->dev_rx.volume = v->default_vol_val; |
| 2721 | v->dev_tx.mute = v->default_mute_val; |
| 2722 | |
| 2723 | v->dev_tx.port_id = 1; |
| 2724 | v->dev_rx.port_id = 0; |
| 2725 | |
Helen Zeng | cc65b5b | 2011-07-06 19:14:48 -0700 | [diff] [blame] | 2726 | v->tty_mode = 0; |
| 2727 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2728 | v->voc_state = VOC_INIT; |
| 2729 | v->voc_path = VOC_PATH_PASSIVE; |
| 2730 | init_waitqueue_head(&v->mvm_wait); |
| 2731 | init_waitqueue_head(&v->cvs_wait); |
| 2732 | init_waitqueue_head(&v->cvp_wait); |
| 2733 | |
| 2734 | mutex_init(&v->lock); |
| 2735 | |
| 2736 | v->mvm_full_handle = 0; |
| 2737 | v->mvm_passive_handle = 0; |
| 2738 | v->cvs_full_handle = 0; |
| 2739 | v->cvs_passive_handle = 0; |
| 2740 | v->cvp_full_handle = 0; |
| 2741 | v->cvp_passive_handle = 0; |
| 2742 | |
| 2743 | v->apr_q6_mvm = NULL; |
| 2744 | v->apr_q6_cvs = NULL; |
| 2745 | v->apr_q6_cvp = NULL; |
| 2746 | |
| 2747 | /* Initialize MVS info. */ |
| 2748 | memset(&v->mvs_info, 0, sizeof(v->mvs_info)); |
| 2749 | v->mvs_info.network_type = VSS_NETWORK_ID_DEFAULT; |
| 2750 | |
| 2751 | return rc; |
| 2752 | } |
| 2753 | |
| 2754 | device_initcall(voice_init); |