Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1 | /* |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 3 | * Not a Contribution. |
| 4 | * |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [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 | |
| 20 | #define LOG_TAG "msm8974_platform" |
| 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> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 28 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 29 | #include <audio_hw.h> |
| 30 | #include <platform_api.h> |
| 31 | #include "platform.h" |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 32 | #include "audio_extn.h" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 33 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 34 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 35 | #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 36 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 37 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 38 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 39 | /* |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 40 | * This file will have a maximum of 38 bytes: |
| 41 | * |
| 42 | * 4 bytes: number of audio blocks |
| 43 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 44 | * Maximum 10 * 3 bytes: SAD blocks |
| 45 | */ |
| 46 | #define MAX_SAD_BLOCKS 10 |
| 47 | #define SAD_BLOCK_SIZE 3 |
| 48 | |
| 49 | /* EDID format ID for LPCM audio */ |
| 50 | #define EDID_FORMAT_LPCM 1 |
| 51 | |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 52 | /* Retry for delay in FW loading*/ |
| 53 | #define RETRY_NUMBER 10 |
| 54 | #define RETRY_US 500000 |
| 55 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 56 | #define SAMPLE_RATE_8KHZ 8000 |
| 57 | #define SAMPLE_RATE_16KHZ 16000 |
| 58 | |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 59 | #define MAX_VOL_INDEX 5 |
| 60 | #define MIN_VOL_INDEX 0 |
| 61 | #define percent_to_index(val, min, max) \ |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 62 | ((val) * ((max) - (min)) * 0.01 + (min) + .5) |
| 63 | |
| 64 | #define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence" |
| 65 | #define AUDIO_PARAMETER_KEY_BTSCO "bt_samplerate" |
| 66 | #define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable" |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 67 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 68 | struct audio_block_header |
| 69 | { |
| 70 | int reserved; |
| 71 | int length; |
| 72 | }; |
| 73 | |
| 74 | typedef void (*acdb_deallocate_t)(); |
| 75 | typedef int (*acdb_init_t)(); |
| 76 | typedef void (*acdb_send_audio_cal_t)(int, int); |
| 77 | typedef void (*acdb_send_voice_cal_t)(int, int); |
| 78 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 79 | struct platform_data { |
| 80 | struct audio_device *adev; |
| 81 | bool fluence_in_spkr_mode; |
| 82 | bool fluence_in_voice_call; |
| 83 | bool fluence_in_voice_rec; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 84 | int fluence_type; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 85 | int btsco_sample_rate; |
| 86 | bool slowtalk; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 87 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 88 | /* Audio calibration related functions */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 89 | void *acdb_handle; |
| 90 | acdb_init_t acdb_init; |
| 91 | acdb_deallocate_t acdb_deallocate; |
| 92 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 93 | acdb_send_voice_cal_t acdb_send_voice_cal; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 94 | |
| 95 | void *hw_info; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static const int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 99 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 100 | DEEP_BUFFER_PCM_DEVICE}, |
| 101 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 102 | LOWLATENCY_PCM_DEVICE}, |
| 103 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE, |
| 104 | MULTIMEDIA2_PCM_DEVICE}, |
Krishnankutty Kolathappilly | a43f96e | 2013-11-01 12:17:53 -0700 | [diff] [blame] | 105 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = |
| 106 | {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE}, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 107 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE}, |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 108 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 109 | LOWLATENCY_PCM_DEVICE}, |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 110 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE, |
| 111 | MULTIMEDIA2_PCM_DEVICE}, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 112 | [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE}, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 113 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE}, |
| 114 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 115 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 116 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 117 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 118 | AUDIO_RECORD_PCM_DEVICE}, |
| 119 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 120 | AUDIO_RECORD_PCM_DEVICE}, |
| 121 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 122 | AUDIO_RECORD_PCM_DEVICE}, |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 123 | [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE, |
| 124 | INCALL_MUSIC_UPLINK_PCM_DEVICE}, |
| 125 | [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE, |
| 126 | INCALL_MUSIC_UPLINK2_PCM_DEVICE}, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /* Array to store sound devices */ |
| 130 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 131 | [SND_DEVICE_NONE] = "none", |
| 132 | /* Playback sound devices */ |
| 133 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 134 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 135 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
| 136 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 137 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
| 138 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
| 139 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 140 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
| 141 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 142 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 143 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 144 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 145 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
| 146 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 147 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 148 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 149 | [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy", |
| 150 | [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones", |
| 151 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 152 | [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm", |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 153 | [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones", |
| 154 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones", |
| 155 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones", |
| 156 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones", |
| 157 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones", |
| 158 | [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 159 | |
| 160 | /* Capture sound devices */ |
| 161 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
| 162 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 163 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 164 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
| 165 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic", |
| 166 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic", |
| 167 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 168 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 169 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 170 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 171 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 172 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 173 | [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef", |
| 174 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus", |
| 175 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 176 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 177 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 178 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
| 179 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 180 | [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef", |
| 181 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence", |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 182 | [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 183 | [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm", |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 184 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic", |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 185 | [SND_DEVICE_IN_QUAD_MIC] = "quad-mic", |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 186 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef", |
| 187 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
| 191 | static const int acdb_device_table[SND_DEVICE_MAX] = { |
| 192 | [SND_DEVICE_NONE] = -1, |
| 193 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 194 | [SND_DEVICE_OUT_SPEAKER] = 15, |
| 195 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15, |
| 196 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 197 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
| 198 | [SND_DEVICE_OUT_VOICE_HANDSET] = 7, |
| 199 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 15, |
| 200 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
| 201 | [SND_DEVICE_OUT_HDMI] = 18, |
| 202 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15, |
| 203 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 204 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
sangwoo | c69476f | 2013-07-26 16:57:26 -0700 | [diff] [blame] | 205 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 206 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 207 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 208 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 209 | [SND_DEVICE_OUT_AFE_PROXY] = 0, |
| 210 | [SND_DEVICE_OUT_USB_HEADSET] = 0, |
| 211 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 212 | [SND_DEVICE_OUT_TRANSMISSION_FM] = 0, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 213 | [SND_DEVICE_OUT_ANC_HEADSET] = 26, |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 214 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 215 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26, |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 216 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 217 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26, |
| 218 | [SND_DEVICE_OUT_ANC_HANDSET] = 103, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 219 | |
| 220 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
| 221 | [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */ |
| 222 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
| 223 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40, |
| 224 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42, |
| 225 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47, |
| 226 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 227 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 228 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 229 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 230 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 231 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 232 | [SND_DEVICE_IN_VOICE_DMIC] = 41, |
| 233 | [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89, |
| 234 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 235 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 236 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 237 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
| 238 | [SND_DEVICE_IN_VOICE_REC_MIC] = 62, |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 239 | [SND_DEVICE_IN_USB_HEADSET_MIC] = 44, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 240 | [SND_DEVICE_IN_CAPTURE_FM] = 0, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 241 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 242 | [SND_DEVICE_IN_QUAD_MIC] = 46, |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 243 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34, |
| 244 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 245 | /* TODO: Update with proper acdb ids */ |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 246 | [SND_DEVICE_IN_VOICE_REC_DMIC] = 62, |
| 247 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 6, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 250 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 251 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
| 252 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 253 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 254 | static bool is_tmus = false; |
| 255 | |
| 256 | static void check_operator() |
| 257 | { |
| 258 | char value[PROPERTY_VALUE_MAX]; |
| 259 | int mccmnc; |
| 260 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 261 | mccmnc = atoi(value); |
| 262 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
| 263 | switch(mccmnc) { |
| 264 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 265 | case 310490: |
| 266 | case 310260: |
| 267 | case 310026: |
sangwon.jeon | b891db5 | 2013-09-14 17:39:15 +0900 | [diff] [blame] | 268 | /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */ |
| 269 | case 310800: |
| 270 | case 310660: |
| 271 | case 310580: |
| 272 | case 310310: |
| 273 | case 310270: |
| 274 | case 310250: |
| 275 | case 310240: |
| 276 | case 310230: |
| 277 | case 310220: |
| 278 | case 310210: |
| 279 | case 310200: |
| 280 | case 310160: |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 281 | is_tmus = true; |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | bool is_operator_tmus() |
| 287 | { |
| 288 | pthread_once(&check_op_once_ctl, check_operator); |
| 289 | return is_tmus; |
| 290 | } |
| 291 | |
| 292 | static int set_echo_reference(struct mixer *mixer, const char* ec_ref) |
| 293 | { |
| 294 | struct mixer_ctl *ctl; |
| 295 | const char *mixer_ctl_name = "EC_REF_RX"; |
| 296 | |
| 297 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 298 | if (!ctl) { |
| 299 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 300 | __func__, mixer_ctl_name); |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | ALOGV("Setting EC Reference: %s", ec_ref); |
| 304 | mixer_ctl_set_enum_by_string(ctl, ec_ref); |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | void *platform_init(struct audio_device *adev) |
| 309 | { |
| 310 | char value[PROPERTY_VALUE_MAX]; |
| 311 | struct platform_data *my_data; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 312 | int retry_num = 0; |
| 313 | const char *snd_card_name; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 314 | |
| 315 | adev->mixer = mixer_open(MIXER_CARD); |
| 316 | |
| 317 | while (!adev->mixer && retry_num < RETRY_NUMBER) { |
| 318 | usleep(RETRY_US); |
| 319 | adev->mixer = mixer_open(MIXER_CARD); |
| 320 | retry_num++; |
| 321 | } |
| 322 | |
| 323 | if (!adev->mixer) { |
| 324 | ALOGE("Unable to open the mixer, aborting."); |
| 325 | return NULL; |
| 326 | } |
| 327 | |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 328 | if (audio_extn_read_xml(adev, MIXER_CARD, MIXER_XML_PATH, |
| 329 | MIXER_XML_PATH_AUXPCM) == -ENOSYS) |
| 330 | adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH); |
| 331 | |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 332 | if (!adev->audio_route) { |
| 333 | ALOGE("%s: Failed to init audio route controls, aborting.", __func__); |
| 334 | return NULL; |
| 335 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 336 | |
| 337 | my_data = calloc(1, sizeof(struct platform_data)); |
| 338 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 339 | snd_card_name = mixer_get_name(adev->mixer); |
| 340 | my_data->hw_info = hw_info_init(snd_card_name); |
| 341 | if (!my_data->hw_info) { |
| 342 | ALOGE("%s: Failed to init hardware info", __func__); |
| 343 | } |
| 344 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 345 | my_data->adev = adev; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 346 | my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 347 | my_data->fluence_in_spkr_mode = false; |
| 348 | my_data->fluence_in_voice_call = false; |
| 349 | my_data->fluence_in_voice_rec = false; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 350 | my_data->fluence_type = FLUENCE_NONE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 351 | |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 352 | property_get("ro.qc.sdk.audio.fluencetype", value, ""); |
| 353 | if (!strncmp("fluencepro", value, sizeof("fluencepro"))) { |
| 354 | my_data->fluence_type = FLUENCE_QUAD_MIC; |
| 355 | } else if (!strncmp("fluence", value, sizeof("fluence"))) { |
| 356 | my_data->fluence_type = FLUENCE_DUAL_MIC; |
| 357 | } else { |
| 358 | my_data->fluence_type = FLUENCE_NONE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 361 | if (my_data->fluence_type != FLUENCE_NONE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 362 | property_get("persist.audio.fluence.voicecall",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 363 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 364 | my_data->fluence_in_voice_call = true; |
| 365 | } |
| 366 | |
| 367 | property_get("persist.audio.fluence.voicerec",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 368 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 369 | my_data->fluence_in_voice_rec = true; |
| 370 | } |
| 371 | |
| 372 | property_get("persist.audio.fluence.speaker",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 373 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 374 | my_data->fluence_in_spkr_mode = true; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 379 | if (my_data->acdb_handle == NULL) { |
| 380 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 381 | } else { |
| 382 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 383 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 384 | "acdb_loader_deallocate_ACDB"); |
| 385 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 386 | "acdb_loader_send_audio_cal"); |
| 387 | if (!my_data->acdb_send_audio_cal) |
| 388 | ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s", |
| 389 | __func__, LIB_ACDB_LOADER); |
| 390 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 391 | "acdb_loader_send_voice_cal"); |
| 392 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
| 393 | "acdb_loader_init_ACDB"); |
| 394 | if (my_data->acdb_init == NULL) |
| 395 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); |
| 396 | else |
| 397 | my_data->acdb_init(); |
| 398 | } |
| 399 | |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 400 | /* init usb */ |
| 401 | audio_extn_usb_init(adev); |
| 402 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 403 | /* Read one time ssr property */ |
| 404 | audio_extn_ssr_update_enabled(adev); |
| 405 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 406 | return my_data; |
| 407 | } |
| 408 | |
| 409 | void platform_deinit(void *platform) |
| 410 | { |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 411 | struct platform_data *my_data = (struct platform_data *)platform; |
| 412 | |
| 413 | hw_info_deinit(my_data->hw_info); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 414 | free(platform); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 415 | /* deinit usb */ |
| 416 | audio_extn_usb_deinit(); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 420 | { |
| 421 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) |
| 422 | return device_table[snd_device]; |
| 423 | else |
| 424 | return ""; |
| 425 | } |
| 426 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 427 | int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device, |
| 428 | char *device_name) |
| 429 | { |
| 430 | struct platform_data *my_data = (struct platform_data *)platform; |
| 431 | |
| 432 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 433 | strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE); |
| 434 | hw_info_append_hw_type(my_data->hw_info, snd_device, device_name); |
| 435 | } else { |
| 436 | strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 443 | void platform_add_backend_name(char *mixer_path, snd_device_t snd_device) |
| 444 | { |
| 445 | if (snd_device == SND_DEVICE_IN_BT_SCO_MIC) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 446 | strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH); |
| 447 | else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB) |
| 448 | strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 449 | else if(snd_device == SND_DEVICE_OUT_BT_SCO) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 450 | strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH); |
| 451 | else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB) |
| 452 | strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 453 | else if (snd_device == SND_DEVICE_OUT_HDMI) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 454 | strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 455 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI) |
| 456 | strcat(mixer_path, " speaker-and-hdmi"); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 457 | else if (snd_device == SND_DEVICE_OUT_AFE_PROXY) |
| 458 | strlcat(mixer_path, " afe-proxy", MIXER_PATH_MAX_LENGTH); |
| 459 | else if (snd_device == SND_DEVICE_OUT_USB_HEADSET) |
| 460 | strlcat(mixer_path, " usb-headphones", MIXER_PATH_MAX_LENGTH); |
| 461 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET) |
| 462 | strlcat(mixer_path, " speaker-and-usb-headphones", |
| 463 | MIXER_PATH_MAX_LENGTH); |
| 464 | else if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC) |
| 465 | strlcat(mixer_path, " usb-headset-mic", MIXER_PATH_MAX_LENGTH); |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 466 | else if (snd_device == SND_DEVICE_IN_CAPTURE_FM) |
| 467 | strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH); |
| 468 | else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM) |
| 469 | strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 473 | { |
| 474 | int device_id; |
| 475 | if (device_type == PCM_PLAYBACK) |
| 476 | device_id = pcm_device_table[usecase][0]; |
| 477 | else |
| 478 | device_id = pcm_device_table[usecase][1]; |
| 479 | return device_id; |
| 480 | } |
| 481 | |
| 482 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 483 | { |
| 484 | struct platform_data *my_data = (struct platform_data *)platform; |
| 485 | int acdb_dev_id, acdb_dev_type; |
| 486 | |
| 487 | acdb_dev_id = acdb_device_table[snd_device]; |
| 488 | if (acdb_dev_id < 0) { |
| 489 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 490 | __func__, snd_device); |
| 491 | return -EINVAL; |
| 492 | } |
| 493 | if (my_data->acdb_send_audio_cal) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 494 | ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 495 | __func__, snd_device, acdb_dev_id); |
| 496 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 497 | snd_device < SND_DEVICE_OUT_END) |
| 498 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 499 | else |
| 500 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 501 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | int platform_switch_voice_call_device_pre(void *platform) |
| 507 | { |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | int platform_switch_voice_call_device_post(void *platform, |
| 512 | snd_device_t out_snd_device, |
| 513 | snd_device_t in_snd_device) |
| 514 | { |
| 515 | struct platform_data *my_data = (struct platform_data *)platform; |
| 516 | int acdb_rx_id, acdb_tx_id; |
| 517 | |
| 518 | if (my_data->acdb_send_voice_cal == NULL) { |
| 519 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 520 | } else { |
| 521 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 522 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 523 | |
| 524 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 525 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 526 | else |
| 527 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 528 | acdb_rx_id, acdb_tx_id); |
| 529 | } |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | int platform_start_voice_call(void *platform) |
| 535 | { |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | int platform_stop_voice_call(void *platform) |
| 540 | { |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | int platform_set_voice_volume(void *platform, int volume) |
| 545 | { |
| 546 | struct platform_data *my_data = (struct platform_data *)platform; |
| 547 | struct audio_device *adev = my_data->adev; |
| 548 | struct mixer_ctl *ctl; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 549 | const char *mixer_ctl_name = "Voice Rx Gain"; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 550 | int vol_index = 0; |
| 551 | uint32_t set_values[ ] = {0, |
| 552 | ALL_SESSION_VSID, |
| 553 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 554 | |
| 555 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 556 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 557 | // But this values don't changed in kernel. So, below change is need. |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 558 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX); |
| 559 | set_values[0] = vol_index; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 560 | |
| 561 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 562 | if (!ctl) { |
| 563 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 564 | __func__, mixer_ctl_name); |
| 565 | return -EINVAL; |
| 566 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 567 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 568 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | int platform_set_mic_mute(void *platform, bool state) |
| 574 | { |
| 575 | struct platform_data *my_data = (struct platform_data *)platform; |
| 576 | struct audio_device *adev = my_data->adev; |
| 577 | struct mixer_ctl *ctl; |
| 578 | const char *mixer_ctl_name = "Voice Tx Mute"; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 579 | uint32_t set_values[ ] = {0, |
| 580 | ALL_SESSION_VSID, |
| 581 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 582 | |
| 583 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 584 | set_values[0] = state; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 585 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 586 | if (!ctl) { |
| 587 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 588 | __func__, mixer_ctl_name); |
| 589 | return -EINVAL; |
| 590 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 591 | ALOGV("Setting voice mute state: %d", state); |
| 592 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 599 | { |
| 600 | struct platform_data *my_data = (struct platform_data *)platform; |
| 601 | struct audio_device *adev = my_data->adev; |
| 602 | audio_mode_t mode = adev->mode; |
| 603 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 604 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 605 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 606 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 607 | int channel_count = popcount(channel_mask); |
| 608 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 609 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 610 | if (devices == AUDIO_DEVICE_NONE || |
| 611 | devices & AUDIO_DEVICE_BIT_IN) { |
| 612 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 613 | goto exit; |
| 614 | } |
| 615 | |
| 616 | if (mode == AUDIO_MODE_IN_CALL) { |
| 617 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 618 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 619 | if (adev->voice.tty_mode == TTY_MODE_FULL) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 620 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 621 | } else if (adev->voice.tty_mode == TTY_MODE_VCO) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 622 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 623 | } else if (adev->voice.tty_mode == TTY_MODE_HCO) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 624 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 625 | } else if (audio_extn_get_anc_enabled()) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 626 | if (audio_extn_should_use_fb_anc()) |
| 627 | snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET; |
| 628 | else |
| 629 | snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 630 | } else { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 631 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 632 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 633 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 634 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 635 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 636 | else |
| 637 | snd_device = SND_DEVICE_OUT_BT_SCO; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 638 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 639 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 640 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 641 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 642 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 643 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 644 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 645 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 646 | if (is_operator_tmus()) |
| 647 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 648 | else if (audio_extn_should_use_handset_anc(channel_count)) |
| 649 | snd_device = SND_DEVICE_OUT_ANC_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 650 | else |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 651 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 652 | } |
| 653 | if (snd_device != SND_DEVICE_NONE) { |
| 654 | goto exit; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | if (popcount(devices) == 2) { |
| 659 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 660 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 661 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 662 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 663 | AUDIO_DEVICE_OUT_SPEAKER)) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 664 | if (audio_extn_get_anc_enabled()) |
| 665 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET; |
| 666 | else |
| 667 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 668 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 669 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 670 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 671 | } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
| 672 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 673 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 674 | } else { |
| 675 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 676 | goto exit; |
| 677 | } |
| 678 | if (snd_device != SND_DEVICE_NONE) { |
| 679 | goto exit; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | if (popcount(devices) != 1) { |
| 684 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 685 | goto exit; |
| 686 | } |
| 687 | |
| 688 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 689 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 690 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET |
| 691 | && audio_extn_get_anc_enabled()) { |
| 692 | if (audio_extn_should_use_fb_anc()) |
| 693 | snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET; |
| 694 | else |
| 695 | snd_device = SND_DEVICE_OUT_ANC_HEADSET; |
| 696 | } |
| 697 | else |
| 698 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 699 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 700 | if (adev->speaker_lr_swap) |
| 701 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 702 | else |
| 703 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 704 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 705 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 706 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 707 | else |
| 708 | snd_device = SND_DEVICE_OUT_BT_SCO; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 709 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 710 | snd_device = SND_DEVICE_OUT_HDMI ; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 711 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 712 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 713 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 714 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 715 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 716 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 717 | snd_device = SND_DEVICE_OUT_HANDSET; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 718 | } else if (devices & AUDIO_DEVICE_OUT_PROXY) { |
| 719 | ALOGD("%s: setting sink capability for Proxy", __func__); |
| 720 | audio_extn_set_afe_proxy_channel_mixer(adev); |
| 721 | snd_device = SND_DEVICE_OUT_AFE_PROXY; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 722 | } else { |
| 723 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 724 | } |
| 725 | exit: |
| 726 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 727 | return snd_device; |
| 728 | } |
| 729 | |
| 730 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 731 | { |
| 732 | struct platform_data *my_data = (struct platform_data *)platform; |
| 733 | struct audio_device *adev = my_data->adev; |
| 734 | audio_source_t source = (adev->active_input == NULL) ? |
| 735 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 736 | |
| 737 | audio_mode_t mode = adev->mode; |
| 738 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 739 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 740 | & ~AUDIO_DEVICE_BIT_IN; |
| 741 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 742 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 743 | snd_device_t snd_device = SND_DEVICE_NONE; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 744 | int channel_count = popcount(channel_mask); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 745 | |
| 746 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
| 747 | __func__, out_device, in_device); |
| 748 | if (mode == AUDIO_MODE_IN_CALL) { |
| 749 | if (out_device == AUDIO_DEVICE_NONE) { |
| 750 | ALOGE("%s: No output device set for voice call", __func__); |
| 751 | goto exit; |
| 752 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 753 | if (adev->voice.tty_mode != TTY_MODE_OFF) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 754 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 755 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 756 | switch (adev->voice.tty_mode) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 757 | case TTY_MODE_FULL: |
| 758 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 759 | break; |
| 760 | case TTY_MODE_VCO: |
| 761 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 762 | break; |
| 763 | case TTY_MODE_HCO: |
| 764 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 765 | break; |
| 766 | default: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 767 | ALOGE("%s: Invalid TTY mode (%#x)", |
| 768 | __func__, adev->voice.tty_mode); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 769 | } |
| 770 | goto exit; |
| 771 | } |
| 772 | } |
| 773 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 774 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 775 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE && |
| 776 | audio_extn_should_use_handset_anc(channel_count)) { |
| 777 | snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC; |
| 778 | } else if (my_data->fluence_type == FLUENCE_NONE || |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 779 | my_data->fluence_in_voice_call == false) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 780 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 781 | } else { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 782 | if (is_operator_tmus()) |
| 783 | snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 784 | else |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 785 | snd_device = SND_DEVICE_IN_VOICE_DMIC; |
| 786 | adev->acdb_settings |= DMIC_FLAG; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 787 | } |
| 788 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 789 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 790 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 791 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 792 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 793 | else |
| 794 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 795 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 796 | if (my_data->fluence_type != FLUENCE_NONE && |
| 797 | my_data->fluence_in_voice_call && |
| 798 | my_data->fluence_in_spkr_mode) { |
| 799 | if(my_data->fluence_type == FLUENCE_DUAL_MIC) { |
| 800 | adev->acdb_settings |= DMIC_FLAG; |
| 801 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC; |
| 802 | } else { |
| 803 | adev->acdb_settings |= QMIC_FLAG; |
| 804 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC; |
| 805 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 806 | } else { |
| 807 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 808 | } |
| 809 | } |
| 810 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 811 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 812 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 813 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 814 | } |
| 815 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 816 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 817 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 818 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC; |
| 819 | else if (my_data->fluence_in_voice_rec) |
| 820 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 821 | |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 822 | if (snd_device == SND_DEVICE_NONE) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 823 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 824 | else |
| 825 | adev->acdb_settings |= DMIC_FLAG; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 826 | } |
| 827 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 828 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 829 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 830 | if (adev->active_input) { |
| 831 | if (adev->active_input->enable_aec) { |
| 832 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 833 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
| 834 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 835 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
| 836 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 837 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
| 838 | } |
| 839 | set_echo_reference(adev->mixer, "SLIM_RX"); |
| 840 | } else |
| 841 | set_echo_reference(adev->mixer, "NONE"); |
| 842 | } |
Mingming Yin | ab42978 | 2013-11-07 11:16:55 -0800 | [diff] [blame] | 843 | } else if (source == AUDIO_SOURCE_FM_RX || |
| 844 | source == AUDIO_SOURCE_FM_RX_A2DP) { |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 845 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 846 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 847 | goto exit; |
| 848 | } |
| 849 | |
| 850 | |
| 851 | if (snd_device != SND_DEVICE_NONE) { |
| 852 | goto exit; |
| 853 | } |
| 854 | |
| 855 | if (in_device != AUDIO_DEVICE_NONE && |
| 856 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 857 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 858 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 859 | if (audio_extn_ssr_get_enabled() && channel_count == 6) |
| 860 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame^] | 861 | else if (channel_count == 2) |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 862 | snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 863 | else |
| 864 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 865 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 866 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 867 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 868 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 869 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 870 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 871 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 872 | else |
| 873 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 874 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 875 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 876 | } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET || |
| 877 | in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) { |
| 878 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 879 | } else if (in_device & AUDIO_DEVICE_IN_FM_RX) { |
| 880 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 881 | } else { |
| 882 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 883 | ALOGW("%s: Using default handset-mic", __func__); |
| 884 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 885 | } |
| 886 | } else { |
| 887 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 888 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 889 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 890 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 891 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 892 | if (channel_count > 1) |
| 893 | snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC; |
| 894 | else |
| 895 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 896 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 897 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 898 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 899 | if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ) |
| 900 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 901 | else |
| 902 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 903 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 904 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 905 | } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 906 | out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 907 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 908 | } else { |
| 909 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 910 | ALOGW("%s: Using default handset-mic", __func__); |
| 911 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 912 | } |
| 913 | } |
| 914 | exit: |
| 915 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 916 | return snd_device; |
| 917 | } |
| 918 | |
| 919 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 920 | { |
| 921 | struct platform_data *my_data = (struct platform_data *)platform; |
| 922 | struct audio_device *adev = my_data->adev; |
| 923 | struct mixer_ctl *ctl; |
| 924 | const char *channel_cnt_str = NULL; |
| 925 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 926 | switch (channel_count) { |
| 927 | case 8: |
| 928 | channel_cnt_str = "Eight"; break; |
| 929 | case 7: |
| 930 | channel_cnt_str = "Seven"; break; |
| 931 | case 6: |
| 932 | channel_cnt_str = "Six"; break; |
| 933 | case 5: |
| 934 | channel_cnt_str = "Five"; break; |
| 935 | case 4: |
| 936 | channel_cnt_str = "Four"; break; |
| 937 | case 3: |
| 938 | channel_cnt_str = "Three"; break; |
| 939 | default: |
| 940 | channel_cnt_str = "Two"; break; |
| 941 | } |
| 942 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 943 | if (!ctl) { |
| 944 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 945 | __func__, mixer_ctl_name); |
| 946 | return -EINVAL; |
| 947 | } |
| 948 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 949 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 950 | return 0; |
| 951 | } |
| 952 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 953 | int platform_edid_get_max_channels(void *platform) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 954 | { |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 955 | struct platform_data *my_data = (struct platform_data *)platform; |
| 956 | struct audio_device *adev = my_data->adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 957 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 958 | char *sad = block; |
| 959 | int num_audio_blocks; |
| 960 | int channel_count; |
| 961 | int max_channels = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 962 | int i, ret, count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 963 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 964 | struct mixer_ctl *ctl; |
| 965 | |
| 966 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 967 | if (!ctl) { |
| 968 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 969 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 970 | return 0; |
| 971 | } |
| 972 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 973 | mixer_ctl_update(ctl); |
| 974 | |
| 975 | count = mixer_ctl_get_num_values(ctl); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 976 | |
| 977 | /* Read SAD blocks, clamping the maximum size for safety */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 978 | if (count > (int)sizeof(block)) |
| 979 | count = (int)sizeof(block); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 980 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 981 | ret = mixer_ctl_get_array(ctl, block, count); |
| 982 | if (ret != 0) { |
| 983 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 984 | return 0; |
| 985 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 986 | |
| 987 | /* Calculate the number of SAD blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 988 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 989 | |
| 990 | for (i = 0; i < num_audio_blocks; i++) { |
| 991 | /* Only consider LPCM blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 992 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 993 | sad += 3; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 994 | continue; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 995 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 996 | |
| 997 | channel_count = (sad[0] & 0x7) + 1; |
| 998 | if (channel_count > max_channels) |
| 999 | max_channels = channel_count; |
| 1000 | |
| 1001 | /* Advance to next block */ |
| 1002 | sad += 3; |
| 1003 | } |
| 1004 | |
| 1005 | return max_channels; |
| 1006 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1007 | |
| 1008 | static int platform_set_slowtalk(struct platform_data *my_data, bool state) |
| 1009 | { |
| 1010 | int ret = 0; |
| 1011 | struct audio_device *adev = my_data->adev; |
| 1012 | struct mixer_ctl *ctl; |
| 1013 | const char *mixer_ctl_name = "Slowtalk Enable"; |
| 1014 | uint32_t set_values[ ] = {0, |
| 1015 | ALL_SESSION_VSID}; |
| 1016 | |
| 1017 | set_values[0] = state; |
| 1018 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1019 | if (!ctl) { |
| 1020 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1021 | __func__, mixer_ctl_name); |
| 1022 | ret = -EINVAL; |
| 1023 | } else { |
| 1024 | ALOGV("Setting slowtalk state: %d", state); |
| 1025 | ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1026 | my_data->slowtalk = state; |
| 1027 | } |
| 1028 | |
| 1029 | return ret; |
| 1030 | } |
| 1031 | |
| 1032 | int platform_set_parameters(void *platform, struct str_parms *parms) |
| 1033 | { |
| 1034 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1035 | char *str; |
| 1036 | char value[32]; |
| 1037 | int val; |
| 1038 | int ret = 0; |
| 1039 | |
| 1040 | ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms)); |
| 1041 | |
| 1042 | ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val); |
| 1043 | if (ret >= 0) { |
| 1044 | str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO); |
| 1045 | pthread_mutex_lock(&my_data->adev->lock); |
| 1046 | my_data->btsco_sample_rate = val; |
| 1047 | pthread_mutex_unlock(&my_data->adev->lock); |
| 1048 | } |
| 1049 | |
| 1050 | ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_SLOWTALK, &val); |
| 1051 | if (ret >= 0) { |
| 1052 | str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK); |
| 1053 | pthread_mutex_lock(&my_data->adev->lock); |
| 1054 | ret = platform_set_slowtalk(my_data, val); |
| 1055 | if (ret) |
| 1056 | ALOGE("%s: Failed to set slow talk err: %d", __func__, ret); |
| 1057 | pthread_mutex_unlock(&my_data->adev->lock); |
| 1058 | } |
| 1059 | |
| 1060 | ALOGV("%s: exit with code(%d)", __func__, ret); |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1064 | int platform_set_incall_recoding_session_id(void *platform, |
| 1065 | uint32_t session_id) |
| 1066 | { |
| 1067 | int ret = 0; |
| 1068 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1069 | struct audio_device *adev = my_data->adev; |
| 1070 | struct mixer_ctl *ctl; |
| 1071 | const char *mixer_ctl_name = "Voc VSID"; |
| 1072 | int num_ctl_values; |
| 1073 | int i; |
| 1074 | |
| 1075 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1076 | if (!ctl) { |
| 1077 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1078 | __func__, mixer_ctl_name); |
| 1079 | ret = -EINVAL; |
| 1080 | } else { |
| 1081 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 1082 | for (i = 0; i < num_ctl_values; i++) { |
| 1083 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 1084 | ALOGV("Error: invalid session_id: %x", session_id); |
| 1085 | ret = -EINVAL; |
| 1086 | break; |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1094 | void platform_get_parameters(void *platform, |
| 1095 | struct str_parms *query, |
| 1096 | struct str_parms *reply) |
| 1097 | { |
| 1098 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1099 | char *str = NULL; |
| 1100 | char value[256] = {0}; |
| 1101 | int ret; |
| 1102 | int fluence_type; |
| 1103 | |
| 1104 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, |
| 1105 | value, sizeof(value)); |
| 1106 | if (ret >= 0) { |
| 1107 | pthread_mutex_lock(&my_data->adev->lock); |
| 1108 | if (my_data->fluence_type == FLUENCE_QUAD_MIC) { |
| 1109 | strlcpy(value, "fluencepro", sizeof(value)); |
| 1110 | } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) { |
| 1111 | strlcpy(value, "fluence", sizeof(value)); |
| 1112 | } else { |
| 1113 | strlcpy(value, "none", sizeof(value)); |
| 1114 | } |
| 1115 | pthread_mutex_unlock(&my_data->adev->lock); |
| 1116 | |
| 1117 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value); |
| 1118 | } |
| 1119 | |
| 1120 | ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply)); |
| 1121 | } |
| 1122 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 1123 | /* Delay in Us */ |
| 1124 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 1125 | { |
| 1126 | switch (usecase) { |
| 1127 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 1128 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 1129 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 1130 | return LOW_LATENCY_PLATFORM_DELAY; |
| 1131 | default: |
| 1132 | return 0; |
| 1133 | } |
| 1134 | } |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 1135 | |
| 1136 | int platform_get_usecase_from_source(int source) |
| 1137 | { |
Mingming Yin | ab42978 | 2013-11-07 11:16:55 -0800 | [diff] [blame] | 1138 | ALOGV("%s: input source :%d", __func__, source); |
| 1139 | if(source == AUDIO_SOURCE_FM_RX_A2DP) |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 1140 | return USECASE_AUDIO_RECORD_FM_VIRTUAL; |
| 1141 | else |
| 1142 | return USECASE_AUDIO_RECORD; |
| 1143 | } |