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