Vignesh Kulothungan | 78d3e82 | 2018-03-13 16:05:20 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 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 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/time.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/dma-mapping.h> |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/soc.h> |
| 23 | #include <sound/soc-dapm.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/initval.h> |
| 26 | #include <sound/control.h> |
| 27 | #include <asm/dma.h> |
| 28 | #include <linux/of_device.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 29 | #include <dsp/q6voice.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 30 | |
| 31 | #include "msm-pcm-voice-v2.h" |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 32 | |
| 33 | static struct msm_voice voice_info[VOICE_SESSION_INDEX_MAX]; |
| 34 | |
| 35 | static struct snd_pcm_hardware msm_pcm_hardware = { |
| 36 | |
| 37 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 38 | SNDRV_PCM_INFO_PAUSE | |
| 39 | SNDRV_PCM_INFO_RESUME), |
| 40 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 41 | .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, |
| 42 | .rate_min = 8000, |
| 43 | .rate_max = 16000, |
| 44 | .channels_min = 1, |
| 45 | .channels_max = 1, |
| 46 | |
| 47 | .buffer_bytes_max = 4096 * 2, |
| 48 | .period_bytes_min = 2048, |
| 49 | .period_bytes_max = 4096, |
| 50 | .periods_min = 2, |
| 51 | .periods_max = 4, |
| 52 | |
| 53 | .fifo_size = 0, |
| 54 | }; |
| 55 | static bool is_volte(struct msm_voice *pvolte) |
| 56 | { |
| 57 | if (pvolte == &voice_info[VOLTE_SESSION_INDEX]) |
| 58 | return true; |
| 59 | else |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | static bool is_voice2(struct msm_voice *pvoice2) |
| 64 | { |
| 65 | if (pvoice2 == &voice_info[VOICE2_SESSION_INDEX]) |
| 66 | return true; |
| 67 | else |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | static bool is_qchat(struct msm_voice *pqchat) |
| 72 | { |
| 73 | if (pqchat == &voice_info[QCHAT_SESSION_INDEX]) |
| 74 | return true; |
| 75 | else |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | static bool is_vowlan(struct msm_voice *pvowlan) |
| 80 | { |
| 81 | if (pvowlan == &voice_info[VOWLAN_SESSION_INDEX]) |
| 82 | return true; |
| 83 | else |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | static bool is_voicemmode1(struct msm_voice *pvoicemmode1) |
| 88 | { |
| 89 | if (pvoicemmode1 == &voice_info[VOICEMMODE1_INDEX]) |
| 90 | return true; |
| 91 | else |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | static bool is_voicemmode2(struct msm_voice *pvoicemmode2) |
| 96 | { |
| 97 | if (pvoicemmode2 == &voice_info[VOICEMMODE2_INDEX]) |
| 98 | return true; |
| 99 | else |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | static uint32_t get_session_id(struct msm_voice *pvoc) |
| 104 | { |
| 105 | uint32_t session_id = 0; |
| 106 | |
| 107 | if (is_volte(pvoc)) |
| 108 | session_id = voc_get_session_id(VOLTE_SESSION_NAME); |
| 109 | else if (is_voice2(pvoc)) |
| 110 | session_id = voc_get_session_id(VOICE2_SESSION_NAME); |
| 111 | else if (is_qchat(pvoc)) |
| 112 | session_id = voc_get_session_id(QCHAT_SESSION_NAME); |
| 113 | else if (is_vowlan(pvoc)) |
| 114 | session_id = voc_get_session_id(VOWLAN_SESSION_NAME); |
| 115 | else if (is_voicemmode1(pvoc)) |
| 116 | session_id = voc_get_session_id(VOICEMMODE1_NAME); |
| 117 | else if (is_voicemmode2(pvoc)) |
| 118 | session_id = voc_get_session_id(VOICEMMODE2_NAME); |
| 119 | else |
| 120 | session_id = voc_get_session_id(VOICE_SESSION_NAME); |
| 121 | |
| 122 | return session_id; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static int msm_pcm_playback_prepare(struct snd_pcm_substream *substream) |
| 127 | { |
| 128 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 129 | struct msm_voice *prtd = runtime->private_data; |
| 130 | |
| 131 | pr_debug("%s\n", __func__); |
| 132 | |
| 133 | if (!prtd->playback_start) |
| 134 | prtd->playback_start = 1; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int msm_pcm_capture_prepare(struct snd_pcm_substream *substream) |
| 140 | { |
| 141 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 142 | struct msm_voice *prtd = runtime->private_data; |
| 143 | |
| 144 | pr_debug("%s\n", __func__); |
| 145 | |
| 146 | if (!prtd->capture_start) |
| 147 | prtd->capture_start = 1; |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | static int msm_pcm_open(struct snd_pcm_substream *substream) |
| 152 | { |
| 153 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 154 | struct msm_voice *voice; |
| 155 | |
| 156 | if (!strncmp("VoLTE", substream->pcm->id, 5)) { |
| 157 | voice = &voice_info[VOLTE_SESSION_INDEX]; |
| 158 | pr_debug("%s: Open VoLTE Substream Id=%s\n", |
| 159 | __func__, substream->pcm->id); |
| 160 | } else if (!strncmp("Voice2", substream->pcm->id, 6)) { |
| 161 | voice = &voice_info[VOICE2_SESSION_INDEX]; |
| 162 | pr_debug("%s: Open Voice2 Substream Id=%s\n", |
| 163 | __func__, substream->pcm->id); |
| 164 | } else if (!strncmp("QCHAT", substream->pcm->id, 5)) { |
| 165 | voice = &voice_info[QCHAT_SESSION_INDEX]; |
| 166 | pr_debug("%s: Open QCHAT Substream Id=%s\n", |
| 167 | __func__, substream->pcm->id); |
| 168 | } else if (!strncmp("VoWLAN", substream->pcm->id, 6)) { |
| 169 | voice = &voice_info[VOWLAN_SESSION_INDEX]; |
| 170 | pr_debug("%s: Open VoWLAN Substream Id=%s\n", |
| 171 | __func__, substream->pcm->id); |
| 172 | } else if (!strncmp("VoiceMMode1", substream->pcm->id, 11)) { |
| 173 | voice = &voice_info[VOICEMMODE1_INDEX]; |
| 174 | pr_debug("%s: Open VoiceMMode1 Substream Id=%s\n", |
| 175 | __func__, substream->pcm->id); |
| 176 | } else if (!strncmp("VoiceMMode2", substream->pcm->id, 11)) { |
| 177 | voice = &voice_info[VOICEMMODE2_INDEX]; |
| 178 | pr_debug("%s: Open VoiceMMode2 Substream Id=%s\n", |
| 179 | __func__, substream->pcm->id); |
| 180 | } else { |
| 181 | voice = &voice_info[VOICE_SESSION_INDEX]; |
| 182 | pr_debug("%s: Open VOICE Substream Id=%s\n", |
| 183 | __func__, substream->pcm->id); |
| 184 | } |
| 185 | mutex_lock(&voice->lock); |
| 186 | |
| 187 | runtime->hw = msm_pcm_hardware; |
| 188 | |
| 189 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 190 | voice->playback_substream = substream; |
| 191 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 192 | voice->capture_substream = substream; |
| 193 | |
| 194 | voice->instance++; |
| 195 | pr_debug("%s: Instance = %d, Stream ID = %s\n", |
| 196 | __func__, voice->instance, substream->pcm->id); |
| 197 | runtime->private_data = voice; |
| 198 | |
| 199 | mutex_unlock(&voice->lock); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | static int msm_pcm_playback_close(struct snd_pcm_substream *substream) |
| 204 | { |
| 205 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 206 | struct msm_voice *prtd = runtime->private_data; |
| 207 | |
| 208 | pr_debug("%s\n", __func__); |
| 209 | |
| 210 | if (prtd->playback_start) |
| 211 | prtd->playback_start = 0; |
| 212 | |
| 213 | prtd->playback_substream = NULL; |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | static int msm_pcm_capture_close(struct snd_pcm_substream *substream) |
| 218 | { |
| 219 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 220 | struct msm_voice *prtd = runtime->private_data; |
| 221 | |
| 222 | pr_debug("%s\n", __func__); |
| 223 | |
| 224 | if (prtd->capture_start) |
| 225 | prtd->capture_start = 0; |
| 226 | prtd->capture_substream = NULL; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | static int msm_pcm_close(struct snd_pcm_substream *substream) |
| 231 | { |
| 232 | |
| 233 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 234 | struct msm_voice *prtd = runtime->private_data; |
| 235 | uint32_t session_id = 0; |
| 236 | int ret = 0; |
| 237 | |
| 238 | mutex_lock(&prtd->lock); |
| 239 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 240 | ret = msm_pcm_playback_close(substream); |
| 241 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 242 | ret = msm_pcm_capture_close(substream); |
| 243 | |
| 244 | prtd->instance--; |
| 245 | if (!prtd->playback_start && !prtd->capture_start) { |
| 246 | pr_debug("end voice call\n"); |
| 247 | |
| 248 | session_id = get_session_id(prtd); |
| 249 | if (session_id) |
| 250 | voc_end_voice_call(session_id); |
| 251 | } |
| 252 | mutex_unlock(&prtd->lock); |
| 253 | |
| 254 | return ret; |
| 255 | } |
| 256 | static int msm_pcm_prepare(struct snd_pcm_substream *substream) |
| 257 | { |
| 258 | int ret = 0; |
| 259 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 260 | struct msm_voice *prtd = runtime->private_data; |
| 261 | uint32_t session_id = 0; |
| 262 | |
| 263 | mutex_lock(&prtd->lock); |
| 264 | |
| 265 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 266 | ret = msm_pcm_playback_prepare(substream); |
| 267 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 268 | ret = msm_pcm_capture_prepare(substream); |
| 269 | |
| 270 | if (prtd->playback_start && prtd->capture_start) { |
| 271 | session_id = get_session_id(prtd); |
| 272 | if (session_id) |
| 273 | voc_start_voice_call(session_id); |
| 274 | } |
| 275 | mutex_unlock(&prtd->lock); |
| 276 | |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | static int msm_pcm_hw_params(struct snd_pcm_substream *substream, |
| 281 | struct snd_pcm_hw_params *params) |
| 282 | { |
| 283 | |
| 284 | pr_debug("%s: Voice\n", __func__); |
| 285 | |
| 286 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static int msm_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 292 | { |
| 293 | int ret = 0; |
| 294 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 295 | struct msm_voice *prtd = runtime->private_data; |
| 296 | uint32_t session_id = 0; |
| 297 | |
| 298 | pr_debug("%s: cmd = %d\n", __func__, cmd); |
| 299 | |
| 300 | session_id = get_session_id(prtd); |
| 301 | |
| 302 | switch (cmd) { |
| 303 | case SNDRV_PCM_TRIGGER_START: |
| 304 | case SNDRV_PCM_TRIGGER_STOP: |
| 305 | pr_debug("Start & Stop Voice call not handled in Trigger.\n"); |
| 306 | break; |
| 307 | case SNDRV_PCM_TRIGGER_RESUME: |
| 308 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 309 | pr_debug("%s: resume call session_id = %d\n", __func__, |
| 310 | session_id); |
| 311 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 312 | ret = msm_pcm_playback_prepare(substream); |
| 313 | else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 314 | ret = msm_pcm_capture_prepare(substream); |
| 315 | if (prtd->playback_start && prtd->capture_start) { |
| 316 | if (session_id) |
| 317 | voc_resume_voice_call(session_id); |
| 318 | } |
| 319 | break; |
| 320 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 321 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 322 | pr_debug("%s: pause call session_id=%d\n", |
| 323 | __func__, session_id); |
| 324 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 325 | if (prtd->playback_start) |
| 326 | prtd->playback_start = 0; |
| 327 | } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 328 | if (prtd->capture_start) |
| 329 | prtd->capture_start = 0; |
| 330 | } |
| 331 | if (session_id) |
| 332 | voc_standby_voice_call(session_id); |
| 333 | break; |
| 334 | default: |
| 335 | ret = -EINVAL; |
| 336 | break; |
| 337 | } |
| 338 | return ret; |
| 339 | } |
| 340 | |
| 341 | static int msm_pcm_ioctl(struct snd_pcm_substream *substream, |
| 342 | unsigned int cmd, void *arg) |
| 343 | { |
| 344 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 345 | struct msm_voice *prtd = runtime->private_data; |
| 346 | uint32_t session_id = get_session_id(prtd); |
| 347 | enum voice_lch_mode lch_mode; |
| 348 | int ret = 0; |
| 349 | |
| 350 | switch (cmd) { |
| 351 | case SNDRV_VOICE_IOCTL_LCH: |
| 352 | if (copy_from_user(&lch_mode, (void *)arg, |
| 353 | sizeof(enum voice_lch_mode))) { |
| 354 | pr_err("%s: Copy from user failed, size %zd\n", |
| 355 | __func__, sizeof(enum voice_lch_mode)); |
| 356 | |
| 357 | ret = -EFAULT; |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | pr_debug("%s: %s lch_mode:%d\n", |
| 362 | __func__, substream->pcm->id, lch_mode); |
| 363 | |
| 364 | switch (lch_mode) { |
| 365 | case VOICE_LCH_START: |
| 366 | case VOICE_LCH_STOP: |
| 367 | ret = voc_set_lch(session_id, lch_mode); |
| 368 | break; |
| 369 | |
| 370 | default: |
| 371 | pr_err("%s: Invalid LCH MODE %d\n", __func__, lch_mode); |
| 372 | |
| 373 | ret = -EFAULT; |
| 374 | } |
| 375 | |
| 376 | break; |
| 377 | default: |
| 378 | pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n", |
| 379 | __func__, cmd); |
| 380 | |
| 381 | ret = snd_pcm_lib_ioctl(substream, cmd, arg); |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | if (!ret) |
| 386 | pr_debug("%s: ret %d\n", __func__, ret); |
| 387 | else |
| 388 | pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, ret); |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | static int msm_voice_sidetone_put(struct snd_kcontrol *kcontrol, |
| 394 | struct snd_ctl_elem_value *ucontrol) |
| 395 | { |
| 396 | int ret; |
| 397 | long value = ucontrol->value.integer.value[0]; |
| 398 | bool sidetone_enable = value; |
| 399 | uint32_t session_id = ALL_SESSION_VSID; |
| 400 | |
| 401 | if (value < 0) { |
| 402 | pr_err("%s: Invalid arguments sidetone enable %ld\n", |
| 403 | __func__, value); |
| 404 | ret = -EINVAL; |
| 405 | return ret; |
| 406 | } |
| 407 | ret = voc_set_afe_sidetone(session_id, sidetone_enable); |
| 408 | pr_debug("%s: AFE Sidetone enable=%d session_id=0x%x ret=%d\n", |
| 409 | __func__, sidetone_enable, session_id, ret); |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | static int msm_voice_sidetone_get(struct snd_kcontrol *kcontrol, |
| 414 | struct snd_ctl_elem_value *ucontrol) |
| 415 | { |
| 416 | ucontrol->value.integer.value[0] = voc_get_afe_sidetone(); |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int msm_voice_gain_put(struct snd_kcontrol *kcontrol, |
| 421 | struct snd_ctl_elem_value *ucontrol) |
| 422 | { |
| 423 | int ret = 0; |
| 424 | int volume = ucontrol->value.integer.value[0]; |
| 425 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 426 | int ramp_duration = ucontrol->value.integer.value[2]; |
| 427 | |
| 428 | if ((volume < 0) || (ramp_duration < 0) |
| 429 | || (ramp_duration > MAX_RAMP_DURATION)) { |
| 430 | pr_err(" %s Invalid arguments", __func__); |
| 431 | |
| 432 | ret = -EINVAL; |
| 433 | goto done; |
| 434 | } |
| 435 | |
| 436 | pr_debug("%s: volume: %d session_id: %#x ramp_duration: %d\n", __func__, |
| 437 | volume, session_id, ramp_duration); |
| 438 | |
| 439 | voc_set_rx_vol_step(session_id, RX_PATH, volume, ramp_duration); |
| 440 | |
| 441 | done: |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | static int msm_voice_mute_put(struct snd_kcontrol *kcontrol, |
| 446 | struct snd_ctl_elem_value *ucontrol) |
| 447 | { |
| 448 | int ret = 0; |
| 449 | int mute = ucontrol->value.integer.value[0]; |
| 450 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 451 | int ramp_duration = ucontrol->value.integer.value[2]; |
| 452 | |
| 453 | if ((mute < 0) || (mute > 1) || (ramp_duration < 0) |
| 454 | || (ramp_duration > MAX_RAMP_DURATION)) { |
| 455 | pr_err(" %s Invalid arguments", __func__); |
| 456 | |
| 457 | ret = -EINVAL; |
| 458 | goto done; |
| 459 | } |
| 460 | |
| 461 | pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__, |
| 462 | mute, session_id, ramp_duration); |
| 463 | |
| 464 | ret = voc_set_tx_mute(session_id, TX_PATH, mute, ramp_duration); |
| 465 | |
| 466 | done: |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | static int msm_voice_tx_device_mute_put(struct snd_kcontrol *kcontrol, |
| 471 | struct snd_ctl_elem_value *ucontrol) |
| 472 | { |
| 473 | int ret = 0; |
| 474 | int mute = ucontrol->value.integer.value[0]; |
| 475 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 476 | int ramp_duration = ucontrol->value.integer.value[2]; |
| 477 | |
| 478 | if ((mute < 0) || (mute > 1) || (ramp_duration < 0) || |
| 479 | (ramp_duration > MAX_RAMP_DURATION)) { |
| 480 | pr_err(" %s Invalid arguments", __func__); |
| 481 | |
| 482 | ret = -EINVAL; |
| 483 | goto done; |
| 484 | } |
| 485 | |
| 486 | pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__, |
| 487 | mute, session_id, ramp_duration); |
| 488 | |
| 489 | ret = voc_set_device_mute(session_id, VSS_IVOLUME_DIRECTION_TX, |
| 490 | mute, ramp_duration); |
| 491 | |
| 492 | done: |
| 493 | return ret; |
| 494 | } |
| 495 | |
| 496 | static int msm_voice_rx_device_mute_put(struct snd_kcontrol *kcontrol, |
| 497 | struct snd_ctl_elem_value *ucontrol) |
| 498 | { |
| 499 | int ret = 0; |
| 500 | int mute = ucontrol->value.integer.value[0]; |
| 501 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 502 | int ramp_duration = ucontrol->value.integer.value[2]; |
| 503 | |
| 504 | if ((mute < 0) || (mute > 1) || (ramp_duration < 0) || |
| 505 | (ramp_duration > MAX_RAMP_DURATION)) { |
| 506 | pr_err(" %s Invalid arguments", __func__); |
| 507 | |
| 508 | ret = -EINVAL; |
| 509 | goto done; |
| 510 | } |
| 511 | |
| 512 | pr_debug("%s: mute=%d session_id=%#x ramp_duration=%d\n", __func__, |
| 513 | mute, session_id, ramp_duration); |
| 514 | |
| 515 | voc_set_device_mute(session_id, VSS_IVOLUME_DIRECTION_RX, |
| 516 | mute, ramp_duration); |
| 517 | |
| 518 | done: |
| 519 | return ret; |
| 520 | } |
| 521 | |
Vignesh Kulothungan | 78d3e82 | 2018-03-13 16:05:20 -0700 | [diff] [blame] | 522 | static int msm_voice_mbd_get(struct snd_kcontrol *kcontrol, |
| 523 | struct snd_ctl_elem_value *ucontrol) |
| 524 | { |
| 525 | ucontrol->value.integer.value[0] = voc_get_mbd_enable(); |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static int msm_voice_mbd_put(struct snd_kcontrol *kcontrol, |
| 530 | struct snd_ctl_elem_value *ucontrol) |
| 531 | { |
| 532 | bool enable = ucontrol->value.integer.value[0]; |
| 533 | |
| 534 | voc_set_mbd_enable(enable); |
| 535 | |
| 536 | return 0; |
| 537 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 538 | |
| 539 | |
| 540 | static const char * const tty_mode[] = {"OFF", "HCO", "VCO", "FULL"}; |
| 541 | static const struct soc_enum msm_tty_mode_enum[] = { |
| 542 | SOC_ENUM_SINGLE_EXT(4, tty_mode), |
| 543 | }; |
| 544 | |
| 545 | static int msm_voice_tty_mode_get(struct snd_kcontrol *kcontrol, |
| 546 | struct snd_ctl_elem_value *ucontrol) |
| 547 | { |
| 548 | ucontrol->value.integer.value[0] = |
| 549 | voc_get_tty_mode(voc_get_session_id(VOICE_SESSION_NAME)); |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | static int msm_voice_tty_mode_put(struct snd_kcontrol *kcontrol, |
| 554 | struct snd_ctl_elem_value *ucontrol) |
| 555 | { |
| 556 | int tty_mode = ucontrol->value.integer.value[0]; |
| 557 | |
| 558 | pr_debug("%s: tty_mode=%d\n", __func__, tty_mode); |
| 559 | |
| 560 | voc_set_tty_mode(voc_get_session_id(VOICE_SESSION_NAME), tty_mode); |
| 561 | voc_set_tty_mode(voc_get_session_id(VOICE2_SESSION_NAME), tty_mode); |
| 562 | voc_set_tty_mode(voc_get_session_id(VOLTE_SESSION_NAME), tty_mode); |
| 563 | voc_set_tty_mode(voc_get_session_id(VOWLAN_SESSION_NAME), tty_mode); |
| 564 | voc_set_tty_mode(voc_get_session_id(VOICEMMODE1_NAME), tty_mode); |
| 565 | voc_set_tty_mode(voc_get_session_id(VOICEMMODE2_NAME), tty_mode); |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static int msm_voice_slowtalk_put(struct snd_kcontrol *kcontrol, |
| 571 | struct snd_ctl_elem_value *ucontrol) |
| 572 | { |
| 573 | int st_enable = ucontrol->value.integer.value[0]; |
| 574 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 575 | |
| 576 | pr_debug("%s: st enable=%d session_id=%#x\n", __func__, st_enable, |
| 577 | session_id); |
| 578 | |
| 579 | voc_set_pp_enable(session_id, |
| 580 | MODULE_ID_VOICE_MODULE_ST, st_enable); |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static int msm_voice_hd_voice_put(struct snd_kcontrol *kcontrol, |
| 586 | struct snd_ctl_elem_value *ucontrol) |
| 587 | { |
| 588 | int ret = 0; |
| 589 | uint32_t hd_enable = ucontrol->value.integer.value[0]; |
| 590 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 591 | |
| 592 | pr_debug("%s: HD Voice enable=%d session_id=%#x\n", __func__, hd_enable, |
| 593 | session_id); |
| 594 | |
| 595 | ret = voc_set_hd_enable(session_id, hd_enable); |
| 596 | |
| 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | static int msm_voice_topology_disable_put(struct snd_kcontrol *kcontrol, |
| 601 | struct snd_ctl_elem_value *ucontrol) |
| 602 | { |
| 603 | int ret = 0; |
| 604 | int disable = ucontrol->value.integer.value[0]; |
| 605 | uint32_t session_id = ucontrol->value.integer.value[1]; |
| 606 | |
| 607 | if ((disable < 0) || (disable > 1)) { |
| 608 | pr_err(" %s Invalid arguments: %d\n", __func__, disable); |
| 609 | |
| 610 | ret = -EINVAL; |
| 611 | goto done; |
| 612 | } |
| 613 | pr_debug("%s: disable = %d, session_id = %d\n", __func__, disable, |
| 614 | session_id); |
| 615 | |
| 616 | ret = voc_disable_topology(session_id, disable); |
| 617 | |
| 618 | done: |
| 619 | return ret; |
| 620 | } |
| 621 | |
| 622 | static int msm_voice_cvd_version_info(struct snd_kcontrol *kcontrol, |
| 623 | struct snd_ctl_elem_info *uinfo) |
| 624 | { |
| 625 | int ret = 0; |
| 626 | |
| 627 | pr_debug("%s:\n", __func__); |
| 628 | |
| 629 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 630 | uinfo->count = CVD_VERSION_STRING_MAX_SIZE; |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | static int msm_voice_cvd_version_get(struct snd_kcontrol *kcontrol, |
| 636 | struct snd_ctl_elem_value *ucontrol) |
| 637 | { |
| 638 | char cvd_version[CVD_VERSION_STRING_MAX_SIZE] = CVD_VERSION_DEFAULT; |
| 639 | int ret; |
| 640 | |
| 641 | pr_debug("%s:\n", __func__); |
| 642 | |
| 643 | ret = voc_get_cvd_version(cvd_version); |
| 644 | |
| 645 | if (ret) |
| 646 | pr_err("%s: Error retrieving CVD version, error:%d\n", |
| 647 | __func__, ret); |
| 648 | |
| 649 | memcpy(ucontrol->value.bytes.data, cvd_version, sizeof(cvd_version)); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | static struct snd_kcontrol_new msm_voice_controls[] = { |
| 654 | SOC_SINGLE_MULTI_EXT("Voice Rx Device Mute", SND_SOC_NOPM, 0, VSID_MAX, |
| 655 | 0, 3, NULL, msm_voice_rx_device_mute_put), |
| 656 | SOC_SINGLE_MULTI_EXT("Voice Tx Device Mute", SND_SOC_NOPM, 0, VSID_MAX, |
| 657 | 0, 3, NULL, msm_voice_tx_device_mute_put), |
| 658 | SOC_SINGLE_MULTI_EXT("Voice Tx Mute", SND_SOC_NOPM, 0, VSID_MAX, |
| 659 | 0, 3, NULL, msm_voice_mute_put), |
| 660 | SOC_SINGLE_MULTI_EXT("Voice Rx Gain", SND_SOC_NOPM, 0, VSID_MAX, 0, 3, |
| 661 | NULL, msm_voice_gain_put), |
| 662 | SOC_ENUM_EXT("TTY Mode", msm_tty_mode_enum[0], msm_voice_tty_mode_get, |
| 663 | msm_voice_tty_mode_put), |
| 664 | SOC_SINGLE_MULTI_EXT("Slowtalk Enable", SND_SOC_NOPM, 0, VSID_MAX, 0, 2, |
| 665 | NULL, msm_voice_slowtalk_put), |
| 666 | SOC_SINGLE_MULTI_EXT("Voice Topology Disable", SND_SOC_NOPM, 0, |
| 667 | VSID_MAX, 0, 2, NULL, |
| 668 | msm_voice_topology_disable_put), |
| 669 | SOC_SINGLE_MULTI_EXT("HD Voice Enable", SND_SOC_NOPM, 0, VSID_MAX, 0, 2, |
| 670 | NULL, msm_voice_hd_voice_put), |
| 671 | { |
| 672 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 673 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 674 | .name = "CVD Version", |
| 675 | .info = msm_voice_cvd_version_info, |
| 676 | .get = msm_voice_cvd_version_get, |
| 677 | }, |
| 678 | SOC_SINGLE_MULTI_EXT("Voice Sidetone Enable", SND_SOC_NOPM, 0, 1, 0, 1, |
| 679 | msm_voice_sidetone_get, msm_voice_sidetone_put), |
Vignesh Kulothungan | 78d3e82 | 2018-03-13 16:05:20 -0700 | [diff] [blame] | 680 | SOC_SINGLE_BOOL_EXT("Voice Mic Break Enable", 0, msm_voice_mbd_get, |
| 681 | msm_voice_mbd_put), |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 682 | }; |
| 683 | |
| 684 | static const struct snd_pcm_ops msm_pcm_ops = { |
| 685 | .open = msm_pcm_open, |
| 686 | .hw_params = msm_pcm_hw_params, |
| 687 | .close = msm_pcm_close, |
| 688 | .prepare = msm_pcm_prepare, |
| 689 | .trigger = msm_pcm_trigger, |
| 690 | .ioctl = msm_pcm_ioctl, |
| 691 | .compat_ioctl = msm_pcm_ioctl, |
| 692 | }; |
| 693 | |
| 694 | |
| 695 | static int msm_asoc_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 696 | { |
| 697 | struct snd_card *card = rtd->card->snd_card; |
| 698 | int ret = 0; |
| 699 | |
| 700 | if (!card->dev->coherent_dma_mask) |
| 701 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); |
| 702 | return ret; |
| 703 | } |
| 704 | |
| 705 | static int msm_pcm_voice_probe(struct snd_soc_platform *platform) |
| 706 | { |
| 707 | snd_soc_add_platform_controls(platform, msm_voice_controls, |
| 708 | ARRAY_SIZE(msm_voice_controls)); |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static struct snd_soc_platform_driver msm_soc_platform = { |
| 714 | .ops = &msm_pcm_ops, |
| 715 | .pcm_new = msm_asoc_pcm_new, |
| 716 | .probe = msm_pcm_voice_probe, |
| 717 | }; |
| 718 | |
| 719 | static int msm_pcm_probe(struct platform_device *pdev) |
| 720 | { |
| 721 | int rc; |
| 722 | bool destroy_cvd = false; |
Aditya Bavanari | bdb45e9 | 2018-12-03 17:27:43 +0530 | [diff] [blame] | 723 | bool vote_bms = false; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 724 | const char *is_destroy_cvd = "qcom,destroy-cvd"; |
Aditya Bavanari | bdb45e9 | 2018-12-03 17:27:43 +0530 | [diff] [blame] | 725 | const char *is_vote_bms = "qcom,vote-bms"; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 726 | |
| 727 | if (!is_voc_initialized()) { |
| 728 | pr_debug("%s: voice module not initialized yet, deferring probe()\n", |
| 729 | __func__); |
| 730 | |
| 731 | rc = -EPROBE_DEFER; |
| 732 | goto done; |
| 733 | } |
| 734 | |
| 735 | rc = voc_alloc_cal_shared_memory(); |
| 736 | if (rc == -EPROBE_DEFER) { |
| 737 | pr_debug("%s: memory allocation for calibration deferred %d\n", |
| 738 | __func__, rc); |
| 739 | |
| 740 | goto done; |
| 741 | } else if (rc < 0) { |
| 742 | pr_err("%s: memory allocation for calibration failed %d\n", |
| 743 | __func__, rc); |
| 744 | } |
| 745 | |
| 746 | pr_debug("%s: dev name %s\n", |
| 747 | __func__, dev_name(&pdev->dev)); |
| 748 | destroy_cvd = of_property_read_bool(pdev->dev.of_node, |
| 749 | is_destroy_cvd); |
| 750 | voc_set_destroy_cvd_flag(destroy_cvd); |
| 751 | |
Aditya Bavanari | bdb45e9 | 2018-12-03 17:27:43 +0530 | [diff] [blame] | 752 | vote_bms = of_property_read_bool(pdev->dev.of_node, |
| 753 | is_vote_bms); |
| 754 | voc_set_vote_bms_flag(vote_bms); |
| 755 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 756 | rc = snd_soc_register_platform(&pdev->dev, |
| 757 | &msm_soc_platform); |
| 758 | |
| 759 | done: |
| 760 | return rc; |
| 761 | } |
| 762 | |
| 763 | static int msm_pcm_remove(struct platform_device *pdev) |
| 764 | { |
| 765 | snd_soc_unregister_platform(&pdev->dev); |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static const struct of_device_id msm_voice_dt_match[] = { |
| 770 | {.compatible = "qcom,msm-pcm-voice"}, |
| 771 | {} |
| 772 | }; |
| 773 | MODULE_DEVICE_TABLE(of, msm_voice_dt_match); |
| 774 | |
| 775 | static struct platform_driver msm_pcm_driver = { |
| 776 | .driver = { |
| 777 | .name = "msm-pcm-voice", |
| 778 | .owner = THIS_MODULE, |
| 779 | .of_match_table = msm_voice_dt_match, |
| 780 | }, |
| 781 | .probe = msm_pcm_probe, |
| 782 | .remove = msm_pcm_remove, |
| 783 | }; |
| 784 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 785 | int __init msm_pcm_voice_init(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 786 | { |
| 787 | int i = 0; |
| 788 | |
| 789 | memset(&voice_info, 0, sizeof(voice_info)); |
| 790 | |
| 791 | for (i = 0; i < VOICE_SESSION_INDEX_MAX; i++) |
| 792 | mutex_init(&voice_info[i].lock); |
| 793 | |
| 794 | return platform_driver_register(&msm_pcm_driver); |
| 795 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 796 | |
Asish Bhattacharya | 5faacb3 | 2017-12-04 17:23:15 +0530 | [diff] [blame] | 797 | void msm_pcm_voice_exit(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 798 | { |
| 799 | platform_driver_unregister(&msm_pcm_driver); |
| 800 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 801 | |
| 802 | MODULE_DESCRIPTION("Voice PCM module platform driver"); |
| 803 | MODULE_LICENSE("GPL v2"); |