Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1 | /* |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
Shiv Maliyappanahalli | 8911f28 | 2014-01-10 15:56:19 -0800 | [diff] [blame] | 5 | * Copyright (C) 2013 The Android Open Source Project |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 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> |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 26 | #include <fcntl.h> |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 27 | #include <sys/ioctl.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 28 | #include <cutils/log.h> |
| 29 | #include <cutils/properties.h> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 30 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 31 | #include <audio_hw.h> |
| 32 | #include <platform_api.h> |
| 33 | #include "platform.h" |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 34 | #include "audio_extn.h" |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 35 | #include "voice_extn.h" |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 36 | #include "sound/compress_params.h" |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 37 | #include "sound/msmcal-hwdep.h" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 38 | |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 39 | #define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100) |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 40 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
Damir Didjusto | f1d46c7 | 2013-11-06 17:59:04 -0800 | [diff] [blame] | 41 | #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml" |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 42 | #define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml" |
| 43 | |
| 44 | #define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml" |
| 45 | #define PLATFORM_INFO_XML_PATH_I2S "/system/etc/audio_platform_info_i2s.xml" |
| 46 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 47 | #define LIB_ACDB_LOADER "libacdbloader.so" |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 48 | #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID" |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 49 | #define CVD_VERSION_MIXER_CTL "CVD Version" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 50 | |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 51 | #define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024) |
| 52 | #define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024) |
| 53 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024) |
| 54 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024) |
| 55 | |
| 56 | /* Used in calculating fragment size for pcm offload */ |
ApurupaPattapu | b57da78 | 2014-04-08 10:41:07 -0700 | [diff] [blame] | 57 | #define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 1000 /* 1 sec */ |
| 58 | #define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 80 /* 80 millisecs */ |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 59 | |
| 60 | /* MAX PCM fragment size cannot be increased further due |
| 61 | * to flinger's cblk size of 1mb,and it has to be a multiple of |
| 62 | * 24 - lcm of channels supported by DSP |
| 63 | */ |
| 64 | #define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024) |
ApurupaPattapu | b57da78 | 2014-04-08 10:41:07 -0700 | [diff] [blame] | 65 | #define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (4 * 1024) |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 66 | |
| 67 | #define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1))) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 68 | /* |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 69 | * This file will have a maximum of 38 bytes: |
| 70 | * |
| 71 | * 4 bytes: number of audio blocks |
| 72 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 73 | * Maximum 10 * 3 bytes: SAD blocks |
| 74 | */ |
| 75 | #define MAX_SAD_BLOCKS 10 |
| 76 | #define SAD_BLOCK_SIZE 3 |
| 77 | |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 78 | #define MAX_CVD_VERSION_STRING_SIZE 100 |
| 79 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 80 | /* EDID format ID for LPCM audio */ |
| 81 | #define EDID_FORMAT_LPCM 1 |
| 82 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 83 | /* fallback app type if the default app type from acdb loader fails */ |
| 84 | #define DEFAULT_APP_TYPE 0x11130 |
| 85 | |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 86 | /* Retry for delay in FW loading*/ |
| 87 | #define RETRY_NUMBER 10 |
| 88 | #define RETRY_US 500000 |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 89 | #define MAX_SND_CARD 8 |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 90 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 91 | #define SAMPLE_RATE_8KHZ 8000 |
| 92 | #define SAMPLE_RATE_16KHZ 16000 |
| 93 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 94 | #define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence" |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 95 | #define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable" |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 96 | #define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice" |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 97 | #define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost" |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 98 | /* Query external audio device connection status */ |
| 99 | #define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device" |
| 100 | |
| 101 | #define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1" |
| 102 | #define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2" |
| 103 | #define EVENT_EXTERNAL_MIC "qc_ext_mic" |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 104 | #define MAX_CAL_NAME 20 |
| 105 | |
| 106 | char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = { |
| 107 | [WCD9XXX_ANC_CAL] = "anc_cal", |
| 108 | [WCD9XXX_MBHC_CAL] = "mbhc_cal", |
| 109 | [WCD9XXX_MAD_CAL] = "mad_cal", |
| 110 | }; |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 111 | |
| 112 | enum { |
| 113 | VOICE_FEATURE_SET_DEFAULT, |
| 114 | VOICE_FEATURE_SET_VOLUME_BOOST |
| 115 | }; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 116 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 117 | struct audio_block_header |
| 118 | { |
| 119 | int reserved; |
| 120 | int length; |
| 121 | }; |
| 122 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 123 | /* Audio calibration related functions */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 124 | typedef void (*acdb_deallocate_t)(); |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 125 | typedef int (*acdb_init_t)(const char *, char *); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 126 | typedef void (*acdb_send_audio_cal_t)(int, int, int , int); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 127 | typedef void (*acdb_send_voice_cal_t)(int, int); |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 128 | typedef int (*acdb_reload_vocvoltable_t)(int); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 129 | typedef int (*acdb_get_default_app_type_t)(void); |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 130 | typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data); |
| 131 | acdb_loader_get_calibration_t acdb_loader_get_calibration; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 132 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 133 | struct platform_data { |
| 134 | struct audio_device *adev; |
| 135 | bool fluence_in_spkr_mode; |
| 136 | bool fluence_in_voice_call; |
| 137 | bool fluence_in_voice_rec; |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 138 | bool fluence_in_audio_rec; |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 139 | bool external_spk_1; |
| 140 | bool external_spk_2; |
| 141 | bool external_mic; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 142 | int fluence_type; |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 143 | int fluence_mode; |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 144 | char fluence_cap[PROPERTY_VALUE_MAX]; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 145 | bool slowtalk; |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 146 | bool hd_voice; |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 147 | bool ec_ref_enabled; |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 148 | bool is_i2s_ext_modem; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 149 | /* Audio calibration related functions */ |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 150 | void *acdb_handle; |
| 151 | int voice_feature_set; |
| 152 | acdb_init_t acdb_init; |
| 153 | acdb_deallocate_t acdb_deallocate; |
| 154 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 155 | acdb_send_voice_cal_t acdb_send_voice_cal; |
| 156 | acdb_reload_vocvoltable_t acdb_reload_vocvoltable; |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 157 | acdb_get_default_app_type_t acdb_get_default_app_type; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 158 | |
| 159 | void *hw_info; |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 160 | struct csd_data *csd; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 163 | static int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 164 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE, |
| 165 | DEEP_BUFFER_PCM_DEVICE}, |
| 166 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 167 | LOWLATENCY_PCM_DEVICE}, |
| 168 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE, |
| 169 | MULTIMEDIA2_PCM_DEVICE}, |
Krishnankutty Kolathappilly | a43f96e | 2013-11-01 12:17:53 -0700 | [diff] [blame] | 170 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = |
| 171 | {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE}, |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 172 | #ifdef MULTIPLE_OFFLOAD_ENABLED |
| 173 | [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = |
| 174 | {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2}, |
| 175 | [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = |
| 176 | {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3}, |
| 177 | [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = |
| 178 | {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4}, |
| 179 | [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = |
| 180 | {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5}, |
| 181 | [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = |
| 182 | {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6}, |
| 183 | [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = |
| 184 | {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7}, |
| 185 | [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = |
| 186 | {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8}, |
| 187 | [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = |
| 188 | {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9}, |
| 189 | #endif |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 190 | [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE}, |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 191 | [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE}, |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 192 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE, |
| 193 | LOWLATENCY_PCM_DEVICE}, |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 194 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE, |
| 195 | MULTIMEDIA2_PCM_DEVICE}, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 196 | [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE}, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 197 | [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX}, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 198 | [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX}, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 199 | [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE}, |
| 200 | [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE}, |
| 201 | [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE}, |
| 202 | [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE}, |
Vicky Sehrawat | 7e4fc15 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 203 | [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE}, |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 204 | [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE}, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 205 | [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 206 | AUDIO_RECORD_PCM_DEVICE}, |
| 207 | [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 208 | AUDIO_RECORD_PCM_DEVICE}, |
| 209 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE, |
| 210 | AUDIO_RECORD_PCM_DEVICE}, |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 211 | [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 212 | COMPRESS_CAPTURE_DEVICE}, |
| 213 | [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 214 | COMPRESS_CAPTURE_DEVICE}, |
| 215 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, |
| 216 | COMPRESS_CAPTURE_DEVICE}, |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 217 | [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE, |
| 218 | INCALL_MUSIC_UPLINK_PCM_DEVICE}, |
| 219 | [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE, |
| 220 | INCALL_MUSIC_UPLINK2_PCM_DEVICE}, |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 221 | [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1}, |
| 222 | [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE}, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | /* Array to store sound devices */ |
| 226 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 227 | [SND_DEVICE_NONE] = "none", |
| 228 | /* Playback sound devices */ |
| 229 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 230 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 231 | [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1", |
| 232 | [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 233 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
| 234 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 235 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 236 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1", |
| 237 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 238 | [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset", |
| 239 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 240 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
| 241 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 242 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 243 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 244 | [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 245 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 246 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 247 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 248 | [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy", |
| 249 | [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones", |
| 250 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 251 | [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm", |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 252 | [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones", |
| 253 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones", |
| 254 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones", |
| 255 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones", |
| 256 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones", |
| 257 | [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset", |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 258 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected", |
Anish Kumar | 46c7b87 | 2014-09-09 01:49:44 -0700 | [diff] [blame] | 259 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 260 | |
| 261 | /* Capture sound devices */ |
| 262 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 263 | [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 264 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 265 | [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic", |
| 266 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic", |
| 267 | [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire", |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 268 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire", |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 269 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire", |
| 270 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire", |
| 271 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 272 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic", |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 273 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic", |
| 274 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic", |
| 275 | [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire", |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 276 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire", |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 277 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire", |
| 278 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire", |
| 279 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 280 | [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 281 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 282 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 283 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 284 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 285 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 286 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb", |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 287 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 288 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 289 | [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef", |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 290 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef", |
Vidyakumar Athota | adfe4e3 | 2013-12-13 14:51:26 -0800 | [diff] [blame] | 291 | [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 292 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 293 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 294 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
| 295 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 296 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic", |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 297 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef", |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 298 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence", |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 299 | [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 300 | [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm", |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 301 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic", |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 302 | [SND_DEVICE_IN_QUAD_MIC] = "quad-mic", |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 303 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef", |
| 304 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef", |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 305 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback", |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 306 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside", |
| 307 | [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside", |
| 308 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside", |
| 309 | [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside", |
| 310 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 314 | static int acdb_device_table[SND_DEVICE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 315 | [SND_DEVICE_NONE] = -1, |
| 316 | [SND_DEVICE_OUT_HANDSET] = 7, |
Vidyakumar Athota | c29d4ab | 2013-11-14 16:58:02 -0800 | [diff] [blame] | 317 | [SND_DEVICE_OUT_SPEAKER] = 14, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 318 | [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14, |
| 319 | [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14, |
Vidyakumar Athota | c29d4ab | 2013-11-14 16:58:02 -0800 | [diff] [blame] | 320 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 321 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 322 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 323 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10, |
| 324 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 325 | [SND_DEVICE_OUT_VOICE_HANDSET] = 7, |
Vidyakumar Athota | c29d4ab | 2013-11-14 16:58:02 -0800 | [diff] [blame] | 326 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 14, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 327 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
| 328 | [SND_DEVICE_OUT_HDMI] = 18, |
Vidyakumar Athota | c29d4ab | 2013-11-14 16:58:02 -0800 | [diff] [blame] | 329 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 330 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 331 | [SND_DEVICE_OUT_BT_SCO_WB] = 39, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 332 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 333 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 334 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 335 | [SND_DEVICE_OUT_AFE_PROXY] = 0, |
Vidyakumar Athota | b952220 | 2014-01-14 20:08:27 -0800 | [diff] [blame] | 336 | [SND_DEVICE_OUT_USB_HEADSET] = 45, |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 337 | [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 338 | [SND_DEVICE_OUT_TRANSMISSION_FM] = 0, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 339 | [SND_DEVICE_OUT_ANC_HEADSET] = 26, |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 340 | [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 341 | [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26, |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 342 | [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 343 | [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26, |
| 344 | [SND_DEVICE_OUT_ANC_HANDSET] = 103, |
Anish Kumar | 46c7b87 | 2014-09-09 01:49:44 -0700 | [diff] [blame] | 345 | [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124, |
| 346 | [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 347 | |
| 348 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 349 | [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 350 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106, |
| 351 | [SND_DEVICE_IN_HANDSET_MIC_NS] = 107, |
| 352 | [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 353 | [SND_DEVICE_IN_HANDSET_DMIC] = 41, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 354 | [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109, |
| 355 | [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110, |
| 356 | [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 357 | [SND_DEVICE_IN_SPEAKER_MIC] = 11, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 358 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112, |
| 359 | [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113, |
| 360 | [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 361 | [SND_DEVICE_IN_SPEAKER_DMIC] = 43, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 362 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115, |
| 363 | [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116, |
| 364 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 365 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 366 | [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 367 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 368 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 369 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 370 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 371 | [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 372 | [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38, |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 373 | [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 374 | [SND_DEVICE_IN_CAMCORDER_MIC] = 4, |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 375 | [SND_DEVICE_IN_VOICE_DMIC] = 41, |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 376 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43, |
Vidyakumar Athota | adfe4e3 | 2013-12-13 14:51:26 -0800 | [diff] [blame] | 377 | [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 378 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 379 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 380 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 381 | [SND_DEVICE_IN_VOICE_REC_MIC] = 4, |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 382 | [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107, |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 383 | [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34, |
| 384 | [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41, |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 385 | [SND_DEVICE_IN_USB_HEADSET_MIC] = 44, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 386 | [SND_DEVICE_IN_CAPTURE_FM] = 0, |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 387 | [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104, |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 388 | [SND_DEVICE_IN_QUAD_MIC] = 46, |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 389 | [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34, |
| 390 | [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35, |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 391 | [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102, |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 392 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12, |
| 393 | [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12, |
| 394 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119, |
| 395 | [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121, |
| 396 | [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 399 | struct name_to_index { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 400 | char name[100]; |
| 401 | unsigned int index; |
| 402 | }; |
| 403 | |
| 404 | #define TO_NAME_INDEX(X) #X, X |
| 405 | |
| 406 | /* Used to get index from parsed sting */ |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 407 | static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 408 | {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)}, |
| 409 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)}, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 410 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)}, |
| 411 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 412 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)}, |
| 413 | {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)}, |
| 414 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)}, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 415 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)}, |
| 416 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 417 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)}, |
| 418 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)}, |
| 419 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)}, |
| 420 | {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)}, |
| 421 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)}, |
| 422 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)}, |
| 423 | {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)}, |
| 424 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)}, |
| 425 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)}, |
| 426 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)}, |
| 427 | {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)}, |
| 428 | {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)}, |
| 429 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)}, |
| 430 | {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)}, |
| 431 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)}, |
| 432 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)}, |
| 433 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)}, |
| 434 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)}, |
| 435 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)}, |
| 436 | {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)}, |
| 437 | {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)}, |
Anish Kumar | 46c7b87 | 2014-09-09 01:49:44 -0700 | [diff] [blame] | 438 | {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 439 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 440 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 441 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)}, |
| 442 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)}, |
| 443 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)}, |
| 444 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)}, |
| 445 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)}, |
| 446 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)}, |
| 447 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)}, |
| 448 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)}, |
| 449 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)}, |
| 450 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)}, |
| 451 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)}, |
| 452 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)}, |
| 453 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)}, |
| 454 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)}, |
| 455 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)}, |
| 456 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)}, |
| 457 | {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)}, |
| 458 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)}, |
| 459 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)}, |
| 460 | {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)}, |
| 461 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)}, |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 462 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 463 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)}, |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 464 | {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 465 | {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)}, |
| 466 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)}, |
| 467 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)}, |
| 468 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)}, |
| 469 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)}, |
| 470 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)}, |
| 471 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)}, |
| 472 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)}, |
| 473 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)}, |
| 474 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)}, |
| 475 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)}, |
| 476 | {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)}, |
| 477 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)}, |
| 478 | {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)}, |
| 479 | {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)}, |
| 480 | {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)}, |
| 481 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)}, |
| 482 | {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)}, |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 483 | {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)}, |
| 484 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)}, |
| 485 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)}, |
| 486 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)}, |
| 487 | {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)}, |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 488 | }; |
| 489 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 490 | static char * backend_table[SND_DEVICE_MAX] = {0}; |
| 491 | |
| 492 | static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = { |
| 493 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)}, |
| 494 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)}, |
| 495 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)}, |
| 496 | {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)}, |
| 497 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD)}, |
| 498 | {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)}, |
| 499 | {TO_NAME_INDEX(USECASE_VOICE_CALL)}, |
| 500 | {TO_NAME_INDEX(USECASE_VOICE2_CALL)}, |
| 501 | {TO_NAME_INDEX(USECASE_VOLTE_CALL)}, |
| 502 | {TO_NAME_INDEX(USECASE_QCHAT_CALL)}, |
| 503 | {TO_NAME_INDEX(USECASE_VOWLAN_CALL)}, |
| 504 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)}, |
| 505 | {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)}, |
| 506 | {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)}, |
| 507 | {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)}, |
| 508 | }; |
| 509 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 510 | #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL) |
| 511 | #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL) |
| 512 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 513 | void platform_set_echo_reference(void *platform, bool enable) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 514 | { |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 515 | struct platform_data *my_data = (struct platform_data *)platform; |
| 516 | struct audio_device *adev = my_data->adev; |
| 517 | |
| 518 | if (enable) { |
| 519 | my_data->ec_ref_enabled = enable; |
| 520 | audio_route_apply_and_update_path(adev->audio_route, "echo-reference"); |
| 521 | } else { |
| 522 | if (my_data->ec_ref_enabled) { |
| 523 | audio_route_reset_and_update_path(adev->audio_route, "echo-reference"); |
| 524 | my_data->ec_ref_enabled = enable; |
| 525 | } else { |
| 526 | ALOGV("EC Reference is already disabled: %d", my_data->ec_ref_enabled); |
| 527 | } |
| 528 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 529 | |
Anish Kumar | 4980fa1 | 2014-04-17 12:42:20 -0700 | [diff] [blame] | 530 | ALOGV("Setting EC Reference: %d", enable); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 533 | static struct csd_data *open_csd_client(bool i2s_ext_modem) |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 534 | { |
| 535 | struct csd_data *csd = calloc(1, sizeof(struct csd_data)); |
| 536 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 537 | if (!csd) { |
| 538 | ALOGE("failed to allocate csd_data mem"); |
| 539 | return NULL; |
| 540 | } |
| 541 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 542 | csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 543 | if (csd->csd_client == NULL) { |
| 544 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 545 | goto error; |
| 546 | } else { |
| 547 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 548 | |
| 549 | csd->deinit = (deinit_t)dlsym(csd->csd_client, |
| 550 | "csd_client_deinit"); |
| 551 | if (csd->deinit == NULL) { |
| 552 | ALOGE("%s: dlsym error %s for csd_client_deinit", __func__, |
| 553 | dlerror()); |
| 554 | goto error; |
| 555 | } |
| 556 | csd->disable_device = (disable_device_t)dlsym(csd->csd_client, |
| 557 | "csd_client_disable_device"); |
| 558 | if (csd->disable_device == NULL) { |
| 559 | ALOGE("%s: dlsym error %s for csd_client_disable_device", |
| 560 | __func__, dlerror()); |
| 561 | goto error; |
| 562 | } |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 563 | csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client, |
| 564 | "csd_client_enable_device_config"); |
| 565 | if (csd->enable_device_config == NULL) { |
| 566 | ALOGE("%s: dlsym error %s for csd_client_enable_device_config", |
| 567 | __func__, dlerror()); |
| 568 | goto error; |
| 569 | } |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 570 | csd->enable_device = (enable_device_t)dlsym(csd->csd_client, |
| 571 | "csd_client_enable_device"); |
| 572 | if (csd->enable_device == NULL) { |
| 573 | ALOGE("%s: dlsym error %s for csd_client_enable_device", |
| 574 | __func__, dlerror()); |
| 575 | goto error; |
| 576 | } |
| 577 | csd->start_voice = (start_voice_t)dlsym(csd->csd_client, |
| 578 | "csd_client_start_voice"); |
| 579 | if (csd->start_voice == NULL) { |
| 580 | ALOGE("%s: dlsym error %s for csd_client_start_voice", |
| 581 | __func__, dlerror()); |
| 582 | goto error; |
| 583 | } |
| 584 | csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client, |
| 585 | "csd_client_stop_voice"); |
| 586 | if (csd->stop_voice == NULL) { |
| 587 | ALOGE("%s: dlsym error %s for csd_client_stop_voice", |
| 588 | __func__, dlerror()); |
| 589 | goto error; |
| 590 | } |
| 591 | csd->volume = (volume_t)dlsym(csd->csd_client, |
| 592 | "csd_client_volume"); |
| 593 | if (csd->volume == NULL) { |
| 594 | ALOGE("%s: dlsym error %s for csd_client_volume", |
| 595 | __func__, dlerror()); |
| 596 | goto error; |
| 597 | } |
| 598 | csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client, |
| 599 | "csd_client_mic_mute"); |
| 600 | if (csd->mic_mute == NULL) { |
| 601 | ALOGE("%s: dlsym error %s for csd_client_mic_mute", |
| 602 | __func__, dlerror()); |
| 603 | goto error; |
| 604 | } |
| 605 | csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client, |
| 606 | "csd_client_slow_talk"); |
| 607 | if (csd->slow_talk == NULL) { |
| 608 | ALOGE("%s: dlsym error %s for csd_client_slow_talk", |
| 609 | __func__, dlerror()); |
| 610 | goto error; |
| 611 | } |
| 612 | csd->start_playback = (start_playback_t)dlsym(csd->csd_client, |
| 613 | "csd_client_start_playback"); |
| 614 | if (csd->start_playback == NULL) { |
| 615 | ALOGE("%s: dlsym error %s for csd_client_start_playback", |
| 616 | __func__, dlerror()); |
| 617 | goto error; |
| 618 | } |
| 619 | csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client, |
| 620 | "csd_client_stop_playback"); |
| 621 | if (csd->stop_playback == NULL) { |
| 622 | ALOGE("%s: dlsym error %s for csd_client_stop_playback", |
| 623 | __func__, dlerror()); |
| 624 | goto error; |
| 625 | } |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 626 | csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch"); |
| 627 | if (csd->set_lch == NULL) { |
| 628 | ALOGE("%s: dlsym error %s for csd_client_set_lch", |
| 629 | __func__, dlerror()); |
| 630 | /* Ignore the error as this is not mandatory function for |
| 631 | * basic voice call to work. |
| 632 | */ |
| 633 | } |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 634 | csd->start_record = (start_record_t)dlsym(csd->csd_client, |
| 635 | "csd_client_start_record"); |
| 636 | if (csd->start_record == NULL) { |
| 637 | ALOGE("%s: dlsym error %s for csd_client_start_record", |
| 638 | __func__, dlerror()); |
| 639 | goto error; |
| 640 | } |
| 641 | csd->stop_record = (stop_record_t)dlsym(csd->csd_client, |
| 642 | "csd_client_stop_record"); |
| 643 | if (csd->stop_record == NULL) { |
| 644 | ALOGE("%s: dlsym error %s for csd_client_stop_record", |
| 645 | __func__, dlerror()); |
| 646 | goto error; |
| 647 | } |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 648 | |
| 649 | csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client, |
| 650 | "csd_client_get_sample_rate"); |
| 651 | if (csd->get_sample_rate == NULL) { |
| 652 | ALOGE("%s: dlsym error %s for csd_client_get_sample_rate", |
| 653 | __func__, dlerror()); |
| 654 | |
| 655 | goto error; |
| 656 | } |
| 657 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 658 | csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init"); |
| 659 | |
| 660 | if (csd->init == NULL) { |
| 661 | ALOGE("%s: dlsym error %s for csd_client_init", |
| 662 | __func__, dlerror()); |
| 663 | goto error; |
| 664 | } else { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 665 | csd->init(i2s_ext_modem); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | return csd; |
| 669 | |
| 670 | error: |
| 671 | free(csd); |
| 672 | csd = NULL; |
| 673 | return csd; |
| 674 | } |
| 675 | |
| 676 | void close_csd_client(struct csd_data *csd) |
| 677 | { |
| 678 | if (csd != NULL) { |
| 679 | csd->deinit(); |
| 680 | dlclose(csd->csd_client); |
| 681 | free(csd); |
| 682 | csd = NULL; |
| 683 | } |
| 684 | } |
| 685 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 686 | static bool platform_is_i2s_ext_modem(const char *snd_card_name, |
| 687 | struct platform_data *plat_data) |
| 688 | { |
| 689 | plat_data->is_i2s_ext_modem = false; |
| 690 | |
| 691 | if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card", |
| 692 | sizeof("apq8084-taiko-i2s-mtp-snd-card")) || |
| 693 | !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card", |
| 694 | sizeof("apq8084-taiko-i2s-cdp-snd-card"))) { |
| 695 | plat_data->is_i2s_ext_modem = true; |
| 696 | } |
| 697 | ALOGV("%s, is_i2s_ext_modem:%d",__func__, plat_data->is_i2s_ext_modem); |
| 698 | |
| 699 | return plat_data->is_i2s_ext_modem; |
Helen Zeng | 008aebd | 2014-02-23 19:13:12 -0800 | [diff] [blame] | 700 | } |
| 701 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 702 | static void set_platform_defaults() |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 703 | { |
| 704 | int32_t dev; |
| 705 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 706 | backend_table[dev] = NULL; |
| 707 | } |
| 708 | |
| 709 | // TBD - do these go to the platform-info.xml file. |
| 710 | // will help in avoiding strdups here |
| 711 | backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco"); |
| 712 | backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb"); |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 713 | backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco"); |
| 714 | backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 715 | backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco"); |
| 716 | backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb"); |
| 717 | backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi"); |
| 718 | backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi"); |
| 719 | backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy"); |
| 720 | backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones"); |
| 721 | backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = |
| 722 | strdup("speaker-and-usb-headphones"); |
| 723 | backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic"); |
| 724 | backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm"); |
| 725 | backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm"); |
| 726 | } |
| 727 | |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 728 | void get_cvd_version(char *cvd_version, struct audio_device *adev) |
| 729 | { |
| 730 | struct mixer_ctl *ctl; |
| 731 | int count; |
| 732 | int ret = 0; |
| 733 | |
| 734 | ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL); |
| 735 | if (!ctl) { |
| 736 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL); |
| 737 | goto done; |
| 738 | } |
| 739 | mixer_ctl_update(ctl); |
| 740 | |
| 741 | count = mixer_ctl_get_num_values(ctl); |
| 742 | if (count > MAX_CVD_VERSION_STRING_SIZE) |
| 743 | count = MAX_CVD_VERSION_STRING_SIZE; |
| 744 | |
| 745 | ret = mixer_ctl_get_array(ctl, cvd_version, count); |
| 746 | if (ret != 0) { |
| 747 | ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__); |
| 748 | goto done; |
| 749 | } |
| 750 | |
| 751 | done: |
| 752 | return; |
| 753 | } |
| 754 | |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 755 | static int hw_util_open(int card_no) |
| 756 | { |
| 757 | int fd = -1; |
| 758 | char dev_name[256]; |
| 759 | |
| 760 | snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u", |
| 761 | card_no, WCD9XXX_CODEC_HWDEP_NODE); |
| 762 | ALOGD("%s Opening device %s\n", __func__, dev_name); |
| 763 | fd = open(dev_name, O_WRONLY); |
| 764 | if (fd < 0) { |
| 765 | ALOGE("%s: cannot open device '%s'\n", __func__, dev_name); |
| 766 | return fd; |
| 767 | } |
| 768 | ALOGD("%s success", __func__); |
| 769 | return fd; |
| 770 | } |
| 771 | |
| 772 | struct param_data { |
| 773 | int use_case; |
| 774 | int acdb_id; |
| 775 | int get_size; |
| 776 | int buff_size; |
| 777 | int data_size; |
| 778 | void *buff; |
| 779 | }; |
| 780 | |
| 781 | static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd) |
| 782 | { |
| 783 | int ret = 0, type; |
| 784 | |
| 785 | for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) { |
| 786 | struct wcdcal_ioctl_buffer codec_buffer; |
| 787 | struct param_data calib; |
| 788 | |
| 789 | if (!strcmp(cal_name_info[type], "mad_cal")) |
| 790 | calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID; |
| 791 | calib.get_size = 1; |
| 792 | ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data), |
| 793 | &calib); |
| 794 | if (ret < 0) { |
| 795 | ALOGE("%s get_calibration failed\n", __func__); |
| 796 | return ret; |
| 797 | } |
| 798 | calib.get_size = 0; |
| 799 | calib.buff = malloc(calib.buff_size); |
| 800 | ret = acdb_loader_get_calibration(cal_name_info[type], |
| 801 | sizeof(struct param_data), &calib); |
| 802 | if (ret < 0) { |
| 803 | ALOGE("%s get_calibration failed\n", __func__); |
| 804 | free(calib.buff); |
| 805 | return ret; |
| 806 | } |
| 807 | codec_buffer.buffer = calib.buff; |
| 808 | codec_buffer.size = calib.data_size; |
| 809 | codec_buffer.cal_type = type; |
| 810 | if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0) |
| 811 | ALOGE("Failed to call ioctl for %s err=%d", |
| 812 | cal_name_info[type], errno); |
| 813 | ALOGD("%s cal sent for %s", __func__, cal_name_info[type]); |
| 814 | free(calib.buff); |
| 815 | } |
| 816 | return ret; |
| 817 | } |
| 818 | |
| 819 | static void audio_hwdep_send_cal(struct platform_data *plat_data) |
| 820 | { |
| 821 | int fd; |
| 822 | |
| 823 | fd = hw_util_open(plat_data->adev->snd_card); |
| 824 | if (fd == -1) { |
| 825 | ALOGE("%s error open\n", __func__); |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | acdb_loader_get_calibration = (acdb_loader_get_calibration_t) |
| 830 | dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration"); |
| 831 | |
| 832 | if (acdb_loader_get_calibration == NULL) { |
| 833 | ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__, |
| 834 | dlerror()); |
| 835 | return; |
| 836 | } |
| 837 | if (send_codec_cal(acdb_loader_get_calibration, fd) < 0) |
| 838 | ALOGE("%s: Could not send anc cal", __FUNCTION__); |
| 839 | } |
| 840 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 841 | void *platform_init(struct audio_device *adev) |
| 842 | { |
Vidyakumar Athota | 77327dd | 2014-08-07 16:44:25 -0700 | [diff] [blame] | 843 | char platform[PROPERTY_VALUE_MAX]; |
| 844 | char baseband[PROPERTY_VALUE_MAX]; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 845 | char value[PROPERTY_VALUE_MAX]; |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 846 | struct platform_data *my_data = NULL; |
| 847 | int retry_num = 0, snd_card_num = 0; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 848 | const char *snd_card_name; |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 849 | char *cvd_version = NULL; |
sangwoo | 1b9f4b3 | 2013-06-21 18:22:55 -0700 | [diff] [blame] | 850 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 851 | my_data = calloc(1, sizeof(struct platform_data)); |
| 852 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 853 | if (!my_data) { |
| 854 | ALOGE("failed to allocate platform data"); |
| 855 | return NULL; |
| 856 | } |
| 857 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 858 | while (snd_card_num < MAX_SND_CARD) { |
| 859 | adev->mixer = mixer_open(snd_card_num); |
| 860 | |
| 861 | while (!adev->mixer && retry_num < RETRY_NUMBER) { |
| 862 | usleep(RETRY_US); |
| 863 | adev->mixer = mixer_open(snd_card_num); |
| 864 | retry_num++; |
| 865 | } |
| 866 | |
| 867 | if (!adev->mixer) { |
| 868 | ALOGE("%s: Unable to open the mixer card: %d", __func__, |
| 869 | snd_card_num); |
| 870 | retry_num = 0; |
| 871 | snd_card_num++; |
| 872 | continue; |
| 873 | } |
| 874 | |
| 875 | snd_card_name = mixer_get_name(adev->mixer); |
| 876 | ALOGV("%s: snd_card_name: %s", __func__, snd_card_name); |
| 877 | |
| 878 | my_data->hw_info = hw_info_init(snd_card_name); |
| 879 | if (!my_data->hw_info) { |
| 880 | ALOGE("%s: Failed to init hardware info", __func__); |
| 881 | } else { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 882 | if (platform_is_i2s_ext_modem(snd_card_name, my_data)) { |
| 883 | ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__); |
| 884 | |
| 885 | adev->audio_route = audio_route_init(snd_card_num, |
| 886 | MIXER_XML_PATH_I2S); |
| 887 | } else if (audio_extn_read_xml(adev, snd_card_num, MIXER_XML_PATH, |
| 888 | MIXER_XML_PATH_AUXPCM) == -ENOSYS) { |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 889 | adev->audio_route = audio_route_init(snd_card_num, |
| 890 | MIXER_XML_PATH); |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 891 | } |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 892 | if (!adev->audio_route) { |
| 893 | ALOGE("%s: Failed to init audio route controls, aborting.", |
| 894 | __func__); |
| 895 | free(my_data); |
| 896 | return NULL; |
| 897 | } |
| 898 | adev->snd_card = snd_card_num; |
| 899 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 900 | break; |
| 901 | } |
| 902 | retry_num = 0; |
| 903 | snd_card_num++; |
| 904 | } |
| 905 | |
| 906 | if (snd_card_num >= MAX_SND_CARD) { |
| 907 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
| 908 | free(my_data); |
| 909 | return NULL; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 912 | my_data->adev = adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 913 | my_data->fluence_in_spkr_mode = false; |
| 914 | my_data->fluence_in_voice_call = false; |
| 915 | my_data->fluence_in_voice_rec = false; |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 916 | my_data->fluence_in_audio_rec = false; |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 917 | my_data->external_spk_1 = false; |
| 918 | my_data->external_spk_2 = false; |
| 919 | my_data->external_mic = false; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 920 | my_data->fluence_type = FLUENCE_NONE; |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 921 | my_data->fluence_mode = FLUENCE_ENDFIRE; |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 922 | my_data->slowtalk = false; |
| 923 | my_data->hd_voice = false; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 924 | |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 925 | property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, ""); |
| 926 | if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) { |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 927 | my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC; |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 928 | } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 929 | my_data->fluence_type = FLUENCE_DUAL_MIC; |
| 930 | } else { |
| 931 | my_data->fluence_type = FLUENCE_NONE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 934 | if (my_data->fluence_type != FLUENCE_NONE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 935 | property_get("persist.audio.fluence.voicecall",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 936 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 937 | my_data->fluence_in_voice_call = true; |
| 938 | } |
| 939 | |
| 940 | property_get("persist.audio.fluence.voicerec",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 941 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 942 | my_data->fluence_in_voice_rec = true; |
| 943 | } |
| 944 | |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 945 | property_get("persist.audio.fluence.audiorec",value,""); |
| 946 | if (!strncmp("true", value, sizeof("true"))) { |
| 947 | my_data->fluence_in_audio_rec = true; |
| 948 | } |
| 949 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 950 | property_get("persist.audio.fluence.speaker",value,""); |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 951 | if (!strncmp("true", value, sizeof("true"))) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 952 | my_data->fluence_in_spkr_mode = true; |
| 953 | } |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 954 | |
| 955 | property_get("persist.audio.fluence.mode",value,""); |
| 956 | if (!strncmp("broadside", value, sizeof("broadside"))) { |
| 957 | my_data->fluence_mode = FLUENCE_BROADSIDE; |
| 958 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 959 | } |
| 960 | |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 961 | my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 962 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 963 | if (my_data->acdb_handle == NULL) { |
| 964 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 965 | } else { |
| 966 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 967 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 968 | "acdb_loader_deallocate_ACDB"); |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 969 | if (!my_data->acdb_deallocate) |
| 970 | ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s", |
| 971 | __func__, LIB_ACDB_LOADER); |
| 972 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 973 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 974 | "acdb_loader_send_audio_cal_v2"); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 975 | if (!my_data->acdb_send_audio_cal) |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 976 | ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 977 | __func__, LIB_ACDB_LOADER); |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 978 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 979 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 980 | "acdb_loader_send_voice_cal"); |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 981 | if (!my_data->acdb_send_voice_cal) |
| 982 | ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s", |
| 983 | __func__, LIB_ACDB_LOADER); |
| 984 | |
| 985 | my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle, |
| 986 | "acdb_loader_reload_vocvoltable"); |
| 987 | if (!my_data->acdb_reload_vocvoltable) |
| 988 | ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s", |
| 989 | __func__, LIB_ACDB_LOADER); |
| 990 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 991 | my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym( |
| 992 | my_data->acdb_handle, |
| 993 | "acdb_loader_get_default_app_type"); |
| 994 | if (!my_data->acdb_get_default_app_type) |
| 995 | ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s", |
| 996 | __func__, LIB_ACDB_LOADER); |
| 997 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 998 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
Ben Romberger | 490d347 | 2014-01-15 17:11:59 -0800 | [diff] [blame] | 999 | "acdb_loader_init_v2"); |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 1000 | if (my_data->acdb_init == NULL) { |
Ben Romberger | 490d347 | 2014-01-15 17:11:59 -0800 | [diff] [blame] | 1001 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 1002 | goto acdb_init_fail; |
| 1003 | } |
| 1004 | |
| 1005 | cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE); |
| 1006 | if (!cvd_version) |
| 1007 | ALOGE("failed to allocate cvd_version"); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1008 | else |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 1009 | get_cvd_version(cvd_version, adev); |
| 1010 | |
| 1011 | my_data->acdb_init(snd_card_name, cvd_version); |
| 1012 | if (cvd_version) |
| 1013 | free(cvd_version); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Walter Yang | 6f80005 | 2014-07-14 16:15:38 -0700 | [diff] [blame] | 1016 | acdb_init_fail: |
| 1017 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1018 | set_platform_defaults(); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1019 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1020 | /* Initialize ACDB ID's */ |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 1021 | if (my_data->is_i2s_ext_modem) |
| 1022 | platform_info_init(PLATFORM_INFO_XML_PATH_I2S); |
| 1023 | else |
| 1024 | platform_info_init(PLATFORM_INFO_XML_PATH); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1025 | |
Vidyakumar Athota | 77327dd | 2014-08-07 16:44:25 -0700 | [diff] [blame] | 1026 | /* If platform is apq8084 and baseband is MDM, load CSD Client specific |
| 1027 | * symbols. Voice call is handled by MDM and apps processor talks to |
| 1028 | * MDM through CSD Client |
| 1029 | */ |
| 1030 | property_get("ro.board.platform", platform, ""); |
| 1031 | property_get("ro.baseband", baseband, ""); |
| 1032 | if (!strncmp("apq8084", platform, sizeof("apq8084")) && |
| 1033 | !strncmp("mdm", baseband, (sizeof("mdm")-1))) { |
| 1034 | my_data->csd = open_csd_client(my_data->is_i2s_ext_modem); |
| 1035 | } else { |
| 1036 | my_data->csd = NULL; |
| 1037 | } |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1038 | |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1039 | /* init usb */ |
| 1040 | audio_extn_usb_init(adev); |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 1041 | /* update sound cards appropriately */ |
| 1042 | audio_extn_usb_set_proxy_sound_card(adev->snd_card); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1043 | |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 1044 | /* Read one time ssr property */ |
Mingming Yin | 49be803 | 2013-12-19 12:51:25 -0800 | [diff] [blame] | 1045 | audio_extn_ssr_update_enabled(); |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 1046 | audio_extn_spkr_prot_init(adev); |
Dhananjay Kumar | 89ea3bd | 2014-04-29 15:45:57 +0530 | [diff] [blame] | 1047 | |
| 1048 | audio_extn_dolby_set_license(adev); |
Anish Kumar | 55e6df2 | 2014-08-26 17:38:05 -0700 | [diff] [blame^] | 1049 | audio_hwdep_send_cal(my_data); |
Dhananjay Kumar | 89ea3bd | 2014-04-29 15:45:57 +0530 | [diff] [blame] | 1050 | |
Lior Barenboim | 0b61bc7 | 2014-05-13 13:01:37 +0300 | [diff] [blame] | 1051 | /* init audio device arbitration */ |
| 1052 | audio_extn_dev_arbi_init(); |
| 1053 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1054 | return my_data; |
| 1055 | } |
| 1056 | |
| 1057 | void platform_deinit(void *platform) |
| 1058 | { |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 1059 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1060 | |
| 1061 | hw_info_deinit(my_data->hw_info); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1062 | close_csd_client(my_data->csd); |
| 1063 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1064 | int32_t dev; |
| 1065 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) { |
| 1066 | if (backend_table[dev]) { |
| 1067 | free(backend_table[dev]); |
| 1068 | backend_table[dev]= NULL; |
| 1069 | } |
| 1070 | } |
| 1071 | |
Lior Barenboim | 0b61bc7 | 2014-05-13 13:01:37 +0300 | [diff] [blame] | 1072 | /* deinit audio device arbitration */ |
| 1073 | audio_extn_dev_arbi_deinit(); |
| 1074 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1075 | free(platform); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1076 | /* deinit usb */ |
| 1077 | audio_extn_usb_deinit(); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 1081 | { |
| 1082 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) |
| 1083 | return device_table[snd_device]; |
| 1084 | else |
| 1085 | return ""; |
| 1086 | } |
| 1087 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 1088 | int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device, |
| 1089 | char *device_name) |
| 1090 | { |
| 1091 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1092 | |
| 1093 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) { |
| 1094 | strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE); |
| 1095 | hw_info_append_hw_type(my_data->hw_info, snd_device, device_name); |
| 1096 | } else { |
| 1097 | strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE); |
| 1098 | return -EINVAL; |
| 1099 | } |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1104 | void platform_add_backend_name(char *mixer_path, snd_device_t snd_device) |
| 1105 | { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1106 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1107 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1108 | return; |
| 1109 | } |
| 1110 | |
| 1111 | const char * suffix = backend_table[snd_device]; |
| 1112 | |
| 1113 | if (suffix != NULL) { |
| 1114 | strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH); |
| 1115 | strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH); |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1116 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 1120 | { |
| 1121 | int device_id; |
| 1122 | if (device_type == PCM_PLAYBACK) |
| 1123 | device_id = pcm_device_table[usecase][0]; |
| 1124 | else |
| 1125 | device_id = pcm_device_table[usecase][1]; |
| 1126 | return device_id; |
| 1127 | } |
| 1128 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1129 | static int find_index(struct name_to_index * table, int32_t len, const char * name) |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1130 | { |
| 1131 | int ret = 0; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1132 | int32_t i; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1133 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1134 | if (table == NULL) { |
| 1135 | ALOGE("%s: table is NULL", __func__); |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1136 | ret = -ENODEV; |
| 1137 | goto done; |
| 1138 | } |
| 1139 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1140 | if (name == NULL) { |
| 1141 | ALOGE("null key"); |
| 1142 | ret = -ENODEV; |
| 1143 | goto done; |
| 1144 | } |
| 1145 | |
| 1146 | for (i=0; i < len; i++) { |
| 1147 | const char* tn = table[i].name; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1148 | size_t len = strlen(tn); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1149 | if (strncmp(tn, name, len) == 0) { |
| 1150 | if (strlen(name) != len) { |
| 1151 | continue; // substring |
| 1152 | } |
| 1153 | ret = table[i].index; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1154 | goto done; |
| 1155 | } |
| 1156 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1157 | ALOGE("%s: Could not find index for name = %s", |
| 1158 | __func__, name); |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1159 | ret = -ENODEV; |
| 1160 | done: |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 1164 | int platform_set_fluence_type(void *platform, char *value) |
| 1165 | { |
| 1166 | int ret = 0; |
| 1167 | int fluence_type = FLUENCE_NONE; |
| 1168 | int fluence_flag = NONE_FLAG; |
| 1169 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1170 | struct audio_device *adev = my_data->adev; |
| 1171 | |
| 1172 | ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type); |
| 1173 | |
| 1174 | /* only dual mic turn on and off is supported as of now through setparameters */ |
| 1175 | if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) { |
| 1176 | if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) || |
| 1177 | !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) { |
| 1178 | ALOGV("fluence dualmic feature enabled \n"); |
| 1179 | fluence_type = FLUENCE_DUAL_MIC; |
| 1180 | fluence_flag = DMIC_FLAG; |
| 1181 | } else { |
| 1182 | ALOGE("%s: Failed to set DUALMIC", __func__); |
| 1183 | ret = -1; |
| 1184 | goto done; |
| 1185 | } |
| 1186 | } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) { |
| 1187 | ALOGV("fluence disabled"); |
| 1188 | fluence_type = FLUENCE_NONE; |
| 1189 | } else { |
| 1190 | ALOGE("Invalid fluence value : %s",value); |
| 1191 | ret = -1; |
| 1192 | goto done; |
| 1193 | } |
| 1194 | |
| 1195 | if (fluence_type != my_data->fluence_type) { |
| 1196 | ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type); |
| 1197 | my_data->fluence_type = fluence_type; |
| 1198 | adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag; |
| 1199 | } |
| 1200 | done: |
| 1201 | return ret; |
| 1202 | } |
| 1203 | |
| 1204 | int platform_get_fluence_type(void *platform, char *value, uint32_t len) |
| 1205 | { |
| 1206 | int ret = 0; |
| 1207 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1208 | |
| 1209 | if (my_data->fluence_type == FLUENCE_QUAD_MIC) { |
| 1210 | strlcpy(value, "quadmic", len); |
| 1211 | } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) { |
| 1212 | strlcpy(value, "dualmic", len); |
| 1213 | } else if (my_data->fluence_type == FLUENCE_NONE) { |
| 1214 | strlcpy(value, "none", len); |
| 1215 | } else |
| 1216 | ret = -1; |
| 1217 | |
| 1218 | return ret; |
| 1219 | } |
| 1220 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 1221 | int platform_get_snd_device_index(char *device_name) |
| 1222 | { |
| 1223 | return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name); |
| 1224 | } |
| 1225 | |
| 1226 | int platform_get_usecase_index(const char *usecase_name) |
| 1227 | { |
| 1228 | return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name); |
| 1229 | } |
| 1230 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1231 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id) |
| 1232 | { |
| 1233 | int ret = 0; |
| 1234 | |
| 1235 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1236 | ALOGE("%s: Invalid snd_device = %d", |
| 1237 | __func__, snd_device); |
| 1238 | ret = -EINVAL; |
| 1239 | goto done; |
| 1240 | } |
| 1241 | |
| 1242 | acdb_device_table[snd_device] = acdb_id; |
| 1243 | done: |
| 1244 | return ret; |
| 1245 | } |
| 1246 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1247 | int platform_get_default_app_type(void *platform) |
| 1248 | { |
| 1249 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1250 | |
| 1251 | if (my_data->acdb_get_default_app_type) |
| 1252 | return my_data->acdb_get_default_app_type(); |
| 1253 | else |
| 1254 | return DEFAULT_APP_TYPE; |
| 1255 | } |
| 1256 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1257 | int platform_get_snd_device_acdb_id(snd_device_t snd_device) |
| 1258 | { |
| 1259 | if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) { |
| 1260 | ALOGE("%s: Invalid snd_device = %d", __func__, snd_device); |
| 1261 | return -EINVAL; |
| 1262 | } |
| 1263 | return acdb_device_table[snd_device]; |
| 1264 | } |
| 1265 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1266 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device, |
| 1267 | int app_type, int sample_rate) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1268 | { |
| 1269 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1270 | int acdb_dev_id, acdb_dev_type; |
| 1271 | |
Anish Kumar | f16721c | 2014-08-01 15:09:25 -0700 | [diff] [blame] | 1272 | acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)]; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1273 | if (acdb_dev_id < 0) { |
| 1274 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 1275 | __func__, snd_device); |
| 1276 | return -EINVAL; |
| 1277 | } |
| 1278 | if (my_data->acdb_send_audio_cal) { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1279 | ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1280 | __func__, snd_device, acdb_dev_id); |
| 1281 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 1282 | snd_device < SND_DEVICE_OUT_END) |
| 1283 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 1284 | else |
| 1285 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1286 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type, |
| 1287 | sample_rate); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1288 | } |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | int platform_switch_voice_call_device_pre(void *platform) |
| 1293 | { |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1294 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1295 | int ret = 0; |
| 1296 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1297 | if (my_data->csd != NULL && |
| 1298 | my_data->adev->mode == AUDIO_MODE_IN_CALL) { |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1299 | /* This must be called before disabling mixer controls on APQ side */ |
| 1300 | ret = my_data->csd->disable_device(); |
| 1301 | if (ret < 0) { |
| 1302 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 1303 | __func__, ret); |
| 1304 | } |
| 1305 | } |
| 1306 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1309 | int platform_switch_voice_call_enable_device_config(void *platform, |
| 1310 | snd_device_t out_snd_device, |
| 1311 | snd_device_t in_snd_device) |
| 1312 | { |
| 1313 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1314 | int acdb_rx_id, acdb_tx_id; |
| 1315 | int ret = 0; |
| 1316 | |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1317 | if (my_data->csd == NULL) |
| 1318 | return ret; |
| 1319 | |
| 1320 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1321 | audio_extn_spkr_prot_is_enabled()) |
| 1322 | acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED]; |
| 1323 | else |
| 1324 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 1325 | |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1326 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 1327 | |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1328 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1329 | ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id); |
| 1330 | if (ret < 0) { |
| 1331 | ALOGE("%s: csd_enable_device_config, failed, error %d", |
| 1332 | __func__, ret); |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1333 | } |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1334 | } else { |
| 1335 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1336 | acdb_rx_id, acdb_tx_id); |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1337 | } |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1338 | |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1339 | return ret; |
| 1340 | } |
| 1341 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1342 | int platform_switch_voice_call_device_post(void *platform, |
| 1343 | snd_device_t out_snd_device, |
| 1344 | snd_device_t in_snd_device) |
| 1345 | { |
| 1346 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1347 | int acdb_rx_id, acdb_tx_id; |
| 1348 | |
| 1349 | if (my_data->acdb_send_voice_cal == NULL) { |
| 1350 | ALOGE("%s: dlsym error for acdb_send_voice_call", __func__); |
| 1351 | } else { |
Anish Kumar | 46c7b87 | 2014-09-09 01:49:44 -0700 | [diff] [blame] | 1352 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1353 | audio_extn_spkr_prot_is_enabled()) |
| 1354 | out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED; |
| 1355 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1356 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 1357 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 1358 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1359 | if (acdb_rx_id > 0 && acdb_tx_id > 0) |
| 1360 | my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id); |
| 1361 | else |
| 1362 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1363 | acdb_rx_id, acdb_tx_id); |
| 1364 | } |
| 1365 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1366 | return 0; |
| 1367 | } |
| 1368 | |
| 1369 | int platform_switch_voice_call_usecase_route_post(void *platform, |
| 1370 | snd_device_t out_snd_device, |
| 1371 | snd_device_t in_snd_device) |
| 1372 | { |
| 1373 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1374 | int acdb_rx_id, acdb_tx_id; |
| 1375 | int ret = 0; |
| 1376 | |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1377 | if (my_data->csd == NULL) |
| 1378 | return ret; |
| 1379 | |
| 1380 | if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER && |
| 1381 | audio_extn_spkr_prot_is_enabled()) |
| 1382 | acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED]; |
| 1383 | else |
| 1384 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 1385 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1386 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 1387 | |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1388 | if (acdb_rx_id > 0 && acdb_tx_id > 0) { |
| 1389 | ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id, |
| 1390 | my_data->adev->acdb_settings); |
| 1391 | if (ret < 0) { |
| 1392 | ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1393 | } |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1394 | } else { |
| 1395 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 1396 | acdb_rx_id, acdb_tx_id); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1397 | } |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 1398 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1399 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1402 | int platform_start_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1403 | { |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1404 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1405 | int ret = 0; |
| 1406 | |
| 1407 | if (my_data->csd != NULL) { |
| 1408 | ret = my_data->csd->start_voice(vsid); |
| 1409 | if (ret < 0) { |
| 1410 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 1411 | } |
| 1412 | } |
| 1413 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1416 | int platform_stop_voice_call(void *platform, uint32_t vsid) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1417 | { |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1418 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1419 | int ret = 0; |
| 1420 | |
| 1421 | if (my_data->csd != NULL) { |
| 1422 | ret = my_data->csd->stop_voice(vsid); |
| 1423 | if (ret < 0) { |
| 1424 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 1425 | } |
| 1426 | } |
| 1427 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 1430 | int platform_get_sample_rate(void *platform, uint32_t *rate) |
| 1431 | { |
| 1432 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1433 | int ret = 0; |
| 1434 | |
| 1435 | if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) { |
| 1436 | ret = my_data->csd->get_sample_rate(rate); |
| 1437 | if (ret < 0) { |
| 1438 | ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret); |
| 1439 | } |
| 1440 | } |
| 1441 | return ret; |
| 1442 | } |
| 1443 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1444 | int platform_set_voice_volume(void *platform, int volume) |
| 1445 | { |
| 1446 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1447 | struct audio_device *adev = my_data->adev; |
| 1448 | struct mixer_ctl *ctl; |
sangwoo | 53b2cf0 | 2013-07-25 19:18:44 -0700 | [diff] [blame] | 1449 | const char *mixer_ctl_name = "Voice Rx Gain"; |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1450 | int vol_index = 0, ret = 0; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1451 | uint32_t set_values[ ] = {0, |
| 1452 | ALL_SESSION_VSID, |
| 1453 | DEFAULT_VOLUME_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1454 | |
| 1455 | // Voice volume levels are mapped to adsp volume levels as follows. |
| 1456 | // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0 |
| 1457 | // 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] | 1458 | vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX); |
| 1459 | set_values[0] = vol_index; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1460 | |
| 1461 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1462 | if (!ctl) { |
| 1463 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1464 | __func__, mixer_ctl_name); |
| 1465 | return -EINVAL; |
| 1466 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1467 | ALOGV("Setting voice volume index: %d", set_values[0]); |
| 1468 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1469 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1470 | if (my_data->csd != NULL) { |
Vidyakumar Athota | c37f42a | 2014-03-11 11:57:48 -0700 | [diff] [blame] | 1471 | ret = my_data->csd->volume(ALL_SESSION_VSID, volume, |
| 1472 | DEFAULT_VOLUME_RAMP_DURATION_MS); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1473 | if (ret < 0) { |
| 1474 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 1475 | } |
| 1476 | } |
| 1477 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | int platform_set_mic_mute(void *platform, bool state) |
| 1481 | { |
| 1482 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1483 | struct audio_device *adev = my_data->adev; |
| 1484 | struct mixer_ctl *ctl; |
| 1485 | const char *mixer_ctl_name = "Voice Tx Mute"; |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1486 | int ret = 0; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1487 | uint32_t set_values[ ] = {0, |
| 1488 | ALL_SESSION_VSID, |
Vidyakumar Athota | c37f42a | 2014-03-11 11:57:48 -0700 | [diff] [blame] | 1489 | DEFAULT_MUTE_RAMP_DURATION_MS}; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1490 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1491 | set_values[0] = state; |
| 1492 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1493 | if (!ctl) { |
| 1494 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1495 | __func__, mixer_ctl_name); |
| 1496 | return -EINVAL; |
| 1497 | } |
| 1498 | ALOGV("Setting voice mute state: %d", state); |
| 1499 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1500 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1501 | if (my_data->csd != NULL) { |
Vidyakumar Athota | c37f42a | 2014-03-11 11:57:48 -0700 | [diff] [blame] | 1502 | ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state, |
| 1503 | DEFAULT_MUTE_RAMP_DURATION_MS); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1504 | if (ret < 0) { |
| 1505 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | return ret; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Shiv Maliyappanahalli | c6fd8ee | 2014-03-07 15:31:55 -0800 | [diff] [blame] | 1511 | int platform_set_device_mute(void *platform, bool state, char *dir) |
| 1512 | { |
| 1513 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1514 | struct audio_device *adev = my_data->adev; |
| 1515 | struct mixer_ctl *ctl; |
| 1516 | char *mixer_ctl_name = NULL; |
| 1517 | int ret = 0; |
| 1518 | uint32_t set_values[ ] = {0, |
| 1519 | ALL_SESSION_VSID, |
| 1520 | 0}; |
| 1521 | if(dir == NULL) { |
| 1522 | ALOGE("%s: Invalid direction:%s", __func__, dir); |
| 1523 | return -EINVAL; |
| 1524 | } |
| 1525 | |
| 1526 | if (!strncmp("rx", dir, sizeof("rx"))) { |
| 1527 | mixer_ctl_name = "Voice Rx Device Mute"; |
| 1528 | } else if (!strncmp("tx", dir, sizeof("tx"))) { |
| 1529 | mixer_ctl_name = "Voice Tx Device Mute"; |
| 1530 | } else { |
| 1531 | return -EINVAL; |
| 1532 | } |
| 1533 | |
| 1534 | set_values[0] = state; |
| 1535 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1536 | if (!ctl) { |
| 1537 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1538 | __func__, mixer_ctl_name); |
| 1539 | return -EINVAL; |
| 1540 | } |
| 1541 | |
| 1542 | ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s", |
| 1543 | __func__,state, mixer_ctl_name); |
| 1544 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 1545 | |
| 1546 | return ret; |
| 1547 | } |
| 1548 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1549 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 1550 | { |
| 1551 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1552 | struct audio_device *adev = my_data->adev; |
| 1553 | audio_mode_t mode = adev->mode; |
| 1554 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 1555 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1556 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1557 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1558 | int channel_count = popcount(channel_mask); |
| 1559 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1560 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 1561 | if (devices == AUDIO_DEVICE_NONE || |
| 1562 | devices & AUDIO_DEVICE_BIT_IN) { |
| 1563 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 1564 | goto exit; |
| 1565 | } |
| 1566 | |
Mingming Yin | 4a72d65 | 2014-01-03 18:54:18 -0800 | [diff] [blame] | 1567 | if (popcount(devices) == 2) { |
| 1568 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 1569 | AUDIO_DEVICE_OUT_SPEAKER)) { |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 1570 | if (my_data->external_spk_1) |
| 1571 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1; |
| 1572 | else if (my_data->external_spk_2) |
| 1573 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2; |
| 1574 | else |
| 1575 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
Mingming Yin | 4a72d65 | 2014-01-03 18:54:18 -0800 | [diff] [blame] | 1576 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 1577 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1578 | if (audio_extn_get_anc_enabled()) |
| 1579 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET; |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 1580 | else if (my_data->external_spk_1) |
| 1581 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1; |
| 1582 | else if (my_data->external_spk_2) |
| 1583 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2; |
Mingming Yin | 4a72d65 | 2014-01-03 18:54:18 -0800 | [diff] [blame] | 1584 | else |
| 1585 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 1586 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 1587 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1588 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
| 1589 | } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
| 1590 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1591 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET; |
| 1592 | } else { |
| 1593 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 1594 | goto exit; |
| 1595 | } |
| 1596 | if (snd_device != SND_DEVICE_NONE) { |
| 1597 | goto exit; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | if (popcount(devices) != 1) { |
| 1602 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 1603 | goto exit; |
| 1604 | } |
| 1605 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1606 | if ((mode == AUDIO_MODE_IN_CALL) || |
| 1607 | voice_extn_compress_voip_is_active(adev)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1608 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1609 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1610 | if ((adev->voice.tty_mode != TTY_MODE_OFF) && |
| 1611 | !voice_extn_compress_voip_is_active(adev)) { |
| 1612 | switch (adev->voice.tty_mode) { |
| 1613 | case TTY_MODE_FULL: |
| 1614 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
| 1615 | break; |
| 1616 | case TTY_MODE_VCO: |
| 1617 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
| 1618 | break; |
| 1619 | case TTY_MODE_HCO: |
| 1620 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 1621 | break; |
| 1622 | default: |
| 1623 | ALOGE("%s: Invalid TTY mode (%#x)", |
| 1624 | __func__, adev->voice.tty_mode); |
| 1625 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1626 | } else if (audio_extn_get_anc_enabled()) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1627 | if (audio_extn_should_use_fb_anc()) |
| 1628 | snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET; |
| 1629 | else |
| 1630 | snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1631 | } else { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1632 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1633 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1634 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Mingming Yin | 514a8bc | 2014-07-29 15:22:21 -0700 | [diff] [blame] | 1635 | if (adev->bt_wb_speech_enabled) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1636 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1637 | else |
| 1638 | snd_device = SND_DEVICE_OUT_BT_SCO; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1639 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 1640 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1641 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1642 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 1643 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 1644 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 1645 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1646 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Ravi Kumar Alamanda | ceb4082 | 2013-11-06 11:01:47 -0800 | [diff] [blame] | 1647 | if (audio_extn_should_use_handset_anc(channel_count)) |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1648 | snd_device = SND_DEVICE_OUT_ANC_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1649 | else |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 1650 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1651 | } |
| 1652 | if (snd_device != SND_DEVICE_NONE) { |
| 1653 | goto exit; |
| 1654 | } |
| 1655 | } |
| 1656 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1657 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1658 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1659 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET |
| 1660 | && audio_extn_get_anc_enabled()) { |
| 1661 | if (audio_extn_should_use_fb_anc()) |
| 1662 | snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET; |
| 1663 | else |
| 1664 | snd_device = SND_DEVICE_OUT_ANC_HEADSET; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1665 | } else |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1666 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1667 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 1668 | if (my_data->external_spk_1) |
| 1669 | snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1; |
| 1670 | else if (my_data->external_spk_2) |
| 1671 | snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2; |
| 1672 | else if (adev->speaker_lr_swap) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1673 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 1674 | else |
| 1675 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 1676 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
Mingming Yin | 514a8bc | 2014-07-29 15:22:21 -0700 | [diff] [blame] | 1677 | if (adev->bt_wb_speech_enabled) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1678 | snd_device = SND_DEVICE_OUT_BT_SCO_WB; |
| 1679 | else |
| 1680 | snd_device = SND_DEVICE_OUT_BT_SCO; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1681 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1682 | snd_device = SND_DEVICE_OUT_HDMI ; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1683 | } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1684 | devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1685 | ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__); |
| 1686 | audio_extn_set_afe_proxy_channel_mixer(adev, 2); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1687 | snd_device = SND_DEVICE_OUT_USB_HEADSET; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 1688 | } else if (devices & AUDIO_DEVICE_OUT_FM_TX) { |
| 1689 | snd_device = SND_DEVICE_OUT_TRANSMISSION_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1690 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1691 | snd_device = SND_DEVICE_OUT_HANDSET; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1692 | } else if (devices & AUDIO_DEVICE_OUT_PROXY) { |
Mingming Yin | 5a7c5d6 | 2014-03-05 17:45:03 -0800 | [diff] [blame] | 1693 | channel_count = audio_extn_get_afe_proxy_channel_count(); |
| 1694 | ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count); |
| 1695 | audio_extn_set_afe_proxy_channel_mixer(adev, channel_count); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1696 | snd_device = SND_DEVICE_OUT_AFE_PROXY; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1697 | } else { |
| 1698 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 1699 | } |
| 1700 | exit: |
| 1701 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 1702 | return snd_device; |
| 1703 | } |
| 1704 | |
| 1705 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 1706 | { |
| 1707 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1708 | struct audio_device *adev = my_data->adev; |
| 1709 | audio_source_t source = (adev->active_input == NULL) ? |
| 1710 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 1711 | |
| 1712 | audio_mode_t mode = adev->mode; |
| 1713 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 1714 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 1715 | & ~AUDIO_DEVICE_BIT_IN; |
| 1716 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 1717 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 1718 | snd_device_t snd_device = SND_DEVICE_NONE; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1719 | int channel_count = popcount(channel_mask); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1720 | |
| 1721 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
| 1722 | __func__, out_device, in_device); |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 1723 | if (my_data->external_mic) { |
| 1724 | if (((out_device != AUDIO_DEVICE_NONE) && (mode == AUDIO_MODE_IN_CALL)) || |
| 1725 | voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev)) { |
| 1726 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1727 | out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 1728 | out_device & AUDIO_DEVICE_OUT_SPEAKER ) |
| 1729 | snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL; |
| 1730 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 1731 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1732 | snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL; |
| 1733 | } |
| 1734 | } |
| 1735 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1736 | if (snd_device != AUDIO_DEVICE_NONE) |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 1737 | goto exit; |
| 1738 | |
Helen Zeng | 067b96b | 2013-11-26 12:10:29 -0800 | [diff] [blame] | 1739 | if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) || |
Satya Krishna Pindiproli | 071950f | 2014-05-21 14:45:28 +0530 | [diff] [blame] | 1740 | voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1741 | if ((adev->voice.tty_mode != TTY_MODE_OFF) && |
| 1742 | !voice_extn_compress_voip_is_active(adev)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1743 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 1744 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1745 | switch (adev->voice.tty_mode) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1746 | case TTY_MODE_FULL: |
| 1747 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 1748 | break; |
| 1749 | case TTY_MODE_VCO: |
| 1750 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 1751 | break; |
| 1752 | case TTY_MODE_HCO: |
| 1753 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 1754 | break; |
| 1755 | default: |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1756 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1757 | } |
| 1758 | goto exit; |
| 1759 | } |
| 1760 | } |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1761 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1762 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE && |
| 1763 | audio_extn_should_use_handset_anc(channel_count)) { |
| 1764 | snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC; |
Banajit Goswami | de0ea45 | 2014-04-07 12:11:47 -0700 | [diff] [blame] | 1765 | adev->acdb_settings |= ANC_FLAG; |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 1766 | } else if (my_data->fluence_type == FLUENCE_NONE || |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 1767 | my_data->fluence_in_voice_call == false) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1768 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1769 | if (audio_extn_hfp_is_active(adev)) |
| 1770 | platform_set_echo_reference(adev->platform, true); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1771 | } else { |
Ravi Kumar Alamanda | ceb4082 | 2013-11-06 11:01:47 -0800 | [diff] [blame] | 1772 | snd_device = SND_DEVICE_IN_VOICE_DMIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1773 | } |
| 1774 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1775 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1776 | if (audio_extn_hfp_is_active(adev)) |
| 1777 | platform_set_echo_reference(adev->platform, true); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1778 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 1779 | if (adev->bt_wb_speech_enabled) { |
| 1780 | if (adev->bluetooth_nrec) |
| 1781 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 1782 | else |
| 1783 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1784 | } else { |
| 1785 | if (adev->bluetooth_nrec) |
| 1786 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 1787 | else |
| 1788 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1789 | } |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1790 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
| 1791 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 1792 | if (my_data->fluence_type != FLUENCE_NONE && |
| 1793 | my_data->fluence_in_voice_call && |
| 1794 | my_data->fluence_in_spkr_mode) { |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1795 | if(my_data->fluence_type & FLUENCE_QUAD_MIC) { |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 1796 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC; |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1797 | } else { |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 1798 | if (my_data->fluence_mode == FLUENCE_BROADSIDE) |
| 1799 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE; |
| 1800 | else |
| 1801 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC; |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 1802 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1803 | } else { |
| 1804 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1805 | if (audio_extn_hfp_is_active(adev)) |
| 1806 | platform_set_echo_reference(adev->platform, true); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 1810 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 1811 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1812 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 1813 | } |
| 1814 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 1815 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1816 | if (channel_count == 2) { |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1817 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1818 | } else if (adev->active_input->enable_ns) |
| 1819 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS; |
| 1820 | else if (my_data->fluence_type != FLUENCE_NONE && |
| 1821 | my_data->fluence_in_voice_rec) { |
| 1822 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1823 | } else { |
| 1824 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 1825 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1826 | } |
| 1827 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 1828 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 1829 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 1830 | if (adev->active_input) { |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1831 | if (adev->active_input->enable_aec && |
| 1832 | adev->active_input->enable_ns) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1833 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1834 | if (my_data->fluence_type & FLUENCE_DUAL_MIC && |
| 1835 | my_data->fluence_in_spkr_mode) { |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 1836 | if (my_data->fluence_mode == FLUENCE_BROADSIDE) |
| 1837 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE; |
| 1838 | else |
| 1839 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1840 | } else |
| 1841 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1842 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1843 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1844 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1845 | } else |
| 1846 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1847 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1848 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1849 | } |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1850 | platform_set_echo_reference(adev->platform, true); |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1851 | } else if (adev->active_input->enable_aec) { |
| 1852 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 1853 | if (my_data->fluence_type & FLUENCE_DUAL_MIC && |
| 1854 | my_data->fluence_in_spkr_mode) { |
| 1855 | if (my_data->fluence_mode == FLUENCE_BROADSIDE) |
| 1856 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE; |
| 1857 | else |
| 1858 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1859 | } else |
| 1860 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
| 1861 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1862 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1863 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1864 | } else |
| 1865 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
| 1866 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1867 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
| 1868 | } |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1869 | platform_set_echo_reference(adev->platform, true); |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1870 | } else if (adev->active_input->enable_ns) { |
| 1871 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Narsinga Rao Chella | 61e0f9b | 2014-03-06 21:25:22 -0800 | [diff] [blame] | 1872 | if (my_data->fluence_type & FLUENCE_DUAL_MIC && |
| 1873 | my_data->fluence_in_spkr_mode) { |
| 1874 | if (my_data->fluence_mode == FLUENCE_BROADSIDE) |
| 1875 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE; |
| 1876 | else |
| 1877 | snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1878 | } else |
| 1879 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS; |
| 1880 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 1881 | if (my_data->fluence_type & FLUENCE_DUAL_MIC) { |
| 1882 | snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1883 | } else |
| 1884 | snd_device = SND_DEVICE_IN_HANDSET_MIC_NS; |
| 1885 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1886 | snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE; |
| 1887 | } |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1888 | platform_set_echo_reference(adev->platform, false); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1889 | } else |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1890 | platform_set_echo_reference(adev->platform, false); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1891 | } |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1892 | } else if (source == AUDIO_SOURCE_MIC) { |
Apoorv Raghuvanshi | c053654 | 2013-11-14 16:25:59 -0800 | [diff] [blame] | 1893 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC && |
| 1894 | channel_count == 1 ) { |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1895 | if(my_data->fluence_type & FLUENCE_DUAL_MIC && |
Ravi Kumar Alamanda | 7076b16 | 2014-03-07 11:40:24 -0800 | [diff] [blame] | 1896 | my_data->fluence_in_audio_rec) { |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1897 | snd_device = SND_DEVICE_IN_HANDSET_DMIC; |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 1898 | platform_set_echo_reference(adev->platform, true); |
Ravi Kumar Alamanda | 7076b16 | 2014-03-07 11:40:24 -0800 | [diff] [blame] | 1899 | } |
Ravi Kumar Alamanda | b034ddb | 2013-11-06 15:52:18 -0800 | [diff] [blame] | 1900 | } |
Mingming Yin | ab42978 | 2013-11-07 11:16:55 -0800 | [diff] [blame] | 1901 | } else if (source == AUDIO_SOURCE_FM_RX || |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 1902 | source == AUDIO_SOURCE_FM_RX_A2DP) { |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 1903 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1904 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 1905 | goto exit; |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | if (snd_device != SND_DEVICE_NONE) { |
| 1910 | goto exit; |
| 1911 | } |
| 1912 | |
| 1913 | if (in_device != AUDIO_DEVICE_NONE && |
| 1914 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 1915 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 1916 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 1917 | if (audio_extn_ssr_get_enabled() && channel_count == 6) |
| 1918 | snd_device = SND_DEVICE_IN_QUAD_MIC; |
Walter Yang | bc136bd | 2014-01-17 11:24:23 +0800 | [diff] [blame] | 1919 | else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) && |
| 1920 | channel_count == 2) |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 1921 | snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 1922 | else |
| 1923 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1924 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 1925 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 1926 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 1927 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 1928 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 1929 | if (adev->bt_wb_speech_enabled) { |
| 1930 | if (adev->bluetooth_nrec) |
| 1931 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 1932 | else |
| 1933 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1934 | } else { |
| 1935 | if (adev->bluetooth_nrec) |
| 1936 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 1937 | else |
| 1938 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1939 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1940 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 1941 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1942 | } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET || |
| 1943 | in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) { |
| 1944 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 1945 | } else if (in_device & AUDIO_DEVICE_IN_FM_RX) { |
| 1946 | snd_device = SND_DEVICE_IN_CAPTURE_FM; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1947 | } else { |
| 1948 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 1949 | ALOGW("%s: Using default handset-mic", __func__); |
| 1950 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1951 | } |
| 1952 | } else { |
| 1953 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 1954 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1955 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 1956 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 1957 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER || |
| 1958 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 1959 | if (channel_count == 2) |
Apoorv Raghuvanshi | 6bd8dbf | 2013-10-19 18:37:52 -0700 | [diff] [blame] | 1960 | snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC; |
| 1961 | else |
| 1962 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1963 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 1964 | if (adev->bt_wb_speech_enabled) { |
| 1965 | if (adev->bluetooth_nrec) |
| 1966 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC; |
| 1967 | else |
| 1968 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB; |
| 1969 | } else { |
| 1970 | if (adev->bluetooth_nrec) |
| 1971 | snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC; |
| 1972 | else |
| 1973 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 1974 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1975 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1976 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 1977 | } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1978 | out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) { |
| 1979 | snd_device = SND_DEVICE_IN_USB_HEADSET_MIC; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1980 | } else { |
| 1981 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 1982 | ALOGW("%s: Using default handset-mic", __func__); |
| 1983 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 1984 | } |
| 1985 | } |
| 1986 | exit: |
| 1987 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 1988 | return snd_device; |
| 1989 | } |
| 1990 | |
| 1991 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 1992 | { |
| 1993 | struct platform_data *my_data = (struct platform_data *)platform; |
| 1994 | struct audio_device *adev = my_data->adev; |
| 1995 | struct mixer_ctl *ctl; |
| 1996 | const char *channel_cnt_str = NULL; |
| 1997 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 1998 | switch (channel_count) { |
| 1999 | case 8: |
| 2000 | channel_cnt_str = "Eight"; break; |
| 2001 | case 7: |
| 2002 | channel_cnt_str = "Seven"; break; |
| 2003 | case 6: |
| 2004 | channel_cnt_str = "Six"; break; |
| 2005 | case 5: |
| 2006 | channel_cnt_str = "Five"; break; |
| 2007 | case 4: |
| 2008 | channel_cnt_str = "Four"; break; |
| 2009 | case 3: |
| 2010 | channel_cnt_str = "Three"; break; |
| 2011 | default: |
| 2012 | channel_cnt_str = "Two"; break; |
| 2013 | } |
| 2014 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2015 | if (!ctl) { |
| 2016 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2017 | __func__, mixer_ctl_name); |
| 2018 | return -EINVAL; |
| 2019 | } |
| 2020 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 2021 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 2022 | return 0; |
| 2023 | } |
| 2024 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2025 | int platform_edid_get_max_channels(void *platform) |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2026 | { |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2027 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2028 | struct audio_device *adev = my_data->adev; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2029 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 2030 | char *sad = block; |
| 2031 | int num_audio_blocks; |
| 2032 | int channel_count; |
| 2033 | int max_channels = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2034 | int i, ret, count; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2035 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2036 | struct mixer_ctl *ctl; |
| 2037 | |
| 2038 | ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL); |
| 2039 | if (!ctl) { |
| 2040 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2041 | __func__, AUDIO_DATA_BLOCK_MIXER_CTL); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2042 | return 0; |
| 2043 | } |
| 2044 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2045 | mixer_ctl_update(ctl); |
| 2046 | |
| 2047 | count = mixer_ctl_get_num_values(ctl); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2048 | |
| 2049 | /* Read SAD blocks, clamping the maximum size for safety */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2050 | if (count > (int)sizeof(block)) |
| 2051 | count = (int)sizeof(block); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2052 | |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2053 | ret = mixer_ctl_get_array(ctl, block, count); |
| 2054 | if (ret != 0) { |
| 2055 | ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__); |
| 2056 | return 0; |
| 2057 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2058 | |
| 2059 | /* Calculate the number of SAD blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2060 | num_audio_blocks = count / SAD_BLOCK_SIZE; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2061 | |
| 2062 | for (i = 0; i < num_audio_blocks; i++) { |
| 2063 | /* Only consider LPCM blocks */ |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2064 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) { |
| 2065 | sad += 3; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2066 | continue; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2067 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2068 | |
| 2069 | channel_count = (sad[0] & 0x7) + 1; |
| 2070 | if (channel_count > max_channels) |
| 2071 | max_channels = channel_count; |
| 2072 | |
| 2073 | /* Advance to next block */ |
| 2074 | sad += 3; |
| 2075 | } |
| 2076 | |
| 2077 | return max_channels; |
| 2078 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2079 | |
| 2080 | static int platform_set_slowtalk(struct platform_data *my_data, bool state) |
| 2081 | { |
| 2082 | int ret = 0; |
| 2083 | struct audio_device *adev = my_data->adev; |
| 2084 | struct mixer_ctl *ctl; |
| 2085 | const char *mixer_ctl_name = "Slowtalk Enable"; |
| 2086 | uint32_t set_values[ ] = {0, |
| 2087 | ALL_SESSION_VSID}; |
| 2088 | |
| 2089 | set_values[0] = state; |
| 2090 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2091 | if (!ctl) { |
| 2092 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2093 | __func__, mixer_ctl_name); |
| 2094 | ret = -EINVAL; |
| 2095 | } else { |
| 2096 | ALOGV("Setting slowtalk state: %d", state); |
| 2097 | ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 2098 | my_data->slowtalk = state; |
| 2099 | } |
| 2100 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 2101 | if (my_data->csd != NULL) { |
| 2102 | ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state); |
| 2103 | if (ret < 0) { |
| 2104 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 2105 | __func__, ret); |
| 2106 | } |
| 2107 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2108 | return ret; |
| 2109 | } |
| 2110 | |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 2111 | static int set_hd_voice(struct platform_data *my_data, bool state) |
| 2112 | { |
| 2113 | struct audio_device *adev = my_data->adev; |
| 2114 | struct mixer_ctl *ctl; |
| 2115 | char *mixer_ctl_name = "HD Voice Enable"; |
| 2116 | int ret = 0; |
| 2117 | uint32_t set_values[ ] = {0, |
| 2118 | ALL_SESSION_VSID}; |
| 2119 | |
| 2120 | set_values[0] = state; |
| 2121 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2122 | if (!ctl) { |
| 2123 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2124 | __func__, mixer_ctl_name); |
| 2125 | return -EINVAL; |
| 2126 | } else { |
| 2127 | ALOGV("Setting HD Voice state: %d", state); |
| 2128 | ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 2129 | my_data->hd_voice = state; |
| 2130 | } |
| 2131 | |
| 2132 | return ret; |
| 2133 | } |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 2134 | |
| 2135 | static int update_external_device_status(struct platform_data *my_data, |
| 2136 | char* event_name, bool status) |
| 2137 | { |
| 2138 | int ret = 0; |
| 2139 | struct audio_usecase *usecase; |
| 2140 | struct listnode *node; |
| 2141 | |
| 2142 | ALOGD("Recieved external event switch %s", event_name); |
| 2143 | |
| 2144 | if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1)) |
| 2145 | my_data->external_spk_1 = status; |
| 2146 | else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2)) |
| 2147 | my_data->external_spk_2 = status; |
| 2148 | else if (!strcmp(event_name, EVENT_EXTERNAL_MIC)) |
| 2149 | my_data->external_mic = status; |
| 2150 | else { |
| 2151 | ALOGE("The audio event type is not found"); |
| 2152 | return -EINVAL; |
| 2153 | } |
| 2154 | |
| 2155 | list_for_each(node, &my_data->adev->usecase_list) { |
| 2156 | usecase = node_to_item(node, struct audio_usecase, list); |
| 2157 | select_devices(my_data->adev, usecase->id); |
| 2158 | } |
| 2159 | |
| 2160 | return ret; |
| 2161 | } |
| 2162 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2163 | int platform_set_parameters(void *platform, struct str_parms *parms) |
| 2164 | { |
| 2165 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2166 | char *str; |
Vidyakumar Athota | 3ade279 | 2013-12-02 11:02:20 -0800 | [diff] [blame] | 2167 | char value[256] = {0}; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2168 | int val; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2169 | int ret = 0, err; |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 2170 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2171 | |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 2172 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2173 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2174 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value)); |
| 2175 | if (err >= 0) { |
Vidyakumar Athota | 3ade279 | 2013-12-02 11:02:20 -0800 | [diff] [blame] | 2176 | bool state = false; |
| 2177 | if (!strncmp("true", value, sizeof("true"))) { |
| 2178 | state = true; |
| 2179 | } |
| 2180 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2181 | str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK); |
Vidyakumar Athota | 3ade279 | 2013-12-02 11:02:20 -0800 | [diff] [blame] | 2182 | ret = platform_set_slowtalk(my_data, state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2183 | if (ret) |
| 2184 | ALOGE("%s: Failed to set slow talk err: %d", __func__, ret); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 2187 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value)); |
| 2188 | if (err >= 0) { |
| 2189 | bool state = false; |
| 2190 | if (!strncmp("true", value, sizeof("true"))) { |
| 2191 | state = true; |
| 2192 | } |
| 2193 | |
| 2194 | str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE); |
| 2195 | if (my_data->hd_voice != state) { |
| 2196 | ret = set_hd_voice(my_data, state); |
| 2197 | if (ret) |
| 2198 | ALOGE("%s: Failed to set HD voice err: %d", __func__, ret); |
| 2199 | } else { |
| 2200 | ALOGV("%s: HD Voice already set to %d", __func__, state); |
| 2201 | } |
| 2202 | } |
| 2203 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2204 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST, |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 2205 | value, sizeof(value)); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2206 | if (err >= 0) { |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 2207 | str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST); |
| 2208 | |
| 2209 | if (my_data->acdb_reload_vocvoltable == NULL) { |
| 2210 | ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__); |
| 2211 | } else if (!strcmp(value, "on")) { |
| 2212 | if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) { |
| 2213 | my_data->voice_feature_set = 1; |
| 2214 | } |
| 2215 | } else { |
| 2216 | if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) { |
| 2217 | my_data->voice_feature_set = 0; |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 2222 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE, |
| 2223 | value, sizeof(value)); |
| 2224 | if (err >= 0) { |
| 2225 | char *event_name, *status_str; |
| 2226 | bool status = false; |
| 2227 | str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE); |
| 2228 | event_name = strtok_r(value, ",", &status_str); |
| 2229 | ALOGV("%s: recieved update of external audio device %s %s", |
| 2230 | __func__, |
| 2231 | event_name, status_str); |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2232 | if (!strncmp(status_str, "ON", sizeof("ON"))) |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 2233 | status = true; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2234 | else if (!strncmp(status_str, "OFF", sizeof("OFF"))) |
Tanya Finkel | 0013005 | 2014-07-14 04:26:56 -0700 | [diff] [blame] | 2235 | status = false; |
| 2236 | update_external_device_status(my_data, event_name, status); |
| 2237 | } |
| 2238 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2239 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 2240 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2241 | return ret; |
| 2242 | } |
| 2243 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 2244 | int platform_set_incall_recording_session_id(void *platform, |
| 2245 | uint32_t session_id, int rec_mode) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 2246 | { |
| 2247 | int ret = 0; |
| 2248 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2249 | struct audio_device *adev = my_data->adev; |
| 2250 | struct mixer_ctl *ctl; |
| 2251 | const char *mixer_ctl_name = "Voc VSID"; |
| 2252 | int num_ctl_values; |
| 2253 | int i; |
| 2254 | |
| 2255 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2256 | if (!ctl) { |
| 2257 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2258 | __func__, mixer_ctl_name); |
| 2259 | ret = -EINVAL; |
| 2260 | } else { |
| 2261 | num_ctl_values = mixer_ctl_get_num_values(ctl); |
| 2262 | for (i = 0; i < num_ctl_values; i++) { |
| 2263 | if (mixer_ctl_set_value(ctl, i, session_id)) { |
| 2264 | ALOGV("Error: invalid session_id: %x", session_id); |
| 2265 | ret = -EINVAL; |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 2271 | if (my_data->csd != NULL) { |
| 2272 | ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode); |
| 2273 | if (ret < 0) { |
| 2274 | ALOGE("%s: csd_client_start_record failed, error %d", |
| 2275 | __func__, ret); |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | return ret; |
| 2280 | } |
| 2281 | |
| 2282 | int platform_stop_incall_recording_usecase(void *platform) |
| 2283 | { |
| 2284 | int ret = 0; |
| 2285 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2286 | |
| 2287 | if (my_data->csd != NULL) { |
| 2288 | ret = my_data->csd->stop_record(ALL_SESSION_VSID); |
| 2289 | if (ret < 0) { |
| 2290 | ALOGE("%s: csd_client_stop_record failed, error %d", |
| 2291 | __func__, ret); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | return ret; |
| 2296 | } |
| 2297 | |
| 2298 | int platform_start_incall_music_usecase(void *platform) |
| 2299 | { |
| 2300 | int ret = 0; |
| 2301 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2302 | |
| 2303 | if (my_data->csd != NULL) { |
| 2304 | ret = my_data->csd->start_playback(ALL_SESSION_VSID); |
| 2305 | if (ret < 0) { |
| 2306 | ALOGE("%s: csd_client_start_playback failed, error %d", |
| 2307 | __func__, ret); |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | return ret; |
| 2312 | } |
| 2313 | |
| 2314 | int platform_stop_incall_music_usecase(void *platform) |
| 2315 | { |
| 2316 | int ret = 0; |
| 2317 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2318 | |
| 2319 | if (my_data->csd != NULL) { |
| 2320 | ret = my_data->csd->stop_playback(ALL_SESSION_VSID); |
| 2321 | if (ret < 0) { |
| 2322 | ALOGE("%s: csd_client_stop_playback failed, error %d", |
| 2323 | __func__, ret); |
| 2324 | } |
| 2325 | } |
| 2326 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 2327 | return ret; |
| 2328 | } |
| 2329 | |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 2330 | int platform_update_lch(void *platform, struct voice_session *session, |
| 2331 | enum voice_lch_mode lch_mode) |
| 2332 | { |
| 2333 | int ret = 0; |
| 2334 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2335 | |
| 2336 | if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL)) |
| 2337 | ret = my_data->csd->set_lch(session->vsid, lch_mode); |
| 2338 | else |
| 2339 | ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode); |
| 2340 | |
| 2341 | return ret; |
| 2342 | } |
| 2343 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2344 | void platform_get_parameters(void *platform, |
| 2345 | struct str_parms *query, |
| 2346 | struct str_parms *reply) |
| 2347 | { |
| 2348 | struct platform_data *my_data = (struct platform_data *)platform; |
| 2349 | char *str = NULL; |
| 2350 | char value[256] = {0}; |
| 2351 | int ret; |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 2352 | char *kv_pairs = NULL; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2353 | |
Shiv Maliyappanahalli | 9d89929 | 2013-11-20 14:43:01 -0800 | [diff] [blame] | 2354 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK, |
| 2355 | value, sizeof(value)); |
| 2356 | if (ret >= 0) { |
Vidyakumar Athota | 3ade279 | 2013-12-02 11:02:20 -0800 | [diff] [blame] | 2357 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK, |
| 2358 | my_data->slowtalk?"true":"false"); |
Shiv Maliyappanahalli | 9d89929 | 2013-11-20 14:43:01 -0800 | [diff] [blame] | 2359 | } |
| 2360 | |
Avinash Vaish | d5fa457 | 2014-09-15 14:41:14 +0530 | [diff] [blame] | 2361 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE, |
| 2362 | value, sizeof(value)); |
| 2363 | if (ret >= 0) { |
| 2364 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE, |
| 2365 | my_data->hd_voice?"true":"false"); |
| 2366 | } |
| 2367 | |
Ben Romberger | c1dc70d | 2013-12-19 15:11:17 -0800 | [diff] [blame] | 2368 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST, |
| 2369 | value, sizeof(value)); |
| 2370 | if (ret >= 0) { |
| 2371 | if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) { |
| 2372 | strlcpy(value, "on", sizeof(value)); |
| 2373 | } else { |
| 2374 | strlcpy(value, "off", sizeof(value)); |
| 2375 | } |
| 2376 | |
| 2377 | str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value); |
| 2378 | } |
| 2379 | |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 2380 | kv_pairs = str_parms_to_str(reply); |
| 2381 | ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs); |
Narsinga Rao Chella | cde45d1 | 2014-02-13 11:44:31 -0800 | [diff] [blame] | 2382 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2385 | /* Delay in Us */ |
| 2386 | int64_t platform_render_latency(audio_usecase_t usecase) |
| 2387 | { |
| 2388 | switch (usecase) { |
| 2389 | case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER: |
| 2390 | return DEEP_BUFFER_PLATFORM_DELAY; |
| 2391 | case USECASE_AUDIO_PLAYBACK_LOW_LATENCY: |
| 2392 | return LOW_LATENCY_PLATFORM_DELAY; |
| 2393 | default: |
| 2394 | return 0; |
| 2395 | } |
| 2396 | } |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 2397 | |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 2398 | int platform_update_usecase_from_source(int source, int usecase) |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 2399 | { |
Mingming Yin | ab42978 | 2013-11-07 11:16:55 -0800 | [diff] [blame] | 2400 | ALOGV("%s: input source :%d", __func__, source); |
| 2401 | if(source == AUDIO_SOURCE_FM_RX_A2DP) |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 2402 | usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL; |
| 2403 | return usecase; |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 2404 | } |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 2405 | |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 2406 | bool platform_listen_device_needs_event(snd_device_t snd_device) |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 2407 | { |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 2408 | bool needs_event = false; |
| 2409 | |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 2410 | if ((snd_device >= SND_DEVICE_IN_BEGIN) && |
| 2411 | (snd_device < SND_DEVICE_IN_END) && |
| 2412 | (snd_device != SND_DEVICE_IN_CAPTURE_FM) && |
| 2413 | (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)) |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 2414 | needs_event = true; |
| 2415 | |
| 2416 | return needs_event; |
| 2417 | } |
| 2418 | |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 2419 | bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused) |
| 2420 | { |
| 2421 | return false; |
| 2422 | } |
| 2423 | |
| 2424 | bool platform_sound_trigger_device_needs_event(snd_device_t snd_device) |
| 2425 | { |
| 2426 | bool needs_event = false; |
| 2427 | |
| 2428 | if ((snd_device >= SND_DEVICE_IN_BEGIN) && |
| 2429 | (snd_device < SND_DEVICE_IN_END) && |
| 2430 | (snd_device != SND_DEVICE_IN_CAPTURE_FM) && |
| 2431 | (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)) |
| 2432 | needs_event = true; |
| 2433 | |
| 2434 | return needs_event; |
| 2435 | } |
| 2436 | |
| 2437 | bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused) |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 2438 | { |
| 2439 | return false; |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 2440 | } |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2441 | |
| 2442 | /* Read offload buffer size from a property. |
| 2443 | * If value is not power of 2 round it to |
| 2444 | * power of 2. |
| 2445 | */ |
| 2446 | uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info) |
| 2447 | { |
| 2448 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 2449 | uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 2450 | if((property_get("audio.offload.buffer.size.kb", value, "")) && |
| 2451 | atoi(value)) { |
| 2452 | fragment_size = atoi(value) * 1024; |
| 2453 | } |
| 2454 | |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2455 | // For FLAC use max size since it is loss less, and has sampling rates |
| 2456 | // upto 192kHZ |
| 2457 | if (info != NULL && !info->has_video && |
| 2458 | info->format == AUDIO_FORMAT_FLAC) { |
| 2459 | fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 2460 | ALOGV("FLAC fragment size %d", fragment_size); |
| 2461 | } |
| 2462 | |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2463 | if (info != NULL && info->has_video && info->is_streaming) { |
| 2464 | fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING; |
| 2465 | ALOGV("%s: offload fragment size reduced for AV streaming to %d", |
ApurupaPattapu | 31d09d7 | 2014-03-05 11:13:32 -0800 | [diff] [blame] | 2466 | __func__, fragment_size); |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | fragment_size = ALIGN( fragment_size, 1024); |
| 2470 | |
| 2471 | if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE) |
| 2472 | fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 2473 | else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE) |
| 2474 | fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 2475 | ALOGV("%s: fragment_size %d", __func__, fragment_size); |
| 2476 | return fragment_size; |
| 2477 | } |
| 2478 | |
| 2479 | uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info) |
| 2480 | { |
| 2481 | uint32_t fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 2482 | uint32_t bits_per_sample = 16; |
| 2483 | |
| 2484 | if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) { |
| 2485 | bits_per_sample = 32; |
| 2486 | } |
| 2487 | |
| 2488 | if (!info->has_video) { |
| 2489 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 2490 | |
| 2491 | } else if (info->has_video && info->is_streaming) { |
| 2492 | fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING |
| 2493 | * info->sample_rate |
ApurupaPattapu | b57da78 | 2014-04-08 10:41:07 -0700 | [diff] [blame] | 2494 | * (bits_per_sample >> 3) |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2495 | * popcount(info->channel_mask))/1000; |
| 2496 | |
| 2497 | } else if (info->has_video) { |
| 2498 | fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV |
| 2499 | * info->sample_rate |
ApurupaPattapu | b57da78 | 2014-04-08 10:41:07 -0700 | [diff] [blame] | 2500 | * (bits_per_sample >> 3) |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2501 | * popcount(info->channel_mask))/1000; |
| 2502 | } |
| 2503 | |
ApurupaPattapu | b57da78 | 2014-04-08 10:41:07 -0700 | [diff] [blame] | 2504 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 2505 | if((property_get("audio.offload.pcm.buffer.size", value, "")) && |
| 2506 | atoi(value)) { |
| 2507 | fragment_size = atoi(value) * 1024; |
| 2508 | ALOGV("Using buffer size from sys prop %d", fragment_size); |
| 2509 | } |
| 2510 | |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2511 | fragment_size = ALIGN( fragment_size, 1024); |
| 2512 | |
| 2513 | if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 2514 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 2515 | else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 2516 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 2517 | |
| 2518 | ALOGV("%s: fragment_size %d", __func__, fragment_size); |
| 2519 | return fragment_size; |
| 2520 | } |
| 2521 | |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2522 | bool platform_check_24_bit_support() { |
| 2523 | |
| 2524 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 2525 | property_get("audio.offload.24bit.enable", value, "0"); |
| 2526 | if (atoi(value)) { |
| 2527 | ALOGW("Property audio.offload.24bit.enable is set"); |
| 2528 | return true; |
| 2529 | } |
| 2530 | return false; |
| 2531 | } |
| 2532 | |
| 2533 | int platform_set_codec_backend_cfg(struct audio_device* adev, |
| 2534 | unsigned int bit_width, unsigned int sample_rate) |
| 2535 | { |
Amit Shekhar | ed7fb5c | 2014-08-01 17:18:53 -0700 | [diff] [blame] | 2536 | ALOGV("%s bit width: %d, sample rate: %d", __func__, bit_width, sample_rate); |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2537 | |
| 2538 | int ret = 0; |
| 2539 | if (bit_width != adev->cur_codec_backend_bit_width) { |
| 2540 | const char * mixer_ctl_name = "SLIM_0_RX Format"; |
| 2541 | struct mixer_ctl *ctl; |
| 2542 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2543 | if (!ctl) { |
| 2544 | ALOGE("%s: Could not get ctl for mixer command - %s", |
| 2545 | __func__, mixer_ctl_name); |
| 2546 | return -EINVAL; |
| 2547 | } |
| 2548 | |
| 2549 | if (bit_width == 24) { |
| 2550 | mixer_ctl_set_enum_by_string(ctl, "S24_LE"); |
| 2551 | } else { |
| 2552 | mixer_ctl_set_enum_by_string(ctl, "S16_LE"); |
| 2553 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 2554 | } |
| 2555 | adev->cur_codec_backend_bit_width = bit_width; |
| 2556 | ALOGE("Backend bit width is set to %d ", bit_width); |
| 2557 | } |
| 2558 | |
Amit Shekhar | ed7fb5c | 2014-08-01 17:18:53 -0700 | [diff] [blame] | 2559 | /* |
| 2560 | * Backend sample rate configuration follows: |
| 2561 | * 16 bit playback - 48khz for streams at any valid sample rate |
| 2562 | * 24 bit playback - 48khz for stream sample rate less than 48khz |
| 2563 | * 24 bit playback - 96khz for sample rate range of 48khz to 96khz |
| 2564 | * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz |
| 2565 | * Upper limit is inclusive in the sample rate range. |
| 2566 | */ |
| 2567 | // TODO: This has to be more dynamic based on policy file |
| 2568 | if (sample_rate != adev->cur_codec_backend_samplerate) { |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2569 | char *rate_str = NULL; |
| 2570 | const char * mixer_ctl_name = "SLIM_0_RX SampleRate"; |
| 2571 | struct mixer_ctl *ctl; |
| 2572 | |
| 2573 | switch (sample_rate) { |
| 2574 | case 8000: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2575 | case 11025: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2576 | case 16000: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2577 | case 22050: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2578 | case 32000: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2579 | case 44100: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2580 | case 48000: |
| 2581 | rate_str = "KHZ_48"; |
| 2582 | break; |
| 2583 | case 64000: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2584 | case 88200: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2585 | case 96000: |
| 2586 | rate_str = "KHZ_96"; |
| 2587 | break; |
| 2588 | case 176400: |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2589 | case 192000: |
| 2590 | rate_str = "KHZ_192"; |
| 2591 | break; |
| 2592 | default: |
| 2593 | rate_str = "KHZ_48"; |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2598 | if(!ctl) { |
| 2599 | ALOGE("%s: Could not get ctl for mixer command - %s", |
| 2600 | __func__, mixer_ctl_name); |
| 2601 | return -EINVAL; |
| 2602 | } |
| 2603 | |
| 2604 | ALOGV("Set sample rate as rate_str = %s", rate_str); |
| 2605 | mixer_ctl_set_enum_by_string(ctl, rate_str); |
| 2606 | adev->cur_codec_backend_samplerate = sample_rate; |
| 2607 | } |
| 2608 | |
| 2609 | return ret; |
| 2610 | } |
| 2611 | |
| 2612 | bool platform_check_codec_backend_cfg(struct audio_device* adev, |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2613 | struct audio_usecase* usecase __unused, |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2614 | unsigned int* new_bit_width, |
| 2615 | unsigned int* new_sample_rate) |
| 2616 | { |
| 2617 | bool backend_change = false; |
| 2618 | struct listnode *node; |
| 2619 | struct stream_out *out = NULL; |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2620 | unsigned int bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 2621 | unsigned int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2622 | |
| 2623 | // For voice calls use default configuration |
| 2624 | // force routing is not required here, caller will do it anyway |
| 2625 | if (adev->mode == AUDIO_MODE_IN_CALL || |
| 2626 | adev->mode == AUDIO_MODE_IN_COMMUNICATION) { |
| 2627 | ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__); |
| 2628 | *new_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 2629 | *new_sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 2630 | backend_change = true; |
| 2631 | } |
| 2632 | |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2633 | /* |
| 2634 | * The backend should be configured at highest bit width and/or |
| 2635 | * sample rate amongst all playback usecases. |
| 2636 | * If the selected sample rate and/or bit width differ with |
| 2637 | * current backend sample rate and/or bit width, then, we set the |
| 2638 | * backend re-configuration flag. |
| 2639 | * |
| 2640 | * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only |
| 2641 | */ |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2642 | if (!backend_change) { |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2643 | list_for_each(node, &adev->usecase_list) { |
| 2644 | struct audio_usecase *curr_usecase; |
| 2645 | curr_usecase = node_to_item(node, struct audio_usecase, list); |
Amit Shekhar | ed7fb5c | 2014-08-01 17:18:53 -0700 | [diff] [blame] | 2646 | if (curr_usecase->type == PCM_PLAYBACK) { |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2647 | struct stream_out *out = |
| 2648 | (struct stream_out*) curr_usecase->stream.out; |
| 2649 | if (out != NULL ) { |
| 2650 | ALOGV("Offload playback running bw %d sr %d", |
| 2651 | out->bit_width, out->sample_rate); |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2652 | if (bit_width < out->bit_width) |
| 2653 | bit_width = out->bit_width; |
| 2654 | if (sample_rate < out->sample_rate) |
| 2655 | sample_rate = out->sample_rate; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2656 | } |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2661 | // 16 bit playbacks is allowed through 16 bit/48 khz backend only |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 2662 | if ((16 == bit_width) || |
| 2663 | ((24 == bit_width) && (SND_DEVICE_OUT_SPEAKER == usecase->devices))) { |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2664 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 2665 | } |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2666 | // Force routing if the expected bitwdith or samplerate |
| 2667 | // is not same as current backend comfiguration |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2668 | if ((bit_width != adev->cur_codec_backend_bit_width) || |
| 2669 | (sample_rate != adev->cur_codec_backend_samplerate)) { |
| 2670 | *new_bit_width = bit_width; |
| 2671 | *new_sample_rate = sample_rate; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2672 | backend_change = true; |
Amit Shekhar | 278e336 | 2014-09-08 14:08:19 -0700 | [diff] [blame] | 2673 | ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d", |
| 2674 | __func__, *new_bit_width, *new_sample_rate); |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | return backend_change; |
| 2678 | } |
| 2679 | |
| 2680 | bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev, struct audio_usecase *usecase) |
| 2681 | { |
| 2682 | // check if 24bit configuration is enabled first |
| 2683 | if (!platform_check_24_bit_support()) { |
| 2684 | ALOGW("24bit not enable, no need to check for backend change"); |
| 2685 | return false; |
| 2686 | } |
| 2687 | |
| 2688 | ALOGV("platform_check_and_set_codec_backend_cfg usecase = %d",usecase->id ); |
| 2689 | |
| 2690 | unsigned int new_bit_width, old_bit_width; |
| 2691 | unsigned int new_sample_rate, old_sample_rate; |
| 2692 | |
| 2693 | new_bit_width = old_bit_width = adev->cur_codec_backend_bit_width; |
| 2694 | new_sample_rate = old_sample_rate = adev->cur_codec_backend_samplerate; |
| 2695 | |
| 2696 | ALOGW("Codec backend bitwidth %d, samplerate %d", old_bit_width, old_sample_rate); |
| 2697 | if (platform_check_codec_backend_cfg(adev, usecase, |
| 2698 | &new_bit_width, &new_sample_rate)) { |
| 2699 | platform_set_codec_backend_cfg(adev, new_bit_width, new_sample_rate); |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 2700 | return true; |
| 2701 | } |
| 2702 | |
| 2703 | return false; |
| 2704 | } |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 2705 | |
| 2706 | int platform_set_snd_device_backend(snd_device_t device, const char *backend) |
| 2707 | { |
| 2708 | int ret = 0; |
| 2709 | |
| 2710 | if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { |
| 2711 | ALOGE("%s: Invalid snd_device = %d", |
| 2712 | __func__, device); |
| 2713 | ret = -EINVAL; |
| 2714 | goto done; |
| 2715 | } |
| 2716 | |
| 2717 | if (backend_table[device]) { |
| 2718 | free(backend_table[device]); |
| 2719 | } |
| 2720 | backend_table[device] = strdup(backend); |
| 2721 | done: |
| 2722 | return ret; |
| 2723 | } |
| 2724 | |
| 2725 | int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id) |
| 2726 | { |
| 2727 | int ret = 0; |
| 2728 | if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) { |
| 2729 | ALOGE("%s: invalid usecase case idx %d", __func__, usecase); |
| 2730 | ret = -EINVAL; |
| 2731 | goto done; |
| 2732 | } |
| 2733 | |
| 2734 | if ((type != 0) && (type != 1)) { |
| 2735 | ALOGE("%s: invalid usecase type", __func__); |
| 2736 | ret = -EINVAL; |
| 2737 | } |
| 2738 | pcm_device_table[usecase][type] = pcm_id; |
| 2739 | done: |
| 2740 | return ret; |
| 2741 | } |