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 | */ |
| 16 | |
| 17 | #define LOG_TAG "msm8974_platform" |
| 18 | /*#define LOG_NDEBUG 0*/ |
| 19 | #define LOG_NDDEBUG 0 |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <dlfcn.h> |
| 23 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 24 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 25 | #include <cutils/properties.h> |
| 26 | #include <audio_hw.h> |
| 27 | #include <platform_api.h> |
| 28 | #include "platform.h" |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 29 | #ifdef PLATFORM_MSM8084 |
| 30 | #include "mdm_detect.h" |
| 31 | #endif |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 32 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 33 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 34 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 35 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 36 | |
| 37 | #define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */ |
| 38 | #define DUALMIC_CONFIG_ENDFIRE 1 |
| 39 | #define DUALMIC_CONFIG_BROADSIDE 2 |
| 40 | |
| 41 | /* |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 42 | * This file will have a maximum of 38 bytes: |
| 43 | * |
| 44 | * 4 bytes: number of audio blocks |
| 45 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 46 | * Maximum 10 * 3 bytes: SAD blocks |
| 47 | */ |
| 48 | #define MAX_SAD_BLOCKS 10 |
| 49 | #define SAD_BLOCK_SIZE 3 |
| 50 | |
| 51 | /* EDID format ID for LPCM audio */ |
| 52 | #define EDID_FORMAT_LPCM 1 |
| 53 | |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 54 | /* Retry for delay in FW loading*/ |
| 55 | #define RETRY_NUMBER 10 |
| 56 | #define RETRY_US 500000 |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 57 | #define MAX_SND_CARD 8 |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 58 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 59 | struct audio_block_header |
| 60 | { |
| 61 | int reserved; |
| 62 | int length; |
| 63 | }; |
| 64 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 65 | /* Audio calibration related functions */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 66 | typedef void (*acdb_deallocate_t)(); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 67 | #ifdef PLATFORM_MSM8084 |
| 68 | typedef int (*acdb_init_t)(char *); |
| 69 | #else |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 70 | typedef int (*acdb_init_t)(); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 71 | #endif |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 72 | typedef void (*acdb_send_audio_cal_t)(int, int); |
| 73 | typedef void (*acdb_send_voice_cal_t)(int, int); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 74 | typedef int (*acdb_reload_vocvoltable_t)(int); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 75 | |
| 76 | /* Audio calibration related functions */ |
| 77 | struct platform_data { |
| 78 | struct audio_device *adev; |
| 79 | bool fluence_in_spkr_mode; |
| 80 | bool fluence_in_voice_call; |
| 81 | bool fluence_in_voice_rec; |
| 82 | int dualmic_config; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 83 | void *acdb_handle; |
| 84 | acdb_init_t acdb_init; |
| 85 | acdb_deallocate_t acdb_deallocate; |
| 86 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 87 | acdb_send_voice_cal_t acdb_send_voice_cal; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 88 | acdb_reload_vocvoltable_t acdb_reload_vocvoltable; |
| 89 | struct csd_data *csd; |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 90 | bool ext_speaker; |
| 91 | bool ext_earpiece; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 94 | static int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 95 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 96 | DEEP_BUFFER_PCM_DEVICE}, |
| 97 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 98 | LOWLATENCY_PCM_DEVICE}, |
| 99 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE, |
| 100 | MULTIMEDIA2_PCM_DEVICE}, |
| 101 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE, |
| 102 | PLAYBACK_OFFLOAD_DEVICE}, |
| 103 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, |
| 104 | AUDIO_RECORD_PCM_DEVICE}, |
| 105 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 106 | LOWLATENCY_PCM_DEVICE}, |
| 107 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, |
| 108 | VOICE_CALL_PCM_DEVICE}, |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 109 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 110 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 111 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
| 112 | [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE}, |
| 113 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 114 | AUDIO_RECORD_PCM_DEVICE}, |
| 115 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 116 | AUDIO_RECORD_PCM_DEVICE}, |
| 117 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 118 | AUDIO_RECORD_PCM_DEVICE}, |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 119 | [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX}, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* Array to store sound devices */ |
| 123 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 124 | [SND_DEVICE_NONE] = "none", |
| 125 | /* Playback sound devices */ |
| 126 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 127 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 128 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
| 129 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 130 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
| 131 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
| 132 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 133 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
| 134 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 135 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 136 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 137 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 138 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
| 139 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 140 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 141 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
| 142 | |
| 143 | /* Capture sound devices */ |
| 144 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
| 145 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 146 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 147 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
Eric Laurent | 34fa769 | 2014-03-07 09:31:06 -0800 | [diff] [blame] | 148 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic-aec", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 149 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic", |
| 150 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 151 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 152 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 153 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 154 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 155 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
| 156 | [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef", |
| 157 | [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs", |
| 158 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus", |
| 159 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef", |
| 160 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs", |
| 161 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 162 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 163 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
| 164 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
| 165 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef", |
| 166 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs", |
| 167 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence", |
| 168 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence", |
| 169 | }; |
| 170 | |
| 171 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 172 | static int acdb_device_table[SND_DEVICE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 173 | [SND_DEVICE_NONE] = -1, |
| 174 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 175 | [SND_DEVICE_OUT_SPEAKER] = 15, |
| 176 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15, |
| 177 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 178 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
Ravi Kumar Alamanda | 1de6e5a | 2014-06-19 21:55:39 -0500 | [diff] [blame] | 179 | #ifdef PLATFORM_MSM8084 |
| 180 | [SND_DEVICE_OUT_VOICE_HANDSET] = 67, |
| 181 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 66, |
| 182 | #else |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 183 | [SND_DEVICE_OUT_VOICE_HANDSET] = 7, |
| 184 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 15, |
Ravi Kumar Alamanda | 1de6e5a | 2014-06-19 21:55:39 -0500 | [diff] [blame] | 185 | #endif |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 186 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
| 187 | [SND_DEVICE_OUT_HDMI] = 18, |
| 188 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15, |
| 189 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 190 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 191 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 192 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 193 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 194 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
| 195 | |
| 196 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
| 197 | [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */ |
| 198 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
| 199 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40, |
| 200 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42, |
| 201 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47, |
| 202 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 203 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 204 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 205 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 206 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 207 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
| 208 | [SND_DEVICE_IN_VOICE_DMIC_EF] = 41, |
| 209 | [SND_DEVICE_IN_VOICE_DMIC_BS] = 5, |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 210 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 211 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 43, |
| 212 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12, |
| 213 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 214 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 215 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
| 216 | [SND_DEVICE_IN_VOICE_REC_MIC] = 62, |
| 217 | /* TODO: Update with proper acdb ids */ |
| 218 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62, |
| 219 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62, |
| 220 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6, |
| 221 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5, |
| 222 | }; |
| 223 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 224 | struct name_to_index { |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 225 | char name[100]; |
| 226 | unsigned int index; |
| 227 | }; |
| 228 | |
| 229 | #define TO_NAME_INDEX(X) #X, X |
| 230 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 231 | /* Used to get index from parsed string */ |
| 232 | static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { |
| 233 | /* out */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 234 | {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)}, |
| 235 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)}, |
| 236 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)}, |
| 237 | {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)}, |
| 238 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)}, |
| 239 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)}, |
| 240 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)}, |
| 241 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)}, |
| 242 | {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)}, |
| 243 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)}, |
| 244 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)}, |
| 245 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 246 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 247 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)}, |
| 248 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)}, |
| 249 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 250 | |
| 251 | /* in */ |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 252 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 253 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 254 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 255 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)}, |
| 256 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)}, |
| 257 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 258 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)}, |
| 259 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)}, |
| 260 | {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)}, |
| 261 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)}, |
| 262 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)}, |
| 263 | {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 264 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_EF)}, |
| 265 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_BS)}, |
| 266 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_EF_TMUS)}, |
| 267 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF)}, |
| 268 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 269 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)}, |
| 270 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)}, |
| 271 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)}, |
| 272 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)}, |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 273 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_EF)}, |
| 274 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_BS)}, |
| 275 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE)}, |
| 276 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE)}, |
| 277 | }; |
| 278 | |
| 279 | static char * backend_table[SND_DEVICE_MAX] = {0}; |
| 280 | |
| 281 | static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = { |
| 282 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)}, |
| 283 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)}, |
| 284 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)}, |
| 285 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)}, |
| 286 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD)}, |
| 287 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)}, |
| 288 | {TO_NAME_INDEX(USECASE_VOICE_CALL)}, |
| 289 | {TO_NAME_INDEX(USECASE_VOICE2_CALL)}, |
| 290 | {TO_NAME_INDEX(USECASE_VOLTE_CALL)}, |
| 291 | {TO_NAME_INDEX(USECASE_QCHAT_CALL)}, |
| 292 | {TO_NAME_INDEX(USECASE_VOWLAN_CALL)}, |
| 293 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)}, |
| 294 | {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)}, |
| 295 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)}, |
| 296 | {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)}, |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 299 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 300 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
| 301 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 302 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 303 | static bool is_tmus = false; |
| 304 | |
| 305 | static void check_operator() |
| 306 | { |
| 307 | char value[PROPERTY_VALUE_MAX]; |
| 308 | int mccmnc; |
| 309 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 310 | mccmnc = atoi(value); |
| 311 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
| 312 | switch(mccmnc) { |
| 313 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 314 | case 310490: |
| 315 | case 310260: |
| 316 | case 310026: |
sangwon.jeon | b891db5 | 2013-09-14 17:39:15 +0900 | [diff] [blame] | 317 | /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */ |
| 318 | case 310800: |
| 319 | case 310660: |
| 320 | case 310580: |
| 321 | case 310310: |
| 322 | case 310270: |
| 323 | case 310250: |
| 324 | case 310240: |
| 325 | case 310230: |
| 326 | case 310220: |
| 327 | case 310210: |
| 328 | case 310200: |
| 329 | case 310160: |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 330 | is_tmus = true; |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | bool is_operator_tmus() |
| 336 | { |
| 337 | pthread_once(&check_op_once_ctl, check_operator); |
| 338 | return is_tmus; |
| 339 | } |
| 340 | |
| 341 | static int set_echo_reference(struct mixer *mixer, const char* ec_ref) |
| 342 | { |
| 343 | struct mixer_ctl *ctl; |
| 344 | const char *mixer_ctl_name = "EC_REF_RX"; |
| 345 | |
| 346 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 347 | if (!ctl) { |
| 348 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 349 | __func__, mixer_ctl_name); |
| 350 | return -EINVAL; |
| 351 | } |
| 352 | ALOGV("Setting EC Reference: %s", ec_ref); |
| 353 | mixer_ctl_set_enum_by_string(ctl, ec_ref); |
| 354 | return 0; |
| 355 | } |
| 356 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 357 | static struct csd_data *open_csd_client(bool i2s_ext_modem) |
| 358 | { |
| 359 | struct csd_data *csd = calloc(1, sizeof(struct csd_data)); |
| 360 | |
| 361 | csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 362 | if (csd->csd_client == NULL) { |
| 363 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 364 | goto error; |
| 365 | } else { |
| 366 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 367 | |
| 368 | csd->deinit = (deinit_t)dlsym(csd->csd_client, |
| 369 | "csd_client_deinit"); |
| 370 | if (csd->deinit == NULL) { |
| 371 | ALOGE("%s: dlsym error %s for csd_client_deinit", __func__, |
| 372 | dlerror()); |
| 373 | goto error; |
| 374 | } |
| 375 | csd->disable_device = (disable_device_t)dlsym(csd->csd_client, |
| 376 | "csd_client_disable_device"); |
| 377 | if (csd->disable_device == NULL) { |
| 378 | ALOGE("%s: dlsym error %s for csd_client_disable_device", |
| 379 | __func__, dlerror()); |
| 380 | goto error; |
| 381 | } |
| 382 | csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client, |
| 383 | "csd_client_enable_device_config"); |
| 384 | if (csd->enable_device_config == NULL) { |
| 385 | ALOGE("%s: dlsym error %s for csd_client_enable_device_config", |
| 386 | __func__, dlerror()); |
| 387 | goto error; |
| 388 | } |
| 389 | csd->enable_device = (enable_device_t)dlsym(csd->csd_client, |
| 390 | "csd_client_enable_device"); |
| 391 | if (csd->enable_device == NULL) { |
| 392 | ALOGE("%s: dlsym error %s for csd_client_enable_device", |
| 393 | __func__, dlerror()); |
| 394 | goto error; |
| 395 | } |
| 396 | csd->start_voice = (start_voice_t)dlsym(csd->csd_client, |
| 397 | "csd_client_start_voice"); |
| 398 | if (csd->start_voice == NULL) { |
| 399 | ALOGE("%s: dlsym error %s for csd_client_start_voice", |
| 400 | __func__, dlerror()); |
| 401 | goto error; |
| 402 | } |
| 403 | csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client, |
| 404 | "csd_client_stop_voice"); |
| 405 | if (csd->stop_voice == NULL) { |
| 406 | ALOGE("%s: dlsym error %s for csd_client_stop_voice", |
| 407 | __func__, dlerror()); |
| 408 | goto error; |
| 409 | } |
| 410 | csd->volume = (volume_t)dlsym(csd->csd_client, |
| 411 | "csd_client_volume"); |
| 412 | if (csd->volume == NULL) { |
| 413 | ALOGE("%s: dlsym error %s for csd_client_volume", |
| 414 | __func__, dlerror()); |
| 415 | goto error; |
| 416 | } |
| 417 | csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client, |
| 418 | "csd_client_mic_mute"); |
| 419 | if (csd->mic_mute == NULL) { |
| 420 | ALOGE("%s: dlsym error %s for csd_client_mic_mute", |
| 421 | __func__, dlerror()); |
| 422 | goto error; |
| 423 | } |
| 424 | csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client, |
| 425 | "csd_client_slow_talk"); |
| 426 | if (csd->slow_talk == NULL) { |
| 427 | ALOGE("%s: dlsym error %s for csd_client_slow_talk", |
| 428 | __func__, dlerror()); |
| 429 | goto error; |
| 430 | } |
| 431 | csd->start_playback = (start_playback_t)dlsym(csd->csd_client, |
| 432 | "csd_client_start_playback"); |
| 433 | if (csd->start_playback == NULL) { |
| 434 | ALOGE("%s: dlsym error %s for csd_client_start_playback", |
| 435 | __func__, dlerror()); |
| 436 | goto error; |
| 437 | } |
| 438 | csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client, |
| 439 | "csd_client_stop_playback"); |
| 440 | if (csd->stop_playback == NULL) { |
| 441 | ALOGE("%s: dlsym error %s for csd_client_stop_playback", |
| 442 | __func__, dlerror()); |
| 443 | goto error; |
| 444 | } |
| 445 | csd->start_record = (start_record_t)dlsym(csd->csd_client, |
| 446 | "csd_client_start_record"); |
| 447 | if (csd->start_record == NULL) { |
| 448 | ALOGE("%s: dlsym error %s for csd_client_start_record", |
| 449 | __func__, dlerror()); |
| 450 | goto error; |
| 451 | } |
| 452 | csd->stop_record = (stop_record_t)dlsym(csd->csd_client, |
| 453 | "csd_client_stop_record"); |
| 454 | if (csd->stop_record == NULL) { |
| 455 | ALOGE("%s: dlsym error %s for csd_client_stop_record", |
| 456 | __func__, dlerror()); |
| 457 | goto error; |
| 458 | } |
| 459 | |
| 460 | csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client, |
| 461 | "csd_client_get_sample_rate"); |
| 462 | if (csd->get_sample_rate == NULL) { |
| 463 | ALOGE("%s: dlsym error %s for csd_client_get_sample_rate", |
| 464 | __func__, dlerror()); |
| 465 | |
| 466 | goto error; |
| 467 | } |
| 468 | |
| 469 | csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init"); |
| 470 | |
| 471 | if (csd->init == NULL) { |
| 472 | ALOGE("%s: dlsym error %s for csd_client_init", |
| 473 | __func__, dlerror()); |
| 474 | goto error; |
| 475 | } else { |
| 476 | csd->init(i2s_ext_modem); |
| 477 | } |
| 478 | } |
| 479 | return csd; |
| 480 | |
| 481 | error: |
| 482 | free(csd); |
| 483 | csd = NULL; |
| 484 | return csd; |
| 485 | } |
| 486 | |
| 487 | void close_csd_client(struct csd_data *csd) |
| 488 | { |
| 489 | if (csd != NULL) { |
| 490 | csd->deinit(); |
| 491 | dlclose(csd->csd_client); |
| 492 | free(csd); |
| 493 | csd = NULL; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | static void platform_csd_init(struct platform_data *my_data) |
| 498 | { |
| 499 | #ifdef PLATFORM_MSM8084 |
| 500 | struct dev_info mdm_detect_info; |
| 501 | int ret = 0; |
| 502 | |
| 503 | /* Call ESOC API to get the number of modems. |
| 504 | * If the number of modems is not zero, load CSD Client specific |
| 505 | * symbols. Voice call is handled by MDM and apps processor talks to |
| 506 | * MDM through CSD Client |
| 507 | */ |
| 508 | ret = get_system_info(&mdm_detect_info); |
| 509 | if (ret > 0) { |
| 510 | ALOGE("%s: Failed to get system info, ret %d", __func__, ret); |
| 511 | } |
| 512 | ALOGD("%s: num_modems %d\n", __func__, mdm_detect_info.num_modems); |
| 513 | |
| 514 | if (mdm_detect_info.num_modems > 0) |
| 515 | my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/); |
| 516 | #else |
| 517 | my_data->csd = NULL; |
| 518 | #endif |
| 519 | } |
| 520 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 521 | static void set_platform_defaults(struct platform_data * my_data) |
| 522 | { |
| 523 | int32_t dev; |
| 524 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 525 | backend_table[dev] = NULL; |
| 526 | } |
| 527 | |
| 528 | // TBD - do these go to the platform-info.xml file. |
| 529 | // will help in avoiding strdups here |
| 530 | backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco"); |
| 531 | backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco"); |
| 532 | backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi"); |
| 533 | backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi"); |
| 534 | backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb"); |
| 535 | backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb"); |
| 536 | |
| 537 | if (my_data->ext_speaker) { |
| 538 | backend_table[SND_DEVICE_OUT_SPEAKER] = strdup("speaker"); |
| 539 | backend_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("speaker"); |
| 540 | backend_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("speaker"); |
| 541 | backend_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = |
| 542 | strdup("speaker-and-headphones"); |
| 543 | } |
| 544 | |
| 545 | if (my_data->ext_earpiece) { |
| 546 | backend_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("handset"); |
| 547 | backend_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("handset"); |
| 548 | backend_table[SND_DEVICE_OUT_HANDSET] = strdup("handset"); |
| 549 | backend_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("handset"); |
| 550 | } |
| 551 | } |
| 552 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 553 | void *platform_init(struct audio_device *adev) |
| 554 | { |
| 555 | char value[PROPERTY_VALUE_MAX]; |
| 556 | struct platform_data *my_data; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 557 | int retry_num = 0, snd_card_num = 0; |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 558 | const char *snd_card_name; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 559 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 560 | while (snd_card_num < MAX_SND_CARD) { |
| 561 | adev->mixer = mixer_open(snd_card_num); |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 562 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 563 | while (!adev->mixer && retry_num < RETRY_NUMBER) { |
| 564 | usleep(RETRY_US); |
| 565 | adev->mixer = mixer_open(snd_card_num); |
| 566 | retry_num++; |
| 567 | } |
| 568 | |
| 569 | if (!adev->mixer) { |
| 570 | ALOGE("%s: Unable to open the mixer card: %d", __func__, |
| 571 | snd_card_num); |
| 572 | retry_num = 0; |
| 573 | snd_card_num++; |
| 574 | continue; |
| 575 | } |
| 576 | |
| 577 | snd_card_name = mixer_get_name(adev->mixer); |
| 578 | ALOGD("%s: snd_card_name: %s", __func__, snd_card_name); |
| 579 | |
| 580 | adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH); |
| 581 | if (!adev->audio_route) { |
| 582 | ALOGE("%s: Failed to init audio route controls, aborting.", __func__); |
| 583 | return NULL; |
| 584 | } |
| 585 | adev->snd_card = snd_card_num; |
| 586 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 587 | break; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 590 | if (snd_card_num >= MAX_SND_CARD) { |
| 591 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 592 | return NULL; |
| 593 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 594 | |
| 595 | my_data = calloc(1, sizeof(struct platform_data)); |
| 596 | |
| 597 | my_data->adev = adev; |
| 598 | my_data->dualmic_config = DUALMIC_CONFIG_NONE; |
| 599 | my_data->fluence_in_spkr_mode = false; |
| 600 | my_data->fluence_in_voice_call = false; |
| 601 | my_data->fluence_in_voice_rec = false; |
| 602 | |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 603 | /* |
| 604 | * The default assumption is that earpiece (handset), speaker and headphones |
| 605 | * devices are connected to internal HW codec and communicated through |
| 606 | * slimbus backend. If any platform communicates with speaker or earpiece |
| 607 | * or headphones through non-slimbus backend such as MI2S or AUXPCM etc., |
| 608 | * the ext_xxxx flags must be set accordingly. |
| 609 | */ |
| 610 | if (strstr(snd_card_name, "tfa9890_stereo")) { |
| 611 | my_data->ext_speaker = true; |
| 612 | my_data->ext_earpiece = true; |
| 613 | } else if (strstr(snd_card_name, "tfa9890")) { |
| 614 | my_data->ext_speaker = true; |
| 615 | } |
| 616 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 617 | property_get("persist.audio.dualmic.config",value,""); |
| 618 | if (!strcmp("broadside", value)) { |
| 619 | my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE; |
| 620 | adev->acdb_settings |= DMIC_FLAG; |
| 621 | } else if (!strcmp("endfire", value)) { |
| 622 | my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE; |
| 623 | adev->acdb_settings |= DMIC_FLAG; |
| 624 | } |
| 625 | |
| 626 | if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) { |
| 627 | property_get("persist.audio.fluence.voicecall",value,""); |
| 628 | if (!strcmp("true", value)) { |
| 629 | my_data->fluence_in_voice_call = true; |
| 630 | } |
| 631 | |
| 632 | property_get("persist.audio.fluence.voicerec",value,""); |
| 633 | if (!strcmp("true", value)) { |
| 634 | my_data->fluence_in_voice_rec = true; |
| 635 | } |
| 636 | |
| 637 | property_get("persist.audio.fluence.speaker",value,""); |
| 638 | if (!strcmp("true", value)) { |
| 639 | my_data->fluence_in_spkr_mode = true; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 644 | if (my_data->acdb_handle == NULL) { |
| 645 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 646 | } else { |
| 647 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 648 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 649 | "acdb_loader_deallocate_ACDB"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 650 | if (!my_data->acdb_deallocate) |
| 651 | ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s", |
| 652 | __func__, LIB_ACDB_LOADER); |
| 653 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 654 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 655 | "acdb_loader_send_audio_cal"); |
| 656 | if (!my_data->acdb_send_audio_cal) |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 657 | 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] | 658 | __func__, LIB_ACDB_LOADER); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 659 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 660 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 661 | "acdb_loader_send_voice_cal"); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 662 | if (!my_data->acdb_send_voice_cal) |
| 663 | ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s", |
| 664 | __func__, LIB_ACDB_LOADER); |
| 665 | |
| 666 | my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle, |
| 667 | "acdb_loader_reload_vocvoltable"); |
| 668 | if (!my_data->acdb_reload_vocvoltable) |
| 669 | ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s", |
| 670 | __func__, LIB_ACDB_LOADER); |
| 671 | #ifdef PLATFORM_MSM8084 |
| 672 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
| 673 | "acdb_loader_init_v2"); |
| 674 | if (my_data->acdb_init == NULL) |
| 675 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); |
| 676 | else |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 677 | my_data->acdb_init((char *)snd_card_name); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 678 | #else |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 679 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
| 680 | "acdb_loader_init_ACDB"); |
| 681 | if (my_data->acdb_init == NULL) |
| 682 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); |
| 683 | else |
| 684 | my_data->acdb_init(); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 685 | #endif |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 686 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 689 | set_platform_defaults(my_data); |
| 690 | |
| 691 | /* Initialize platform specific ids and/or backends*/ |
| 692 | platform_info_init(); |
| 693 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 694 | /* load csd client */ |
| 695 | platform_csd_init(my_data); |
| 696 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 697 | return my_data; |
| 698 | } |
| 699 | |
| 700 | void platform_deinit(void *platform) |
| 701 | { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 702 | struct platform_data *my_data = (struct platform_data *)platform; |
| 703 | close_csd_client(my_data->csd); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 704 | free(platform); |
| 705 | } |
| 706 | |
| 707 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 708 | { |
| 709 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) |
| 710 | return device_table[snd_device]; |
| 711 | else |
| 712 | return ""; |
| 713 | } |
| 714 | |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 715 | void platform_add_backend_name(void *platform, char *mixer_path, |
| 716 | snd_device_t snd_device) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 717 | { |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 718 | struct platform_data *my_data = (struct platform_data *)platform; |
| 719 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 720 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 721 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 722 | return; |
Ravi Kumar Alamanda | 1de6e5a | 2014-06-19 21:55:39 -0500 | [diff] [blame] | 723 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 724 | |
| 725 | const char * suffix = backend_table[snd_device]; |
| 726 | |
| 727 | if (suffix != NULL) { |
| 728 | strcat(mixer_path, " "); |
| 729 | strcat(mixer_path, suffix); |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 730 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 734 | { |
| 735 | int device_id; |
| 736 | if (device_type == PCM_PLAYBACK) |
| 737 | device_id = pcm_device_table[usecase][0]; |
| 738 | else |
| 739 | device_id = pcm_device_table[usecase][1]; |
| 740 | return device_id; |
| 741 | } |
| 742 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 743 | static int find_index(const struct name_to_index * table, int32_t len, |
| 744 | const char * name) |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 745 | { |
| 746 | int ret = 0; |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 747 | int32_t i; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 748 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 749 | if (table == NULL) { |
| 750 | ALOGE("%s: table is NULL", __func__); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 751 | ret = -ENODEV; |
| 752 | goto done; |
| 753 | } |
| 754 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 755 | if (name == NULL) { |
| 756 | ALOGE("null key"); |
| 757 | ret = -ENODEV; |
| 758 | goto done; |
| 759 | } |
| 760 | |
| 761 | for (i=0; i < len; i++) { |
| 762 | if (!strcmp(table[i].name, name)) { |
| 763 | ret = table[i].index; |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 764 | goto done; |
| 765 | } |
| 766 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 767 | ALOGE("%s: Could not find index for name = %s", |
| 768 | __func__, name); |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 769 | ret = -ENODEV; |
| 770 | done: |
| 771 | return ret; |
| 772 | } |
| 773 | |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 774 | int platform_get_snd_device_index(char *device_name) |
| 775 | { |
| 776 | return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name); |
| 777 | } |
| 778 | |
| 779 | int platform_get_usecase_index(const char *usecase_name) |
| 780 | { |
| 781 | return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name); |
| 782 | } |
| 783 | |
Haynes Mathew George | 5bc1884 | 2014-06-16 16:36:20 -0700 | [diff] [blame] | 784 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id) |
| 785 | { |
| 786 | int ret = 0; |
| 787 | |
| 788 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 789 | ALOGE("%s: Invalid snd_device = %d", |
| 790 | __func__, snd_device); |
| 791 | ret = -EINVAL; |
| 792 | goto done; |
| 793 | } |
| 794 | |
| 795 | acdb_device_table[snd_device] = acdb_id; |
| 796 | done: |
| 797 | return ret; |
| 798 | } |
| 799 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 800 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 801 | { |
| 802 | struct platform_data *my_data = (struct platform_data *)platform; |
| 803 | int acdb_dev_id, acdb_dev_type; |
| 804 | |
| 805 | acdb_dev_id = acdb_device_table[snd_device]; |
| 806 | if (acdb_dev_id < 0) { |
| 807 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 808 | __func__, snd_device); |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | if (my_data->acdb_send_audio_cal) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 812 | ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 813 | __func__, snd_device, acdb_dev_id); |
| 814 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 815 | snd_device < SND_DEVICE_OUT_END) |
| 816 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 817 | else |
| 818 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 819 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 820 | } |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | int platform_switch_voice_call_device_pre(void *platform) |
| 825 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 826 | struct platform_data *my_data = (struct platform_data *)platform; |
| 827 | int ret = 0; |
| 828 | |
| 829 | if (my_data->csd != NULL && |
| 830 | my_data->adev->mode == AUDIO_MODE_IN_CALL) { |
| 831 | /* This must be called before disabling mixer controls on APQ side */ |
| 832 | ret = my_data->csd->disable_device(); |
| 833 | if (ret < 0) { |
| 834 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 835 | __func__, ret); |
| 836 | } |
| 837 | } |
| 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | int platform_switch_voice_call_enable_device_config(void *platform, |
| 842 | snd_device_t out_snd_device, |
| 843 | snd_device_t in_snd_device) |
| 844 | { |
| 845 | struct platform_data *my_data = (struct platform_data *)platform; |
| 846 | int acdb_rx_id, acdb_tx_id; |
| 847 | int ret = 0; |
| 848 | |
| 849 | if (my_data->csd == NULL) |
| 850 | return ret; |
| 851 | |
| 852 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 853 | |
| 854 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 855 | |
| 856 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 857 | ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id); |
| 858 | if (ret < 0) { |
| 859 | ALOGE("%s: csd_enable_device_config, failed, error %d", |
| 860 | __func__, ret); |
| 861 | } |
| 862 | } else { |
| 863 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 864 | acdb_rx_id, acdb_tx_id); |
| 865 | } |
| 866 | |
| 867 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | int platform_switch_voice_call_device_post(void *platform, |
| 871 | snd_device_t out_snd_device, |
| 872 | snd_device_t in_snd_device) |
| 873 | { |
| 874 | struct platform_data *my_data = (struct platform_data *)platform; |
| 875 | int acdb_rx_id, acdb_tx_id; |
| 876 | |
| 877 | if (my_data->acdb_send_voice_cal == NULL) { |
| 878 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 879 | } else { |
| 880 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 881 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 882 | |
| 883 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 884 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 885 | else |
| 886 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 887 | acdb_rx_id, acdb_tx_id); |
| 888 | } |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 893 | int platform_switch_voice_call_usecase_route_post(void *platform, |
| 894 | snd_device_t out_snd_device, |
| 895 | snd_device_t in_snd_device) |
| 896 | { |
| 897 | struct platform_data *my_data = (struct platform_data *)platform; |
| 898 | int acdb_rx_id, acdb_tx_id; |
| 899 | int ret = 0; |
| 900 | |
| 901 | if (my_data->csd == NULL) |
| 902 | return ret; |
| 903 | |
| 904 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 905 | |
| 906 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 907 | |
| 908 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 909 | ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id, |
| 910 | my_data->adev->acdb_settings); |
| 911 | if (ret < 0) { |
| 912 | ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret); |
| 913 | } |
| 914 | } else { |
| 915 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 916 | acdb_rx_id, acdb_tx_id); |
| 917 | } |
| 918 | |
| 919 | return ret; |
| 920 | } |
| 921 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 922 | int platform_start_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 923 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 924 | struct platform_data *my_data = (struct platform_data *)platform; |
| 925 | int ret = 0; |
| 926 | |
| 927 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 928 | ret = my_data->csd->start_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 929 | if (ret < 0) { |
| 930 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 931 | } |
| 932 | } |
| 933 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 936 | int platform_stop_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 937 | { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 938 | struct platform_data *my_data = (struct platform_data *)platform; |
| 939 | int ret = 0; |
| 940 | |
| 941 | if (my_data->csd != NULL) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 942 | ret = my_data->csd->stop_voice(vsid); |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 943 | if (ret < 0) { |
| 944 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 945 | } |
| 946 | } |
| 947 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 950 | int platform_get_sample_rate(void *platform, uint32_t *rate) |
| 951 | { |
| 952 | struct platform_data *my_data = (struct platform_data *)platform; |
| 953 | int ret = 0; |
| 954 | |
| 955 | if (my_data->csd != NULL) { |
| 956 | ret = my_data->csd->get_sample_rate(rate); |
| 957 | if (ret < 0) { |
| 958 | ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret); |
| 959 | } |
| 960 | } |
| 961 | return ret; |
| 962 | } |
| 963 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 964 | int platform_set_voice_volume(void *platform, int volume) |
| 965 | { |
| 966 | struct platform_data *my_data = (struct platform_data *)platform; |
| 967 | struct audio_device *adev = my_data->adev; |
| 968 | struct mixer_ctl *ctl; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 969 | const char *mixer_ctl_name = "Voice Rx Gain"; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 970 | int vol_index = 0, ret = 0; |
| 971 | uint32_t set_values[ ] = {0, |
| 972 | ALL_SESSION_VSID, |
| 973 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 974 | |
| 975 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 976 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 977 | // But this values don't changed in kernel. So, below change is need. |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 978 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX); |
| 979 | set_values[0] = vol_index; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 980 | |
| 981 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 982 | if (!ctl) { |
| 983 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 984 | __func__, mixer_ctl_name); |
| 985 | return -EINVAL; |
| 986 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 987 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 988 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 989 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 990 | if (my_data->csd != NULL) { |
| 991 | ret = my_data->csd->volume(ALL_SESSION_VSID, volume, |
| 992 | DEFAULT_VOLUME_RAMP_DURATION_MS); |
| 993 | if (ret < 0) { |
| 994 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 995 | } |
| 996 | } |
| 997 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | int platform_set_mic_mute(void *platform, bool state) |
| 1001 | { |
| 1002 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1003 | struct audio_device *adev = my_data->adev; |
| 1004 | struct mixer_ctl *ctl; |
| 1005 | const char *mixer_ctl_name = "Voice Tx Mute"; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1006 | int ret = 0; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1007 | uint32_t set_values[ ] = {0, |
| 1008 | ALL_SESSION_VSID, |
| 1009 | DEFAULT_MUTE_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1010 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1011 | if (adev->mode != AUDIO_MODE_IN_CALL) |
| 1012 | return 0; |
| 1013 | |
| 1014 | set_values[0] = state; |
| 1015 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1016 | if (!ctl) { |
| 1017 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1018 | __func__, mixer_ctl_name); |
| 1019 | return -EINVAL; |
| 1020 | } |
| 1021 | ALOGV("Setting voice mute state: %d", state); |
| 1022 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1023 | |
| 1024 | if (my_data->csd != NULL) { |
| 1025 | ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state, |
| 1026 | DEFAULT_MUTE_RAMP_DURATION_MS); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1027 | if (ret < 0) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1028 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1029 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1030 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1033 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1034 | int platform_set_device_mute(void *platform, bool state, char *dir) |
| 1035 | { |
| 1036 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1037 | struct audio_device *adev = my_data->adev; |
| 1038 | struct mixer_ctl *ctl; |
| 1039 | char *mixer_ctl_name = NULL; |
| 1040 | int ret = 0; |
| 1041 | uint32_t set_values[ ] = {0, |
| 1042 | ALL_SESSION_VSID, |
| 1043 | 0}; |
| 1044 | if(dir == NULL) { |
| 1045 | ALOGE("%s: Invalid direction:%s", __func__, dir); |
| 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
| 1049 | if (!strncmp("rx", dir, sizeof("rx"))) { |
| 1050 | mixer_ctl_name = "Voice Rx Device Mute"; |
| 1051 | } else if (!strncmp("tx", dir, sizeof("tx"))) { |
| 1052 | mixer_ctl_name = "Voice Tx Device Mute"; |
| 1053 | } else { |
| 1054 | return -EINVAL; |
| 1055 | } |
| 1056 | |
| 1057 | set_values[0] = state; |
| 1058 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1059 | if (!ctl) { |
| 1060 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1061 | __func__, mixer_ctl_name); |
| 1062 | return -EINVAL; |
| 1063 | } |
| 1064 | |
| 1065 | ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s", |
| 1066 | __func__,state, mixer_ctl_name); |
| 1067 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1068 | |
| 1069 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 1073 | { |
| 1074 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1075 | struct audio_device *adev = my_data->adev; |
| 1076 | audio_mode_t mode = adev->mode; |
| 1077 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 1078 | |
| 1079 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 1080 | if (devices == AUDIO_DEVICE_NONE || |
| 1081 | devices & AUDIO_DEVICE_BIT_IN) { |
| 1082 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 1083 | goto exit; |
| 1084 | } |
| 1085 | |
| 1086 | if (mode == AUDIO_MODE_IN_CALL) { |
| 1087 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1088 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1089 | if (adev->voice.tty_mode == TTY_MODE_FULL) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1090 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1091 | else if (adev->voice.tty_mode == TTY_MODE_VCO) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1092 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1093 | else if (adev->voice.tty_mode == TTY_MODE_HCO) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1094 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 1095 | else |
| 1096 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
| 1097 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1098 | if (adev->bt_wb_speech_enabled) { |
| 1099 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1100 | } else { |
| 1101 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 1102 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1103 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1104 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 1105 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1106 | if (is_operator_tmus()) |
| 1107 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
| 1108 | else |
Eric Laurent | b4d368e | 2014-06-25 10:21:54 -0500 | [diff] [blame] | 1109 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1110 | } |
| 1111 | if (snd_device != SND_DEVICE_NONE) { |
| 1112 | goto exit; |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | if (popcount(devices) == 2) { |
| 1117 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 1118 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1119 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 1120 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 1121 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1122 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 1123 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 1124 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1125 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
| 1126 | } else { |
| 1127 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 1128 | goto exit; |
| 1129 | } |
| 1130 | if (snd_device != SND_DEVICE_NONE) { |
| 1131 | goto exit; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | if (popcount(devices) != 1) { |
| 1136 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 1137 | goto exit; |
| 1138 | } |
| 1139 | |
| 1140 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1141 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1142 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
| 1143 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1144 | if (adev->speaker_lr_swap) |
| 1145 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 1146 | else |
| 1147 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 1148 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1149 | if (adev->bt_wb_speech_enabled) { |
| 1150 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1151 | } else { |
| 1152 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 1153 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1154 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1155 | snd_device = SND_DEVICE_OUT_HDMI ; |
| 1156 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1157 | snd_device = SND_DEVICE_OUT_HANDSET; |
| 1158 | } else { |
| 1159 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 1160 | } |
| 1161 | exit: |
| 1162 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 1163 | return snd_device; |
| 1164 | } |
| 1165 | |
| 1166 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 1167 | { |
| 1168 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1169 | struct audio_device *adev = my_data->adev; |
| 1170 | audio_source_t source = (adev->active_input == NULL) ? |
| 1171 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 1172 | |
| 1173 | audio_mode_t mode = adev->mode; |
| 1174 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 1175 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 1176 | & ~AUDIO_DEVICE_BIT_IN; |
| 1177 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1178 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1179 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 1180 | |
| 1181 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
| 1182 | __func__, out_device, in_device); |
| 1183 | if (mode == AUDIO_MODE_IN_CALL) { |
| 1184 | if (out_device == AUDIO_DEVICE_NONE) { |
| 1185 | ALOGE("%s: No output device set for voice call", __func__); |
| 1186 | goto exit; |
| 1187 | } |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1188 | if (adev->voice.tty_mode != TTY_MODE_OFF) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1189 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1190 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1191 | switch (adev->voice.tty_mode) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1192 | case TTY_MODE_FULL: |
| 1193 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 1194 | break; |
| 1195 | case TTY_MODE_VCO: |
| 1196 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 1197 | break; |
| 1198 | case TTY_MODE_HCO: |
| 1199 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 1200 | break; |
| 1201 | default: |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1202 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1203 | } |
| 1204 | goto exit; |
| 1205 | } |
| 1206 | } |
| 1207 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 1208 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 1209 | if (my_data->fluence_in_voice_call == false) { |
| 1210 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 1211 | set_echo_reference(adev->mixer, "SLIM_RX"); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1212 | } else { |
| 1213 | if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 1214 | if (is_operator_tmus()) |
| 1215 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS; |
| 1216 | else |
| 1217 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF; |
| 1218 | } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) |
| 1219 | snd_device = SND_DEVICE_IN_VOICE_DMIC_BS; |
| 1220 | else |
| 1221 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1222 | } |
| 1223 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1224 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 1225 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1226 | if (adev->bt_wb_speech_enabled) { |
| 1227 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1228 | } else { |
| 1229 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1230 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1231 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1232 | if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode && |
| 1233 | my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 1234 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF; |
| 1235 | } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode && |
| 1236 | my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 1237 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS; |
| 1238 | } else { |
| 1239 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 1240 | } |
| 1241 | } |
| 1242 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 1243 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 1244 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1245 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 1246 | } |
| 1247 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1248 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1249 | if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 1250 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 1251 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF; |
| 1252 | else if (my_data->fluence_in_voice_rec) |
| 1253 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE; |
| 1254 | } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 1255 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 1256 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS; |
| 1257 | else if (my_data->fluence_in_voice_rec) |
| 1258 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE; |
| 1259 | } |
| 1260 | |
| 1261 | if (snd_device == SND_DEVICE_NONE) { |
| 1262 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 1263 | } |
| 1264 | } |
| 1265 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 1266 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 1267 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 1268 | if (adev->active_input) { |
| 1269 | if (adev->active_input->enable_aec) { |
| 1270 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1271 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
| 1272 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1273 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
| 1274 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1275 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
| 1276 | } |
| 1277 | set_echo_reference(adev->mixer, "SLIM_RX"); |
| 1278 | } else |
| 1279 | set_echo_reference(adev->mixer, "NONE"); |
| 1280 | } |
| 1281 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 1282 | goto exit; |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | if (snd_device != SND_DEVICE_NONE) { |
| 1287 | goto exit; |
| 1288 | } |
| 1289 | |
| 1290 | if (in_device != AUDIO_DEVICE_NONE && |
| 1291 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 1292 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 1293 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1294 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1295 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1296 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 1297 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1298 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 1299 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1300 | if (adev->bt_wb_speech_enabled) { |
| 1301 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1302 | } else { |
| 1303 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1304 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1305 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 1306 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 1307 | } else { |
| 1308 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 1309 | ALOGW("%s: Using default handset-mic", __func__); |
| 1310 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1311 | } |
| 1312 | } else { |
| 1313 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1314 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1315 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1316 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 1317 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1318 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 1319 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 1320 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1321 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 1322 | if (adev->bt_wb_speech_enabled) { |
| 1323 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1324 | } else { |
| 1325 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1326 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1327 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1328 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 1329 | } else { |
| 1330 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 1331 | ALOGW("%s: Using default handset-mic", __func__); |
| 1332 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1333 | } |
| 1334 | } |
| 1335 | exit: |
| 1336 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 1337 | return snd_device; |
| 1338 | } |
| 1339 | |
| 1340 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 1341 | { |
| 1342 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1343 | struct audio_device *adev = my_data->adev; |
| 1344 | struct mixer_ctl *ctl; |
| 1345 | const char *channel_cnt_str = NULL; |
| 1346 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 1347 | switch (channel_count) { |
| 1348 | case 8: |
| 1349 | channel_cnt_str = "Eight"; break; |
| 1350 | case 7: |
| 1351 | channel_cnt_str = "Seven"; break; |
| 1352 | case 6: |
| 1353 | channel_cnt_str = "Six"; break; |
| 1354 | case 5: |
| 1355 | channel_cnt_str = "Five"; break; |
| 1356 | case 4: |
| 1357 | channel_cnt_str = "Four"; break; |
| 1358 | case 3: |
| 1359 | channel_cnt_str = "Three"; break; |
| 1360 | default: |
| 1361 | channel_cnt_str = "Two"; break; |
| 1362 | } |
| 1363 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1364 | if (!ctl) { |
| 1365 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1366 | __func__, mixer_ctl_name); |
| 1367 | return -EINVAL; |
| 1368 | } |
| 1369 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 1370 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1374 | int platform_edid_get_max_channels(void *platform) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1375 | { |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1376 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1377 | struct audio_device *adev = my_data->adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1378 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 1379 | char *sad = block; |
| 1380 | int num_audio_blocks; |
| 1381 | int channel_count; |
| 1382 | int max_channels = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1383 | int i, ret, count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1384 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1385 | struct mixer_ctl *ctl; |
| 1386 | |
| 1387 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 1388 | if (!ctl) { |
| 1389 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1390 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1391 | return 0; |
| 1392 | } |
| 1393 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1394 | mixer_ctl_update(ctl); |
| 1395 | |
| 1396 | count = mixer_ctl_get_num_values(ctl); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1397 | |
| 1398 | /* Read SAD blocks, clamping the maximum size for safety */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1399 | if (count > (int)sizeof(block)) |
| 1400 | count = (int)sizeof(block); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1401 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1402 | ret = mixer_ctl_get_array(ctl, block, count); |
| 1403 | if (ret != 0) { |
| 1404 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 1405 | return 0; |
| 1406 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1407 | |
| 1408 | /* Calculate the number of SAD blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1409 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1410 | |
| 1411 | for (i = 0; i < num_audio_blocks; i++) { |
| 1412 | /* Only consider LPCM blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1413 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 1414 | sad += 3; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1415 | continue; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1416 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1417 | |
| 1418 | channel_count = (sad[0] & 0x7) + 1; |
| 1419 | if (channel_count > max_channels) |
| 1420 | max_channels = channel_count; |
| 1421 | |
| 1422 | /* Advance to next block */ |
| 1423 | sad += 3; |
| 1424 | } |
| 1425 | |
| 1426 | return max_channels; |
| 1427 | } |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 1428 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1429 | int platform_set_incall_recording_session_id(void *platform, |
| 1430 | uint32_t session_id, int rec_mode) |
| 1431 | { |
| 1432 | int ret = 0; |
| 1433 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1434 | struct audio_device *adev = my_data->adev; |
| 1435 | struct mixer_ctl *ctl; |
| 1436 | const char *mixer_ctl_name = "Voc VSID"; |
| 1437 | int num_ctl_values; |
| 1438 | int i; |
| 1439 | |
| 1440 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1441 | if (!ctl) { |
| 1442 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1443 | __func__, mixer_ctl_name); |
| 1444 | ret = -EINVAL; |
| 1445 | } else { |
| 1446 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 1447 | for (i = 0; i < num_ctl_values; i++) { |
| 1448 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 1449 | ALOGV("Error: invalid session_id: %x", session_id); |
| 1450 | ret = -EINVAL; |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | if (my_data->csd != NULL) { |
| 1457 | ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode); |
| 1458 | if (ret < 0) { |
| 1459 | ALOGE("%s: csd_client_start_record failed, error %d", |
| 1460 | __func__, ret); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | return ret; |
| 1465 | } |
| 1466 | |
| 1467 | int platform_stop_incall_recording_usecase(void *platform) |
| 1468 | { |
| 1469 | int ret = 0; |
| 1470 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1471 | |
| 1472 | if (my_data->csd != NULL) { |
| 1473 | ret = my_data->csd->stop_record(ALL_SESSION_VSID); |
| 1474 | if (ret < 0) { |
| 1475 | ALOGE("%s: csd_client_stop_record failed, error %d", |
| 1476 | __func__, ret); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | return ret; |
| 1481 | } |
| 1482 | |
| 1483 | int platform_start_incall_music_usecase(void *platform) |
| 1484 | { |
| 1485 | int ret = 0; |
| 1486 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1487 | |
| 1488 | if (my_data->csd != NULL) { |
| 1489 | ret = my_data->csd->start_playback(ALL_SESSION_VSID); |
| 1490 | if (ret < 0) { |
| 1491 | ALOGE("%s: csd_client_start_playback failed, error %d", |
| 1492 | __func__, ret); |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | return ret; |
| 1497 | } |
| 1498 | |
| 1499 | int platform_stop_incall_music_usecase(void *platform) |
| 1500 | { |
| 1501 | int ret = 0; |
| 1502 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1503 | |
| 1504 | if (my_data->csd != NULL) { |
| 1505 | ret = my_data->csd->stop_playback(ALL_SESSION_VSID); |
| 1506 | if (ret < 0) { |
| 1507 | ALOGE("%s: csd_client_stop_playback failed, error %d", |
| 1508 | __func__, ret); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | return ret; |
| 1513 | } |
| 1514 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 1515 | /* Delay in Us */ |
| 1516 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 1517 | { |
| 1518 | switch (usecase) { |
| 1519 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 1520 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 1521 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 1522 | return LOW_LATENCY_PLATFORM_DELAY; |
| 1523 | default: |
| 1524 | return 0; |
| 1525 | } |
| 1526 | } |
Haynes Mathew George | 98c9562 | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1527 | |
| 1528 | int platform_set_snd_device_backend(snd_device_t device, const char *backend) |
| 1529 | { |
| 1530 | int ret = 0; |
| 1531 | |
| 1532 | if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { |
| 1533 | ALOGE("%s: Invalid snd_device = %d", |
| 1534 | __func__, device); |
| 1535 | ret = -EINVAL; |
| 1536 | goto done; |
| 1537 | } |
| 1538 | |
| 1539 | if (backend_table[device]) { |
| 1540 | free(backend_table[device]); |
| 1541 | } |
| 1542 | backend_table[device] = strdup(backend); |
| 1543 | done: |
| 1544 | return ret; |
| 1545 | } |
| 1546 | |
| 1547 | int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id) |
| 1548 | { |
| 1549 | int ret = 0; |
| 1550 | if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) { |
| 1551 | ALOGE("%s: invalid usecase case idx %d", __func__, usecase); |
| 1552 | ret = -EINVAL; |
| 1553 | goto done; |
| 1554 | } |
| 1555 | |
| 1556 | if ((type != 0) && (type != 1)) { |
| 1557 | ALOGE("%s: invalid usecase type", __func__); |
| 1558 | ret = -EINVAL; |
| 1559 | } |
| 1560 | pcm_device_table[usecase][type] = pcm_id; |
| 1561 | done: |
| 1562 | return ret; |
| 1563 | } |