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