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