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 | |
| 415 | if (rxDevice != NULL) { |
| 416 | if ((handle->handle) && (((!strncmp(rxDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 417 | ((!strncmp(curRxUCMDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 418 | (!strncmp(curRxUCMDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))) || |
| 419 | (((!strncmp(curRxUCMDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 420 | ((!strncmp(rxDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 421 | (!strncmp(rxDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))))) && |
| 422 | ((!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI, strlen(SND_USE_CASE_VERB_HIFI))) || |
| 423 | (!strncmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC, strlen(SND_USE_CASE_MOD_PLAY_MUSIC))))) { |
| 424 | pcm_close(handle->handle); |
| 425 | handle->handle=NULL; |
| 426 | handle->rxHandle=NULL; |
| 427 | pflag = true; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | if ((rxDevice != NULL) && (txDevice != NULL)) { |
| 432 | if (((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || |
| 433 | (strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN))) && (mode == AudioSystem::MODE_IN_CALL)) |
| 434 | inCallDevSwitch = true; |
| 435 | } |
Ajay Dudani | 91bf891 | 2012-08-20 18:48:13 -0700 | [diff] [blame] | 436 | |
| 437 | #ifdef QCOM_CSDCLIENT_ENABLED |
| 438 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
| 439 | err = csd_client_disable_device(); |
| 440 | if (err < 0) |
| 441 | { |
| 442 | ALOGE("csd_client_disable_device, failed, error %d", err); |
| 443 | } |
| 444 | } |
| 445 | #endif |
| 446 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 447 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&use_case); |
| 448 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
| 449 | if (rxDevice != NULL) { |
| 450 | if ((strncmp(curRxUCMDevice, "None", 4)) && |
| 451 | ((strncmp(rxDevice, curRxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 452 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 453 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 454 | usecase_type = getUseCaseType(use_case); |
| 455 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 456 | 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] | 457 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 458 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 459 | mUseCaseList.push_front(useCaseNode); |
| 460 | } |
| 461 | } |
| 462 | if (mods_size) { |
| 463 | for(index = 0; index < mods_size; index++) { |
| 464 | usecase_type = getUseCaseType(mods_list[index]); |
| 465 | if (usecase_type & USECASE_TYPE_RX) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 466 | 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] | 467 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 468 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 469 | mUseCaseList.push_back(useCaseNode); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 474 | } |
| 475 | } |
| 476 | if (txDevice != NULL) { |
| 477 | if ((strncmp(curTxUCMDevice, "None", 4)) && |
| 478 | ((strncmp(txDevice, curTxUCMDevice, MAX_STR_LEN)) || (inCallDevSwitch == true))) { |
| 479 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 480 | strlen(SND_USE_CASE_VERB_INACTIVE)))) { |
| 481 | usecase_type = getUseCaseType(use_case); |
| 482 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 483 | 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] | 484 | strlcpy(useCaseNode.useCase, use_case, MAX_STR_LEN); |
| 485 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 486 | mUseCaseList.push_front(useCaseNode); |
| 487 | } |
| 488 | } |
| 489 | if (mods_size) { |
| 490 | for(index = 0; index < mods_size; index++) { |
| 491 | usecase_type = getUseCaseType(mods_list[index]); |
| 492 | if ((usecase_type & USECASE_TYPE_TX) && (!(usecase_type & USECASE_TYPE_RX))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 493 | 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] | 494 | strlcpy(useCaseNode.useCase, mods_list[index], MAX_STR_LEN); |
| 495 | snd_use_case_set(handle->ucMgr, "_dismod", mods_list[index]); |
| 496 | mUseCaseList.push_back(useCaseNode); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 501 | } |
| 502 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 503 | 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] | 504 | |
| 505 | if (rxDevice != NULL) { |
| 506 | snd_use_case_set(handle->ucMgr, "_enadev", rxDevice); |
| 507 | strlcpy(curRxUCMDevice, rxDevice, sizeof(curRxUCMDevice)); |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 508 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 509 | if (devices & AudioSystem::DEVICE_OUT_FM) |
| 510 | s_set_fm_vol(fmVolume); |
| 511 | #endif |
| 512 | } |
| 513 | if (txDevice != NULL) { |
| 514 | snd_use_case_set(handle->ucMgr, "_enadev", txDevice); |
| 515 | strlcpy(curTxUCMDevice, txDevice, sizeof(curTxUCMDevice)); |
| 516 | } |
| 517 | for(ALSAUseCaseList::iterator it = mUseCaseList.begin(); it != mUseCaseList.end(); ++it) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 518 | ALOGD("Route use case %s\n", it->useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 519 | if ((use_case != NULL) && (strncmp(use_case, SND_USE_CASE_VERB_INACTIVE, |
| 520 | strlen(SND_USE_CASE_VERB_INACTIVE))) && (!strncmp(use_case, it->useCase, MAX_UC_LEN))) { |
| 521 | snd_use_case_set(handle->ucMgr, "_verb", it->useCase); |
| 522 | } else { |
| 523 | snd_use_case_set(handle->ucMgr, "_enamod", it->useCase); |
| 524 | } |
| 525 | } |
| 526 | if (!mUseCaseList.empty()) |
| 527 | mUseCaseList.clear(); |
| 528 | if (use_case != NULL) { |
| 529 | free(use_case); |
| 530 | use_case = NULL; |
| 531 | } |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 532 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 533 | ALOGD("switchDevice: curTxUCMDevivce %s curRxDevDevice %s", curTxUCMDevice, curRxUCMDevice); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 534 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 535 | |
| 536 | if (mode == AudioSystem::MODE_IN_CALL && platform_is_Fusion3() && (inCallDevSwitch == true)) { |
| 537 | /* get tx acdb id */ |
| 538 | memset(&ident,0,sizeof(ident)); |
| 539 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 540 | strlcat(ident, curTxUCMDevice, sizeof(ident)); |
| 541 | tx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 542 | |
| 543 | /* get rx acdb id */ |
| 544 | memset(&ident,0,sizeof(ident)); |
| 545 | strlcpy(ident, "ACDBID/", sizeof(ident)); |
| 546 | strlcat(ident, curRxUCMDevice, sizeof(ident)); |
| 547 | rx_dev_id = snd_use_case_get(handle->ucMgr, ident, NULL); |
| 548 | |
ehgrace.kim | 91e9fad | 2012-07-02 18:27:28 -0700 | [diff] [blame] | 549 | if (((rx_dev_id == DEVICE_SPEAKER_MONO_RX_ACDB_ID ) || (rx_dev_id == DEVICE_SPEAKER_STEREO_RX_ACDB_ID )) |
| 550 | && tx_dev_id == DEVICE_HANDSET_TX_ACDB_ID) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 551 | tx_dev_id = DEVICE_SPEAKER_TX_ACDB_ID; |
| 552 | } |
| 553 | |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 554 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 555 | 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] | 556 | err = csd_client_enable_device(rx_dev_id, tx_dev_id, mDevSettingsFlag); |
| 557 | if (err < 0) |
| 558 | { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 559 | ALOGE("csd_client_disable_device failed, error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 560 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 561 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | if (rxDevice != NULL) { |
| 565 | if (pflag && (((!strncmp(rxDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 566 | ((!strncmp(curRxUCMDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 567 | (!strncmp(curRxUCMDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))) || |
| 568 | (((!strncmp(curRxUCMDevice, DEVICE_SPEAKER_HEADSET, strlen(DEVICE_SPEAKER_HEADSET))) && |
| 569 | ((!strncmp(rxDevice, DEVICE_HEADPHONES, strlen(DEVICE_HEADPHONES))) || |
| 570 | (!strncmp(rxDevice, DEVICE_HEADSET, strlen(DEVICE_HEADSET))))))) && |
| 571 | ((!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI, strlen(SND_USE_CASE_VERB_HIFI))) || |
| 572 | (!strncmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC, strlen(SND_USE_CASE_MOD_PLAY_MUSIC))))) { |
| 573 | s_open(handle); |
| 574 | pflag = false; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | if (rxDevice != NULL) { |
| 579 | free(rxDevice); |
| 580 | rxDevice = NULL; |
| 581 | } |
| 582 | if (txDevice != NULL) { |
| 583 | free(txDevice); |
| 584 | txDevice = NULL; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // ---------------------------------------------------------------------------- |
| 589 | |
| 590 | static status_t s_init(alsa_device_t *module, ALSAHandleList &list) |
| 591 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 592 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 593 | ALOGD("s_init: Initializing devices for ALSA module"); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 594 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 595 | |
| 596 | list.clear(); |
| 597 | |
| 598 | return NO_ERROR; |
| 599 | } |
| 600 | |
| 601 | static status_t s_open(alsa_handle_t *handle) |
| 602 | { |
| 603 | char *devName; |
| 604 | unsigned flags = 0; |
| 605 | int err = NO_ERROR; |
| 606 | |
| 607 | /* No need to call s_close for LPA as pcm device open and close is handled by LPAPlayer in stagefright */ |
| 608 | if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) |
| 609 | ||(!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] | 610 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 611 | ALOGD("s_open: Opening LPA /Tunnel playback"); |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 612 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 613 | return NO_ERROR; |
| 614 | } |
| 615 | |
| 616 | s_close(handle); |
| 617 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 618 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 619 | ALOGD("s_open: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 620 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 621 | |
| 622 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 623 | // the device to be opened |
| 624 | |
| 625 | // The PCM stream is opened in blocking mode, per ALSA defaults. The |
| 626 | // AudioFlinger seems to assume blocking mode too, so asynchronous mode |
| 627 | // should not be used. |
| 628 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI)) || |
| 629 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_MUSIC))) { |
| 630 | flags = PCM_OUT; |
| 631 | } else { |
| 632 | flags = PCM_IN; |
| 633 | } |
| 634 | if (handle->channels == 1) { |
| 635 | flags |= PCM_MONO; |
| 636 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 637 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 638 | else if (handle->channels == 4 ) { |
| 639 | flags |= PCM_QUAD; |
| 640 | } else if (handle->channels == 6 ) { |
| 641 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 642 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
| 643 | flags |= PCM_QUAD; |
| 644 | } else { |
| 645 | flags |= PCM_5POINT1; |
| 646 | } |
| 647 | } |
| 648 | #endif |
| 649 | else { |
| 650 | flags |= PCM_STEREO; |
| 651 | } |
| 652 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 653 | ALOGE("Failed to get pcm device node: %s", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 654 | return NO_INIT; |
| 655 | } |
| 656 | if (devName != NULL) { |
| 657 | handle->handle = pcm_open(flags, (char*)devName); |
| 658 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 659 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 660 | return NO_INIT; |
| 661 | } |
| 662 | |
| 663 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 664 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 665 | free(devName); |
| 666 | return NO_INIT; |
| 667 | } |
| 668 | |
| 669 | handle->handle->flags = flags; |
| 670 | err = setHardwareParams(handle); |
| 671 | |
| 672 | if (err == NO_ERROR) { |
| 673 | err = setSoftwareParams(handle); |
| 674 | } |
| 675 | |
| 676 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 677 | ALOGE("Set HW/SW params failed: Closing the pcm stream"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 678 | s_standby(handle); |
| 679 | } |
| 680 | |
| 681 | free(devName); |
| 682 | return NO_ERROR; |
| 683 | } |
| 684 | |
| 685 | static status_t s_start_voip_call(alsa_handle_t *handle) |
| 686 | { |
| 687 | |
| 688 | char* devName; |
| 689 | char* devName1; |
| 690 | unsigned flags = 0; |
| 691 | int err = NO_ERROR; |
| 692 | uint8_t voc_pkt[VOIP_BUFFER_MAX_SIZE]; |
| 693 | |
| 694 | s_close(handle); |
| 695 | flags = PCM_OUT; |
| 696 | flags |= PCM_MONO; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 697 | ALOGV("s_open:s_start_voip_call handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 698 | |
| 699 | if (deviceName(handle, flags, &devName) < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 700 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 701 | return NO_INIT; |
| 702 | } |
| 703 | |
| 704 | if (devName != NULL) { |
| 705 | handle->handle = pcm_open(flags, (char*)devName); |
| 706 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 707 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 708 | return NO_INIT; |
| 709 | } |
| 710 | |
| 711 | if (!handle->handle) { |
| 712 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 713 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 714 | return NO_INIT; |
| 715 | } |
| 716 | |
| 717 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 718 | ALOGE(" pcm ready failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | handle->handle->flags = flags; |
| 722 | err = setHardwareParams(handle); |
| 723 | |
| 724 | if (err == NO_ERROR) { |
| 725 | err = setSoftwareParams(handle); |
| 726 | } |
| 727 | |
| 728 | err = pcm_prepare(handle->handle); |
| 729 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 730 | ALOGE("DEVICE_OUT_DIRECTOUTPUT: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /* first write required start dsp */ |
| 734 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 735 | pcm_write(handle->handle,&voc_pkt,handle->handle->period_size); |
| 736 | handle->rxHandle = handle->handle; |
| 737 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 738 | ALOGV("s_open: DEVICE_IN_COMMUNICATION "); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 739 | flags = PCM_IN; |
| 740 | flags |= PCM_MONO; |
| 741 | handle->handle = 0; |
| 742 | |
| 743 | if (deviceName(handle, flags, &devName1) < 0) { |
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 | if (devName != NULL) { |
| 748 | handle->handle = pcm_open(flags, (char*)devName1); |
| 749 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 750 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 751 | return NO_INIT; |
| 752 | } |
| 753 | |
| 754 | if (!handle->handle) { |
| 755 | free(devName); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 756 | ALOGE("s_open: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 757 | return NO_INIT; |
| 758 | } |
| 759 | |
| 760 | if (!pcm_ready(handle->handle)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 761 | ALOGE(" pcm ready in failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | handle->handle->flags = flags; |
| 765 | |
| 766 | err = setHardwareParams(handle); |
| 767 | |
| 768 | if (err == NO_ERROR) { |
| 769 | err = setSoftwareParams(handle); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | err = pcm_prepare(handle->handle); |
| 774 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 775 | ALOGE("DEVICE_IN_COMMUNICATION: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /* first read required start dsp */ |
| 779 | memset(&voc_pkt,0,sizeof(voc_pkt)); |
| 780 | pcm_read(handle->handle,&voc_pkt,handle->handle->period_size); |
| 781 | return NO_ERROR; |
| 782 | } |
| 783 | |
| 784 | static status_t s_start_voice_call(alsa_handle_t *handle) |
| 785 | { |
| 786 | char* devName; |
| 787 | unsigned flags = 0; |
| 788 | int err = NO_ERROR; |
| 789 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 790 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 791 | ALOGD("s_start_voice_call: handle %p", handle); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 792 | #endif |
| 793 | |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 794 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 795 | // the device to be opened |
| 796 | |
| 797 | flags = PCM_OUT | PCM_MONO; |
| 798 | if (deviceName(handle, flags, &devName) < 0) { |
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 (devName != NULL) { |
| 803 | handle->handle = pcm_open(flags, (char*)devName); |
| 804 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 805 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 806 | return NO_INIT; |
| 807 | } |
| 808 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 809 | ALOGE("s_start_voicecall: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 810 | goto Error; |
| 811 | } |
| 812 | |
| 813 | handle->handle->flags = flags; |
| 814 | err = setHardwareParams(handle); |
| 815 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 816 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 817 | goto Error; |
| 818 | } |
| 819 | |
| 820 | err = setSoftwareParams(handle); |
| 821 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 822 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 823 | goto Error; |
| 824 | } |
| 825 | |
| 826 | err = pcm_prepare(handle->handle); |
| 827 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 828 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 829 | goto Error; |
| 830 | } |
| 831 | |
| 832 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 833 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 834 | goto Error; |
| 835 | } |
| 836 | |
| 837 | // Store the PCM playback device pointer in rxHandle |
| 838 | handle->rxHandle = handle->handle; |
| 839 | free(devName); |
| 840 | |
| 841 | // Open PCM capture device |
| 842 | flags = PCM_IN | PCM_MONO; |
| 843 | if (deviceName(handle, flags, &devName) < 0) { |
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 | goto Error; |
| 846 | } |
| 847 | if (devName != NULL) { |
| 848 | handle->handle = pcm_open(flags, (char*)devName); |
| 849 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 850 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 851 | return NO_INIT; |
| 852 | } |
| 853 | if (!handle->handle) { |
| 854 | free(devName); |
| 855 | goto Error; |
| 856 | } |
| 857 | |
| 858 | handle->handle->flags = flags; |
| 859 | err = setHardwareParams(handle); |
| 860 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 861 | ALOGE("s_start_voice_call: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 862 | goto Error; |
| 863 | } |
| 864 | |
| 865 | err = setSoftwareParams(handle); |
| 866 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 867 | ALOGE("s_start_voice_call: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 868 | goto Error; |
| 869 | } |
| 870 | |
| 871 | err = pcm_prepare(handle->handle); |
| 872 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 873 | ALOGE("s_start_voice_call: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 874 | goto Error; |
| 875 | } |
| 876 | |
| 877 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 878 | ALOGE("s_start_voice_call:SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 879 | goto Error; |
| 880 | } |
| 881 | |
| 882 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 883 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 884 | err = csd_client_start_voice(); |
| 885 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 886 | ALOGE("s_start_voice_call: csd_client error %d\n", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 887 | goto Error; |
| 888 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 889 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | free(devName); |
| 893 | return NO_ERROR; |
| 894 | |
| 895 | Error: |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 896 | ALOGE("s_start_voice_call: Failed to initialize ALSA device '%s'", devName); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 897 | free(devName); |
| 898 | s_close(handle); |
| 899 | return NO_INIT; |
| 900 | } |
| 901 | |
| 902 | static status_t s_start_fm(alsa_handle_t *handle) |
| 903 | { |
| 904 | char *devName; |
| 905 | unsigned flags = 0; |
| 906 | int err = NO_ERROR; |
| 907 | |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame^] | 908 | ALOGD("s_start_fm: handle %p", handle); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 909 | |
| 910 | // ASoC multicomponent requires a valid path (frontend/backend) for |
| 911 | // the device to be opened |
| 912 | |
| 913 | flags = PCM_OUT | PCM_STEREO; |
| 914 | if (deviceName(handle, flags, &devName) < 0) { |
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 | goto Error; |
| 917 | } |
| 918 | if (devName != NULL) { |
| 919 | handle->handle = pcm_open(flags, (char*)devName); |
| 920 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 921 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 922 | return NO_INIT; |
| 923 | } |
| 924 | if (!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 925 | ALOGE("s_start_fm: could not open PCM device"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 926 | goto Error; |
| 927 | } |
| 928 | |
| 929 | handle->handle->flags = flags; |
| 930 | err = setHardwareParams(handle); |
| 931 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 932 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 933 | goto Error; |
| 934 | } |
| 935 | |
| 936 | err = setSoftwareParams(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 | err = pcm_prepare(handle->handle); |
| 943 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 944 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 945 | goto Error; |
| 946 | } |
| 947 | |
| 948 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 949 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 950 | goto Error; |
| 951 | } |
| 952 | |
| 953 | // Store the PCM playback device pointer in rxHandle |
| 954 | handle->rxHandle = handle->handle; |
| 955 | free(devName); |
| 956 | |
| 957 | // Open PCM capture device |
| 958 | flags = PCM_IN | PCM_STEREO; |
| 959 | if (deviceName(handle, flags, &devName) < 0) { |
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 | goto Error; |
| 962 | } |
| 963 | if (devName != NULL) { |
| 964 | handle->handle = pcm_open(flags, (char*)devName); |
| 965 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 966 | ALOGE("Failed to get pcm device node"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 967 | return NO_INIT; |
| 968 | } |
| 969 | if (!handle->handle) { |
| 970 | goto Error; |
| 971 | } |
| 972 | |
| 973 | handle->handle->flags = flags; |
| 974 | err = setHardwareParams(handle); |
| 975 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 976 | ALOGE("s_start_fm: setHardwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 977 | goto Error; |
| 978 | } |
| 979 | |
| 980 | err = setSoftwareParams(handle); |
| 981 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 982 | ALOGE("s_start_fm: setSoftwareParams failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 983 | goto Error; |
| 984 | } |
| 985 | |
| 986 | err = pcm_prepare(handle->handle); |
| 987 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 988 | ALOGE("s_start_fm: pcm_prepare failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 989 | goto Error; |
| 990 | } |
| 991 | |
| 992 | if (ioctl(handle->handle->fd, SNDRV_PCM_IOCTL_START)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 993 | ALOGE("s_start_fm: SNDRV_PCM_IOCTL_START failed\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 994 | goto Error; |
| 995 | } |
| 996 | |
| 997 | s_set_fm_vol(fmVolume); |
| 998 | free(devName); |
| 999 | return NO_ERROR; |
| 1000 | |
| 1001 | Error: |
| 1002 | free(devName); |
| 1003 | s_close(handle); |
| 1004 | return NO_INIT; |
| 1005 | } |
| 1006 | |
| 1007 | static status_t s_set_fm_vol(int value) |
| 1008 | { |
| 1009 | status_t err = NO_ERROR; |
| 1010 | |
| 1011 | ALSAControl control("/dev/snd/controlC0"); |
| 1012 | control.set("Internal FM RX Volume",value,0); |
| 1013 | fmVolume = value; |
| 1014 | |
| 1015 | return err; |
| 1016 | } |
| 1017 | |
| 1018 | static status_t s_set_lpa_vol(int value) |
| 1019 | { |
| 1020 | status_t err = NO_ERROR; |
| 1021 | |
| 1022 | ALSAControl control("/dev/snd/controlC0"); |
| 1023 | control.set("LPA RX Volume",value,0); |
| 1024 | |
| 1025 | return err; |
| 1026 | } |
| 1027 | |
| 1028 | static status_t s_start(alsa_handle_t *handle) |
| 1029 | { |
| 1030 | status_t err = NO_ERROR; |
| 1031 | |
| 1032 | if(!handle->handle) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1033 | ALOGE("No active PCM driver to start"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1034 | return err; |
| 1035 | } |
| 1036 | |
| 1037 | err = pcm_prepare(handle->handle); |
| 1038 | |
| 1039 | return err; |
| 1040 | } |
| 1041 | |
| 1042 | static status_t s_close(alsa_handle_t *handle) |
| 1043 | { |
| 1044 | int ret; |
| 1045 | status_t err = NO_ERROR; |
| 1046 | struct pcm *h = handle->rxHandle; |
| 1047 | |
| 1048 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1049 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1050 | ALOGD("s_close: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1051 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1052 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1053 | ALOGV("s_close rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1054 | err = pcm_close(h); |
| 1055 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1056 | ALOGE("s_close: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | h = handle->handle; |
| 1061 | handle->handle = 0; |
| 1062 | |
| 1063 | if (h) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1064 | ALOGV("s_close handle h %p\n", h); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1065 | err = pcm_close(h); |
| 1066 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1067 | ALOGE("s_close: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | if ((!strcmp(handle->useCase, SND_USE_CASE_VERB_VOICECALL) || |
| 1071 | !strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_VOICE)) && |
| 1072 | platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1073 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1074 | err = csd_client_stop_voice(); |
| 1075 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1076 | ALOGE("s_close: csd_client error %d\n", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1077 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1078 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | disableDevice(handle); |
| 1082 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1083 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1084 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1085 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))){ |
| 1086 | disableDevice(handle); |
| 1087 | } |
| 1088 | |
| 1089 | return err; |
| 1090 | } |
| 1091 | |
| 1092 | /* |
| 1093 | this is same as s_close, but don't discard |
| 1094 | the device/mode info. This way we can still |
| 1095 | close the device, hit idle and power-save, reopen the pcm |
| 1096 | for the same device/mode after resuming |
| 1097 | */ |
| 1098 | static status_t s_standby(alsa_handle_t *handle) |
| 1099 | { |
| 1100 | int ret; |
| 1101 | status_t err = NO_ERROR; |
| 1102 | struct pcm *h = handle->rxHandle; |
| 1103 | handle->rxHandle = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1104 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1105 | ALOGD("s_standby: handle %p h %p", handle, h); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1106 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1107 | if (h) { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame^] | 1108 | ALOGD("s_standby rxHandle\n"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1109 | err = pcm_close(h); |
| 1110 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1111 | ALOGE("s_standby: pcm_close failed for rxHandle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | h = handle->handle; |
| 1116 | handle->handle = 0; |
| 1117 | |
| 1118 | if (h) { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1119 | #if LOCAL_LOGD |
| 1120 | ALOGD("s_standby handle h %p\n", h); |
| 1121 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1122 | err = pcm_close(h); |
| 1123 | if(err != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1124 | ALOGE("s_standby: pcm_close failed for handle with err %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1125 | } |
| 1126 | disableDevice(handle); |
| 1127 | } else if((!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1128 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1129 | (!strcmp(handle->useCase, SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1130 | (!strcmp(handle->useCase, SND_USE_CASE_MOD_PLAY_TUNNEL))) { |
| 1131 | disableDevice(handle); |
| 1132 | } |
| 1133 | |
| 1134 | return err; |
| 1135 | } |
| 1136 | |
| 1137 | static status_t s_route(alsa_handle_t *handle, uint32_t devices, int mode) |
| 1138 | { |
| 1139 | status_t status = NO_ERROR; |
| 1140 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1141 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1142 | ALOGD("s_route: devices 0x%x in mode %d", devices, mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1143 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1144 | callMode = mode; |
| 1145 | switchDevice(handle, devices, mode); |
| 1146 | return status; |
| 1147 | } |
| 1148 | |
| 1149 | int getUseCaseType(const char *useCase) |
| 1150 | { |
SathishKumar Mani | 0a01991 | 2012-09-11 12:33:11 -0700 | [diff] [blame^] | 1151 | ALOGD("use case is %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1152 | if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI, |
| 1153 | strlen(SND_USE_CASE_VERB_HIFI)) || |
| 1154 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_LOW_POWER, |
| 1155 | strlen(SND_USE_CASE_VERB_HIFI_LOW_POWER)) || |
| 1156 | !strncmp(useCase, SND_USE_CASE_VERB_HIFI_TUNNEL, |
| 1157 | strlen(SND_USE_CASE_VERB_HIFI_TUNNEL)) || |
| 1158 | !strncmp(useCase, SND_USE_CASE_VERB_DIGITAL_RADIO, |
| 1159 | strlen(SND_USE_CASE_VERB_DIGITAL_RADIO)) || |
| 1160 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_MUSIC, |
| 1161 | strlen(SND_USE_CASE_MOD_PLAY_MUSIC)) || |
| 1162 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_LPA, |
| 1163 | strlen(SND_USE_CASE_MOD_PLAY_LPA)) || |
| 1164 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_TUNNEL, |
| 1165 | strlen(SND_USE_CASE_MOD_PLAY_TUNNEL)) || |
| 1166 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_FM, |
| 1167 | strlen(SND_USE_CASE_MOD_PLAY_FM))) { |
| 1168 | return USECASE_TYPE_RX; |
| 1169 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_HIFI_REC, |
| 1170 | strlen(SND_USE_CASE_VERB_HIFI_REC)) || |
| 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)) || |
| 1177 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_FM, |
| 1178 | strlen(SND_USE_CASE_MOD_CAPTURE_FM)) || |
| 1179 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_A2DP_FM, |
| 1180 | strlen(SND_USE_CASE_MOD_CAPTURE_A2DP_FM))) { |
| 1181 | return USECASE_TYPE_TX; |
| 1182 | } else if (!strncmp(useCase, SND_USE_CASE_VERB_VOICECALL, |
| 1183 | strlen(SND_USE_CASE_VERB_VOICECALL)) || |
| 1184 | !strncmp(useCase, SND_USE_CASE_VERB_IP_VOICECALL, |
| 1185 | strlen(SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 1186 | !strncmp(useCase, SND_USE_CASE_VERB_DL_REC, |
| 1187 | strlen(SND_USE_CASE_VERB_DL_REC)) || |
| 1188 | !strncmp(useCase, SND_USE_CASE_VERB_UL_DL_REC, |
| 1189 | strlen(SND_USE_CASE_VERB_UL_DL_REC)) || |
| 1190 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOICE, |
| 1191 | strlen(SND_USE_CASE_MOD_PLAY_VOICE)) || |
| 1192 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOIP, |
| 1193 | strlen(SND_USE_CASE_MOD_PLAY_VOIP)) || |
| 1194 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_DL, |
| 1195 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_DL)) || |
| 1196 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL, |
| 1197 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL)) || |
| 1198 | !strncmp(useCase, SND_USE_CASE_MOD_CAPTURE_VOICE, |
| 1199 | strlen(SND_USE_CASE_MOD_CAPTURE_VOICE)) || |
| 1200 | !strncmp(useCase, SND_USE_CASE_VERB_VOLTE, |
| 1201 | strlen(SND_USE_CASE_VERB_VOLTE)) || |
| 1202 | !strncmp(useCase, SND_USE_CASE_MOD_PLAY_VOLTE, |
| 1203 | strlen(SND_USE_CASE_MOD_PLAY_VOLTE))) { |
| 1204 | return (USECASE_TYPE_RX | USECASE_TYPE_TX); |
| 1205 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1206 | ALOGE("unknown use case %s\n", useCase); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1207 | return 0; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static void disableDevice(alsa_handle_t *handle) |
| 1212 | { |
| 1213 | unsigned usecase_type = 0; |
| 1214 | int i, mods_size; |
| 1215 | char *useCase; |
| 1216 | const char **mods_list; |
| 1217 | |
| 1218 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1219 | if (useCase != NULL) { |
| 1220 | if (!strncmp(useCase, handle->useCase, MAX_UC_LEN)) { |
| 1221 | snd_use_case_set(handle->ucMgr, "_verb", SND_USE_CASE_VERB_INACTIVE); |
| 1222 | } else { |
| 1223 | snd_use_case_set(handle->ucMgr, "_dismod", handle->useCase); |
| 1224 | } |
| 1225 | free(useCase); |
| 1226 | snd_use_case_get(handle->ucMgr, "_verb", (const char **)&useCase); |
| 1227 | if (strncmp(useCase, SND_USE_CASE_VERB_INACTIVE, |
| 1228 | strlen(SND_USE_CASE_VERB_INACTIVE))) |
| 1229 | usecase_type |= getUseCaseType(useCase); |
| 1230 | mods_size = snd_use_case_get_list(handle->ucMgr, "_enamods", &mods_list); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1231 | #if LOCAL_LOGD |
| 1232 | ALOGD("Number of modifiers %d\n", mods_size); |
| 1233 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1234 | if (mods_size) { |
| 1235 | for(i = 0; i < mods_size; i++) { |
Ajay Dudani | 8a9785b | 2012-09-10 23:28:45 -0700 | [diff] [blame] | 1236 | #if LOCAL_LOGD |
| 1237 | ALOGD("index %d modifier %s\n", i, mods_list[i]); |
| 1238 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1239 | usecase_type |= getUseCaseType(mods_list[i]); |
| 1240 | } |
| 1241 | } |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1242 | #if LOCAL_LOGD |
| 1243 | ALOGD("usecase_type is %d\n", usecase_type); |
| 1244 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1245 | if (!(usecase_type & USECASE_TYPE_TX) && (strncmp(curTxUCMDevice, "None", 4))) |
| 1246 | snd_use_case_set(handle->ucMgr, "_disdev", curTxUCMDevice); |
| 1247 | if (!(usecase_type & USECASE_TYPE_RX) && (strncmp(curRxUCMDevice, "None", 4))) |
| 1248 | snd_use_case_set(handle->ucMgr, "_disdev", curRxUCMDevice); |
| 1249 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1250 | ALOGE("Invalid state, no valid use case found to disable"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1251 | } |
| 1252 | free(useCase); |
| 1253 | } |
| 1254 | |
| 1255 | char *getUCMDevice(uint32_t devices, int input, char *rxDevice) |
| 1256 | { |
| 1257 | if (!input) { |
| 1258 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1259 | (callMode == AudioSystem::MODE_IN_CALL) && |
| 1260 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1261 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1262 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1263 | || |
| 1264 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1265 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1266 | #endif |
| 1267 | if (mDevSettingsFlag & TTY_VCO) { |
| 1268 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_RX); |
| 1269 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1270 | return strdup(SND_USE_CASE_DEV_TTY_FULL_RX); |
| 1271 | } else if (mDevSettingsFlag & TTY_HCO) { |
| 1272 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_RX); /* HANDSET RX */ |
| 1273 | } |
| 1274 | }else if ((devices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET) || |
| 1275 | (devices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) { |
| 1276 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
| 1277 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1278 | ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1279 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE))) { |
| 1280 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1281 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1282 | } else { |
| 1283 | return strdup(SND_USE_CASE_DEV_SPEAKER_HEADSET); /* COMBO SPEAKER+HEADSET RX */ |
| 1284 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1285 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1286 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1287 | ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1288 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE))) { |
| 1289 | return strdup(SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET); /* COMBO SPEAKER+ANC HEADSET RX */ |
| 1290 | } else if ((devices & AudioSystem::DEVICE_OUT_SPEAKER) && |
| 1291 | (devices & AudioSystem::DEVICE_OUT_FM_TX)) { |
| 1292 | return strdup(SND_USE_CASE_DEV_SPEAKER_FM_TX); /* COMBO SPEAKER+FM_TX RX */ |
| 1293 | #endif |
| 1294 | } else if (devices & AudioSystem::DEVICE_OUT_EARPIECE) { |
| 1295 | return strdup(SND_USE_CASE_DEV_EARPIECE); /* HANDSET RX */ |
| 1296 | } else if (devices & AudioSystem::DEVICE_OUT_SPEAKER) { |
| 1297 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1298 | } else if ((devices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) || |
| 1299 | (devices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE)) { |
| 1300 | if (mDevSettingsFlag & ANC_FLAG) { |
| 1301 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1302 | } else { |
| 1303 | return strdup(SND_USE_CASE_DEV_HEADPHONES); /* HEADSET RX */ |
| 1304 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1305 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1306 | } else if ((devices & AudioSystem::DEVICE_OUT_ANC_HEADSET) || |
| 1307 | (devices & AudioSystem::DEVICE_OUT_ANC_HEADPHONE)) { |
| 1308 | return strdup(SND_USE_CASE_DEV_ANC_HEADSET); /* ANC HEADSET RX */ |
| 1309 | #endif |
| 1310 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO) || |
| 1311 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET) || |
| 1312 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT)) { |
| 1313 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1314 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_RX); /* BTSCO RX*/ |
| 1315 | else |
| 1316 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_RX); /* BTSCO RX*/ |
| 1317 | } else if ((devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP) || |
| 1318 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) || |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1319 | #ifdef QCOM_VOIP_ENABLED |
| 1320 | (devices & AudioSystem::DEVICE_OUT_DIRECTOUTPUT) || |
| 1321 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1322 | (devices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) { |
| 1323 | /* Nothing to be done, use current active device */ |
| 1324 | if (strncmp(curRxUCMDevice, "None", 4)) { |
| 1325 | return strdup(curRxUCMDevice); |
| 1326 | } |
| 1327 | } else if (devices & AudioSystem::DEVICE_OUT_AUX_DIGITAL) { |
| 1328 | return strdup(SND_USE_CASE_DEV_HDMI); /* HDMI RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1329 | #ifdef QCOM_PROXY_DEVICE_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1330 | } else if (devices & AudioSystem::DEVICE_OUT_PROXY) { |
| 1331 | return strdup(SND_USE_CASE_DEV_PROXY_RX); /* PROXY RX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1332 | #endif |
| 1333 | #ifdef QCOM_FM_TX_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1334 | } else if (devices & AudioSystem::DEVICE_OUT_FM_TX) { |
| 1335 | return strdup(SND_USE_CASE_DEV_FM_TX); /* FM Tx */ |
| 1336 | #endif |
| 1337 | } else if (devices & AudioSystem::DEVICE_OUT_DEFAULT) { |
| 1338 | return strdup(SND_USE_CASE_DEV_SPEAKER); /* SPEAKER RX */ |
| 1339 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1340 | ALOGD("No valid output device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1341 | } |
| 1342 | } else { |
| 1343 | if (!(mDevSettingsFlag & TTY_OFF) && |
| 1344 | (callMode == AudioSystem::MODE_IN_CALL) && |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1345 | ((devices & AudioSystem::DEVICE_IN_WIRED_HEADSET))) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1346 | #ifdef QCOM_ANC_HEADSET_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1347 | ||(devices & AudioSystem::DEVICE_IN_ANC_HEADSET))) { |
| 1348 | #endif |
| 1349 | if (mDevSettingsFlag & TTY_HCO) { |
| 1350 | return strdup(SND_USE_CASE_DEV_TTY_HEADSET_TX); |
| 1351 | } else if (mDevSettingsFlag & TTY_FULL) { |
| 1352 | return strdup(SND_USE_CASE_DEV_TTY_FULL_TX); |
| 1353 | } else if (mDevSettingsFlag & TTY_VCO) { |
| 1354 | if (!strncmp(mic_type, "analog", 6)) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1355 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_ANALOG_TX); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1356 | } else { |
| 1357 | return strdup(SND_USE_CASE_DEV_TTY_HANDSET_TX); |
| 1358 | } |
| 1359 | } |
| 1360 | } else if (devices & AudioSystem::DEVICE_IN_BUILTIN_MIC) { |
| 1361 | if (!strncmp(mic_type, "analog", 6)) { |
| 1362 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1363 | } else { |
| 1364 | if (mDevSettingsFlag & DMIC_FLAG) { |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1365 | #ifdef USES_FLUENCE_INCALL |
| 1366 | if(callMode == AudioSystem::MODE_IN_CALL) { |
| 1367 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1368 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1369 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1370 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1371 | } else { |
| 1372 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
| 1373 | } |
| 1374 | } |
| 1375 | #else |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1376 | if (((rxDevice != NULL) && |
| 1377 | !strncmp(rxDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1378 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) || |
| 1379 | !strncmp(curRxUCMDevice, SND_USE_CASE_DEV_SPEAKER, |
| 1380 | (strlen(SND_USE_CASE_DEV_SPEAKER)+1))) { |
| 1381 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1382 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1383 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1384 | return strdup(SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1385 | } |
| 1386 | } else { |
| 1387 | if (fluence_mode == FLUENCE_MODE_ENDFIRE) { |
| 1388 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE); /* DUALMIC EF TX */ |
| 1389 | } else if (fluence_mode == FLUENCE_MODE_BROADSIDE) { |
| 1390 | return strdup(SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE); /* DUALMIC BS TX */ |
| 1391 | } |
| 1392 | } |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1393 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1394 | } else if (mDevSettingsFlag & QMIC_FLAG){ |
| 1395 | return strdup(SND_USE_CASE_DEV_QUAD_MIC); |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1396 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1397 | #ifdef QCOM_SSR_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1398 | else if (mDevSettingsFlag & SSRQMIC_FLAG){ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1399 | ALOGV("return SSRQMIC_FLAG: 0x%x devices:0x%x",mDevSettingsFlag,devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1400 | // Mapping for quad mic input device. |
| 1401 | return strdup(SND_USE_CASE_DEV_SSR_QUAD_MIC); /* SSR Quad MIC */ |
ty.lee | 924f798 | 2012-08-01 23:15:30 +0900 | [diff] [blame] | 1402 | } |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1403 | #endif |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1404 | #ifdef SEPERATED_AUDIO_INPUT |
| 1405 | if(input_source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1406 | ALOGV("getUCMdevice returned the VOICE_RECOGNITION UCM by input source = %d", input_source); |
| 1407 | return strdup(SND_USE_CASE_DEV_VOICE_RECOGNITION ); /* VOICE RECOGNITION TX */ |
| 1408 | } else if(input_source == AUDIO_SOURCE_CAMCORDER) { |
| 1409 | ALOGV("getUCMdevice returned the Camcorder Tx UCM by input source = %d", input_source); |
| 1410 | return strdup(SND_USE_CASE_DEV_CAMCORDER_TX ); /* CAMCORDER TX */ |
| 1411 | } |
| 1412 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1413 | else { |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1414 | return strdup(SND_USE_CASE_DEV_HANDSET); /* BUILTIN-MIC TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | } else if (devices & AudioSystem::DEVICE_IN_AUX_DIGITAL) { |
| 1418 | return strdup(SND_USE_CASE_DEV_HDMI_TX); /* HDMI TX */ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1419 | #ifdef QCOM_ANC_HEADSET_ENABLED |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1420 | } else if (devices & AudioSystem::DEVICE_IN_ANC_HEADSET) { |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1421 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
| 1422 | #endif |
ehgrace.kim | 249f87d | 2012-08-12 20:40:32 -0700 | [diff] [blame] | 1423 | } else if (devices & AudioSystem::DEVICE_IN_WIRED_HEADSET) { |
| 1424 | return strdup(SND_USE_CASE_DEV_HEADSET); /* HEADSET TX */ |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1425 | } else if (devices & AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 1426 | if (btsco_samplerate == BTSCO_RATE_16KHZ) |
| 1427 | return strdup(SND_USE_CASE_DEV_BTSCO_WB_TX); /* BTSCO TX*/ |
| 1428 | else |
| 1429 | return strdup(SND_USE_CASE_DEV_BTSCO_NB_TX); /* BTSCO TX*/ |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1430 | #ifdef QCOM_USBAUDIO_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1431 | } else if ((devices & AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET) || |
| 1432 | (devices & AudioSystem::DEVICE_IN_PROXY)) { |
| 1433 | return strdup(SND_USE_CASE_DEV_PROXY_TX); /* PROXY TX */ |
| 1434 | #endif |
| 1435 | } else if ((devices & AudioSystem::DEVICE_IN_COMMUNICATION) || |
| 1436 | (devices & AudioSystem::DEVICE_IN_VOICE_CALL)) { |
| 1437 | /* Nothing to be done, use current active device */ |
| 1438 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1439 | return strdup(curTxUCMDevice); |
| 1440 | } |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1441 | #ifdef QCOM_FM_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1442 | } else if ((devices & AudioSystem::DEVICE_IN_FM_RX) || |
| 1443 | (devices & AudioSystem::DEVICE_IN_FM_RX_A2DP)) { |
| 1444 | /* Nothing to be done, use current tx device or set dummy device */ |
| 1445 | if (strncmp(curTxUCMDevice, "None", 4)) { |
| 1446 | return strdup(curTxUCMDevice); |
| 1447 | } else { |
| 1448 | return strdup(SND_USE_CASE_DEV_DUMMY_TX); |
| 1449 | } |
| 1450 | #endif |
| 1451 | } else if ((devices & AudioSystem::DEVICE_IN_AMBIENT) || |
| 1452 | (devices & AudioSystem::DEVICE_IN_BACK_MIC)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1453 | ALOGI("No proper mapping found with UCM device list, setting default"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1454 | if (!strncmp(mic_type, "analog", 6)) { |
| 1455 | return strdup(SND_USE_CASE_DEV_HANDSET); /* HANDSET TX */ |
| 1456 | } else { |
| 1457 | return strdup(SND_USE_CASE_DEV_LINE); /* BUILTIN-MIC TX */ |
| 1458 | } |
| 1459 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1460 | ALOGD("No valid input device: %u", devices); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | return NULL; |
| 1464 | } |
| 1465 | |
| 1466 | void s_set_voice_volume(int vol) |
| 1467 | { |
| 1468 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1469 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1470 | ALOGD("s_set_voice_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1471 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1472 | ALSAControl control("/dev/snd/controlC0"); |
| 1473 | control.set("Voice Rx Volume", vol, 0); |
| 1474 | |
| 1475 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1476 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1477 | err = csd_client_volume(vol); |
| 1478 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1479 | ALOGE("s_set_voice_volume: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1480 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1481 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | void s_set_volte_volume(int vol) |
| 1486 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1487 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1488 | ALOGD("s_set_volte_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1489 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1490 | ALSAControl control("/dev/snd/controlC0"); |
| 1491 | control.set("VoLTE Rx Volume", vol, 0); |
| 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | void s_set_voip_volume(int vol) |
| 1496 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1497 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1498 | ALOGD("s_set_voip_volume: volume %d", vol); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1499 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1500 | ALSAControl control("/dev/snd/controlC0"); |
| 1501 | control.set("Voip Rx Volume", vol, 0); |
| 1502 | } |
| 1503 | void s_set_mic_mute(int state) |
| 1504 | { |
| 1505 | int err = 0; |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1506 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1507 | ALOGD("s_set_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1508 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1509 | ALSAControl control("/dev/snd/controlC0"); |
| 1510 | control.set("Voice Tx Mute", state, 0); |
| 1511 | |
| 1512 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1513 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1514 | err = csd_client_mic_mute(state); |
| 1515 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1516 | ALOGE("s_set_mic_mute: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1517 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1518 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | void s_set_volte_mic_mute(int state) |
| 1522 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1523 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1524 | ALOGD("s_set_volte_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1525 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1526 | ALSAControl control("/dev/snd/controlC0"); |
| 1527 | control.set("VoLTE Tx Mute", state, 0); |
| 1528 | } |
| 1529 | |
| 1530 | void s_set_voip_mic_mute(int state) |
| 1531 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1532 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1533 | ALOGD("s_set_voip_mic_mute: state %d", state); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1534 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1535 | ALSAControl control("/dev/snd/controlC0"); |
| 1536 | control.set("Voip Tx Mute", state, 0); |
| 1537 | } |
| 1538 | |
| 1539 | void s_set_voip_config(int mode, int rate) |
| 1540 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1541 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1542 | ALOGD("s_set_voip_config: mode %d,rate %d", mode, rate); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1543 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1544 | ALSAControl control("/dev/snd/controlC0"); |
| 1545 | char** setValues; |
| 1546 | setValues = (char**)malloc(2*sizeof(char*)); |
| 1547 | if (setValues == NULL) { |
| 1548 | return; |
| 1549 | } |
| 1550 | setValues[0] = (char*)malloc(4*sizeof(char)); |
| 1551 | if (setValues[0] == NULL) { |
| 1552 | free(setValues); |
| 1553 | return; |
| 1554 | } |
| 1555 | |
| 1556 | setValues[1] = (char*)malloc(8*sizeof(char)); |
| 1557 | if (setValues[1] == NULL) { |
| 1558 | free(setValues); |
| 1559 | free(setValues[0]); |
| 1560 | return; |
| 1561 | } |
| 1562 | |
| 1563 | sprintf(setValues[0], "%d",mode); |
| 1564 | sprintf(setValues[1], "%d",rate); |
| 1565 | |
| 1566 | control.setext("Voip Mode Rate Config", 2, setValues); |
| 1567 | free(setValues[1]); |
| 1568 | free(setValues[0]); |
| 1569 | free(setValues); |
| 1570 | return; |
| 1571 | } |
| 1572 | |
| 1573 | void s_set_btsco_rate(int rate) |
| 1574 | { |
| 1575 | btsco_samplerate = rate; |
| 1576 | } |
| 1577 | |
| 1578 | void s_enable_wide_voice(bool flag) |
| 1579 | { |
| 1580 | int err = 0; |
| 1581 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1582 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1583 | ALOGD("s_enable_wide_voice: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1584 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1585 | ALSAControl control("/dev/snd/controlC0"); |
| 1586 | if(flag == true) { |
| 1587 | control.set("Widevoice Enable", 1, 0); |
| 1588 | } else { |
| 1589 | control.set("Widevoice Enable", 0, 0); |
| 1590 | } |
| 1591 | |
| 1592 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1593 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1594 | err == csd_client_wide_voice(flag); |
| 1595 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1596 | ALOGE("s_enable_wide_voice: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1597 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1598 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | void s_set_voc_rec_mode(uint8_t mode) |
| 1603 | { |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1604 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1605 | ALOGD("s_set_voc_rec_mode: mode %d", mode); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1606 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1607 | ALSAControl control("/dev/snd/controlC0"); |
| 1608 | control.set("Incall Rec Mode", mode, 0); |
| 1609 | } |
| 1610 | |
| 1611 | void s_enable_fens(bool flag) |
| 1612 | { |
| 1613 | int err = 0; |
| 1614 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1615 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1616 | ALOGD("s_enable_fens: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1617 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1618 | ALSAControl control("/dev/snd/controlC0"); |
| 1619 | if(flag == true) { |
| 1620 | control.set("FENS Enable", 1, 0); |
| 1621 | } else { |
| 1622 | control.set("FENS Enable", 0, 0); |
| 1623 | } |
| 1624 | |
| 1625 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1626 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1627 | err = csd_client_fens(flag); |
| 1628 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1629 | ALOGE("s_enable_fens: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1630 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1631 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | void s_enable_slow_talk(bool flag) |
| 1636 | { |
| 1637 | int err = 0; |
| 1638 | |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1639 | #if LOCAL_LOGD |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1640 | ALOGD("s_enable_slow_talk: flag %d", flag); |
Ajay Dudani | 86c852b | 2012-07-19 15:28:45 -0700 | [diff] [blame] | 1641 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1642 | ALSAControl control("/dev/snd/controlC0"); |
| 1643 | if(flag == true) { |
| 1644 | control.set("Slowtalk Enable", 1, 0); |
| 1645 | } else { |
| 1646 | control.set("Slowtalk Enable", 0, 0); |
| 1647 | } |
| 1648 | |
| 1649 | if (platform_is_Fusion3()) { |
Ajay Dudani | 9746c47 | 2012-06-18 16:01:16 -0700 | [diff] [blame] | 1650 | #ifdef QCOM_CSDCLIENT_ENABLED |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1651 | err = csd_client_slow_talk(flag); |
| 1652 | if (err < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1653 | ALOGE("s_enable_slow_talk: csd_client error %d", err); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1654 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1655 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void s_set_flags(uint32_t flags) |
| 1660 | { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame] | 1661 | ALOGV("s_set_flags: flags %d", flags); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1662 | mDevSettingsFlag = flags; |
| 1663 | } |
| 1664 | |
| 1665 | static status_t s_set_compressed_vol(int value) |
| 1666 | { |
| 1667 | status_t err = NO_ERROR; |
| 1668 | |
| 1669 | ALSAControl control("/dev/snd/controlC0"); |
| 1670 | control.set("COMPRESSED RX Volume",value,0); |
| 1671 | |
| 1672 | return err; |
| 1673 | } |
| 1674 | |
ty.lee | 74060de | 2012-08-02 00:47:00 +0900 | [diff] [blame] | 1675 | #ifdef SEPERATED_AUDIO_INPUT |
| 1676 | void s_setInput(int input) |
| 1677 | { |
| 1678 | input_source = input; |
| 1679 | ALOGD("s_setInput() : input_source = %d",input_source); |
| 1680 | } |
| 1681 | #endif |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1682 | } |