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