Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1 | /* |
vivek mehta | a51fd40 | 2016-02-04 19:49:33 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2016 The Android Open Source Project |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 16 | #define LOG_TAG "msm8974_platform" |
| 17 | /*#define LOG_NDEBUG 0*/ |
| 18 | #define LOG_NDDEBUG 0 |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <dlfcn.h> |
| 22 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 23 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
| 25 | #include <audio_hw.h> |
| 26 | #include <platform_api.h> |
| 27 | #include "platform.h" |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 28 | #include "audio_extn.h" |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 29 | #include <linux/msm_audio.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 30 | |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 31 | #define MIXER_XML_DEFAULT_PATH "/system/etc/mixer_paths.xml" |
| 32 | #define MIXER_XML_BASE_STRING "/system/etc/mixer_paths" |
| 33 | #define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card" |
| 34 | #define TOMTOM_MIXER_FILE_SUFFIX "wcd9330" |
| 35 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 36 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 37 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 38 | #define CVD_VERSION_MIXER_CTL "CVD Version" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 39 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 42 | * This file will have a maximum of 38 bytes: |
| 43 | * |
| 44 | * 4 bytes: number of audio blocks |
| 45 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 46 | * Maximum 10 * 3 bytes: SAD blocks |
| 47 | */ |
| 48 | #define MAX_SAD_BLOCKS 10 |
| 49 | #define SAD_BLOCK_SIZE 3 |
| 50 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 51 | #define MAX_CVD_VERSION_STRING_SIZE 100 |
| 52 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 53 | /* EDID format ID for LPCM audio */ |
| 54 | #define EDID_FORMAT_LPCM 1 |
| 55 | |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 56 | /* Retry for delay in FW loading*/ |
| 57 | #define RETRY_NUMBER 10 |
| 58 | #define RETRY_US 500000 |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 59 | #define MAX_SND_CARD 8 |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 60 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 61 | #define MAX_SND_CARD_NAME_LEN 31 |
| 62 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 63 | #define DEFAULT_APP_TYPE_RX_PATH 0x11130 |
| 64 | |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 65 | #define TOSTRING_(x) #x |
| 66 | #define TOSTRING(x) TOSTRING_(x) |
| 67 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 68 | struct audio_block_header |
| 69 | { |
| 70 | int reserved; |
| 71 | int length; |
| 72 | }; |
| 73 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 74 | enum { |
| 75 | CAL_MODE_SEND = 0x1, |
| 76 | CAL_MODE_PERSIST = 0x2, |
| 77 | CAL_MODE_RTAC = 0x4 |
| 78 | }; |
| 79 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 80 | #define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info" |
| 81 | |
| 82 | struct operator_info { |
| 83 | struct listnode list; |
| 84 | char *name; |
| 85 | char *mccmnc; |
| 86 | }; |
| 87 | |
| 88 | struct operator_specific_device { |
| 89 | struct listnode list; |
| 90 | char *operator; |
| 91 | char *mixer_path; |
| 92 | int acdb_id; |
| 93 | }; |
| 94 | |
| 95 | static struct listnode operator_info_list; |
| 96 | static struct listnode *operator_specific_device_table[SND_DEVICE_MAX]; |
| 97 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 98 | /* Audio calibration related functions */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 99 | typedef void (*acdb_deallocate_t)(); |
vivek mehta | c698f13 | 2016-02-25 18:50:35 -0800 | [diff] [blame] | 100 | typedef int (*acdb_init_v2_cvd_t)(char *, char *, int); |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 101 | typedef int (*acdb_init_v2_t)(char *); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 102 | typedef int (*acdb_init_t)(); |
| 103 | typedef void (*acdb_send_audio_cal_t)(int, int); |
| 104 | typedef void (*acdb_send_voice_cal_t)(int, int); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 105 | typedef int (*acdb_reload_vocvoltable_t)(int); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 106 | typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 107 | |
| 108 | /* Audio calibration related functions */ |
| 109 | struct platform_data { |
| 110 | struct audio_device *adev; |
| 111 | bool fluence_in_spkr_mode; |
| 112 | bool fluence_in_voice_call; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 113 | bool fluence_in_voice_comm; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 114 | bool fluence_in_voice_rec; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 115 | /* 0 = no fluence, 1 = fluence, 2 = fluence pro */ |
| 116 | int fluence_type; |
| 117 | int source_mic_type; |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 118 | bool speaker_lr_swap; |
| 119 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 120 | void *acdb_handle; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 121 | acdb_deallocate_t acdb_deallocate; |
| 122 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 123 | acdb_send_voice_cal_t acdb_send_voice_cal; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 124 | acdb_reload_vocvoltable_t acdb_reload_vocvoltable; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 125 | acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 126 | struct csd_data *csd; |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 127 | char ec_ref_mixer_path[64]; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 128 | |
| 129 | char *snd_card_name; |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 130 | int max_vol_index; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 131 | int max_mic_count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 134 | static int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 135 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 136 | DEEP_BUFFER_PCM_DEVICE}, |
| 137 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 138 | LOWLATENCY_PCM_DEVICE}, |
| 139 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE, |
| 140 | MULTIMEDIA2_PCM_DEVICE}, |
| 141 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE, |
| 142 | PLAYBACK_OFFLOAD_DEVICE}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 143 | [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE, |
| 144 | MULTIMEDIA2_PCM_DEVICE}, |
| 145 | [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, |
| 146 | MULTIMEDIA3_PCM_DEVICE}, |
| 147 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 148 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, |
| 149 | AUDIO_RECORD_PCM_DEVICE}, |
| 150 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 151 | LOWLATENCY_PCM_DEVICE}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 152 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 153 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, |
| 154 | VOICE_CALL_PCM_DEVICE}, |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 155 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 156 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 157 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
| 158 | [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE}, |
vivek mehta | a51fd40 | 2016-02-04 19:49:33 -0800 | [diff] [blame] | 159 | [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE, |
| 160 | VOICEMMODE1_CALL_PCM_DEVICE}, |
| 161 | [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE, |
| 162 | VOICEMMODE2_CALL_PCM_DEVICE}, |
| 163 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 164 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 165 | AUDIO_RECORD_PCM_DEVICE}, |
| 166 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 167 | AUDIO_RECORD_PCM_DEVICE}, |
| 168 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 169 | AUDIO_RECORD_PCM_DEVICE}, |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 170 | [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX}, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 171 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 172 | [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1}, |
| 173 | [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE}, |
| 174 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 175 | [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE, |
| 176 | AFE_PROXY_RECORD_PCM_DEVICE}, |
| 177 | [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE, |
| 178 | AFE_PROXY_RECORD_PCM_DEVICE}, |
zhaoyang yin | 4211fad | 2015-06-04 21:13:25 +0800 | [diff] [blame] | 179 | [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE}, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 180 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* Array to store sound devices */ |
| 184 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 185 | [SND_DEVICE_NONE] = "none", |
| 186 | /* Playback sound devices */ |
| 187 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 188 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 189 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 190 | [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 191 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 192 | [SND_DEVICE_OUT_LINE] = "line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 193 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 194 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones", |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 195 | [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line", |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 196 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 197 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 198 | [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 199 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 200 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 201 | [SND_DEVICE_OUT_VOICE_LINE] = "voice-line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 202 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 203 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 204 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 205 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 206 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
| 207 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 208 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 209 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 210 | [SND_DEVICE_OUT_VOICE_TX] = "voice-tx", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 211 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected", |
| 212 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected", |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 213 | [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 214 | |
| 215 | /* Capture sound devices */ |
| 216 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 217 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 218 | [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic", |
| 219 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic", |
| 220 | [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire", |
| 221 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire", |
| 222 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire", |
| 223 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire", |
| 224 | [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire", |
| 225 | |
| 226 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 227 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic", |
| 228 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic", |
| 229 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic", |
| 230 | [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire", |
| 231 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire", |
| 232 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire", |
| 233 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire", |
| 234 | [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire", |
| 235 | |
| 236 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 237 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 238 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 239 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 240 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 241 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 242 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 243 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 244 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 245 | |
| 246 | [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef", |
| 247 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus", |
| 248 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 249 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef", |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 250 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 251 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 252 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 253 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 254 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 255 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 256 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 257 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic", |
| 258 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef", |
| 259 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence", |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 260 | [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic", |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 261 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 262 | [SND_DEVICE_IN_UNPROCESSED_MIC] = "voice-rec-mic", |
| 263 | [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic", |
| 264 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 265 | [SND_DEVICE_IN_VOICE_RX] = "voice-rx", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 266 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 267 | [SND_DEVICE_IN_THREE_MIC] = "three-mic", |
| 268 | [SND_DEVICE_IN_QUAD_MIC] = "quad-mic", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 269 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback", |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 270 | [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic", |
| 271 | [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 275 | static int acdb_device_table[SND_DEVICE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 276 | [SND_DEVICE_NONE] = -1, |
| 277 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 278 | [SND_DEVICE_OUT_SPEAKER] = 15, |
| 279 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15, |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 280 | [SND_DEVICE_OUT_SPEAKER_SAFE] = 15, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 281 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 282 | [SND_DEVICE_OUT_LINE] = 77, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 283 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 284 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 285 | [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 286 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77, |
Ravi Kumar Alamanda | 235c348 | 2014-08-21 17:32:44 -0700 | [diff] [blame] | 287 | [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET, |
| 288 | [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER, |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 289 | [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 290 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 291 | [SND_DEVICE_OUT_VOICE_LINE] = 77, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 292 | [SND_DEVICE_OUT_HDMI] = 18, |
| 293 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15, |
| 294 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 295 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 296 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 297 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 298 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 299 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 300 | [SND_DEVICE_OUT_VOICE_TX] = 45, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 301 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124, |
| 302 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 303 | [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 304 | |
| 305 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 306 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106, |
| 307 | [SND_DEVICE_IN_HANDSET_MIC_NS] = 107, |
| 308 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108, |
| 309 | [SND_DEVICE_IN_HANDSET_DMIC] = 41, |
| 310 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109, |
| 311 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110, |
| 312 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111, |
| 313 | [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34, |
| 314 | |
| 315 | [SND_DEVICE_IN_SPEAKER_MIC] = 11, |
| 316 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112, |
| 317 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113, |
| 318 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114, |
| 319 | [SND_DEVICE_IN_SPEAKER_DMIC] = 43, |
| 320 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115, |
| 321 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116, |
| 322 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117, |
| 323 | [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35, |
| 324 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 325 | [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 326 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 327 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 328 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 329 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 330 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 331 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 332 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 333 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 334 | |
| 335 | [SND_DEVICE_IN_VOICE_DMIC] = 41, |
| 336 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS, |
| 337 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 338 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 339 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43, |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 340 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 341 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 342 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 343 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 344 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 345 | [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 346 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113, |
| 347 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35, |
| 348 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43, |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 349 | [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
| 350 | |
| 351 | [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC, |
| 352 | [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 353 | |
| 354 | [SND_DEVICE_IN_VOICE_RX] = 44, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 355 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 356 | [SND_DEVICE_IN_THREE_MIC] = 46, |
| 357 | [SND_DEVICE_IN_QUAD_MIC] = 46, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 358 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 359 | [SND_DEVICE_IN_HANDSET_TMIC] = 125, |
| 360 | [SND_DEVICE_IN_HANDSET_QMIC] = 125, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 363 | struct name_to_index { |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 364 | char name[100]; |
| 365 | unsigned int index; |
| 366 | }; |
| 367 | |
| 368 | #define TO_NAME_INDEX(X) #X, X |
| 369 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 370 | /* Used to get index from parsed string */ |
| 371 | static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { |
| 372 | /* out */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 373 | {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)}, |
| 374 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)}, |
| 375 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)}, |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 376 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 377 | {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)}, |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 378 | {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 379 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)}, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 380 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)}, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 381 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)}, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 382 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 383 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)}, |
| 384 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)}, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 385 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 386 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)}, |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 387 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 388 | {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)}, |
| 389 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)}, |
| 390 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)}, |
| 391 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 392 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)}, |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 393 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 394 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)}, |
| 395 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)}, |
| 396 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 397 | |
| 398 | /* in */ |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 399 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)}, |
| 400 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 401 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 402 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 403 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)}, |
| 404 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)}, |
| 405 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)}, |
| 406 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)}, |
| 407 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)}, |
| 408 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)}, |
| 409 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)}, |
| 410 | |
| 411 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 412 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 413 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)}, |
| 414 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)}, |
| 415 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)}, |
| 416 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)}, |
| 417 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)}, |
| 418 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)}, |
| 419 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)}, |
| 420 | |
| 421 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)}, |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 422 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 423 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 424 | {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)}, |
| 425 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)}, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 426 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 427 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)}, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 428 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 429 | {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 430 | |
| 431 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)}, |
| 432 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)}, |
| 433 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)}, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 434 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 435 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)}, |
| 436 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 437 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)}, |
| 438 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)}, |
| 439 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 440 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 441 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 442 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)}, |
| 443 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)}, |
| 444 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)}, |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 445 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)}, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 446 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 447 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)}, |
| 448 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)}, |
| 449 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 450 | {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)}, |
| 451 | {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)}, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 452 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)}, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 453 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)}, |
| 454 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 457 | static char * backend_tag_table[SND_DEVICE_MAX] = {0}; |
| 458 | static char * hw_interface_table[SND_DEVICE_MAX] = {0}; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 459 | |
| 460 | static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = { |
| 461 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)}, |
| 462 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)}, |
| 463 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)}, |
| 464 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 465 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)}, |
| 466 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 467 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD)}, |
| 468 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)}, |
| 469 | {TO_NAME_INDEX(USECASE_VOICE_CALL)}, |
| 470 | {TO_NAME_INDEX(USECASE_VOICE2_CALL)}, |
| 471 | {TO_NAME_INDEX(USECASE_VOLTE_CALL)}, |
| 472 | {TO_NAME_INDEX(USECASE_QCHAT_CALL)}, |
| 473 | {TO_NAME_INDEX(USECASE_VOWLAN_CALL)}, |
| 474 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)}, |
| 475 | {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)}, |
| 476 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)}, |
| 477 | {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 478 | }; |
| 479 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 480 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 481 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
| 482 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 483 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 484 | static bool is_tmus = false; |
| 485 | |
| 486 | static void check_operator() |
| 487 | { |
| 488 | char value[PROPERTY_VALUE_MAX]; |
| 489 | int mccmnc; |
| 490 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 491 | mccmnc = atoi(value); |
| 492 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
| 493 | switch(mccmnc) { |
| 494 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 495 | case 310490: |
| 496 | case 310260: |
| 497 | case 310026: |
sangwon.jeon | b891db5 | 2013-09-14 17:39:15 +0900 | [diff] [blame] | 498 | /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */ |
| 499 | case 310800: |
| 500 | case 310660: |
| 501 | case 310580: |
| 502 | case 310310: |
| 503 | case 310270: |
| 504 | case 310250: |
| 505 | case 310240: |
| 506 | case 310230: |
| 507 | case 310220: |
| 508 | case 310210: |
| 509 | case 310200: |
| 510 | case 310160: |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 511 | is_tmus = true; |
| 512 | break; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | bool is_operator_tmus() |
| 517 | { |
| 518 | pthread_once(&check_op_once_ctl, check_operator); |
| 519 | return is_tmus; |
| 520 | } |
| 521 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 522 | static char *get_current_operator() |
| 523 | { |
| 524 | struct listnode *node; |
| 525 | struct operator_info *info_item; |
| 526 | char mccmnc[PROPERTY_VALUE_MAX]; |
| 527 | char *ret = NULL; |
| 528 | |
| 529 | property_get("gsm.sim.operator.numeric",mccmnc,"0"); |
| 530 | |
| 531 | list_for_each(node, &operator_info_list) { |
| 532 | info_item = node_to_item(node, struct operator_info, list); |
| 533 | if (strstr(info_item->mccmnc, mccmnc) != NULL) { |
| 534 | ret = info_item->name; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | return ret; |
| 539 | } |
| 540 | |
| 541 | static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device) |
| 542 | { |
| 543 | struct listnode *node; |
| 544 | struct operator_specific_device *ret = NULL; |
| 545 | struct operator_specific_device *device_item; |
| 546 | char *operator_name; |
| 547 | |
| 548 | operator_name = get_current_operator(); |
| 549 | if (operator_name == NULL) |
| 550 | return ret; |
| 551 | |
| 552 | list_for_each(node, operator_specific_device_table[snd_device]) { |
| 553 | device_item = node_to_item(node, struct operator_specific_device, list); |
| 554 | if (strcmp(operator_name, device_item->operator) == 0) { |
| 555 | ret = device_item; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return ret; |
| 560 | } |
| 561 | |
| 562 | |
| 563 | static int get_operator_specific_device_acdb_id(snd_device_t snd_device) |
| 564 | { |
| 565 | struct operator_specific_device *device; |
| 566 | int ret = acdb_device_table[snd_device]; |
| 567 | |
| 568 | device = get_operator_specific_device(snd_device); |
| 569 | if (device != NULL) |
| 570 | ret = device->acdb_id; |
| 571 | |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device) |
| 576 | { |
| 577 | struct operator_specific_device *device; |
| 578 | const char *ret = device_table[snd_device]; |
| 579 | |
| 580 | device = get_operator_specific_device(snd_device); |
| 581 | if (device != NULL) |
| 582 | ret = device->mixer_path; |
| 583 | |
| 584 | return ret; |
| 585 | } |
| 586 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 587 | bool platform_send_gain_dep_cal(void *platform, int level) |
| 588 | { |
| 589 | bool ret_val = false; |
| 590 | struct platform_data *my_data = (struct platform_data *)platform; |
| 591 | struct audio_device *adev = my_data->adev; |
| 592 | int acdb_dev_id, app_type; |
| 593 | int acdb_dev_type = MSM_SNDDEV_CAP_RX; |
| 594 | int mode = CAL_MODE_RTAC; |
| 595 | struct listnode *node; |
| 596 | struct audio_usecase *usecase; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 597 | |
| 598 | if (my_data->acdb_send_gain_dep_cal == NULL) { |
| 599 | ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__); |
| 600 | return ret_val; |
| 601 | } |
| 602 | |
| 603 | if (!voice_is_in_call(adev)) { |
| 604 | ALOGV("%s: Not Voice call usecase, apply new cal for level %d", |
| 605 | __func__, level); |
| 606 | app_type = DEFAULT_APP_TYPE_RX_PATH; |
| 607 | |
| 608 | // find the current active sound device |
| 609 | list_for_each(node, &adev->usecase_list) { |
| 610 | usecase = node_to_item(node, struct audio_usecase, list); |
| 611 | |
| 612 | if (usecase != NULL && |
| 613 | usecase->type == PCM_PLAYBACK && |
| 614 | (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) { |
| 615 | |
| 616 | ALOGV("%s: out device is %d", __func__, usecase->out_snd_device); |
vivek mehta | 4cb8298 | 2015-07-13 12:05:49 -0700 | [diff] [blame] | 617 | if (audio_extn_spkr_prot_is_enabled()) { |
| 618 | acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device); |
| 619 | } else { |
| 620 | acdb_dev_id = acdb_device_table[usecase->out_snd_device]; |
| 621 | } |
| 622 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 623 | if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type, |
| 624 | acdb_dev_type, mode, level)) { |
| 625 | // set ret_val true if at least one calibration is set successfully |
| 626 | ret_val = true; |
| 627 | } else { |
| 628 | ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__); |
| 629 | } |
| 630 | } else { |
| 631 | ALOGW("%s: Usecase list is empty", __func__); |
| 632 | } |
| 633 | } |
| 634 | } else { |
| 635 | ALOGW("%s: Voice call in progress .. ignore setting new cal", |
| 636 | __func__); |
| 637 | } |
| 638 | return ret_val; |
| 639 | } |
| 640 | |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 641 | void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 642 | { |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 643 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 644 | snd_device_t snd_device = SND_DEVICE_NONE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 645 | |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 646 | if (strcmp(my_data->ec_ref_mixer_path, "")) { |
| 647 | ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path); |
| 648 | audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path); |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 651 | if (enable) { |
| 652 | strcpy(my_data->ec_ref_mixer_path, "echo-reference"); |
| 653 | if (out_device != AUDIO_DEVICE_NONE) { |
| 654 | snd_device = platform_get_output_snd_device(adev->platform, out_device); |
| 655 | platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device); |
| 656 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 657 | |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 658 | ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path); |
| 659 | audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path); |
| 660 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 663 | static struct csd_data *open_csd_client(bool i2s_ext_modem) |
| 664 | { |
| 665 | struct csd_data *csd = calloc(1, sizeof(struct csd_data)); |
| 666 | |
| 667 | csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 668 | if (csd->csd_client == NULL) { |
| 669 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 670 | goto error; |
| 671 | } else { |
| 672 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 673 | |
| 674 | csd->deinit = (deinit_t)dlsym(csd->csd_client, |
| 675 | "csd_client_deinit"); |
| 676 | if (csd->deinit == NULL) { |
| 677 | ALOGE("%s: dlsym error %s for csd_client_deinit", __func__, |
| 678 | dlerror()); |
| 679 | goto error; |
| 680 | } |
| 681 | csd->disable_device = (disable_device_t)dlsym(csd->csd_client, |
| 682 | "csd_client_disable_device"); |
| 683 | if (csd->disable_device == NULL) { |
| 684 | ALOGE("%s: dlsym error %s for csd_client_disable_device", |
| 685 | __func__, dlerror()); |
| 686 | goto error; |
| 687 | } |
| 688 | csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client, |
| 689 | "csd_client_enable_device_config"); |
| 690 | if (csd->enable_device_config == NULL) { |
| 691 | ALOGE("%s: dlsym error %s for csd_client_enable_device_config", |
| 692 | __func__, dlerror()); |
| 693 | goto error; |
| 694 | } |
| 695 | csd->enable_device = (enable_device_t)dlsym(csd->csd_client, |
| 696 | "csd_client_enable_device"); |
| 697 | if (csd->enable_device == NULL) { |
| 698 | ALOGE("%s: dlsym error %s for csd_client_enable_device", |
| 699 | __func__, dlerror()); |
| 700 | goto error; |
| 701 | } |
| 702 | csd->start_voice = (start_voice_t)dlsym(csd->csd_client, |
| 703 | "csd_client_start_voice"); |
| 704 | if (csd->start_voice == NULL) { |
| 705 | ALOGE("%s: dlsym error %s for csd_client_start_voice", |
| 706 | __func__, dlerror()); |
| 707 | goto error; |
| 708 | } |
| 709 | csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client, |
| 710 | "csd_client_stop_voice"); |
| 711 | if (csd->stop_voice == NULL) { |
| 712 | ALOGE("%s: dlsym error %s for csd_client_stop_voice", |
| 713 | __func__, dlerror()); |
| 714 | goto error; |
| 715 | } |
| 716 | csd->volume = (volume_t)dlsym(csd->csd_client, |
| 717 | "csd_client_volume"); |
| 718 | if (csd->volume == NULL) { |
| 719 | ALOGE("%s: dlsym error %s for csd_client_volume", |
| 720 | __func__, dlerror()); |
| 721 | goto error; |
| 722 | } |
| 723 | csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client, |
| 724 | "csd_client_mic_mute"); |
| 725 | if (csd->mic_mute == NULL) { |
| 726 | ALOGE("%s: dlsym error %s for csd_client_mic_mute", |
| 727 | __func__, dlerror()); |
| 728 | goto error; |
| 729 | } |
| 730 | csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client, |
| 731 | "csd_client_slow_talk"); |
| 732 | if (csd->slow_talk == NULL) { |
| 733 | ALOGE("%s: dlsym error %s for csd_client_slow_talk", |
| 734 | __func__, dlerror()); |
| 735 | goto error; |
| 736 | } |
| 737 | csd->start_playback = (start_playback_t)dlsym(csd->csd_client, |
| 738 | "csd_client_start_playback"); |
| 739 | if (csd->start_playback == NULL) { |
| 740 | ALOGE("%s: dlsym error %s for csd_client_start_playback", |
| 741 | __func__, dlerror()); |
| 742 | goto error; |
| 743 | } |
| 744 | csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client, |
| 745 | "csd_client_stop_playback"); |
| 746 | if (csd->stop_playback == NULL) { |
| 747 | ALOGE("%s: dlsym error %s for csd_client_stop_playback", |
| 748 | __func__, dlerror()); |
| 749 | goto error; |
| 750 | } |
| 751 | csd->start_record = (start_record_t)dlsym(csd->csd_client, |
| 752 | "csd_client_start_record"); |
| 753 | if (csd->start_record == NULL) { |
| 754 | ALOGE("%s: dlsym error %s for csd_client_start_record", |
| 755 | __func__, dlerror()); |
| 756 | goto error; |
| 757 | } |
| 758 | csd->stop_record = (stop_record_t)dlsym(csd->csd_client, |
| 759 | "csd_client_stop_record"); |
| 760 | if (csd->stop_record == NULL) { |
| 761 | ALOGE("%s: dlsym error %s for csd_client_stop_record", |
| 762 | __func__, dlerror()); |
| 763 | goto error; |
| 764 | } |
| 765 | |
| 766 | csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client, |
| 767 | "csd_client_get_sample_rate"); |
| 768 | if (csd->get_sample_rate == NULL) { |
| 769 | ALOGE("%s: dlsym error %s for csd_client_get_sample_rate", |
| 770 | __func__, dlerror()); |
| 771 | |
| 772 | goto error; |
| 773 | } |
| 774 | |
| 775 | csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init"); |
| 776 | |
| 777 | if (csd->init == NULL) { |
| 778 | ALOGE("%s: dlsym error %s for csd_client_init", |
| 779 | __func__, dlerror()); |
| 780 | goto error; |
| 781 | } else { |
| 782 | csd->init(i2s_ext_modem); |
| 783 | } |
| 784 | } |
| 785 | return csd; |
| 786 | |
| 787 | error: |
| 788 | free(csd); |
| 789 | csd = NULL; |
| 790 | return csd; |
| 791 | } |
| 792 | |
| 793 | void close_csd_client(struct csd_data *csd) |
| 794 | { |
| 795 | if (csd != NULL) { |
| 796 | csd->deinit(); |
| 797 | dlclose(csd->csd_client); |
| 798 | free(csd); |
| 799 | csd = NULL; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | static void platform_csd_init(struct platform_data *my_data) |
| 804 | { |
| 805 | #ifdef PLATFORM_MSM8084 |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 806 | int32_t modems, (*count_modems)(void); |
| 807 | const char *name = "libdetectmodem.so"; |
| 808 | const char *func = "count_modems"; |
| 809 | const char *error; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 810 | |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 811 | my_data->csd = NULL; |
| 812 | |
| 813 | void *lib = dlopen(name, RTLD_NOW); |
| 814 | error = dlerror(); |
| 815 | if (!lib) { |
| 816 | ALOGE("%s: could not find %s: %s", __func__, name, error); |
| 817 | return; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 818 | } |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 819 | |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 820 | count_modems = NULL; |
| 821 | *(void **)(&count_modems) = dlsym(lib, func); |
| 822 | error = dlerror(); |
| 823 | if (!count_modems) { |
| 824 | ALOGE("%s: could not find symbol %s in %s: %s", |
| 825 | __func__, func, name, error); |
| 826 | goto done; |
| 827 | } |
| 828 | |
| 829 | modems = count_modems(); |
| 830 | if (modems < 0) { |
| 831 | ALOGE("%s: count_modems failed\n", __func__); |
| 832 | goto done; |
| 833 | } |
| 834 | |
| 835 | ALOGD("%s: num_modems %d\n", __func__, modems); |
| 836 | if (modems > 0) |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 837 | my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/); |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 838 | |
| 839 | done: |
| 840 | dlclose(lib); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 841 | #else |
| 842 | my_data->csd = NULL; |
| 843 | #endif |
| 844 | } |
| 845 | |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 846 | static void set_platform_defaults(struct platform_data * my_data) |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 847 | { |
| 848 | int32_t dev; |
| 849 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 850 | backend_tag_table[dev] = NULL; |
| 851 | hw_interface_table[dev] = NULL; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 852 | operator_specific_device_table[dev] = NULL; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 855 | // To overwrite these go to the audio_platform_info.xml file. |
| 856 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco"); |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 857 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 858 | backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco"); |
| 859 | backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi"); |
| 860 | backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi"); |
| 861 | backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb"); |
| 862 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb"); |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 863 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 864 | backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy"); |
| 865 | backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy"); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 866 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 867 | hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 868 | hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX"); |
| 869 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX"); |
| 870 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX"); |
| 871 | hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 872 | hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX"); |
| 873 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 874 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 875 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 876 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 877 | hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 878 | hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 879 | hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX"); |
| 880 | hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 881 | hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX"); |
| 882 | hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX"); |
| 883 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX"); |
| 884 | hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX"); |
| 885 | hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX"); |
| 886 | hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX"); |
| 887 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 888 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 889 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 890 | hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX"); |
| 891 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX"); |
| 892 | hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX"); |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 893 | |
| 894 | my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 897 | void get_cvd_version(char *cvd_version, struct audio_device *adev) |
| 898 | { |
| 899 | struct mixer_ctl *ctl; |
| 900 | int count; |
| 901 | int ret = 0; |
| 902 | |
| 903 | ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL); |
| 904 | if (!ctl) { |
| 905 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL); |
| 906 | goto done; |
| 907 | } |
| 908 | mixer_ctl_update(ctl); |
| 909 | |
| 910 | count = mixer_ctl_get_num_values(ctl); |
| 911 | if (count > MAX_CVD_VERSION_STRING_SIZE) |
| 912 | count = MAX_CVD_VERSION_STRING_SIZE - 1; |
| 913 | |
| 914 | ret = mixer_ctl_get_array(ctl, cvd_version, count); |
| 915 | if (ret != 0) { |
| 916 | ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__); |
| 917 | goto done; |
| 918 | } |
| 919 | |
| 920 | done: |
| 921 | return; |
| 922 | } |
| 923 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 924 | void *platform_init(struct audio_device *adev) |
| 925 | { |
| 926 | char value[PROPERTY_VALUE_MAX]; |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 927 | struct platform_data *my_data = NULL; |
| 928 | int retry_num = 0, snd_card_num = 0, key = 0, ret = 0; |
| 929 | bool dual_mic_config = false, use_default_mixer_path = true; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 930 | const char *snd_card_name; |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 931 | char *cvd_version = NULL; |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 932 | char *snd_internal_name = NULL; |
| 933 | char *tmp = NULL; |
| 934 | char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0}; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 935 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 936 | my_data = calloc(1, sizeof(struct platform_data)); |
| 937 | |
| 938 | my_data->adev = adev; |
| 939 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 940 | list_init(&operator_info_list); |
| 941 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 942 | set_platform_defaults(my_data); |
| 943 | |
| 944 | /* Initialize platform specific ids and/or backends*/ |
| 945 | platform_info_init(my_data); |
| 946 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 947 | while (snd_card_num < MAX_SND_CARD) { |
| 948 | adev->mixer = mixer_open(snd_card_num); |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 949 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 950 | while (!adev->mixer && retry_num < RETRY_NUMBER) { |
| 951 | usleep(RETRY_US); |
| 952 | adev->mixer = mixer_open(snd_card_num); |
| 953 | retry_num++; |
| 954 | } |
| 955 | |
| 956 | if (!adev->mixer) { |
| 957 | ALOGE("%s: Unable to open the mixer card: %d", __func__, |
| 958 | snd_card_num); |
| 959 | retry_num = 0; |
| 960 | snd_card_num++; |
| 961 | continue; |
| 962 | } |
| 963 | |
| 964 | snd_card_name = mixer_get_name(adev->mixer); |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 965 | |
| 966 | /* validate the sound card name */ |
| 967 | if (my_data->snd_card_name != NULL && |
| 968 | strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) { |
| 969 | ALOGI("%s: found valid sound card %s, but not primary sound card %s", |
| 970 | __func__, snd_card_name, my_data->snd_card_name); |
| 971 | retry_num = 0; |
| 972 | snd_card_num++; |
| 973 | continue; |
| 974 | } |
| 975 | |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 976 | if ((snd_internal_name = strtok_r(snd_card_name, "-", &tmp)) != NULL) { |
| 977 | /* Get the codec internal name from the sound card name |
| 978 | * and form the mixer paths file name dynamically. This |
| 979 | * is generic way of picking any codec name based mixer |
| 980 | * files in future with no code change. This code |
| 981 | * assumes mixer files are formed with format as |
| 982 | * mixer_paths_internalcodecname.xml |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 983 | |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 984 | * If this dynamically read mixer files fails to open then it |
| 985 | * falls back to default mixer file i.e mixer_paths.xml. This is |
| 986 | * done to preserve backward compatibility but not mandatory as |
| 987 | * long as the mixer files are named as per above assumption. |
| 988 | */ |
| 989 | |
| 990 | if ((snd_internal_name = strtok_r(NULL, "-", &tmp)) != NULL) { |
| 991 | // need to carryforward old file name |
| 992 | if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME, |
| 993 | sizeof(TOMTOM_8226_SND_CARD_NAME))) { |
| 994 | snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml", |
| 995 | MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX ); |
| 996 | } else { |
| 997 | snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml", |
| 998 | MIXER_XML_BASE_STRING, snd_internal_name); |
| 999 | } |
| 1000 | |
| 1001 | if (F_OK == access(mixer_xml_file, 0)) { |
| 1002 | use_default_mixer_path = false; |
| 1003 | } |
| 1004 | } |
Uday Kishore Pasupuleti | 11dd223 | 2015-06-24 14:18:01 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame^] | 1007 | if (use_default_mixer_path) { |
| 1008 | memset(mixer_xml_file, 0, sizeof(mixer_xml_file)); |
| 1009 | strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH); |
| 1010 | } |
| 1011 | |
| 1012 | ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file); |
| 1013 | adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file); |
| 1014 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1015 | if (!adev->audio_route) { |
| 1016 | ALOGE("%s: Failed to init audio route controls, aborting.", __func__); |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1017 | goto init_failed; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1018 | } |
| 1019 | adev->snd_card = snd_card_num; |
| 1020 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 1021 | break; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1024 | if (snd_card_num >= MAX_SND_CARD) { |
| 1025 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1026 | goto init_failed; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 1027 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1028 | |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 1029 | //set max volume step for voice call |
| 1030 | property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX)); |
| 1031 | my_data->max_vol_index = atoi(value); |
| 1032 | |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1033 | property_get("persist.audio.dualmic.config",value,""); |
| 1034 | if (!strcmp("endfire", value)) { |
| 1035 | dual_mic_config = true; |
| 1036 | } |
| 1037 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1038 | my_data->source_mic_type = SOURCE_DUAL_MIC; |
| 1039 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1040 | my_data->fluence_in_spkr_mode = false; |
| 1041 | my_data->fluence_in_voice_call = false; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1042 | my_data->fluence_in_voice_comm = false; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1043 | my_data->fluence_in_voice_rec = false; |
| 1044 | |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1045 | property_get("ro.qc.sdk.audio.fluencetype", value, "none"); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1046 | if (!strcmp("fluencepro", value)) { |
| 1047 | my_data->fluence_type = FLUENCE_PRO_ENABLE; |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1048 | } else if (!strcmp("fluence", value) || (dual_mic_config)) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1049 | my_data->fluence_type = FLUENCE_ENABLE; |
| 1050 | } else if (!strcmp("none", value)) { |
| 1051 | my_data->fluence_type = FLUENCE_DISABLE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1054 | if (my_data->fluence_type != FLUENCE_DISABLE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1055 | property_get("persist.audio.fluence.voicecall",value,""); |
| 1056 | if (!strcmp("true", value)) { |
| 1057 | my_data->fluence_in_voice_call = true; |
| 1058 | } |
| 1059 | |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1060 | property_get("persist.audio.fluence.voicecomm",value,""); |
| 1061 | if (!strcmp("true", value)) { |
| 1062 | my_data->fluence_in_voice_comm = true; |
| 1063 | } |
| 1064 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1065 | property_get("persist.audio.fluence.voicerec",value,""); |
| 1066 | if (!strcmp("true", value)) { |
| 1067 | my_data->fluence_in_voice_rec = true; |
| 1068 | } |
| 1069 | |
| 1070 | property_get("persist.audio.fluence.speaker",value,""); |
| 1071 | if (!strcmp("true", value)) { |
| 1072 | my_data->fluence_in_spkr_mode = true; |
| 1073 | } |
| 1074 | } |
| 1075 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1076 | // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic |
| 1077 | switch (my_data->max_mic_count) { |
| 1078 | case 4: |
| 1079 | my_data->source_mic_type |= SOURCE_QUAD_MIC; |
| 1080 | case 3: |
| 1081 | my_data->source_mic_type |= SOURCE_THREE_MIC; |
| 1082 | case 2: |
| 1083 | my_data->source_mic_type |= SOURCE_DUAL_MIC; |
| 1084 | case 1: |
| 1085 | my_data->source_mic_type |= SOURCE_MONO_MIC; |
| 1086 | break; |
| 1087 | default: |
| 1088 | ALOGE("%s: max_mic_count (%d), is not supported, setting to default", |
| 1089 | __func__, my_data->max_mic_count); |
| 1090 | my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC; |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)" |
| 1095 | " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ", |
| 1096 | __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type, |
| 1097 | my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm, |
| 1098 | my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode); |
| 1099 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1100 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 1101 | if (my_data->acdb_handle == NULL) { |
| 1102 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 1103 | } else { |
| 1104 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 1105 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 1106 | "acdb_loader_deallocate_ACDB"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1107 | if (!my_data->acdb_deallocate) |
| 1108 | ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s", |
| 1109 | __func__, LIB_ACDB_LOADER); |
| 1110 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1111 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 1112 | "acdb_loader_send_audio_cal"); |
| 1113 | if (!my_data->acdb_send_audio_cal) |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1114 | ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1115 | __func__, LIB_ACDB_LOADER); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1116 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1117 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 1118 | "acdb_loader_send_voice_cal"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1119 | if (!my_data->acdb_send_voice_cal) |
| 1120 | ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s", |
| 1121 | __func__, LIB_ACDB_LOADER); |
| 1122 | |
| 1123 | my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle, |
| 1124 | "acdb_loader_reload_vocvoltable"); |
| 1125 | if (!my_data->acdb_reload_vocvoltable) |
| 1126 | ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s", |
| 1127 | __func__, LIB_ACDB_LOADER); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 1128 | |
| 1129 | my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle, |
| 1130 | "acdb_loader_send_gain_dep_cal"); |
| 1131 | if (!my_data->acdb_send_gain_dep_cal) |
| 1132 | ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s", |
| 1133 | __func__, LIB_ACDB_LOADER); |
| 1134 | |
vivek mehta | c698f13 | 2016-02-25 18:50:35 -0800 | [diff] [blame] | 1135 | #if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1136 | acdb_init_v2_cvd_t acdb_init; |
| 1137 | acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle, |
| 1138 | "acdb_loader_init_v2"); |
| 1139 | if (acdb_init == NULL) { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1140 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1141 | goto acdb_init_fail; |
| 1142 | } |
| 1143 | |
| 1144 | cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE); |
| 1145 | get_cvd_version(cvd_version, adev); |
| 1146 | if (!cvd_version) |
| 1147 | ALOGE("failed to allocate cvd_version"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1148 | else |
vivek mehta | c698f13 | 2016-02-25 18:50:35 -0800 | [diff] [blame] | 1149 | acdb_init((char *)snd_card_name, cvd_version, 0); |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1150 | free(cvd_version); |
| 1151 | #elif defined (PLATFORM_MSM8084) |
| 1152 | acdb_init_v2_t acdb_init; |
| 1153 | acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle, |
| 1154 | "acdb_loader_init_v2"); |
| 1155 | if (acdb_init == NULL) { |
| 1156 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); |
| 1157 | goto acdb_init_fail; |
| 1158 | } |
| 1159 | acdb_init((char *)snd_card_name); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1160 | #else |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1161 | acdb_init_t acdb_init; |
| 1162 | acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1163 | "acdb_loader_init_ACDB"); |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1164 | if (acdb_init == NULL) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1165 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); |
| 1166 | else |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1167 | acdb_init(); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1168 | #endif |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1171 | acdb_init_fail: |
| 1172 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1173 | audio_extn_spkr_prot_init(adev); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1174 | |
Ravi Kumar Alamanda | 7631557 | 2015-04-23 13:13:56 -0700 | [diff] [blame] | 1175 | audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle); |
| 1176 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1177 | /* load csd client */ |
| 1178 | platform_csd_init(my_data); |
| 1179 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1180 | return my_data; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1181 | |
| 1182 | init_failed: |
| 1183 | if (my_data) |
| 1184 | free(my_data); |
| 1185 | return NULL; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | void platform_deinit(void *platform) |
| 1189 | { |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1190 | int32_t dev; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1191 | struct operator_info *info_item; |
| 1192 | struct operator_specific_device *device_item; |
| 1193 | struct listnode *node; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1194 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1195 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1196 | close_csd_client(my_data->csd); |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1197 | |
| 1198 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 1199 | if (backend_tag_table[dev]) |
| 1200 | free(backend_tag_table[dev]); |
| 1201 | if (hw_interface_table[dev]) |
| 1202 | free(hw_interface_table[dev]); |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1203 | if (operator_specific_device_table[dev]) { |
| 1204 | while (!list_empty(operator_specific_device_table[dev])) { |
| 1205 | node = list_head(operator_specific_device_table[dev]); |
| 1206 | list_remove(node); |
| 1207 | device_item = node_to_item(node, struct operator_specific_device, list); |
| 1208 | free(device_item->operator); |
| 1209 | free(device_item->mixer_path); |
| 1210 | free(device_item); |
| 1211 | } |
| 1212 | free(operator_specific_device_table[dev]); |
| 1213 | } |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (my_data->snd_card_name) |
| 1217 | free(my_data->snd_card_name); |
| 1218 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1219 | while (!list_empty(&operator_info_list)) { |
| 1220 | node = list_head(&operator_info_list); |
| 1221 | list_remove(node); |
| 1222 | info_item = node_to_item(node, struct operator_info, list); |
| 1223 | free(info_item->name); |
| 1224 | free(info_item->mccmnc); |
| 1225 | free(info_item); |
| 1226 | } |
| 1227 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1228 | free(platform); |
| 1229 | } |
| 1230 | |
| 1231 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 1232 | { |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1233 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 1234 | if (operator_specific_device_table[snd_device] != NULL) { |
| 1235 | return get_operator_specific_device_mixer_path(snd_device); |
| 1236 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1237 | return device_table[snd_device]; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1238 | } else |
Ravi Kumar Alamanda | 6402646 | 2014-09-15 00:08:58 -0700 | [diff] [blame] | 1239 | return "none"; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1242 | void platform_add_backend_name(void *platform, char *mixer_path, |
| 1243 | snd_device_t snd_device) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1244 | { |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1245 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1246 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1247 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1248 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1249 | return; |
Ravi Kumar Alamanda | 1de6e5a | 2014-06-19 21:55:39 -0500 | [diff] [blame] | 1250 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1251 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1252 | const char * suffix = backend_tag_table[snd_device]; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1253 | |
| 1254 | if (suffix != NULL) { |
| 1255 | strcat(mixer_path, " "); |
| 1256 | strcat(mixer_path, suffix); |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1257 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1260 | bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2) |
| 1261 | { |
| 1262 | bool result = true; |
| 1263 | |
| 1264 | ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__, |
| 1265 | platform_get_snd_device_name(snd_device1), |
| 1266 | platform_get_snd_device_name(snd_device2)); |
| 1267 | |
| 1268 | if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) { |
| 1269 | ALOGE("%s: Invalid snd_device = %s", __func__, |
| 1270 | platform_get_snd_device_name(snd_device1)); |
| 1271 | return false; |
| 1272 | } |
| 1273 | if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) { |
| 1274 | ALOGE("%s: Invalid snd_device = %s", __func__, |
| 1275 | platform_get_snd_device_name(snd_device2)); |
| 1276 | return false; |
| 1277 | } |
| 1278 | const char * be_itf1 = hw_interface_table[snd_device1]; |
| 1279 | const char * be_itf2 = hw_interface_table[snd_device2]; |
| 1280 | |
| 1281 | if (NULL != be_itf1 && NULL != be_itf2) { |
Eric Laurent | e63e61d | 2015-09-10 12:19:33 -0700 | [diff] [blame] | 1282 | if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2))) |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1283 | result = false; |
| 1284 | } |
| 1285 | |
| 1286 | ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result); |
| 1287 | return result; |
| 1288 | } |
| 1289 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1290 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 1291 | { |
| 1292 | int device_id; |
| 1293 | if (device_type == PCM_PLAYBACK) |
| 1294 | device_id = pcm_device_table[usecase][0]; |
| 1295 | else |
| 1296 | device_id = pcm_device_table[usecase][1]; |
| 1297 | return device_id; |
| 1298 | } |
| 1299 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1300 | static int find_index(const struct name_to_index * table, int32_t len, |
| 1301 | const char * name) |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1302 | { |
| 1303 | int ret = 0; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1304 | int32_t i; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1305 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1306 | if (table == NULL) { |
| 1307 | ALOGE("%s: table is NULL", __func__); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1308 | ret = -ENODEV; |
| 1309 | goto done; |
| 1310 | } |
| 1311 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1312 | if (name == NULL) { |
| 1313 | ALOGE("null key"); |
| 1314 | ret = -ENODEV; |
| 1315 | goto done; |
| 1316 | } |
| 1317 | |
| 1318 | for (i=0; i < len; i++) { |
| 1319 | if (!strcmp(table[i].name, name)) { |
| 1320 | ret = table[i].index; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1321 | goto done; |
| 1322 | } |
| 1323 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1324 | ALOGE("%s: Could not find index for name = %s", |
| 1325 | __func__, name); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1326 | ret = -ENODEV; |
| 1327 | done: |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1331 | int platform_get_snd_device_index(char *device_name) |
| 1332 | { |
| 1333 | return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name); |
| 1334 | } |
| 1335 | |
| 1336 | int platform_get_usecase_index(const char *usecase_name) |
| 1337 | { |
| 1338 | return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name); |
| 1339 | } |
| 1340 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1341 | void platform_add_operator_specific_device(snd_device_t snd_device, |
| 1342 | const char *operator, |
| 1343 | const char *mixer_path, |
| 1344 | unsigned int acdb_id) |
| 1345 | { |
| 1346 | struct operator_specific_device *device; |
| 1347 | |
| 1348 | if (operator_specific_device_table[snd_device] == NULL) { |
| 1349 | operator_specific_device_table[snd_device] = |
| 1350 | (struct listnode *)calloc(1, sizeof(struct listnode)); |
| 1351 | list_init(operator_specific_device_table[snd_device]); |
| 1352 | } |
| 1353 | |
| 1354 | device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device)); |
| 1355 | |
| 1356 | device->operator = strdup(operator); |
| 1357 | device->mixer_path = strdup(mixer_path); |
| 1358 | device->acdb_id = acdb_id; |
| 1359 | |
| 1360 | list_add_tail(operator_specific_device_table[snd_device], &device->list); |
| 1361 | |
| 1362 | ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__, |
| 1363 | platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id); |
| 1364 | |
| 1365 | } |
| 1366 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1367 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id) |
| 1368 | { |
| 1369 | int ret = 0; |
| 1370 | |
| 1371 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1372 | ALOGE("%s: Invalid snd_device = %d", |
| 1373 | __func__, snd_device); |
| 1374 | ret = -EINVAL; |
| 1375 | goto done; |
| 1376 | } |
| 1377 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1378 | ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__, |
| 1379 | platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1380 | acdb_device_table[snd_device] = acdb_id; |
| 1381 | done: |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1385 | int platform_get_snd_device_acdb_id(snd_device_t snd_device) |
| 1386 | { |
| 1387 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1388 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1389 | return -EINVAL; |
| 1390 | } |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1391 | |
| 1392 | if (operator_specific_device_table[snd_device] != NULL) |
| 1393 | return get_operator_specific_device_acdb_id(snd_device); |
| 1394 | else |
| 1395 | return acdb_device_table[snd_device]; |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1398 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 1399 | { |
| 1400 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1401 | int acdb_dev_id, acdb_dev_type; |
| 1402 | |
Ravi Kumar Alamanda | adf0f3b | 2015-06-04 02:34:02 -0700 | [diff] [blame] | 1403 | acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)]; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1404 | if (acdb_dev_id < 0) { |
| 1405 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 1406 | __func__, snd_device); |
| 1407 | return -EINVAL; |
| 1408 | } |
| 1409 | if (my_data->acdb_send_audio_cal) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1410 | ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1411 | __func__, snd_device, acdb_dev_id); |
| 1412 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 1413 | snd_device < SND_DEVICE_OUT_END) |
| 1414 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 1415 | else |
| 1416 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 1417 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 1418 | } |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | int platform_switch_voice_call_device_pre(void *platform) |
| 1423 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1424 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1425 | int ret = 0; |
| 1426 | |
| 1427 | if (my_data->csd != NULL && |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1428 | voice_is_in_call(my_data->adev)) { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1429 | /* This must be called before disabling mixer controls on APQ side */ |
| 1430 | ret = my_data->csd->disable_device(); |
| 1431 | if (ret < 0) { |
| 1432 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 1433 | __func__, ret); |
| 1434 | } |
| 1435 | } |
| 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | int platform_switch_voice_call_enable_device_config(void *platform, |
| 1440 | snd_device_t out_snd_device, |
| 1441 | snd_device_t in_snd_device) |
| 1442 | { |
| 1443 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1444 | int acdb_rx_id, acdb_tx_id; |
| 1445 | int ret = 0; |
| 1446 | |
| 1447 | if (my_data->csd == NULL) |
| 1448 | return ret; |
| 1449 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1450 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1451 | audio_extn_spkr_prot_is_enabled()) |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1452 | acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1453 | else |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1454 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1455 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1456 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1457 | |
| 1458 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1459 | ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id); |
| 1460 | if (ret < 0) { |
| 1461 | ALOGE("%s: csd_enable_device_config, failed, error %d", |
| 1462 | __func__, ret); |
| 1463 | } |
| 1464 | } else { |
| 1465 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1466 | acdb_rx_id, acdb_tx_id); |
| 1467 | } |
| 1468 | |
| 1469 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | int platform_switch_voice_call_device_post(void *platform, |
| 1473 | snd_device_t out_snd_device, |
| 1474 | snd_device_t in_snd_device) |
| 1475 | { |
| 1476 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1477 | int acdb_rx_id, acdb_tx_id; |
| 1478 | |
| 1479 | if (my_data->acdb_send_voice_cal == NULL) { |
| 1480 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 1481 | } else { |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1482 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1483 | audio_extn_spkr_prot_is_enabled()) |
| 1484 | out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED; |
| 1485 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1486 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
| 1487 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1488 | |
| 1489 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 1490 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 1491 | else |
| 1492 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1493 | acdb_rx_id, acdb_tx_id); |
| 1494 | } |
| 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1499 | int platform_switch_voice_call_usecase_route_post(void *platform, |
| 1500 | snd_device_t out_snd_device, |
| 1501 | snd_device_t in_snd_device) |
| 1502 | { |
| 1503 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1504 | int acdb_rx_id, acdb_tx_id; |
| 1505 | int ret = 0; |
| 1506 | |
| 1507 | if (my_data->csd == NULL) |
| 1508 | return ret; |
| 1509 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1510 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1511 | audio_extn_spkr_prot_is_enabled()) |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1512 | acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1513 | else |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1514 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1515 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1516 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1517 | |
| 1518 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1519 | ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id, |
| 1520 | my_data->adev->acdb_settings); |
| 1521 | if (ret < 0) { |
| 1522 | ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret); |
| 1523 | } |
| 1524 | } else { |
| 1525 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1526 | acdb_rx_id, acdb_tx_id); |
| 1527 | } |
| 1528 | |
| 1529 | return ret; |
| 1530 | } |
| 1531 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1532 | int platform_start_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1533 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1534 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1535 | int ret = 0; |
| 1536 | |
| 1537 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1538 | ret = my_data->csd->start_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1539 | if (ret < 0) { |
| 1540 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 1541 | } |
| 1542 | } |
| 1543 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1546 | int platform_stop_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1547 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1548 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1549 | int ret = 0; |
| 1550 | |
| 1551 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1552 | ret = my_data->csd->stop_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1553 | if (ret < 0) { |
| 1554 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 1555 | } |
| 1556 | } |
| 1557 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1560 | int platform_get_sample_rate(void *platform, uint32_t *rate) |
| 1561 | { |
| 1562 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1563 | int ret = 0; |
| 1564 | |
| 1565 | if (my_data->csd != NULL) { |
| 1566 | ret = my_data->csd->get_sample_rate(rate); |
| 1567 | if (ret < 0) { |
| 1568 | ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret); |
| 1569 | } |
| 1570 | } |
| 1571 | return ret; |
| 1572 | } |
| 1573 | |
vivek mehta | b650641 | 2015-08-07 16:55:17 -0700 | [diff] [blame] | 1574 | void platform_set_speaker_gain_in_combo(struct audio_device *adev, |
| 1575 | snd_device_t snd_device, |
| 1576 | bool enable) |
| 1577 | { |
| 1578 | const char* name; |
| 1579 | switch (snd_device) { |
| 1580 | case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES: |
| 1581 | if (enable) |
| 1582 | name = "spkr-gain-in-headphone-combo"; |
| 1583 | else |
| 1584 | name = "speaker-gain-default"; |
| 1585 | break; |
| 1586 | case SND_DEVICE_OUT_SPEAKER_AND_LINE: |
| 1587 | if (enable) |
| 1588 | name = "spkr-gain-in-line-combo"; |
| 1589 | else |
| 1590 | name = "speaker-gain-default"; |
| 1591 | break; |
| 1592 | case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES: |
| 1593 | if (enable) |
| 1594 | name = "spkr-safe-gain-in-headphone-combo"; |
| 1595 | else |
| 1596 | name = "speaker-safe-gain-default"; |
| 1597 | break; |
| 1598 | case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE: |
| 1599 | if (enable) |
| 1600 | name = "spkr-safe-gain-in-line-combo"; |
| 1601 | else |
| 1602 | name = "speaker-safe-gain-default"; |
| 1603 | break; |
| 1604 | default: |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | audio_route_apply_and_update_path(adev->audio_route, name); |
| 1609 | } |
| 1610 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1611 | int platform_set_voice_volume(void *platform, int volume) |
| 1612 | { |
| 1613 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1614 | struct audio_device *adev = my_data->adev; |
| 1615 | struct mixer_ctl *ctl; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1616 | const char *mixer_ctl_name = "Voice Rx Gain"; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1617 | int vol_index = 0, ret = 0; |
| 1618 | uint32_t set_values[ ] = {0, |
| 1619 | ALL_SESSION_VSID, |
| 1620 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1621 | |
| 1622 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 1623 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 1624 | // But this values don't changed in kernel. So, below change is need. |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 1625 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1626 | set_values[0] = vol_index; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1627 | |
| 1628 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1629 | if (!ctl) { |
| 1630 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1631 | __func__, mixer_ctl_name); |
| 1632 | return -EINVAL; |
| 1633 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1634 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 1635 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1636 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1637 | if (my_data->csd != NULL) { |
| 1638 | ret = my_data->csd->volume(ALL_SESSION_VSID, volume, |
| 1639 | DEFAULT_VOLUME_RAMP_DURATION_MS); |
| 1640 | if (ret < 0) { |
| 1641 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 1642 | } |
| 1643 | } |
| 1644 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | int platform_set_mic_mute(void *platform, bool state) |
| 1648 | { |
| 1649 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1650 | struct audio_device *adev = my_data->adev; |
| 1651 | struct mixer_ctl *ctl; |
| 1652 | const char *mixer_ctl_name = "Voice Tx Mute"; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1653 | int ret = 0; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1654 | uint32_t set_values[ ] = {0, |
| 1655 | ALL_SESSION_VSID, |
| 1656 | DEFAULT_MUTE_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1657 | |
Uday Kishore Pasupuleti | a1f4805 | 2015-09-08 22:49:18 +0900 | [diff] [blame] | 1658 | if (adev->mode != AUDIO_MODE_IN_CALL && |
| 1659 | adev->mode != AUDIO_MODE_IN_COMMUNICATION) |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1660 | return 0; |
| 1661 | |
Uday Kishore Pasupuleti | a1f4805 | 2015-09-08 22:49:18 +0900 | [diff] [blame] | 1662 | if (adev->enable_hfp) |
| 1663 | mixer_ctl_name = "HFP Tx Mute"; |
| 1664 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1665 | set_values[0] = state; |
| 1666 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1667 | if (!ctl) { |
| 1668 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1669 | __func__, mixer_ctl_name); |
| 1670 | return -EINVAL; |
| 1671 | } |
| 1672 | ALOGV("Setting voice mute state: %d", state); |
| 1673 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1674 | |
| 1675 | if (my_data->csd != NULL) { |
| 1676 | ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state, |
| 1677 | DEFAULT_MUTE_RAMP_DURATION_MS); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1678 | if (ret < 0) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1679 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1680 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1681 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1682 | return ret; |
| 1683 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1684 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1685 | int platform_set_device_mute(void *platform, bool state, char *dir) |
| 1686 | { |
| 1687 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1688 | struct audio_device *adev = my_data->adev; |
| 1689 | struct mixer_ctl *ctl; |
| 1690 | char *mixer_ctl_name = NULL; |
| 1691 | int ret = 0; |
| 1692 | uint32_t set_values[ ] = {0, |
| 1693 | ALL_SESSION_VSID, |
| 1694 | 0}; |
| 1695 | if(dir == NULL) { |
| 1696 | ALOGE("%s: Invalid direction:%s", __func__, dir); |
| 1697 | return -EINVAL; |
| 1698 | } |
| 1699 | |
| 1700 | if (!strncmp("rx", dir, sizeof("rx"))) { |
| 1701 | mixer_ctl_name = "Voice Rx Device Mute"; |
| 1702 | } else if (!strncmp("tx", dir, sizeof("tx"))) { |
| 1703 | mixer_ctl_name = "Voice Tx Device Mute"; |
| 1704 | } else { |
| 1705 | return -EINVAL; |
| 1706 | } |
| 1707 | |
| 1708 | set_values[0] = state; |
| 1709 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1710 | if (!ctl) { |
| 1711 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1712 | __func__, mixer_ctl_name); |
| 1713 | return -EINVAL; |
| 1714 | } |
| 1715 | |
| 1716 | ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s", |
| 1717 | __func__,state, mixer_ctl_name); |
| 1718 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1719 | |
| 1720 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1723 | bool platform_can_split_snd_device(snd_device_t snd_device, |
| 1724 | int *num_devices, |
| 1725 | snd_device_t *new_snd_devices) |
| 1726 | { |
| 1727 | bool status = false; |
| 1728 | |
| 1729 | if (NULL == num_devices || NULL == new_snd_devices) { |
| 1730 | ALOGE("%s: NULL pointer ..", __func__); |
| 1731 | return false; |
| 1732 | } |
| 1733 | |
| 1734 | /* |
| 1735 | * If wired headset/headphones/line devices share the same backend |
| 1736 | * with speaker/earpiece this routine returns false. |
| 1737 | */ |
| 1738 | if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES && |
| 1739 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) { |
| 1740 | *num_devices = 2; |
| 1741 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 1742 | new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES; |
| 1743 | status = true; |
| 1744 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE && |
| 1745 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) { |
| 1746 | *num_devices = 2; |
| 1747 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 1748 | new_snd_devices[1] = SND_DEVICE_OUT_LINE; |
| 1749 | status = true; |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 1750 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES && |
| 1751 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) { |
| 1752 | *num_devices = 2; |
| 1753 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE; |
| 1754 | new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES; |
| 1755 | status = true; |
| 1756 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE && |
| 1757 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) { |
| 1758 | *num_devices = 2; |
| 1759 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE; |
| 1760 | new_snd_devices[1] = SND_DEVICE_OUT_LINE; |
| 1761 | status = true; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1762 | } |
| 1763 | return status; |
| 1764 | } |
| 1765 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1766 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 1767 | { |
| 1768 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1769 | struct audio_device *adev = my_data->adev; |
| 1770 | audio_mode_t mode = adev->mode; |
| 1771 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 1772 | |
| 1773 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 1774 | if (devices == AUDIO_DEVICE_NONE || |
| 1775 | devices & AUDIO_DEVICE_BIT_IN) { |
| 1776 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 1777 | goto exit; |
| 1778 | } |
| 1779 | |
Eric Laurent | 1b49155 | 2015-09-15 17:52:41 -0700 | [diff] [blame] | 1780 | if (popcount(devices) == 2) { |
| 1781 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 1782 | AUDIO_DEVICE_OUT_SPEAKER) || |
| 1783 | devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 1784 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1785 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 1786 | } else if (devices == (AUDIO_DEVICE_OUT_LINE | |
| 1787 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1788 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE; |
| 1789 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 1790 | AUDIO_DEVICE_OUT_SPEAKER_SAFE) || |
| 1791 | devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 1792 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 1793 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES; |
| 1794 | } else if (devices == (AUDIO_DEVICE_OUT_LINE | |
| 1795 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 1796 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE; |
| 1797 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 1798 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1799 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
| 1800 | } else { |
| 1801 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 1802 | goto exit; |
| 1803 | } |
| 1804 | if (snd_device != SND_DEVICE_NONE) { |
| 1805 | goto exit; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | if (popcount(devices) != 1) { |
| 1810 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 1811 | goto exit; |
| 1812 | } |
| 1813 | |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1814 | if (voice_is_in_call(adev) || adev->enable_voicerx) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1815 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 1816 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 1817 | devices & AUDIO_DEVICE_OUT_LINE) { |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1818 | if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 1819 | (adev->voice.tty_mode == TTY_MODE_FULL)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1820 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1821 | else if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 1822 | (adev->voice.tty_mode == TTY_MODE_VCO)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1823 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1824 | else if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 1825 | (adev->voice.tty_mode == TTY_MODE_HCO)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1826 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 1827 | else { |
| 1828 | if (devices & AUDIO_DEVICE_OUT_LINE) |
| 1829 | snd_device = SND_DEVICE_OUT_VOICE_LINE; |
| 1830 | else |
| 1831 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
| 1832 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1833 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1834 | if (adev->bt_wb_speech_enabled) { |
| 1835 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1836 | } else { |
| 1837 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 1838 | } |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 1839 | } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 1840 | if (!adev->enable_hfp) { |
| 1841 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 1842 | } else { |
| 1843 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP; |
| 1844 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1845 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 1846 | if(adev->voice.hac) |
| 1847 | snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET; |
| 1848 | else if (is_operator_tmus()) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1849 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
| 1850 | else |
Eric Laurent | b4d368e | 2014-06-25 10:21:54 -0500 | [diff] [blame] | 1851 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1852 | } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) |
| 1853 | snd_device = SND_DEVICE_OUT_VOICE_TX; |
| 1854 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1855 | if (snd_device != SND_DEVICE_NONE) { |
| 1856 | goto exit; |
| 1857 | } |
| 1858 | } |
| 1859 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1860 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1861 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1862 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 1863 | } else if (devices & AUDIO_DEVICE_OUT_LINE) { |
| 1864 | snd_device = SND_DEVICE_OUT_LINE; |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 1865 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) { |
| 1866 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1867 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 1868 | if (my_data->speaker_lr_swap) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1869 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 1870 | else |
| 1871 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 1872 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1873 | if (adev->bt_wb_speech_enabled) { |
| 1874 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1875 | } else { |
| 1876 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 1877 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1878 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1879 | snd_device = SND_DEVICE_OUT_HDMI ; |
| 1880 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 1881 | /*HAC support for voice-ish audio (eg visual voicemail)*/ |
| 1882 | if(adev->voice.hac) |
| 1883 | snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET; |
| 1884 | else |
| 1885 | snd_device = SND_DEVICE_OUT_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1886 | } else { |
| 1887 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 1888 | } |
| 1889 | exit: |
| 1890 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 1891 | return snd_device; |
| 1892 | } |
| 1893 | |
| 1894 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 1895 | { |
| 1896 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1897 | struct audio_device *adev = my_data->adev; |
| 1898 | audio_source_t source = (adev->active_input == NULL) ? |
| 1899 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 1900 | |
| 1901 | audio_mode_t mode = adev->mode; |
| 1902 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 1903 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 1904 | & ~AUDIO_DEVICE_BIT_IN; |
| 1905 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1906 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1907 | snd_device_t snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1908 | int channel_count = popcount(channel_mask); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1909 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1910 | ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)", |
| 1911 | __func__, out_device, in_device, channel_count, channel_mask); |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1912 | if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1913 | if (adev->voice.tty_mode != TTY_MODE_OFF) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1914 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 1915 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 1916 | out_device & AUDIO_DEVICE_OUT_LINE) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1917 | switch (adev->voice.tty_mode) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1918 | case TTY_MODE_FULL: |
| 1919 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 1920 | break; |
| 1921 | case TTY_MODE_VCO: |
| 1922 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 1923 | break; |
| 1924 | case TTY_MODE_HCO: |
| 1925 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 1926 | break; |
| 1927 | default: |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1928 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1929 | } |
| 1930 | goto exit; |
| 1931 | } |
| 1932 | } |
Eric Laurent | b991fb0 | 2014-08-29 15:23:17 -0500 | [diff] [blame] | 1933 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1934 | if (my_data->fluence_in_voice_call == false) { |
| 1935 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1936 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1937 | if (is_operator_tmus()) |
| 1938 | snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1939 | else |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1940 | snd_device = SND_DEVICE_IN_VOICE_DMIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1943 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 1944 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1945 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 1946 | if (adev->bluetooth_nrec) |
| 1947 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 1948 | else |
| 1949 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1950 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 1951 | if (adev->bluetooth_nrec) |
| 1952 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 1953 | else |
| 1954 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1955 | } |
Eric Laurent | b991fb0 | 2014-08-29 15:23:17 -0500 | [diff] [blame] | 1956 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1957 | out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE || |
| 1958 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1959 | out_device & AUDIO_DEVICE_OUT_LINE) { |
| 1960 | if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) { |
| 1961 | if (my_data->source_mic_type & SOURCE_DUAL_MIC) { |
| 1962 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC; |
| 1963 | } else { |
| 1964 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 1965 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1966 | } |
vivek mehta | fe121d5 | 2015-08-10 23:39:23 -0700 | [diff] [blame] | 1967 | |
| 1968 | //select default |
| 1969 | if (snd_device == SND_DEVICE_NONE) { |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 1970 | if (!adev->enable_hfp) { |
| 1971 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 1972 | } else { |
| 1973 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP; |
| 1974 | platform_set_echo_reference(adev, true, out_device); |
| 1975 | } |
vivek mehta | fe121d5 | 2015-08-10 23:39:23 -0700 | [diff] [blame] | 1976 | } |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1977 | } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1978 | snd_device = SND_DEVICE_IN_VOICE_RX; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1979 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1980 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 1981 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 1982 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1983 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 1984 | } |
| 1985 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1986 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1987 | if (my_data->fluence_in_voice_rec && channel_count == 1) { |
| 1988 | if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) && |
| 1989 | (my_data->source_mic_type & SOURCE_QUAD_MIC)) { |
| 1990 | snd_device = SND_DEVICE_IN_HANDSET_QMIC; |
| 1991 | } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) && |
| 1992 | (my_data->source_mic_type & SOURCE_THREE_MIC)) { |
| 1993 | snd_device = SND_DEVICE_IN_HANDSET_TMIC; |
| 1994 | } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) || |
| 1995 | (my_data->fluence_type == FLUENCE_ENABLE)) && |
| 1996 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1997 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1998 | } |
| 1999 | platform_set_echo_reference(adev, true, out_device); |
| 2000 | } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) && |
| 2001 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
| 2002 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO; |
| 2003 | } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) && |
| 2004 | (my_data->source_mic_type & SOURCE_THREE_MIC)) { |
| 2005 | snd_device = SND_DEVICE_IN_THREE_MIC; |
| 2006 | } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) && |
| 2007 | (my_data->source_mic_type & SOURCE_QUAD_MIC)) { |
| 2008 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2009 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2010 | if (snd_device == SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2011 | if (adev->active_input->enable_ns) |
| 2012 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS; |
| 2013 | else |
| 2014 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2015 | } |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 2016 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2017 | snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2018 | } |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2019 | } else if (source == AUDIO_SOURCE_UNPROCESSED) { |
| 2020 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 2021 | snd_device = SND_DEVICE_IN_UNPROCESSED_MIC; |
| 2022 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2023 | snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC; |
| 2024 | } |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 2025 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2026 | mode == AUDIO_MODE_IN_COMMUNICATION) { |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2027 | if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2028 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 2029 | if (adev->active_input) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2030 | if (adev->active_input->enable_aec && |
| 2031 | adev->active_input->enable_ns) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2032 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2033 | if (my_data->fluence_in_spkr_mode && |
| 2034 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2035 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2036 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2037 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2038 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2039 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2040 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2041 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2042 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2043 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2044 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2045 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2046 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2047 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2048 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2049 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2050 | platform_set_echo_reference(adev, true, out_device); |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2051 | } else if (adev->active_input->enable_aec) { |
| 2052 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 2053 | if (my_data->fluence_in_spkr_mode && |
| 2054 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2055 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2056 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2057 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2058 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2059 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2060 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 2061 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2062 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2063 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2064 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2065 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2066 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2067 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2068 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
| 2069 | } |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 2070 | platform_set_echo_reference(adev, true, out_device); |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2071 | } else if (adev->active_input->enable_ns) { |
| 2072 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 2073 | if (my_data->fluence_in_spkr_mode && |
| 2074 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2075 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2076 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2077 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2078 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2079 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2080 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 2081 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2082 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2083 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2084 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2085 | snd_device = SND_DEVICE_IN_HANDSET_MIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2086 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2087 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2088 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 2091 | goto exit; |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | if (snd_device != SND_DEVICE_NONE) { |
| 2096 | goto exit; |
| 2097 | } |
| 2098 | |
| 2099 | if (in_device != AUDIO_DEVICE_NONE && |
| 2100 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 2101 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 2102 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2103 | if ((my_data->source_mic_type & SOURCE_QUAD_MIC) && |
| 2104 | (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) { |
| 2105 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
| 2106 | } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) && |
| 2107 | (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) { |
| 2108 | snd_device = SND_DEVICE_IN_THREE_MIC; |
| 2109 | } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2110 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2111 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2112 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2113 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2114 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2115 | } else { |
| 2116 | ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .." |
| 2117 | " channel mask (0x%x) no combination found .. setting to mono", __func__, |
| 2118 | my_data->source_mic_type, channel_count, channel_mask); |
| 2119 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2120 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2121 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2122 | if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2123 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2124 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2125 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2126 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2127 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2128 | } else { |
| 2129 | ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .." |
| 2130 | " no combination found .. setting to mono", __func__, |
| 2131 | my_data->source_mic_type, channel_count); |
| 2132 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 2133 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2134 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2135 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 2136 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2137 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2138 | if (adev->bluetooth_nrec) |
| 2139 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 2140 | else |
| 2141 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2142 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2143 | if (adev->bluetooth_nrec) |
| 2144 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 2145 | else |
| 2146 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2147 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2148 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 2149 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 2150 | } else { |
| 2151 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 2152 | ALOGW("%s: Using default handset-mic", __func__); |
| 2153 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2154 | } |
| 2155 | } else { |
| 2156 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 2157 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2158 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 2159 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2160 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2161 | out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE || |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2162 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2163 | out_device & AUDIO_DEVICE_OUT_LINE) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2164 | if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2165 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2166 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2167 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2168 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2169 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2170 | } else { |
| 2171 | ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .." |
| 2172 | " no combination found .. setting to mono", __func__, |
| 2173 | my_data->source_mic_type, channel_count); |
| 2174 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 2175 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2176 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2177 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2178 | if (adev->bluetooth_nrec) |
| 2179 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 2180 | else |
| 2181 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2182 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2183 | if (adev->bluetooth_nrec) |
| 2184 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 2185 | else |
| 2186 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2187 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2188 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 2189 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 2190 | } else { |
| 2191 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 2192 | ALOGW("%s: Using default handset-mic", __func__); |
| 2193 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2194 | } |
| 2195 | } |
| 2196 | exit: |
| 2197 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 2198 | return snd_device; |
| 2199 | } |
| 2200 | |
| 2201 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 2202 | { |
| 2203 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2204 | struct audio_device *adev = my_data->adev; |
| 2205 | struct mixer_ctl *ctl; |
| 2206 | const char *channel_cnt_str = NULL; |
| 2207 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 2208 | switch (channel_count) { |
| 2209 | case 8: |
| 2210 | channel_cnt_str = "Eight"; break; |
| 2211 | case 7: |
| 2212 | channel_cnt_str = "Seven"; break; |
| 2213 | case 6: |
| 2214 | channel_cnt_str = "Six"; break; |
| 2215 | case 5: |
| 2216 | channel_cnt_str = "Five"; break; |
| 2217 | case 4: |
| 2218 | channel_cnt_str = "Four"; break; |
| 2219 | case 3: |
| 2220 | channel_cnt_str = "Three"; break; |
| 2221 | default: |
| 2222 | channel_cnt_str = "Two"; break; |
| 2223 | } |
| 2224 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2225 | if (!ctl) { |
| 2226 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2227 | __func__, mixer_ctl_name); |
| 2228 | return -EINVAL; |
| 2229 | } |
| 2230 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 2231 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2235 | int platform_edid_get_max_channels(void *platform) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2236 | { |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2237 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2238 | struct audio_device *adev = my_data->adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2239 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 2240 | char *sad = block; |
| 2241 | int num_audio_blocks; |
| 2242 | int channel_count; |
| 2243 | int max_channels = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2244 | int i, ret, count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2245 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2246 | struct mixer_ctl *ctl; |
| 2247 | |
| 2248 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 2249 | if (!ctl) { |
| 2250 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2251 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2252 | return 0; |
| 2253 | } |
| 2254 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2255 | mixer_ctl_update(ctl); |
| 2256 | |
| 2257 | count = mixer_ctl_get_num_values(ctl); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2258 | |
| 2259 | /* Read SAD blocks, clamping the maximum size for safety */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2260 | if (count > (int)sizeof(block)) |
| 2261 | count = (int)sizeof(block); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2262 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2263 | ret = mixer_ctl_get_array(ctl, block, count); |
| 2264 | if (ret != 0) { |
| 2265 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 2266 | return 0; |
| 2267 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2268 | |
| 2269 | /* Calculate the number of SAD blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2270 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2271 | |
| 2272 | for (i = 0; i < num_audio_blocks; i++) { |
| 2273 | /* Only consider LPCM blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2274 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 2275 | sad += 3; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2276 | continue; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2277 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2278 | |
| 2279 | channel_count = (sad[0] & 0x7) + 1; |
| 2280 | if (channel_count > max_channels) |
| 2281 | max_channels = channel_count; |
| 2282 | |
| 2283 | /* Advance to next block */ |
| 2284 | sad += 3; |
| 2285 | } |
| 2286 | |
| 2287 | return max_channels; |
| 2288 | } |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2289 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2290 | int platform_set_incall_recording_session_id(void *platform, |
| 2291 | uint32_t session_id, int rec_mode) |
| 2292 | { |
| 2293 | int ret = 0; |
| 2294 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2295 | struct audio_device *adev = my_data->adev; |
| 2296 | struct mixer_ctl *ctl; |
| 2297 | const char *mixer_ctl_name = "Voc VSID"; |
| 2298 | int num_ctl_values; |
| 2299 | int i; |
| 2300 | |
| 2301 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2302 | if (!ctl) { |
| 2303 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2304 | __func__, mixer_ctl_name); |
| 2305 | ret = -EINVAL; |
| 2306 | } else { |
| 2307 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 2308 | for (i = 0; i < num_ctl_values; i++) { |
| 2309 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 2310 | ALOGV("Error: invalid session_id: %x", session_id); |
| 2311 | ret = -EINVAL; |
| 2312 | break; |
| 2313 | } |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | if (my_data->csd != NULL) { |
| 2318 | ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode); |
| 2319 | if (ret < 0) { |
| 2320 | ALOGE("%s: csd_client_start_record failed, error %d", |
| 2321 | __func__, ret); |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | return ret; |
| 2326 | } |
| 2327 | |
| 2328 | int platform_stop_incall_recording_usecase(void *platform) |
| 2329 | { |
| 2330 | int ret = 0; |
| 2331 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2332 | |
| 2333 | if (my_data->csd != NULL) { |
| 2334 | ret = my_data->csd->stop_record(ALL_SESSION_VSID); |
| 2335 | if (ret < 0) { |
| 2336 | ALOGE("%s: csd_client_stop_record failed, error %d", |
| 2337 | __func__, ret); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | return ret; |
| 2342 | } |
| 2343 | |
| 2344 | int platform_start_incall_music_usecase(void *platform) |
| 2345 | { |
| 2346 | int ret = 0; |
| 2347 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2348 | |
| 2349 | if (my_data->csd != NULL) { |
| 2350 | ret = my_data->csd->start_playback(ALL_SESSION_VSID); |
| 2351 | if (ret < 0) { |
| 2352 | ALOGE("%s: csd_client_start_playback failed, error %d", |
| 2353 | __func__, ret); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | return ret; |
| 2358 | } |
| 2359 | |
| 2360 | int platform_stop_incall_music_usecase(void *platform) |
| 2361 | { |
| 2362 | int ret = 0; |
| 2363 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2364 | |
| 2365 | if (my_data->csd != NULL) { |
| 2366 | ret = my_data->csd->stop_playback(ALL_SESSION_VSID); |
| 2367 | if (ret < 0) { |
| 2368 | ALOGE("%s: csd_client_stop_playback failed, error %d", |
| 2369 | __func__, ret); |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | return ret; |
| 2374 | } |
| 2375 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 2376 | int platform_set_parameters(void *platform, struct str_parms *parms) |
| 2377 | { |
| 2378 | struct platform_data *my_data = (struct platform_data *)platform; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 2379 | char value[128]; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 2380 | char *kv_pairs = str_parms_to_str(parms); |
| 2381 | int ret = 0, err; |
| 2382 | |
| 2383 | if (kv_pairs == NULL) { |
| 2384 | ret = -EINVAL; |
| 2385 | ALOGE("%s: key-value pair is NULL",__func__); |
| 2386 | goto done; |
| 2387 | } |
| 2388 | |
| 2389 | ALOGV("%s: enter: %s", __func__, kv_pairs); |
| 2390 | |
| 2391 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME, |
| 2392 | value, sizeof(value)); |
| 2393 | if (err >= 0) { |
| 2394 | str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME); |
| 2395 | my_data->snd_card_name = strdup(value); |
| 2396 | ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name); |
| 2397 | } |
| 2398 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 2399 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO, |
| 2400 | value, sizeof(value)); |
| 2401 | if (err >= 0) { |
| 2402 | struct operator_info *info; |
| 2403 | char *str = value; |
| 2404 | char *name; |
| 2405 | |
| 2406 | str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO); |
| 2407 | info = (struct operator_info *)calloc(1, sizeof(struct operator_info)); |
| 2408 | name = strtok(str, ";"); |
| 2409 | info->name = strdup(name); |
| 2410 | info->mccmnc = strdup(str + strlen(name) + 1); |
| 2411 | |
| 2412 | list_add_tail(&operator_info_list, &info->list); |
| 2413 | ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc); |
| 2414 | } |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2415 | |
| 2416 | memset(value, 0, sizeof(value)); |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 2417 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2418 | value, sizeof(value)); |
| 2419 | if (err >= 0) { |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 2420 | str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2421 | my_data->max_mic_count = atoi(value); |
| 2422 | ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 2425 | done: |
| 2426 | ALOGV("%s: exit with code(%d)", __func__, ret); |
| 2427 | if (kv_pairs != NULL) |
| 2428 | free(kv_pairs); |
| 2429 | |
| 2430 | return ret; |
| 2431 | } |
| 2432 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2433 | /* Delay in Us */ |
| 2434 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 2435 | { |
| 2436 | switch (usecase) { |
| 2437 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 2438 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 2439 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 2440 | return LOW_LATENCY_PLATFORM_DELAY; |
| 2441 | default: |
| 2442 | return 0; |
| 2443 | } |
| 2444 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2445 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2446 | int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag, |
| 2447 | const char * hw_interface) |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2448 | { |
| 2449 | int ret = 0; |
| 2450 | |
| 2451 | if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { |
| 2452 | ALOGE("%s: Invalid snd_device = %d", |
| 2453 | __func__, device); |
| 2454 | ret = -EINVAL; |
| 2455 | goto done; |
| 2456 | } |
| 2457 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2458 | ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__, |
| 2459 | platform_get_snd_device_name(device), |
| 2460 | backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag); |
| 2461 | if (backend_tag_table[device]) { |
| 2462 | free(backend_tag_table[device]); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2463 | } |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2464 | backend_tag_table[device] = strdup(backend_tag); |
| 2465 | |
| 2466 | if (hw_interface != NULL) { |
| 2467 | if (hw_interface_table[device]) |
| 2468 | free(hw_interface_table[device]); |
| 2469 | ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface); |
| 2470 | hw_interface_table[device] = strdup(hw_interface); |
| 2471 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2472 | done: |
| 2473 | return ret; |
| 2474 | } |
| 2475 | |
| 2476 | int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id) |
| 2477 | { |
| 2478 | int ret = 0; |
| 2479 | if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) { |
| 2480 | ALOGE("%s: invalid usecase case idx %d", __func__, usecase); |
| 2481 | ret = -EINVAL; |
| 2482 | goto done; |
| 2483 | } |
| 2484 | |
| 2485 | if ((type != 0) && (type != 1)) { |
| 2486 | ALOGE("%s: invalid usecase type", __func__); |
| 2487 | ret = -EINVAL; |
| 2488 | } |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2489 | ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2490 | pcm_device_table[usecase][type] = pcm_id; |
| 2491 | done: |
| 2492 | return ret; |
| 2493 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2494 | |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 2495 | #define DEFAULT_NOMINAL_SPEAKER_GAIN 20 |
| 2496 | int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) { |
| 2497 | // backup_gain: gain to try to set in case of an error during ramp |
| 2498 | int start_gain, end_gain, step, backup_gain, i; |
| 2499 | bool error = false; |
| 2500 | const struct mixer_ctl *ctl; |
| 2501 | const char *mixer_ctl_name_gain_left = "Left Speaker Gain"; |
| 2502 | const char *mixer_ctl_name_gain_right = "Right Speaker Gain"; |
| 2503 | struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left); |
| 2504 | struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right); |
| 2505 | if (!ctl_left || !ctl_right) { |
| 2506 | ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp", |
| 2507 | __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right); |
| 2508 | return -EINVAL; |
| 2509 | } else if ((mixer_ctl_get_num_values(ctl_left) != 1) |
| 2510 | || (mixer_ctl_get_num_values(ctl_right) != 1)) { |
| 2511 | ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp", |
| 2512 | __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right); |
| 2513 | return -EINVAL; |
| 2514 | } |
| 2515 | if (ramp_up) { |
| 2516 | start_gain = 0; |
| 2517 | end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN; |
| 2518 | step = +1; |
| 2519 | backup_gain = end_gain; |
| 2520 | } else { |
| 2521 | // using same gain on left and right |
| 2522 | const int left_gain = mixer_ctl_get_value(ctl_left, 0); |
| 2523 | start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN; |
| 2524 | end_gain = 0; |
| 2525 | step = -1; |
| 2526 | backup_gain = start_gain; |
| 2527 | } |
| 2528 | for (i = start_gain ; i != (end_gain + step) ; i += step) { |
| 2529 | //ALOGV("setting speaker gain to %d", i); |
| 2530 | if (mixer_ctl_set_value(ctl_left, 0, i)) { |
| 2531 | ALOGE("%s: error setting %s to %d during gain ramp", |
| 2532 | __func__, mixer_ctl_name_gain_left, i); |
| 2533 | error = true; |
| 2534 | break; |
| 2535 | } |
| 2536 | if (mixer_ctl_set_value(ctl_right, 0, i)) { |
| 2537 | ALOGE("%s: error setting %s to %d during gain ramp", |
| 2538 | __func__, mixer_ctl_name_gain_right, i); |
| 2539 | error = true; |
| 2540 | break; |
| 2541 | } |
| 2542 | usleep(1000); |
| 2543 | } |
| 2544 | if (error) { |
| 2545 | // an error occured during the ramp, let's still try to go back to a safe volume |
| 2546 | if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) { |
| 2547 | ALOGE("%s: error restoring left gain to %d", __func__, backup_gain); |
| 2548 | } |
| 2549 | if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) { |
| 2550 | ALOGE("%s: error restoring right gain to %d", __func__, backup_gain); |
| 2551 | } |
| 2552 | } |
| 2553 | return start_gain; |
| 2554 | } |
| 2555 | |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2556 | int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels) |
| 2557 | { |
| 2558 | // only update if there is active pcm playback on speaker |
| 2559 | struct audio_usecase *usecase; |
| 2560 | struct listnode *node; |
| 2561 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
| 2562 | |
| 2563 | if (my_data->speaker_lr_swap != swap_channels) { |
| 2564 | my_data->speaker_lr_swap = swap_channels; |
| 2565 | |
| 2566 | list_for_each(node, &adev->usecase_list) { |
| 2567 | usecase = node_to_item(node, struct audio_usecase, list); |
| 2568 | if (usecase->type == PCM_PLAYBACK && |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 2569 | usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 2570 | /* |
| 2571 | * If acdb tuning is different for SPEAKER_REVERSE, it is must |
| 2572 | * to perform device switch to disable the current backend to |
| 2573 | * enable it with new acdb data. |
| 2574 | */ |
| 2575 | if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] != |
| 2576 | acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) { |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 2577 | const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1); |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 2578 | select_devices(adev, usecase->id); |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 2579 | if (initial_skpr_gain != -EINVAL) { |
| 2580 | ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain); |
| 2581 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2582 | } else { |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 2583 | const char *mixer_path; |
| 2584 | if (swap_channels) { |
| 2585 | mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE); |
| 2586 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
| 2587 | } else { |
| 2588 | mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER); |
| 2589 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
| 2590 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2591 | } |
| 2592 | break; |
| 2593 | } |
| 2594 | } |
| 2595 | } |
| 2596 | return 0; |
| 2597 | } |