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