Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1 | /* |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2017 The Android Open Source Project |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 16 | #define LOG_TAG "msm8974_platform" |
| 17 | /*#define LOG_NDEBUG 0*/ |
| 18 | #define LOG_NDDEBUG 0 |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <dlfcn.h> |
| 22 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 23 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
| 25 | #include <audio_hw.h> |
| 26 | #include <platform_api.h> |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 27 | #include "acdb.h" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 28 | #include "platform.h" |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 29 | #include "audio_extn.h" |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 30 | #include <linux/msm_audio.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 31 | |
Jaekyun Seok | f62e17d | 2017-03-08 17:15:28 +0900 | [diff] [blame] | 32 | #define MIXER_XML_DEFAULT_PATH "mixer_paths.xml" |
| 33 | #define MIXER_XML_BASE_STRING "mixer_paths" |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame] | 34 | #define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card" |
| 35 | #define TOMTOM_MIXER_FILE_SUFFIX "wcd9330" |
| 36 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 37 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 38 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 39 | #define CVD_VERSION_MIXER_CTL "CVD Version" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 40 | |
Eric Laurent | f9583c3 | 2016-03-28 13:50:50 -0700 | [diff] [blame] | 41 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 44 | * This file will have a maximum of 38 bytes: |
| 45 | * |
| 46 | * 4 bytes: number of audio blocks |
| 47 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 48 | * Maximum 10 * 3 bytes: SAD blocks |
| 49 | */ |
| 50 | #define MAX_SAD_BLOCKS 10 |
| 51 | #define SAD_BLOCK_SIZE 3 |
| 52 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 53 | #define MAX_CVD_VERSION_STRING_SIZE 100 |
| 54 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 55 | /* EDID format ID for LPCM audio */ |
| 56 | #define EDID_FORMAT_LPCM 1 |
| 57 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 58 | #define MAX_SND_CARD_NAME_LEN 31 |
| 59 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 60 | #define DEFAULT_APP_TYPE_RX_PATH 69936 |
| 61 | #define DEFAULT_APP_TYPE_TX_PATH 69938 |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 62 | |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 63 | #define TOSTRING_(x) #x |
| 64 | #define TOSTRING(x) TOSTRING_(x) |
| 65 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 66 | struct audio_block_header |
| 67 | { |
| 68 | int reserved; |
| 69 | int length; |
| 70 | }; |
| 71 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 72 | enum { |
| 73 | CAL_MODE_SEND = 0x1, |
| 74 | CAL_MODE_PERSIST = 0x2, |
| 75 | CAL_MODE_RTAC = 0x4 |
| 76 | }; |
| 77 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 78 | #define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info" |
| 79 | |
| 80 | struct operator_info { |
| 81 | struct listnode list; |
| 82 | char *name; |
| 83 | char *mccmnc; |
| 84 | }; |
| 85 | |
| 86 | struct operator_specific_device { |
| 87 | struct listnode list; |
| 88 | char *operator; |
| 89 | char *mixer_path; |
| 90 | int acdb_id; |
| 91 | }; |
| 92 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 93 | #define BE_DAI_NAME_MAX_LENGTH 24 |
| 94 | struct be_dai_name_struct { |
| 95 | unsigned int be_id; |
| 96 | char be_name[BE_DAI_NAME_MAX_LENGTH]; |
| 97 | }; |
| 98 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 99 | static struct listnode operator_info_list; |
| 100 | static struct listnode *operator_specific_device_table[SND_DEVICE_MAX]; |
| 101 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 102 | /* Audio calibration related functions */ |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 103 | typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 104 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 105 | struct platform_data { |
| 106 | struct audio_device *adev; |
| 107 | bool fluence_in_spkr_mode; |
| 108 | bool fluence_in_voice_call; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 109 | bool fluence_in_voice_comm; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 110 | bool fluence_in_voice_rec; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 111 | /* 0 = no fluence, 1 = fluence, 2 = fluence pro */ |
| 112 | int fluence_type; |
| 113 | int source_mic_type; |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 114 | bool speaker_lr_swap; |
| 115 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 116 | void *acdb_handle; |
Thierry Strudel | 92232b4 | 2017-01-26 10:51:48 -0800 | [diff] [blame] | 117 | #if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 118 | acdb_init_v2_cvd_t acdb_init; |
| 119 | #elif defined (PLATFORM_MSM8084) |
| 120 | acdb_init_v2_t acdb_init; |
| 121 | #else |
| 122 | acdb_init_t acdb_init; |
| 123 | #endif |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 124 | acdb_deallocate_t acdb_deallocate; |
| 125 | acdb_send_audio_cal_t acdb_send_audio_cal; |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 126 | acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 127 | acdb_send_voice_cal_t acdb_send_voice_cal; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 128 | acdb_reload_vocvoltable_t acdb_reload_vocvoltable; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 129 | acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal; |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 130 | acdb_send_custom_top_t acdb_send_custom_top; |
| 131 | bool acdb_initialized; |
| 132 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 133 | struct csd_data *csd; |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 134 | char ec_ref_mixer_path[64]; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 135 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 136 | codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS]; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 137 | char *snd_card_name; |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 138 | int max_vol_index; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 139 | int max_mic_count; |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 140 | |
| 141 | void *hw_info; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 144 | static int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 145 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 146 | DEEP_BUFFER_PCM_DEVICE}, |
| 147 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 148 | LOWLATENCY_PCM_DEVICE}, |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 149 | [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE, |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 150 | MULTIMEDIA2_PCM_DEVICE}, |
| 151 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE, |
| 152 | PLAYBACK_OFFLOAD_DEVICE}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 153 | [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE, |
| 154 | MULTIMEDIA2_PCM_DEVICE}, |
| 155 | [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE, |
| 156 | MULTIMEDIA3_PCM_DEVICE}, |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 157 | [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE, |
| 158 | MMAP_PLAYBACK_PCM_DEVICE}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 159 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 160 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, |
| 161 | AUDIO_RECORD_PCM_DEVICE}, |
| 162 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 163 | LOWLATENCY_PCM_DEVICE}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 164 | |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 165 | [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE, |
| 166 | MMAP_RECORD_PCM_DEVICE}, |
| 167 | |
Haynes Mathew George | 569b748 | 2017-05-08 14:44:27 -0700 | [diff] [blame] | 168 | [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE, |
| 169 | MULTIMEDIA2_PCM_DEVICE}, |
| 170 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 171 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, |
| 172 | VOICE_CALL_PCM_DEVICE}, |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 173 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 174 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 175 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
| 176 | [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE}, |
vivek mehta | a51fd40 | 2016-02-04 19:49:33 -0800 | [diff] [blame] | 177 | [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE, |
| 178 | VOICEMMODE1_CALL_PCM_DEVICE}, |
| 179 | [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE, |
| 180 | VOICEMMODE2_CALL_PCM_DEVICE}, |
| 181 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 182 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 183 | AUDIO_RECORD_PCM_DEVICE}, |
| 184 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 185 | AUDIO_RECORD_PCM_DEVICE}, |
| 186 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 187 | AUDIO_RECORD_PCM_DEVICE}, |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 188 | [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX}, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 189 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 190 | [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1}, |
| 191 | [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE}, |
| 192 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 193 | [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE, |
| 194 | AFE_PROXY_RECORD_PCM_DEVICE}, |
| 195 | [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE, |
| 196 | AFE_PROXY_RECORD_PCM_DEVICE}, |
zhaoyang yin | 4211fad | 2015-06-04 21:13:25 +0800 | [diff] [blame] | 197 | [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE}, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 198 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 199 | [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, |
| 200 | AUDIO_PLAYBACK_VOIP_PCM_DEVICE}, |
| 201 | [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, |
| 202 | AUDIO_RECORD_VOIP_PCM_DEVICE}, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /* Array to store sound devices */ |
| 206 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 207 | [SND_DEVICE_NONE] = "none", |
| 208 | /* Playback sound devices */ |
| 209 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 210 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 211 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 212 | [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 213 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 214 | [SND_DEVICE_OUT_LINE] = "line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 215 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 216 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones", |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 217 | [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line", |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 218 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 219 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 220 | [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 221 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 222 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 223 | [SND_DEVICE_OUT_VOICE_LINE] = "voice-line", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 224 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 225 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 226 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 227 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 228 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
| 229 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 230 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 231 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 232 | [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb", |
| 233 | [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb", |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 234 | [SND_DEVICE_OUT_VOICE_TX] = "voice-tx", |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 235 | [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset", |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 236 | [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset", |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 237 | [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones", |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 238 | [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones", |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 239 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones", |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 240 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 241 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected", |
| 242 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected", |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 243 | [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp", |
Haynes Mathew George | 6dcb1a8 | 2016-12-21 12:38:55 -0800 | [diff] [blame] | 244 | [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco", |
| 245 | [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 246 | |
| 247 | /* Capture sound devices */ |
| 248 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 249 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 250 | [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic", |
| 251 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic", |
| 252 | [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire", |
| 253 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire", |
| 254 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire", |
| 255 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire", |
| 256 | [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire", |
| 257 | |
| 258 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 259 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic", |
| 260 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic", |
| 261 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic", |
| 262 | [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire", |
| 263 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire", |
| 264 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire", |
| 265 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire", |
| 266 | [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire", |
| 267 | |
| 268 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 269 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 270 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 271 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 272 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 273 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 274 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 275 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 276 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 277 | |
| 278 | [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef", |
| 279 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus", |
| 280 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 281 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef", |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 282 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 283 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 284 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 285 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 286 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 287 | [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic", |
| 288 | [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 289 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 290 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 291 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic", |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 292 | [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic", |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 293 | [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic", |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 294 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef", |
| 295 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence", |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 296 | [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic", |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 297 | [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic", |
| 298 | [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic", |
| 299 | [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic", |
| 300 | [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic", |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 301 | [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic", |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 302 | |
Ricardo Garcia | 9034bc4 | 2016-04-04 07:11:46 -0700 | [diff] [blame] | 303 | [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic", |
vivek mehta | 0125e78 | 2016-06-16 18:03:11 -0700 | [diff] [blame] | 304 | [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic", |
| 305 | [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic", |
| 306 | [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic", |
| 307 | [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic", |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 308 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 309 | [SND_DEVICE_IN_VOICE_RX] = "voice-rx", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 310 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 311 | [SND_DEVICE_IN_THREE_MIC] = "three-mic", |
| 312 | [SND_DEVICE_IN_QUAD_MIC] = "quad-mic", |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 313 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback", |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 314 | [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic", |
| 315 | [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic", |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 316 | [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic", |
| 317 | [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 321 | static int acdb_device_table[SND_DEVICE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 322 | [SND_DEVICE_NONE] = -1, |
| 323 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 324 | [SND_DEVICE_OUT_SPEAKER] = 15, |
| 325 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15, |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 326 | [SND_DEVICE_OUT_SPEAKER_SAFE] = 15, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 327 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 328 | [SND_DEVICE_OUT_LINE] = 77, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 329 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 330 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 331 | [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 332 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77, |
Ravi Kumar Alamanda | 235c348 | 2014-08-21 17:32:44 -0700 | [diff] [blame] | 333 | [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET, |
| 334 | [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER, |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 335 | [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 336 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 337 | [SND_DEVICE_OUT_VOICE_LINE] = 77, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 338 | [SND_DEVICE_OUT_HDMI] = 18, |
| 339 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15, |
| 340 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 341 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 342 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 343 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 344 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 345 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 346 | [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17, |
| 347 | [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 348 | [SND_DEVICE_OUT_VOICE_TX] = 45, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 349 | [SND_DEVICE_OUT_USB_HEADSET] = 45, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 350 | [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 351 | [SND_DEVICE_OUT_USB_HEADPHONES] = 45, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 352 | [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 353 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14, |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 354 | [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 355 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124, |
| 356 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 357 | [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 358 | |
| 359 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 360 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106, |
| 361 | [SND_DEVICE_IN_HANDSET_MIC_NS] = 107, |
| 362 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108, |
| 363 | [SND_DEVICE_IN_HANDSET_DMIC] = 41, |
| 364 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109, |
| 365 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110, |
| 366 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111, |
| 367 | [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34, |
| 368 | |
| 369 | [SND_DEVICE_IN_SPEAKER_MIC] = 11, |
| 370 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112, |
| 371 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113, |
| 372 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114, |
| 373 | [SND_DEVICE_IN_SPEAKER_DMIC] = 43, |
| 374 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115, |
| 375 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116, |
| 376 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117, |
| 377 | [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35, |
| 378 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 379 | [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 380 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 381 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 382 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 383 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 384 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 385 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 386 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 387 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 388 | |
| 389 | [SND_DEVICE_IN_VOICE_DMIC] = 41, |
| 390 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS, |
| 391 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 392 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 393 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43, |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 394 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 395 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 396 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 397 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 398 | [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16, |
| 399 | [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 400 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 401 | [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 402 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113, |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 403 | [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112, |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 404 | [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 405 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35, |
| 406 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43, |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 407 | [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
| 408 | |
| 409 | [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC, |
| 410 | [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC, |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 411 | [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35, |
| 412 | [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125, |
| 413 | [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125, |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 414 | |
| 415 | [SND_DEVICE_IN_VOICE_RX] = 44, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 416 | [SND_DEVICE_IN_USB_HEADSET_MIC] = 44, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 417 | [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44, |
| 418 | [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44, |
| 419 | [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44, |
| 420 | [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 421 | [SND_DEVICE_IN_THREE_MIC] = 46, |
| 422 | [SND_DEVICE_IN_QUAD_MIC] = 46, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 423 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 424 | [SND_DEVICE_IN_HANDSET_TMIC] = 125, |
| 425 | [SND_DEVICE_IN_HANDSET_QMIC] = 125, |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 426 | [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */ |
| 427 | [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 430 | // Platform specific backend bit width table |
| 431 | static int backend_bit_width_table[SND_DEVICE_MAX] = {0}; |
| 432 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 433 | struct name_to_index { |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 434 | char name[100]; |
| 435 | unsigned int index; |
| 436 | }; |
| 437 | |
| 438 | #define TO_NAME_INDEX(X) #X, X |
| 439 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 440 | /* Used to get index from parsed string */ |
| 441 | static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { |
| 442 | /* out */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 443 | {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)}, |
| 444 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)}, |
| 445 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)}, |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 446 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 447 | {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)}, |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 448 | {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 449 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)}, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 450 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)}, |
Eric Laurent | 744996b | 2014-10-01 11:40:40 -0500 | [diff] [blame] | 451 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)}, |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 452 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 453 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)}, |
| 454 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)}, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 455 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 456 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)}, |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 457 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 458 | {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)}, |
| 459 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)}, |
| 460 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)}, |
| 461 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 462 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)}, |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 463 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 464 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)}, |
| 465 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)}, |
| 466 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)}, |
Haynes Mathew George | 6dcb1a8 | 2016-12-21 12:38:55 -0800 | [diff] [blame] | 467 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)}, |
| 468 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)}, |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 469 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)}, |
| 470 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)}, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 471 | {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)}, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 472 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)}, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 473 | {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)}, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 474 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)}, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 475 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)}, |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 476 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)}, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 477 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)}, |
| 478 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)}, |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 479 | |
| 480 | /* in */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 481 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 482 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 483 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)}, |
| 484 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)}, |
| 485 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)}, |
| 486 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)}, |
| 487 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)}, |
| 488 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)}, |
| 489 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)}, |
| 490 | |
| 491 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 492 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 493 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)}, |
| 494 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)}, |
| 495 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)}, |
| 496 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)}, |
| 497 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)}, |
| 498 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)}, |
| 499 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)}, |
| 500 | |
| 501 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)}, |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 502 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 503 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 504 | {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)}, |
| 505 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)}, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 506 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 507 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)}, |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 508 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 509 | {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 510 | |
| 511 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)}, |
| 512 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)}, |
| 513 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)}, |
Uday Kishore Pasupuleti | e9ef478 | 2015-09-21 08:33:55 -0700 | [diff] [blame] | 514 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 515 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)}, |
| 516 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 517 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)}, |
| 518 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)}, |
| 519 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)}, |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 520 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)}, |
| 521 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)}, |
| 522 | |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 523 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 524 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 525 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)}, |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 526 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)}, |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 527 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)}, |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 528 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)}, |
| 529 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)}, |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 530 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)}, |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 531 | {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)}, |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 532 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)}, |
| 533 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)}, |
| 534 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)}, |
| 535 | {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)}, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 536 | |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 537 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)}, |
| 538 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)}, |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 539 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)}, |
| 540 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)}, |
| 541 | {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)}, |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 542 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 543 | {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)}, |
| 544 | {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)}, |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 545 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)}, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 546 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)}, |
| 547 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)}, |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 548 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)}, |
| 549 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 550 | }; |
| 551 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 552 | static char * backend_tag_table[SND_DEVICE_MAX] = {0}; |
| 553 | static char * hw_interface_table[SND_DEVICE_MAX] = {0}; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 554 | |
| 555 | static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = { |
| 556 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)}, |
| 557 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)}, |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 558 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 559 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)}, |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 560 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)}, |
| 561 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)}, |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 562 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 563 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD)}, |
| 564 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)}, |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 565 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)}, |
Haynes Mathew George | 569b748 | 2017-05-08 14:44:27 -0700 | [diff] [blame] | 566 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 567 | {TO_NAME_INDEX(USECASE_VOICE_CALL)}, |
| 568 | {TO_NAME_INDEX(USECASE_VOICE2_CALL)}, |
| 569 | {TO_NAME_INDEX(USECASE_VOLTE_CALL)}, |
| 570 | {TO_NAME_INDEX(USECASE_QCHAT_CALL)}, |
| 571 | {TO_NAME_INDEX(USECASE_VOWLAN_CALL)}, |
John Muir | f1346ce | 2016-12-06 00:03:41 -0800 | [diff] [blame] | 572 | {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)}, |
| 573 | {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 574 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)}, |
| 575 | {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)}, |
| 576 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)}, |
| 577 | {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)}, |
John Muir | f1346ce | 2016-12-06 00:03:41 -0800 | [diff] [blame] | 578 | {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)}, |
| 579 | {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)}, |
| 580 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)}, |
| 581 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)}, |
| 582 | {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)}, |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 583 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)}, |
| 584 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 585 | }; |
| 586 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 587 | static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = { |
| 588 | {TO_NAME_INDEX(PCM_PLAYBACK)}, |
| 589 | {TO_NAME_INDEX(PCM_CAPTURE)}, |
| 590 | {TO_NAME_INDEX(VOICE_CALL)}, |
| 591 | {TO_NAME_INDEX(PCM_HFP_CALL)}, |
| 592 | }; |
| 593 | |
| 594 | struct app_type_entry { |
| 595 | int uc_type; |
| 596 | int bit_width; |
| 597 | int app_type; |
| 598 | int max_rate; |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 599 | char *mode; |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 600 | struct listnode node; // membership in app_type_entry_list; |
| 601 | }; |
| 602 | |
| 603 | static struct listnode app_type_entry_list; |
| 604 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 605 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 606 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 607 | #define ULL_PLATFORM_DELAY (3*1000LL) |
| 608 | #define MMAP_PLATFORM_DELAY (3*1000LL) |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 609 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 610 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 611 | static bool is_tmus = false; |
| 612 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 613 | static int init_be_dai_name_table(struct audio_device *adev); |
| 614 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 615 | static void check_operator() |
| 616 | { |
| 617 | char value[PROPERTY_VALUE_MAX]; |
| 618 | int mccmnc; |
| 619 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 620 | mccmnc = atoi(value); |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 621 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 622 | switch(mccmnc) { |
| 623 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 624 | case 310490: |
| 625 | case 310260: |
| 626 | case 310026: |
sangwon.jeon | b891db5 | 2013-09-14 17:39:15 +0900 | [diff] [blame] | 627 | /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */ |
| 628 | case 310800: |
| 629 | case 310660: |
| 630 | case 310580: |
| 631 | case 310310: |
| 632 | case 310270: |
| 633 | case 310250: |
| 634 | case 310240: |
| 635 | case 310230: |
| 636 | case 310220: |
| 637 | case 310210: |
| 638 | case 310200: |
| 639 | case 310160: |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 640 | is_tmus = true; |
| 641 | break; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | bool is_operator_tmus() |
| 646 | { |
| 647 | pthread_once(&check_op_once_ctl, check_operator); |
| 648 | return is_tmus; |
| 649 | } |
| 650 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 651 | static char *get_current_operator() |
| 652 | { |
| 653 | struct listnode *node; |
| 654 | struct operator_info *info_item; |
| 655 | char mccmnc[PROPERTY_VALUE_MAX]; |
| 656 | char *ret = NULL; |
| 657 | |
Tom Cherry | 7fea204 | 2016-11-10 18:05:59 -0800 | [diff] [blame] | 658 | property_get("gsm.sim.operator.numeric",mccmnc,"00000"); |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 659 | |
| 660 | list_for_each(node, &operator_info_list) { |
| 661 | info_item = node_to_item(node, struct operator_info, list); |
| 662 | if (strstr(info_item->mccmnc, mccmnc) != NULL) { |
| 663 | ret = info_item->name; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device) |
| 671 | { |
| 672 | struct listnode *node; |
| 673 | struct operator_specific_device *ret = NULL; |
| 674 | struct operator_specific_device *device_item; |
| 675 | char *operator_name; |
| 676 | |
| 677 | operator_name = get_current_operator(); |
| 678 | if (operator_name == NULL) |
| 679 | return ret; |
| 680 | |
| 681 | list_for_each(node, operator_specific_device_table[snd_device]) { |
| 682 | device_item = node_to_item(node, struct operator_specific_device, list); |
| 683 | if (strcmp(operator_name, device_item->operator) == 0) { |
| 684 | ret = device_item; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | return ret; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | static int get_operator_specific_device_acdb_id(snd_device_t snd_device) |
| 693 | { |
| 694 | struct operator_specific_device *device; |
| 695 | int ret = acdb_device_table[snd_device]; |
| 696 | |
| 697 | device = get_operator_specific_device(snd_device); |
| 698 | if (device != NULL) |
| 699 | ret = device->acdb_id; |
| 700 | |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device) |
| 705 | { |
| 706 | struct operator_specific_device *device; |
| 707 | const char *ret = device_table[snd_device]; |
| 708 | |
| 709 | device = get_operator_specific_device(snd_device); |
| 710 | if (device != NULL) |
| 711 | ret = device->mixer_path; |
| 712 | |
| 713 | return ret; |
| 714 | } |
| 715 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 716 | inline bool platform_supports_app_type_cfg() |
| 717 | { |
| 718 | #ifdef PLATFORM_MSM8998 |
| 719 | return true; |
| 720 | #else |
| 721 | return false; |
| 722 | #endif |
| 723 | } |
| 724 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 725 | bool platform_send_gain_dep_cal(void *platform, int level) |
| 726 | { |
| 727 | bool ret_val = false; |
| 728 | struct platform_data *my_data = (struct platform_data *)platform; |
| 729 | struct audio_device *adev = my_data->adev; |
| 730 | int acdb_dev_id, app_type; |
| 731 | int acdb_dev_type = MSM_SNDDEV_CAP_RX; |
| 732 | int mode = CAL_MODE_RTAC; |
| 733 | struct listnode *node; |
| 734 | struct audio_usecase *usecase; |
Haynes Mathew George | 67486e2 | 2017-06-26 12:58:38 -0700 | [diff] [blame] | 735 | bool valid_uc_type; |
| 736 | bool valid_dev; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 737 | |
| 738 | if (my_data->acdb_send_gain_dep_cal == NULL) { |
| 739 | ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__); |
| 740 | return ret_val; |
| 741 | } |
| 742 | |
| 743 | if (!voice_is_in_call(adev)) { |
| 744 | ALOGV("%s: Not Voice call usecase, apply new cal for level %d", |
| 745 | __func__, level); |
| 746 | app_type = DEFAULT_APP_TYPE_RX_PATH; |
| 747 | |
| 748 | // find the current active sound device |
| 749 | list_for_each(node, &adev->usecase_list) { |
| 750 | usecase = node_to_item(node, struct audio_usecase, list); |
Haynes Mathew George | 67486e2 | 2017-06-26 12:58:38 -0700 | [diff] [blame] | 751 | LOG_ALWAYS_FATAL_IF(usecase == NULL, |
| 752 | "unxpected NULL usecase in usecase_list"); |
| 753 | valid_uc_type = usecase->type == PCM_PLAYBACK; |
| 754 | valid_dev = false; |
| 755 | if (valid_uc_type) { |
| 756 | audio_devices_t dev = usecase->stream.out->devices; |
| 757 | valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER || |
| 758 | dev == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 759 | dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE); |
| 760 | } |
| 761 | if (valid_dev) { |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 762 | ALOGV("%s: out device is %d", __func__, usecase->out_snd_device); |
| 763 | if (audio_extn_spkr_prot_is_enabled()) { |
vivek mehta | 4cb8298 | 2015-07-13 12:05:49 -0700 | [diff] [blame] | 764 | acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device); |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 765 | } else { |
| 766 | acdb_dev_id = acdb_device_table[usecase->out_snd_device]; |
| 767 | } |
vivek mehta | 4cb8298 | 2015-07-13 12:05:49 -0700 | [diff] [blame] | 768 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 769 | if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type, |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 770 | acdb_dev_type, mode, level)) { |
| 771 | // set ret_val true if at least one calibration is set successfully |
| 772 | ret_val = true; |
| 773 | } else { |
| 774 | ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__); |
| 775 | } |
| 776 | } else { |
| 777 | ALOGW("%s: Usecase list is empty", __func__); |
| 778 | } |
| 779 | } |
| 780 | } else { |
| 781 | ALOGW("%s: Voice call in progress .. ignore setting new cal", |
| 782 | __func__); |
| 783 | } |
| 784 | return ret_val; |
| 785 | } |
| 786 | |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 787 | void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 788 | { |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 789 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 790 | snd_device_t snd_device = SND_DEVICE_NONE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 791 | |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 792 | if (strcmp(my_data->ec_ref_mixer_path, "")) { |
| 793 | ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path); |
| 794 | audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path); |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 795 | } |
| 796 | |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 797 | if (enable) { |
| 798 | strcpy(my_data->ec_ref_mixer_path, "echo-reference"); |
| 799 | if (out_device != AUDIO_DEVICE_NONE) { |
| 800 | snd_device = platform_get_output_snd_device(adev->platform, out_device); |
| 801 | platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device); |
| 802 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 803 | |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 804 | ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path); |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 805 | audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path); |
| 806 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 809 | static struct csd_data *open_csd_client(bool i2s_ext_modem) |
| 810 | { |
| 811 | struct csd_data *csd = calloc(1, sizeof(struct csd_data)); |
| 812 | |
| 813 | csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 814 | if (csd->csd_client == NULL) { |
| 815 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 816 | goto error; |
| 817 | } else { |
| 818 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 819 | |
| 820 | csd->deinit = (deinit_t)dlsym(csd->csd_client, |
| 821 | "csd_client_deinit"); |
| 822 | if (csd->deinit == NULL) { |
| 823 | ALOGE("%s: dlsym error %s for csd_client_deinit", __func__, |
| 824 | dlerror()); |
| 825 | goto error; |
| 826 | } |
| 827 | csd->disable_device = (disable_device_t)dlsym(csd->csd_client, |
| 828 | "csd_client_disable_device"); |
| 829 | if (csd->disable_device == NULL) { |
| 830 | ALOGE("%s: dlsym error %s for csd_client_disable_device", |
| 831 | __func__, dlerror()); |
| 832 | goto error; |
| 833 | } |
| 834 | csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client, |
| 835 | "csd_client_enable_device_config"); |
| 836 | if (csd->enable_device_config == NULL) { |
| 837 | ALOGE("%s: dlsym error %s for csd_client_enable_device_config", |
| 838 | __func__, dlerror()); |
| 839 | goto error; |
| 840 | } |
| 841 | csd->enable_device = (enable_device_t)dlsym(csd->csd_client, |
| 842 | "csd_client_enable_device"); |
| 843 | if (csd->enable_device == NULL) { |
| 844 | ALOGE("%s: dlsym error %s for csd_client_enable_device", |
| 845 | __func__, dlerror()); |
| 846 | goto error; |
| 847 | } |
| 848 | csd->start_voice = (start_voice_t)dlsym(csd->csd_client, |
| 849 | "csd_client_start_voice"); |
| 850 | if (csd->start_voice == NULL) { |
| 851 | ALOGE("%s: dlsym error %s for csd_client_start_voice", |
| 852 | __func__, dlerror()); |
| 853 | goto error; |
| 854 | } |
| 855 | csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client, |
| 856 | "csd_client_stop_voice"); |
| 857 | if (csd->stop_voice == NULL) { |
| 858 | ALOGE("%s: dlsym error %s for csd_client_stop_voice", |
| 859 | __func__, dlerror()); |
| 860 | goto error; |
| 861 | } |
| 862 | csd->volume = (volume_t)dlsym(csd->csd_client, |
| 863 | "csd_client_volume"); |
| 864 | if (csd->volume == NULL) { |
| 865 | ALOGE("%s: dlsym error %s for csd_client_volume", |
| 866 | __func__, dlerror()); |
| 867 | goto error; |
| 868 | } |
| 869 | csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client, |
| 870 | "csd_client_mic_mute"); |
| 871 | if (csd->mic_mute == NULL) { |
| 872 | ALOGE("%s: dlsym error %s for csd_client_mic_mute", |
| 873 | __func__, dlerror()); |
| 874 | goto error; |
| 875 | } |
| 876 | csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client, |
| 877 | "csd_client_slow_talk"); |
| 878 | if (csd->slow_talk == NULL) { |
| 879 | ALOGE("%s: dlsym error %s for csd_client_slow_talk", |
| 880 | __func__, dlerror()); |
| 881 | goto error; |
| 882 | } |
| 883 | csd->start_playback = (start_playback_t)dlsym(csd->csd_client, |
| 884 | "csd_client_start_playback"); |
| 885 | if (csd->start_playback == NULL) { |
| 886 | ALOGE("%s: dlsym error %s for csd_client_start_playback", |
| 887 | __func__, dlerror()); |
| 888 | goto error; |
| 889 | } |
| 890 | csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client, |
| 891 | "csd_client_stop_playback"); |
| 892 | if (csd->stop_playback == NULL) { |
| 893 | ALOGE("%s: dlsym error %s for csd_client_stop_playback", |
| 894 | __func__, dlerror()); |
| 895 | goto error; |
| 896 | } |
| 897 | csd->start_record = (start_record_t)dlsym(csd->csd_client, |
| 898 | "csd_client_start_record"); |
| 899 | if (csd->start_record == NULL) { |
| 900 | ALOGE("%s: dlsym error %s for csd_client_start_record", |
| 901 | __func__, dlerror()); |
| 902 | goto error; |
| 903 | } |
| 904 | csd->stop_record = (stop_record_t)dlsym(csd->csd_client, |
| 905 | "csd_client_stop_record"); |
| 906 | if (csd->stop_record == NULL) { |
| 907 | ALOGE("%s: dlsym error %s for csd_client_stop_record", |
| 908 | __func__, dlerror()); |
| 909 | goto error; |
| 910 | } |
| 911 | |
| 912 | csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client, |
| 913 | "csd_client_get_sample_rate"); |
| 914 | if (csd->get_sample_rate == NULL) { |
| 915 | ALOGE("%s: dlsym error %s for csd_client_get_sample_rate", |
| 916 | __func__, dlerror()); |
| 917 | |
| 918 | goto error; |
| 919 | } |
| 920 | |
| 921 | csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init"); |
| 922 | |
| 923 | if (csd->init == NULL) { |
| 924 | ALOGE("%s: dlsym error %s for csd_client_init", |
| 925 | __func__, dlerror()); |
| 926 | goto error; |
| 927 | } else { |
| 928 | csd->init(i2s_ext_modem); |
| 929 | } |
| 930 | } |
| 931 | return csd; |
| 932 | |
| 933 | error: |
| 934 | free(csd); |
| 935 | csd = NULL; |
| 936 | return csd; |
| 937 | } |
| 938 | |
| 939 | void close_csd_client(struct csd_data *csd) |
| 940 | { |
| 941 | if (csd != NULL) { |
| 942 | csd->deinit(); |
| 943 | dlclose(csd->csd_client); |
| 944 | free(csd); |
| 945 | csd = NULL; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | static void platform_csd_init(struct platform_data *my_data) |
| 950 | { |
| 951 | #ifdef PLATFORM_MSM8084 |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 952 | int32_t modems, (*count_modems)(void); |
| 953 | const char *name = "libdetectmodem.so"; |
| 954 | const char *func = "count_modems"; |
| 955 | const char *error; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 956 | |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 957 | my_data->csd = NULL; |
| 958 | |
| 959 | void *lib = dlopen(name, RTLD_NOW); |
| 960 | error = dlerror(); |
| 961 | if (!lib) { |
| 962 | ALOGE("%s: could not find %s: %s", __func__, name, error); |
| 963 | return; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 964 | } |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 965 | |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 966 | count_modems = NULL; |
| 967 | *(void **)(&count_modems) = dlsym(lib, func); |
| 968 | error = dlerror(); |
| 969 | if (!count_modems) { |
| 970 | ALOGE("%s: could not find symbol %s in %s: %s", |
| 971 | __func__, func, name, error); |
| 972 | goto done; |
| 973 | } |
| 974 | |
| 975 | modems = count_modems(); |
| 976 | if (modems < 0) { |
| 977 | ALOGE("%s: count_modems failed\n", __func__); |
| 978 | goto done; |
| 979 | } |
| 980 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 981 | ALOGD("%s: num_modems %d\n", __func__, modems); |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 982 | if (modems > 0) |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 983 | my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/); |
Iliyan Malchev | ae9a10c | 2014-08-09 13:07:21 -0700 | [diff] [blame] | 984 | |
| 985 | done: |
| 986 | dlclose(lib); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 987 | #else |
| 988 | my_data->csd = NULL; |
| 989 | #endif |
| 990 | } |
| 991 | |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 992 | static void set_platform_defaults(struct platform_data * my_data) |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 993 | { |
| 994 | int32_t dev; |
| 995 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 996 | backend_tag_table[dev] = NULL; |
| 997 | hw_interface_table[dev] = NULL; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 998 | operator_specific_device_table[dev] = NULL; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1001 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 1002 | backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 1003 | } |
| 1004 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1005 | // To overwrite these go to the audio_platform_info.xml file. |
| 1006 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco"); |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 1007 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1008 | backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco"); |
| 1009 | backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi"); |
| 1010 | backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi"); |
| 1011 | backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb"); |
| 1012 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb"); |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 1013 | backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1014 | backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy"); |
| 1015 | backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy"); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1016 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1017 | backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset"); |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 1018 | backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1019 | backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones"); |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 1020 | backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1021 | backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = |
| 1022 | strdup("speaker-and-usb-headphones"); |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 1023 | backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = |
| 1024 | strdup("speaker-safe-and-usb-headphones"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1025 | backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic"); |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 1026 | backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic"); |
| 1027 | backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic"); |
| 1028 | backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic"); |
| 1029 | backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1030 | hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 1031 | hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX"); |
| 1032 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX"); |
| 1033 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX"); |
| 1034 | hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 1035 | hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX"); |
| 1036 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 1037 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1038 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 1039 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1040 | hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 1041 | hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX"); |
| 1042 | hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX"); |
| 1043 | hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 1044 | hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX"); |
| 1045 | hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX"); |
| 1046 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX"); |
| 1047 | hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX"); |
| 1048 | hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX"); |
| 1049 | hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX"); |
| 1050 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 1051 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX"); |
| 1052 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1053 | hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX"); |
Haynes Mathew George | e95340e | 2017-05-24 15:42:06 -0700 | [diff] [blame] | 1054 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX"); |
| 1055 | hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX"); |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 1056 | hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1057 | hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX"); |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 1058 | hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX"); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1059 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX"); |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 1060 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX"); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1061 | hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX"); |
| 1062 | hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX"); |
| 1063 | hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX"); |
Haynes Mathew George | e95340e | 2017-05-24 15:42:06 -0700 | [diff] [blame] | 1064 | hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX"); |
| 1065 | hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX"); |
| 1066 | hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX"); |
| 1067 | hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX"); |
| 1068 | hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX"); |
| 1069 | hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX"); |
| 1070 | hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX"); |
| 1071 | hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX"); |
| 1072 | hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX"); |
| 1073 | hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX"); |
| 1074 | hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX"); |
| 1075 | hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX"); |
Haynes Mathew George | c2f805c | 2017-06-27 11:28:35 -0700 | [diff] [blame^] | 1076 | hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX"); |
| 1077 | hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX"); |
| 1078 | hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX"); |
| 1079 | hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX"); |
| 1080 | hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX"); |
| 1081 | hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX"); |
| 1082 | hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX"); |
| 1083 | hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX"); |
| 1084 | hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX"); |
| 1085 | hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX"); |
| 1086 | hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX"); |
| 1087 | hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX"); |
| 1088 | hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX"); |
| 1089 | hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX"); |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 1090 | my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1093 | void get_cvd_version(char *cvd_version, struct audio_device *adev) |
| 1094 | { |
| 1095 | struct mixer_ctl *ctl; |
| 1096 | int count; |
| 1097 | int ret = 0; |
| 1098 | |
| 1099 | ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL); |
| 1100 | if (!ctl) { |
| 1101 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL); |
| 1102 | goto done; |
| 1103 | } |
| 1104 | mixer_ctl_update(ctl); |
| 1105 | |
| 1106 | count = mixer_ctl_get_num_values(ctl); |
| 1107 | if (count > MAX_CVD_VERSION_STRING_SIZE) |
| 1108 | count = MAX_CVD_VERSION_STRING_SIZE - 1; |
| 1109 | |
| 1110 | ret = mixer_ctl_get_array(ctl, cvd_version, count); |
| 1111 | if (ret != 0) { |
| 1112 | ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__); |
| 1113 | goto done; |
| 1114 | } |
| 1115 | |
| 1116 | done: |
| 1117 | return; |
| 1118 | } |
| 1119 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1120 | static int platform_acdb_init(void *platform) |
| 1121 | { |
| 1122 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1123 | struct audio_device *adev = my_data->adev; |
| 1124 | |
| 1125 | if (!my_data->acdb_init) { |
| 1126 | ALOGE("%s: no acdb_init fn provided", __func__); |
| 1127 | return -1; |
| 1128 | } |
| 1129 | |
| 1130 | if (my_data->acdb_initialized) { |
| 1131 | ALOGW("acdb is already initialized"); |
| 1132 | return 0; |
| 1133 | } |
| 1134 | |
Thierry Strudel | 92232b4 | 2017-01-26 10:51:48 -0800 | [diff] [blame] | 1135 | #if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1136 | char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE); |
| 1137 | if (!cvd_version) |
| 1138 | ALOGE("failed to allocate cvd_version"); |
| 1139 | else { |
| 1140 | get_cvd_version(cvd_version, adev); |
| 1141 | my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0); |
| 1142 | free(cvd_version); |
| 1143 | } |
| 1144 | #elif defined (PLATFORM_MSM8084) |
| 1145 | my_data->acdb_init((char *)my_data->snd_card_name); |
| 1146 | #else |
| 1147 | my_data->acdb_init(); |
| 1148 | #endif |
| 1149 | my_data->acdb_initialized = true; |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1153 | static void |
| 1154 | platform_backend_config_init(struct platform_data *pdata) |
| 1155 | { |
| 1156 | int i; |
| 1157 | |
| 1158 | /* initialize backend config */ |
| 1159 | for (i = 0; i < MAX_CODEC_BACKENDS; i++) { |
| 1160 | pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 1161 | pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 1162 | pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS; |
| 1163 | |
| 1164 | if (i > MAX_RX_CODEC_BACKENDS) |
| 1165 | pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS; |
| 1166 | |
| 1167 | pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL; |
| 1168 | pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL; |
| 1169 | pdata->current_backend_cfg[i].channels_mixer_ctl = NULL; |
| 1170 | } |
| 1171 | |
| 1172 | pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl = |
| 1173 | strdup("SLIM_0_RX Format"); |
| 1174 | pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl = |
| 1175 | strdup("SLIM_0_RX SampleRate"); |
| 1176 | |
| 1177 | pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl = |
| 1178 | strdup("SLIM_0_TX Format"); |
| 1179 | pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl = |
| 1180 | strdup("SLIM_0_TX SampleRate"); |
| 1181 | |
| 1182 | pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl = |
| 1183 | strdup("USB_AUDIO_TX Format"); |
| 1184 | pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl = |
| 1185 | strdup("USB_AUDIO_TX SampleRate"); |
| 1186 | pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl = |
| 1187 | strdup("USB_AUDIO_TX Channels"); |
| 1188 | |
| 1189 | pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl = |
| 1190 | strdup("SLIM_6_RX Format"); |
| 1191 | pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl = |
| 1192 | strdup("SLIM_6_RX SampleRate"); |
| 1193 | |
| 1194 | pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl = |
| 1195 | strdup("USB_AUDIO_RX Format"); |
| 1196 | pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl = |
| 1197 | strdup("USB_AUDIO_RX SampleRate"); |
| 1198 | |
| 1199 | pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1; |
| 1200 | pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl = |
| 1201 | strdup("USB_AUDIO_RX Channels"); |
| 1202 | } |
| 1203 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1204 | static int |
| 1205 | platform_backend_app_type_cfg_init(struct platform_data *pdata, |
| 1206 | struct mixer *mixer) |
| 1207 | { |
| 1208 | size_t app_type_cfg[128] = {0}; |
| 1209 | int length, num_app_types = 0; |
| 1210 | struct mixer_ctl *ctl = NULL; |
| 1211 | |
| 1212 | const char *mixer_ctl_name = "App Type Config"; |
| 1213 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 1214 | if (!ctl) { |
| 1215 | ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); |
| 1216 | return -1; |
| 1217 | } |
| 1218 | |
| 1219 | length = 1; // reserve index 0 for number of app types |
| 1220 | |
| 1221 | struct listnode *node; |
| 1222 | struct app_type_entry *entry; |
| 1223 | list_for_each(node, &app_type_entry_list) { |
| 1224 | entry = node_to_item(node, struct app_type_entry, node); |
| 1225 | app_type_cfg[length++] = entry->app_type; |
| 1226 | app_type_cfg[length++] = entry->max_rate; |
| 1227 | app_type_cfg[length++] = entry->bit_width; |
| 1228 | ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width); |
| 1229 | num_app_types += 1; |
| 1230 | } |
| 1231 | |
| 1232 | // default for capture |
| 1233 | int t; |
| 1234 | platform_get_default_app_type_v2(pdata, |
| 1235 | PCM_CAPTURE, |
| 1236 | &t); |
| 1237 | app_type_cfg[length++] = t; |
| 1238 | app_type_cfg[length++] = 48000; |
| 1239 | app_type_cfg[length++] = 16; |
| 1240 | num_app_types += 1; |
| 1241 | |
| 1242 | if (num_app_types) { |
| 1243 | app_type_cfg[0] = num_app_types; |
| 1244 | if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) { |
| 1245 | ALOGE("Failed to set app type cfg"); |
| 1246 | } |
| 1247 | } |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1251 | void *platform_init(struct audio_device *adev) |
| 1252 | { |
| 1253 | char value[PROPERTY_VALUE_MAX]; |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame] | 1254 | struct platform_data *my_data = NULL; |
| 1255 | int retry_num = 0, snd_card_num = 0, key = 0, ret = 0; |
| 1256 | bool dual_mic_config = false, use_default_mixer_path = true; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1257 | const char *snd_card_name; |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1258 | char *cvd_version = NULL; |
vivek mehta | 60ea415 | 2016-02-18 17:10:26 -0800 | [diff] [blame] | 1259 | char *snd_internal_name = NULL; |
| 1260 | char *tmp = NULL; |
| 1261 | char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0}; |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 1262 | char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0}; |
| 1263 | struct snd_card_split *snd_split_handle = NULL; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1264 | my_data = calloc(1, sizeof(struct platform_data)); |
| 1265 | |
| 1266 | my_data->adev = adev; |
| 1267 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1268 | list_init(&operator_info_list); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1269 | list_init(&app_type_entry_list); |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1270 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1271 | set_platform_defaults(my_data); |
| 1272 | |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1273 | // audio_extn_utils_get_snd_card_num does |
| 1274 | // - open mixer and get snd card name |
| 1275 | // - parse platform info xml file and check for valid snd card name |
| 1276 | // - on failure loop through all the active snd card |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 1277 | |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1278 | snd_card_num = audio_extn_utils_get_snd_card_num(); |
| 1279 | if (-1 == snd_card_num) { |
| 1280 | ALOGE("%s: invalid sound card number (-1), bailing out ", __func__); |
| 1281 | goto init_failed; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1284 | adev->mixer = mixer_open(snd_card_num); |
| 1285 | snd_card_name = mixer_get_name(adev->mixer); |
| 1286 | my_data->hw_info = hw_info_init(snd_card_name); |
| 1287 | |
| 1288 | audio_extn_set_snd_card_split(snd_card_name); |
| 1289 | snd_split_handle = audio_extn_get_snd_card_split(); |
| 1290 | |
| 1291 | /* Get the codec internal name from the sound card and/or form factor |
| 1292 | * name and form the mixer paths and platfor info file name dynamically. |
| 1293 | * This is generic way of picking any codec and forma factor name based |
| 1294 | * mixer and platform info files in future with no code change. |
| 1295 | |
| 1296 | * current code extends and looks for any of the exteneded mixer path and |
| 1297 | * platform info file present based on codec and form factor. |
| 1298 | |
| 1299 | * order of picking appropriate file is |
| 1300 | * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present |
| 1301 | * <ii> mixer_paths_<codec_name>.xml, if file not present |
| 1302 | * <iii> mixer_paths.xml |
| 1303 | |
| 1304 | * same order is followed for audio_platform_info.xml as well |
| 1305 | */ |
| 1306 | |
| 1307 | // need to carryforward old file name |
| 1308 | if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME, |
| 1309 | min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) { |
| 1310 | snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml", |
| 1311 | MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX ); |
| 1312 | } else { |
| 1313 | |
| 1314 | snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml", |
| 1315 | MIXER_XML_BASE_STRING, snd_split_handle->snd_card, |
| 1316 | snd_split_handle->form_factor); |
| 1317 | if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) { |
| 1318 | memset(mixer_xml_file, 0, sizeof(mixer_xml_file)); |
| 1319 | snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml", |
| 1320 | MIXER_XML_BASE_STRING, snd_split_handle->snd_card); |
| 1321 | |
| 1322 | if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) { |
| 1323 | memset(mixer_xml_file, 0, sizeof(mixer_xml_file)); |
| 1324 | strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH); |
| 1325 | audio_extn_utils_resolve_config_file(mixer_xml_file); |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | audio_extn_utils_get_platform_info(snd_card_name, platform_info_file); |
| 1331 | |
| 1332 | /* Initialize platform specific ids and/or backends*/ |
| 1333 | platform_info_init(platform_info_file, my_data); |
| 1334 | |
| 1335 | ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file); |
| 1336 | adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file); |
| 1337 | |
| 1338 | if (!adev->audio_route) { |
| 1339 | ALOGE("%s: Failed to init audio route controls, aborting.", __func__); |
| 1340 | mixer_close(adev->mixer); |
| 1341 | adev->mixer = NULL; |
| 1342 | hw_info_deinit(my_data->hw_info); |
| 1343 | my_data->hw_info = NULL; |
| 1344 | goto init_failed; |
| 1345 | } |
| 1346 | adev->snd_card = snd_card_num; |
| 1347 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 1348 | |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 1349 | //set max volume step for voice call |
| 1350 | property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX)); |
| 1351 | my_data->max_vol_index = atoi(value); |
| 1352 | |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1353 | property_get("persist.audio.dualmic.config",value,""); |
| 1354 | if (!strcmp("endfire", value)) { |
| 1355 | dual_mic_config = true; |
| 1356 | } |
| 1357 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1358 | my_data->source_mic_type = SOURCE_DUAL_MIC; |
| 1359 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1360 | my_data->fluence_in_spkr_mode = false; |
| 1361 | my_data->fluence_in_voice_call = false; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1362 | my_data->fluence_in_voice_comm = false; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1363 | my_data->fluence_in_voice_rec = false; |
| 1364 | |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1365 | property_get("ro.qc.sdk.audio.fluencetype", value, "none"); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1366 | if (!strcmp("fluencepro", value)) { |
| 1367 | my_data->fluence_type = FLUENCE_PRO_ENABLE; |
vivek mehta | 65ad12d | 2015-08-13 18:32:48 -0700 | [diff] [blame] | 1368 | } else if (!strcmp("fluence", value) || (dual_mic_config)) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1369 | my_data->fluence_type = FLUENCE_ENABLE; |
| 1370 | } else if (!strcmp("none", value)) { |
| 1371 | my_data->fluence_type = FLUENCE_DISABLE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1374 | if (my_data->fluence_type != FLUENCE_DISABLE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1375 | property_get("persist.audio.fluence.voicecall",value,""); |
| 1376 | if (!strcmp("true", value)) { |
| 1377 | my_data->fluence_in_voice_call = true; |
| 1378 | } |
| 1379 | |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 1380 | property_get("persist.audio.fluence.voicecomm",value,""); |
| 1381 | if (!strcmp("true", value)) { |
| 1382 | my_data->fluence_in_voice_comm = true; |
| 1383 | } |
| 1384 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1385 | property_get("persist.audio.fluence.voicerec",value,""); |
| 1386 | if (!strcmp("true", value)) { |
| 1387 | my_data->fluence_in_voice_rec = true; |
| 1388 | } |
| 1389 | |
| 1390 | property_get("persist.audio.fluence.speaker",value,""); |
| 1391 | if (!strcmp("true", value)) { |
| 1392 | my_data->fluence_in_spkr_mode = true; |
| 1393 | } |
| 1394 | } |
| 1395 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 1396 | // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic |
| 1397 | switch (my_data->max_mic_count) { |
| 1398 | case 4: |
| 1399 | my_data->source_mic_type |= SOURCE_QUAD_MIC; |
| 1400 | case 3: |
| 1401 | my_data->source_mic_type |= SOURCE_THREE_MIC; |
| 1402 | case 2: |
| 1403 | my_data->source_mic_type |= SOURCE_DUAL_MIC; |
| 1404 | case 1: |
| 1405 | my_data->source_mic_type |= SOURCE_MONO_MIC; |
| 1406 | break; |
| 1407 | default: |
| 1408 | ALOGE("%s: max_mic_count (%d), is not supported, setting to default", |
| 1409 | __func__, my_data->max_mic_count); |
| 1410 | my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC; |
| 1411 | break; |
| 1412 | } |
| 1413 | |
| 1414 | ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)" |
| 1415 | " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ", |
| 1416 | __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type, |
| 1417 | my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm, |
| 1418 | my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode); |
| 1419 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1420 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 1421 | if (my_data->acdb_handle == NULL) { |
| 1422 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 1423 | } else { |
| 1424 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 1425 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 1426 | "acdb_loader_deallocate_ACDB"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1427 | if (!my_data->acdb_deallocate) |
| 1428 | ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s", |
| 1429 | __func__, LIB_ACDB_LOADER); |
| 1430 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1431 | my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle, |
| 1432 | "acdb_loader_send_audio_cal_v3"); |
| 1433 | if (!my_data->acdb_send_audio_cal_v3) |
| 1434 | ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s", |
| 1435 | __func__, LIB_ACDB_LOADER); |
| 1436 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1437 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 1438 | "acdb_loader_send_audio_cal"); |
| 1439 | if (!my_data->acdb_send_audio_cal) |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1440 | ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1441 | __func__, LIB_ACDB_LOADER); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1442 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1443 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 1444 | "acdb_loader_send_voice_cal"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1445 | if (!my_data->acdb_send_voice_cal) |
| 1446 | ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s", |
| 1447 | __func__, LIB_ACDB_LOADER); |
| 1448 | |
| 1449 | my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle, |
| 1450 | "acdb_loader_reload_vocvoltable"); |
| 1451 | if (!my_data->acdb_reload_vocvoltable) |
| 1452 | ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s", |
| 1453 | __func__, LIB_ACDB_LOADER); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 1454 | |
| 1455 | my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle, |
| 1456 | "acdb_loader_send_gain_dep_cal"); |
| 1457 | if (!my_data->acdb_send_gain_dep_cal) |
| 1458 | ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s", |
| 1459 | __func__, LIB_ACDB_LOADER); |
| 1460 | |
Thierry Strudel | 92232b4 | 2017-01-26 10:51:48 -0800 | [diff] [blame] | 1461 | #if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1462 | acdb_init_v2_cvd_t acdb_init_local; |
| 1463 | acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle, |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1464 | "acdb_loader_init_v2"); |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1465 | if (acdb_init_local == NULL) |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1466 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, |
| 1467 | dlerror()); |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1468 | |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1469 | #elif defined (PLATFORM_MSM8084) |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1470 | acdb_init_v2_t acdb_init_local; |
| 1471 | acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle, |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1472 | "acdb_loader_init_v2"); |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1473 | if (acdb_init_local == NULL) |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1474 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, |
| 1475 | dlerror()); |
| 1476 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1477 | #else |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1478 | acdb_init_t acdb_init_local; |
| 1479 | acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1480 | "acdb_loader_init_ACDB"); |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1481 | if (acdb_init_local == NULL) |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1482 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, |
| 1483 | dlerror()); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1484 | #endif |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1485 | my_data->acdb_init = acdb_init_local; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1486 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1487 | my_data->acdb_send_custom_top = (acdb_send_custom_top_t) |
| 1488 | dlsym(my_data->acdb_handle, |
| 1489 | "acdb_loader_send_common_custom_topology"); |
| 1490 | |
| 1491 | if (!my_data->acdb_send_custom_top) |
| 1492 | ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s", |
| 1493 | __func__, LIB_ACDB_LOADER); |
| 1494 | |
vivek mehta | 0fb1131 | 2017-05-15 19:35:32 -0700 | [diff] [blame] | 1495 | int result = acdb_init(adev->snd_card); |
| 1496 | if (!result) { |
| 1497 | my_data->acdb_initialized = true; |
| 1498 | ALOGD("ACDB initialized"); |
| 1499 | } else { |
| 1500 | my_data->acdb_initialized = false; |
| 1501 | ALOGD("ACDB initialization failed"); |
| 1502 | } |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1503 | } |
Ravi Kumar Alamanda | 5c049df | 2015-07-01 16:23:03 +0900 | [diff] [blame] | 1504 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1505 | /* init usb */ |
| 1506 | audio_extn_usb_init(adev); |
| 1507 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1508 | audio_extn_spkr_prot_init(adev); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1509 | |
Ravi Kumar Alamanda | 7631557 | 2015-04-23 13:13:56 -0700 | [diff] [blame] | 1510 | audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle); |
| 1511 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1512 | /* load csd client */ |
| 1513 | platform_csd_init(my_data); |
| 1514 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1515 | platform_backend_config_init(my_data); |
| 1516 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1517 | init_be_dai_name_table(adev); |
| 1518 | |
| 1519 | if (platform_supports_app_type_cfg()) |
| 1520 | platform_backend_app_type_cfg_init(my_data, adev->mixer); |
| 1521 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1522 | return my_data; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1523 | |
| 1524 | init_failed: |
| 1525 | if (my_data) |
| 1526 | free(my_data); |
| 1527 | return NULL; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void platform_deinit(void *platform) |
| 1531 | { |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1532 | int32_t dev; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1533 | struct operator_info *info_item; |
| 1534 | struct operator_specific_device *device_item; |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1535 | struct app_type_entry *ap; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1536 | struct listnode *node; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1537 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1538 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1539 | close_csd_client(my_data->csd); |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1540 | |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 1541 | hw_info_deinit(my_data->hw_info); |
| 1542 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1543 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 1544 | if (backend_tag_table[dev]) |
| 1545 | free(backend_tag_table[dev]); |
| 1546 | if (hw_interface_table[dev]) |
| 1547 | free(hw_interface_table[dev]); |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1548 | if (operator_specific_device_table[dev]) { |
| 1549 | while (!list_empty(operator_specific_device_table[dev])) { |
| 1550 | node = list_head(operator_specific_device_table[dev]); |
| 1551 | list_remove(node); |
| 1552 | device_item = node_to_item(node, struct operator_specific_device, list); |
| 1553 | free(device_item->operator); |
| 1554 | free(device_item->mixer_path); |
| 1555 | free(device_item); |
| 1556 | } |
| 1557 | free(operator_specific_device_table[dev]); |
| 1558 | } |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | if (my_data->snd_card_name) |
| 1562 | free(my_data->snd_card_name); |
| 1563 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1564 | while (!list_empty(&operator_info_list)) { |
| 1565 | node = list_head(&operator_info_list); |
| 1566 | list_remove(node); |
| 1567 | info_item = node_to_item(node, struct operator_info, list); |
| 1568 | free(info_item->name); |
| 1569 | free(info_item->mccmnc); |
| 1570 | free(info_item); |
| 1571 | } |
| 1572 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1573 | while (!list_empty(&app_type_entry_list)) { |
| 1574 | node = list_head(&app_type_entry_list); |
| 1575 | list_remove(node); |
| 1576 | ap = node_to_item(node, struct app_type_entry, node); |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 1577 | if (ap->mode) free(ap->mode); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1578 | free(ap); |
| 1579 | } |
| 1580 | |
Kevin Rocard | e35d4af | 2017-05-02 16:55:28 -0700 | [diff] [blame] | 1581 | mixer_close(my_data->adev->mixer); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1582 | free(platform); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1583 | |
| 1584 | /* deinit usb */ |
| 1585 | audio_extn_usb_deinit(); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 1589 | { |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1590 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 1591 | if (operator_specific_device_table[snd_device] != NULL) { |
| 1592 | return get_operator_specific_device_mixer_path(snd_device); |
| 1593 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1594 | return device_table[snd_device]; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1595 | } else |
Ravi Kumar Alamanda | 6402646 | 2014-09-15 00:08:58 -0700 | [diff] [blame] | 1596 | return "none"; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 1599 | int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device, |
| 1600 | char *device_name) |
| 1601 | { |
| 1602 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1603 | |
David Benjamin | 1565f99 | 2016-09-21 12:10:34 -0400 | [diff] [blame] | 1604 | if (platform == NULL) { |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 1605 | ALOGW("%s: something wrong, use legacy get_snd_device name", __func__); |
David Benjamin | 1565f99 | 2016-09-21 12:10:34 -0400 | [diff] [blame] | 1606 | strlcpy(device_name, platform_get_snd_device_name(snd_device), |
| 1607 | DEVICE_NAME_MAX_SIZE); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 1608 | } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 1609 | if (operator_specific_device_table[snd_device] != NULL) { |
| 1610 | strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device), |
| 1611 | DEVICE_NAME_MAX_SIZE); |
| 1612 | } else { |
| 1613 | strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE); |
| 1614 | } |
| 1615 | hw_info_append_hw_type(my_data->hw_info, snd_device, device_name); |
| 1616 | } else { |
| 1617 | strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE); |
| 1618 | } |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1623 | void platform_add_backend_name(void *platform, char *mixer_path, |
| 1624 | snd_device_t snd_device) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1625 | { |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1626 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1627 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1628 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1629 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1630 | return; |
Ravi Kumar Alamanda | 1de6e5a | 2014-06-19 21:55:39 -0500 | [diff] [blame] | 1631 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1632 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1633 | const char * suffix = backend_tag_table[snd_device]; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (suffix != NULL) { |
| 1636 | strcat(mixer_path, " "); |
| 1637 | strcat(mixer_path, suffix); |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 1638 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1641 | bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2) |
| 1642 | { |
| 1643 | bool result = true; |
| 1644 | |
| 1645 | ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__, |
| 1646 | platform_get_snd_device_name(snd_device1), |
| 1647 | platform_get_snd_device_name(snd_device2)); |
| 1648 | |
| 1649 | if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) { |
| 1650 | ALOGE("%s: Invalid snd_device = %s", __func__, |
| 1651 | platform_get_snd_device_name(snd_device1)); |
| 1652 | return false; |
| 1653 | } |
| 1654 | if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) { |
| 1655 | ALOGE("%s: Invalid snd_device = %s", __func__, |
| 1656 | platform_get_snd_device_name(snd_device2)); |
| 1657 | return false; |
| 1658 | } |
| 1659 | const char * be_itf1 = hw_interface_table[snd_device1]; |
| 1660 | const char * be_itf2 = hw_interface_table[snd_device2]; |
| 1661 | |
| 1662 | if (NULL != be_itf1 && NULL != be_itf2) { |
Eric Laurent | e63e61d | 2015-09-10 12:19:33 -0700 | [diff] [blame] | 1663 | if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2))) |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1664 | result = false; |
| 1665 | } |
| 1666 | |
| 1667 | ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result); |
| 1668 | return result; |
| 1669 | } |
| 1670 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1671 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 1672 | { |
| 1673 | int device_id; |
| 1674 | if (device_type == PCM_PLAYBACK) |
| 1675 | device_id = pcm_device_table[usecase][0]; |
| 1676 | else |
| 1677 | device_id = pcm_device_table[usecase][1]; |
| 1678 | return device_id; |
| 1679 | } |
| 1680 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1681 | static int find_index(const struct name_to_index * table, int32_t len, |
| 1682 | const char * name) |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1683 | { |
| 1684 | int ret = 0; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1685 | int32_t i; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1686 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1687 | if (table == NULL) { |
| 1688 | ALOGE("%s: table is NULL", __func__); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1689 | ret = -ENODEV; |
| 1690 | goto done; |
| 1691 | } |
| 1692 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1693 | if (name == NULL) { |
| 1694 | ALOGE("null key"); |
| 1695 | ret = -ENODEV; |
| 1696 | goto done; |
| 1697 | } |
| 1698 | |
| 1699 | for (i=0; i < len; i++) { |
| 1700 | if (!strcmp(table[i].name, name)) { |
| 1701 | ret = table[i].index; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1702 | goto done; |
| 1703 | } |
| 1704 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1705 | ALOGE("%s: Could not find index for name = %s", |
| 1706 | __func__, name); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1707 | ret = -ENODEV; |
| 1708 | done: |
| 1709 | return ret; |
| 1710 | } |
| 1711 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1712 | int platform_get_snd_device_index(char *device_name) |
| 1713 | { |
| 1714 | return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name); |
| 1715 | } |
| 1716 | |
| 1717 | int platform_get_usecase_index(const char *usecase_name) |
| 1718 | { |
| 1719 | return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name); |
| 1720 | } |
| 1721 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1722 | void platform_add_operator_specific_device(snd_device_t snd_device, |
| 1723 | const char *operator, |
| 1724 | const char *mixer_path, |
| 1725 | unsigned int acdb_id) |
| 1726 | { |
| 1727 | struct operator_specific_device *device; |
| 1728 | |
| 1729 | if (operator_specific_device_table[snd_device] == NULL) { |
| 1730 | operator_specific_device_table[snd_device] = |
| 1731 | (struct listnode *)calloc(1, sizeof(struct listnode)); |
| 1732 | list_init(operator_specific_device_table[snd_device]); |
| 1733 | } |
| 1734 | |
| 1735 | device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device)); |
| 1736 | |
| 1737 | device->operator = strdup(operator); |
| 1738 | device->mixer_path = strdup(mixer_path); |
| 1739 | device->acdb_id = acdb_id; |
| 1740 | |
| 1741 | list_add_tail(operator_specific_device_table[snd_device], &device->list); |
| 1742 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 1743 | ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__, |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1744 | platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id); |
| 1745 | |
| 1746 | } |
| 1747 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1748 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id) |
| 1749 | { |
| 1750 | int ret = 0; |
| 1751 | |
| 1752 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1753 | ALOGE("%s: Invalid snd_device = %d", |
| 1754 | __func__, snd_device); |
| 1755 | ret = -EINVAL; |
| 1756 | goto done; |
| 1757 | } |
| 1758 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1759 | ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__, |
| 1760 | platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 1761 | acdb_device_table[snd_device] = acdb_id; |
| 1762 | done: |
| 1763 | return ret; |
| 1764 | } |
| 1765 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1766 | int platform_get_snd_device_acdb_id(snd_device_t snd_device) |
| 1767 | { |
| 1768 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1769 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1770 | return -EINVAL; |
| 1771 | } |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1772 | |
| 1773 | if (operator_specific_device_table[snd_device] != NULL) |
| 1774 | return get_operator_specific_device_acdb_id(snd_device); |
| 1775 | else |
| 1776 | return acdb_device_table[snd_device]; |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 1779 | static int platform_get_backend_index(snd_device_t snd_device) |
| 1780 | { |
| 1781 | int32_t port = DEFAULT_CODEC_BACKEND; |
| 1782 | |
| 1783 | if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) { |
| 1784 | if (backend_tag_table[snd_device] != NULL) { |
| 1785 | if (strncmp(backend_tag_table[snd_device], "headphones", |
| 1786 | sizeof("headphones")) == 0) |
| 1787 | port = HEADPHONE_BACKEND; |
| 1788 | else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0) |
| 1789 | port = HDMI_RX_BACKEND; |
| 1790 | else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) || |
| 1791 | (strcmp(backend_tag_table[snd_device], "usb-headset") == 0)) |
| 1792 | port = USB_AUDIO_RX_BACKEND; |
| 1793 | } |
| 1794 | } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) { |
| 1795 | port = DEFAULT_CODEC_TX_BACKEND; |
| 1796 | if (backend_tag_table[snd_device] != NULL) { |
| 1797 | if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0) |
| 1798 | port = USB_AUDIO_TX_BACKEND; |
| 1799 | else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL) |
| 1800 | port = BT_SCO_TX_BACKEND; |
| 1801 | } |
| 1802 | } else { |
| 1803 | ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device); |
| 1804 | } |
| 1805 | |
| 1806 | ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device); |
| 1807 | |
| 1808 | return port; |
| 1809 | } |
| 1810 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1811 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 1812 | { |
| 1813 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1814 | int acdb_dev_id, acdb_dev_type; |
| 1815 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1816 | if (platform_supports_app_type_cfg()) // use v2 instead |
| 1817 | return -ENOSYS; |
| 1818 | |
Ravi Kumar Alamanda | adf0f3b | 2015-06-04 02:34:02 -0700 | [diff] [blame] | 1819 | acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)]; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1820 | if (acdb_dev_id < 0) { |
| 1821 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 1822 | __func__, snd_device); |
| 1823 | return -EINVAL; |
| 1824 | } |
| 1825 | if (my_data->acdb_send_audio_cal) { |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 1826 | ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1827 | __func__, snd_device, acdb_dev_id); |
| 1828 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 1829 | snd_device < SND_DEVICE_OUT_END) |
| 1830 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 1831 | else |
| 1832 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 1833 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 1834 | } |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 1838 | int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase, |
| 1839 | int app_type, int sample_rate) |
| 1840 | { |
| 1841 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1842 | int acdb_dev_id, acdb_dev_type; |
| 1843 | int snd_device = SND_DEVICE_OUT_SPEAKER; |
| 1844 | int new_snd_device[SND_DEVICE_OUT_END] = {0}; |
| 1845 | int i, num_devices = 1; |
| 1846 | |
| 1847 | if (!platform_supports_app_type_cfg()) // use v1 instead |
| 1848 | return -ENOSYS; |
| 1849 | |
| 1850 | if (usecase->type == PCM_PLAYBACK) |
| 1851 | snd_device = usecase->out_snd_device; |
| 1852 | else if (usecase->type == PCM_CAPTURE) |
| 1853 | snd_device = usecase->in_snd_device; |
| 1854 | |
| 1855 | // skipped over get_spkr_prot_device |
| 1856 | acdb_dev_id = acdb_device_table[snd_device]; |
| 1857 | if (acdb_dev_id < 0) { |
| 1858 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 1859 | __func__, snd_device); |
| 1860 | return -EINVAL; |
| 1861 | } |
| 1862 | |
| 1863 | if (platform_can_split_snd_device(snd_device, |
| 1864 | &num_devices, new_snd_device) < 0) { |
| 1865 | new_snd_device[0] = snd_device; |
| 1866 | } |
| 1867 | |
| 1868 | for (i = 0; i < num_devices; i++) { |
| 1869 | acdb_dev_id = acdb_device_table[new_snd_device[i]]; |
| 1870 | if (acdb_dev_id < 0) { |
| 1871 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 1872 | __func__, new_snd_device[i]); |
| 1873 | return -EINVAL; |
| 1874 | } |
| 1875 | ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
| 1876 | __func__, new_snd_device[i], acdb_dev_id); |
| 1877 | if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN && |
| 1878 | new_snd_device[i] < SND_DEVICE_OUT_END) |
| 1879 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 1880 | else |
| 1881 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 1882 | |
| 1883 | if (my_data->acdb_send_audio_cal_v3) { |
| 1884 | my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type, |
| 1885 | app_type, sample_rate, i); |
| 1886 | } else if (my_data->acdb_send_audio_cal) { |
| 1887 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
| 1894 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1895 | int platform_switch_voice_call_device_pre(void *platform) |
| 1896 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1897 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1898 | int ret = 0; |
| 1899 | |
| 1900 | if (my_data->csd != NULL && |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 1901 | voice_is_in_call(my_data->adev)) { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1902 | /* This must be called before disabling mixer controls on APQ side */ |
| 1903 | ret = my_data->csd->disable_device(); |
| 1904 | if (ret < 0) { |
| 1905 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 1906 | __func__, ret); |
| 1907 | } |
| 1908 | } |
| 1909 | return ret; |
| 1910 | } |
| 1911 | |
| 1912 | int platform_switch_voice_call_enable_device_config(void *platform, |
| 1913 | snd_device_t out_snd_device, |
| 1914 | snd_device_t in_snd_device) |
| 1915 | { |
| 1916 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1917 | int acdb_rx_id, acdb_tx_id; |
| 1918 | int ret = 0; |
| 1919 | |
| 1920 | if (my_data->csd == NULL) |
| 1921 | return ret; |
| 1922 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1923 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1924 | audio_extn_spkr_prot_is_enabled()) |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1925 | acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1926 | else |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1927 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1928 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1929 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1930 | |
| 1931 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1932 | ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id); |
| 1933 | if (ret < 0) { |
| 1934 | ALOGE("%s: csd_enable_device_config, failed, error %d", |
| 1935 | __func__, ret); |
| 1936 | } |
| 1937 | } else { |
| 1938 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1939 | acdb_rx_id, acdb_tx_id); |
| 1940 | } |
| 1941 | |
| 1942 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | int platform_switch_voice_call_device_post(void *platform, |
| 1946 | snd_device_t out_snd_device, |
| 1947 | snd_device_t in_snd_device) |
| 1948 | { |
| 1949 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1950 | int acdb_rx_id, acdb_tx_id; |
| 1951 | |
| 1952 | if (my_data->acdb_send_voice_cal == NULL) { |
| 1953 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 1954 | } else { |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1955 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1956 | audio_extn_spkr_prot_is_enabled()) |
| 1957 | out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED; |
| 1958 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1959 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
| 1960 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1961 | |
| 1962 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 1963 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 1964 | else |
| 1965 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1966 | acdb_rx_id, acdb_tx_id); |
| 1967 | } |
| 1968 | |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1972 | int platform_switch_voice_call_usecase_route_post(void *platform, |
| 1973 | snd_device_t out_snd_device, |
| 1974 | snd_device_t in_snd_device) |
| 1975 | { |
| 1976 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1977 | int acdb_rx_id, acdb_tx_id; |
| 1978 | int ret = 0; |
| 1979 | |
| 1980 | if (my_data->csd == NULL) |
| 1981 | return ret; |
| 1982 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1983 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1984 | audio_extn_spkr_prot_is_enabled()) |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1985 | acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 1986 | else |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1987 | acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1988 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 1989 | acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 1990 | |
| 1991 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1992 | ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id, |
| 1993 | my_data->adev->acdb_settings); |
| 1994 | if (ret < 0) { |
| 1995 | ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret); |
| 1996 | } |
| 1997 | } else { |
| 1998 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1999 | acdb_rx_id, acdb_tx_id); |
| 2000 | } |
| 2001 | |
| 2002 | return ret; |
| 2003 | } |
| 2004 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2005 | int platform_start_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2006 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 2007 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2008 | int ret = 0; |
| 2009 | |
| 2010 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2011 | ret = my_data->csd->start_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 2012 | if (ret < 0) { |
| 2013 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 2014 | } |
| 2015 | } |
| 2016 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2019 | int platform_stop_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2020 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 2021 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2022 | int ret = 0; |
| 2023 | |
| 2024 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2025 | ret = my_data->csd->stop_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 2026 | if (ret < 0) { |
| 2027 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 2028 | } |
| 2029 | } |
| 2030 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2033 | int platform_get_sample_rate(void *platform, uint32_t *rate) |
| 2034 | { |
| 2035 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2036 | int ret = 0; |
| 2037 | |
| 2038 | if (my_data->csd != NULL) { |
| 2039 | ret = my_data->csd->get_sample_rate(rate); |
| 2040 | if (ret < 0) { |
| 2041 | ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret); |
| 2042 | } |
| 2043 | } |
| 2044 | return ret; |
| 2045 | } |
| 2046 | |
vivek mehta | b650641 | 2015-08-07 16:55:17 -0700 | [diff] [blame] | 2047 | void platform_set_speaker_gain_in_combo(struct audio_device *adev, |
| 2048 | snd_device_t snd_device, |
| 2049 | bool enable) |
| 2050 | { |
| 2051 | const char* name; |
| 2052 | switch (snd_device) { |
| 2053 | case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES: |
| 2054 | if (enable) |
| 2055 | name = "spkr-gain-in-headphone-combo"; |
| 2056 | else |
| 2057 | name = "speaker-gain-default"; |
| 2058 | break; |
| 2059 | case SND_DEVICE_OUT_SPEAKER_AND_LINE: |
| 2060 | if (enable) |
| 2061 | name = "spkr-gain-in-line-combo"; |
| 2062 | else |
| 2063 | name = "speaker-gain-default"; |
| 2064 | break; |
| 2065 | case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES: |
| 2066 | if (enable) |
| 2067 | name = "spkr-safe-gain-in-headphone-combo"; |
| 2068 | else |
| 2069 | name = "speaker-safe-gain-default"; |
| 2070 | break; |
| 2071 | case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE: |
| 2072 | if (enable) |
| 2073 | name = "spkr-safe-gain-in-line-combo"; |
| 2074 | else |
| 2075 | name = "speaker-safe-gain-default"; |
| 2076 | break; |
| 2077 | default: |
| 2078 | return; |
| 2079 | } |
| 2080 | |
| 2081 | audio_route_apply_and_update_path(adev->audio_route, name); |
| 2082 | } |
| 2083 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2084 | int platform_set_voice_volume(void *platform, int volume) |
| 2085 | { |
| 2086 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2087 | struct audio_device *adev = my_data->adev; |
| 2088 | struct mixer_ctl *ctl; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 2089 | const char *mixer_ctl_name = "Voice Rx Gain"; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2090 | int vol_index = 0, ret = 0; |
| 2091 | uint32_t set_values[ ] = {0, |
| 2092 | ALL_SESSION_VSID, |
| 2093 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2094 | |
| 2095 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 2096 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 2097 | // But this values don't changed in kernel. So, below change is need. |
keunhui.park | c5aaa0e | 2015-07-13 10:57:37 +0900 | [diff] [blame] | 2098 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2099 | set_values[0] = vol_index; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2100 | |
| 2101 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2102 | if (!ctl) { |
| 2103 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2104 | __func__, mixer_ctl_name); |
| 2105 | return -EINVAL; |
| 2106 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2107 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 2108 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 2109 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 2110 | if (my_data->csd != NULL) { |
| 2111 | ret = my_data->csd->volume(ALL_SESSION_VSID, volume, |
| 2112 | DEFAULT_VOLUME_RAMP_DURATION_MS); |
| 2113 | if (ret < 0) { |
| 2114 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 2115 | } |
| 2116 | } |
| 2117 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | int platform_set_mic_mute(void *platform, bool state) |
| 2121 | { |
| 2122 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2123 | struct audio_device *adev = my_data->adev; |
| 2124 | struct mixer_ctl *ctl; |
| 2125 | const char *mixer_ctl_name = "Voice Tx Mute"; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 2126 | int ret = 0; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2127 | uint32_t set_values[ ] = {0, |
| 2128 | ALL_SESSION_VSID, |
| 2129 | DEFAULT_MUTE_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2130 | |
Uday Kishore Pasupuleti | a1f4805 | 2015-09-08 22:49:18 +0900 | [diff] [blame] | 2131 | if (adev->mode != AUDIO_MODE_IN_CALL && |
| 2132 | adev->mode != AUDIO_MODE_IN_COMMUNICATION) |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2133 | return 0; |
| 2134 | |
Uday Kishore Pasupuleti | a1f4805 | 2015-09-08 22:49:18 +0900 | [diff] [blame] | 2135 | if (adev->enable_hfp) |
| 2136 | mixer_ctl_name = "HFP Tx Mute"; |
| 2137 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2138 | set_values[0] = state; |
| 2139 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2140 | if (!ctl) { |
| 2141 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2142 | __func__, mixer_ctl_name); |
| 2143 | return -EINVAL; |
| 2144 | } |
| 2145 | ALOGV("Setting voice mute state: %d", state); |
| 2146 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 2147 | |
| 2148 | if (my_data->csd != NULL) { |
| 2149 | ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state, |
| 2150 | DEFAULT_MUTE_RAMP_DURATION_MS); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 2151 | if (ret < 0) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2152 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 2153 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2154 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2155 | return ret; |
| 2156 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2157 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2158 | int platform_set_device_mute(void *platform, bool state, char *dir) |
| 2159 | { |
| 2160 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2161 | struct audio_device *adev = my_data->adev; |
| 2162 | struct mixer_ctl *ctl; |
| 2163 | char *mixer_ctl_name = NULL; |
| 2164 | int ret = 0; |
| 2165 | uint32_t set_values[ ] = {0, |
| 2166 | ALL_SESSION_VSID, |
| 2167 | 0}; |
| 2168 | if(dir == NULL) { |
| 2169 | ALOGE("%s: Invalid direction:%s", __func__, dir); |
| 2170 | return -EINVAL; |
| 2171 | } |
| 2172 | |
| 2173 | if (!strncmp("rx", dir, sizeof("rx"))) { |
| 2174 | mixer_ctl_name = "Voice Rx Device Mute"; |
| 2175 | } else if (!strncmp("tx", dir, sizeof("tx"))) { |
| 2176 | mixer_ctl_name = "Voice Tx Device Mute"; |
| 2177 | } else { |
| 2178 | return -EINVAL; |
| 2179 | } |
| 2180 | |
| 2181 | set_values[0] = state; |
| 2182 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2183 | if (!ctl) { |
| 2184 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2185 | __func__, mixer_ctl_name); |
| 2186 | return -EINVAL; |
| 2187 | } |
| 2188 | |
| 2189 | ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s", |
| 2190 | __func__,state, mixer_ctl_name); |
| 2191 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 2192 | |
| 2193 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2196 | int platform_can_split_snd_device(snd_device_t snd_device, |
| 2197 | int *num_devices, |
| 2198 | snd_device_t *new_snd_devices) |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2199 | { |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2200 | int ret = -EINVAL; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2201 | if (NULL == num_devices || NULL == new_snd_devices) { |
| 2202 | ALOGE("%s: NULL pointer ..", __func__); |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2203 | return -EINVAL; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /* |
| 2207 | * If wired headset/headphones/line devices share the same backend |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2208 | * with speaker/earpiece this routine returns -EINVAL. |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2209 | */ |
| 2210 | if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES && |
| 2211 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) { |
| 2212 | *num_devices = 2; |
| 2213 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 2214 | new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES; |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2215 | ret = 0; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2216 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE && |
| 2217 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) { |
| 2218 | *num_devices = 2; |
| 2219 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 2220 | new_snd_devices[1] = SND_DEVICE_OUT_LINE; |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2221 | ret = 0; |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 2222 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES && |
| 2223 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) { |
| 2224 | *num_devices = 2; |
| 2225 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE; |
| 2226 | new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES; |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2227 | ret = 0; |
Ravi Kumar Alamanda | 3b86d47 | 2015-06-08 00:35:57 -0700 | [diff] [blame] | 2228 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE && |
| 2229 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) { |
| 2230 | *num_devices = 2; |
| 2231 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE; |
| 2232 | new_snd_devices[1] = SND_DEVICE_OUT_LINE; |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2233 | ret = 0; |
Haynes Mathew George | 6dcb1a8 | 2016-12-21 12:38:55 -0800 | [diff] [blame] | 2234 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO && |
| 2235 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, |
| 2236 | SND_DEVICE_OUT_BT_SCO)) { |
| 2237 | *num_devices = 2; |
| 2238 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 2239 | new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO; |
| 2240 | ret = 0; |
| 2241 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB && |
| 2242 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, |
| 2243 | SND_DEVICE_OUT_BT_SCO_WB)) { |
| 2244 | *num_devices = 2; |
| 2245 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 2246 | new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB; |
| 2247 | ret = 0; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 2248 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET && |
| 2249 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) { |
| 2250 | *num_devices = 2; |
| 2251 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER; |
| 2252 | new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET; |
| 2253 | ret = 0; |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 2254 | } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET && |
| 2255 | !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) { |
| 2256 | *num_devices = 2; |
| 2257 | new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE; |
| 2258 | new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET; |
| 2259 | ret = 0; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2260 | } |
Haynes Mathew George | 2d809e0 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 2261 | return ret; |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2264 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 2265 | { |
| 2266 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2267 | struct audio_device *adev = my_data->adev; |
| 2268 | audio_mode_t mode = adev->mode; |
| 2269 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 2270 | |
| 2271 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 2272 | if (devices == AUDIO_DEVICE_NONE || |
| 2273 | devices & AUDIO_DEVICE_BIT_IN) { |
| 2274 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 2275 | goto exit; |
| 2276 | } |
| 2277 | |
Eric Laurent | 1b49155 | 2015-09-15 17:52:41 -0700 | [diff] [blame] | 2278 | if (popcount(devices) == 2) { |
| 2279 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 2280 | AUDIO_DEVICE_OUT_SPEAKER) || |
| 2281 | devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 2282 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 2283 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 2284 | } else if (devices == (AUDIO_DEVICE_OUT_LINE | |
| 2285 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 2286 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE; |
| 2287 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 2288 | AUDIO_DEVICE_OUT_SPEAKER_SAFE) || |
| 2289 | devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 2290 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 2291 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES; |
| 2292 | } else if (devices == (AUDIO_DEVICE_OUT_LINE | |
| 2293 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 2294 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE; |
| 2295 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 2296 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 2297 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
Haynes Mathew George | 6dcb1a8 | 2016-12-21 12:38:55 -0800 | [diff] [blame] | 2298 | } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) && |
| 2299 | ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) { |
| 2300 | snd_device = adev->bt_wb_speech_enabled ? |
| 2301 | SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB : |
| 2302 | SND_DEVICE_OUT_SPEAKER_AND_BT_SCO; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2303 | } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE | |
| 2304 | AUDIO_DEVICE_OUT_SPEAKER)) || |
| 2305 | (devices == (AUDIO_DEVICE_OUT_USB_HEADSET | |
| 2306 | AUDIO_DEVICE_OUT_SPEAKER))) { |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 2307 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET; |
Haynes Mathew George | 9090bfb | 2017-05-31 11:44:50 -0700 | [diff] [blame] | 2308 | } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE | |
| 2309 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
| 2310 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET; |
Eric Laurent | 1b49155 | 2015-09-15 17:52:41 -0700 | [diff] [blame] | 2311 | } else { |
| 2312 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 2313 | goto exit; |
| 2314 | } |
| 2315 | if (snd_device != SND_DEVICE_NONE) { |
| 2316 | goto exit; |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | if (popcount(devices) != 1) { |
| 2321 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 2322 | goto exit; |
| 2323 | } |
| 2324 | |
Madhuri Athota | 3f6051b | 2016-10-13 23:25:38 +0530 | [diff] [blame] | 2325 | if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2326 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2327 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 2328 | devices & AUDIO_DEVICE_OUT_LINE) { |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 2329 | if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2330 | (adev->voice.tty_mode == TTY_MODE_FULL)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2331 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 2332 | else if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2333 | (adev->voice.tty_mode == TTY_MODE_VCO)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2334 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
Ravi Kumar Alamanda | b09e4a0 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 2335 | else if (voice_is_in_call(adev) && |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2336 | (adev->voice.tty_mode == TTY_MODE_HCO)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2337 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2338 | else { |
| 2339 | if (devices & AUDIO_DEVICE_OUT_LINE) |
| 2340 | snd_device = SND_DEVICE_OUT_VOICE_LINE; |
| 2341 | else |
| 2342 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
| 2343 | } |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2344 | } else if (audio_is_usb_out_device(devices)) { |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 2345 | if (voice_is_in_call(adev)) { |
| 2346 | switch (adev->voice.tty_mode) { |
| 2347 | case TTY_MODE_FULL: |
| 2348 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB; |
| 2349 | break; |
| 2350 | case TTY_MODE_VCO: |
| 2351 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB; |
| 2352 | break; |
| 2353 | case TTY_MODE_HCO: |
| 2354 | // since Hearing will be on handset\speaker, use existing device |
| 2355 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 2356 | break; |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2357 | case TTY_MODE_OFF: |
| 2358 | break; |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 2359 | default: |
| 2360 | ALOGE("%s: Invalid TTY mode (%#x)", |
| 2361 | __func__, adev->voice.tty_mode); |
| 2362 | } |
| 2363 | } |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2364 | if (snd_device == SND_DEVICE_NONE) { |
| 2365 | snd_device = audio_extn_usb_is_capture_supported() ? |
| 2366 | SND_DEVICE_OUT_VOICE_USB_HEADSET : |
| 2367 | SND_DEVICE_OUT_VOICE_USB_HEADPHONES; |
| 2368 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2369 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2370 | if (adev->bt_wb_speech_enabled) { |
| 2371 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 2372 | } else { |
| 2373 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 2374 | } |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2375 | } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 2376 | if (!adev->enable_hfp) { |
| 2377 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 2378 | } else { |
| 2379 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP; |
| 2380 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2381 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 2382 | if(adev->voice.hac) |
| 2383 | snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET; |
| 2384 | else if (is_operator_tmus()) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2385 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
| 2386 | else |
Eric Laurent | b4d368e | 2014-06-25 10:21:54 -0500 | [diff] [blame] | 2387 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2388 | } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) |
| 2389 | snd_device = SND_DEVICE_OUT_VOICE_TX; |
| 2390 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2391 | if (snd_device != SND_DEVICE_NONE) { |
| 2392 | goto exit; |
| 2393 | } |
| 2394 | } |
| 2395 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2396 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 2397 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 2398 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2399 | } else if (devices & AUDIO_DEVICE_OUT_LINE) { |
| 2400 | snd_device = SND_DEVICE_OUT_LINE; |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2401 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) { |
| 2402 | snd_device = SND_DEVICE_OUT_SPEAKER_SAFE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2403 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2404 | if (my_data->speaker_lr_swap) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2405 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 2406 | else |
| 2407 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 2408 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2409 | if (adev->bt_wb_speech_enabled) { |
| 2410 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 2411 | } else { |
| 2412 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 2413 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2414 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 2415 | snd_device = SND_DEVICE_OUT_HDMI ; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2416 | } else if (audio_is_usb_out_device(devices)) { |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 2417 | if (audio_extn_usb_is_capture_supported()) |
| 2418 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
| 2419 | else |
| 2420 | snd_device = SND_DEVICE_OUT_USB_HEADPHONES; |
| 2421 | }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | 9d0d3f1 | 2014-07-25 12:40:29 -0500 | [diff] [blame] | 2422 | /*HAC support for voice-ish audio (eg visual voicemail)*/ |
| 2423 | if(adev->voice.hac) |
| 2424 | snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET; |
| 2425 | else |
| 2426 | snd_device = SND_DEVICE_OUT_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2427 | } else { |
| 2428 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 2429 | } |
| 2430 | exit: |
| 2431 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 2432 | return snd_device; |
| 2433 | } |
| 2434 | |
| 2435 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 2436 | { |
| 2437 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2438 | struct audio_device *adev = my_data->adev; |
| 2439 | audio_source_t source = (adev->active_input == NULL) ? |
| 2440 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 2441 | |
| 2442 | audio_mode_t mode = adev->mode; |
| 2443 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 2444 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 2445 | & ~AUDIO_DEVICE_BIT_IN; |
| 2446 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 2447 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 2448 | snd_device_t snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2449 | int channel_count = popcount(channel_mask); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2450 | |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2451 | ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)", |
| 2452 | __func__, out_device, in_device, channel_count, channel_mask); |
Devin Kim | d789e43 | 2016-10-26 15:07:27 -0700 | [diff] [blame] | 2453 | if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) || |
| 2454 | audio_extn_hfp_is_active(adev))) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2455 | if (adev->voice.tty_mode != TTY_MODE_OFF) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2456 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2457 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 2458 | out_device & AUDIO_DEVICE_OUT_LINE) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2459 | switch (adev->voice.tty_mode) { |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 2460 | case TTY_MODE_FULL: |
| 2461 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 2462 | break; |
| 2463 | case TTY_MODE_VCO: |
| 2464 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 2465 | break; |
| 2466 | case TTY_MODE_HCO: |
| 2467 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 2468 | break; |
| 2469 | default: |
| 2470 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode); |
| 2471 | } |
| 2472 | goto exit; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2473 | } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) { |
vivek mehta | a6b7974 | 2017-03-09 15:40:43 -0800 | [diff] [blame] | 2474 | switch (adev->voice.tty_mode) { |
| 2475 | case TTY_MODE_FULL: |
| 2476 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC; |
| 2477 | break; |
| 2478 | case TTY_MODE_VCO: |
| 2479 | // since voice will be captured from handset mic, use existing device |
| 2480 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 2481 | break; |
| 2482 | case TTY_MODE_HCO: |
| 2483 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC; |
| 2484 | break; |
| 2485 | default: |
| 2486 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2487 | } |
| 2488 | goto exit; |
| 2489 | } |
| 2490 | } |
Eric Laurent | b991fb0 | 2014-08-29 15:23:17 -0500 | [diff] [blame] | 2491 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2492 | if (my_data->fluence_in_voice_call == false) { |
| 2493 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2494 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2495 | if (is_operator_tmus()) |
| 2496 | snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2497 | else |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2498 | snd_device = SND_DEVICE_IN_VOICE_DMIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2499 | } |
| 2500 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 2501 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 2502 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2503 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2504 | if (adev->bluetooth_nrec) |
| 2505 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 2506 | else |
| 2507 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2508 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2509 | if (adev->bluetooth_nrec) |
| 2510 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 2511 | else |
| 2512 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2513 | } |
Eric Laurent | b991fb0 | 2014-08-29 15:23:17 -0500 | [diff] [blame] | 2514 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2515 | out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE || |
| 2516 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 2517 | out_device & AUDIO_DEVICE_OUT_LINE) { |
| 2518 | if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) { |
| 2519 | if (my_data->source_mic_type & SOURCE_DUAL_MIC) { |
| 2520 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC; |
| 2521 | } else { |
| 2522 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 2523 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2524 | } |
vivek mehta | fe121d5 | 2015-08-10 23:39:23 -0700 | [diff] [blame] | 2525 | |
| 2526 | //select default |
| 2527 | if (snd_device == SND_DEVICE_NONE) { |
Uday Kishore Pasupuleti | 7629719 | 2015-09-18 08:39:43 -0700 | [diff] [blame] | 2528 | if (!adev->enable_hfp) { |
| 2529 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 2530 | } else { |
| 2531 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP; |
| 2532 | platform_set_echo_reference(adev, true, out_device); |
| 2533 | } |
vivek mehta | fe121d5 | 2015-08-10 23:39:23 -0700 | [diff] [blame] | 2534 | } |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2535 | } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2536 | snd_device = SND_DEVICE_IN_VOICE_RX; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2537 | } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) { |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2538 | if (audio_extn_usb_is_capture_supported()) { |
| 2539 | snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC; |
| 2540 | } |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2541 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2542 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 2543 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 2544 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 2545 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 2546 | } |
| 2547 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 2548 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2549 | if (my_data->fluence_in_voice_rec && channel_count == 1) { |
| 2550 | if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) && |
| 2551 | (my_data->source_mic_type & SOURCE_QUAD_MIC)) { |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2552 | if (adev->active_input->enable_aec) |
| 2553 | snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC; |
| 2554 | else |
| 2555 | snd_device = SND_DEVICE_IN_HANDSET_QMIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2556 | } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) && |
| 2557 | (my_data->source_mic_type & SOURCE_THREE_MIC)) { |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2558 | if (adev->active_input->enable_aec) |
| 2559 | snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC; |
| 2560 | else |
| 2561 | snd_device = SND_DEVICE_IN_HANDSET_TMIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2562 | } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) || |
| 2563 | (my_data->fluence_type == FLUENCE_ENABLE)) && |
| 2564 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2565 | if (adev->active_input->enable_aec) |
| 2566 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC; |
| 2567 | else |
| 2568 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2569 | } |
| 2570 | platform_set_echo_reference(adev, true, out_device); |
| 2571 | } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) && |
| 2572 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
| 2573 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO; |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2574 | } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2575 | (my_data->source_mic_type & SOURCE_THREE_MIC)) { |
| 2576 | snd_device = SND_DEVICE_IN_THREE_MIC; |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2577 | } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2578 | (my_data->source_mic_type & SOURCE_QUAD_MIC)) { |
| 2579 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2580 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2581 | if (snd_device == SND_DEVICE_NONE) { |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 2582 | if (adev->active_input->enable_aec) { |
| 2583 | if (adev->active_input->enable_ns) { |
| 2584 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS; |
| 2585 | } else { |
| 2586 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC; |
| 2587 | } |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2588 | platform_set_echo_reference(adev, true, out_device); |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 2589 | } else if (adev->active_input->enable_ns) { |
| 2590 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS; |
| 2591 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2592 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
vivek mehta | f344068 | 2016-05-11 14:24:37 -0700 | [diff] [blame] | 2593 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2594 | } |
Jean-Michel Trivi | 8c83fe8 | 2015-09-25 15:06:53 -0700 | [diff] [blame] | 2595 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2596 | snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2597 | } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) { |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2598 | snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2599 | } |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2600 | } else if (source == AUDIO_SOURCE_UNPROCESSED) { |
| 2601 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2602 | if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) || |
| 2603 | (channel_mask == AUDIO_CHANNEL_IN_STEREO)) && |
| 2604 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
| 2605 | snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC; |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2606 | } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) && |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2607 | (my_data->source_mic_type & SOURCE_THREE_MIC)) { |
| 2608 | snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC; |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2609 | } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) && |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2610 | (my_data->source_mic_type & SOURCE_QUAD_MIC)) { |
| 2611 | snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC; |
| 2612 | } else { |
| 2613 | snd_device = SND_DEVICE_IN_UNPROCESSED_MIC; |
| 2614 | } |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2615 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2616 | snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2617 | } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) { |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2618 | snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC; |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2619 | } |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 2620 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
rago | 90fb961 | 2015-12-02 11:37:53 -0800 | [diff] [blame] | 2621 | mode == AUDIO_MODE_IN_COMMUNICATION) { |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2622 | if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2623 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 2624 | if (adev->active_input) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2625 | if (adev->active_input->enable_aec && |
| 2626 | adev->active_input->enable_ns) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2627 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2628 | if (my_data->fluence_in_spkr_mode && |
| 2629 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2630 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2631 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2632 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2633 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2634 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2635 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2636 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2637 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2638 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2639 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2640 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2641 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2642 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2643 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2644 | } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) { |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2645 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2646 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2647 | platform_set_echo_reference(adev, true, out_device); |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2648 | } else if (adev->active_input->enable_aec) { |
| 2649 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 2650 | if (my_data->fluence_in_spkr_mode && |
| 2651 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2652 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2653 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2654 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2655 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2656 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2657 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 2658 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2659 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2660 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2661 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2662 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2663 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2664 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2665 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2666 | } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) { |
Haynes Mathew George | 9a29f37 | 2017-04-11 19:19:07 -0700 | [diff] [blame] | 2667 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2668 | } |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 2669 | platform_set_echo_reference(adev, true, out_device); |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2670 | } else if (adev->active_input->enable_ns) { |
| 2671 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 2672 | if (my_data->fluence_in_spkr_mode && |
| 2673 | my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2674 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2675 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2676 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2677 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2678 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2679 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 2680 | if (my_data->fluence_in_voice_comm && |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2681 | (my_data->source_mic_type & SOURCE_DUAL_MIC)) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2682 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2683 | } else { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2684 | snd_device = SND_DEVICE_IN_HANDSET_MIC_NS; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2685 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2686 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2687 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2688 | } |
| 2689 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 2690 | goto exit; |
| 2691 | } |
| 2692 | |
| 2693 | |
| 2694 | if (snd_device != SND_DEVICE_NONE) { |
| 2695 | goto exit; |
| 2696 | } |
| 2697 | |
| 2698 | if (in_device != AUDIO_DEVICE_NONE && |
| 2699 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 2700 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 2701 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2702 | if ((my_data->source_mic_type & SOURCE_QUAD_MIC) && |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2703 | channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2704 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
| 2705 | } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) && |
Glenn Kasten | cbe06ca | 2016-11-09 10:49:26 -0800 | [diff] [blame] | 2706 | channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2707 | snd_device = SND_DEVICE_IN_THREE_MIC; |
| 2708 | } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2709 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2710 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2711 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2712 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2713 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2714 | } else { |
| 2715 | ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .." |
| 2716 | " channel mask (0x%x) no combination found .. setting to mono", __func__, |
| 2717 | my_data->source_mic_type, channel_count, channel_mask); |
| 2718 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2719 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2720 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2721 | if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2722 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2723 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2724 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2725 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2726 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2727 | } else { |
| 2728 | ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .." |
| 2729 | " no combination found .. setting to mono", __func__, |
| 2730 | my_data->source_mic_type, channel_count); |
| 2731 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 2732 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2733 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 2734 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 2735 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2736 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2737 | if (adev->bluetooth_nrec) |
| 2738 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 2739 | else |
| 2740 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2741 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2742 | if (adev->bluetooth_nrec) |
| 2743 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 2744 | else |
| 2745 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2746 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2747 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 2748 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2749 | } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) { |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 2750 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2751 | } else { |
| 2752 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 2753 | ALOGW("%s: Using default handset-mic", __func__); |
| 2754 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2755 | } |
| 2756 | } else { |
| 2757 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 2758 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2759 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 2760 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2761 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
Eric Laurent | 1b0d8ce | 2014-09-11 09:59:28 -0700 | [diff] [blame] | 2762 | out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE || |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2763 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Eric Laurent | 09f2e0e | 2014-07-29 16:02:32 -0500 | [diff] [blame] | 2764 | out_device & AUDIO_DEVICE_OUT_LINE) { |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2765 | if ((my_data->source_mic_type & SOURCE_DUAL_MIC) && |
| 2766 | channel_count == 2) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2767 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2768 | } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) && |
| 2769 | channel_count == 1) { |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2770 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 2771 | } else { |
| 2772 | ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .." |
| 2773 | " no combination found .. setting to mono", __func__, |
| 2774 | my_data->source_mic_type, channel_count); |
| 2775 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 2776 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2777 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2778 | if (adev->bt_wb_speech_enabled) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2779 | if (adev->bluetooth_nrec) |
| 2780 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 2781 | else |
| 2782 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2783 | } else { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2784 | if (adev->bluetooth_nrec) |
| 2785 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 2786 | else |
| 2787 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2788 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2789 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 2790 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Eric Laurent | 99dab49 | 2017-06-17 15:19:08 -0700 | [diff] [blame] | 2791 | } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) { |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 2792 | if (audio_extn_usb_is_capture_supported()) |
| 2793 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
| 2794 | else |
| 2795 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2796 | } else { |
| 2797 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 2798 | ALOGW("%s: Using default handset-mic", __func__); |
| 2799 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 2800 | } |
| 2801 | } |
| 2802 | exit: |
| 2803 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 2804 | return snd_device; |
| 2805 | } |
| 2806 | |
| 2807 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 2808 | { |
| 2809 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2810 | struct audio_device *adev = my_data->adev; |
| 2811 | struct mixer_ctl *ctl; |
| 2812 | const char *channel_cnt_str = NULL; |
| 2813 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 2814 | switch (channel_count) { |
| 2815 | case 8: |
| 2816 | channel_cnt_str = "Eight"; break; |
| 2817 | case 7: |
| 2818 | channel_cnt_str = "Seven"; break; |
| 2819 | case 6: |
| 2820 | channel_cnt_str = "Six"; break; |
| 2821 | case 5: |
| 2822 | channel_cnt_str = "Five"; break; |
| 2823 | case 4: |
| 2824 | channel_cnt_str = "Four"; break; |
| 2825 | case 3: |
| 2826 | channel_cnt_str = "Three"; break; |
| 2827 | default: |
| 2828 | channel_cnt_str = "Two"; break; |
| 2829 | } |
| 2830 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2831 | if (!ctl) { |
| 2832 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2833 | __func__, mixer_ctl_name); |
| 2834 | return -EINVAL; |
| 2835 | } |
| 2836 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 2837 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 2838 | return 0; |
| 2839 | } |
| 2840 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2841 | int platform_edid_get_max_channels(void *platform) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2842 | { |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2843 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2844 | struct audio_device *adev = my_data->adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2845 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 2846 | char *sad = block; |
| 2847 | int num_audio_blocks; |
| 2848 | int channel_count; |
| 2849 | int max_channels = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2850 | int i, ret, count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2851 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2852 | struct mixer_ctl *ctl; |
| 2853 | |
| 2854 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 2855 | if (!ctl) { |
| 2856 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2857 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2858 | return 0; |
| 2859 | } |
| 2860 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2861 | mixer_ctl_update(ctl); |
| 2862 | |
| 2863 | count = mixer_ctl_get_num_values(ctl); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2864 | |
| 2865 | /* Read SAD blocks, clamping the maximum size for safety */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2866 | if (count > (int)sizeof(block)) |
| 2867 | count = (int)sizeof(block); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2868 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2869 | ret = mixer_ctl_get_array(ctl, block, count); |
| 2870 | if (ret != 0) { |
| 2871 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 2872 | return 0; |
| 2873 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2874 | |
| 2875 | /* Calculate the number of SAD blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2876 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2877 | |
| 2878 | for (i = 0; i < num_audio_blocks; i++) { |
| 2879 | /* Only consider LPCM blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2880 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 2881 | sad += 3; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2882 | continue; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2883 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2884 | |
| 2885 | channel_count = (sad[0] & 0x7) + 1; |
| 2886 | if (channel_count > max_channels) |
| 2887 | max_channels = channel_count; |
| 2888 | |
| 2889 | /* Advance to next block */ |
| 2890 | sad += 3; |
| 2891 | } |
| 2892 | |
| 2893 | return max_channels; |
| 2894 | } |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2895 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2896 | int platform_set_incall_recording_session_id(void *platform, |
| 2897 | uint32_t session_id, int rec_mode) |
| 2898 | { |
| 2899 | int ret = 0; |
| 2900 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2901 | struct audio_device *adev = my_data->adev; |
| 2902 | struct mixer_ctl *ctl; |
| 2903 | const char *mixer_ctl_name = "Voc VSID"; |
| 2904 | int num_ctl_values; |
| 2905 | int i; |
| 2906 | |
| 2907 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2908 | if (!ctl) { |
| 2909 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2910 | __func__, mixer_ctl_name); |
| 2911 | ret = -EINVAL; |
| 2912 | } else { |
| 2913 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 2914 | for (i = 0; i < num_ctl_values; i++) { |
| 2915 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 2916 | ALOGV("Error: invalid session_id: %x", session_id); |
| 2917 | ret = -EINVAL; |
| 2918 | break; |
| 2919 | } |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | if (my_data->csd != NULL) { |
| 2924 | ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode); |
| 2925 | if (ret < 0) { |
| 2926 | ALOGE("%s: csd_client_start_record failed, error %d", |
| 2927 | __func__, ret); |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | return ret; |
| 2932 | } |
| 2933 | |
| 2934 | int platform_stop_incall_recording_usecase(void *platform) |
| 2935 | { |
| 2936 | int ret = 0; |
| 2937 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2938 | |
| 2939 | if (my_data->csd != NULL) { |
| 2940 | ret = my_data->csd->stop_record(ALL_SESSION_VSID); |
| 2941 | if (ret < 0) { |
| 2942 | ALOGE("%s: csd_client_stop_record failed, error %d", |
| 2943 | __func__, ret); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | return ret; |
| 2948 | } |
| 2949 | |
| 2950 | int platform_start_incall_music_usecase(void *platform) |
| 2951 | { |
| 2952 | int ret = 0; |
| 2953 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2954 | |
| 2955 | if (my_data->csd != NULL) { |
| 2956 | ret = my_data->csd->start_playback(ALL_SESSION_VSID); |
| 2957 | if (ret < 0) { |
| 2958 | ALOGE("%s: csd_client_start_playback failed, error %d", |
| 2959 | __func__, ret); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | return ret; |
| 2964 | } |
| 2965 | |
| 2966 | int platform_stop_incall_music_usecase(void *platform) |
| 2967 | { |
| 2968 | int ret = 0; |
| 2969 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2970 | |
| 2971 | if (my_data->csd != NULL) { |
| 2972 | ret = my_data->csd->stop_playback(ALL_SESSION_VSID); |
| 2973 | if (ret < 0) { |
| 2974 | ALOGE("%s: csd_client_stop_playback failed, error %d", |
| 2975 | __func__, ret); |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | return ret; |
| 2980 | } |
| 2981 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 2982 | int platform_set_parameters(void *platform, struct str_parms *parms) |
| 2983 | { |
| 2984 | struct platform_data *my_data = (struct platform_data *)platform; |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 2985 | char value[128]; |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 2986 | char *kv_pairs = str_parms_to_str(parms); |
| 2987 | int ret = 0, err; |
| 2988 | |
| 2989 | if (kv_pairs == NULL) { |
| 2990 | ret = -EINVAL; |
| 2991 | ALOGE("%s: key-value pair is NULL",__func__); |
| 2992 | goto done; |
| 2993 | } |
| 2994 | |
| 2995 | ALOGV("%s: enter: %s", __func__, kv_pairs); |
| 2996 | |
| 2997 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME, |
| 2998 | value, sizeof(value)); |
| 2999 | if (err >= 0) { |
| 3000 | str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME); |
| 3001 | my_data->snd_card_name = strdup(value); |
| 3002 | ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name); |
| 3003 | } |
| 3004 | |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 3005 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO, |
| 3006 | value, sizeof(value)); |
| 3007 | if (err >= 0) { |
| 3008 | struct operator_info *info; |
| 3009 | char *str = value; |
| 3010 | char *name; |
| 3011 | |
| 3012 | str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO); |
| 3013 | info = (struct operator_info *)calloc(1, sizeof(struct operator_info)); |
| 3014 | name = strtok(str, ";"); |
| 3015 | info->name = strdup(name); |
| 3016 | info->mccmnc = strdup(str + strlen(name) + 1); |
| 3017 | |
| 3018 | list_add_tail(&operator_info_list, &info->list); |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 3019 | ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc); |
keunhui.park | 2f7306a | 2015-07-16 16:48:06 +0900 | [diff] [blame] | 3020 | } |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 3021 | |
| 3022 | memset(value, 0, sizeof(value)); |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 3023 | err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT, |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 3024 | value, sizeof(value)); |
| 3025 | if (err >= 0) { |
Eric Laurent | c633338 | 2015-09-14 12:43:44 -0700 | [diff] [blame] | 3026 | str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 3027 | my_data->max_mic_count = atoi(value); |
| 3028 | ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count); |
Prashant Malani | c92c596 | 2015-08-11 15:10:18 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
Ravi Kumar Alamanda | c4f5731 | 2015-06-26 17:41:02 -0700 | [diff] [blame] | 3031 | done: |
| 3032 | ALOGV("%s: exit with code(%d)", __func__, ret); |
| 3033 | if (kv_pairs != NULL) |
| 3034 | free(kv_pairs); |
| 3035 | |
| 3036 | return ret; |
| 3037 | } |
| 3038 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 3039 | /* Delay in Us */ |
| 3040 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 3041 | { |
| 3042 | switch (usecase) { |
| 3043 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 3044 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 3045 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 3046 | return LOW_LATENCY_PLATFORM_DELAY; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3047 | case USECASE_AUDIO_PLAYBACK_ULL: |
| 3048 | return ULL_PLATFORM_DELAY; |
Eric Laurent | 0e46adf | 2016-12-16 12:49:24 -0800 | [diff] [blame] | 3049 | case USECASE_AUDIO_PLAYBACK_MMAP: |
| 3050 | return MMAP_PLATFORM_DELAY; |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 3051 | default: |
| 3052 | return 0; |
| 3053 | } |
| 3054 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 3055 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 3056 | int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag, |
| 3057 | const char * hw_interface) |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 3058 | { |
| 3059 | int ret = 0; |
| 3060 | |
| 3061 | if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { |
| 3062 | ALOGE("%s: Invalid snd_device = %d", |
| 3063 | __func__, device); |
| 3064 | ret = -EINVAL; |
| 3065 | goto done; |
| 3066 | } |
| 3067 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 3068 | ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__, |
| 3069 | platform_get_snd_device_name(device), |
| 3070 | backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag); |
| 3071 | if (backend_tag_table[device]) { |
| 3072 | free(backend_tag_table[device]); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 3073 | } |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 3074 | backend_tag_table[device] = strdup(backend_tag); |
| 3075 | |
| 3076 | if (hw_interface != NULL) { |
| 3077 | if (hw_interface_table[device]) |
| 3078 | free(hw_interface_table[device]); |
| 3079 | ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface); |
| 3080 | hw_interface_table[device] = strdup(hw_interface); |
| 3081 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 3082 | done: |
| 3083 | return ret; |
| 3084 | } |
| 3085 | |
| 3086 | int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id) |
| 3087 | { |
| 3088 | int ret = 0; |
| 3089 | if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) { |
| 3090 | ALOGE("%s: invalid usecase case idx %d", __func__, usecase); |
| 3091 | ret = -EINVAL; |
| 3092 | goto done; |
| 3093 | } |
| 3094 | |
| 3095 | if ((type != 0) && (type != 1)) { |
| 3096 | ALOGE("%s: invalid usecase type", __func__); |
| 3097 | ret = -EINVAL; |
| 3098 | } |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3099 | ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase, |
| 3100 | use_case_table[usecase], |
| 3101 | type, pcm_id); |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 3102 | pcm_device_table[usecase][type] = pcm_id; |
| 3103 | done: |
| 3104 | return ret; |
| 3105 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 3106 | |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 3107 | #define DEFAULT_NOMINAL_SPEAKER_GAIN 20 |
| 3108 | int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) { |
| 3109 | // backup_gain: gain to try to set in case of an error during ramp |
| 3110 | int start_gain, end_gain, step, backup_gain, i; |
| 3111 | bool error = false; |
| 3112 | const struct mixer_ctl *ctl; |
| 3113 | const char *mixer_ctl_name_gain_left = "Left Speaker Gain"; |
| 3114 | const char *mixer_ctl_name_gain_right = "Right Speaker Gain"; |
| 3115 | struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left); |
| 3116 | struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right); |
| 3117 | if (!ctl_left || !ctl_right) { |
| 3118 | ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp", |
| 3119 | __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right); |
| 3120 | return -EINVAL; |
| 3121 | } else if ((mixer_ctl_get_num_values(ctl_left) != 1) |
| 3122 | || (mixer_ctl_get_num_values(ctl_right) != 1)) { |
| 3123 | ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp", |
| 3124 | __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right); |
| 3125 | return -EINVAL; |
| 3126 | } |
| 3127 | if (ramp_up) { |
| 3128 | start_gain = 0; |
| 3129 | end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN; |
| 3130 | step = +1; |
| 3131 | backup_gain = end_gain; |
| 3132 | } else { |
| 3133 | // using same gain on left and right |
| 3134 | const int left_gain = mixer_ctl_get_value(ctl_left, 0); |
| 3135 | start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN; |
| 3136 | end_gain = 0; |
| 3137 | step = -1; |
| 3138 | backup_gain = start_gain; |
| 3139 | } |
| 3140 | for (i = start_gain ; i != (end_gain + step) ; i += step) { |
| 3141 | //ALOGV("setting speaker gain to %d", i); |
| 3142 | if (mixer_ctl_set_value(ctl_left, 0, i)) { |
| 3143 | ALOGE("%s: error setting %s to %d during gain ramp", |
| 3144 | __func__, mixer_ctl_name_gain_left, i); |
| 3145 | error = true; |
| 3146 | break; |
| 3147 | } |
| 3148 | if (mixer_ctl_set_value(ctl_right, 0, i)) { |
| 3149 | ALOGE("%s: error setting %s to %d during gain ramp", |
| 3150 | __func__, mixer_ctl_name_gain_right, i); |
| 3151 | error = true; |
| 3152 | break; |
| 3153 | } |
| 3154 | usleep(1000); |
| 3155 | } |
| 3156 | if (error) { |
| 3157 | // an error occured during the ramp, let's still try to go back to a safe volume |
| 3158 | if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) { |
| 3159 | ALOGE("%s: error restoring left gain to %d", __func__, backup_gain); |
| 3160 | } |
| 3161 | if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) { |
| 3162 | ALOGE("%s: error restoring right gain to %d", __func__, backup_gain); |
| 3163 | } |
| 3164 | } |
| 3165 | return start_gain; |
| 3166 | } |
| 3167 | |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 3168 | int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels) |
| 3169 | { |
| 3170 | // only update if there is active pcm playback on speaker |
| 3171 | struct audio_usecase *usecase; |
| 3172 | struct listnode *node; |
| 3173 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
| 3174 | |
| 3175 | if (my_data->speaker_lr_swap != swap_channels) { |
Jean-Michel Trivi | f714870 | 2016-09-16 18:23:05 -0700 | [diff] [blame] | 3176 | |
| 3177 | // do not swap channels in audio modes with concurrent capture and playback |
| 3178 | // as this may break the echo reference |
| 3179 | if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) { |
| 3180 | ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode); |
| 3181 | return 0; |
| 3182 | } |
| 3183 | |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 3184 | my_data->speaker_lr_swap = swap_channels; |
| 3185 | |
| 3186 | list_for_each(node, &adev->usecase_list) { |
| 3187 | usecase = node_to_item(node, struct audio_usecase, list); |
| 3188 | if (usecase->type == PCM_PLAYBACK && |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 3189 | usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 3190 | /* |
| 3191 | * If acdb tuning is different for SPEAKER_REVERSE, it is must |
| 3192 | * to perform device switch to disable the current backend to |
| 3193 | * enable it with new acdb data. |
| 3194 | */ |
| 3195 | if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] != |
| 3196 | acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) { |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 3197 | const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1); |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 3198 | select_devices(adev, usecase->id); |
Jean-Michel Trivi | 88cbad3 | 2015-09-23 14:51:02 -0700 | [diff] [blame] | 3199 | if (initial_skpr_gain != -EINVAL) { |
| 3200 | ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain); |
| 3201 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 3202 | } else { |
Ravi Kumar Alamanda | 425e154 | 2015-09-22 09:11:18 -0700 | [diff] [blame] | 3203 | const char *mixer_path; |
| 3204 | if (swap_channels) { |
| 3205 | mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE); |
| 3206 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
| 3207 | } else { |
| 3208 | mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER); |
| 3209 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
| 3210 | } |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 3211 | } |
| 3212 | break; |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | return 0; |
| 3217 | } |
vivek mehta | a8d7c92 | 2016-05-25 14:40:44 -0700 | [diff] [blame] | 3218 | |
| 3219 | static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS]; |
| 3220 | static int num_gain_tbl_entry = 0; |
| 3221 | |
| 3222 | bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) { |
| 3223 | |
| 3224 | ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level); |
| 3225 | if (num_gain_tbl_entry == -1) { |
| 3226 | ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping", |
| 3227 | __func__); |
| 3228 | return false; |
| 3229 | } |
| 3230 | |
| 3231 | if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) { |
| 3232 | ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__, |
| 3233 | MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry); |
| 3234 | num_gain_tbl_entry = -1; // indicates error and no more info will be cached |
| 3235 | return false; |
| 3236 | } |
| 3237 | |
| 3238 | if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) { |
| 3239 | ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__); |
| 3240 | num_gain_tbl_entry = -1; // indicates error and no more info will be cached |
| 3241 | return false; |
| 3242 | } |
| 3243 | |
| 3244 | tbl_mapping[num_gain_tbl_entry] = *tbl_entry; |
| 3245 | ++num_gain_tbl_entry; |
| 3246 | |
| 3247 | return true; |
| 3248 | } |
| 3249 | |
| 3250 | int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl, |
| 3251 | int table_size) { |
| 3252 | int itt = 0; |
| 3253 | ALOGV("platform_get_gain_level_mapping called "); |
| 3254 | |
| 3255 | if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) { |
| 3256 | ALOGD("%s: empty or currupted gain_mapping_table", __func__); |
| 3257 | return 0; |
| 3258 | } |
| 3259 | |
| 3260 | for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) { |
| 3261 | mapping_tbl[itt] = tbl_mapping[itt]; |
| 3262 | ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__, |
| 3263 | mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level); |
| 3264 | } |
| 3265 | |
| 3266 | return num_gain_tbl_entry; |
| 3267 | } |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3268 | |
| 3269 | int platform_snd_card_update(void *platform, card_status_t status) |
| 3270 | { |
| 3271 | struct platform_data *my_data = (struct platform_data *)platform; |
| 3272 | struct audio_device *adev = my_data->adev; |
| 3273 | |
| 3274 | if (status == CARD_STATUS_ONLINE) { |
| 3275 | if (my_data->acdb_send_custom_top) |
| 3276 | my_data->acdb_send_custom_top(); |
| 3277 | } |
| 3278 | return 0; |
| 3279 | } |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3280 | |
| 3281 | /* |
| 3282 | * configures afe with bit width and Sample Rate |
| 3283 | */ |
| 3284 | static int platform_set_backend_cfg(const struct audio_device* adev, |
| 3285 | snd_device_t snd_device, |
| 3286 | const struct audio_backend_cfg *backend_cfg) |
| 3287 | { |
| 3288 | |
| 3289 | int ret = 0; |
| 3290 | const int backend_idx = platform_get_backend_index(snd_device); |
| 3291 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
| 3292 | const unsigned int bit_width = backend_cfg->bit_width; |
| 3293 | const unsigned int sample_rate = backend_cfg->sample_rate; |
| 3294 | const unsigned int channels = backend_cfg->channels; |
| 3295 | const audio_format_t format = backend_cfg->format; |
| 3296 | const bool passthrough_enabled = backend_cfg->passthrough_enabled; |
| 3297 | |
| 3298 | |
| 3299 | ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d" |
| 3300 | ", backend_idx %d device (%s)", __func__, bit_width, |
| 3301 | sample_rate, channels, backend_idx, |
| 3302 | platform_get_snd_device_name(snd_device)); |
| 3303 | |
| 3304 | if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) && |
| 3305 | (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) { |
| 3306 | |
| 3307 | struct mixer_ctl *ctl = NULL; |
| 3308 | ctl = mixer_get_ctl_by_name(adev->mixer, |
| 3309 | my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl); |
| 3310 | if (!ctl) { |
| 3311 | ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s", |
| 3312 | __func__, |
| 3313 | my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl); |
| 3314 | return -EINVAL; |
| 3315 | } |
| 3316 | |
| 3317 | if (bit_width == 24) { |
| 3318 | if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED) |
| 3319 | ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE"); |
| 3320 | else |
| 3321 | ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE"); |
| 3322 | } else if (bit_width == 32) { |
| 3323 | ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE"); |
| 3324 | } else { |
| 3325 | ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE"); |
| 3326 | } |
| 3327 | if ( ret < 0) { |
| 3328 | ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__, |
| 3329 | my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format); |
| 3330 | } else { |
| 3331 | my_data->current_backend_cfg[backend_idx].bit_width = bit_width; |
| 3332 | ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__, |
| 3333 | my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format); |
| 3334 | } |
| 3335 | /* set the ret as 0 and not pass back to upper layer */ |
| 3336 | ret = 0; |
| 3337 | } |
| 3338 | |
| 3339 | if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) && |
| 3340 | (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) { |
| 3341 | char *rate_str = NULL; |
| 3342 | struct mixer_ctl *ctl = NULL; |
| 3343 | |
| 3344 | switch (sample_rate) { |
| 3345 | case 32000: |
| 3346 | if (passthrough_enabled) { |
| 3347 | rate_str = "KHZ_32"; |
| 3348 | break; |
| 3349 | } |
| 3350 | case 8000: |
| 3351 | case 11025: |
| 3352 | case 16000: |
| 3353 | case 22050: |
| 3354 | case 48000: |
| 3355 | rate_str = "KHZ_48"; |
| 3356 | break; |
| 3357 | case 44100: |
| 3358 | rate_str = "KHZ_44P1"; |
| 3359 | break; |
| 3360 | case 64000: |
| 3361 | case 96000: |
| 3362 | rate_str = "KHZ_96"; |
| 3363 | break; |
| 3364 | case 88200: |
| 3365 | rate_str = "KHZ_88P2"; |
| 3366 | break; |
| 3367 | case 176400: |
| 3368 | rate_str = "KHZ_176P4"; |
| 3369 | break; |
| 3370 | case 192000: |
| 3371 | rate_str = "KHZ_192"; |
| 3372 | break; |
| 3373 | case 352800: |
| 3374 | rate_str = "KHZ_352P8"; |
| 3375 | break; |
| 3376 | case 384000: |
| 3377 | rate_str = "KHZ_384"; |
| 3378 | break; |
| 3379 | case 144000: |
| 3380 | if (passthrough_enabled) { |
| 3381 | rate_str = "KHZ_144"; |
| 3382 | break; |
| 3383 | } |
| 3384 | default: |
| 3385 | rate_str = "KHZ_48"; |
| 3386 | break; |
| 3387 | } |
| 3388 | |
| 3389 | ctl = mixer_get_ctl_by_name(adev->mixer, |
| 3390 | my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl); |
| 3391 | if(!ctl) { |
| 3392 | ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s", |
| 3393 | __func__, |
| 3394 | my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl); |
| 3395 | return -EINVAL; |
| 3396 | } |
| 3397 | |
| 3398 | ALOGD("%s:becf: afe: %s set to %s", __func__, |
| 3399 | my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str); |
| 3400 | mixer_ctl_set_enum_by_string(ctl, rate_str); |
| 3401 | my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate; |
| 3402 | } |
| 3403 | if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) && |
| 3404 | (channels != my_data->current_backend_cfg[backend_idx].channels)) { |
| 3405 | struct mixer_ctl *ctl = NULL; |
| 3406 | char *channel_cnt_str = NULL; |
| 3407 | |
| 3408 | switch (channels) { |
| 3409 | case 8: |
| 3410 | channel_cnt_str = "Eight"; break; |
| 3411 | case 7: |
| 3412 | channel_cnt_str = "Seven"; break; |
| 3413 | case 6: |
| 3414 | channel_cnt_str = "Six"; break; |
| 3415 | case 5: |
| 3416 | channel_cnt_str = "Five"; break; |
| 3417 | case 4: |
| 3418 | channel_cnt_str = "Four"; break; |
| 3419 | case 3: |
| 3420 | channel_cnt_str = "Three"; break; |
| 3421 | case 1: |
| 3422 | channel_cnt_str = "One"; break; |
| 3423 | case 2: |
| 3424 | default: |
| 3425 | channel_cnt_str = "Two"; break; |
| 3426 | } |
| 3427 | |
| 3428 | ctl = mixer_get_ctl_by_name(adev->mixer, |
| 3429 | my_data->current_backend_cfg[backend_idx].channels_mixer_ctl); |
| 3430 | if (!ctl) { |
| 3431 | ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s", |
| 3432 | __func__, |
| 3433 | my_data->current_backend_cfg[backend_idx].channels_mixer_ctl); |
| 3434 | return -EINVAL; |
| 3435 | } |
| 3436 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 3437 | my_data->current_backend_cfg[backend_idx].channels = channels; |
| 3438 | |
| 3439 | // skip EDID configuration for HDMI backend |
| 3440 | |
| 3441 | ALOGD("%s:becf: afe: %s set to %s", __func__, |
| 3442 | my_data->current_backend_cfg[backend_idx].channels_mixer_ctl, |
| 3443 | channel_cnt_str); |
| 3444 | } |
| 3445 | |
| 3446 | // skip set ext_display format mixer control |
| 3447 | return ret; |
| 3448 | } |
| 3449 | |
| 3450 | static int platform_get_snd_device_bit_width(snd_device_t snd_device) |
| 3451 | { |
| 3452 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 3453 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 3454 | return CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 3455 | } |
| 3456 | |
| 3457 | return backend_bit_width_table[snd_device]; |
| 3458 | } |
| 3459 | |
| 3460 | /* |
| 3461 | * return backend_idx on which voice call is active |
| 3462 | */ |
| 3463 | static int platform_get_voice_call_backend(struct audio_device* adev) |
| 3464 | { |
| 3465 | struct audio_usecase *uc = NULL; |
| 3466 | struct listnode *node; |
| 3467 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 3468 | |
| 3469 | int backend_idx = -1; |
| 3470 | |
| 3471 | if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) { |
| 3472 | list_for_each(node, &adev->usecase_list) { |
| 3473 | uc = node_to_item(node, struct audio_usecase, list); |
| 3474 | if (uc && uc->type == VOICE_CALL && uc->stream.out) { |
| 3475 | out_snd_device = platform_get_output_snd_device(adev->platform, |
| 3476 | uc->stream.out->devices); |
| 3477 | backend_idx = platform_get_backend_index(out_snd_device); |
| 3478 | break; |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | return backend_idx; |
| 3483 | } |
| 3484 | |
| 3485 | /* |
| 3486 | * goes through all the current usecases and picks the highest |
| 3487 | * bitwidth & samplerate |
| 3488 | */ |
| 3489 | static bool platform_check_capture_backend_cfg(struct audio_device* adev, |
| 3490 | int backend_idx, |
| 3491 | struct audio_backend_cfg *backend_cfg) |
| 3492 | { |
| 3493 | bool backend_change = false; |
| 3494 | unsigned int bit_width; |
| 3495 | unsigned int sample_rate; |
| 3496 | unsigned int channels; |
| 3497 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
| 3498 | |
| 3499 | bit_width = backend_cfg->bit_width; |
| 3500 | sample_rate = backend_cfg->sample_rate; |
| 3501 | channels = backend_cfg->channels; |
| 3502 | |
| 3503 | ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and " |
| 3504 | "sample rate: %d, channels %d",__func__,backend_idx, bit_width, |
| 3505 | sample_rate, channels); |
| 3506 | |
| 3507 | // For voice calls use default configuration i.e. 16b/48K, only applicable to |
| 3508 | // default backend |
| 3509 | // force routing is not required here, caller will do it anyway |
| 3510 | if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) { |
| 3511 | ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and " |
| 3512 | "for unprocessed/camera source", __func__); |
| 3513 | bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 3514 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3515 | } |
| 3516 | |
| 3517 | if (backend_idx == USB_AUDIO_TX_BACKEND) { |
| 3518 | audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false); |
| 3519 | ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)", |
| 3520 | __func__, bit_width, sample_rate, channels); |
| 3521 | } |
| 3522 | |
| 3523 | ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and " |
| 3524 | "sample rate: %d", __func__, backend_idx, bit_width, sample_rate); |
| 3525 | |
| 3526 | // Force routing if the expected bitwdith or samplerate |
| 3527 | // is not same as current backend comfiguration |
| 3528 | if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) || |
| 3529 | (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) || |
| 3530 | (channels != my_data->current_backend_cfg[backend_idx].channels)) { |
| 3531 | backend_cfg->bit_width = bit_width; |
| 3532 | backend_cfg->sample_rate= sample_rate; |
| 3533 | backend_cfg->channels = channels; |
| 3534 | backend_change = true; |
| 3535 | ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d " |
| 3536 | "new sample rate: %d new channel: %d", |
| 3537 | __func__, backend_cfg->bit_width, |
| 3538 | backend_cfg->sample_rate, backend_cfg->channels); |
| 3539 | } |
| 3540 | |
| 3541 | return backend_change; |
| 3542 | } |
| 3543 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3544 | static void pick_playback_cfg_for_uc(struct audio_device *adev, |
| 3545 | struct audio_usecase *usecase, |
| 3546 | snd_device_t snd_device, |
| 3547 | unsigned int *bit_width, |
| 3548 | unsigned int *sample_rate, |
| 3549 | unsigned int *channels) |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3550 | { |
| 3551 | int i =0; |
| 3552 | struct listnode *node; |
| 3553 | list_for_each(node, &adev->usecase_list) { |
| 3554 | struct audio_usecase *uc; |
| 3555 | uc = node_to_item(node, struct audio_usecase, list); |
| 3556 | struct stream_out *out = (struct stream_out*) uc->stream.out; |
| 3557 | if (uc->type == PCM_PLAYBACK && out && usecase != uc) { |
| 3558 | unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask); |
| 3559 | ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw " |
| 3560 | "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id], |
| 3561 | uc->id, out->sample_rate, |
| 3562 | pcm_format_to_bits(out->config.format), out_channels, |
| 3563 | platform_get_snd_device_name(uc->out_snd_device)); |
| 3564 | |
| 3565 | if (platform_check_backends_match(snd_device, uc->out_snd_device)) { |
| 3566 | if (*bit_width < pcm_format_to_bits(out->config.format)) |
| 3567 | *bit_width = pcm_format_to_bits(out->config.format); |
| 3568 | if (*sample_rate < out->sample_rate) |
| 3569 | *sample_rate = out->sample_rate; |
| 3570 | if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100) |
| 3571 | *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3572 | if (*channels < out_channels) |
| 3573 | *channels = out_channels; |
| 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | return; |
| 3578 | } |
| 3579 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3580 | static void headset_is_config_supported(unsigned int *bit_width, |
| 3581 | unsigned int *sample_rate, |
| 3582 | unsigned int *channels) { |
| 3583 | switch (*bit_width) { |
| 3584 | case 16: |
| 3585 | case 24: |
| 3586 | break; |
| 3587 | default: |
| 3588 | *bit_width = 16; |
| 3589 | break; |
| 3590 | } |
| 3591 | |
| 3592 | if (*sample_rate > 192000) { |
| 3593 | *sample_rate = 192000; |
| 3594 | } |
| 3595 | |
| 3596 | if (*channels > 2) { |
| 3597 | *channels = 2; |
| 3598 | } |
| 3599 | } |
| 3600 | |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3601 | static bool platform_check_playback_backend_cfg(struct audio_device* adev, |
| 3602 | struct audio_usecase* usecase, |
| 3603 | snd_device_t snd_device, |
| 3604 | struct audio_backend_cfg *backend_cfg) |
| 3605 | { |
| 3606 | bool backend_change = false; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3607 | unsigned int bit_width; |
| 3608 | unsigned int sample_rate; |
| 3609 | unsigned int channels; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3610 | int backend_idx = DEFAULT_CODEC_BACKEND; |
| 3611 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3612 | |
| 3613 | if (snd_device == SND_DEVICE_OUT_BT_SCO || |
| 3614 | snd_device == SND_DEVICE_OUT_BT_SCO_WB) { |
| 3615 | backend_change = false; |
| 3616 | return backend_change; |
| 3617 | } |
| 3618 | |
| 3619 | backend_idx = platform_get_backend_index(snd_device); |
| 3620 | bit_width = backend_cfg->bit_width; |
| 3621 | sample_rate = backend_cfg->sample_rate; |
| 3622 | channels = backend_cfg->channels; |
| 3623 | |
| 3624 | ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d" |
| 3625 | ", backend_idx %d usecase = %d device (%s)", __func__, bit_width, |
| 3626 | sample_rate, channels, backend_idx, usecase->id, |
| 3627 | platform_get_snd_device_name(snd_device)); |
| 3628 | |
| 3629 | if (backend_idx == platform_get_voice_call_backend(adev)) { |
| 3630 | ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ", |
| 3631 | __func__); |
| 3632 | bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 3633 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3634 | channels = CODEC_BACKEND_DEFAULT_CHANNELS; |
| 3635 | } else { |
| 3636 | /* |
| 3637 | * The backend should be configured at highest bit width and/or |
| 3638 | * sample rate amongst all playback usecases. |
| 3639 | * If the selected sample rate and/or bit width differ with |
| 3640 | * current backend sample rate and/or bit width, then, we set the |
| 3641 | * backend re-configuration flag. |
| 3642 | * |
| 3643 | * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only |
| 3644 | */ |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3645 | pick_playback_cfg_for_uc(adev, usecase, snd_device, |
| 3646 | &bit_width, |
| 3647 | &sample_rate, |
| 3648 | &channels); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3651 | switch (backend_idx) { |
| 3652 | case USB_AUDIO_RX_BACKEND: |
| 3653 | audio_extn_usb_is_config_supported(&bit_width, |
| 3654 | &sample_rate, &channels, true); |
| 3655 | ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)", |
| 3656 | __func__, bit_width, sample_rate, channels); |
| 3657 | break; |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3658 | case HEADPHONE_BACKEND: |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3659 | headset_is_config_supported(&bit_width, &sample_rate, &channels); |
| 3660 | break; |
| 3661 | case DEFAULT_CODEC_BACKEND: |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3662 | default: |
| 3663 | bit_width = platform_get_snd_device_bit_width(snd_device); |
| 3664 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3665 | channels = CODEC_BACKEND_DEFAULT_CHANNELS; |
| 3666 | break; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3669 | ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and" |
| 3670 | "sample rate: %d", |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3671 | __func__, backend_idx , bit_width, sample_rate); |
| 3672 | |
| 3673 | // Force routing if the expected bitwdith or samplerate |
| 3674 | // is not same as current backend comfiguration |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3675 | if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width || |
| 3676 | sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate || |
| 3677 | channels != my_data->current_backend_cfg[backend_idx].channels) { |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3678 | backend_cfg->bit_width = bit_width; |
| 3679 | backend_cfg->sample_rate = sample_rate; |
| 3680 | backend_cfg->channels = channels; |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3681 | backend_cfg->passthrough_enabled = false; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3682 | backend_change = true; |
| 3683 | ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d" |
| 3684 | "new sample rate: %d new channels: %d", |
| 3685 | __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels); |
| 3686 | } |
| 3687 | |
| 3688 | return backend_change; |
| 3689 | } |
| 3690 | |
| 3691 | bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev, |
| 3692 | struct audio_usecase *usecase, snd_device_t snd_device) |
| 3693 | { |
| 3694 | int backend_idx = DEFAULT_CODEC_BACKEND; |
| 3695 | int new_snd_devices[SND_DEVICE_OUT_END]; |
| 3696 | int i, num_devices = 1; |
| 3697 | bool ret = false; |
| 3698 | struct platform_data *my_data = (struct platform_data *)adev->platform; |
| 3699 | struct audio_backend_cfg backend_cfg; |
| 3700 | |
| 3701 | backend_idx = platform_get_backend_index(snd_device); |
| 3702 | |
| 3703 | backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format); |
| 3704 | backend_cfg.sample_rate = usecase->stream.out->sample_rate; |
| 3705 | backend_cfg.format = usecase->stream.out->format; |
| 3706 | backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask); |
| 3707 | /*this is populated by check_codec_backend_cfg hence set default value to false*/ |
| 3708 | backend_cfg.passthrough_enabled = false; |
| 3709 | |
| 3710 | ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d" |
| 3711 | ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width, |
| 3712 | backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id, |
| 3713 | platform_get_snd_device_name(snd_device)); |
| 3714 | |
| 3715 | if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0) |
| 3716 | new_snd_devices[0] = snd_device; |
| 3717 | |
| 3718 | for (i = 0; i < num_devices; i++) { |
| 3719 | ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]); |
| 3720 | if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i], |
| 3721 | &backend_cfg))) { |
| 3722 | platform_set_backend_cfg(adev, new_snd_devices[i], |
| 3723 | &backend_cfg); |
| 3724 | ret = true; |
| 3725 | } |
| 3726 | } |
| 3727 | return ret; |
| 3728 | } |
| 3729 | |
| 3730 | bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev, |
| 3731 | struct audio_usecase *usecase, snd_device_t snd_device) |
| 3732 | { |
| 3733 | int backend_idx = platform_get_backend_index(snd_device); |
| 3734 | int ret = 0; |
| 3735 | struct audio_backend_cfg backend_cfg; |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3736 | memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg)); |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3737 | |
Haynes Mathew George | 4bd4799 | 2017-03-09 17:59:38 -0800 | [diff] [blame] | 3738 | if (usecase->type == PCM_CAPTURE) { |
| 3739 | backend_cfg.format = usecase->stream.in->format; |
David Lin | ee3fe40 | 2017-03-13 10:00:42 -0700 | [diff] [blame] | 3740 | backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask); |
| 3741 | } else { |
| 3742 | backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 3743 | backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3744 | backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 3745 | backend_cfg.channels = 1; |
| 3746 | } |
| 3747 | |
| 3748 | ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d" |
| 3749 | ", backend_idx %d usecase = %d device (%s)", __func__, |
| 3750 | backend_cfg.bit_width, |
| 3751 | backend_cfg.sample_rate, |
| 3752 | backend_cfg.channels, |
| 3753 | backend_idx, usecase->id, |
| 3754 | platform_get_snd_device_name(snd_device)); |
| 3755 | |
| 3756 | if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) { |
| 3757 | ret = platform_set_backend_cfg(adev, snd_device, |
| 3758 | &backend_cfg); |
| 3759 | if(!ret) |
| 3760 | return true; |
| 3761 | } |
| 3762 | |
| 3763 | return false; |
| 3764 | } |
| 3765 | |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3766 | static int max_be_dai_names = 0; |
| 3767 | static const struct be_dai_name_struct *be_dai_name_table; |
| 3768 | |
| 3769 | /* |
| 3770 | * Retrieves the be_dai_name_table from kernel to enable a mapping |
| 3771 | * between sound device hw interfaces and backend IDs. This allows HAL to |
| 3772 | * specify the backend a specific calibration is needed for. |
| 3773 | */ |
| 3774 | static int init_be_dai_name_table(struct audio_device *adev) |
| 3775 | { |
| 3776 | const char *mixer_ctl_name = "Backend DAI Name Table"; |
| 3777 | struct mixer_ctl *ctl; |
| 3778 | int i, j, ret, size; |
| 3779 | bool valid_hw_interface; |
| 3780 | |
| 3781 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 3782 | if (!ctl) { |
| 3783 | ALOGE("%s: Could not get ctl for mixer name %s\n", |
| 3784 | __func__, mixer_ctl_name); |
| 3785 | ret = -EINVAL; |
| 3786 | goto done; |
| 3787 | } |
| 3788 | |
| 3789 | mixer_ctl_update(ctl); |
| 3790 | |
| 3791 | size = mixer_ctl_get_num_values(ctl); |
| 3792 | if (size <= 0){ |
| 3793 | ALOGE("%s: Failed to get %s size %d\n", |
| 3794 | __func__, mixer_ctl_name, size); |
| 3795 | ret = -EFAULT; |
| 3796 | goto done; |
| 3797 | } |
| 3798 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3799 | be_dai_name_table = |
| 3800 | (const struct be_dai_name_struct *)calloc(1, size); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3801 | if (be_dai_name_table == NULL) { |
| 3802 | ALOGE("%s: Failed to allocate memory for %s\n", |
| 3803 | __func__, mixer_ctl_name); |
| 3804 | ret = -ENOMEM; |
| 3805 | goto freeMem; |
| 3806 | } |
| 3807 | |
| 3808 | ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size); |
| 3809 | if (ret) { |
| 3810 | ALOGE("%s: Failed to get %s, ret %d\n", |
| 3811 | __func__, mixer_ctl_name, ret); |
| 3812 | ret = -EFAULT; |
| 3813 | goto freeMem; |
| 3814 | } |
| 3815 | |
| 3816 | if (be_dai_name_table != NULL) { |
| 3817 | max_be_dai_names = size / sizeof(struct be_dai_name_struct); |
| 3818 | ALOGV("%s: Successfully got %s, number of be dais is %d\n", |
| 3819 | __func__, mixer_ctl_name, max_be_dai_names); |
| 3820 | ret = 0; |
| 3821 | } else { |
| 3822 | ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name); |
| 3823 | ret = -EFAULT; |
| 3824 | goto freeMem; |
| 3825 | } |
| 3826 | |
| 3827 | /* |
| 3828 | * Validate all sound devices have a valid backend set to catch |
| 3829 | * errors for uncommon sound devices |
| 3830 | */ |
| 3831 | for (i = 0; i < SND_DEVICE_MAX; i++) { |
| 3832 | valid_hw_interface = false; |
| 3833 | |
| 3834 | if (hw_interface_table[i] == NULL) { |
| 3835 | ALOGW("%s: sound device %s has no hw interface set\n", |
| 3836 | __func__, platform_get_snd_device_name(i)); |
| 3837 | continue; |
| 3838 | } |
| 3839 | |
| 3840 | for (j = 0; j < max_be_dai_names; j++) { |
| 3841 | if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name) |
| 3842 | == 0) { |
| 3843 | valid_hw_interface = true; |
| 3844 | break; |
| 3845 | } |
| 3846 | } |
| 3847 | if (!valid_hw_interface) |
| 3848 | ALOGD("%s: sound device %s does not have a valid hw interface set " |
| 3849 | "(disregard for combo devices) %s\n", |
| 3850 | __func__, platform_get_snd_device_name(i), |
| 3851 | hw_interface_table[i]); |
| 3852 | } |
| 3853 | |
| 3854 | goto done; |
| 3855 | |
| 3856 | freeMem: |
| 3857 | if (be_dai_name_table) { |
| 3858 | free((void *)be_dai_name_table); |
| 3859 | be_dai_name_table = NULL; |
| 3860 | } |
| 3861 | |
| 3862 | done: |
| 3863 | return ret; |
| 3864 | } |
| 3865 | |
| 3866 | int platform_get_snd_device_backend_index(snd_device_t device) |
| 3867 | { |
| 3868 | int i, be_dai_id; |
| 3869 | const char * hw_interface_name = NULL; |
| 3870 | |
| 3871 | ALOGV("%s: enter with device %d\n", __func__, device); |
| 3872 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3873 | if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3874 | ALOGE("%s: Invalid snd_device = %d", |
| 3875 | __func__, device); |
| 3876 | be_dai_id = -EINVAL; |
| 3877 | goto done; |
| 3878 | } |
| 3879 | |
| 3880 | /* Get string value of necessary backend for device */ |
| 3881 | hw_interface_name = hw_interface_table[device]; |
| 3882 | if (hw_interface_name == NULL) { |
| 3883 | ALOGE("%s: no hw_interface set for device %d\n", __func__, device); |
| 3884 | be_dai_id = -EINVAL; |
| 3885 | goto done; |
| 3886 | } |
| 3887 | |
| 3888 | /* Check if be dai name table was retrieved successfully */ |
| 3889 | if (be_dai_name_table == NULL) { |
| 3890 | ALOGE("%s: BE DAI Name Table is not present\n", __func__); |
| 3891 | be_dai_id = -EFAULT; |
| 3892 | goto done; |
| 3893 | } |
| 3894 | |
| 3895 | /* Get backend ID for device specified */ |
| 3896 | for (i = 0; i < max_be_dai_names; i++) { |
| 3897 | if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) { |
| 3898 | be_dai_id = be_dai_name_table[i].be_id; |
| 3899 | goto done; |
| 3900 | } |
| 3901 | } |
| 3902 | ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name); |
| 3903 | be_dai_id = -EINVAL; |
| 3904 | goto done; |
| 3905 | |
| 3906 | done: |
| 3907 | return be_dai_id; |
| 3908 | } |
| 3909 | |
| 3910 | void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device, |
| 3911 | unsigned int stream_sr, int* sample_rate) |
| 3912 | { |
| 3913 | struct platform_data* my_data = (struct platform_data *)platform; |
| 3914 | int backend_idx = platform_get_backend_index(snd_device); |
| 3915 | int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate; |
| 3916 | /* |
| 3917 | *Check if device SR is multiple of 8K or 11.025 Khz |
| 3918 | *check if the stream SR is multiple of same base, if yes |
| 3919 | *then have copp SR equal to stream SR, this ensures that |
| 3920 | *post processing happens at stream SR, else have |
| 3921 | *copp SR equal to device SR. |
| 3922 | */ |
| 3923 | if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) && |
| 3924 | (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) || |
| 3925 | ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) && |
| 3926 | (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) { |
| 3927 | *sample_rate = device_sr; |
| 3928 | } else |
| 3929 | *sample_rate = stream_sr; |
| 3930 | |
| 3931 | ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr |
| 3932 | , *sample_rate); |
| 3933 | |
| 3934 | } |
| 3935 | |
| 3936 | // called from info parser |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3937 | void platform_add_app_type(const char *uc_type, |
| 3938 | const char *mode, |
| 3939 | int bw, |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3940 | int app_type, int max_rate) { |
| 3941 | struct app_type_entry *ap = |
| 3942 | (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry)); |
| 3943 | |
| 3944 | if (!ap) { |
| 3945 | ALOGE("%s failed to allocate mem for app type", __func__); |
| 3946 | return; |
| 3947 | } |
| 3948 | |
| 3949 | ap->uc_type = -1; |
| 3950 | for (int i=0; i<USECASE_TYPE_MAX; i++) { |
| 3951 | if (!strcmp(uc_type, usecase_type_index[i].name)) { |
| 3952 | ap->uc_type = usecase_type_index[i].index; |
| 3953 | break; |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | if (ap->uc_type == -1) { |
| 3958 | free(ap); |
| 3959 | return; |
| 3960 | } |
| 3961 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3962 | ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d", |
| 3963 | __func__, uc_type, mode, bw, app_type, max_rate); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3964 | ap->bit_width = bw; |
| 3965 | ap->app_type = app_type; |
| 3966 | ap->max_rate = max_rate; |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3967 | ap->mode = strdup(mode); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3968 | list_add_tail(&app_type_entry_list, &ap->node); |
| 3969 | } |
| 3970 | |
| 3971 | |
| 3972 | int platform_get_default_app_type_v2(void *platform __unused, |
| 3973 | usecase_type_t type, |
| 3974 | int *app_type ) |
| 3975 | { |
| 3976 | if (type == PCM_PLAYBACK) |
| 3977 | *app_type = DEFAULT_APP_TYPE_RX_PATH; |
| 3978 | else |
| 3979 | *app_type = DEFAULT_APP_TYPE_TX_PATH; |
| 3980 | return 0; |
| 3981 | } |
| 3982 | |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3983 | int platform_get_app_type_v2(void *platform, |
| 3984 | usecase_type_t uc_type, |
| 3985 | const char *mode, |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3986 | int bw, int sr __unused, |
| 3987 | int *app_type) |
| 3988 | { |
| 3989 | struct listnode *node; |
| 3990 | struct app_type_entry *entry; |
| 3991 | *app_type = -1; |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3992 | |
| 3993 | ALOGV("%s find match for uc %d mode %s bw %d rate %d", |
| 3994 | __func__, uc_type, mode, bw, sr); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 3995 | list_for_each(node, &app_type_entry_list) { |
| 3996 | entry = node_to_item(node, struct app_type_entry, node); |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 3997 | ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d", |
| 3998 | __func__, entry->uc_type, entry->mode, entry->bit_width, |
| 3999 | entry->app_type, entry->max_rate); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 4000 | if (entry->bit_width == bw && |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 4001 | entry->uc_type == uc_type && |
| 4002 | sr <= entry->max_rate && |
| 4003 | entry->mode && !strcmp(mode, entry->mode)) { |
| 4004 | ALOGV("%s found match %d", __func__, entry->app_type); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 4005 | *app_type = entry->app_type; |
| 4006 | break; |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | if (*app_type == -1) { |
vivek mehta | a68fea6 | 2017-06-08 19:04:02 -0700 | [diff] [blame] | 4011 | ALOGV("%s no match found, return default", __func__); |
Haynes Mathew George | e5ff0fc | 2017-02-16 20:33:38 -0800 | [diff] [blame] | 4012 | return platform_get_default_app_type_v2(platform, uc_type, app_type); |
| 4013 | } |
| 4014 | return 0; |
| 4015 | } |