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