Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1 | /* |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
| 3 | * Not a Contribution. |
| 4 | * |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 20 | #define LOG_TAG "msm8916_platform" |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 21 | /*#define LOG_NDEBUG 0*/ |
| 22 | #define LOG_NDDEBUG 0 |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <dlfcn.h> |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/properties.h> |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 28 | #include <cutils/str_parms.h> |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 29 | #include <audio_hw.h> |
| 30 | #include <platform_api.h> |
| 31 | #include "platform.h" |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 32 | #include "audio_extn.h" |
| 33 | #include "voice_extn.h" |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 34 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 35 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
| 36 | #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml" |
| 37 | #define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml" |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 38 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 39 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 40 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 41 | #define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024) |
| 42 | #define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024) |
| 43 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024) |
| 44 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024) |
| 45 | /* Used in calculating fragment size for pcm offload */ |
| 46 | #define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */ |
| 47 | #define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */ |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 48 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 49 | /* MAX PCM fragment size cannot be increased further due |
| 50 | * to flinger's cblk size of 1mb,and it has to be a multiple of |
| 51 | * 24 - lcm of channels supported by DSP |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 52 | */ |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 53 | #define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024) |
| 54 | #define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 55 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 56 | #define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1))) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 57 | /* |
| 58 | * This file will have a maximum of 38 bytes: |
| 59 | * |
| 60 | * 4 bytes: number of audio blocks |
| 61 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 62 | * Maximum 10 * 3 bytes: SAD blocks |
| 63 | */ |
| 64 | #define MAX_SAD_BLOCKS 10 |
| 65 | #define SAD_BLOCK_SIZE 3 |
| 66 | |
| 67 | /* EDID format ID for LPCM audio */ |
| 68 | #define EDID_FORMAT_LPCM 1 |
| 69 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 70 | /* Retry for delay in FW loading*/ |
| 71 | #define RETRY_NUMBER 20 |
| 72 | #define RETRY_US 500000 |
| 73 | #define MAX_SND_CARD 8 |
| 74 | |
| 75 | #define SAMPLE_RATE_8KHZ 8000 |
| 76 | #define SAMPLE_RATE_16KHZ 16000 |
| 77 | |
| 78 | #define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence" |
| 79 | #define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate" |
| 80 | #define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable" |
| 81 | #define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost" |
| 82 | |
| 83 | enum { |
| 84 | VOICE_FEATURE_SET_DEFAULT, |
| 85 | VOICE_FEATURE_SET_VOLUME_BOOST |
| 86 | }; |
| 87 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 88 | struct audio_block_header |
| 89 | { |
| 90 | int reserved; |
| 91 | int length; |
| 92 | }; |
| 93 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 94 | /* Audio calibration related functions */ |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 95 | typedef void (*acdb_deallocate_t)(); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 96 | typedef int (*acdb_init_t)(char *); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 97 | typedef void (*acdb_send_audio_cal_t)(int, int); |
| 98 | typedef void (*acdb_send_voice_cal_t)(int, int); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 99 | typedef int (*acdb_reload_vocvoltable_t)(int); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 100 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 101 | struct platform_data { |
| 102 | struct audio_device *adev; |
| 103 | bool fluence_in_spkr_mode; |
| 104 | bool fluence_in_voice_call; |
| 105 | bool fluence_in_voice_rec; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 106 | bool fluence_in_audio_rec; |
| 107 | int fluence_type; |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 108 | char fluence_cap[PROPERTY_VALUE_MAX]; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 109 | int btsco_sample_rate; |
| 110 | bool slowtalk; |
| 111 | /* Audio calibration related functions */ |
| 112 | void *acdb_handle; |
| 113 | int voice_feature_set; |
| 114 | acdb_init_t acdb_init; |
| 115 | acdb_deallocate_t acdb_deallocate; |
| 116 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 117 | acdb_send_voice_cal_t acdb_send_voice_cal; |
| 118 | acdb_reload_vocvoltable_t acdb_reload_vocvoltable; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 119 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 120 | void *hw_info; |
| 121 | struct csd_data *csd; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | static const int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 125 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 126 | DEEP_BUFFER_PCM_DEVICE}, |
| 127 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 128 | LOWLATENCY_PCM_DEVICE}, |
| 129 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE, |
| 130 | MULTIMEDIA2_PCM_DEVICE}, |
| 131 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = |
| 132 | {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE}, |
| 133 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE}, |
| 134 | [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE}, |
| 135 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 136 | LOWLATENCY_PCM_DEVICE}, |
| 137 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE, |
| 138 | MULTIMEDIA2_PCM_DEVICE}, |
| 139 | [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE}, |
| 140 | [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX}, |
| 141 | [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX}, |
| 142 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE}, |
| 143 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 144 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 145 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
Karthik Reddy Katta | 3b0a60c | 2014-04-06 14:52:37 +0530 | [diff] [blame] | 146 | [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE}, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 147 | [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE}, |
| 148 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 149 | AUDIO_RECORD_PCM_DEVICE}, |
| 150 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 151 | AUDIO_RECORD_PCM_DEVICE}, |
| 152 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 153 | AUDIO_RECORD_PCM_DEVICE}, |
| 154 | [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 155 | COMPRESS_CAPTURE_DEVICE}, |
| 156 | [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 157 | COMPRESS_CAPTURE_DEVICE}, |
| 158 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 159 | COMPRESS_CAPTURE_DEVICE}, |
| 160 | [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE, |
| 161 | INCALL_MUSIC_UPLINK_PCM_DEVICE}, |
| 162 | [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE, |
| 163 | INCALL_MUSIC_UPLINK2_PCM_DEVICE}, |
| 164 | [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1}, |
| 165 | [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE}, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | /* Array to store sound devices */ |
| 169 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 170 | [SND_DEVICE_NONE] = "none", |
| 171 | /* Playback sound devices */ |
| 172 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 173 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 174 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
| 175 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 176 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
| 177 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
| 178 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 179 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
| 180 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 181 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 182 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 183 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 184 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 185 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 186 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 187 | [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy", |
| 188 | [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones", |
| 189 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones", |
| 190 | [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm", |
| 191 | [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones", |
| 192 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones", |
| 193 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones", |
| 194 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones", |
| 195 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones", |
| 196 | [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset", |
| 197 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 198 | |
| 199 | /* Capture sound devices */ |
| 200 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 201 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 202 | [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic", |
| 203 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic", |
| 204 | [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire", |
| 205 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire", |
| 206 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire", |
| 207 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire", |
| 208 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 209 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic", |
| 210 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic", |
| 211 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic", |
| 212 | [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire", |
| 213 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire", |
| 214 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire", |
| 215 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire", |
| 216 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 217 | [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 218 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 219 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 220 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 221 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 222 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 223 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 224 | [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef", |
| 225 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef", |
| 226 | [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 227 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 228 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 229 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
| 230 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 231 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic", |
| 232 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef", |
| 233 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence", |
| 234 | [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic", |
| 235 | [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm", |
| 236 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic", |
| 237 | [SND_DEVICE_IN_QUAD_MIC] = "quad-mic", |
| 238 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef", |
| 239 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef", |
| 240 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 244 | static int acdb_device_table[SND_DEVICE_MAX] = { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 245 | [SND_DEVICE_NONE] = -1, |
| 246 | [SND_DEVICE_OUT_HANDSET] = 7, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 247 | [SND_DEVICE_OUT_SPEAKER] = 14, |
| 248 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 249 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 250 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
| 251 | [SND_DEVICE_OUT_VOICE_HANDSET] = 7, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 252 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 14, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 253 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
| 254 | [SND_DEVICE_OUT_HDMI] = 18, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 255 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 256 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 257 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 258 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 259 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 260 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 261 | [SND_DEVICE_OUT_AFE_PROXY] = 0, |
| 262 | [SND_DEVICE_OUT_USB_HEADSET] = 45, |
| 263 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14, |
| 264 | [SND_DEVICE_OUT_TRANSMISSION_FM] = 0, |
| 265 | [SND_DEVICE_OUT_ANC_HEADSET] = 26, |
| 266 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27, |
| 267 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26, |
| 268 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27, |
| 269 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26, |
| 270 | [SND_DEVICE_OUT_ANC_HANDSET] = 103, |
| 271 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 272 | |
| 273 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 274 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106, |
| 275 | [SND_DEVICE_IN_HANDSET_MIC_NS] = 107, |
| 276 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108, |
| 277 | [SND_DEVICE_IN_HANDSET_DMIC] = 41, |
| 278 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109, |
| 279 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110, |
| 280 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111, |
| 281 | [SND_DEVICE_IN_SPEAKER_MIC] = 11, |
| 282 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112, |
| 283 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113, |
| 284 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114, |
| 285 | [SND_DEVICE_IN_SPEAKER_DMIC] = 43, |
| 286 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115, |
| 287 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116, |
| 288 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 289 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 290 | [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 291 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 292 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 293 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 294 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 295 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
| 296 | [SND_DEVICE_IN_CAMCORDER_MIC] = 4, |
| 297 | [SND_DEVICE_IN_VOICE_DMIC] = 41, |
| 298 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43, |
| 299 | [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 300 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 301 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 302 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 303 | [SND_DEVICE_IN_VOICE_REC_MIC] = 4, |
| 304 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107, |
| 305 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34, |
| 306 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41, |
| 307 | [SND_DEVICE_IN_USB_HEADSET_MIC] = 44, |
| 308 | [SND_DEVICE_IN_CAPTURE_FM] = 0, |
| 309 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104, |
| 310 | [SND_DEVICE_IN_QUAD_MIC] = 46, |
| 311 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34, |
| 312 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35, |
| 313 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102, |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 314 | }; |
| 315 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 316 | struct snd_device_index { |
| 317 | char name[100]; |
| 318 | unsigned int index; |
| 319 | }; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 320 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 321 | #define TO_NAME_INDEX(X) #X, X |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 322 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 323 | /* Used to get index from parsed sting */ |
| 324 | struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = { |
| 325 | {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)}, |
| 326 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)}, |
| 327 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)}, |
| 328 | {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)}, |
| 329 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)}, |
| 330 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)}, |
| 331 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)}, |
| 332 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)}, |
| 333 | {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)}, |
| 334 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)}, |
| 335 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)}, |
| 336 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)}, |
| 337 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)}, |
| 338 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)}, |
| 339 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)}, |
| 340 | {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)}, |
| 341 | {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)}, |
| 342 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)}, |
| 343 | {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)}, |
| 344 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)}, |
| 345 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)}, |
| 346 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)}, |
| 347 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)}, |
| 348 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)}, |
| 349 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)}, |
| 350 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)}, |
| 351 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, |
| 352 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)}, |
| 353 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)}, |
| 354 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)}, |
| 355 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)}, |
| 356 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)}, |
| 357 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)}, |
| 358 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)}, |
| 359 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)}, |
| 360 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)}, |
| 361 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)}, |
| 362 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)}, |
| 363 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)}, |
| 364 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)}, |
| 365 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)}, |
| 366 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)}, |
| 367 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)}, |
| 368 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)}, |
| 369 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)}, |
| 370 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)}, |
| 371 | {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)}, |
| 372 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)}, |
| 373 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)}, |
| 374 | {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)}, |
| 375 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)}, |
| 376 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)}, |
| 377 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)}, |
| 378 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)}, |
| 379 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)}, |
| 380 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)}, |
| 381 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)}, |
| 382 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)}, |
| 383 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)}, |
| 384 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)}, |
| 385 | {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)}, |
| 386 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)}, |
| 387 | {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)}, |
| 388 | {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)}, |
| 389 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)}, |
| 390 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)}, |
| 391 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)}, |
| 392 | }; |
| 393 | |
| 394 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 395 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 396 | |
| 397 | static int set_echo_reference(struct mixer *mixer, const char* ec_ref) |
| 398 | { |
| 399 | struct mixer_ctl *ctl; |
| 400 | const char *mixer_ctl_name = "EC_REF_RX"; |
| 401 | |
| 402 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 403 | if (!ctl) { |
| 404 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 405 | __func__, mixer_ctl_name); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | ALOGV("Setting EC Reference: %s", ec_ref); |
| 409 | mixer_ctl_set_enum_by_string(ctl, ec_ref); |
| 410 | return 0; |
| 411 | } |
| 412 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 413 | static struct csd_data *open_csd_client() |
| 414 | { |
| 415 | struct csd_data *csd = calloc(1, sizeof(struct csd_data)); |
| 416 | |
| 417 | csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 418 | if (csd->csd_client == NULL) { |
| 419 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 420 | goto error; |
| 421 | } else { |
| 422 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 423 | |
| 424 | csd->deinit = (deinit_t)dlsym(csd->csd_client, |
| 425 | "csd_client_deinit"); |
| 426 | if (csd->deinit == NULL) { |
| 427 | ALOGE("%s: dlsym error %s for csd_client_deinit", __func__, |
| 428 | dlerror()); |
| 429 | goto error; |
| 430 | } |
| 431 | csd->disable_device = (disable_device_t)dlsym(csd->csd_client, |
| 432 | "csd_client_disable_device"); |
| 433 | if (csd->disable_device == NULL) { |
| 434 | ALOGE("%s: dlsym error %s for csd_client_disable_device", |
| 435 | __func__, dlerror()); |
| 436 | goto error; |
| 437 | } |
| 438 | csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client, |
| 439 | "csd_client_enable_device_config"); |
| 440 | if (csd->enable_device_config == NULL) { |
| 441 | ALOGE("%s: dlsym error %s for csd_client_enable_device_config", |
| 442 | __func__, dlerror()); |
| 443 | goto error; |
| 444 | } |
| 445 | csd->enable_device = (enable_device_t)dlsym(csd->csd_client, |
| 446 | "csd_client_enable_device"); |
| 447 | if (csd->enable_device == NULL) { |
| 448 | ALOGE("%s: dlsym error %s for csd_client_enable_device", |
| 449 | __func__, dlerror()); |
| 450 | goto error; |
| 451 | } |
| 452 | csd->start_voice = (start_voice_t)dlsym(csd->csd_client, |
| 453 | "csd_client_start_voice"); |
| 454 | if (csd->start_voice == NULL) { |
| 455 | ALOGE("%s: dlsym error %s for csd_client_start_voice", |
| 456 | __func__, dlerror()); |
| 457 | goto error; |
| 458 | } |
| 459 | csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client, |
| 460 | "csd_client_stop_voice"); |
| 461 | if (csd->stop_voice == NULL) { |
| 462 | ALOGE("%s: dlsym error %s for csd_client_stop_voice", |
| 463 | __func__, dlerror()); |
| 464 | goto error; |
| 465 | } |
| 466 | csd->volume = (volume_t)dlsym(csd->csd_client, |
| 467 | "csd_client_volume"); |
| 468 | if (csd->volume == NULL) { |
| 469 | ALOGE("%s: dlsym error %s for csd_client_volume", |
| 470 | __func__, dlerror()); |
| 471 | goto error; |
| 472 | } |
| 473 | csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client, |
| 474 | "csd_client_mic_mute"); |
| 475 | if (csd->mic_mute == NULL) { |
| 476 | ALOGE("%s: dlsym error %s for csd_client_mic_mute", |
| 477 | __func__, dlerror()); |
| 478 | goto error; |
| 479 | } |
| 480 | csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client, |
| 481 | "csd_client_slow_talk"); |
| 482 | if (csd->slow_talk == NULL) { |
| 483 | ALOGE("%s: dlsym error %s for csd_client_slow_talk", |
| 484 | __func__, dlerror()); |
| 485 | goto error; |
| 486 | } |
| 487 | csd->start_playback = (start_playback_t)dlsym(csd->csd_client, |
| 488 | "csd_client_start_playback"); |
| 489 | if (csd->start_playback == NULL) { |
| 490 | ALOGE("%s: dlsym error %s for csd_client_start_playback", |
| 491 | __func__, dlerror()); |
| 492 | goto error; |
| 493 | } |
| 494 | csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client, |
| 495 | "csd_client_stop_playback"); |
| 496 | if (csd->stop_playback == NULL) { |
| 497 | ALOGE("%s: dlsym error %s for csd_client_stop_playback", |
| 498 | __func__, dlerror()); |
| 499 | goto error; |
| 500 | } |
| 501 | csd->start_record = (start_record_t)dlsym(csd->csd_client, |
| 502 | "csd_client_start_record"); |
| 503 | if (csd->start_record == NULL) { |
| 504 | ALOGE("%s: dlsym error %s for csd_client_start_record", |
| 505 | __func__, dlerror()); |
| 506 | goto error; |
| 507 | } |
| 508 | csd->stop_record = (stop_record_t)dlsym(csd->csd_client, |
| 509 | "csd_client_stop_record"); |
| 510 | if (csd->stop_record == NULL) { |
| 511 | ALOGE("%s: dlsym error %s for csd_client_stop_record", |
| 512 | __func__, dlerror()); |
| 513 | goto error; |
| 514 | } |
| 515 | csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init"); |
| 516 | |
| 517 | if (csd->init == NULL) { |
| 518 | ALOGE("%s: dlsym error %s for csd_client_init", |
| 519 | __func__, dlerror()); |
| 520 | goto error; |
| 521 | } else { |
| 522 | csd->init(); |
| 523 | } |
| 524 | } |
| 525 | return csd; |
| 526 | |
| 527 | error: |
| 528 | free(csd); |
| 529 | csd = NULL; |
| 530 | return csd; |
| 531 | } |
| 532 | |
| 533 | void close_csd_client(struct csd_data *csd) |
| 534 | { |
| 535 | if (csd != NULL) { |
| 536 | csd->deinit(); |
| 537 | dlclose(csd->csd_client); |
| 538 | free(csd); |
| 539 | csd = NULL; |
| 540 | } |
| 541 | } |
| 542 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 543 | void *platform_init(struct audio_device *adev) |
| 544 | { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 545 | char platform[PROPERTY_VALUE_MAX]; |
| 546 | char baseband[PROPERTY_VALUE_MAX]; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 547 | char value[PROPERTY_VALUE_MAX]; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 548 | struct platform_data *my_data = NULL; |
| 549 | int retry_num = 0, snd_card_num = 0; |
| 550 | const char *snd_card_name; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 551 | |
| 552 | my_data = calloc(1, sizeof(struct platform_data)); |
| 553 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 554 | while (snd_card_num < MAX_SND_CARD) { |
| 555 | adev->mixer = mixer_open(snd_card_num); |
| 556 | |
| 557 | while (!adev->mixer && retry_num < RETRY_NUMBER) { |
| 558 | usleep(RETRY_US); |
| 559 | adev->mixer = mixer_open(snd_card_num); |
| 560 | retry_num++; |
| 561 | } |
| 562 | |
| 563 | if (!adev->mixer) { |
| 564 | ALOGE("%s: Unable to open the mixer card: %d", __func__, |
| 565 | snd_card_num); |
| 566 | retry_num = 0; |
| 567 | snd_card_num++; |
| 568 | continue; |
| 569 | } |
| 570 | |
| 571 | snd_card_name = mixer_get_name(adev->mixer); |
| 572 | ALOGV("%s: snd_card_name: %s", __func__, snd_card_name); |
| 573 | |
| 574 | my_data->hw_info = hw_info_init(snd_card_name); |
| 575 | if (!my_data->hw_info) { |
| 576 | ALOGE("%s: Failed to init hardware info", __func__); |
| 577 | } else { |
| 578 | if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH, |
| 579 | MIXER_XML_PATH_AUXPCM) == -ENOSYS) |
| 580 | adev->audio_route = audio_route_init(snd_card_num, |
| 581 | MIXER_XML_PATH); |
| 582 | if (!adev->audio_route) { |
| 583 | ALOGE("%s: Failed to init audio route controls, aborting.", |
| 584 | __func__); |
| 585 | free(my_data); |
| 586 | return NULL; |
| 587 | } |
| 588 | adev->snd_card = snd_card_num; |
| 589 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 590 | break; |
| 591 | } |
| 592 | retry_num = 0; |
| 593 | snd_card_num++; |
| 594 | } |
| 595 | |
| 596 | if (snd_card_num >= MAX_SND_CARD) { |
| 597 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
| 598 | free(my_data); |
| 599 | return NULL; |
| 600 | } |
| 601 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 602 | my_data->adev = adev; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 603 | my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 604 | my_data->fluence_in_spkr_mode = false; |
| 605 | my_data->fluence_in_voice_call = false; |
| 606 | my_data->fluence_in_voice_rec = false; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 607 | my_data->fluence_in_audio_rec = false; |
| 608 | my_data->fluence_type = FLUENCE_NONE; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 609 | |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 610 | property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, ""); |
| 611 | if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 612 | my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC; |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 613 | } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 614 | my_data->fluence_type = FLUENCE_DUAL_MIC; |
| 615 | } else { |
| 616 | my_data->fluence_type = FLUENCE_NONE; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 617 | } |
| 618 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 619 | if (my_data->fluence_type != FLUENCE_NONE) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 620 | property_get("persist.audio.fluence.voicecall",value,""); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 621 | if (!strncmp("true", value, sizeof("true"))) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 622 | my_data->fluence_in_voice_call = true; |
| 623 | } |
| 624 | |
| 625 | property_get("persist.audio.fluence.voicerec",value,""); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 626 | if (!strncmp("true", value, sizeof("true"))) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 627 | my_data->fluence_in_voice_rec = true; |
| 628 | } |
| 629 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 630 | property_get("persist.audio.fluence.audiorec",value,""); |
| 631 | if (!strncmp("true", value, sizeof("true"))) { |
| 632 | my_data->fluence_in_audio_rec = true; |
| 633 | } |
| 634 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 635 | property_get("persist.audio.fluence.speaker",value,""); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 636 | if (!strncmp("true", value, sizeof("true"))) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 637 | my_data->fluence_in_spkr_mode = true; |
| 638 | } |
| 639 | } |
| 640 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 641 | my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 642 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 643 | if (my_data->acdb_handle == NULL) { |
| 644 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 645 | } else { |
| 646 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 647 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 648 | "acdb_loader_deallocate_ACDB"); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 649 | if (!my_data->acdb_deallocate) |
| 650 | ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s", |
| 651 | __func__, LIB_ACDB_LOADER); |
| 652 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 653 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 654 | "acdb_loader_send_audio_cal"); |
| 655 | if (!my_data->acdb_send_audio_cal) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 656 | ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 657 | __func__, LIB_ACDB_LOADER); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 658 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 659 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 660 | "acdb_loader_send_voice_cal"); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 661 | if (!my_data->acdb_send_voice_cal) |
| 662 | ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s", |
| 663 | __func__, LIB_ACDB_LOADER); |
| 664 | |
| 665 | my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle, |
| 666 | "acdb_loader_reload_vocvoltable"); |
| 667 | if (!my_data->acdb_reload_vocvoltable) |
| 668 | ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s", |
| 669 | __func__, LIB_ACDB_LOADER); |
| 670 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 671 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 672 | "acdb_loader_init_v2"); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 673 | if (my_data->acdb_init == NULL) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 674 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 675 | else |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 676 | my_data->acdb_init(snd_card_name); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 677 | } |
| 678 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 679 | /* Initialize ACDB ID's */ |
| 680 | platform_info_init(PLATFORM_INFO_XML_PATH); |
| 681 | |
| 682 | /* init usb */ |
| 683 | audio_extn_usb_init(adev); |
| 684 | /* update sound cards appropriately */ |
| 685 | audio_extn_usb_set_proxy_sound_card(adev->snd_card); |
| 686 | |
| 687 | /* Read one time ssr property */ |
| 688 | audio_extn_ssr_update_enabled(); |
| 689 | audio_extn_spkr_prot_init(adev); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 690 | return my_data; |
| 691 | } |
| 692 | |
| 693 | void platform_deinit(void *platform) |
| 694 | { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 695 | struct platform_data *my_data = (struct platform_data *)platform; |
| 696 | |
| 697 | hw_info_deinit(my_data->hw_info); |
| 698 | close_csd_client(my_data->csd); |
| 699 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 700 | free(platform); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 701 | /* deinit usb */ |
| 702 | audio_extn_usb_deinit(); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 706 | { |
| 707 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) |
| 708 | return device_table[snd_device]; |
| 709 | else |
| 710 | return ""; |
| 711 | } |
| 712 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 713 | int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device, |
| 714 | char *device_name) |
| 715 | { |
| 716 | struct platform_data *my_data = (struct platform_data *)platform; |
| 717 | |
| 718 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 719 | strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE); |
| 720 | hw_info_append_hw_type(my_data->hw_info, snd_device, device_name); |
| 721 | } else { |
| 722 | strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE); |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 729 | void platform_add_backend_name(char *mixer_path, snd_device_t snd_device) |
| 730 | { |
| 731 | if (snd_device == SND_DEVICE_IN_BT_SCO_MIC) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 732 | strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH); |
| 733 | else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB) |
| 734 | strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 735 | else if(snd_device == SND_DEVICE_OUT_BT_SCO) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 736 | strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH); |
| 737 | else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB) |
| 738 | strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 739 | else if (snd_device == SND_DEVICE_OUT_HDMI) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 740 | strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 741 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI) |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 742 | strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH); |
| 743 | else if (snd_device == SND_DEVICE_OUT_AFE_PROXY) |
| 744 | strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH); |
| 745 | else if (snd_device == SND_DEVICE_OUT_USB_HEADSET) |
| 746 | strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH); |
| 747 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET) |
| 748 | strlcat(mixer_path, " speaker-and-usb-headphones", |
| 749 | MIXER_PATH_MAX_LENGTH); |
| 750 | else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC) |
| 751 | strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH); |
| 752 | else if (snd_device == SND_DEVICE_IN_CAPTURE_FM) |
| 753 | strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH); |
| 754 | else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM) |
| 755 | strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 759 | { |
| 760 | int device_id; |
| 761 | if (device_type == PCM_PLAYBACK) |
| 762 | device_id = pcm_device_table[usecase][0]; |
| 763 | else |
| 764 | device_id = pcm_device_table[usecase][1]; |
| 765 | return device_id; |
| 766 | } |
| 767 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 768 | int platform_get_snd_device_index(char *snd_device_index_name) |
| 769 | { |
| 770 | int ret = 0; |
| 771 | int i; |
| 772 | |
| 773 | if (snd_device_index_name == NULL) { |
| 774 | ALOGE("%s: snd_device_index_name is NULL", __func__); |
| 775 | ret = -ENODEV; |
| 776 | goto done; |
| 777 | } |
| 778 | |
| 779 | for (i=0; i < SND_DEVICE_MAX; i++) { |
| 780 | if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) { |
| 781 | ret = snd_device_name_index[i].index; |
| 782 | goto done; |
| 783 | } |
| 784 | } |
| 785 | ALOGE("%s: Could not find index for snd_device_index_name = %s", |
| 786 | __func__, snd_device_index_name); |
| 787 | ret = -ENODEV; |
| 788 | done: |
| 789 | return ret; |
| 790 | } |
| 791 | |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 792 | int platform_set_fluence_type(void *platform, char *value) |
| 793 | { |
| 794 | int ret = 0; |
| 795 | int fluence_type = FLUENCE_NONE; |
| 796 | int fluence_flag = NONE_FLAG; |
| 797 | struct platform_data *my_data = (struct platform_data *)platform; |
| 798 | struct audio_device *adev = my_data->adev; |
| 799 | |
| 800 | ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type); |
| 801 | |
| 802 | /* only dual mic turn on and off is supported as of now through setparameters */ |
| 803 | if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) { |
| 804 | if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) || |
| 805 | !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) { |
| 806 | ALOGV("fluence dualmic feature enabled \n"); |
| 807 | fluence_type = FLUENCE_DUAL_MIC; |
| 808 | fluence_flag = DMIC_FLAG; |
| 809 | } else { |
| 810 | ALOGE("%s: Failed to set DUALMIC", __func__); |
| 811 | ret = -1; |
| 812 | goto done; |
| 813 | } |
| 814 | } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) { |
| 815 | ALOGV("fluence disabled"); |
| 816 | fluence_type = FLUENCE_NONE; |
| 817 | } else { |
| 818 | ALOGE("Invalid fluence value : %s",value); |
| 819 | ret = -1; |
| 820 | goto done; |
| 821 | } |
| 822 | |
| 823 | if (fluence_type != my_data->fluence_type) { |
| 824 | ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type); |
| 825 | my_data->fluence_type = fluence_type; |
| 826 | adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag; |
| 827 | } |
| 828 | done: |
| 829 | return ret; |
| 830 | } |
| 831 | |
| 832 | int platform_get_fluence_type(void *platform, char *value, uint32_t len) |
| 833 | { |
| 834 | int ret = 0; |
| 835 | struct platform_data *my_data = (struct platform_data *)platform; |
| 836 | |
| 837 | if (my_data->fluence_type == FLUENCE_QUAD_MIC) { |
| 838 | strlcpy(value, "quadmic", len); |
| 839 | } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) { |
| 840 | strlcpy(value, "dualmic", len); |
| 841 | } else if (my_data->fluence_type == FLUENCE_NONE) { |
| 842 | strlcpy(value, "none", len); |
| 843 | } else |
| 844 | ret = -1; |
| 845 | |
| 846 | return ret; |
| 847 | } |
| 848 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 849 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id) |
| 850 | { |
| 851 | int ret = 0; |
| 852 | |
| 853 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 854 | ALOGE("%s: Invalid snd_device = %d", |
| 855 | __func__, snd_device); |
| 856 | ret = -EINVAL; |
| 857 | goto done; |
| 858 | } |
| 859 | |
| 860 | acdb_device_table[snd_device] = acdb_id; |
| 861 | done: |
| 862 | return ret; |
| 863 | } |
| 864 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 865 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 866 | { |
| 867 | struct platform_data *my_data = (struct platform_data *)platform; |
| 868 | int acdb_dev_id, acdb_dev_type; |
| 869 | |
| 870 | acdb_dev_id = acdb_device_table[snd_device]; |
| 871 | if (acdb_dev_id < 0) { |
| 872 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 873 | __func__, snd_device); |
| 874 | return -EINVAL; |
| 875 | } |
| 876 | if (my_data->acdb_send_audio_cal) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 877 | ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 878 | __func__, snd_device, acdb_dev_id); |
| 879 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 880 | snd_device < SND_DEVICE_OUT_END) |
| 881 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 882 | else |
| 883 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 884 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 885 | } |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | int platform_switch_voice_call_device_pre(void *platform) |
| 890 | { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 891 | struct platform_data *my_data = (struct platform_data *)platform; |
| 892 | int ret = 0; |
| 893 | |
| 894 | if (my_data->csd != NULL && |
| 895 | my_data->adev->mode == AUDIO_MODE_IN_CALL) { |
| 896 | /* This must be called before disabling mixer controls on APQ side */ |
| 897 | ret = my_data->csd->disable_device(); |
| 898 | if (ret < 0) { |
| 899 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 900 | __func__, ret); |
| 901 | } |
| 902 | } |
| 903 | return ret; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 904 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 905 | int platform_switch_voice_call_enable_device_config(void *platform, |
| 906 | snd_device_t out_snd_device, |
| 907 | snd_device_t in_snd_device) |
| 908 | { |
| 909 | struct platform_data *my_data = (struct platform_data *)platform; |
| 910 | int acdb_rx_id, acdb_tx_id; |
| 911 | int ret = 0; |
| 912 | |
| 913 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 914 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 915 | |
| 916 | if (my_data->csd != NULL) { |
| 917 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 918 | ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id); |
| 919 | if (ret < 0) { |
| 920 | ALOGE("%s: csd_enable_device_config, failed, error %d", |
| 921 | __func__, ret); |
| 922 | } |
| 923 | } else { |
| 924 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 925 | acdb_rx_id, acdb_tx_id); |
| 926 | } |
| 927 | } |
| 928 | return ret; |
| 929 | } |
| 930 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 931 | |
| 932 | int platform_switch_voice_call_device_post(void *platform, |
| 933 | snd_device_t out_snd_device, |
| 934 | snd_device_t in_snd_device) |
| 935 | { |
| 936 | struct platform_data *my_data = (struct platform_data *)platform; |
| 937 | int acdb_rx_id, acdb_tx_id; |
| 938 | |
| 939 | if (my_data->acdb_send_voice_cal == NULL) { |
| 940 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 941 | } else { |
| 942 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 943 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 944 | |
| 945 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 946 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 947 | else |
| 948 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 949 | acdb_rx_id, acdb_tx_id); |
| 950 | } |
| 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 955 | int platform_switch_voice_call_usecase_route_post(void *platform, |
| 956 | snd_device_t out_snd_device, |
| 957 | snd_device_t in_snd_device) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 958 | { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 959 | struct platform_data *my_data = (struct platform_data *)platform; |
| 960 | int acdb_rx_id, acdb_tx_id; |
| 961 | int ret = 0; |
| 962 | |
| 963 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 964 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 965 | |
| 966 | if (my_data->csd != NULL) { |
| 967 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 968 | ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id, |
| 969 | my_data->adev->acdb_settings); |
| 970 | if (ret < 0) { |
| 971 | ALOGE("%s: csd_enable_device, failed, error %d", |
| 972 | __func__, ret); |
| 973 | } |
| 974 | } else { |
| 975 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 976 | acdb_rx_id, acdb_tx_id); |
| 977 | } |
| 978 | } |
| 979 | return ret; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 980 | } |
| 981 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 982 | int platform_start_voice_call(void *platform, uint32_t vsid) |
| 983 | { |
| 984 | struct platform_data *my_data = (struct platform_data *)platform; |
| 985 | int ret = 0; |
| 986 | |
| 987 | if (my_data->csd != NULL) { |
| 988 | ret = my_data->csd->start_voice(vsid); |
| 989 | if (ret < 0) { |
| 990 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 991 | } |
| 992 | } |
| 993 | return ret; |
| 994 | } |
| 995 | |
| 996 | int platform_stop_voice_call(void *platform, uint32_t vsid) |
| 997 | { |
| 998 | struct platform_data *my_data = (struct platform_data *)platform; |
| 999 | int ret = 0; |
| 1000 | |
| 1001 | if (my_data->csd != NULL) { |
| 1002 | ret = my_data->csd->stop_voice(vsid); |
| 1003 | if (ret < 0) { |
| 1004 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 1005 | } |
| 1006 | } |
| 1007 | return ret; |
| 1008 | } |
| 1009 | int platform_get_sample_rate(void *platform, uint32_t *rate) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1010 | { |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | int platform_set_voice_volume(void *platform, int volume) |
| 1015 | { |
| 1016 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1017 | struct audio_device *adev = my_data->adev; |
| 1018 | struct mixer_ctl *ctl; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1019 | const char *mixer_ctl_name = "Voice Rx Gain"; |
| 1020 | int vol_index = 0, ret = 0; |
| 1021 | uint32_t set_values[ ] = {0, |
| 1022 | ALL_SESSION_VSID, |
| 1023 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1024 | |
| 1025 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 1026 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 1027 | // But this values don't changed in kernel. So, below change is need. |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1028 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX); |
| 1029 | set_values[0] = vol_index; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1030 | |
| 1031 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1032 | if (!ctl) { |
| 1033 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1034 | __func__, mixer_ctl_name); |
| 1035 | return -EINVAL; |
| 1036 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1037 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 1038 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1039 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1040 | if (my_data->csd != NULL) { |
| 1041 | ret = my_data->csd->volume(ALL_SESSION_VSID, volume); |
| 1042 | if (ret < 0) { |
| 1043 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 1044 | } |
| 1045 | } |
| 1046 | return ret; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | int platform_set_mic_mute(void *platform, bool state) |
| 1050 | { |
| 1051 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1052 | struct audio_device *adev = my_data->adev; |
| 1053 | struct mixer_ctl *ctl; |
| 1054 | const char *mixer_ctl_name = "Voice Tx Mute"; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1055 | int ret = 0; |
| 1056 | uint32_t set_values[ ] = {0, |
| 1057 | ALL_SESSION_VSID, |
| 1058 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1059 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1060 | set_values[0] = state; |
| 1061 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1062 | if (!ctl) { |
| 1063 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1064 | __func__, mixer_ctl_name); |
| 1065 | return -EINVAL; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1066 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1067 | ALOGV("Setting voice mute state: %d", state); |
| 1068 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1069 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1070 | if (my_data->csd != NULL) { |
| 1071 | ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state); |
| 1072 | if (ret < 0) { |
| 1073 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
| 1074 | } |
| 1075 | } |
| 1076 | return ret; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1077 | } |
| 1078 | |
Shiv Maliyappanahalli | c6fd8ee | 2014-03-07 15:31:55 -0800 | [diff] [blame] | 1079 | int platform_set_device_mute(void *platform, bool state, char *dir) |
| 1080 | { |
| 1081 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1082 | struct audio_device *adev = my_data->adev; |
| 1083 | struct mixer_ctl *ctl; |
| 1084 | char *mixer_ctl_name = NULL; |
| 1085 | int ret = 0; |
| 1086 | uint32_t set_values[ ] = {0, |
| 1087 | ALL_SESSION_VSID, |
| 1088 | 0}; |
| 1089 | if(dir == NULL) { |
| 1090 | ALOGE("%s: Invalid direction:%s", __func__, dir); |
| 1091 | return -EINVAL; |
| 1092 | } |
| 1093 | |
| 1094 | if (!strncmp("rx", dir, sizeof("rx"))) { |
| 1095 | mixer_ctl_name = "Voice Rx Device Mute"; |
| 1096 | } else if (!strncmp("tx", dir, sizeof("tx"))) { |
| 1097 | mixer_ctl_name = "Voice Tx Device Mute"; |
| 1098 | } else { |
| 1099 | return -EINVAL; |
| 1100 | } |
| 1101 | |
| 1102 | set_values[0] = state; |
| 1103 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1104 | if (!ctl) { |
| 1105 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1106 | __func__, mixer_ctl_name); |
| 1107 | return -EINVAL; |
| 1108 | } |
| 1109 | |
| 1110 | ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s", |
| 1111 | __func__,state, mixer_ctl_name); |
| 1112 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1113 | |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1117 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 1118 | { |
| 1119 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1120 | struct audio_device *adev = my_data->adev; |
| 1121 | audio_mode_t mode = adev->mode; |
| 1122 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 1123 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1124 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1125 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1126 | int channel_count = popcount(channel_mask); |
| 1127 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1128 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 1129 | if (devices == AUDIO_DEVICE_NONE || |
| 1130 | devices & AUDIO_DEVICE_BIT_IN) { |
| 1131 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 1132 | goto exit; |
| 1133 | } |
| 1134 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1135 | if (popcount(devices) == 2) { |
| 1136 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 1137 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1138 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 1139 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 1140 | AUDIO_DEVICE_OUT_SPEAKER)) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1141 | if (audio_extn_get_anc_enabled()) |
| 1142 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET; |
| 1143 | else |
| 1144 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1145 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 1146 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1147 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1148 | } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
| 1149 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1150 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1151 | } else { |
| 1152 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 1153 | goto exit; |
| 1154 | } |
| 1155 | if (snd_device != SND_DEVICE_NONE) { |
| 1156 | goto exit; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | if (popcount(devices) != 1) { |
| 1161 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 1162 | goto exit; |
| 1163 | } |
| 1164 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1165 | if ((mode == AUDIO_MODE_IN_CALL) || |
| 1166 | voice_extn_compress_voip_is_active(adev)) { |
| 1167 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1168 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1169 | if ((adev->voice.tty_mode != TTY_MODE_OFF) && |
| 1170 | !voice_extn_compress_voip_is_active(adev)) { |
| 1171 | switch (adev->voice.tty_mode) { |
| 1172 | case TTY_MODE_FULL: |
| 1173 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
| 1174 | break; |
| 1175 | case TTY_MODE_VCO: |
| 1176 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
| 1177 | break; |
| 1178 | case TTY_MODE_HCO: |
| 1179 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 1180 | break; |
| 1181 | default: |
| 1182 | ALOGE("%s: Invalid TTY mode (%#x)", |
| 1183 | __func__, adev->voice.tty_mode); |
| 1184 | } |
| 1185 | } else if (audio_extn_get_anc_enabled()) { |
| 1186 | if (audio_extn_should_use_fb_anc()) |
| 1187 | snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET; |
| 1188 | else |
| 1189 | snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET; |
| 1190 | } else { |
| 1191 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
| 1192 | } |
| 1193 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 1194 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 1195 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1196 | else |
| 1197 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 1198 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1199 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 1200 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1201 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 1202 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
| 1203 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 1204 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
| 1205 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1206 | if (audio_extn_should_use_handset_anc(channel_count)) |
| 1207 | snd_device = SND_DEVICE_OUT_ANC_HANDSET; |
| 1208 | else |
| 1209 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
| 1210 | } |
| 1211 | if (snd_device != SND_DEVICE_NONE) { |
| 1212 | goto exit; |
| 1213 | } |
| 1214 | } |
| 1215 | |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1216 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1217 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1218 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET |
| 1219 | && audio_extn_get_anc_enabled()) { |
| 1220 | if (audio_extn_should_use_fb_anc()) |
| 1221 | snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET; |
| 1222 | else |
| 1223 | snd_device = SND_DEVICE_OUT_ANC_HEADSET; |
| 1224 | } |
| 1225 | else |
| 1226 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1227 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1228 | if (adev->speaker_lr_swap) |
| 1229 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 1230 | else |
| 1231 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 1232 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1233 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 1234 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1235 | else |
| 1236 | snd_device = SND_DEVICE_OUT_BT_SCO; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1237 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1238 | snd_device = SND_DEVICE_OUT_HDMI ; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1239 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1240 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1241 | ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__); |
| 1242 | audio_extn_set_afe_proxy_channel_mixer(adev, 2); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1243 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
| 1244 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 1245 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1246 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1247 | snd_device = SND_DEVICE_OUT_HANDSET; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1248 | } else if (devices & AUDIO_DEVICE_OUT_PROXY) { |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1249 | channel_count = audio_extn_get_afe_proxy_channel_count(); |
| 1250 | ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count); |
| 1251 | audio_extn_set_afe_proxy_channel_mixer(adev, channel_count); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1252 | snd_device = SND_DEVICE_OUT_AFE_PROXY; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1253 | } else { |
| 1254 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 1255 | } |
| 1256 | exit: |
| 1257 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 1258 | return snd_device; |
| 1259 | } |
| 1260 | |
| 1261 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 1262 | { |
| 1263 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1264 | struct audio_device *adev = my_data->adev; |
| 1265 | audio_source_t source = (adev->active_input == NULL) ? |
| 1266 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 1267 | |
| 1268 | audio_mode_t mode = adev->mode; |
| 1269 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 1270 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 1271 | & ~AUDIO_DEVICE_BIT_IN; |
| 1272 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1273 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1274 | snd_device_t snd_device = SND_DEVICE_NONE; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1275 | int channel_count = popcount(channel_mask); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1276 | |
| 1277 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
| 1278 | __func__, out_device, in_device); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1279 | if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) || |
| 1280 | voice_extn_compress_voip_is_active(adev))) { |
| 1281 | if ((adev->voice.tty_mode != TTY_MODE_OFF) && |
| 1282 | !voice_extn_compress_voip_is_active(adev)) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1283 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1284 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1285 | switch (adev->voice.tty_mode) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1286 | case TTY_MODE_FULL: |
| 1287 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 1288 | break; |
| 1289 | case TTY_MODE_VCO: |
| 1290 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 1291 | break; |
| 1292 | case TTY_MODE_HCO: |
| 1293 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 1294 | break; |
| 1295 | default: |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1296 | ALOGE("%s: Invalid TTY mode (%#x)", |
| 1297 | __func__, adev->voice.tty_mode); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1298 | } |
| 1299 | goto exit; |
| 1300 | } |
| 1301 | } |
| 1302 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 1303 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1304 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE && |
| 1305 | audio_extn_should_use_handset_anc(channel_count)) { |
| 1306 | snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC; |
| 1307 | } else if (my_data->fluence_type == FLUENCE_NONE || |
| 1308 | my_data->fluence_in_voice_call == false) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1309 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1310 | set_echo_reference(adev->mixer, EC_REF_RX); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1311 | } else { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1312 | snd_device = SND_DEVICE_IN_VOICE_DMIC; |
| 1313 | adev->acdb_settings |= DMIC_FLAG; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1314 | } |
| 1315 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1316 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
Satya Krishna Pindiproli | 624c780 | 2014-04-11 11:33:27 +0530 | [diff] [blame] | 1317 | set_echo_reference(adev->mixer, EC_REF_RX); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1318 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1319 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 1320 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1321 | else |
| 1322 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1323 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1324 | if (my_data->fluence_type != FLUENCE_NONE && |
| 1325 | my_data->fluence_in_voice_call && |
| 1326 | my_data->fluence_in_spkr_mode) { |
| 1327 | if(my_data->fluence_type & FLUENCE_QUAD_MIC) { |
| 1328 | adev->acdb_settings |= QMIC_FLAG; |
| 1329 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC; |
| 1330 | } else { |
| 1331 | adev->acdb_settings |= DMIC_FLAG; |
| 1332 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC; |
| 1333 | } |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1334 | } else { |
| 1335 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
Satya Krishna Pindiproli | 624c780 | 2014-04-11 11:33:27 +0530 | [diff] [blame] | 1336 | set_echo_reference(adev->mixer, EC_REF_RX); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 1340 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 1341 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1342 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 1343 | } |
| 1344 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1345 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1346 | if (channel_count == 2) { |
| 1347 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO; |
| 1348 | adev->acdb_settings |= DMIC_FLAG; |
| 1349 | } else if (adev->active_input->enable_ns) |
| 1350 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS; |
| 1351 | else if (my_data->fluence_type != FLUENCE_NONE && |
| 1352 | my_data->fluence_in_voice_rec) { |
| 1353 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE; |
| 1354 | adev->acdb_settings |= DMIC_FLAG; |
| 1355 | } else { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1356 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 1357 | } |
| 1358 | } |
| 1359 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 1360 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 1361 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 1362 | if (adev->active_input) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1363 | if (adev->active_input->enable_aec && |
| 1364 | adev->active_input->enable_ns) { |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1365 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1366 | if (my_data->fluence_type & FLUENCE_DUAL_MIC && |
| 1367 | my_data->fluence_in_spkr_mode) { |
| 1368 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS; |
| 1369 | adev->acdb_settings |= DMIC_FLAG; |
| 1370 | } else |
| 1371 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1372 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1373 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1374 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS; |
| 1375 | adev->acdb_settings |= DMIC_FLAG; |
| 1376 | } else |
| 1377 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1378 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1379 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1380 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1381 | set_echo_reference(adev->mixer, EC_REF_RX); |
| 1382 | } else if (adev->active_input->enable_aec) { |
| 1383 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1384 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1385 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC; |
| 1386 | adev->acdb_settings |= DMIC_FLAG; |
| 1387 | } else |
| 1388 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
| 1389 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1390 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1391 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC; |
| 1392 | adev->acdb_settings |= DMIC_FLAG; |
| 1393 | } else |
| 1394 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
| 1395 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1396 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
| 1397 | } |
| 1398 | set_echo_reference(adev->mixer, EC_REF_RX); |
| 1399 | } else if (adev->active_input->enable_ns) { |
| 1400 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1401 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1402 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS; |
| 1403 | adev->acdb_settings |= DMIC_FLAG; |
| 1404 | } else |
| 1405 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS; |
| 1406 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1407 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1408 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS; |
| 1409 | adev->acdb_settings |= DMIC_FLAG; |
| 1410 | } else |
| 1411 | snd_device = SND_DEVICE_IN_HANDSET_MIC_NS; |
| 1412 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1413 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
| 1414 | } |
| 1415 | set_echo_reference(adev->mixer, "NONE"); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1416 | } else |
| 1417 | set_echo_reference(adev->mixer, "NONE"); |
| 1418 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1419 | } else if (source == AUDIO_SOURCE_MIC) { |
| 1420 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC && |
| 1421 | channel_count == 1 ) { |
| 1422 | if(my_data->fluence_type & FLUENCE_DUAL_MIC && |
| 1423 | my_data->fluence_in_audio_rec) |
| 1424 | snd_device = SND_DEVICE_IN_HANDSET_DMIC; |
| 1425 | } |
| 1426 | } else if (source == AUDIO_SOURCE_FM_RX || |
| 1427 | source == AUDIO_SOURCE_FM_RX_A2DP) { |
| 1428 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1429 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 1430 | goto exit; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | if (snd_device != SND_DEVICE_NONE) { |
| 1435 | goto exit; |
| 1436 | } |
| 1437 | |
| 1438 | if (in_device != AUDIO_DEVICE_NONE && |
| 1439 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 1440 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 1441 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1442 | if (audio_extn_ssr_get_enabled() && channel_count == 6) |
| 1443 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
| 1444 | else if (channel_count == 2) |
| 1445 | snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC; |
| 1446 | else |
| 1447 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1448 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1449 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 1450 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1451 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 1452 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1453 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 1454 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1455 | else |
| 1456 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1457 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 1458 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1459 | } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET || |
| 1460 | in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) { |
| 1461 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
| 1462 | } else if (in_device & AUDIO_DEVICE_IN_FM_RX) { |
| 1463 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1464 | } else { |
| 1465 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 1466 | ALOGW("%s: Using default handset-mic", __func__); |
| 1467 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1468 | } |
| 1469 | } else { |
| 1470 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1471 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1472 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1473 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 1474 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1475 | if (channel_count > 1) |
| 1476 | snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC; |
| 1477 | else |
| 1478 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1479 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 1480 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1481 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1482 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 1483 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1484 | else |
| 1485 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1486 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1487 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1488 | } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1489 | out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 1490 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1491 | } else { |
| 1492 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 1493 | ALOGW("%s: Using default handset-mic", __func__); |
| 1494 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1495 | } |
| 1496 | } |
| 1497 | exit: |
| 1498 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 1499 | return snd_device; |
| 1500 | } |
| 1501 | |
| 1502 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 1503 | { |
| 1504 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1505 | struct audio_device *adev = my_data->adev; |
| 1506 | struct mixer_ctl *ctl; |
| 1507 | const char *channel_cnt_str = NULL; |
| 1508 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 1509 | switch (channel_count) { |
| 1510 | case 8: |
| 1511 | channel_cnt_str = "Eight"; break; |
| 1512 | case 7: |
| 1513 | channel_cnt_str = "Seven"; break; |
| 1514 | case 6: |
| 1515 | channel_cnt_str = "Six"; break; |
| 1516 | case 5: |
| 1517 | channel_cnt_str = "Five"; break; |
| 1518 | case 4: |
| 1519 | channel_cnt_str = "Four"; break; |
| 1520 | case 3: |
| 1521 | channel_cnt_str = "Three"; break; |
| 1522 | default: |
| 1523 | channel_cnt_str = "Two"; break; |
| 1524 | } |
| 1525 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1526 | if (!ctl) { |
| 1527 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1528 | __func__, mixer_ctl_name); |
| 1529 | return -EINVAL; |
| 1530 | } |
| 1531 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 1532 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1536 | int platform_edid_get_max_channels(void *platform) |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1537 | { |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1538 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1539 | struct audio_device *adev = my_data->adev; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1540 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 1541 | char *sad = block; |
| 1542 | int num_audio_blocks; |
| 1543 | int channel_count; |
| 1544 | int max_channels = 0; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1545 | int i, ret, count; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1546 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1547 | struct mixer_ctl *ctl; |
| 1548 | |
| 1549 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 1550 | if (!ctl) { |
| 1551 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1552 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1553 | return 0; |
| 1554 | } |
| 1555 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1556 | mixer_ctl_update(ctl); |
| 1557 | |
| 1558 | count = mixer_ctl_get_num_values(ctl); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1559 | |
| 1560 | /* Read SAD blocks, clamping the maximum size for safety */ |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1561 | if (count > (int)sizeof(block)) |
| 1562 | count = (int)sizeof(block); |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1563 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1564 | ret = mixer_ctl_get_array(ctl, block, count); |
| 1565 | if (ret != 0) { |
| 1566 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 1567 | return 0; |
| 1568 | } |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1569 | |
| 1570 | /* Calculate the number of SAD blocks */ |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1571 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1572 | |
| 1573 | for (i = 0; i < num_audio_blocks; i++) { |
| 1574 | /* Only consider LPCM blocks */ |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1575 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 1576 | sad += 3; |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1577 | continue; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1578 | } |
Naresh Tanniru | e3b1845 | 2014-03-04 14:44:27 +0530 | [diff] [blame] | 1579 | |
| 1580 | channel_count = (sad[0] & 0x7) + 1; |
| 1581 | if (channel_count > max_channels) |
| 1582 | max_channels = channel_count; |
| 1583 | |
| 1584 | /* Advance to next block */ |
| 1585 | sad += 3; |
| 1586 | } |
| 1587 | |
| 1588 | return max_channels; |
| 1589 | } |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1590 | |
| 1591 | static int platform_set_slowtalk(struct platform_data *my_data, bool state) |
| 1592 | { |
| 1593 | int ret = 0; |
| 1594 | struct audio_device *adev = my_data->adev; |
| 1595 | struct mixer_ctl *ctl; |
| 1596 | const char *mixer_ctl_name = "Slowtalk Enable"; |
| 1597 | uint32_t set_values[ ] = {0, |
| 1598 | ALL_SESSION_VSID}; |
| 1599 | |
| 1600 | set_values[0] = state; |
| 1601 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1602 | if (!ctl) { |
| 1603 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1604 | __func__, mixer_ctl_name); |
| 1605 | ret = -EINVAL; |
| 1606 | } else { |
| 1607 | ALOGV("Setting slowtalk state: %d", state); |
| 1608 | ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1609 | my_data->slowtalk = state; |
| 1610 | } |
| 1611 | |
| 1612 | if (my_data->csd != NULL) { |
| 1613 | ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state); |
| 1614 | if (ret < 0) { |
| 1615 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 1616 | __func__, ret); |
| 1617 | } |
| 1618 | } |
| 1619 | return ret; |
| 1620 | } |
| 1621 | |
| 1622 | int platform_set_parameters(void *platform, struct str_parms *parms) |
| 1623 | { |
| 1624 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1625 | char *str; |
| 1626 | char value[256] = {0}; |
| 1627 | int val; |
| 1628 | int ret = 0, err; |
| 1629 | |
| 1630 | ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms)); |
| 1631 | |
| 1632 | err = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val); |
| 1633 | if (err >= 0) { |
| 1634 | str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO); |
| 1635 | my_data->btsco_sample_rate = val; |
| 1636 | if (val == SAMPLE_RATE_16KHZ) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame^] | 1637 | audio_route_apply_and_update_path(my_data->adev->audio_route, |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1638 | "bt-sco-wb-samplerate"); |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value)); |
| 1643 | if (err >= 0) { |
| 1644 | bool state = false; |
| 1645 | if (!strncmp("true", value, sizeof("true"))) { |
| 1646 | state = true; |
| 1647 | } |
| 1648 | |
| 1649 | str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK); |
| 1650 | ret = platform_set_slowtalk(my_data, state); |
| 1651 | if (ret) |
| 1652 | ALOGE("%s: Failed to set slow talk err: %d", __func__, ret); |
| 1653 | } |
| 1654 | |
| 1655 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST, |
| 1656 | value, sizeof(value)); |
| 1657 | if (err >= 0) { |
| 1658 | str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST); |
| 1659 | |
| 1660 | if (my_data->acdb_reload_vocvoltable == NULL) { |
| 1661 | ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__); |
| 1662 | } else if (!strcmp(value, "on")) { |
| 1663 | if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) { |
| 1664 | my_data->voice_feature_set = 1; |
| 1665 | } |
| 1666 | } else { |
| 1667 | if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) { |
| 1668 | my_data->voice_feature_set = 0; |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | ALOGV("%s: exit with code(%d)", __func__, ret); |
| 1674 | return ret; |
| 1675 | } |
| 1676 | |
| 1677 | int platform_set_incall_recording_session_id(void *platform, |
| 1678 | uint32_t session_id, int rec_mode) |
| 1679 | { |
| 1680 | int ret = 0; |
| 1681 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1682 | struct audio_device *adev = my_data->adev; |
| 1683 | struct mixer_ctl *ctl; |
| 1684 | const char *mixer_ctl_name = "Voc VSID"; |
| 1685 | int num_ctl_values; |
| 1686 | int i; |
| 1687 | |
| 1688 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1689 | if (!ctl) { |
| 1690 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1691 | __func__, mixer_ctl_name); |
| 1692 | ret = -EINVAL; |
| 1693 | } else { |
| 1694 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 1695 | for (i = 0; i < num_ctl_values; i++) { |
| 1696 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 1697 | ALOGV("Error: invalid session_id: %x", session_id); |
| 1698 | ret = -EINVAL; |
| 1699 | break; |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | if (my_data->csd != NULL) { |
| 1705 | ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode); |
| 1706 | if (ret < 0) { |
| 1707 | ALOGE("%s: csd_client_start_record failed, error %d", |
| 1708 | __func__, ret); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | return ret; |
| 1713 | } |
| 1714 | |
| 1715 | int platform_stop_incall_recording_usecase(void *platform) |
| 1716 | { |
| 1717 | int ret = 0; |
| 1718 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1719 | |
| 1720 | if (my_data->csd != NULL) { |
| 1721 | ret = my_data->csd->stop_record(ALL_SESSION_VSID); |
| 1722 | if (ret < 0) { |
| 1723 | ALOGE("%s: csd_client_stop_record failed, error %d", |
| 1724 | __func__, ret); |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | return ret; |
| 1729 | } |
| 1730 | |
| 1731 | int platform_start_incall_music_usecase(void *platform) |
| 1732 | { |
| 1733 | int ret = 0; |
| 1734 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1735 | |
| 1736 | if (my_data->csd != NULL) { |
| 1737 | ret = my_data->csd->start_playback(ALL_SESSION_VSID); |
| 1738 | if (ret < 0) { |
| 1739 | ALOGE("%s: csd_client_start_playback failed, error %d", |
| 1740 | __func__, ret); |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
| 1747 | int platform_stop_incall_music_usecase(void *platform) |
| 1748 | { |
| 1749 | int ret = 0; |
| 1750 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1751 | |
| 1752 | if (my_data->csd != NULL) { |
| 1753 | ret = my_data->csd->stop_playback(ALL_SESSION_VSID); |
| 1754 | if (ret < 0) { |
| 1755 | ALOGE("%s: csd_client_stop_playback failed, error %d", |
| 1756 | __func__, ret); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | return ret; |
| 1761 | } |
| 1762 | |
| 1763 | void platform_get_parameters(void *platform, |
| 1764 | struct str_parms *query, |
| 1765 | struct str_parms *reply) |
| 1766 | { |
| 1767 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1768 | char *str = NULL; |
| 1769 | char value[256] = {0}; |
| 1770 | int ret; |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1771 | |
Naresh Tanniru | db72d1e | 2014-03-05 17:33:47 +0530 | [diff] [blame] | 1772 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK, |
| 1773 | value, sizeof(value)); |
| 1774 | if (ret >= 0) { |
| 1775 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK, |
| 1776 | my_data->slowtalk?"true":"false"); |
| 1777 | } |
| 1778 | |
| 1779 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST, |
| 1780 | value, sizeof(value)); |
| 1781 | if (ret >= 0) { |
| 1782 | if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) { |
| 1783 | strlcpy(value, "on", sizeof(value)); |
| 1784 | } else { |
| 1785 | strlcpy(value, "off", sizeof(value)); |
| 1786 | } |
| 1787 | |
| 1788 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value); |
| 1789 | } |
| 1790 | |
| 1791 | ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply)); |
| 1792 | } |
| 1793 | |
| 1794 | /* Delay in Us */ |
| 1795 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 1796 | { |
| 1797 | switch (usecase) { |
| 1798 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 1799 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 1800 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 1801 | return LOW_LATENCY_PLATFORM_DELAY; |
| 1802 | default: |
| 1803 | return 0; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | int platform_update_usecase_from_source(int source, int usecase) |
| 1808 | { |
| 1809 | ALOGV("%s: input source :%d", __func__, source); |
| 1810 | if(source == AUDIO_SOURCE_FM_RX_A2DP) |
| 1811 | usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL; |
| 1812 | return usecase; |
| 1813 | } |
| 1814 | |
| 1815 | bool platform_listen_update_status(snd_device_t snd_device) |
| 1816 | { |
| 1817 | if ((snd_device >= SND_DEVICE_IN_BEGIN) && |
| 1818 | (snd_device < SND_DEVICE_IN_END) && |
| 1819 | (snd_device != SND_DEVICE_IN_CAPTURE_FM) && |
| 1820 | (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)) |
| 1821 | return true; |
| 1822 | else |
| 1823 | return false; |
| 1824 | } |
| 1825 | |
| 1826 | /* Read offload buffer size from a property. |
| 1827 | * If value is not power of 2 round it to |
| 1828 | * power of 2. |
| 1829 | */ |
| 1830 | uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info) |
| 1831 | { |
| 1832 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 1833 | uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 1834 | if((property_get("audio.offload.buffer.size.kb", value, "")) && |
| 1835 | atoi(value)) { |
| 1836 | fragment_size = atoi(value) * 1024; |
| 1837 | } |
| 1838 | |
| 1839 | if (info != NULL && info->has_video && info->is_streaming) { |
| 1840 | fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING; |
| 1841 | ALOGV("%s: offload fragment size reduced for AV streaming to %d", |
| 1842 | __func__, out->compr_config.fragment_size); |
| 1843 | } |
| 1844 | |
| 1845 | fragment_size = ALIGN( fragment_size, 1024); |
| 1846 | |
| 1847 | if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE) |
| 1848 | fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 1849 | else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE) |
| 1850 | fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 1851 | ALOGV("%s: fragment_size %d", __func__, fragment_size); |
| 1852 | return fragment_size; |
| 1853 | } |
| 1854 | |
| 1855 | uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info) |
| 1856 | { |
| 1857 | uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1858 | uint32_t bits_per_sample = 16; |
| 1859 | |
| 1860 | if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) { |
| 1861 | bits_per_sample = 32; |
| 1862 | } |
| 1863 | |
| 1864 | if (!info->has_video) { |
| 1865 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1866 | |
| 1867 | } else if (info->has_video && info->is_streaming) { |
| 1868 | fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING |
| 1869 | * info->sample_rate |
| 1870 | * bits_per_sample |
| 1871 | * popcount(info->channel_mask))/1000; |
| 1872 | |
| 1873 | } else if (info->has_video) { |
| 1874 | fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV |
| 1875 | * info->sample_rate |
| 1876 | * bits_per_sample |
| 1877 | * popcount(info->channel_mask))/1000; |
| 1878 | } |
| 1879 | |
| 1880 | fragment_size = ALIGN( fragment_size, 1024); |
| 1881 | |
| 1882 | if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1883 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1884 | else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1885 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1886 | |
| 1887 | ALOGV("%s: fragment_size %d", __func__, fragment_size); |
| 1888 | return fragment_size; |
| 1889 | } |
| 1890 | |