Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1 | /* alsa_default.cpp |
| 2 | ** |
| 3 | ** Copyright 2009 Wind River Systems |
| 4 | ** Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 19 | #define LOG_TAG "ALSAModule" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 20 | //#define LOG_NDEBUG 0 |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 21 | #define LOG_NDDEBUG 0 |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | #include <cutils/properties.h> |
| 24 | #include <linux/ioctl.h> |
| 25 | #include "AudioHardwareALSA.h" |
| 26 | #include <media/AudioRecord.h> |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 27 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 28 | extern "C" { |
| 29 | #include "csd_client.h" |
| 30 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 31 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 32 | |
| 33 | #ifndef ALSA_DEFAULT_SAMPLE_RATE |
| 34 | #define ALSA_DEFAULT_SAMPLE_RATE 44100 // in Hz |
| 35 | #endif |
| 36 | |
| 37 | #define BTSCO_RATE_16KHZ 16000 |
| 38 | #define USECASE_TYPE_RX 1 |
| 39 | #define USECASE_TYPE_TX 2 |
| 40 | |
| 41 | namespace android_audio_legacy |
| 42 | { |
| 43 | |
| 44 | static int s_device_open(const hw_module_t*, const char*, hw_device_t**); |
| 45 | static int s_device_close(hw_device_t*); |
| 46 | static status_t s_init(alsa_device_t *, ALSAHandleList &); |
| 47 | static status_t s_open(alsa_handle_t *); |
| 48 | static status_t s_close(alsa_handle_t *); |
| 49 | static status_t s_standby(alsa_handle_t *); |
| 50 | static status_t s_route(alsa_handle_t *, uint32_t, int); |
| 51 | static status_t s_start_voice_call(alsa_handle_t *); |
| 52 | static status_t s_start_voip_call(alsa_handle_t *); |
| 53 | static status_t s_start_fm(alsa_handle_t *); |
| 54 | static void s_set_voice_volume(int); |
| 55 | static void s_set_voip_volume(int); |
| 56 | static void s_set_mic_mute(int); |
| 57 | static void s_set_voip_mic_mute(int); |
| 58 | static void s_set_voip_config(int, int); |
| 59 | static status_t s_set_fm_vol(int); |
| 60 | static void s_set_btsco_rate(int); |
| 61 | static status_t s_set_lpa_vol(int); |
| 62 | static void s_enable_wide_voice(bool flag); |
| 63 | static void s_enable_fens(bool flag); |
| 64 | static void s_set_flags(uint32_t flags); |
| 65 | static status_t s_set_compressed_vol(int); |
| 66 | static void s_enable_slow_talk(bool flag); |
| 67 | static void s_set_voc_rec_mode(uint8_t mode); |
| 68 | static void s_set_volte_mic_mute(int state); |
| 69 | static void s_set_volte_volume(int vol); |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 70 | #ifdef SEPERATED_AUDIO_INPUT |
| 71 | static void s_setInput(int); |
| 72 | |
| 73 | static int input_source; |
| 74 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 75 | |
| 76 | static char mic_type[25]; |
| 77 | static char curRxUCMDevice[50]; |
| 78 | static char curTxUCMDevice[50]; |
| 79 | static int fluence_mode; |
| 80 | static int fmVolume; |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 81 | #ifdef USES_FLUENCE_INCALL |
| 82 | static uint32_t mDevSettingsFlag = TTY_OFF | DMIC_FLAG; |
| 83 | #else |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 84 | static uint32_t mDevSettingsFlag = TTY_OFF; |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 85 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 86 | static int btsco_samplerate = 8000; |
| 87 | static bool pflag = false; |
| 88 | static ALSAUseCaseList mUseCaseList; |
| 89 | |
| 90 | static hw_module_methods_t s_module_methods = { |
| 91 | open : s_device_open |
| 92 | }; |
| 93 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 94 | extern "C" hw_module_t HAL_MODULE_INFO_SYM = { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 95 | tag : HARDWARE_MODULE_TAG, |
| 96 | version_major : 1, |
| 97 | version_minor : 0, |
| 98 | id : ALSA_HARDWARE_MODULE_ID, |
| 99 | name : "QCOM ALSA module", |
| 100 | author : "QuIC Inc", |
| 101 | methods : &s_module_methods, |
| 102 | dso : 0, |
| 103 | reserved : {0,}, |
| 104 | }; |
| 105 | |
| 106 | static int s_device_open(const hw_module_t* module, const char* name, |
| 107 | hw_device_t** device) |
| 108 | { |
| 109 | char value[128]; |
| 110 | alsa_device_t *dev; |
| 111 | dev = (alsa_device_t *) malloc(sizeof(*dev)); |
| 112 | if (!dev) return -ENOMEM; |
| 113 | |
| 114 | memset(dev, 0, sizeof(*dev)); |
| 115 | |
| 116 | /* initialize the procs */ |
| 117 | dev->common.tag = HARDWARE_DEVICE_TAG; |
| 118 | dev->common.version = 0; |
| 119 | dev->common.module = (hw_module_t *) module; |
| 120 | dev->common.close = s_device_close; |
| 121 | dev->init = s_init; |
| 122 | dev->open = s_open; |
| 123 | dev->close = s_close; |
| 124 | dev->route = s_route; |
| 125 | dev->standby = s_standby; |
| 126 | dev->startVoiceCall = s_start_voice_call; |
| 127 | dev->startVoipCall = s_start_voip_call; |
| 128 | dev->startFm = s_start_fm; |
| 129 | dev->setVoiceVolume = s_set_voice_volume; |
| 130 | dev->setVoipVolume = s_set_voip_volume; |
| 131 | dev->setMicMute = s_set_mic_mute; |
| 132 | dev->setVoipMicMute = s_set_voip_mic_mute; |
| 133 | dev->setVoipConfig = s_set_voip_config; |
| 134 | dev->setFmVolume = s_set_fm_vol; |
| 135 | dev->setBtscoRate = s_set_btsco_rate; |
| 136 | dev->setLpaVolume = s_set_lpa_vol; |
| 137 | dev->enableWideVoice = s_enable_wide_voice; |
| 138 | dev->enableFENS = s_enable_fens; |
| 139 | dev->setFlags = s_set_flags; |
| 140 | dev->setCompressedVolume = s_set_compressed_vol; |
| 141 | dev->enableSlowTalk = s_enable_slow_talk; |
| 142 | dev->setVocRecMode = s_set_voc_rec_mode; |
| 143 | dev->setVoLTEMicMute = s_set_volte_mic_mute; |
| 144 | dev->setVoLTEVolume = s_set_volte_volume; |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 145 | #ifdef SEPERATED_AUDIO_INPUT |
| 146 | dev->setInput = s_setInput; |
| 147 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 148 | |
| 149 | *device = &dev->common; |
| 150 | |
| 151 | property_get("persist.audio.handset.mic",value,"0"); |
| 152 | strlcpy(mic_type, value, sizeof(mic_type)); |
| 153 | property_get("persist.audio.fluence.mode",value,"0"); |
| 154 | if (!strcmp("broadside", value)) { |
| 155 | fluence_mode = FLUENCE_MODE_BROADSIDE; |
| 156 | } else { |
| 157 | fluence_mode = FLUENCE_MODE_ENDFIRE; |
| 158 | } |
| 159 | strlcpy(curRxUCMDevice, "None", sizeof(curRxUCMDevice)); |
| 160 | strlcpy(curTxUCMDevice, "None", sizeof(curTxUCMDevice)); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 161 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 162 | ALOGD("ALSA module opened"); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 163 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int s_device_close(hw_device_t* device) |
| 169 | { |
| 170 | free(device); |
| 171 | device = NULL; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | // ---------------------------------------------------------------------------- |
| 176 | |
| 177 | static const int DEFAULT_SAMPLE_RATE = ALSA_DEFAULT_SAMPLE_RATE; |
| 178 | |
| 179 | static void switchDevice(alsa_handle_t *handle, uint32_t devices, uint32_t mode); |
| 180 | static char *getUCMDevice(uint32_t devices, int input, char *rxDevice); |
| 181 | static void disableDevice(alsa_handle_t *handle); |
| 182 | int getUseCaseType(const char *useCase); |
| 183 | |
| 184 | static int callMode = AudioSystem::MODE_NORMAL; |
| 185 | // ---------------------------------------------------------------------------- |
| 186 | |
| 187 | bool platform_is_Fusion3() |
| 188 | { |
| 189 | char platform[128], baseband[128]; |
| 190 | property_get("ro.board.platform", platform, ""); |
| 191 | property_get("ro.baseband", baseband, ""); |
| 192 | if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) |
| 193 | return true; |
| 194 | else |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | int deviceName(alsa_handle_t *handle, unsigned flags, char **value) |
| 199 | { |
| 200 | int ret = 0; |
| 201 | char ident[70]; |
| 202 | |
| 203 | if (flags & PCM_IN) { |
| 204 | strlcpy(ident, "CapturePCM/", sizeof(ident)); |
| 205 | } else { |
| 206 | strlcpy(ident, "PlaybackPCM/", sizeof(ident)); |
| 207 | } |
| 208 | strlcat(ident, handle->useCase, sizeof(ident)); |
| 209 | ret = snd_use_case_get(handle->ucMgr, ident, (const char **)value); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 210 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 211 | ALOGD("Device value returned is %s", (*value)); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 212 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | status_t setHardwareParams(alsa_handle_t *handle) |
| 217 | { |
| 218 | struct snd_pcm_hw_params *params; |
| 219 | unsigned long bufferSize, reqBuffSize; |
| 220 | unsigned int periodTime, bufferTime; |
| 221 | unsigned int requestedRate = handle->sampleRate; |
| 222 | int status = 0; |
| 223 | int channels = handle->channels; |
| 224 | snd_pcm_format_t format = SNDRV_PCM_FORMAT_S16_LE; |
| 225 | |
| 226 | params = (snd_pcm_hw_params*) calloc(1, sizeof(struct snd_pcm_hw_params)); |
| 227 | if (!params) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 228 | ALOGE("Failed to allocate ALSA hardware parameters!"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 229 | return NO_INIT; |
| 230 | } |
| 231 | |
| 232 | reqBuffSize = handle->bufferSize; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 233 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 234 | ALOGD("setHardwareParams: reqBuffSize %d channels %d sampleRate %d", |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 235 | (int) reqBuffSize, handle->channels, handle->sampleRate); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 236 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 237 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 238 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 239 | if (channels == 6) { |
| 240 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 241 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 242 | ALOGV("HWParams: Use 4 channels in kernel for 5.1(%s) recording ", handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 243 | channels = 4; |
| 244 | reqBuffSize = DEFAULT_IN_BUFFER_SIZE; |
| 245 | } |
| 246 | } |
| 247 | #endif |
| 248 | |
| 249 | param_init(params); |
| 250 | param_set_mask(params, SNDRV_PCM_HW_PARAM_ACCESS, |
| 251 | SNDRV_PCM_ACCESS_RW_INTERLEAVED); |
| 252 | if (handle->format != SNDRV_PCM_FORMAT_S16_LE) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 253 | if (handle->format == AudioSystem::AMR_NB |
| 254 | || handle->format == AudioSystem::AMR_WB |
| 255 | #ifdef QCOM_QCHAT_ENABLED |
| 256 | || handle->format == AudioSystem::EVRC |
| 257 | || handle->format == AudioSystem::EVRCB |
| 258 | || handle->format == AudioSystem::EVRCWB |
| 259 | #endif |
| 260 | ) |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 261 | format = SNDRV_PCM_FORMAT_SPECIAL; |
| 262 | } |
| 263 | param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, |
| 264 | format); |
| 265 | param_set_mask(params, SNDRV_PCM_HW_PARAM_SUBFORMAT, |
| 266 | SNDRV_PCM_SUBFORMAT_STD); |
| 267 | param_set_min(params, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, reqBuffSize); |
| 268 | param_set_int(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 16); |
| 269 | param_set_int(params, SNDRV_PCM_HW_PARAM_FRAME_BITS, |
| 270 | channels * 16); |
| 271 | param_set_int(params, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 272 | channels); |
| 273 | param_set_int(params, SNDRV_PCM_HW_PARAM_RATE, handle->sampleRate); |
| 274 | param_set_hw_refine(handle->handle, params); |
| 275 | |
| 276 | if (param_set_hw_params(handle->handle, params)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 277 | ALOGE("cannot set hw params"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 278 | return NO_INIT; |
| 279 | } |
| 280 | param_dump(params); |
| 281 | |
| 282 | handle->handle->buffer_size = pcm_buffer_size(params); |
| 283 | handle->handle->period_size = pcm_period_size(params); |
| 284 | handle->handle->period_cnt = handle->handle->buffer_size/handle->handle->period_size; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 285 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 286 | ALOGD("setHardwareParams: buffer_size %d, period_size %d, period_cnt %d", |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 287 | handle->handle->buffer_size, handle->handle->period_size, |
| 288 | handle->handle->period_cnt); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 289 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 290 | handle->handle->rate = handle->sampleRate; |
| 291 | handle->handle->channels = handle->channels; |
| 292 | handle->periodSize = handle->handle->period_size; |
| 293 | if (strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC) && |
| 294 | strcmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC) && |
| 295 | (6 != handle->channels)) { |
| 296 | //Do not update buffersize for 5.1 recording |
| 297 | handle->bufferSize = handle->handle->period_size; |
| 298 | } |
| 299 | |
| 300 | return NO_ERROR; |
| 301 | } |
| 302 | |
| 303 | status_t setSoftwareParams(alsa_handle_t *handle) |
| 304 | { |
| 305 | struct snd_pcm_sw_params* params; |
| 306 | struct pcm* pcm = handle->handle; |
| 307 | |
| 308 | unsigned long periodSize = pcm->period_size; |
| 309 | int channels = handle->channels; |
| 310 | |
| 311 | params = (snd_pcm_sw_params*) calloc(1, sizeof(struct snd_pcm_sw_params)); |
| 312 | if (!params) { |
| 313 | LOG_ALWAYS_FATAL("Failed to allocate ALSA software parameters!"); |
| 314 | return NO_INIT; |
| 315 | } |
| 316 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 317 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 318 | if (channels == 6) { |
| 319 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 320 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 321 | ALOGV("SWParams: Use 4 channels in kernel for 5.1(%s) recording ", handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 322 | channels = 4; |
| 323 | } |
| 324 | } |
| 325 | #endif |
| 326 | |
| 327 | // Get the current software parameters |
| 328 | params->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; |
| 329 | params->period_step = 1; |
| 330 | if(((!strcmp(handle->useCase,SND_USE_CASE_MOD_PLAY_VOIP)) || |
| 331 | (!strcmp(handle->useCase,SND_USE_CASE_VERB_IP_VOICECALL)))){ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 332 | ALOGV("setparam: start & stop threshold for Voip "); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 333 | params->avail_min = handle->channels - 1 ? periodSize/4 : periodSize/2; |
| 334 | params->start_threshold = periodSize/2; |
| 335 | params->stop_threshold = INT_MAX; |
| 336 | } else { |
| 337 | params->avail_min = periodSize/2; |
| 338 | params->start_threshold = channels * (periodSize/4); |
| 339 | params->stop_threshold = INT_MAX; |
| 340 | } |
| 341 | params->silence_threshold = 0; |
| 342 | params->silence_size = 0; |
| 343 | |
| 344 | if (param_set_sw_params(handle->handle, params)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 345 | ALOGE("cannot set sw params"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 346 | return NO_INIT; |
| 347 | } |
| 348 | return NO_ERROR; |
| 349 | } |
| 350 | |
| 351 | void switchDevice(alsa_handle_t *handle, uint32_t devices, uint32_t mode) |
| 352 | { |
| 353 | const char **mods_list; |
| 354 | use_case_t useCaseNode; |
| 355 | unsigned usecase_type = 0; |
| 356 | bool inCallDevSwitch = false; |
| 357 | char *rxDevice, *txDevice, ident[70], *use_case = NULL; |
| 358 | int err = 0, index, mods_size; |
| 359 | int rx_dev_id, tx_dev_id; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 360 | ALOGV("%s: device %d", __FUNCTION__, devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 361 | |
| 362 | if ((mode == AudioSystem::MODE_IN_CALL) || (mode == AudioSystem::MODE_IN_COMMUNICATION)) { |
| 363 | if ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 364 | (devices & AudioSystem::DEVICE_IN_WIRED_HEADSET)) { |
| 365 | devices = devices | (AudioSystem::DEVICE_OUT_WIRED_HEADSET | |
| 366 | AudioSystem::DEVICE_IN_WIRED_HEADSET); |
| 367 | } else if (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE) { |
| 368 | devices = devices | (AudioSystem::DEVICE_OUT_WIRED_HEADPHONE | |
| 369 | AudioSystem::DEVICE_IN_BUILTIN_MIC); |
| 370 | } else if ((devices & AudioSystem::DEVICE_OUT_EARPIECE) || |
| 371 | (devices & AudioSystem::DEVICE_IN_BUILTIN_MIC)) { |
| 372 | devices = devices | (AudioSystem::DEVICE_IN_BUILTIN_MIC | |
| 373 | AudioSystem::DEVICE_OUT_EARPIECE); |
| 374 | } else if (devices & AudioSystem::DEVICE_OUT_SPEAKER) { |
ty.lee | 10dfa85 | 2012-08-01 21:09:45 +0900 | [diff] [blame] | 375 | devices = devices | (AudioSystem::DEVICE_IN_BACK_MIC | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 376 | AudioSystem::DEVICE_OUT_SPEAKER); |
| 377 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO) || |
| 378 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET) || |
| 379 | (devices & AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET)) { |
| 380 | devices = devices | (AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
| 381 | AudioSystem::DEVICE_OUT_BLUETOOTH_SCO); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 382 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 383 | } else if ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 384 | (devices & AudioSystem::DEVICE_IN_ANC_HEADSET)) { |
| 385 | devices = devices | (AudioSystem::DEVICE_OUT_ANC_HEADSET | |
| 386 | AudioSystem::DEVICE_IN_ANC_HEADSET); |
| 387 | } else if (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE) { |
| 388 | devices = devices | (AudioSystem::DEVICE_OUT_ANC_HEADPHONE | |
| 389 | AudioSystem::DEVICE_IN_BUILTIN_MIC); |
| 390 | #endif |
| 391 | } else if (devices & AudioSystem::DEVICE_OUT_AUX_DIGITAL) { |
| 392 | devices = devices | (AudioSystem::DEVICE_OUT_AUX_DIGITAL | |
| 393 | AudioSystem::DEVICE_IN_AUX_DIGITAL); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 394 | #ifdef QCOM_PROXY_DEVICE_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 395 | } else if ((devices & AudioSystem::DEVICE_OUT_PROXY) || |
| 396 | (devices & AudioSystem::DEVICE_IN_PROXY)) { |
| 397 | devices = devices | (AudioSystem::DEVICE_OUT_PROXY | |
| 398 | AudioSystem::DEVICE_IN_PROXY); |
| 399 | #endif |
| 400 | } |
| 401 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 402 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 403 | if ((devices & AudioSystem::DEVICE_IN_BUILTIN_MIC) && ( 6 == handle->channels)) { |
| 404 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 405 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 406 | ALOGV(" switchDevice , use ssr devices for channels:%d usecase:%s",handle->channels,handle->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 407 | s_set_flags(SSRQMIC_FLAG); |
| 408 | } |
| 409 | } |
| 410 | #endif |
| 411 | |
| 412 | rxDevice = getUCMDevice(devices & AudioSystem::DEVICE_OUT_ALL, 0, NULL); |
| 413 | txDevice = getUCMDevice(devices & AudioSystem::DEVICE_IN_ALL, 1, rxDevice); |
| 414 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 415 | if ((rxDevice != NULL) && (txDevice != NULL)) { |
| 416 | if (((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || |
| 417 | (strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN))) && (mode == AudioSystem::MODE_IN_CALL)) |
| 418 | inCallDevSwitch = true; |
| 419 | } |
Ajay Dudani | 91bf891 | 2012-08-20 18:48:13 -0700 | [diff] [blame] | 420 | |
| 421 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 422 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
| 423 | err = csd_client_disable_device(); |
| 424 | if (err < 0) |
| 425 | { |
| 426 | ALOGE("csd_client_disable_device, failed, error %d", err); |
| 427 | } |
| 428 | } |
| 429 | #endif |
| 430 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 431 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&use_case); |
| 432 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
| 433 | if (rxDevice != NULL) { |
| 434 | if ((strncmp(curRxUCMDevice, "None", 4)) && |
| 435 | ((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 436 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 437 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 438 | usecase_type = getUseCaseType(use_case); |
| 439 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 440 | ALOGD("Deroute use case %s type is %d\n", use_case, usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 441 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 442 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 443 | mUseCaseList.push_front(useCaseNode); |
| 444 | } |
| 445 | } |
| 446 | if (mods_size) { |
| 447 | for(index = 0; index < mods_size; index++) { |
| 448 | usecase_type = getUseCaseType(mods_list[index]); |
| 449 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 450 | ALOGD("Deroute use case %s type is %d\n", mods_list[index], usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 451 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 452 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 453 | mUseCaseList.push_back(useCaseNode); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 458 | } |
| 459 | } |
| 460 | if (txDevice != NULL) { |
| 461 | if ((strncmp(curTxUCMDevice, "None", 4)) && |
| 462 | ((strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 463 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 464 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 465 | usecase_type = getUseCaseType(use_case); |
| 466 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 467 | ALOGD("Deroute use case %s type is %d\n", use_case, usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 468 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 469 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 470 | mUseCaseList.push_front(useCaseNode); |
| 471 | } |
| 472 | } |
| 473 | if (mods_size) { |
| 474 | for(index = 0; index < mods_size; index++) { |
| 475 | usecase_type = getUseCaseType(mods_list[index]); |
| 476 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 477 | ALOGD("Deroute use case %s type is %d\n", mods_list[index], usecase_type); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 478 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 479 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 480 | mUseCaseList.push_back(useCaseNode); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 485 | } |
| 486 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 487 | ALOGV("%s,rxDev:%s, txDev:%s, curRxDev:%s, curTxDev:%s\n", __FUNCTION__, rxDevice, txDevice, curRxUCMDevice, curTxUCMDevice); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 488 | |
| 489 | if (rxDevice != NULL) { |
| 490 | snd_use_case_set(handle->ucMgr, "_enadev", rxDevice); |
| 491 | strlcpy(curRxUCMDevice, rxDevice, sizeof(curRxUCMDevice)); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 492 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 493 | if (devices & AudioSystem::DEVICE_OUT_FM) |
| 494 | s_set_fm_vol(fmVolume); |
| 495 | #endif |
| 496 | } |
| 497 | if (txDevice != NULL) { |
| 498 | snd_use_case_set(handle->ucMgr, "_enadev", txDevice); |
| 499 | strlcpy(curTxUCMDevice, txDevice, sizeof(curTxUCMDevice)); |
| 500 | } |
| 501 | for(ALSAUseCaseList::iterator it = mUseCaseList.begin(); it != mUseCaseList.end(); ++it) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 502 | ALOGD("Route use case %s\n", it->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 503 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 504 | strlen(SND_USE_CASE_VERB_INACTIVE))) && (!strncmp(use_case, it->useCase, MAX_UC_LEN))) { |
| 505 | snd_use_case_set(handle->ucMgr, "_verb", it->useCase); |
| 506 | } else { |
| 507 | snd_use_case_set(handle->ucMgr, "_enamod", it->useCase); |
| 508 | } |
| 509 | } |
| 510 | if (!mUseCaseList.empty()) |
| 511 | mUseCaseList.clear(); |
| 512 | if (use_case != NULL) { |
| 513 | free(use_case); |
| 514 | use_case = NULL; |
| 515 | } |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 516 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 517 | ALOGD("switchDevice: curTxUCMDevivce %s curRxDevDevice %s", curTxUCMDevice, curRxUCMDevice); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 518 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 519 | |
| 520 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
| 521 | /* get tx acdb id */ |
| 522 | memset(&ident,0,sizeof(ident)); |
| 523 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 524 | strlcat(ident, curTxUCMDevice, sizeof(ident)); |
| 525 | tx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 526 | |
| 527 | /* get rx acdb id */ |
| 528 | memset(&ident,0,sizeof(ident)); |
| 529 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 530 | strlcat(ident, curRxUCMDevice, sizeof(ident)); |
| 531 | rx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 532 | |
ehgrace.kim | 91e9fad | 2012-07-02 18:27:28 -0700 | [diff] [blame] | 533 | if (((rx_dev_id == DEVICE_SPEAKER_MONO_RX_ACDB_ID ) || (rx_dev_id == DEVICE_SPEAKER_STEREO_RX_ACDB_ID )) |
| 534 | && tx_dev_id == DEVICE_HANDSET_TX_ACDB_ID) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 535 | tx_dev_id = DEVICE_SPEAKER_TX_ACDB_ID; |
| 536 | } |
| 537 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 538 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 539 | ALOGV("rx_dev_id=%d, tx_dev_id=%d\n", rx_dev_id, tx_dev_id); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 540 | err = csd_client_enable_device(rx_dev_id, tx_dev_id, mDevSettingsFlag); |
| 541 | if (err < 0) |
| 542 | { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 543 | ALOGE("csd_client_disable_device failed, error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 544 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 545 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (rxDevice != NULL) { |
| 549 | if (pflag && (((!strncmp(rxDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 550 | ((!strncmp(curRxUCMDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 551 | (!strncmp(curRxUCMDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))) || |
| 552 | (((!strncmp(curRxUCMDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 553 | ((!strncmp(rxDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 554 | (!strncmp(rxDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))))) && |
| 555 | ((!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI, strlen(SND_USE_CASE_VERB_HIFI))) || |
| 556 | (!strncmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC, strlen(SND_USE_CASE_MOD_PLAY_MUSIC))))) { |
| 557 | s_open(handle); |
| 558 | pflag = false; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if (rxDevice != NULL) { |
| 563 | free(rxDevice); |
| 564 | rxDevice = NULL; |
| 565 | } |
| 566 | if (txDevice != NULL) { |
| 567 | free(txDevice); |
| 568 | txDevice = NULL; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | // ---------------------------------------------------------------------------- |
| 573 | |
| 574 | static status_t s_init(alsa_device_t *module, ALSAHandleList &list) |
| 575 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 576 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 577 | ALOGD("s_init: Initializing devices for ALSA module"); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 578 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 579 | |
| 580 | list.clear(); |
| 581 | |
| 582 | return NO_ERROR; |
| 583 | } |
| 584 | |
| 585 | static status_t s_open(alsa_handle_t *handle) |
| 586 | { |
| 587 | char *devName; |
| 588 | unsigned flags = 0; |
| 589 | int err = NO_ERROR; |
| 590 | |
| 591 | /* No need to call s_close for LPA as pcm device open and close is handled by LPAPlayer in stagefright */ |
| 592 | if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) |
| 593 | ||(!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 594 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 595 | ALOGD("s_open: Opening LPA /Tunnel playback"); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 596 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 597 | return NO_ERROR; |
| 598 | } |
| 599 | |
| 600 | s_close(handle); |
| 601 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 602 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 603 | ALOGD("s_open: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 604 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 605 | |
| 606 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 607 | // the device to be opened |
| 608 | |
| 609 | // The PCM stream is opened in blocking mode, per ALSA defaults. The |
| 610 | // AudioFlinger seems to assume blocking mode too, so asynchronous mode |
| 611 | // should not be used. |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 612 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 613 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 614 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 615 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
| 616 | ALOGV("LPA/tunnel use case"); |
| 617 | flags |= PCM_MMAP; |
| 618 | flags |= DEBUG_ON; |
| 619 | } else if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI)) || |
| 620 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC)) || |
| 621 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 622 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC))) { |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 623 | ALOGV("Music case"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 624 | flags = PCM_OUT; |
| 625 | } else { |
| 626 | flags = PCM_IN; |
| 627 | } |
| 628 | if (handle->channels == 1) { |
| 629 | flags |= PCM_MONO; |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 630 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 631 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 632 | else if (handle->channels == 4 ) { |
| 633 | flags |= PCM_QUAD; |
| 634 | } else if (handle->channels == 6 ) { |
| 635 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 636 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
| 637 | flags |= PCM_QUAD; |
| 638 | } else { |
| 639 | flags |= PCM_5POINT1; |
| 640 | } |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 641 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 642 | #endif |
| 643 | else { |
| 644 | flags |= PCM_STEREO; |
| 645 | } |
| 646 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 647 | ALOGE("Failed to get pcm device node: %s", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 648 | return NO_INIT; |
| 649 | } |
| 650 | if (devName != NULL) { |
| 651 | handle->handle = pcm_open(flags, (char*)devName); |
| 652 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 653 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 654 | return NO_INIT; |
| 655 | } |
| 656 | |
| 657 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 658 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 659 | free(devName); |
| 660 | return NO_INIT; |
| 661 | } |
| 662 | |
| 663 | handle->handle->flags = flags; |
| 664 | err = setHardwareParams(handle); |
| 665 | |
| 666 | if (err == NO_ERROR) { |
| 667 | err = setSoftwareParams(handle); |
| 668 | } |
| 669 | |
| 670 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 671 | ALOGE("Set HW/SW params failed: Closing the pcm stream"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 672 | s_standby(handle); |
| 673 | } |
| 674 | |
| 675 | free(devName); |
| 676 | return NO_ERROR; |
| 677 | } |
| 678 | |
| 679 | static status_t s_start_voip_call(alsa_handle_t *handle) |
| 680 | { |
| 681 | |
| 682 | char* devName; |
| 683 | char* devName1; |
| 684 | unsigned flags = 0; |
| 685 | int err = NO_ERROR; |
| 686 | uint8_t voc_pkt[VOIP_BUFFER_MAX_SIZE]; |
| 687 | |
| 688 | s_close(handle); |
| 689 | flags = PCM_OUT; |
| 690 | flags |= PCM_MONO; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 691 | ALOGV("s_open:s_start_voip_call handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 692 | |
| 693 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 694 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 695 | return NO_INIT; |
| 696 | } |
| 697 | |
| 698 | if (devName != NULL) { |
| 699 | handle->handle = pcm_open(flags, (char*)devName); |
| 700 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 701 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 702 | return NO_INIT; |
| 703 | } |
| 704 | |
| 705 | if (!handle->handle) { |
| 706 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 707 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 708 | return NO_INIT; |
| 709 | } |
| 710 | |
| 711 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 712 | ALOGE(" pcm ready failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | handle->handle->flags = flags; |
| 716 | err = setHardwareParams(handle); |
| 717 | |
| 718 | if (err == NO_ERROR) { |
| 719 | err = setSoftwareParams(handle); |
| 720 | } |
| 721 | |
| 722 | err = pcm_prepare(handle->handle); |
| 723 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 724 | ALOGE("DEVICE_OUT_DIRECTOUTPUT: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /* first write required start dsp */ |
| 728 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 729 | pcm_write(handle->handle,&voc_pkt,handle->handle->period_size); |
| 730 | handle->rxHandle = handle->handle; |
| 731 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 732 | ALOGV("s_open: DEVICE_IN_COMMUNICATION "); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 733 | flags = PCM_IN; |
| 734 | flags |= PCM_MONO; |
| 735 | handle->handle = 0; |
| 736 | |
| 737 | if (deviceName(handle, flags, &devName1) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 738 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 739 | return NO_INIT; |
| 740 | } |
| 741 | if (devName != NULL) { |
| 742 | handle->handle = pcm_open(flags, (char*)devName1); |
| 743 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 744 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 745 | return NO_INIT; |
| 746 | } |
| 747 | |
| 748 | if (!handle->handle) { |
| 749 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 750 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 751 | return NO_INIT; |
| 752 | } |
| 753 | |
| 754 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 755 | ALOGE(" pcm ready in failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | handle->handle->flags = flags; |
| 759 | |
| 760 | err = setHardwareParams(handle); |
| 761 | |
| 762 | if (err == NO_ERROR) { |
| 763 | err = setSoftwareParams(handle); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | err = pcm_prepare(handle->handle); |
| 768 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 769 | ALOGE("DEVICE_IN_COMMUNICATION: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* first read required start dsp */ |
| 773 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 774 | pcm_read(handle->handle,&voc_pkt,handle->handle->period_size); |
| 775 | return NO_ERROR; |
| 776 | } |
| 777 | |
| 778 | static status_t s_start_voice_call(alsa_handle_t *handle) |
| 779 | { |
| 780 | char* devName; |
| 781 | unsigned flags = 0; |
| 782 | int err = NO_ERROR; |
| 783 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 784 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 785 | ALOGD("s_start_voice_call: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 786 | #endif |
| 787 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 788 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 789 | // the device to be opened |
| 790 | |
| 791 | flags = PCM_OUT | PCM_MONO; |
| 792 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 793 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 794 | return NO_INIT; |
| 795 | } |
| 796 | if (devName != NULL) { |
| 797 | handle->handle = pcm_open(flags, (char*)devName); |
| 798 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 799 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 800 | return NO_INIT; |
| 801 | } |
| 802 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 803 | ALOGE("s_start_voicecall: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 804 | goto Error; |
| 805 | } |
| 806 | |
| 807 | handle->handle->flags = flags; |
| 808 | err = setHardwareParams(handle); |
| 809 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 810 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 811 | goto Error; |
| 812 | } |
| 813 | |
| 814 | err = setSoftwareParams(handle); |
| 815 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 816 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 817 | goto Error; |
| 818 | } |
| 819 | |
| 820 | err = pcm_prepare(handle->handle); |
| 821 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 822 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 823 | goto Error; |
| 824 | } |
| 825 | |
| 826 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 827 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 828 | goto Error; |
| 829 | } |
| 830 | |
| 831 | // Store the PCM playback device pointer in rxHandle |
| 832 | handle->rxHandle = handle->handle; |
| 833 | free(devName); |
| 834 | |
| 835 | // Open PCM capture device |
| 836 | flags = PCM_IN | PCM_MONO; |
| 837 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 838 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 839 | goto Error; |
| 840 | } |
| 841 | if (devName != NULL) { |
| 842 | handle->handle = pcm_open(flags, (char*)devName); |
| 843 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 844 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 845 | return NO_INIT; |
| 846 | } |
| 847 | if (!handle->handle) { |
| 848 | free(devName); |
| 849 | goto Error; |
| 850 | } |
| 851 | |
| 852 | handle->handle->flags = flags; |
| 853 | err = setHardwareParams(handle); |
| 854 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 855 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 856 | goto Error; |
| 857 | } |
| 858 | |
| 859 | err = setSoftwareParams(handle); |
| 860 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 861 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 862 | goto Error; |
| 863 | } |
| 864 | |
| 865 | err = pcm_prepare(handle->handle); |
| 866 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 867 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 868 | goto Error; |
| 869 | } |
| 870 | |
| 871 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 872 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 873 | goto Error; |
| 874 | } |
| 875 | |
| 876 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 877 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 878 | err = csd_client_start_voice(); |
| 879 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 880 | ALOGE("s_start_voice_call: csd_client error %d\n", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 881 | goto Error; |
| 882 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 883 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | free(devName); |
| 887 | return NO_ERROR; |
| 888 | |
| 889 | Error: |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 890 | ALOGE("s_start_voice_call: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 891 | free(devName); |
| 892 | s_close(handle); |
| 893 | return NO_INIT; |
| 894 | } |
| 895 | |
| 896 | static status_t s_start_fm(alsa_handle_t *handle) |
| 897 | { |
| 898 | char *devName; |
| 899 | unsigned flags = 0; |
| 900 | int err = NO_ERROR; |
| 901 | |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 902 | ALOGD("s_start_fm: handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 903 | |
| 904 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 905 | // the device to be opened |
| 906 | |
| 907 | flags = PCM_OUT | PCM_STEREO; |
| 908 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 909 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 910 | goto Error; |
| 911 | } |
| 912 | if (devName != NULL) { |
| 913 | handle->handle = pcm_open(flags, (char*)devName); |
| 914 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 915 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 916 | return NO_INIT; |
| 917 | } |
| 918 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 919 | ALOGE("s_start_fm: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 920 | goto Error; |
| 921 | } |
| 922 | |
| 923 | handle->handle->flags = flags; |
| 924 | err = setHardwareParams(handle); |
| 925 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 926 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 927 | goto Error; |
| 928 | } |
| 929 | |
| 930 | err = setSoftwareParams(handle); |
| 931 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 932 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 933 | goto Error; |
| 934 | } |
| 935 | |
| 936 | err = pcm_prepare(handle->handle); |
| 937 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 938 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 939 | goto Error; |
| 940 | } |
| 941 | |
| 942 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 943 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 944 | goto Error; |
| 945 | } |
| 946 | |
| 947 | // Store the PCM playback device pointer in rxHandle |
| 948 | handle->rxHandle = handle->handle; |
| 949 | free(devName); |
| 950 | |
| 951 | // Open PCM capture device |
| 952 | flags = PCM_IN | PCM_STEREO; |
| 953 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 954 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 955 | goto Error; |
| 956 | } |
| 957 | if (devName != NULL) { |
| 958 | handle->handle = pcm_open(flags, (char*)devName); |
| 959 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 960 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 961 | return NO_INIT; |
| 962 | } |
| 963 | if (!handle->handle) { |
| 964 | goto Error; |
| 965 | } |
| 966 | |
| 967 | handle->handle->flags = flags; |
| 968 | err = setHardwareParams(handle); |
| 969 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 970 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 971 | goto Error; |
| 972 | } |
| 973 | |
| 974 | err = setSoftwareParams(handle); |
| 975 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 976 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 977 | goto Error; |
| 978 | } |
| 979 | |
| 980 | err = pcm_prepare(handle->handle); |
| 981 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 982 | ALOGE("s_start_fm: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 983 | goto Error; |
| 984 | } |
| 985 | |
| 986 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 987 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 988 | goto Error; |
| 989 | } |
| 990 | |
| 991 | s_set_fm_vol(fmVolume); |
| 992 | free(devName); |
| 993 | return NO_ERROR; |
| 994 | |
| 995 | Error: |
| 996 | free(devName); |
| 997 | s_close(handle); |
| 998 | return NO_INIT; |
| 999 | } |
| 1000 | |
| 1001 | static status_t s_set_fm_vol(int value) |
| 1002 | { |
| 1003 | status_t err = NO_ERROR; |
| 1004 | |
| 1005 | ALSAControl control("/dev/snd/controlC0"); |
| 1006 | control.set("Internal FM RX Volume",value,0); |
| 1007 | fmVolume = value; |
| 1008 | |
| 1009 | return err; |
| 1010 | } |
| 1011 | |
| 1012 | static status_t s_set_lpa_vol(int value) |
| 1013 | { |
| 1014 | status_t err = NO_ERROR; |
| 1015 | |
| 1016 | ALSAControl control("/dev/snd/controlC0"); |
| 1017 | control.set("LPA RX Volume",value,0); |
| 1018 | |
| 1019 | return err; |
| 1020 | } |
| 1021 | |
| 1022 | static status_t s_start(alsa_handle_t *handle) |
| 1023 | { |
| 1024 | status_t err = NO_ERROR; |
| 1025 | |
| 1026 | if(!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1027 | ALOGE("No active PCM driver to start"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1028 | return err; |
| 1029 | } |
| 1030 | |
| 1031 | err = pcm_prepare(handle->handle); |
| 1032 | |
| 1033 | return err; |
| 1034 | } |
| 1035 | |
| 1036 | static status_t s_close(alsa_handle_t *handle) |
| 1037 | { |
| 1038 | int ret; |
| 1039 | status_t err = NO_ERROR; |
| 1040 | struct pcm *h = handle->rxHandle; |
| 1041 | |
| 1042 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1043 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1044 | ALOGD("s_close: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1045 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1046 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1047 | ALOGV("s_close rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1048 | err = pcm_close(h); |
| 1049 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1050 | ALOGE("s_close: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | h = handle->handle; |
| 1055 | handle->handle = 0; |
| 1056 | |
| 1057 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1058 | ALOGV("s_close handle h %p\n", h); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1059 | err = pcm_close(h); |
| 1060 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1061 | ALOGE("s_close: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_VOICECALL) || |
| 1065 | !strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_VOICE)) && |
| 1066 | platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1067 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1068 | err = csd_client_stop_voice(); |
| 1069 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1070 | ALOGE("s_close: csd_client error %d\n", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1071 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1072 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | disableDevice(handle); |
| 1076 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1077 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1078 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1079 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))){ |
| 1080 | disableDevice(handle); |
| 1081 | } |
| 1082 | |
| 1083 | return err; |
| 1084 | } |
| 1085 | |
| 1086 | /* |
| 1087 | this is same as s_close, but don't discard |
| 1088 | the device/mode info. This way we can still |
| 1089 | close the device, hit idle and power-save, reopen the pcm |
| 1090 | for the same device/mode after resuming |
| 1091 | */ |
| 1092 | static status_t s_standby(alsa_handle_t *handle) |
| 1093 | { |
| 1094 | int ret; |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 1095 | status_t err = NO_ERROR; |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1096 | struct pcm *h = handle->rxHandle; |
| 1097 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1098 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1099 | ALOGD("s_standby: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1100 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1101 | if (h) { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 1102 | ALOGD("s_standby rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1103 | err = pcm_close(h); |
| 1104 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1105 | ALOGE("s_standby: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | h = handle->handle; |
| 1110 | handle->handle = 0; |
| 1111 | |
| 1112 | if (h) { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1113 | #if LOCAL_LOGD |
| 1114 | ALOGD("s_standby handle h %p\n", h); |
| 1115 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1116 | err = pcm_close(h); |
| 1117 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1118 | ALOGE("s_standby: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1119 | } |
| 1120 | disableDevice(handle); |
| 1121 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1122 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1123 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1124 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
| 1125 | disableDevice(handle); |
| 1126 | } |
| 1127 | |
| 1128 | return err; |
| 1129 | } |
| 1130 | |
| 1131 | static status_t s_route(alsa_handle_t *handle, uint32_t devices, int mode) |
| 1132 | { |
| 1133 | status_t status = NO_ERROR; |
| 1134 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1135 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1136 | ALOGD("s_route: devices 0x%x in mode %d", devices, mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1137 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1138 | callMode = mode; |
| 1139 | switchDevice(handle, devices, mode); |
| 1140 | return status; |
| 1141 | } |
| 1142 | |
| 1143 | int getUseCaseType(const char *useCase) |
| 1144 | { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame] | 1145 | ALOGD("use case is %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1146 | if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI, |
| 1147 | strlen(SND_USE_CASE_VERB_HIFI)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1148 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC, |
| 1149 | strlen(SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1150 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER, |
| 1151 | strlen(SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1152 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_TUNNEL, |
| 1153 | strlen(SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1154 | !strncmp(useCase, SND_USE_CASE_VERB_DIGITAL_RADIO, |
| 1155 | strlen(SND_USE_CASE_VERB_DIGITAL_RADIO)) || |
| 1156 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_MUSIC, |
| 1157 | strlen(SND_USE_CASE_MOD_PLAY_MUSIC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1158 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC, |
| 1159 | strlen(SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1160 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_LPA, |
| 1161 | strlen(SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1162 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_TUNNEL, |
| 1163 | strlen(SND_USE_CASE_MOD_PLAY_TUNNEL)) || |
| 1164 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_FM, |
| 1165 | strlen(SND_USE_CASE_MOD_PLAY_FM))) { |
| 1166 | return USECASE_TYPE_RX; |
| 1167 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI_REC, |
| 1168 | strlen(SND_USE_CASE_VERB_HIFI_REC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1169 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOWLATENCY_REC, |
| 1170 | strlen(SND_USE_CASE_VERB_HIFI_LOWLATENCY_REC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1171 | !strncmp(useCase, SND_USE_CASE_VERB_FM_REC, |
| 1172 | strlen(SND_USE_CASE_VERB_FM_REC)) || |
| 1173 | !strncmp(useCase, SND_USE_CASE_VERB_FM_A2DP_REC, |
| 1174 | strlen(SND_USE_CASE_VERB_FM_A2DP_REC)) || |
| 1175 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, |
| 1176 | strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC)) || |
SathishKumar Mani | 8861338 | 2012-08-13 18:40:18 -0700 | [diff] [blame] | 1177 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_LOWLATENCY_MUSIC, |
| 1178 | strlen(SND_USE_CASE_MOD_CAPTURE_LOWLATENCY_MUSIC)) || |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1179 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_FM, |
| 1180 | strlen(SND_USE_CASE_MOD_CAPTURE_FM)) || |
| 1181 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_A2DP_FM, |
| 1182 | strlen(SND_USE_CASE_MOD_CAPTURE_A2DP_FM))) { |
| 1183 | return USECASE_TYPE_TX; |
| 1184 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_VOICECALL, |
| 1185 | strlen(SND_USE_CASE_VERB_VOICECALL)) || |
| 1186 | !strncmp(useCase, SND_USE_CASE_VERB_IP_VOICECALL, |
| 1187 | strlen(SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 1188 | !strncmp(useCase, SND_USE_CASE_VERB_DL_REC, |
| 1189 | strlen(SND_USE_CASE_VERB_DL_REC)) || |
| 1190 | !strncmp(useCase, SND_USE_CASE_VERB_UL_DL_REC, |
| 1191 | strlen(SND_USE_CASE_VERB_UL_DL_REC)) || |
| 1192 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOICE, |
| 1193 | strlen(SND_USE_CASE_MOD_PLAY_VOICE)) || |
| 1194 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOIP, |
| 1195 | strlen(SND_USE_CASE_MOD_PLAY_VOIP)) || |
| 1196 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_DL, |
| 1197 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_DL)) || |
| 1198 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL, |
| 1199 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL)) || |
| 1200 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE, |
| 1201 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE)) || |
| 1202 | !strncmp(useCase, SND_USE_CASE_VERB_VOLTE, |
| 1203 | strlen(SND_USE_CASE_VERB_VOLTE)) || |
| 1204 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOLTE, |
| 1205 | strlen(SND_USE_CASE_MOD_PLAY_VOLTE))) { |
| 1206 | return (USECASE_TYPE_RX | USECASE_TYPE_TX); |
| 1207 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1208 | ALOGE("unknown use case %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1209 | return 0; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | static void disableDevice(alsa_handle_t *handle) |
| 1214 | { |
| 1215 | unsigned usecase_type = 0; |
| 1216 | int i, mods_size; |
| 1217 | char *useCase; |
| 1218 | const char **mods_list; |
| 1219 | |
| 1220 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1221 | if (useCase != NULL) { |
| 1222 | if (!strncmp(useCase, handle->useCase, MAX_UC_LEN)) { |
| 1223 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 1224 | } else { |
| 1225 | snd_use_case_set(handle->ucMgr, "_dismod", handle->useCase); |
| 1226 | } |
| 1227 | free(useCase); |
| 1228 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1229 | if (strncmp(useCase, SND_USE_CASE_VERB_INACTIVE, |
| 1230 | strlen(SND_USE_CASE_VERB_INACTIVE))) |
| 1231 | usecase_type |= getUseCaseType(useCase); |
| 1232 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1233 | #if LOCAL_LOGD |
| 1234 | ALOGD("Number of modifiers %d\n", mods_size); |
| 1235 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1236 | if (mods_size) { |
| 1237 | for(i = 0; i < mods_size; i++) { |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 1238 | #if LOCAL_LOGD |
| 1239 | ALOGD("index %d modifier %s\n", i, mods_list[i]); |
| 1240 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1241 | usecase_type |= getUseCaseType(mods_list[i]); |
| 1242 | } |
| 1243 | } |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1244 | #if LOCAL_LOGD |
| 1245 | ALOGD("usecase_type is %d\n", usecase_type); |
| 1246 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1247 | if (!(usecase_type & USECASE_TYPE_TX) && (strncmp(curTxUCMDevice, "None", 4))) |
| 1248 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 1249 | if (!(usecase_type & USECASE_TYPE_RX) && (strncmp(curRxUCMDevice, "None", 4))) |
| 1250 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 1251 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1252 | ALOGE("Invalid state, no valid use case found to disable"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1253 | } |
| 1254 | free(useCase); |
| 1255 | } |
| 1256 | |
| 1257 | char *getUCMDevice(uint32_t devices, int input, char *rxDevice) |
| 1258 | { |
| 1259 | if (!input) { |
| 1260 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1261 | (callMode == AudioSystem::MODE_IN_CALL) && |
| 1262 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1263 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1264 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1265 | || |
| 1266 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1267 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1268 | #endif |
| 1269 | if (mDevSettingsFlag & TTY_VCO) { |
| 1270 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_RX); |
| 1271 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1272 | return strdup(SND_USE_CASE_DEV_TTY_FULL_RX); |
| 1273 | } else if (mDevSettingsFlag & TTY_HCO) { |
| 1274 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_RX); /* HANDSET RX */ |
| 1275 | } |
| 1276 | }else if ((devices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET) || |
| 1277 | (devices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) { |
| 1278 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
| 1279 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1280 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1281 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
| 1282 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1283 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1284 | } else { |
| 1285 | return strdup(SND_USE_CASE_DEV_SPEAKER_HEADSET); /* COMBO SPEAKER+HEADSET RX */ |
| 1286 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1287 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1288 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1289 | ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1290 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1291 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1292 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1293 | (devices & AudioSystem::DEVICE_OUT_FM_TX)) { |
| 1294 | return strdup(SND_USE_CASE_DEV_SPEAKER_FM_TX); /* COMBO SPEAKER+FM_TX RX */ |
| 1295 | #endif |
| 1296 | } else if (devices & AudioSystem::DEVICE_OUT_EARPIECE) { |
| 1297 | return strdup(SND_USE_CASE_DEV_EARPIECE); /* HANDSET RX */ |
| 1298 | } else if (devices & AudioSystem::DEVICE_OUT_SPEAKER) { |
| 1299 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1300 | } else if ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1301 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE)) { |
| 1302 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1303 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1304 | } else { |
| 1305 | return strdup(SND_USE_CASE_DEV_HEADPHONES); /* HEADSET RX */ |
| 1306 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1307 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1308 | } else if ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1309 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE)) { |
| 1310 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1311 | #endif |
| 1312 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO) || |
| 1313 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET) || |
| 1314 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT)) { |
| 1315 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1316 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_RX); /* BTSCO RX*/ |
| 1317 | else |
| 1318 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_RX); /* BTSCO RX*/ |
| 1319 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP) || |
| 1320 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) || |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1321 | #ifdef QCOM_VOIP_ENABLED |
| 1322 | (devices & AudioSystem::DEVICE_OUT_DIRECTOUTPUT) || |
| 1323 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1324 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) { |
| 1325 | /* Nothing to be done, use current active device */ |
| 1326 | if (strncmp(curRxUCMDevice, "None", 4)) { |
| 1327 | return strdup(curRxUCMDevice); |
| 1328 | } |
| 1329 | } else if (devices & AudioSystem::DEVICE_OUT_AUX_DIGITAL) { |
| 1330 | return strdup(SND_USE_CASE_DEV_HDMI); /* HDMI RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1331 | #ifdef QCOM_PROXY_DEVICE_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1332 | } else if (devices & AudioSystem::DEVICE_OUT_PROXY) { |
| 1333 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1334 | #endif |
| 1335 | #ifdef QCOM_FM_TX_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1336 | } else if (devices & AudioSystem::DEVICE_OUT_FM_TX) { |
| 1337 | return strdup(SND_USE_CASE_DEV_FM_TX); /* FM Tx */ |
| 1338 | #endif |
| 1339 | } else if (devices & AudioSystem::DEVICE_OUT_DEFAULT) { |
| 1340 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1341 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1342 | ALOGD("No valid output device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } else { |
| 1345 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1346 | (callMode == AudioSystem::MODE_IN_CALL) && |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1347 | ((devices & AudioSystem::DEVICE_IN_WIRED_HEADSET))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1348 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1349 | ||(devices & AudioSystem::DEVICE_IN_ANC_HEADSET))) { |
| 1350 | #endif |
| 1351 | if (mDevSettingsFlag & TTY_HCO) { |
| 1352 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_TX); |
| 1353 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1354 | return strdup(SND_USE_CASE_DEV_TTY_FULL_TX); |
| 1355 | } else if (mDevSettingsFlag & TTY_VCO) { |
| 1356 | if (!strncmp(mic_type, "analog", 6)) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1357 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_ANALOG_TX); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1358 | } else { |
| 1359 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_TX); |
| 1360 | } |
| 1361 | } |
| 1362 | } else if (devices & AudioSystem::DEVICE_IN_BUILTIN_MIC) { |
| 1363 | if (!strncmp(mic_type, "analog", 6)) { |
| 1364 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1365 | } else { |
| 1366 | if (mDevSettingsFlag & DMIC_FLAG) { |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1367 | #ifdef USES_FLUENCE_INCALL |
| 1368 | if(callMode == AudioSystem::MODE_IN_CALL) { |
| 1369 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1370 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1371 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1372 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1373 | } else { |
| 1374 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
| 1375 | } |
| 1376 | } |
| 1377 | #else |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1378 | if (((rxDevice != NULL) && |
| 1379 | !strncmp(rxDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1380 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) || |
| 1381 | !strncmp(curRxUCMDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1382 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) { |
| 1383 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1384 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1385 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1386 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1387 | } |
| 1388 | } else { |
| 1389 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1390 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1391 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1392 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1393 | } |
| 1394 | } |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1395 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1396 | } else if (mDevSettingsFlag & QMIC_FLAG){ |
| 1397 | return strdup(SND_USE_CASE_DEV_QUAD_MIC); |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1398 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1399 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1400 | else if (mDevSettingsFlag & SSRQMIC_FLAG){ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1401 | ALOGV("return SSRQMIC_FLAG: 0x%x devices:0x%x",mDevSettingsFlag,devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1402 | // Mapping for quad mic input device. |
| 1403 | return strdup(SND_USE_CASE_DEV_SSR_QUAD_MIC); /* SSR Quad MIC */ |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1404 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1405 | #endif |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1406 | #ifdef SEPERATED_AUDIO_INPUT |
| 1407 | if(input_source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1408 | ALOGV("getUCMdevice returned the VOICE_RECOGNITION UCM by input source = %d", input_source); |
| 1409 | return strdup(SND_USE_CASE_DEV_VOICE_RECOGNITION ); /* VOICE RECOGNITION TX */ |
| 1410 | } else if(input_source == AUDIO_SOURCE_CAMCORDER) { |
| 1411 | ALOGV("getUCMdevice returned the Camcorder Tx UCM by input source = %d", input_source); |
| 1412 | return strdup(SND_USE_CASE_DEV_CAMCORDER_TX ); /* CAMCORDER TX */ |
| 1413 | } |
| 1414 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1415 | else { |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1416 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | } else if (devices & AudioSystem::DEVICE_IN_AUX_DIGITAL) { |
| 1420 | return strdup(SND_USE_CASE_DEV_HDMI_TX); /* HDMI TX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1421 | #ifdef QCOM_ANC_HEADSET_ENABLED |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1422 | } else if (devices & AudioSystem::DEVICE_IN_ANC_HEADSET) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1423 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
| 1424 | #endif |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1425 | } else if (devices & AudioSystem::DEVICE_IN_WIRED_HEADSET) { |
| 1426 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1427 | } else if (devices & AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 1428 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1429 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_TX); /* BTSCO TX*/ |
| 1430 | else |
| 1431 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_TX); /* BTSCO TX*/ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1432 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1433 | } else if ((devices & AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET) || |
| 1434 | (devices & AudioSystem::DEVICE_IN_PROXY)) { |
| 1435 | return strdup(SND_USE_CASE_DEV_PROXY_TX); /* PROXY TX */ |
| 1436 | #endif |
| 1437 | } else if ((devices & AudioSystem::DEVICE_IN_COMMUNICATION) || |
| 1438 | (devices & AudioSystem::DEVICE_IN_VOICE_CALL)) { |
| 1439 | /* Nothing to be done, use current active device */ |
| 1440 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1441 | return strdup(curTxUCMDevice); |
| 1442 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1443 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1444 | } else if ((devices & AudioSystem::DEVICE_IN_FM_RX) || |
| 1445 | (devices & AudioSystem::DEVICE_IN_FM_RX_A2DP)) { |
| 1446 | /* Nothing to be done, use current tx device or set dummy device */ |
| 1447 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1448 | return strdup(curTxUCMDevice); |
| 1449 | } else { |
| 1450 | return strdup(SND_USE_CASE_DEV_DUMMY_TX); |
| 1451 | } |
| 1452 | #endif |
| 1453 | } else if ((devices & AudioSystem::DEVICE_IN_AMBIENT) || |
| 1454 | (devices & AudioSystem::DEVICE_IN_BACK_MIC)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1455 | ALOGI("No proper mapping found with UCM device list, setting default"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1456 | if (!strncmp(mic_type, "analog", 6)) { |
| 1457 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1458 | } else { |
| 1459 | return strdup(SND_USE_CASE_DEV_LINE); /* BUILTIN-MIC TX */ |
| 1460 | } |
| 1461 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1462 | ALOGD("No valid input device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1463 | } |
| 1464 | } |
| 1465 | return NULL; |
| 1466 | } |
| 1467 | |
| 1468 | void s_set_voice_volume(int vol) |
| 1469 | { |
| 1470 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1471 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1472 | ALOGD("s_set_voice_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1473 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1474 | ALSAControl control("/dev/snd/controlC0"); |
| 1475 | control.set("Voice Rx Volume", vol, 0); |
| 1476 | |
| 1477 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1478 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1479 | err = csd_client_volume(vol); |
| 1480 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1481 | ALOGE("s_set_voice_volume: csd_client error %d", err); |
SathishKumar Mani | e42406e | 2012-08-29 16:25:54 -0700 | [diff] [blame] | 1482 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1483 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | void s_set_volte_volume(int vol) |
| 1488 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1489 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1490 | ALOGD("s_set_volte_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1491 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1492 | ALSAControl control("/dev/snd/controlC0"); |
| 1493 | control.set("VoLTE Rx Volume", vol, 0); |
| 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | void s_set_voip_volume(int vol) |
| 1498 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1499 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1500 | ALOGD("s_set_voip_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1501 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1502 | ALSAControl control("/dev/snd/controlC0"); |
| 1503 | control.set("Voip Rx Volume", vol, 0); |
| 1504 | } |
| 1505 | void s_set_mic_mute(int state) |
| 1506 | { |
| 1507 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1508 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1509 | ALOGD("s_set_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1510 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1511 | ALSAControl control("/dev/snd/controlC0"); |
| 1512 | control.set("Voice Tx Mute", state, 0); |
| 1513 | |
| 1514 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1515 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1516 | err = csd_client_mic_mute(state); |
| 1517 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1518 | ALOGE("s_set_mic_mute: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1519 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1520 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1521 | } |
| 1522 | } |
| 1523 | void s_set_volte_mic_mute(int state) |
| 1524 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1525 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1526 | ALOGD("s_set_volte_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1527 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1528 | ALSAControl control("/dev/snd/controlC0"); |
| 1529 | control.set("VoLTE Tx Mute", state, 0); |
| 1530 | } |
| 1531 | |
| 1532 | void s_set_voip_mic_mute(int state) |
| 1533 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1534 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1535 | ALOGD("s_set_voip_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1536 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1537 | ALSAControl control("/dev/snd/controlC0"); |
| 1538 | control.set("Voip Tx Mute", state, 0); |
| 1539 | } |
| 1540 | |
| 1541 | void s_set_voip_config(int mode, int rate) |
| 1542 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1543 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1544 | ALOGD("s_set_voip_config: mode %d,rate %d", mode, rate); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1545 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1546 | ALSAControl control("/dev/snd/controlC0"); |
| 1547 | char** setValues; |
| 1548 | setValues = (char**)malloc(2*sizeof(char*)); |
| 1549 | if (setValues == NULL) { |
| 1550 | return; |
| 1551 | } |
| 1552 | setValues[0] = (char*)malloc(4*sizeof(char)); |
| 1553 | if (setValues[0] == NULL) { |
| 1554 | free(setValues); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | setValues[1] = (char*)malloc(8*sizeof(char)); |
| 1559 | if (setValues[1] == NULL) { |
| 1560 | free(setValues); |
| 1561 | free(setValues[0]); |
| 1562 | return; |
| 1563 | } |
| 1564 | |
| 1565 | sprintf(setValues[0], "%d",mode); |
| 1566 | sprintf(setValues[1], "%d",rate); |
| 1567 | |
| 1568 | control.setext("Voip Mode Rate Config", 2, setValues); |
| 1569 | free(setValues[1]); |
| 1570 | free(setValues[0]); |
| 1571 | free(setValues); |
| 1572 | return; |
| 1573 | } |
| 1574 | |
| 1575 | void s_set_btsco_rate(int rate) |
| 1576 | { |
| 1577 | btsco_samplerate = rate; |
| 1578 | } |
| 1579 | |
| 1580 | void s_enable_wide_voice(bool flag) |
| 1581 | { |
| 1582 | int err = 0; |
| 1583 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1584 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1585 | ALOGD("s_enable_wide_voice: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1586 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1587 | ALSAControl control("/dev/snd/controlC0"); |
| 1588 | if(flag == true) { |
| 1589 | control.set("Widevoice Enable", 1, 0); |
| 1590 | } else { |
| 1591 | control.set("Widevoice Enable", 0, 0); |
| 1592 | } |
| 1593 | |
| 1594 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1595 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1596 | err == csd_client_wide_voice(flag); |
| 1597 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1598 | ALOGE("s_enable_wide_voice: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1599 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1600 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | void s_set_voc_rec_mode(uint8_t mode) |
| 1605 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1606 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1607 | ALOGD("s_set_voc_rec_mode: mode %d", mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1608 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1609 | ALSAControl control("/dev/snd/controlC0"); |
| 1610 | control.set("Incall Rec Mode", mode, 0); |
| 1611 | } |
| 1612 | |
| 1613 | void s_enable_fens(bool flag) |
| 1614 | { |
| 1615 | int err = 0; |
| 1616 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1617 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1618 | ALOGD("s_enable_fens: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1619 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1620 | ALSAControl control("/dev/snd/controlC0"); |
| 1621 | if(flag == true) { |
| 1622 | control.set("FENS Enable", 1, 0); |
| 1623 | } else { |
| 1624 | control.set("FENS Enable", 0, 0); |
| 1625 | } |
| 1626 | |
| 1627 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1628 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1629 | err = csd_client_fens(flag); |
| 1630 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1631 | ALOGE("s_enable_fens: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1632 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1633 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | void s_enable_slow_talk(bool flag) |
| 1638 | { |
| 1639 | int err = 0; |
| 1640 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1641 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1642 | ALOGD("s_enable_slow_talk: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1643 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1644 | ALSAControl control("/dev/snd/controlC0"); |
| 1645 | if(flag == true) { |
| 1646 | control.set("Slowtalk Enable", 1, 0); |
| 1647 | } else { |
| 1648 | control.set("Slowtalk Enable", 0, 0); |
| 1649 | } |
| 1650 | |
| 1651 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1652 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1653 | err = csd_client_slow_talk(flag); |
| 1654 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1655 | ALOGE("s_enable_slow_talk: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1656 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1657 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | void s_set_flags(uint32_t flags) |
| 1662 | { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1663 | ALOGV("s_set_flags: flags %d", flags); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1664 | mDevSettingsFlag = flags; |
| 1665 | } |
| 1666 | |
| 1667 | static status_t s_set_compressed_vol(int value) |
| 1668 | { |
| 1669 | status_t err = NO_ERROR; |
| 1670 | |
| 1671 | ALSAControl control("/dev/snd/controlC0"); |
| 1672 | control.set("COMPRESSED RX Volume",value,0); |
| 1673 | |
| 1674 | return err; |
| 1675 | } |
| 1676 | |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1677 | #ifdef SEPERATED_AUDIO_INPUT |
| 1678 | void s_setInput(int input) |
| 1679 | { |
| 1680 | input_source = input; |
| 1681 | ALOGD("s_setInput() : input_source = %d",input_source); |
| 1682 | } |
| 1683 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1684 | } |