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