blob: 0c4b8d34884ae8bd978fb9c9cdc3904fa7bda988 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Pallavi Mishra5627c162020-02-15 19:00:40 +05302 * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07003 * Not a Contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07006 *
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"
Ashish Jain3e37a702016-11-25 12:27:15 +053021//#define LOG_NDEBUG 0
Eric Laurentb23d5282013-05-14 15:27:20 -070022#define LOG_NDDEBUG 0
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070023/*#define VERY_VERY_VERBOSE_LOGGING*/
24#ifdef VERY_VERY_VERBOSE_LOGGING
25#define ALOGVV ALOGV
26#else
27#define ALOGVV(a...) do { } while(0)
28#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070029
30#include <stdlib.h>
31#include <dlfcn.h>
Anish Kumar55e6df22014-08-26 17:38:05 -070032#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070033#include <sys/ioctl.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080034#include <log/log.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070035#include <cutils/properties.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070036#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070037#include <audio_hw.h>
38#include <platform_api.h>
Aalique Grahame22e49102018-12-18 14:23:57 -080039#include <pthread.h>
Vinay Vermaaddfa4a2018-04-29 14:03:38 +053040#include <unistd.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070041#include "platform.h"
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070042#include "audio_extn.h"
Vignesh Kulothungan55396882017-04-20 14:37:02 -070043#include "acdb.h"
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080044#include "voice_extn.h"
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070045#include "edid.h"
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080046#include "sound/compress_params.h"
Anish Kumar55e6df22014-08-26 17:38:05 -070047#include "sound/msmcal-hwdep.h"
Sujin Panickerb904fbe2019-04-04 13:28:07 +053048#include <dirent.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070049
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053050#ifdef DYNAMIC_LOG_ENABLED
51#include <log_xml_parser.h>
52#define LOG_MASK HAL_MOD_FILE_PLATFORM
53#include <log_utils.h>
54#endif
55
Anish Kumar55e6df22014-08-26 17:38:05 -070056#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -070057#define MIXER_FILE_DELIMITER "_"
58#define MIXER_FILE_EXT ".xml"
59
Aalique Grahame22e49102018-12-18 14:23:57 -080060#define MIXER_XML_BASE_STRING "mixer_paths"
61#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
62
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080063#ifdef LINUX_ENABLED
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +053064#define PLATFORM_INFO_XML_PATH_INTCODEC "/etc/audio_platform_info_intcodec.xml"
65#define PLATFORM_INFO_XML_PATH_SKUSH "/etc/audio_platform_info_skush.xml"
Walter Yang319c6fe2017-09-21 17:09:39 +080066#define PLATFORM_INFO_XML_PATH_SKUW "/etc/audio_platform_info_skuw.xml"
kunleiz291f3412018-09-04 16:04:44 +080067#define PLATFORM_INFO_XML_PATH_QRD "/etc/audio_platform_info_qrd.xml"
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080068#define PLATFORM_INFO_XML_PATH "/etc/audio_platform_info.xml"
69#define MIXER_XML_PATH_AUXPCM "/etc/mixer_paths_auxpcm.xml"
70#define MIXER_XML_PATH_I2S "/etc/mixer_paths_i2s.xml"
Josh Kirschf6932f72017-12-12 11:31:01 -080071#define PLATFORM_INFO_XML_PATH_I2S "/etc/audio_platform_info_extcodec.xml"
Ramu Gottipati54ed9482018-08-21 16:00:22 +053072#define PLATFORM_INFO_XML_PATH_WSA "/etc/audio_platform_info_wsa.xml"
Dhananjay Kumarb34c5c12018-09-25 16:04:26 +053073#define PLATFORM_INFO_XML_PATH_TDM "/etc/audio_platform_info_tdm.xml"
Anurag Chouhand9867322020-03-09 13:26:25 +053074#define PLATFORM_INFO_XML_PATH_PCIE "/etc/audio_platform_info_pcie.xml"
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080075#else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +053076#define PLATFORM_INFO_XML_PATH_INTCODEC "/vendor/etc/audio_platform_info_intcodec.xml"
77#define PLATFORM_INFO_XML_PATH_SKUSH "/vendor/etc/audio_platform_info_skush.xml"
Walter Yang319c6fe2017-09-21 17:09:39 +080078#define PLATFORM_INFO_XML_PATH_SKUW "/vendor/etc/audio_platform_info_skuw.xml"
kunleiz291f3412018-09-04 16:04:44 +080079#define PLATFORM_INFO_XML_PATH_QRD "/vendor/etc/audio_platform_info_qrd.xml"
Naresh Tanniru10758b62017-06-05 21:05:53 +053080#define PLATFORM_INFO_XML_PATH "/vendor/etc/audio_platform_info.xml"
81#define MIXER_XML_PATH_AUXPCM "/vendor/etc/mixer_paths_auxpcm.xml"
82#define MIXER_XML_PATH_I2S "/vendor/etc/mixer_paths_i2s.xml"
83#define PLATFORM_INFO_XML_PATH_I2S "/vendor/etc/audio_platform_info_i2s.xml"
Ramu Gottipati54ed9482018-08-21 16:00:22 +053084#define PLATFORM_INFO_XML_PATH_WSA "/vendor/etc/audio_platform_info_wsa.xml"
Dhananjay Kumarb34c5c12018-09-25 16:04:26 +053085#define PLATFORM_INFO_XML_PATH_TDM "/vendor/etc/audio_platform_info_tdm.xml"
Anurag Chouhand9867322020-03-09 13:26:25 +053086#define PLATFORM_INFO_XML_PATH_PCIE "/vendor/etc/audio_platform_info_pcie.xml"
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080087#endif
Helen Zeng6a16ad72014-02-23 22:04:44 -080088
vivek mehtaa76401a2015-04-24 14:12:15 -070089#include <linux/msm_audio.h>
Meng Wangef2f6e12018-10-08 13:06:05 +080090#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || \
91 defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \
92 defined (PLATFORM_KONA) || defined (PLATFORM_MSMSTEPPE) || \
Manisha Agarwal888e9762019-02-27 22:18:49 +053093 defined (PLATFORM_QCS405) || defined (PLATFORM_TRINKET) || \
Manisha Agarwal13c65ae2019-05-16 10:48:28 +080094 defined (PLATFORM_LITO) || defined (PLATFORM_MSMFALCON) || \
95 defined (PLATFORM_ATOLL)
96
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070097#include <sound/devdep_params.h>
98#endif
Helen Zeng6a16ad72014-02-23 22:04:44 -080099
Aalique Grahame22e49102018-12-18 14:23:57 -0800100#include <resolv.h>
101
Vignesh Kulothungane4039c12019-05-07 15:51:39 -0700102#define QTIME_FREQ_KHZ 19200
103#define IPC_ERROR_DELAY 10000
104
105#define max(a, b) ((a) > (b) ? (a) : (b))
Aalique Grahame22e49102018-12-18 14:23:57 -0800106#define min(a, b) ((a) < (b) ? (a) : (b))
107
108#define TOSTRING_(x) #x
109#define TOSTRING(x) TOSTRING_(x)
110
Eric Laurentb23d5282013-05-14 15:27:20 -0700111#define LIB_ACDB_LOADER "libacdbloader.so"
Walter Yang6f800052014-07-14 16:15:38 -0700112#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -0700113
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +0530114#define FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
115#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024 * 1024)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -0800116#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
117#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
118#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
119
Vikram Panduranga7e784962016-10-27 12:32:30 -0700120
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700121/*
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 * This file will have a maximum of 38 bytes:
123 *
124 * 4 bytes: number of audio blocks
125 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
126 * Maximum 10 * 3 bytes: SAD blocks
127 */
128#define MAX_SAD_BLOCKS 10
129#define SAD_BLOCK_SIZE 3
130
Walter Yang6f800052014-07-14 16:15:38 -0700131#define MAX_CVD_VERSION_STRING_SIZE 100
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530132#define MAX_SND_CARD_STRING_SIZE 100
Walter Yang6f800052014-07-14 16:15:38 -0700133
Eric Laurentb23d5282013-05-14 15:27:20 -0700134/* EDID format ID for LPCM audio */
135#define EDID_FORMAT_LPCM 1
136
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700137/* fallback app type if the default app type from acdb loader fails */
Aalique Grahame22e49102018-12-18 14:23:57 -0800138#define DEFAULT_APP_TYPE_RX_PATH 69936
139#define DEFAULT_APP_TYPE_TX_PATH 69938
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700140
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700141#define SAMPLE_RATE_8KHZ 8000
142#define SAMPLE_RATE_16KHZ 16000
143
Ben Rombergera04fabc2014-11-14 12:16:03 -0800144#define MAX_SET_CAL_BYTE_SIZE 65536
145
Vikram Panduranga6e761cd2016-10-12 16:50:52 -0700146/* Mixer path names */
147#define AFE_SIDETONE_MIXER_PATH "afe-sidetone"
148
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700149#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530150#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800151#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800152#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
153#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
154
Rohit kumarf4120402016-08-05 19:19:48 +0530155#define AUDIO_PARAMETER_KEY_MONO_SPEAKER "mono_speaker"
156
Jhansi Konathala170875c2018-10-11 18:34:10 +0530157#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence_type"
158#define AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL "fluence_voice"
159#define AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC "fluence_voice_rec"
160#define AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC "fluence_audio_rec"
161#define AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER "fluence_speaker"
162#define AUDIO_PARAMETER_KEY_FLUENCE_MODE "fluence_mode"
163#define AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL "fluence_hfp"
164#define AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC "fluence_tri_mic"
165
Sudheer Papothifa9d2282015-09-17 01:53:25 +0530166#define AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS "perf_lock_opts"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800167
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530168/* Reload ACDB files from specified path */
169#define AUDIO_PARAMETER_KEY_RELOAD_ACDB "reload_acdb"
170
Tanya Finkel00130052014-07-14 04:26:56 -0700171/* Query external audio device connection status */
172#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
173
Aalique Grahame37659862017-12-03 22:34:26 -0800174/* Query whether it is ok to select display-port as output
175 * device for voice usecase
176 */
177#define AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE "dp_for_voice"
Weiyin Jiangff72f812018-04-13 15:02:33 +0800178#define AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK "dp_channel_mask"
Surendar Karka45850ae2018-07-02 17:45:27 +0530179#define AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP "spkr_device_chmap"
Aalique Grahame37659862017-12-03 22:34:26 -0800180
Tanya Finkel00130052014-07-14 04:26:56 -0700181#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
182#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
183#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Anish Kumar55e6df22014-08-26 17:38:05 -0700184#define MAX_CAL_NAME 20
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530185#define MAX_MIME_TYPE_LENGTH 30
Aditya Bavanari4875a262019-01-17 19:39:59 +0530186#define MAX_SND_CARD_NAME_LENGTH 100
Anish Kumar55e6df22014-08-26 17:38:05 -0700187
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700188#define GET_IN_DEVICE_INDEX(SND_DEVICE) ((SND_DEVICE) - (SND_DEVICE_IN_BEGIN))
189
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +0530190#ifdef DYNAMIC_LOG_ENABLED
191extern void log_utils_init(void);
192extern void log_utils_deinit(void);
193#endif
194
Anish Kumar55e6df22014-08-26 17:38:05 -0700195char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
196 [WCD9XXX_ANC_CAL] = "anc_cal",
197 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700198 [WCD9XXX_VBAT_CAL] = "vbat_cal",
Anish Kumar55e6df22014-08-26 17:38:05 -0700199};
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530200static char *default_rx_backend = NULL;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800201
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530202#define AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED "is_hw_dec_session_allowed"
203
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530204char dsp_only_decoders_mime[][MAX_MIME_TYPE_LENGTH] = {
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530205 "audio/x-ms-wma" /* wma*/ ,
206 "audio/x-ms-wma-lossless" /* wma lossless */ ,
207 "audio/x-ms-wma-pro" /* wma prop */ ,
208 "audio/amr-wb-plus" /* amr wb plus */ ,
209 "audio/alac" /*alac */ ,
210 "audio/x-ape" /*ape */,
211};
212
213
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800214enum {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530215 VOICE_FEATURE_SET_DEFAULT,
216 VOICE_FEATURE_SET_VOLUME_BOOST
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800217};
sangwoo53b2cf02013-07-25 19:18:44 -0700218
Eric Laurentb23d5282013-05-14 15:27:20 -0700219struct audio_block_header
220{
221 int reserved;
222 int length;
223};
224
vivek mehtaa76401a2015-04-24 14:12:15 -0700225enum {
226 CAL_MODE_SEND = 0x1,
227 CAL_MODE_PERSIST = 0x2,
228 CAL_MODE_RTAC = 0x4
229};
230
Aalique Grahame22e49102018-12-18 14:23:57 -0800231#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
232
233struct operator_info {
234 struct listnode list;
235 char *name;
236 char *mccmnc;
237};
238
239struct operator_specific_device {
240 struct listnode list;
241 char *operator;
242 char *mixer_path;
243 int acdb_id;
244};
245
Carter Hsu32a62362018-10-15 15:01:42 -0700246struct external_specific_device {
247 struct listnode list;
248 char *usbid;
249 int acdb_id;
250};
251
Aalique Grahame22e49102018-12-18 14:23:57 -0800252static struct listnode operator_info_list;
253static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
254
Anish Kumar55e6df22014-08-26 17:38:05 -0700255acdb_loader_get_calibration_t acdb_loader_get_calibration;
Eric Laurentb23d5282013-05-14 15:27:20 -0700256
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800257typedef struct codec_backend_cfg {
258 uint32_t sample_rate;
259 uint32_t bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530260 uint32_t channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +0530261 uint32_t format;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800262 char *bitwidth_mixer_ctl;
263 char *samplerate_mixer_ctl;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530264 char *channels_mixer_ctl;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800265} codec_backend_cfg_t;
266
Ashish Jain4826f6c2017-02-06 13:33:20 +0530267static native_audio_prop na_props = {0, 0, NATIVE_AUDIO_MODE_INVALID};
Ashish Jainf1eaa582016-05-23 20:54:24 +0530268static bool supports_true_32_bit = false;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530269
Siena Richard7c2db772016-12-21 11:32:34 -0800270static int max_be_dai_names = 0;
271static const struct be_dai_name_struct *be_dai_name_table;
272
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530273struct snd_device_to_mic_map {
274 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
275 size_t mic_count;
276};
277
Carter Hsu32a62362018-10-15 15:01:42 -0700278static struct listnode *external_specific_device_table[SND_DEVICE_MAX];
279
Eric Laurentb23d5282013-05-14 15:27:20 -0700280struct platform_data {
281 struct audio_device *adev;
282 bool fluence_in_spkr_mode;
283 bool fluence_in_voice_call;
Aalique Grahame22e49102018-12-18 14:23:57 -0800284 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800286 bool fluence_in_audio_rec;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +0530287 bool fluence_in_hfp_call;
Tanya Finkel00130052014-07-14 04:26:56 -0700288 bool external_spk_1;
289 bool external_spk_2;
290 bool external_mic;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -0700291 bool speaker_lr_swap;
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800292 bool fluence_sb_enabled;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700293 int fluence_type;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800294 int fluence_mode;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530295 char fluence_cap[PROPERTY_VALUE_MAX];
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +0530296 bool ambisonic_capture;
297 bool ambisonic_profile;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700298 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530299 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530300 bool ec_ref_enabled;
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530301 bool is_wsa_speaker;
302 bool hifi_audio;
Aditya Bavanarif2be3c92019-10-11 19:46:43 +0530303 bool is_cls_ab_only_supported;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800304 bool is_i2s_ext_modem;
Ramjee Singh203473b2015-06-09 15:18:42 +0530305 bool is_acdb_initialized;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700306 /* Vbat monitor related flags */
307 bool is_vbat_speaker;
Aditya Bavanari9b589022018-09-20 08:47:55 +0530308 bool is_bcl_speaker;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700309 bool gsm_mode_enabled;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530310 bool is_slimbus_interface;
311 bool is_internal_codec;
Rohit kumarf4120402016-08-05 19:19:48 +0530312 int mono_speaker;
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700313 bool voice_speaker_stereo;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700314 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800315 void *acdb_handle;
316 int voice_feature_set;
317 acdb_init_t acdb_init;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530318 acdb_init_v3_t acdb_init_v3;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530319 acdb_init_v4_t acdb_init_v4;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800320 acdb_deallocate_t acdb_deallocate;
321 acdb_send_audio_cal_t acdb_send_audio_cal;
Siena Richard7c2db772016-12-21 11:32:34 -0800322 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +0530323 acdb_send_audio_cal_v4_t acdb_send_audio_cal_v4;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800324 acdb_set_audio_cal_t acdb_set_audio_cal;
325 acdb_get_audio_cal_t acdb_get_audio_cal;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800326 acdb_send_voice_cal_t acdb_send_voice_cal;
327 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700328 acdb_get_default_app_type_t acdb_get_default_app_type;
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700329 acdb_send_common_top_t acdb_send_common_top;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700330 acdb_set_codec_data_t acdb_set_codec_data;
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530331 acdb_reload_t acdb_reload;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530332 acdb_reload_v2_t acdb_reload_v2;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700333 void *hw_info;
vivek mehtaa76401a2015-04-24 14:12:15 -0700334 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800335 struct csd_data *csd;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700336 void *edid_info;
337 bool edid_valid;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700338 int ext_disp_type;
kunleize96916e2018-07-16 16:25:59 +0800339 char ec_ref_mixer_path[MIXER_PATH_MAX_LENGTH];
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800340 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530341 char codec_version[CODEC_VERSION_MAX_LENGTH];
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +0530342 char codec_variant[CODEC_VARIANT_MAX_LENGTH];
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +0530343 int hw_dep_fd;
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530344 char cvd_version[MAX_CVD_VERSION_STRING_SIZE];
345 char snd_card_name[MAX_SND_CARD_STRING_SIZE];
Aalique Grahame22e49102018-12-18 14:23:57 -0800346 int max_vol_index;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530347 int source_mic_type;
348 int max_mic_count;
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530349 bool is_dsd_supported;
Preetam Singh Ranawatb0c0dd72016-08-18 00:32:06 +0530350 bool is_asrc_supported;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530351 struct listnode acdb_meta_key_list;
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530352 bool use_generic_handset;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530353 struct acdb_init_data_v4 acdb_init_data;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530354 uint32_t declared_mic_count;
355 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
356 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Surendar Karka45850ae2018-07-02 17:45:27 +0530357 struct spkr_device_chmap *spkr_ch_map;
Dieter Luecking5d57def2018-09-07 14:23:37 +0200358 bool use_sprk_default_sample_rate;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530359 struct listnode custom_mtmx_params_list;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530360 struct listnode custom_mtmx_in_params_list;
Surendar Karka45850ae2018-07-02 17:45:27 +0530361};
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530362
Surendar Karka45850ae2018-07-02 17:45:27 +0530363struct spkr_device_chmap {
364 int num_ch;
365 char chmap[AUDIO_CHANNEL_COUNT_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700366};
367
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700368static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700369 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
370 DEEP_BUFFER_PCM_DEVICE},
Vignesh Kulothungana6927272019-02-20 15:17:07 -0800371 [USECASE_AUDIO_PLAYBACK_WITH_HAPTICS] = {AUDIO_HAPTICS_PCM_DEVICE,
372 AUDIO_HAPTICS_PCM_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700373 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700374 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -0700375 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
376 MULTIMEDIA3_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700377 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -0700378 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700379 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
380 MULTIMEDIA2_PCM_DEVICE},
Aalique Grahame22e49102018-12-18 14:23:57 -0800381 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
382 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700383 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
384 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700385 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =
386 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
387 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =
388 {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3},
389 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] =
390 {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4},
391 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] =
392 {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5},
393 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] =
394 {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6},
395 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] =
396 {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7},
397 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] =
398 {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8},
399 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] =
400 {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9},
vivek mehta0ea887a2015-08-26 14:01:20 -0700401
vivek mehta0ea887a2015-08-26 14:01:20 -0700402
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700403 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700404 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530405 [USECASE_AUDIO_RECORD_COMPRESS2] = {-1, -1},
406 [USECASE_AUDIO_RECORD_COMPRESS3] = {-1, -1},
407 [USECASE_AUDIO_RECORD_COMPRESS4] = {-1, -1},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +0530408 [USECASE_AUDIO_RECORD_COMPRESS5] = {-1, -1},
409 [USECASE_AUDIO_RECORD_COMPRESS6] = {-1, -1},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700410 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
411 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700412 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
413 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700414 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
415 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700416 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800417 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800418 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700419 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
Haynes Mathew George16081042017-05-31 17:16:49 -0700420 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
421 MMAP_PLAYBACK_PCM_DEVICE},
422 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
423 MMAP_RECORD_PCM_DEVICE},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700424 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
425 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
426 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800427 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Vidyakumar Athota0e109352015-02-12 17:38:22 -0800428 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
429 VOICEMMODE1_CALL_PCM_DEVICE},
430 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
431 VOICEMMODE2_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800432 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700433 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
434 AUDIO_RECORD_PCM_DEVICE},
435 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
436 AUDIO_RECORD_PCM_DEVICE},
437 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
438 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800439 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
440 COMPRESS_CAPTURE_DEVICE},
441 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
442 COMPRESS_CAPTURE_DEVICE},
443 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
444 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700445 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
446 INCALL_MUSIC_UPLINK_PCM_DEVICE},
447 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
448 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700449 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
450 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700451
452 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
453 AFE_PROXY_RECORD_PCM_DEVICE},
454 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
455 AFE_PROXY_RECORD_PCM_DEVICE},
Aalique Grahame22e49102018-12-18 14:23:57 -0800456 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530457 [USECASE_AUDIO_PLAYBACK_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
Surendar Karka93cd25a2018-08-28 14:21:37 +0530458 [USECASE_AUDIO_TRANSCODE_LOOPBACK_RX] = {TRANSCODE_LOOPBACK_RX_DEV_ID, -1},
459 [USECASE_AUDIO_TRANSCODE_LOOPBACK_TX] = {-1, TRANSCODE_LOOPBACK_TX_DEV_ID},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700460
Vikram Panduranga93f080e2017-06-07 18:16:14 -0700461 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
462 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, AUDIO_RECORD_VOIP_PCM_DEVICE},
Varun Balaraje49253e2017-07-06 19:48:56 +0530463 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM1] =
464 {PLAYBACK_INTERACTIVE_STRM_DEVICE1, PLAYBACK_INTERACTIVE_STRM_DEVICE1},
465 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM2] =
466 {PLAYBACK_INTERACTIVE_STRM_DEVICE2, PLAYBACK_INTERACTIVE_STRM_DEVICE2},
467 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM3] =
468 {PLAYBACK_INTERACTIVE_STRM_DEVICE3, PLAYBACK_INTERACTIVE_STRM_DEVICE3},
469 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM4] =
470 {PLAYBACK_INTERACTIVE_STRM_DEVICE4, PLAYBACK_INTERACTIVE_STRM_DEVICE4},
471 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM5] =
472 {PLAYBACK_INTERACTIVE_STRM_DEVICE5, PLAYBACK_INTERACTIVE_STRM_DEVICE5},
473 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM6] =
474 {PLAYBACK_INTERACTIVE_STRM_DEVICE6, PLAYBACK_INTERACTIVE_STRM_DEVICE6},
475 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM7] =
476 {PLAYBACK_INTERACTIVE_STRM_DEVICE7, PLAYBACK_INTERACTIVE_STRM_DEVICE7},
477 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM8] =
478 {PLAYBACK_INTERACTIVE_STRM_DEVICE8, PLAYBACK_INTERACTIVE_STRM_DEVICE8},
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530479 [USECASE_AUDIO_EC_REF_LOOPBACK] = {-1, -1}, /* pcm id updated from platform info file */
Derek Chenf6318be2017-06-12 17:16:24 -0400480 [USECASE_AUDIO_PLAYBACK_MEDIA] = {MEDIA_PCM_DEVICE,
481 MEDIA_PCM_DEVICE},
482 [USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION] = {SYS_NOTIFICATION_PCM_DEVICE,
483 SYS_NOTIFICATION_PCM_DEVICE},
484 [USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE] = {NAV_GUIDANCE_PCM_DEVICE,
485 NAV_GUIDANCE_PCM_DEVICE},
486 [USECASE_AUDIO_PLAYBACK_PHONE] = {PHONE_PCM_DEVICE,
487 PHONE_PCM_DEVICE},
Rahul Sharma99770982019-03-06 17:05:26 +0530488 [USECASE_AUDIO_FM_TUNER_EXT] = {-1, -1},
Eric Laurentb23d5282013-05-14 15:27:20 -0700489};
490
491/* Array to store sound devices */
492static const char * const device_table[SND_DEVICE_MAX] = {
493 [SND_DEVICE_NONE] = "none",
494 /* Playback sound devices */
495 [SND_DEVICE_OUT_HANDSET] = "handset",
496 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Tanya Finkel00130052014-07-14 04:26:56 -0700497 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
498 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530499 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700500 [SND_DEVICE_OUT_SPEAKER_VBAT] = "speaker-vbat",
Eric Laurentb23d5282013-05-14 15:27:20 -0700501 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Aalique Grahame22e49102018-12-18 14:23:57 -0800502 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700503 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530504 [SND_DEVICE_OUT_HEADPHONES_DSD] = "headphones-dsd",
Ramlal Karra10d22b92019-08-08 19:02:35 +0530505 [SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = "headphones-hifi-filter",
506 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = "speaker-and-headphones-hifi-filter",
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800507 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700508 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700509 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800510 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700511 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Aalique Grahame22e49102018-12-18 14:23:57 -0800512 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Tanya Finkel00130052014-07-14 04:26:56 -0700513 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
514 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700515 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Aalique Grahame22e49102018-12-18 14:23:57 -0800516 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700517 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700518 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = "voice-speaker-stereo",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530519 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700520 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = "voice-speaker-vbat",
Rohit kumarf4120402016-08-05 19:19:48 +0530521 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = "voice-speaker-2",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530522 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = "wsa-voice-speaker-2",
Rohit kumarf4120402016-08-05 19:19:48 +0530523 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = "voice-speaker-2-vbat",
Eric Laurentb23d5282013-05-14 15:27:20 -0700524 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530525 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headset",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700526 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700527 [SND_DEVICE_OUT_HDMI] = "hdmi",
528 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700529 [SND_DEVICE_OUT_DISPLAY_PORT] = "display-port",
530 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = "speaker-and-display-port",
Eric Laurentb23d5282013-05-14 15:27:20 -0700531 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700532 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800533 [SND_DEVICE_OUT_BT_SCO_SWB] = "bt-sco-headset-swb",
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530534 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
535 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aalique Grahame22e49102018-12-18 14:23:57 -0800536 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
537 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Eric Laurentb23d5282013-05-14 15:27:20 -0700538 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
Samyak Jainc9250dc2019-06-14 12:19:28 +0530539 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = "voice-tty-full-headset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700540 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
Samyak Jainc9250dc2019-06-14 12:19:28 +0530541 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = "voice-tty-vco-headset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700542 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700543 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
544 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700545 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Aalique Grahame22e49102018-12-18 14:23:57 -0800546 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700547 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
Ashish Jain3e37a702016-11-25 12:27:15 +0530548 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700549 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
Ashish Jain3e37a702016-11-25 12:27:15 +0530550 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800551 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700552 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700553 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800554 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700555 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700556 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
557 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
558 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
559 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530560 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = "voice-speaker-and-voice-headphones",
561 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = "voice-speaker-and-voice-anc-headphones",
562 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = "voice-speaker-and-voice-anc-fb-headphones",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700563 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = "voice-speaker-stereo-and-voice-headphones",
564 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = "voice-speaker-stereo-and-voice-anc-headphones",
565 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = "voice-speaker-stereo-and-voice-anc-fb-headphones",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700566 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
Meng Wang841d6c02017-01-24 12:34:36 +0800567 [SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = "speaker-and-anc-fb-headphones",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700568 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700569 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Anish Kumar46c7b872014-09-09 01:49:44 -0700570 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Aalique Grahame22e49102018-12-18 14:23:57 -0800571 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700572 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = "voice-speaker-stereo-protected",
Rohit kumarf4120402016-08-05 19:19:48 +0530573 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = "voice-speaker-2-protected",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700574 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = "speaker-protected-vbat",
575 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = "voice-speaker-protected-vbat",
Rohit kumarf4120402016-08-05 19:19:48 +0530576 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = "voice-speaker-2-protected-vbat",
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -0800577 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = "speaker-protected",
578 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = "speaker-protected-vbat",
kunleizbe6a8442017-08-08 17:11:35 +0800579 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
Aalique Grahame22e49102018-12-18 14:23:57 -0800580 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
kunleizbe6a8442017-08-08 17:11:35 +0800581 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800582 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB] = "speaker-and-bt-sco-swb",
Aalique Grahame22e49102018-12-18 14:23:57 -0800583 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800584 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] = "speaker-safe-and-bt-sco-swb",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530585 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO] = "wsa-speaker-and-bt-sco",
586 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB] = "wsa-speaker-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800587 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB] = "wsa-speaker-and-bt-sco-wb",
juyuchen2d415992018-11-16 14:15:16 +0800588 [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid",
Derek Chenf6318be2017-06-12 17:16:24 -0400589 [SND_DEVICE_OUT_BUS_MEDIA] = "bus-speaker",
590 [SND_DEVICE_OUT_BUS_SYS] = "bus-speaker",
591 [SND_DEVICE_OUT_BUS_NAV] = "bus-speaker",
592 [SND_DEVICE_OUT_BUS_PHN] = "bus-speaker",
Eric Laurentb23d5282013-05-14 15:27:20 -0700593
594 /* Capture sound devices */
595 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800596 [SND_DEVICE_IN_HANDSET_MIC_SB] = "handset-mic",
Tanya Finkel00130052014-07-14 04:26:56 -0700597 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Eric Laurentb23d5282013-05-14 15:27:20 -0700598 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800599 [SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800600 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800601 [SND_DEVICE_IN_HANDSET_MIC_NS_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800602 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800603 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800604 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800605 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800606 [SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800607 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800608 [SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800609 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800610 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800611 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800612 [SND_DEVICE_IN_SPEAKER_MIC_SB] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800613 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800614 [SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800615 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800616 [SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800617 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800618 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800619 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800620 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800621 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800622 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800623 [SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800624 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800625 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800626 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800627 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800628 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700629 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800630 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = "voice-speaker-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700631 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Ralf Herzafb164f2018-07-03 07:08:07 +0200632 [SND_DEVICE_IN_SPDIF] = "spdif-in",
633 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-in",
634 [SND_DEVICE_IN_HDMI_ARC] = "hdmi-arc-in",
Eric Laurentb23d5282013-05-14 15:27:20 -0700635 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700636 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700637 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700638 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800639 [SND_DEVICE_IN_BT_SCO_MIC_SWB] = "bt-sco-mic-swb",
640 [SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = "bt-sco-mic-swb",
Florian Pfister1a84f312018-07-19 14:38:18 +0200641 [SND_DEVICE_IN_BT_A2DP] = "bt-a2dp-cap",
Eric Laurent4b084132018-10-19 17:33:43 -0700642 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700643 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800644 [SND_DEVICE_IN_VOICE_DMIC_SB] = "voice-dmic-ef",
Aalique Grahame22e49102018-12-18 14:23:57 -0800645 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700646 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800647 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = "voice-speaker-dmic-ef",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700648 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = "voice-speaker-tmic",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800649 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800650 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700651 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
652 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
653 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700654 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
655 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700656 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
657
Eric Laurentb23d5282013-05-14 15:27:20 -0700658 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800659 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800660 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
661 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800662 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700663 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700664 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700665 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
666 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
667 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
668 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800669 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Karthikeyan Mani07faa602018-08-20 11:01:32 -0700670 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
671 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
672 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = "usb-headset-mic",
673 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700674 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700675 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -0800676 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700677 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800678 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "handset-stereo-dmic-ef",
679 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700680 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Rohit kumarf4120402016-08-05 19:19:48 +0530681 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = "vi-feedback-mono-1",
682 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = "vi-feedback-mono-2",
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800683 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
684 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
685 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
686 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
687 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700688 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
689 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
690 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
691 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800692 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Ben Romberger182c8252016-07-18 16:54:54 -0700693 [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = "quad-mic",
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700694 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530695 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = "three-mic",
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530696 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530697 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
698 [SND_DEVICE_IN_HANDSET_TMIC_NS] = "three-mic",
699 [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = "three-mic",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700700 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = "speaker-tmic",
701 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = "speaker-tmic",
702 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = "speaker-tmic",
Ben Rombergera4d76db2016-10-13 15:26:02 -0700703 [SND_DEVICE_IN_VOICE_REC_TMIC] = "three-mic",
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530704 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
Aalique Grahame97748be2017-10-10 14:32:29 -0700705 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
706 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
707 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
708 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530709 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = "quad-mic",
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530710 [SND_DEVICE_IN_INCALL_REC_RX] = "incall-rec-rx",
711 [SND_DEVICE_IN_INCALL_REC_TX] = "incall-rec-tx",
712 [SND_DEVICE_IN_INCALL_REC_RX_TX] = "incall-rec-rx-tx",
Ramu Gottipati813ae982018-07-25 14:14:48 +0530713 [SND_DEVICE_IN_LINE] = "line-in",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530714 [SND_DEVICE_IN_HANDSET_6MIC] = "handset-6mic",
715 [SND_DEVICE_IN_HANDSET_8MIC] = "handset-8mic",
Eric Laurent4b084132018-10-19 17:33:43 -0700716 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
717 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
718 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
719 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
720 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530721 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
722 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
723 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
juyuchen2d415992018-11-16 14:15:16 +0800724 [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic",
Derek Chenf6318be2017-06-12 17:16:24 -0400725 [SND_DEVICE_IN_BUS] = "bus-mic",
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530726 [SND_DEVICE_IN_EC_REF_LOOPBACK] = "ec-ref-loopback",
727 [SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK] = "handset-dmic-and-ec-ref-loopback",
728 [SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK] = "handset-qmic-and-ec-ref-loopback",
729 [SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK] = "handset-6mic-and-ec-ref-loopback",
730 [SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK] = "handset-8mic-and-ec-ref-loopback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700731};
732
Amit Shekhar5a39c912014-10-14 15:39:30 -0700733// Platform specific backend bit width table
734static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
735
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700736static struct audio_effect_config effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_MAX] = {
737 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
738 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_NS] = {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x02},
Vignesh Kulothungan80d87ee2018-07-17 11:59:25 -0700739 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_TM_FLUENCE_PRO_VC, 0x0, 0x10EAF, 0x01},
740 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)][EFFECT_NS] = {TX_VOICE_TM_FLUENCE_PRO_VC, 0x0, 0x10EAF, 0x02},
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700741 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_AEC] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
742 0x10EAF, 0x01},
743 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_NS] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
744 0x10EAF, 0x02},
745 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
746 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_NS] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -0700747 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
748 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC)][EFFECT_NS] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x02},
Vignesh Kulothungan80d87ee2018-07-17 11:59:25 -0700749 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_TM_FLUENCE_EF, 0x8000, 0x10EAF, 0x01},
750 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)][EFFECT_NS] = {TX_VOICE_TM_FLUENCE_EF, 0x8000, 0x10EAF, 0x02},
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700751 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
752 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_NS] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x02},
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -0700753 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
754 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC)][EFFECT_NS] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x02},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800755
Vignesh Kulothungan033fd432019-04-16 18:43:38 -0700756 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
757 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x02},
758 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
759 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x02},
760 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
761 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_MM_SB, 0x8000, 0x10EAF, 0x02},
762 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
763 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x02},
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700764};
765
Eric Laurentb23d5282013-05-14 15:27:20 -0700766/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800767static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700768 [SND_DEVICE_NONE] = -1,
769 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800770 [SND_DEVICE_OUT_SPEAKER] = 14,
Tanya Finkel87af1a52015-03-27 14:54:23 -0700771 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 130,
772 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 130,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530773 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700774 [SND_DEVICE_OUT_SPEAKER_VBAT] = 14,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800775 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800776 [SND_DEVICE_OUT_SPEAKER_SAFE] = 14,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700777 [SND_DEVICE_OUT_LINE] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700778 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530779 [SND_DEVICE_OUT_HEADPHONES_DSD] = 10,
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800780 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700781 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Aalique Grahame22e49102018-12-18 14:23:57 -0800782 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700783 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
Aalique Grahame22e49102018-12-18 14:23:57 -0800784 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 10,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800785 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 130,
786 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 130,
Eric Laurentb23d5282013-05-14 15:27:20 -0700787 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800788 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700789 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = 15,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700790 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = 14,
Rohit kumarf4120402016-08-05 19:19:48 +0530791 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = 14,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530792 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
793 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = 135,
Rohit kumarf4120402016-08-05 19:19:48 +0530794 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800795 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700796 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530797 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700798 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530799 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = 10,
800 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = 10,
801 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = 10,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700802 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = 10,
803 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = 10,
804 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700805 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800806 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700807 [SND_DEVICE_OUT_DISPLAY_PORT] = 18,
808 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700809 [SND_DEVICE_OUT_BT_SCO] = 22,
Aalique Grahame22e49102018-12-18 14:23:57 -0800810 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700811 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Zhou Song12c29502019-03-16 10:37:18 +0800812 [SND_DEVICE_OUT_BT_SCO_SWB] = 39,
Aalique Grahame22e49102018-12-18 14:23:57 -0800813 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Zhou Song12c29502019-03-16 10:37:18 +0800814 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] = 14,
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530815 [SND_DEVICE_OUT_BT_A2DP] = 20,
816 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800817 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
818 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700819 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
Samyak Jainc9250dc2019-06-14 12:19:28 +0530820 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = 17,
Eric Laurentb23d5282013-05-14 15:27:20 -0700821 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
Samyak Jainc9250dc2019-06-14 12:19:28 +0530822 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = 17,
Eric Laurentb23d5282013-05-14 15:27:20 -0700823 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700824 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
825 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700826 [SND_DEVICE_OUT_VOICE_TX] = 45,
Aalique Grahame22e49102018-12-18 14:23:57 -0800827 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700828 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800829 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700830 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
Ashish Jain3e37a702016-11-25 12:27:15 +0530831 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Aalique Grahame22e49102018-12-18 14:23:57 -0800832 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700833 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700834 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800835 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700836 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700837 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700838 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Ramlal Karra10d22b92019-08-08 19:02:35 +0530839 [SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = 188,
840 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = 188,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700841 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700842 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700843 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
Meng Wang841d6c02017-01-24 12:34:36 +0800844 [SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700845 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Anish Kumar46c7b872014-09-09 01:49:44 -0700846 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
Aalique Grahame22e49102018-12-18 14:23:57 -0800847 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = 14,
Anish Kumar46c7b872014-09-09 01:49:44 -0700848 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530849 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = 101,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700850 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = 124,
851 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530852 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = 101,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700853 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = 124,
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -0800854 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = 134,
855 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = 134,
juyuchen2d415992018-11-16 14:15:16 +0800856 [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45,
Derek Chenf6318be2017-06-12 17:16:24 -0400857 [SND_DEVICE_OUT_BUS_MEDIA] = 78,
858 [SND_DEVICE_OUT_BUS_SYS] = 78,
859 [SND_DEVICE_OUT_BUS_NAV] = 14,
860 [SND_DEVICE_OUT_BUS_PHN] = 94,
Eric Laurentb23d5282013-05-14 15:27:20 -0700861 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800862 [SND_DEVICE_IN_HANDSET_MIC_SB] = 163,
Tanya Finkel00130052014-07-14 04:26:56 -0700863 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800864 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800865 [SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = 164,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800866 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800867 [SND_DEVICE_IN_HANDSET_MIC_NS_SB] = 165,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800868 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800869 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = 166,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800870 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800871 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800872 [SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = 168,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800873 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800874 [SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = 169,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800875 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800876 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = 170,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800877 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800878 [SND_DEVICE_IN_SPEAKER_MIC_SB] = 171,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800879 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800880 [SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = 172,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800881 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800882 [SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = 173,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800883 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800884 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = 174,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800885 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800886 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800887 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = 176,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800888 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800889 [SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = 177,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800890 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800891 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = 178,
Eric Laurentb23d5282013-05-14 15:27:20 -0700892 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Aalique Grahame22e49102018-12-18 14:23:57 -0800893 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800894 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700895 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800896 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = 171,
Aalique Grahame22e49102018-12-18 14:23:57 -0800897 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Eric Laurentb23d5282013-05-14 15:27:20 -0700898 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
Ralf Herz76b455c2018-09-10 13:58:04 +0200899 [SND_DEVICE_IN_SPDIF] = 143,
900 [SND_DEVICE_IN_HDMI_MIC] = 143,
901 [SND_DEVICE_IN_HDMI_ARC] = 143,
Eric Laurentb23d5282013-05-14 15:27:20 -0700902 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700903 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700904 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700905 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Zhou Song12c29502019-03-16 10:37:18 +0800906 [SND_DEVICE_IN_BT_SCO_MIC_SWB] = 38,
907 [SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = 123,
Florian Pfister1a84f312018-07-19 14:38:18 +0200908 [SND_DEVICE_IN_BT_A2DP] = 21,
Eric Laurent4b084132018-10-19 17:33:43 -0700909 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700910 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800911 [SND_DEVICE_IN_VOICE_DMIC_SB] = 167,
Aalique Grahame22e49102018-12-18 14:23:57 -0800912 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700913 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800914 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = 175,
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700915 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = 161,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800916 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700917 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
918 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
919 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700920 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
921 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700922 [SND_DEVICE_IN_VOICE_RX] = 44,
923
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800924 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800925 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Aalique Grahame22e49102018-12-18 14:23:57 -0800926 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
927 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800928 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
929 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Aalique Grahame22e49102018-12-18 14:23:57 -0800930 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = 8,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700931 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700932 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
933 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
934 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
935 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Karthikeyan Mani07faa602018-08-20 11:01:32 -0700936 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
937 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
938 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = 162,
939 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700940 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700941 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -0800942 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700943 [SND_DEVICE_IN_QUAD_MIC] = 46,
Aalique Grahame22e49102018-12-18 14:23:57 -0800944 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
945 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700946 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Rohit kumarf4120402016-08-05 19:19:48 +0530947 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = 102,
948 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = 102,
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800949 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
950 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
951 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
952 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
953 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700954 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Aalique Grahame22e49102018-12-18 14:23:57 -0800955 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700956 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
957 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
958 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Ben Romberger182c8252016-07-18 16:54:54 -0700959 [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = 125,
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530960 [SND_DEVICE_IN_THREE_MIC] = 46, /* for APSS Surround Sound Recording */
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -0700961 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = 138,
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530962 [SND_DEVICE_IN_HANDSET_TMIC] = 153,
963 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 154,
964 [SND_DEVICE_IN_HANDSET_TMIC_NS] = 155,
965 [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = 156,
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700966 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = 158,
967 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = 159,
968 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = 160,
Ben Rombergera4d76db2016-10-13 15:26:02 -0700969 [SND_DEVICE_IN_VOICE_REC_TMIC] = 125,
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530970 [SND_DEVICE_IN_UNPROCESSED_MIC] = 143,
971 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 144,
972 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 145,
973 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 146,
974 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = 147,
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530975 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = 150,
Ramu Gottipati813ae982018-07-25 14:14:48 +0530976 [SND_DEVICE_IN_LINE] = 4,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530977 [SND_DEVICE_IN_HANDSET_6MIC] = 4,
978 [SND_DEVICE_IN_HANDSET_8MIC] = 4,
979 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
980 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
981 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
Eric Laurent4b084132018-10-19 17:33:43 -0700982 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 4,
983 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 4,
984 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 4,
985 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 4,
986 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 4,
juyuchen2d415992018-11-16 14:15:16 +0800987 [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
Derek Chenf6318be2017-06-12 17:16:24 -0400988 [SND_DEVICE_IN_BUS] = 11,
Eric Laurentb23d5282013-05-14 15:27:20 -0700989};
990
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700991struct name_to_index {
Ben Romberger61764e32014-01-10 13:49:02 -0800992 char name[100];
993 unsigned int index;
994};
995
996#define TO_NAME_INDEX(X) #X, X
997
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800998/* Used to get index from parsed string */
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700999static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Ben Romberger61764e32014-01-10 13:49:02 -08001000 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
1001 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Tanya Finkel00130052014-07-14 04:26:56 -07001002 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
1003 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301004 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001005 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_VBAT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001006 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001007 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001008 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05301009 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_DSD)},
Ramlal Karra10d22b92019-08-08 19:02:35 +05301010 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)},
1011 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER)},
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08001012 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001013 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001014 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001015 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001016 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001017 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Tanya Finkel00130052014-07-14 04:26:56 -07001018 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
1019 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -08001020 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
1021 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05301022 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301023 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001024 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001025 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +05301026 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301027 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)},
Rohit kumarf4120402016-08-05 19:19:48 +05301028 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001029 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Samyak Jainfd24f1e2019-04-30 11:58:43 +05301030 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001031 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001032 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
1033 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07001034 {TO_NAME_INDEX(SND_DEVICE_OUT_DISPLAY_PORT)},
1035 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001036 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001037 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001038 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001039 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_SWB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001040 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001041 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB)},
Naresh Tanniru9d027a62015-03-13 01:32:10 +05301042 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
1043 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001044 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
1045 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
1046 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001047 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
Samyak Jainc9250dc2019-06-14 12:19:28 +05301048 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001049 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
Samyak Jainc9250dc2019-06-14 12:19:28 +05301050 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001051 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
kunleizbe6a8442017-08-08 17:11:35 +08001052 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
1053 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001054 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301055 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO)},
1056 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001057 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB)},
Aniket Kumar Lata91886592017-05-25 16:53:32 -07001058 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
1059 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301060 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Ben Romberger61764e32014-01-10 13:49:02 -08001061 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
1062 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001063 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
Ashish Jain3e37a702016-11-25 12:27:15 +05301064 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001065 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
Ben Romberger61764e32014-01-10 13:49:02 -08001066 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001067 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
1068 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001069 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
1070 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
1071 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
1072 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
1073 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
1074 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
Meng Wang841d6c02017-01-24 12:34:36 +08001075 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001076 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
1077 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Anish Kumar46c7b872014-09-09 01:49:44 -07001078 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Rohit kumarf4120402016-08-05 19:19:48 +05301079 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED)},
Vikram Panduranga8c68e862018-04-27 12:59:42 -07001080 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001081 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT)},
1082 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +05301083 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT)},
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08001084 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS)},
1085 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301086 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
1087 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
1088 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
juyuchen2d415992018-11-16 14:15:16 +08001089 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)},
Derek Chenf6318be2017-06-12 17:16:24 -04001090 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_MEDIA)},
1091 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_SYS)},
1092 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_NAV)},
1093 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_PHN)},
Ben Romberger61764e32014-01-10 13:49:02 -08001094 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001095 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)},
Tanya Finkel00130052014-07-14 04:26:56 -07001096 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Ben Romberger61764e32014-01-10 13:49:02 -08001097 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001098 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001099 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001100 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001101 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001102 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001103 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
1104 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001105 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001106 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001107 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001108 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001109 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001110 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001111 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001112 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001113 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001114 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001115 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001116 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001117 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001118 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
1119 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001120 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001121 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001122 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001123 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001124 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001125 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001126 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001127 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001128 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
1129 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001130 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001131 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ben Romberger61764e32014-01-10 13:49:02 -08001132 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Ralf Herzafb164f2018-07-03 07:08:07 +02001133 {TO_NAME_INDEX(SND_DEVICE_IN_SPDIF)},
Ben Romberger61764e32014-01-10 13:49:02 -08001134 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
Ralf Herzafb164f2018-07-03 07:08:07 +02001135 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_ARC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001136 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001137 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001138 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001139 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Zhou Song12c29502019-03-16 10:37:18 +08001140 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB)},
1141 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC)},
Florian Pfister1a84f312018-07-19 14:38:18 +02001142 {TO_NAME_INDEX(SND_DEVICE_IN_BT_A2DP)},
Eric Laurent4b084132018-10-19 17:33:43 -07001143 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001144 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001145 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001146 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
Ben Romberger61764e32014-01-10 13:49:02 -08001147 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001148 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001149 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_TMIC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001150 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
1151 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
1152 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
1153 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Aniket Kumar Lata91886592017-05-25 16:53:32 -07001154 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
1155 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001156 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
1157 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001158 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
1159 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ben Romberger61764e32014-01-10 13:49:02 -08001160 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
1161 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001162 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301163 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Ben Romberger61764e32014-01-10 13:49:02 -08001164 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001165 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
1166 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
1167 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
1168 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001169 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC)},
1170 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC)},
1171 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC)},
1172 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001173 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
1174 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -08001175 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001176 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001177 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
1178 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001179 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Rohit kumarf4120402016-08-05 19:19:48 +05301180 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1)},
1181 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2)},
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001182 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
1183 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
1184 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
1185 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
1186 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001187 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001188 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001189 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
juyuchen2d415992018-11-16 14:15:16 +08001190 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001191 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
1192 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Ben Romberger182c8252016-07-18 16:54:54 -07001193 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301194 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05301195 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301196 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05301197 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
1198 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_NS)},
1199 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001200 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC)},
1201 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_NS)},
1202 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)},
Ben Rombergera4d76db2016-10-13 15:26:02 -07001203 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_TMIC)},
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05301204 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
1205 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
1206 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
1207 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
1208 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301209 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC)},
1210 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC)},
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05301211 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_GENERIC_QMIC)},
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05301212 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX)},
1213 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_TX)},
1214 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX_TX)},
Ramu Gottipati813ae982018-07-25 14:14:48 +05301215 {TO_NAME_INDEX(SND_DEVICE_IN_LINE)},
Eric Laurent4b084132018-10-19 17:33:43 -07001216 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
1217 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
1218 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
1219 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
1220 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
1221 /* For legacy xml file parsing */
1222 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Derek Chenf6318be2017-06-12 17:16:24 -04001223 {TO_NAME_INDEX(SND_DEVICE_IN_BUS)},
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301224 {TO_NAME_INDEX(SND_DEVICE_IN_EC_REF_LOOPBACK)},
1225 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK)},
1226 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK)},
1227 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK)},
1228 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK)},
Ben Romberger61764e32014-01-10 13:49:02 -08001229};
1230
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301231static char * backend_tag_table[SND_DEVICE_MAX] = {0};
1232static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001233
1234static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
1235 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
Vignesh Kulothungana6927272019-02-20 15:17:07 -08001236 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001237 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001238 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
1239 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -07001240 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001241 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
1242 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Alexy Joseph2f89cfa2014-10-06 12:15:01 -07001243 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
1244 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
1245 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
1246 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
1247 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
1248 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
1249 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
1250 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
Haynes Mathew George16081042017-05-31 17:16:49 -07001251 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001252 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301253 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS)},
1254 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS2)},
1255 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS3)},
1256 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS4)},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +05301257 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS5)},
1258 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS6)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001259 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Haynes Mathew George16081042017-05-31 17:16:49 -07001260 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001261 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001262 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
1263 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
1264 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
1265 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
1266 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
Shiv Maliyappanahallif2d2a492016-05-11 22:03:47 -07001267 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
1268 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001269 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
1270 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
1271 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
1272 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +05301273 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO_WB)},
Shiv Maliyappanahallie236ff02016-05-26 11:47:48 -07001274 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_FM)},
1275 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_FM_VIRTUAL)},
Stephen Oglesbyf8a7bf92016-05-11 14:23:16 -07001276 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
1277 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
Garmond Leunge1e8c762016-06-27 16:35:15 -07001278 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
1279 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001280 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05301281 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SILENCE)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301282 {TO_NAME_INDEX(USECASE_AUDIO_EC_REF_LOOPBACK)},
Arun Mirpurie5c697c2018-07-17 17:58:17 -07001283 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301284 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK2)},
Aniket Kumar Lata7fd86e12018-02-20 19:26:10 -08001285 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
kunleiz6f796ac2018-07-16 17:03:59 +08001286 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
1287 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Surendar Karka93cd25a2018-08-28 14:21:37 +05301288 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_RX)},
1289 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_TX)},
Derek Chenf6318be2017-06-12 17:16:24 -04001290 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MEDIA)},
1291 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION)},
1292 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE)},
1293 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_PHONE)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001294};
1295
Aalique Grahame22e49102018-12-18 14:23:57 -08001296static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
1297 {TO_NAME_INDEX(PCM_PLAYBACK)},
1298 {TO_NAME_INDEX(PCM_CAPTURE)},
1299 {TO_NAME_INDEX(VOICE_CALL)},
1300 {TO_NAME_INDEX(PCM_HFP_CALL)},
1301};
1302
1303struct app_type_entry {
1304 int uc_type;
1305 int bit_width;
1306 int app_type;
1307 int max_rate;
1308 char *mode;
1309 struct listnode node; // membership in app_type_entry_list;
1310};
1311
1312static struct listnode app_type_entry_list;
1313
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001314#define NO_COLS 2
1315#ifdef PLATFORM_APQ8084
1316static int msm_device_to_be_id [][NO_COLS] = {
1317 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1318 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1319 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
1320 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
1321 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1322 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1323 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1324 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1325 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1326 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1327 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1328 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1329 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1330 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1331 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301332 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001333 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1334 {AUDIO_DEVICE_OUT_PROXY , 9},
1335 {AUDIO_DEVICE_OUT_FM , 7},
1336 {AUDIO_DEVICE_OUT_FM_TX , 8},
1337 {AUDIO_DEVICE_OUT_ALL , -1},
1338 {AUDIO_DEVICE_NONE , -1},
1339 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1340};
1341#elif PLATFORM_MSM8994
1342static int msm_device_to_be_id [][NO_COLS] = {
1343 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1344 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1345 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
1346 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
1347 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 38},
1348 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 38},
1349 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 38},
1350 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1351 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1352 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1353 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1354 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1355 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1356 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1357 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301358 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001359 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1360 {AUDIO_DEVICE_OUT_PROXY , 9},
1361/* Add the correct be ids */
1362 {AUDIO_DEVICE_OUT_FM , 7},
1363 {AUDIO_DEVICE_OUT_FM_TX , 8},
1364 {AUDIO_DEVICE_OUT_ALL , -1},
1365 {AUDIO_DEVICE_NONE , -1},
1366 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1367};
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001368#elif PLATFORM_MSM8996
1369static int msm_device_to_be_id [][NO_COLS] = {
1370 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1371 {AUDIO_DEVICE_OUT_SPEAKER , 2},
Sharad Sangle1f705a72016-10-05 20:01:39 +05301372 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1373 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001374 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1375 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1376 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1377 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1378 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1379 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1380 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1381 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1382 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1383 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1384 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301385 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001386 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1387 {AUDIO_DEVICE_OUT_PROXY , 9},
1388/* Add the correct be ids */
1389 {AUDIO_DEVICE_OUT_FM , 7},
1390 {AUDIO_DEVICE_OUT_FM_TX , 8},
1391 {AUDIO_DEVICE_OUT_ALL , -1},
1392 {AUDIO_DEVICE_NONE , -1},
1393 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1394};
Weiyin Jiang6f4c8062016-11-23 15:30:29 +08001395#elif PLATFORM_MSM8998
1396static int msm_device_to_be_id [][NO_COLS] = {
1397 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1398 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1399 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1400 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
1401 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1402 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1403 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1404 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1405 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1406 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1407 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1408 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1409 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1410 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1411 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301412 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Weiyin Jiang6f4c8062016-11-23 15:30:29 +08001413 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1414 {AUDIO_DEVICE_OUT_PROXY , 9},
1415/* Add the correct be ids */
1416 {AUDIO_DEVICE_OUT_FM , 7},
1417 {AUDIO_DEVICE_OUT_FM_TX , 8},
1418 {AUDIO_DEVICE_OUT_ALL , -1},
1419 {AUDIO_DEVICE_NONE , -1},
1420 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1421};
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301422#elif defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1423static int (*msm_device_to_be_id)[];
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001424#else
1425static int msm_device_to_be_id [][NO_COLS] = {
1426 {AUDIO_DEVICE_NONE, -1},
1427};
1428#endif
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301429
1430#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1431static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
1432 {AUDIO_DEVICE_OUT_EARPIECE , 34},
1433 {AUDIO_DEVICE_OUT_SPEAKER , 34},
1434 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
1435 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
1436 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1437 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1438 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1439 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1440 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1441 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1442 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1443 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1444 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1445 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1446 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
1447 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
1448 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1449 {AUDIO_DEVICE_OUT_PROXY , 9},
1450 {AUDIO_DEVICE_OUT_FM , 7},
1451 {AUDIO_DEVICE_OUT_FM_TX , 8},
1452 {AUDIO_DEVICE_OUT_ALL , -1},
1453 {AUDIO_DEVICE_NONE , -1},
1454 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1455};
1456
1457static int msm_device_to_be_id_external_codec [][NO_COLS] = {
1458 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1459 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1460 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1461 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
1462 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1463 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1464 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1465 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1466 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1467 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1468 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1469 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1470 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1471 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1472 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
1473 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
1474 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1475 {AUDIO_DEVICE_OUT_PROXY , 9},
1476 {AUDIO_DEVICE_OUT_FM , 7},
1477 {AUDIO_DEVICE_OUT_FM_TX , 8},
1478 {AUDIO_DEVICE_OUT_ALL , -1},
1479 {AUDIO_DEVICE_NONE , -1},
1480 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1481};
1482#endif
1483
1484#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1485static int msm_be_id_array_len;
1486#else
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001487static int msm_be_id_array_len =
1488 sizeof(msm_device_to_be_id) / sizeof(msm_device_to_be_id[0]);
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301489#endif
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001490
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001491#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
Ashish Jain5106d362016-05-11 19:23:33 +05301492#define PCM_OFFLOAD_PLATFORM_DELAY (30*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001493#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Aalique Grahame22e49102018-12-18 14:23:57 -08001494#define ULL_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George16081042017-05-31 17:16:49 -07001495#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001496
Aalique Grahame22e49102018-12-18 14:23:57 -08001497static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
1498static bool is_tmus = false;
1499
Carter Hsu32a62362018-10-15 15:01:42 -07001500static bool is_usb_snd_dev(snd_device_t snd_device)
1501{
1502 if (snd_device < SND_DEVICE_IN_BEGIN) {
1503 if (snd_device == SND_DEVICE_OUT_USB_HEADSET ||\
1504 snd_device == SND_DEVICE_OUT_USB_HEADPHONES ||\
1505 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADPHONES ||\
1506 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET ||\
1507 snd_device == SND_DEVICE_OUT_VOICE_TTY_FULL_USB ||\
1508 snd_device == SND_DEVICE_OUT_VOICE_TTY_VCO_USB)
1509 return true;
1510 } else {
1511 if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC ||\
1512 snd_device == SND_DEVICE_IN_USB_HEADSET_MIC_AEC ||\
1513 snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC ||\
1514 snd_device == SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC ||\
1515 snd_device == SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)
1516 return true;
1517 }
1518 return false;
1519}
1520
Aalique Grahame22e49102018-12-18 14:23:57 -08001521static void check_operator()
1522{
1523 char value[PROPERTY_VALUE_MAX];
1524 int mccmnc;
1525 property_get("gsm.sim.operator.numeric",value,"0");
1526 mccmnc = atoi(value);
1527 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
1528 switch(mccmnc) {
1529 /* TMUS MCC(310), MNC(490, 260, 026) */
1530 case 310490:
1531 case 310260:
1532 case 310026:
1533 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
1534 case 310800:
1535 case 310660:
1536 case 310580:
1537 case 310310:
1538 case 310270:
1539 case 310250:
1540 case 310240:
1541 case 310230:
1542 case 310220:
1543 case 310210:
1544 case 310200:
1545 case 310160:
1546 is_tmus = true;
1547 break;
1548 }
1549}
1550
1551bool is_operator_tmus()
1552{
1553 pthread_once(&check_op_once_ctl, check_operator);
1554 return is_tmus;
1555}
1556
1557static char *get_current_operator()
1558{
1559 struct listnode *node;
1560 struct operator_info *info_item;
1561 char mccmnc[PROPERTY_VALUE_MAX];
1562 char *ret = NULL;
1563
1564 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
1565
1566 list_for_each(node, &operator_info_list) {
1567 info_item = node_to_item(node, struct operator_info, list);
1568 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
1569 ret = info_item->name;
1570 }
1571 }
1572
1573 return ret;
1574}
1575
1576static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
1577{
1578 struct listnode *node;
1579 struct operator_specific_device *ret = NULL;
1580 struct operator_specific_device *device_item;
1581 char *operator_name;
1582
1583 operator_name = get_current_operator();
1584 if (operator_name == NULL)
1585 return ret;
1586
1587 list_for_each(node, operator_specific_device_table[snd_device]) {
1588 device_item = node_to_item(node, struct operator_specific_device, list);
1589 if (strcmp(operator_name, device_item->operator) == 0) {
1590 ret = device_item;
1591 }
1592 }
1593
1594 return ret;
1595}
1596
1597static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
1598{
1599 struct operator_specific_device *device;
1600 int ret = acdb_device_table[snd_device];
1601
1602 device = get_operator_specific_device(snd_device);
1603 if (device != NULL)
1604 ret = device->acdb_id;
1605
1606 return ret;
1607}
1608
Carter Hsu32a62362018-10-15 15:01:42 -07001609static int get_external_specific_device_acdb_id(snd_device_t snd_device)
1610{
1611 struct external_specific_device *ext_dev;
1612 int ret = acdb_device_table[snd_device];
1613 char *usbid = NULL;
1614 struct listnode *node;
1615
1616 if (is_usb_snd_dev(snd_device))
1617 usbid = audio_extn_usb_usbid();
1618
1619 if (usbid) {
1620 list_for_each(node, external_specific_device_table[snd_device]) {
1621 ext_dev = node_to_item(node, struct external_specific_device, list);
1622 if (ext_dev->usbid && !strcmp(usbid, ext_dev->usbid)) {
1623 ret = ext_dev->acdb_id;
1624 break;
1625 }
1626 }
1627
1628 free(usbid);
1629 }
1630 return ret;
1631}
1632
Aalique Grahame22e49102018-12-18 14:23:57 -08001633static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
1634{
1635 struct operator_specific_device *device;
1636 const char *ret = device_table[snd_device];
1637
1638 device = get_operator_specific_device(snd_device);
1639 if (device != NULL)
1640 ret = device->mixer_path;
1641
1642 return ret;
1643}
1644
Meng Wangef2f6e12018-10-08 13:06:05 +08001645static void update_codec_type_and_interface(struct platform_data * my_data,
1646 const char *snd_card_name)
1647{
Walter Yang319c6fe2017-09-21 17:09:39 +08001648 if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
1649 sizeof("sdm670-skuw-snd-card")) ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301650 !strncmp(snd_card_name, "sdm660-snd-card",
1651 sizeof("sdm660-snd-card")) ||
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301652 !strncmp(snd_card_name, "sdm660-snd-card-skush",
Walter Yang319c6fe2017-09-21 17:09:39 +08001653 sizeof("sdm660-snd-card-skush")) ||
Walter Yang725a57f2017-11-03 14:32:49 +08001654 !strncmp(snd_card_name, "sdm670-360cam-snd-card",
1655 sizeof("sdm670-360cam-snd-card")) ||
Walter Yang319c6fe2017-09-21 17:09:39 +08001656 !strncmp(snd_card_name, "sdm660-snd-card-mtp",
1657 sizeof("sdm660-snd-card-mtp")) ||
Sharad Sangle999cf722017-10-18 18:25:47 +05301658 !strncmp(snd_card_name, "sdm670-mtp-snd-card",
Naresh Tanniruc21e2022018-08-13 21:58:06 +05301659 sizeof("sdm670-mtp-snd-card")) ||
Xiaojun Sangfcddd672018-08-15 17:53:48 +08001660 !strncmp(snd_card_name, "sm6150-qrd-snd-card",
1661 sizeof("sm6150-qrd-snd-card")) ||
Naresh Tanniruc21e2022018-08-13 21:58:06 +05301662 !strncmp(snd_card_name, "sm6150-idp-snd-card",
Naresh Tannirucb5b5782018-10-12 20:42:07 +05301663 sizeof("sm6150-idp-snd-card")) ||
Sachin Mohan Gadageffd7562018-02-13 17:10:09 +05301664 !strncmp(snd_card_name, "qcs605-lc-snd-card",
Meng Wangef2f6e12018-10-08 13:06:05 +08001665 sizeof("qcs605-lc-snd-card")) ||
1666 !strncmp(snd_card_name, "kona-mtp-snd-card",
1667 sizeof("kona-mtp-snd-card")) ||
1668 !strncmp(snd_card_name, "kona-qrd-snd-card",
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05301669 sizeof("kona-qrd-snd-card")) ||
Vatsal Bucha6339b092019-04-17 16:27:32 +05301670 !strncmp(snd_card_name, "lito-mtp-snd-card",
1671 sizeof("lito-mtp-snd-card")) ||
1672 !strncmp(snd_card_name, "lito-qrd-snd-card",
1673 sizeof("lito-qrd-snd-card")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05301674 !strncmp(snd_card_name, "trinket-idp-snd-card",
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301675 sizeof("trinket-idp-snd-card")) ||
1676 !strncmp(snd_card_name, "sdm439-sku1-snd-card",
1677 sizeof("sdm439-sku1-snd-card")) ||
1678 !strncmp(snd_card_name, "sdm439-snd-card-mtp",
kunleiz3ae92e52019-04-28 15:35:31 +08001679 sizeof("sdm439-snd-card-mtp")) ||
1680 !strncmp(snd_card_name, "sm6150-wcd9375qrd-snd-card",
Aditya Bavanari4dbceed2018-10-11 18:31:55 +05301681 sizeof("sm6150-wcd9375qrd-snd-card")) ||
1682 !strncmp(snd_card_name, "sm6150-wcd9375-snd-card",
Faiz Nabi Kuchay536d7b92019-08-05 20:36:31 +05301683 sizeof("sm6150-wcd9375-snd-card")) ||
1684 !strncmp(snd_card_name, "atoll-wcd937x-snd-card",
1685 sizeof("atoll-wcd937x-snd-card")) ||
1686 !strncmp(snd_card_name, "atoll-idp-snd-card",
Kunlei Zhangb526fb02019-08-16 16:41:28 +08001687 sizeof("atoll-idp-snd-card")) ||
1688 !strncmp(snd_card_name, "atoll-qrd-snd-card",
1689 sizeof("atoll-qrd-snd-card"))) {
Aditya Bavanari4dbceed2018-10-11 18:31:55 +05301690 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301691 my_data->is_internal_codec = true;
1692 my_data->is_slimbus_interface = false;
1693 }
1694}
1695
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301696static bool can_enable_mbdrc_on_device(snd_device_t snd_device)
1697{
1698 bool ret = false;
1699
1700 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
1701 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
1702 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
1703 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
1704 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
1705 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
1706 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05301707 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301708 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
1709 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
1710 ret = true;
1711 }
1712 return ret;
1713}
1714
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001715static snd_device_t fixup_usb_headset_mic_snd_device(void *platform,
1716 snd_device_t base,
1717 snd_device_t other)
1718{
1719 struct platform_data *my_data = (struct platform_data *)platform;
1720 struct audio_device *adev = my_data->adev;
Eric Laurent637e2d42018-11-15 12:24:31 -08001721 struct stream_in *in = adev_get_active_input(adev);
1722 if (in == NULL)
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001723 return base;
Eric Laurent637e2d42018-11-15 12:24:31 -08001724 unsigned int sr = in->sample_rate;
1725 unsigned int ch = popcount(in->channel_mask);
1726 unsigned int bit_width = in->bit_width;
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001727 if (audio_extn_usb_is_config_supported(&bit_width, &sr, &ch, false)
1728 && ((ch == 6) || (ch == 8))) {
1729 return other;
1730 } else {
1731 return base;
1732 }
1733}
1734
`Deeraj Soman676c2702017-09-18 19:25:53 +05301735static const char *platform_get_mixer_control(struct mixer_ctl *);
1736
vivek mehtaa76401a2015-04-24 14:12:15 -07001737bool platform_send_gain_dep_cal(void *platform, int level) {
1738 bool ret_val = false;
1739 struct platform_data *my_data = (struct platform_data *)platform;
1740 struct audio_device *adev = my_data->adev;
1741 int acdb_dev_id, app_type;
1742 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
1743 int mode = CAL_MODE_RTAC;
1744 struct listnode *node;
1745 struct audio_usecase *usecase;
1746
1747 if (my_data->acdb_send_gain_dep_cal == NULL) {
1748 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
1749 return ret_val;
1750 }
1751
1752 if (!voice_is_in_call(adev)) {
1753 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
1754 __func__, level);
1755
1756 // find the current active sound device
1757 list_for_each(node, &adev->usecase_list) {
1758 usecase = node_to_item(node, struct audio_usecase, list);
1759
Sujin Panicker390724d2019-04-26 10:43:36 +05301760 if (usecase != NULL && usecase->stream.out &&
1761 usecase->type == PCM_PLAYBACK) {
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301762 int new_snd_device[2] = {0};
1763 int i, num_devices = 1;
vivek mehtaa76401a2015-04-24 14:12:15 -07001764
1765 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1766 app_type = usecase->stream.out->app_type_cfg.app_type;
Aalique Grahame22e49102018-12-18 14:23:57 -08001767 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta0b8ea6f2015-07-23 17:27:26 -07001768
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301769 if (platform_split_snd_device(my_data, usecase->out_snd_device,
1770 &num_devices, new_snd_device) < 0)
1771 new_snd_device[0] = usecase->out_snd_device;
1772
1773 for (i = 0; i < num_devices; i++)
1774 if (can_enable_mbdrc_on_device(new_snd_device[i])) {
1775 if (audio_extn_spkr_prot_is_enabled())
1776 acdb_dev_id = platform_get_spkr_prot_acdb_id(new_snd_device[i]);
1777 else
1778 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1779 }
vivek mehta0b8ea6f2015-07-23 17:27:26 -07001780
vivek mehtaa76401a2015-04-24 14:12:15 -07001781 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
1782 acdb_dev_type, mode, level)) {
1783 // set ret_val true if at least one calibration is set successfully
1784 ret_val = true;
1785 } else {
1786 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1787 }
1788 } else {
1789 ALOGW("%s: Usecase list is empty", __func__);
1790 }
1791 }
1792 } else {
1793 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1794 __func__);
1795 }
1796 return ret_val;
1797}
1798
Banajit Goswami20cdd212015-09-11 01:11:30 -07001799void platform_set_gsm_mode(void *platform, bool enable)
1800{
1801 struct platform_data *my_data = (struct platform_data *)platform;
1802 struct audio_device *adev = my_data->adev;
1803
1804 if (my_data->gsm_mode_enabled) {
1805 my_data->gsm_mode_enabled = false;
1806 ALOGV("%s: disabling gsm mode", __func__);
1807 audio_route_reset_and_update_path(adev->audio_route, "gsm-mode");
1808 }
1809
1810 if (enable) {
1811 my_data->gsm_mode_enabled = true;
1812 ALOGD("%s: enabling gsm mode", __func__);
1813 audio_route_apply_and_update_path(adev->audio_route, "gsm-mode");
1814 }
1815}
1816
1817void platform_set_echo_reference(struct audio_device *adev, bool enable,
kunleizceb286c2018-12-21 16:01:32 +08001818 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001819{
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001820 struct platform_data *my_data = (struct platform_data *)adev->platform;
kunleize96916e2018-07-16 16:25:59 +08001821 char ec_ref_mixer_path[MIXER_PATH_MAX_LENGTH] = "echo-reference";
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001822
kunleiz70e57612018-12-28 17:50:23 +08001823 audio_extn_sound_trigger_update_ec_ref_status(enable);
1824
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001825 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1826 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
Banajit Goswami20cdd212015-09-11 01:11:30 -07001827 audio_route_reset_and_update_path(adev->audio_route,
1828 my_data->ec_ref_mixer_path);
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301829 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001830
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -08001831 if (enable) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08001832 if (!voice_extn_is_compress_voip_supported()) {
Gangadhar Sb0210342019-02-22 17:39:41 +05301833 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
1834 strlcat(ec_ref_mixer_path, "-voip", MIXER_PATH_MAX_LENGTH);
1835 }
kunleizceb286c2018-12-21 16:01:32 +08001836 strlcpy(my_data->ec_ref_mixer_path, ec_ref_mixer_path,
1837 MIXER_PATH_MAX_LENGTH);
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001838 /*
1839 * If native audio device reference count > 0, then apply codec EC otherwise
kunleizceb286c2018-12-21 16:01:32 +08001840 * apply EC based on output device.
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001841 */
1842 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
kunleize96916e2018-07-16 16:25:59 +08001843 strlcat(ec_ref_mixer_path, " headphones-44.1",
1844 MIXER_PATH_MAX_LENGTH);
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08001845 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
kunleize96916e2018-07-16 16:25:59 +08001846 strlcat(ec_ref_mixer_path, " speaker-vbat",
1847 MIXER_PATH_MAX_LENGTH);
Aalique Grahame37659862017-12-03 22:34:26 -08001848 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_DISPLAY_PORT] > 0)
kunleize96916e2018-07-16 16:25:59 +08001849 strlcat(ec_ref_mixer_path, " display-port",
1850 MIXER_PATH_MAX_LENGTH);
kunleizceb286c2018-12-21 16:01:32 +08001851 else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
1852 strlcat(ec_ref_mixer_path, " handset",
1853 MIXER_PATH_MAX_LENGTH);
1854 else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
1855 strlcat(ec_ref_mixer_path, " headphones",
1856 MIXER_PATH_MAX_LENGTH);
1857 else if (out_device & AUDIO_DEVICE_OUT_USB_HEADSET)
1858 strlcat(ec_ref_mixer_path, " usb-headphones",
1859 MIXER_PATH_MAX_LENGTH);
Mingshu Pang2b134472020-02-26 18:19:56 +08001860 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_BT_SCO_WB] > 0)
1861 strlcat(ec_ref_mixer_path, " bt-sco-wb",
1862 MIXER_PATH_MAX_LENGTH);
1863 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_BT_SCO_SWB] > 0)
1864 strlcat(ec_ref_mixer_path, " bt-sco-swb",
1865 MIXER_PATH_MAX_LENGTH);
1866 else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO)
1867 strlcat(ec_ref_mixer_path, " bt-sco",
1868 MIXER_PATH_MAX_LENGTH);
kunleize96916e2018-07-16 16:25:59 +08001869
kunleizceb286c2018-12-21 16:01:32 +08001870 if (audio_route_apply_and_update_path(adev->audio_route,
1871 ec_ref_mixer_path) == 0)
1872 strlcpy(my_data->ec_ref_mixer_path, ec_ref_mixer_path,
1873 MIXER_PATH_MAX_LENGTH);
1874 else
1875 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -08001876
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001877 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001878 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001879}
1880
Helen Zeng6a16ad72014-02-23 22:04:44 -08001881static struct csd_data *open_csd_client(bool i2s_ext_modem)
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001882{
1883 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1884
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001885 if (!csd) {
1886 ALOGE("failed to allocate csd_data mem");
1887 return NULL;
1888 }
1889
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001890 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1891 if (csd->csd_client == NULL) {
1892 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1893 goto error;
1894 } else {
1895 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1896
1897 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1898 "csd_client_deinit");
1899 if (csd->deinit == NULL) {
1900 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1901 dlerror());
1902 goto error;
1903 }
1904 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1905 "csd_client_disable_device");
1906 if (csd->disable_device == NULL) {
1907 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1908 __func__, dlerror());
1909 goto error;
1910 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001911 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1912 "csd_client_enable_device_config");
1913 if (csd->enable_device_config == NULL) {
1914 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1915 __func__, dlerror());
1916 goto error;
1917 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001918 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1919 "csd_client_enable_device");
1920 if (csd->enable_device == NULL) {
1921 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1922 __func__, dlerror());
1923 goto error;
1924 }
1925 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1926 "csd_client_start_voice");
1927 if (csd->start_voice == NULL) {
1928 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1929 __func__, dlerror());
1930 goto error;
1931 }
1932 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1933 "csd_client_stop_voice");
1934 if (csd->stop_voice == NULL) {
1935 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1936 __func__, dlerror());
1937 goto error;
1938 }
1939 csd->volume = (volume_t)dlsym(csd->csd_client,
1940 "csd_client_volume");
1941 if (csd->volume == NULL) {
1942 ALOGE("%s: dlsym error %s for csd_client_volume",
1943 __func__, dlerror());
1944 goto error;
1945 }
1946 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1947 "csd_client_mic_mute");
1948 if (csd->mic_mute == NULL) {
1949 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1950 __func__, dlerror());
1951 goto error;
1952 }
1953 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1954 "csd_client_slow_talk");
1955 if (csd->slow_talk == NULL) {
1956 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1957 __func__, dlerror());
1958 goto error;
1959 }
1960 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1961 "csd_client_start_playback");
1962 if (csd->start_playback == NULL) {
1963 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1964 __func__, dlerror());
1965 goto error;
1966 }
1967 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1968 "csd_client_stop_playback");
1969 if (csd->stop_playback == NULL) {
1970 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1971 __func__, dlerror());
1972 goto error;
1973 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07001974 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
1975 if (csd->set_lch == NULL) {
1976 ALOGE("%s: dlsym error %s for csd_client_set_lch",
1977 __func__, dlerror());
1978 /* Ignore the error as this is not mandatory function for
1979 * basic voice call to work.
1980 */
1981 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001982 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1983 "csd_client_start_record");
1984 if (csd->start_record == NULL) {
1985 ALOGE("%s: dlsym error %s for csd_client_start_record",
1986 __func__, dlerror());
1987 goto error;
1988 }
1989 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1990 "csd_client_stop_record");
1991 if (csd->stop_record == NULL) {
1992 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1993 __func__, dlerror());
1994 goto error;
1995 }
Helen Zeng6a16ad72014-02-23 22:04:44 -08001996
1997 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1998 "csd_client_get_sample_rate");
1999 if (csd->get_sample_rate == NULL) {
2000 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
2001 __func__, dlerror());
2002
2003 goto error;
2004 }
2005
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002006 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
2007
2008 if (csd->init == NULL) {
2009 ALOGE("%s: dlsym error %s for csd_client_init",
2010 __func__, dlerror());
2011 goto error;
2012 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -08002013 csd->init(i2s_ext_modem);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002014 }
2015 }
2016 return csd;
2017
2018error:
2019 free(csd);
2020 csd = NULL;
2021 return csd;
2022}
2023
2024void close_csd_client(struct csd_data *csd)
2025{
2026 if (csd != NULL) {
2027 csd->deinit();
2028 dlclose(csd->csd_client);
2029 free(csd);
2030 csd = NULL;
2031 }
2032}
2033
Helen Zeng6a16ad72014-02-23 22:04:44 -08002034static bool platform_is_i2s_ext_modem(const char *snd_card_name,
2035 struct platform_data *plat_data)
2036{
2037 plat_data->is_i2s_ext_modem = false;
2038
2039 if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card",
2040 sizeof("apq8084-taiko-i2s-mtp-snd-card")) ||
2041 !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card",
Josh Kirschc3894372016-03-28 15:59:48 -07002042 sizeof("apq8084-taiko-i2s-cdp-snd-card")) ||
2043 !strncmp(snd_card_name, "apq8096-tasha-i2c-snd-card",
Xiaoyu Yec494c752017-11-02 18:52:48 -07002044 sizeof("apq8096-tasha-i2c-snd-card")) ||
2045 !strncmp(snd_card_name, "sdx-tavil-i2s-snd-card",
Josh Kirschf20adbf2018-03-06 16:26:22 -08002046 sizeof("sdx-tavil-i2s-snd-card")) ||
2047 !strncmp(snd_card_name, "sda845-tavil-i2s-snd-card",
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302048 sizeof("sda845-tavil-i2s-snd-card")) ||
Pallavi Mishra5627c162020-02-15 19:00:40 +05302049 !strncmp(snd_card_name, "sm8150-hana55-snd-card",
2050 sizeof("sm8150-hana55-snd-card")) ||
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302051 !strncmp(snd_card_name, "sa6155-adp-star-snd-card",
2052 sizeof("sa6155-adp-star-snd-card"))) {
Helen Zeng6a16ad72014-02-23 22:04:44 -08002053 plat_data->is_i2s_ext_modem = true;
2054 }
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302055 ALOGV("%s, is_i2s_ext_modem:%d soundcard name is %s",__func__,
2056 plat_data->is_i2s_ext_modem, snd_card_name);
Helen Zeng6a16ad72014-02-23 22:04:44 -08002057
2058 return plat_data->is_i2s_ext_modem;
Helen Zeng008aebd2014-02-23 19:13:12 -08002059}
2060
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302061static bool is_auto_snd_card(const char *snd_card_name)
2062{
2063 bool is_auto_snd_card = false;
2064
2065 if (!strncmp(snd_card_name, "sa6155-adp-star-snd-card",
2066 sizeof("sa6155-adp-star-snd-card"))) {
2067 is_auto_snd_card = true;
2068 ALOGV("%s : Auto snd card detected: soundcard name is %s",__func__,
2069 snd_card_name);
2070 }
2071
2072 return is_auto_snd_card;
2073}
2074
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302075static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002076{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302077 int32_t dev;
2078 unsigned int count = 0;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302079 const char *MEDIA_MIMETYPE_AUDIO_ALAC = "audio/alac";
2080 const char *MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape";
2081
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002082 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302083 backend_tag_table[dev] = NULL;
2084 hw_interface_table[dev] = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08002085 operator_specific_device_table[dev] = NULL;
Carter Hsu32a62362018-10-15 15:01:42 -07002086 external_specific_device_table[dev] = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002087 }
Amit Shekhar5a39c912014-10-14 15:39:30 -07002088 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002089 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -07002090 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002091
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302092 // To overwrite these go to the audio_platform_info.xml file.
2093 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
2094 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
2095 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
2096 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002097 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_SWB] = strdup("bt-sco-swb");
2098 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = strdup("bt-sco-swb");
Ralf Herzafb164f2018-07-03 07:08:07 +02002099 backend_tag_table[SND_DEVICE_IN_SPDIF] = strdup("spdif-in");
2100 backend_tag_table[SND_DEVICE_IN_HDMI_MIC] = strdup("hdmi-in");
2101 backend_tag_table[SND_DEVICE_IN_HDMI_ARC] = strdup("hdmi-arc-in");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302102 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
2103 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002104 backend_tag_table[SND_DEVICE_OUT_BT_SCO_SWB] = strdup("bt-sco-swb");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302105 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
2106 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07002107 backend_tag_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("display-port");
2108 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("speaker-and-display-port");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302109 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
2110 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
2111 backend_tag_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
Ashish Jain3e37a702016-11-25 12:27:15 +05302112 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002113 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
Ashish Jain3e37a702016-11-25 12:27:15 +05302114 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002115 backend_tag_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("usb-headset");
2116 backend_tag_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("usb-headphones");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002117 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302118 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
Sidipotu Ashokeaec6392016-04-19 09:37:57 +05302119 strdup("speaker-and-usb-headphones");
Aalique Grahame22e49102018-12-18 14:23:57 -08002120 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
2121 strdup("speaker-safe-and-usb-headphones");
2122 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
2123 strdup("speaker-safe-and-bt-sco");
2124 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
2125 strdup("speaker-safe-and-bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002126 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] =
2127 strdup("speaker-safe-and-bt-sco-swb");
Aniket Kumar Lata6bbd3bb2017-07-21 11:09:21 -07002128 backend_tag_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("usb-headset-mic");
2129 backend_tag_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("usb-headset-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302130 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002131 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2132 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2133 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2134 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Karthikeyan Mani07faa602018-08-20 11:01:32 -07002135 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2136 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2137 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2138 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = strdup("usb-headset-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302139 backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
2140 backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05302141 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("headphones-dsd");
Ramlal Karra10d22b92019-08-08 19:02:35 +05302142 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = strdup("headphones-hifi-filter");
2143 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] =
2144 strdup("speaker-and-headphones-hifi-filter");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302145 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
2146 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("voice-speaker-vbat");
Rohit kumarf4120402016-08-05 19:19:48 +05302147 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("voice-speaker-2-vbat");
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302148 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
Florian Pfister1a84f312018-07-19 14:38:18 +02002149 backend_tag_table[SND_DEVICE_IN_BT_A2DP] = strdup("bt-a2dp-cap");
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302150 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aalique Grahame22e49102018-12-18 14:23:57 -08002151 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
2152 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05302153 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
2154 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
2155 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002156 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
2157 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
2158 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones");
juyuchen2d415992018-11-16 14:15:16 +08002159 backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302160
Siena Richard7c2db772016-12-21 11:32:34 -08002161 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
2162 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
2163 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = strdup("SLIMBUS_0_RX");
2164 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = strdup("SLIMBUS_0_RX");
2165 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002166 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002167 hw_interface_table[SND_DEVICE_OUT_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
2168 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_6_RX");
2169 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_6_RX");
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05302170 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("SLIMBUS_2_RX");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302171 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("SLIMBUS_5_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002172 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002173 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05302174 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2175 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2176 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002177 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2178 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2179 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002180 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002181 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002182 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2183 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2184 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002185 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002186 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05302187 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002188 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
2189 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2] = strdup("SLIMBUS_0_RX");
2190 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("SLIMBUS_0_RX");
2191 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainfd24f1e2019-04-30 11:58:43 +05302192 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002193 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002194 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_6_RX");
2195 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI");
2196 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI");
2197 hw_interface_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("DISPLAY_PORT");
2198 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("SLIMBUS_0_RX-and-DISPLAY_PORT");
2199 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SLIMBUS_7_RX");
2200 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SLIMBUS_7_RX");
Zhou Song12c29502019-03-16 10:37:18 +08002201 hw_interface_table[SND_DEVICE_OUT_BT_SCO_SWB] = strdup("SLIMBUS_7_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002202 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
2203 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002204 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
2205 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
2206 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002207 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainc9250dc2019-06-14 12:19:28 +05302208 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = strdup("SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002209 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainc9250dc2019-06-14 12:19:28 +05302210 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = strdup("SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002211 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002212 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
2213 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002214 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("RT_PROXY_DAI_001_RX");
2215 hw_interface_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("RT_PROXY_DAI_001_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05302216 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002217 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
Ashish Jain3e37a702016-11-25 12:27:15 +05302218 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002219 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
2220 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
2221 strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002222 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05302223 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002224 hw_interface_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("SLIMBUS_8_TX");
2225 hw_interface_table[SND_DEVICE_OUT_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
2226 hw_interface_table[SND_DEVICE_OUT_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
2227 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
2228 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
2229 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2230 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2231 hw_interface_table[SND_DEVICE_OUT_ANC_HANDSET] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05302232 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
2233 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002234 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
2235 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
2236 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
Zhou Song12c29502019-03-16 10:37:18 +08002237 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002238 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX");
2239 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX");
Zhou Song12c29502019-03-16 10:37:18 +08002240 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05302241 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = strdup("SLIMBUS_0_RX");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002242 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05302243 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
2244 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
2245 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002246 hw_interface_table[SND_DEVICE_OUT_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
2247 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
2248 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = strdup("SLIMBUS_0_RX");
juyuchen2d415992018-11-16 14:15:16 +08002249 /* So far, primary hal doesn't support hearing aid device.
2250 Need snd_device to route voice call and use specific acdb tuning.
2251 Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */
2252 hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"),
Derek Chenf6318be2017-06-12 17:16:24 -04002253 hw_interface_table[SND_DEVICE_OUT_BUS_MEDIA] = strdup("TERT_TDM_RX_0");
2254 hw_interface_table[SND_DEVICE_OUT_BUS_SYS] = strdup("TERT_TDM_RX_0");
2255 hw_interface_table[SND_DEVICE_OUT_BUS_NAV] = strdup("TERT_TDM_RX_1");
2256 hw_interface_table[SND_DEVICE_OUT_BUS_PHN] = strdup("TERT_TDM_RX_2");
Siena Richard7c2db772016-12-21 11:32:34 -08002257 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002258 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002259 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = strdup("SLIMBUS_0_TX");
2260 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002261 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002262 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002263 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002264 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002265 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002266 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
2267 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002268 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002269 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002270 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002271 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002272 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002273 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2274 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent4b084132018-10-19 17:33:43 -07002275 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002276 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002277 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002278 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002279 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002280 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002281 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002282 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002283 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002284 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
2285 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002286 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002287 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002288 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002289 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002290 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002291 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002292 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
2293 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2294 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002295 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002296 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Ralf Herzafb164f2018-07-03 07:08:07 +02002297 hw_interface_table[SND_DEVICE_IN_SPDIF] = strdup("PRI_SPDIF_TX");
2298 hw_interface_table[SND_DEVICE_IN_HDMI_MIC] = strdup("SEC_MI2S_TX");
2299 hw_interface_table[SND_DEVICE_IN_HDMI_ARC] = strdup("SEC_SPDIF_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002300 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SLIMBUS_7_TX");
2301 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SLIMBUS_7_TX");
2302 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SLIMBUS_7_TX");
2303 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SLIMBUS_7_TX");
Zhou Song12c29502019-03-16 10:37:18 +08002304 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_SWB] = strdup("SLIMBUS_7_TX");
2305 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = strdup("SLIMBUS_7_TX");
Florian Pfister1a84f312018-07-19 14:38:18 +02002306 hw_interface_table[SND_DEVICE_IN_BT_A2DP] = strdup("SLIMBUS_7_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002307 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
2308 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002309 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002310 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002311 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002312 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002313 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07002314 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002315 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = strdup("SLIMBUS_0_TX");
2316 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
2317 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
2318 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002319 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002320 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
2321 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002322 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
2323 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002324 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
2325 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002326 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2327 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2328 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("RT_PROXY_DAI_002_TX");
2329 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002330 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
2331 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
2332 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
2333 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
Karthikeyan Mani07faa602018-08-20 11:01:32 -07002334 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("USB_AUDIO_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002335 hw_interface_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("SLIMBUS_8_TX");
2336 hw_interface_table[SND_DEVICE_IN_AANC_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
2337 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002338 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2339 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002340 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = strdup("SLIMBUS_4_TX");
2341 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = strdup("SLIMBUS_4_TX");
2342 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = strdup("SLIMBUS_4_TX");
2343 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2344 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2345 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2346 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
2347 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
2348 hw_interface_table[SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = strdup("SLIMBUS_0_TX");
2349 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002350 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002351 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC] = strdup("SLIMBUS_0_TX");
2352 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
2353 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
2354 hw_interface_table[SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2355 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05302356 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002357 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05302358 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
2359 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_NS] = strdup("SLIMBUS_0_TX");
2360 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07002361 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC] = strdup("SLIMBUS_0_TX");
2362 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_NS] = strdup("SLIMBUS_0_TX");
2363 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002364 hw_interface_table[SND_DEVICE_IN_VOICE_REC_TMIC] = strdup("SLIMBUS_0_TX");
2365 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
2366 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
2367 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
2368 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
2369 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05302370 hw_interface_table[SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = strdup("SLIMBUS_0_TX");
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05302371 hw_interface_table[SND_DEVICE_IN_INCALL_REC_RX] = strdup("INCALL_RECORD_RX");
2372 hw_interface_table[SND_DEVICE_IN_INCALL_REC_TX] = strdup("INCALL_RECORD_TX");
Ramu Gottipati813ae982018-07-25 14:14:48 +05302373 hw_interface_table[SND_DEVICE_IN_LINE] = strdup("SLIMBUS_0_TX");
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302374 hw_interface_table[SND_DEVICE_OUT_VOIP_HANDSET] = strdup("SLIMBUS_0_RX");
2375 hw_interface_table[SND_DEVICE_OUT_VOIP_SPEAKER] = strdup("SLIMBUS_0_RX");
2376 hw_interface_table[SND_DEVICE_OUT_VOIP_HEADPHONES] = strdup("SLIMBUS_6_RX");
Eric Laurent4b084132018-10-19 17:33:43 -07002377 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2378 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
2379 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2380 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2381 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
juyuchen2d415992018-11-16 14:15:16 +08002382 hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
Derek Chenf6318be2017-06-12 17:16:24 -04002383 hw_interface_table[SND_DEVICE_IN_BUS] = strdup("TERT_TDM_TX_0");
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302384 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302385
2386 /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
Alexy Josephb1379942016-01-29 15:49:38 -08002387 for (count = 0; count < (int32_t)(sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302388 count++) {
2389
2390 if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
2391 strlen(dsp_only_decoders_mime[count]))) {
2392
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002393 if(property_get_bool("vendor.audio.use.sw.alac.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302394 ALOGD("Alac software decoder is available...removing alac from DSP decoder list");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302395 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302396 }
2397 } else if (!strncmp(MEDIA_MIMETYPE_AUDIO_APE, dsp_only_decoders_mime[count],
2398 strlen(dsp_only_decoders_mime[count]))) {
2399
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002400 if(property_get_bool("vendor.audio.use.sw.ape.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302401 ALOGD("APE software decoder is available...removing ape from DSP decoder list");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302402 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302403 }
2404 }
2405 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002406}
2407
Walter Yang6f800052014-07-14 16:15:38 -07002408void get_cvd_version(char *cvd_version, struct audio_device *adev)
2409{
2410 struct mixer_ctl *ctl;
2411 int count;
2412 int ret = 0;
2413
2414 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
2415 if (!ctl) {
2416 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
2417 goto done;
2418 }
2419 mixer_ctl_update(ctl);
2420
2421 count = mixer_ctl_get_num_values(ctl);
2422 if (count > MAX_CVD_VERSION_STRING_SIZE)
Aalique Grahame22e49102018-12-18 14:23:57 -08002423 count = MAX_CVD_VERSION_STRING_SIZE - 1;
Walter Yang6f800052014-07-14 16:15:38 -07002424
2425 ret = mixer_ctl_get_array(ctl, cvd_version, count);
2426 if (ret != 0) {
2427 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
2428 goto done;
2429 }
2430
2431done:
2432 return;
2433}
2434
Anish Kumar55e6df22014-08-26 17:38:05 -07002435static int hw_util_open(int card_no)
2436{
2437 int fd = -1;
2438 char dev_name[256];
2439
2440 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
2441 card_no, WCD9XXX_CODEC_HWDEP_NODE);
2442 ALOGD("%s Opening device %s\n", __func__, dev_name);
2443 fd = open(dev_name, O_WRONLY);
2444 if (fd < 0) {
2445 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
2446 return fd;
2447 }
2448 ALOGD("%s success", __func__);
2449 return fd;
2450}
2451
2452struct param_data {
2453 int use_case;
2454 int acdb_id;
2455 int get_size;
2456 int buff_size;
2457 int data_size;
2458 void *buff;
2459};
2460
Banajit Goswami20cdd212015-09-11 01:11:30 -07002461static int send_vbat_adc_data_to_acdb(struct platform_data *plat_data, char *cal_type)
2462{
2463 int ret = 0;
2464 struct mixer_ctl *ctl;
2465 uint16_t vbat_adc_data[2];
2466 struct platform_data *my_data = plat_data;
2467 struct audio_device *adev = my_data->adev;
2468
2469 const char *mixer_ctl_name = "Vbat ADC data";
2470
2471 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2472 if (!ctl) {
2473 ALOGE("%s: Could not get ctl for mixer ctl name - %s",
2474 __func__, mixer_ctl_name);
2475 ret = -EINVAL;
2476 goto done;
2477 }
2478
2479 vbat_adc_data[0] = mixer_ctl_get_value(ctl, 0);
2480 vbat_adc_data[1] = mixer_ctl_get_value(ctl, 1);
2481
2482 ALOGD("%s: Vbat ADC output values: Dcp1: %d , Dcp2: %d",
2483 __func__, vbat_adc_data[0], vbat_adc_data[1]);
2484
2485 ret = my_data->acdb_set_codec_data(&vbat_adc_data[0], cal_type);
2486
2487done:
2488 return ret;
2489}
2490
2491static void send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
2492 struct platform_data *plat_data, int fd)
Anish Kumar55e6df22014-08-26 17:38:05 -07002493{
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002494 int type;
Anish Kumar55e6df22014-08-26 17:38:05 -07002495
2496 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
2497 struct wcdcal_ioctl_buffer codec_buffer;
2498 struct param_data calib;
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002499 int ret;
Anish Kumar55e6df22014-08-26 17:38:05 -07002500
Bharath Ramachandramurthy63a47ef2015-08-31 17:41:46 -07002501 /* MAD calibration is handled by sound trigger HAL, skip here */
2502 if (type == WCD9XXX_MAD_CAL)
2503 continue;
2504
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002505 ret = 0;
Banajit Goswami20cdd212015-09-11 01:11:30 -07002506
Banajit Goswami4dc87fb2015-10-11 21:46:07 -07002507 if ((plat_data->is_vbat_speaker) && (WCD9XXX_VBAT_CAL == type)) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05302508 /* VBAT BCL speaker does not need tuning data */
2509 if (!plat_data->is_bcl_speaker)
2510 return;
Banajit Goswami20cdd212015-09-11 01:11:30 -07002511 ret = send_vbat_adc_data_to_acdb(plat_data, cal_name_info[type]);
2512 if (ret < 0)
2513 ALOGE("%s error in sending vbat adc data to acdb", __func__);
2514 }
2515
Anish Kumar55e6df22014-08-26 17:38:05 -07002516 calib.get_size = 1;
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002517 ret = acdb_loader_get_calibration(cal_name_info[type],
2518 sizeof(struct param_data),
2519 &calib);
Anish Kumar55e6df22014-08-26 17:38:05 -07002520 if (ret < 0) {
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002521 ALOGE("%s: %s get_calibration size failed, err = %d\n",
2522 __func__, cal_name_info[type], ret);
2523 continue;
Anish Kumar55e6df22014-08-26 17:38:05 -07002524 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002525
Anish Kumar55e6df22014-08-26 17:38:05 -07002526 calib.get_size = 0;
2527 calib.buff = malloc(calib.buff_size);
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002528 if (!calib.buff) {
2529 ALOGE("%s: %s: No Memory for size = %d\n",
2530 __func__, cal_name_info[type], calib.buff_size);
2531 continue;
2532 }
2533
Anish Kumar55e6df22014-08-26 17:38:05 -07002534 ret = acdb_loader_get_calibration(cal_name_info[type],
2535 sizeof(struct param_data), &calib);
2536 if (ret < 0) {
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002537 ALOGE("%s: %s get_calibration failed, err = %d\n",
2538 __func__, cal_name_info[type], ret);
Anish Kumar55e6df22014-08-26 17:38:05 -07002539 free(calib.buff);
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002540 continue;
Anish Kumar55e6df22014-08-26 17:38:05 -07002541 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002542
Anish Kumar55e6df22014-08-26 17:38:05 -07002543 codec_buffer.buffer = calib.buff;
2544 codec_buffer.size = calib.data_size;
2545 codec_buffer.cal_type = type;
2546 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002547 ALOGE("%s: %s Failed to call ioctl, err=%d",
2548 __func__, cal_name_info[type], errno);
2549 else
2550 ALOGD("%s: %s cal sent successfully\n",
2551 __func__, cal_name_info[type]);
2552
Anish Kumar55e6df22014-08-26 17:38:05 -07002553 free(calib.buff);
2554 }
Anish Kumar55e6df22014-08-26 17:38:05 -07002555}
2556
2557static void audio_hwdep_send_cal(struct platform_data *plat_data)
2558{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302559 int fd = plat_data->hw_dep_fd;
Anish Kumar55e6df22014-08-26 17:38:05 -07002560
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302561 if (fd < 0)
2562 fd = hw_util_open(plat_data->adev->snd_card);
Anish Kumar55e6df22014-08-26 17:38:05 -07002563 if (fd == -1) {
2564 ALOGE("%s error open\n", __func__);
2565 return;
2566 }
2567
2568 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
2569 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
2570
2571 if (acdb_loader_get_calibration == NULL) {
2572 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
2573 dlerror());
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302574 if (fd >= 0) {
2575 close(fd);
2576 plat_data->hw_dep_fd = -1;
2577 }
Anish Kumar55e6df22014-08-26 17:38:05 -07002578 return;
2579 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002580
Banajit Goswami20cdd212015-09-11 01:11:30 -07002581 send_codec_cal(acdb_loader_get_calibration, plat_data, fd);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302582 plat_data->hw_dep_fd = fd;
Anish Kumar55e6df22014-08-26 17:38:05 -07002583}
2584
Aditya Bavanari4875a262019-01-17 19:39:59 +05302585const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name)
2586{
2587 const char *acdb_card_name = NULL;
2588 char *substring = NULL;
2589 char string[MAX_SND_CARD_NAME_LENGTH] = {0};
2590 int length = 0;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302591
Aditya Bavanari4875a262019-01-17 19:39:59 +05302592 if (snd_card_name == NULL)
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302593 return NULL;
2594
Aditya Bavanari4875a262019-01-17 19:39:59 +05302595 /* Both tasha & tasha-lite uses tasha ACDB files
2596 simulate sound card name for tasha lite, so that
2597 ACDB module loads tasha ACDB files for tasha lite */
2598 if ((substring = strstr(snd_card_name, "tashalite")) ||
2599 (substring = strstr(snd_card_name, "tasha9326"))) {
2600 ALOGD("%s: using tasha ACDB files for tasha-lite", __func__);
2601 length = substring - snd_card_name + 1;
2602 snprintf(string, length, "%s", snd_card_name);
2603 strlcat(string, "tasha-snd-card", sizeof(string));
2604 acdb_card_name = strdup(string);
2605 return acdb_card_name;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302606 }
Aditya Bavanari4875a262019-01-17 19:39:59 +05302607 acdb_card_name = strdup(snd_card_name);
2608 return acdb_card_name;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302609}
2610
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002611static int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05302612{
2613 struct platform_data *my_data = (struct platform_data *)platform;
2614 char *cvd_version = NULL;
Ramjee Singh203473b2015-06-09 15:18:42 +05302615 const char *snd_card_name;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302616 int result = -1;
2617 struct listnode *node;
2618 struct meta_key_list *key_info;
2619 int key = 0;
2620
Ramjee Singh203473b2015-06-09 15:18:42 +05302621 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302622 if (!cvd_version) {
Ramjee Singh203473b2015-06-09 15:18:42 +05302623 ALOGE("Failed to allocate cvd version");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302624 return -1;
2625 } else {
Ramjee Singh203473b2015-06-09 15:18:42 +05302626 get_cvd_version(cvd_version, my_data->adev);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302627 }
Ramjee Singh203473b2015-06-09 15:18:42 +05302628
Ramjee Singh203473b2015-06-09 15:18:42 +05302629 snd_card_name = mixer_get_name(my_data->adev->mixer);
Weiyin Jiang29c08a42019-04-30 17:11:10 +08002630 snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
Aditya Bavanari6e4faec2019-02-15 18:17:44 +05302631 if (!snd_card_name) {
2632 ALOGE("Failed to get snd_card_name");
2633 goto cleanup;
2634 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302635
Aditya Bavanari29bcea22017-10-03 20:10:35 +05302636 my_data->acdb_init_data.cvd_version = cvd_version;
2637 my_data->acdb_init_data.snd_card_name = strdup(snd_card_name);
2638 my_data->acdb_init_data.meta_key_list = &my_data->acdb_meta_key_list;
2639 if (my_data->acdb_init_v4) {
2640 result = my_data->acdb_init_v4(&my_data->acdb_init_data, ACDB_LOADER_INIT_V4);
2641 } else if (my_data->acdb_init_v3) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302642 result = my_data->acdb_init_v3(snd_card_name, cvd_version,
2643 &my_data->acdb_meta_key_list);
2644 } else if (my_data->acdb_init) {
2645 node = list_head(&my_data->acdb_meta_key_list);
2646 key_info = node_to_item(node, struct meta_key_list, list);
2647 key = key_info->cal_info.nKey;
2648 result = my_data->acdb_init(snd_card_name, cvd_version, key);
2649 }
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05302650
2651 /* Save these variables in platform_data. These will be used
2652 while reloading ACDB files during run time. */
2653 strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
2654 strlcpy(my_data->snd_card_name, snd_card_name,
2655 MAX_SND_CARD_STRING_SIZE);
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05302656
Aditya Bavanari6e4faec2019-02-15 18:17:44 +05302657cleanup:
Ramjee Singh203473b2015-06-09 15:18:42 +05302658 if (cvd_version)
2659 free(cvd_version);
2660 if (!result) {
2661 my_data->is_acdb_initialized = true;
2662 ALOGD("ACDB initialized");
2663 audio_hwdep_send_cal(my_data);
2664 } else {
2665 my_data->is_acdb_initialized = false;
2666 ALOGD("ACDB initialization failed");
2667 }
2668 return result;
2669}
2670
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302671#define MAX_PATH (256)
2672#define THERMAL_SYSFS "/sys/class/thermal"
2673#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
2674#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
2675
2676static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
2677 bool *is_wsa_combo_supported)
2678{
2679 DIR *tdir = NULL;
2680 struct dirent *tdirent = NULL;
2681 int tzn = 0;
2682 char name[MAX_PATH] = {0};
2683 char cwd[MAX_PATH] = {0};
2684 char file[10] = "wsa";
2685 bool found = false;
2686 int wsa_count = 0;
2687
2688 if (!getcwd(cwd, sizeof(cwd)))
2689 return false;
2690
2691 chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
2692 otherwise */
2693 tdir = opendir(THERMAL_SYSFS);
2694 if (!tdir) {
2695 ALOGE("Unable to open %s\n", THERMAL_SYSFS);
2696 return false;
2697 }
2698
2699 while ((tdirent = readdir(tdir))) {
2700 char buf[50];
2701 struct dirent *tzdirent;
2702 DIR *tzdir = NULL;
2703
2704 tzdir = opendir(tdirent->d_name);
2705 if (!tzdir)
2706 continue;
2707 while ((tzdirent = readdir(tzdir))) {
2708 if (strcmp(tzdirent->d_name, "type"))
2709 continue;
2710 snprintf(name, MAX_PATH, TZ_TYPE, tzn);
2711 ALOGD("Opening %s\n", name);
2712 read_line_from_file(name, buf, sizeof(buf));
2713 if (strstr(buf, file)) {
2714 wsa_count++;
2715 /*We support max only two WSA speakers*/
2716 if (wsa_count == 2)
2717 break;
2718 }
2719 tzn++;
2720 }
2721 closedir(tzdir);
2722 }
2723 if (wsa_count > 0){
2724 ALOGD("Found %d WSA present on the platform", wsa_count);
2725 found = true;
2726 *wsaCount = wsa_count;
2727
2728 /* update wsa combo supported flag based on sound card name */
2729 /* wsa combo flag needs to be set to true only for hardware
2730 combinations which has support for both wsa and non-wsa speaker */
2731 *is_wsa_combo_supported = false;
2732 if(snd_card_name) {
2733 if (((!strncmp(snd_card_name, "sdm439-sku1-snd-card",
2734 sizeof("sdm439-sku1-snd-card"))) ||
2735 (!strncmp(snd_card_name, "sdm439-snd-card-mtp",
2736 sizeof("sdm439-snd-card-mtp"))))) {
2737 *is_wsa_combo_supported = true;
2738 }
2739 }
2740 }
2741 closedir(tdir);
2742 chdir(cwd); /* Restore current working dir */
2743 return found;
2744}
2745
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302746static void get_source_mic_type(struct platform_data * my_data)
2747{
2748 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
2749 switch (my_data->max_mic_count) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302750 case 6:
2751 my_data->source_mic_type |= SOURCE_HEX_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302752 case 4:
2753 my_data->source_mic_type |= SOURCE_QUAD_MIC;
2754 case 3:
2755 my_data->source_mic_type |= SOURCE_THREE_MIC;
2756 case 2:
2757 my_data->source_mic_type |= SOURCE_DUAL_MIC;
2758 case 1:
2759 my_data->source_mic_type |= SOURCE_MONO_MIC;
2760 break;
2761 default:
2762 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
2763 __func__, my_data->max_mic_count);
2764 my_data->source_mic_type = SOURCE_MONO_MIC | SOURCE_DUAL_MIC;
2765 break;
2766 }
2767}
2768
Siena Richard7c2db772016-12-21 11:32:34 -08002769/*
2770 * Retrieves the be_dai_name_table from kernel to enable a mapping
2771 * between sound device hw interfaces and backend IDs. This allows HAL to
2772 * specify the backend a specific calibration is needed for.
2773 */
2774static int init_be_dai_name_table(struct audio_device *adev)
2775{
2776 const char *mixer_ctl_name = "Backend DAI Name Table";
2777 struct mixer_ctl *ctl;
2778 int i, j, ret, size;
2779 bool valid_hw_interface;
2780
2781 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2782 if (!ctl) {
2783 ALOGE("%s: Could not get ctl for mixer name %s\n",
2784 __func__, mixer_ctl_name);
2785 ret = -EINVAL;
2786 goto done;
2787 }
2788
2789 mixer_ctl_update(ctl);
2790
2791 size = mixer_ctl_get_num_values(ctl);
2792 if (size <= 0){
2793 ALOGE("%s: Failed to get %s size %d\n",
2794 __func__, mixer_ctl_name, size);
2795 ret = -EFAULT;
2796 goto done;
2797 }
2798
2799 be_dai_name_table =
2800 (const struct be_dai_name_struct *)calloc(1, size);
2801 if (be_dai_name_table == NULL) {
2802 ALOGE("%s: Failed to allocate memory for %s\n",
2803 __func__, mixer_ctl_name);
2804 ret = -ENOMEM;
2805 goto freeMem;
2806 }
2807
2808 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
2809 if (ret) {
2810 ALOGE("%s: Failed to get %s, ret %d\n",
2811 __func__, mixer_ctl_name, ret);
2812 ret = -EFAULT;
2813 goto freeMem;
2814 }
2815
2816 if (be_dai_name_table != NULL) {
2817 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
2818 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
2819 __func__, mixer_ctl_name, max_be_dai_names);
2820 ret = 0;
2821 } else {
2822 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
2823 ret = -EFAULT;
2824 goto freeMem;
2825 }
2826
2827 /*
2828 * Validate all sound devices have a valid backend set to catch
2829 * errors for uncommon sound devices
2830 */
2831 for (i = 0; i < SND_DEVICE_MAX; i++) {
2832 valid_hw_interface = false;
2833
2834 if (hw_interface_table[i] == NULL) {
2835 ALOGW("%s: sound device %s has no hw interface set\n",
2836 __func__, platform_get_snd_device_name(i));
2837 continue;
2838 }
2839
2840 for (j = 0; j < max_be_dai_names; j++) {
2841 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
2842 == 0) {
2843 valid_hw_interface = true;
2844 break;
2845 }
2846 }
2847 if (!valid_hw_interface)
2848 ALOGD("%s: sound device %s does not have a valid hw interface set (disregard for combo devices) %s\n",
2849 __func__, platform_get_snd_device_name(i), hw_interface_table[i]);
2850 }
2851
2852 goto done;
2853
2854freeMem:
2855 if (be_dai_name_table) {
2856 free((void *)be_dai_name_table);
2857 be_dai_name_table = NULL;
2858 }
2859
2860done:
2861 return ret;
2862}
2863
Aalique Grahame22e49102018-12-18 14:23:57 -08002864#ifdef FLICKER_SENSOR_INPUT
2865static void configure_flicker_sensor_input(struct mixer *mixer)
2866{
2867 struct mixer_ctl *ctl;
2868 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
2869 int setting1 = 1;
2870 const char* ctl2 = "CDC_IF TX2 MUX";
2871 const char* setting2 = "DEC2";
2872 const char* ctl3 = "SLIM_1_TX Channels";
2873 const char* setting3 = "One";
2874 const char* ctl4 = "ADC MUX2";
2875 const char* setting4 = "AMIC";
2876 const char* ctl5 = "AMIC MUX2";
2877 const char* setting5 = "ADC1";
2878 const char* ctl6 = "DEC2 Volume";
2879 int setting6 = 84;
2880 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
2881 int setting7 = 1;
2882 const char* ctl8 = "SLIM_1_TX SampleRate";
2883 const char* setting8 = "KHZ_8";
2884
2885 ctl = mixer_get_ctl_by_name(mixer, ctl1);
2886 mixer_ctl_set_value(ctl, 0, setting1);
2887 ctl = mixer_get_ctl_by_name(mixer, ctl2);
2888 mixer_ctl_set_enum_by_string(ctl, setting2);
2889 ctl = mixer_get_ctl_by_name(mixer, ctl3);
2890 mixer_ctl_set_enum_by_string(ctl, setting3);
2891 ctl = mixer_get_ctl_by_name(mixer, ctl4);
2892 mixer_ctl_set_enum_by_string(ctl, setting4);
2893 ctl = mixer_get_ctl_by_name(mixer, ctl5);
2894 mixer_ctl_set_enum_by_string(ctl, setting5);
2895 ctl = mixer_get_ctl_by_name(mixer, ctl6);
2896 mixer_ctl_set_value(ctl, 0, setting6);
2897 ctl = mixer_get_ctl_by_name(mixer, ctl7);
2898 mixer_ctl_set_value(ctl, 0, setting7);
2899 ctl = mixer_get_ctl_by_name(mixer, ctl8);
2900 mixer_ctl_set_enum_by_string(ctl, setting8);
2901}
2902#endif
2903
Eric Laurentb23d5282013-05-14 15:27:20 -07002904void *platform_init(struct audio_device *adev)
2905{
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07002906 char platform[PROPERTY_VALUE_MAX];
2907 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -07002908 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08002909 struct platform_data *my_data = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08002910 char *snd_card_name = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07002911 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
Aalique Grahame22e49102018-12-18 14:23:57 -08002912 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302913 char ffspEnable[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08002914 int idx;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302915 int wsaCount =0;
2916 bool is_wsa_combo_supported = false;
`Deeraj Soman676c2702017-09-18 19:25:53 +05302917 struct mixer_ctl *ctl = NULL;
2918 const char *id_string = NULL;
2919 int cfg_value = -1;
Aalique Grahame22e49102018-12-18 14:23:57 -08002920 bool dual_mic_config = false;
2921 struct snd_card_split *snd_split_handle = NULL;
2922
2923 list_init(&operator_info_list);
2924 list_init(&app_type_entry_list);
sangwoo1b9f4b32013-06-21 18:22:55 -07002925
Arun Mirpurie008ed22019-03-21 11:21:04 -07002926 if(audio_extn_is_concurrent_capture_enabled())
2927 AUDIO_DEVICE_IN_ALL_CODEC_BACKEND = (AUDIO_DEVICE_IN_BUILTIN_MIC | \
2928 AUDIO_DEVICE_IN_BACK_MIC | AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN;
2929 else
2930 AUDIO_DEVICE_IN_ALL_CODEC_BACKEND = (AUDIO_DEVICE_IN_BUILTIN_MIC | \
2931 AUDIO_DEVICE_IN_BACK_MIC | AUDIO_DEVICE_IN_WIRED_HEADSET | \
2932 AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN;
2933
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302934 adev->snd_card = audio_extn_utils_open_snd_mixer(&adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002935 if (adev->snd_card < 0) {
2936 ALOGE("%s: Unable to find correct sound card", __func__);
2937 return NULL;
2938 }
2939 ALOGD("%s: Opened sound card:%d", __func__, adev->snd_card);
Eric Laurentb23d5282013-05-14 15:27:20 -07002940
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002941 snd_card_name = strdup(mixer_get_name(adev->mixer));
2942 if (!snd_card_name) {
2943 ALOGE("failed to allocate memory for snd_card_name\n");
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302944 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002945 return NULL;
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08002946 }
2947
Aalique Grahame22e49102018-12-18 14:23:57 -08002948 audio_extn_set_snd_card_split(snd_card_name);
2949 snd_split_handle = audio_extn_get_snd_card_split();
2950
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002951 my_data = calloc(1, sizeof(struct platform_data));
2952 if (!my_data) {
2953 ALOGE("failed to allocate platform data");
2954 if (snd_card_name)
2955 free(snd_card_name);
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302956 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002957 return NULL;
2958 }
2959
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302960 my_data->is_slimbus_interface = true;
2961 my_data->is_internal_codec = false;
2962
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002963 my_data->hw_info = hw_info_init(snd_card_name);
2964 if (!my_data->hw_info) {
2965 ALOGE("failed to init hw_info");
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302966 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002967 if (my_data)
2968 free(my_data);
2969
2970 if (snd_card_name)
2971 free(snd_card_name);
2972 return NULL;
2973 }
2974
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302975 if (platform_is_i2s_ext_modem(snd_card_name, my_data) &&
2976 !is_auto_snd_card(snd_card_name)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002977 ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
2978
2979 adev->audio_route = audio_route_init(adev->snd_card,
2980 MIXER_XML_PATH_I2S);
2981 } else {
2982 /* Get the codec internal name from the sound card name
2983 * and form the mixer paths file name dynamically. This
2984 * is generic way of picking any codec name based mixer
2985 * files in future with no code change. This code
2986 * assumes mixer files are formed with format as
2987 * mixer_paths_internalcodecname.xml
2988
2989 * If this dynamically read mixer files fails to open then it
2990 * falls back to default mixer file i.e mixer_paths.xml. This is
2991 * done to preserve backward compatibility but not mandatory as
2992 * long as the mixer files are named as per above assumption.
2993 */
Aalique Grahame22e49102018-12-18 14:23:57 -08002994 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
2995 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
2996 snd_split_handle->form_factor);
2997 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
2998 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
2999 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303000 MIXER_XML_BASE_STRING, snd_split_handle->variant);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003001
Aalique Grahame22e49102018-12-18 14:23:57 -08003002 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
3003 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303004 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
3005 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
3006
3007 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
3008 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
3009 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
3010 audio_extn_utils_resolve_config_file(mixer_xml_file);
3011 }
Aalique Grahame22e49102018-12-18 14:23:57 -08003012 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003013 }
3014
Aalique Grahame22e49102018-12-18 14:23:57 -08003015 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
3016 if (audio_extn_read_xml(adev, adev->snd_card, mixer_xml_file,
3017 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
3018 adev->audio_route = audio_route_init(adev->snd_card, mixer_xml_file);
3019 update_codec_type_and_interface(my_data, snd_card_name);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003020 }
3021 }
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303022
3023#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
3024 if (my_data->is_internal_codec == true) {
3025 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
3026 msm_be_id_array_len =
3027 sizeof(msm_device_to_be_id_internal_codec) /
3028 sizeof(msm_device_to_be_id_internal_codec[0]);
3029 } else {
3030 msm_device_to_be_id = msm_device_to_be_id_external_codec;
3031 msm_be_id_array_len =
3032 sizeof(msm_device_to_be_id_external_codec) /
3033 sizeof(msm_device_to_be_id_external_codec[0]);
3034 }
3035#endif
3036
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003037 if (!adev->audio_route) {
3038 ALOGE("%s: Failed to init audio route controls, aborting.",
3039 __func__);
Alexy Josephb1379942016-01-29 15:49:38 -08003040 if (my_data)
3041 free(my_data);
Ravi Kumar Alamanda31c90df2015-10-16 10:06:59 -07003042 if (snd_card_name)
3043 free(snd_card_name);
Soumya Managoli9fee7c62018-04-06 16:21:50 +05303044 audio_extn_utils_close_snd_mixer(adev->mixer);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08003045 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003046 }
3047
Aalique Grahame37659862017-12-03 22:34:26 -08003048 adev->dp_allowed_for_voice =
3049 property_get_bool("vendor.audio.enable.dp.for.voice", false);
3050
Eric Laurentb23d5282013-05-14 15:27:20 -07003051 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003052 my_data->fluence_in_spkr_mode = false;
3053 my_data->fluence_in_voice_call = false;
3054 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08003055 my_data->fluence_in_audio_rec = false;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303056 my_data->fluence_in_hfp_call = false;
Tanya Finkel00130052014-07-14 04:26:56 -07003057 my_data->external_spk_1 = false;
3058 my_data->external_spk_2 = false;
3059 my_data->external_mic = false;
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08003060 my_data->fluence_sb_enabled = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003061 my_data->fluence_type = FLUENCE_NONE;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003062 my_data->fluence_mode = FLUENCE_ENDFIRE;
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303063 my_data->ambisonic_capture = false;
3064 my_data->ambisonic_profile = false;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303065 my_data->slowtalk = false;
3066 my_data->hd_voice = false;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003067 my_data->edid_info = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07003068 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303069 my_data->is_wsa_speaker = false;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303070 my_data->hw_dep_fd = -1;
Rohit kumarf4120402016-08-05 19:19:48 +05303071 my_data->mono_speaker = SPKR_1;
Aalique Grahame5f596f32018-01-09 12:56:35 -08003072 my_data->speaker_lr_swap = false;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07003073 my_data->voice_speaker_stereo = false;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05303074 my_data->declared_mic_count = 0;
Surendar Karka45850ae2018-07-02 17:45:27 +05303075 my_data->spkr_ch_map = NULL;
Dieter Luecking5d57def2018-09-07 14:23:37 +02003076 my_data->use_sprk_default_sample_rate = true;
Aalique Grahame22e49102018-12-18 14:23:57 -08003077 my_data->fluence_in_voice_comm = false;
3078
3079 //set max volume step for voice call
3080 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
3081 my_data->max_vol_index = atoi(value);
3082
Siena Richard7c2db772016-12-21 11:32:34 -08003083 be_dai_name_table = NULL;
3084
Dhananjay Kumardf511452019-08-06 16:31:51 +05303085 property_get("persist.vendor.audio.dualmic.config",value,"");
Aalique Grahame22e49102018-12-18 14:23:57 -08003086 if (!strcmp("endfire", value)) {
3087 dual_mic_config = true;
3088 }
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303089
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08003090 /* Check for Fluence Sub Band Enablement */
3091 if (property_get_bool("ro.vendor.audio.sdk.fluence.subband.enabled",false))
3092 my_data->fluence_sb_enabled = true;
3093
Aalique Grahame22e49102018-12-18 14:23:57 -08003094 my_data->fluence_type = FLUENCE_NONE;
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303095 if (property_get("ro.vendor.audio.sdk.fluencetype",
3096 my_data->fluence_cap, NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003097 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
3098 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303099
Aalique Grahame22e49102018-12-18 14:23:57 -08003100 if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
3101 my_data->fluence_type |= FLUENCE_TRI_MIC;
3102 }
3103 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence")) ||
3104 dual_mic_config) {
3105 my_data->fluence_type = FLUENCE_DUAL_MIC;
3106
3107 if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
3108 my_data->fluence_type |= FLUENCE_TRI_MIC;
3109 }
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303110 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003111 }
3112
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003113 if (my_data->fluence_type != FLUENCE_NONE) {
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303114 if (property_get("persist.vendor.audio.fluence.voicecall",
3115 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003116 if (!strncmp("true", value, sizeof("true")))
3117 my_data->fluence_in_voice_call = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003118 }
3119
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303120 if (property_get("persist.vendor.audio.fluence.voicerec",
3121 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003122 if (!strncmp("true", value, sizeof("true")))
3123 my_data->fluence_in_voice_rec = true;
3124 }
3125
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303126 property_get("persist.vendor.audio.fluence.voicecomm",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003127 if (!strncmp("true", value, sizeof("true"))) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003128 my_data->fluence_in_voice_comm = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003129 }
3130
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003131 property_get("persist.vendor.audio.fluence.audiorec",value,"");
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08003132 if (!strncmp("true", value, sizeof("true"))) {
3133 my_data->fluence_in_audio_rec = true;
3134 }
3135
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303136 if (property_get("persist.vendor.audio.fluence.speaker",
3137 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003138 if (!strncmp("true", value, sizeof("true"))) {
3139 my_data->fluence_in_spkr_mode = true;
3140 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003141 }
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003142
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003143 property_get("persist.vendor.audio.fluence.mode",value,"");
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003144 if (!strncmp("broadside", value, sizeof("broadside"))) {
3145 my_data->fluence_mode = FLUENCE_BROADSIDE;
3146 }
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303147
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003148 property_get("persist.vendor.audio.fluence.hfpcall",value,"");
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303149 if (!strncmp("true", value, sizeof("true"))) {
3150 my_data->fluence_in_hfp_call = true;
3151 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003152 }
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303153 /* Check for Ambisonic Capture Enablement */
Fawad Shaukat42d38e92019-05-08 22:40:54 -07003154 if (property_get_bool("vendor.audio.ambisonic.capture",false))
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303155 my_data->ambisonic_capture = true;
3156
3157 /* Check for Ambisonic Profile Assignment*/
Fawad Shaukat42d38e92019-05-08 22:40:54 -07003158 if (property_get_bool("vendor.audio.ambisonic.auto.profile",false))
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303159 my_data->ambisonic_profile = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003160
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303161 if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)
3162 && audio_extn_is_wsa_enabled()) {
3163 /*Set ACDB ID of Stereo speaker if two WSAs are present*/
3164 /*Default ACDB ID for wsa speaker is that for mono*/
3165 if (wsaCount == 2) {
3166 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
3167 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
3168 }
3169
3170 my_data->is_wsa_speaker = true;
3171
3172 if (is_wsa_combo_supported)
3173 hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
3174
3175 }
Vikram Panduranga8c68e862018-04-27 12:59:42 -07003176 my_data->voice_speaker_stereo =
3177 property_get_bool("persist.vendor.audio.voicecall.speaker.stereo", false);
3178
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303179 property_get("persist.vendor.audio.FFSP.enable", ffspEnable, "");
3180 if (!strncmp("true", ffspEnable, sizeof("true"))) {
3181 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
3182 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
3183 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
3184 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
3185 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
3186 }
3187
Banajit Goswami20cdd212015-09-11 01:11:30 -07003188 /* Check if Vbat speaker enabled property is set, this should be done before acdb init */
3189 bool ret = false;
3190 ret = audio_extn_can_use_vbat();
3191 if (ret)
3192 my_data->is_vbat_speaker = true;
3193
Aditya Bavanari9b589022018-09-20 08:47:55 +05303194 ret = audio_extn_can_use_bcl();
3195 if (ret)
3196 my_data->is_bcl_speaker = true;
3197
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303198 list_init(&my_data->acdb_meta_key_list);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303199 list_init(&my_data->custom_mtmx_params_list);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303200 list_init(&my_data->custom_mtmx_in_params_list);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303201
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303202 ret = audio_extn_is_hifi_audio_supported();
3203 if (ret || !my_data->is_internal_codec)
3204 my_data->hifi_audio = true;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303205 set_platform_defaults(my_data);
3206
3207 /* Initialize ACDB ID's */
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05303208 if (my_data->is_i2s_ext_modem && !is_auto_snd_card(snd_card_name))
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003209 platform_info_init(PLATFORM_INFO_XML_PATH_I2S, my_data, PLATFORM);
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303210 else if (!strncmp(snd_card_name, "sdm660-snd-card-skush",
3211 sizeof("sdm660-snd-card-skush")))
3212 platform_info_init(PLATFORM_INFO_XML_PATH_SKUSH, my_data, PLATFORM);
Walter Yang319c6fe2017-09-21 17:09:39 +08003213 else if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
3214 sizeof("sdm670-skuw-snd-card")))
3215 platform_info_init(PLATFORM_INFO_XML_PATH_SKUW, my_data, PLATFORM);
kunleiz291f3412018-09-04 16:04:44 +08003216 else if (!strncmp(snd_card_name, "sm6150-qrd-snd-card",
3217 sizeof("sm6150-qrd-snd-card")))
3218 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
kunleiz3ae92e52019-04-28 15:35:31 +08003219 else if (!strncmp(snd_card_name, "sm6150-wcd9375qrd-snd-card",
3220 sizeof("sm6150-wcd9375qrd-snd-card")))
3221 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Meng Wangef2f6e12018-10-08 13:06:05 +08003222 else if (!strncmp(snd_card_name, "kona-qrd-snd-card",
3223 sizeof("kona-qrd-snd-card")))
3224 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Vatsal Bucha6339b092019-04-17 16:27:32 +05303225 else if (!strncmp(snd_card_name, "lito-qrd-snd-card",
3226 sizeof("lito-qrd-snd-card")))
3227 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Kunlei Zhang9ea4e4f2019-08-28 15:39:27 +08003228 else if (!strncmp(snd_card_name, "atoll-qrd-snd-card",
3229 sizeof("atoll-qrd-snd-card")))
3230 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Ramu Gottipati54ed9482018-08-21 16:00:22 +05303231 else if (!strncmp(snd_card_name, "qcs405-wsa-snd-card",
3232 sizeof("qcs405-wsa-snd-card")))
3233 platform_info_init(PLATFORM_INFO_XML_PATH_WSA, my_data, PLATFORM);
Dhananjay Kumarb34c5c12018-09-25 16:04:26 +05303234 else if (!strncmp(snd_card_name, "qcs405-tdm-snd-card",
3235 sizeof("qcs405-tdm-snd-card")))
3236 platform_info_init(PLATFORM_INFO_XML_PATH_TDM, my_data, PLATFORM);
Anurag Chouhand9867322020-03-09 13:26:25 +05303237 else if (!strncmp(snd_card_name, "sm8150-pcie-snd-card",
3238 sizeof("sm8150-pcie-snd-card")))
3239 platform_info_init(PLATFORM_INFO_XML_PATH_PCIE, my_data, PLATFORM);
Walter Yang319c6fe2017-09-21 17:09:39 +08003240 else if (my_data->is_internal_codec)
3241 platform_info_init(PLATFORM_INFO_XML_PATH_INTCODEC, my_data, PLATFORM);
Aalique Grahame22e49102018-12-18 14:23:57 -08003242 else {
3243 // Try to load pixel or default
3244 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
3245 platform_info_init(platform_info_file, my_data, PLATFORM);
3246 }
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303247
Dieter Luecking5d57def2018-09-07 14:23:37 +02003248 /* CSRA devices support multiple sample rates via I2S at spkr out */
3249 if (!strncmp(snd_card_name, "qcs405-csra", strlen("qcs405-csra"))) {
3250 ALOGE("%s: soundcard: %s supports multiple sample rates", __func__, snd_card_name);
3251 my_data->use_sprk_default_sample_rate = false;
3252 } else {
3253 my_data->use_sprk_default_sample_rate = true;
3254 ALOGE("%s: soundcard: %s supports only default sample rate", __func__, snd_card_name);
3255 }
3256
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003257 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -07003258 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
3259 if (my_data->acdb_handle == NULL) {
3260 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
3261 } else {
3262 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
3263 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
3264 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003265 if (!my_data->acdb_deallocate)
3266 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
3267 __func__, LIB_ACDB_LOADER);
3268
Eric Laurentb23d5282013-05-14 15:27:20 -07003269 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07003270 "acdb_loader_send_audio_cal_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -07003271 if (!my_data->acdb_send_audio_cal)
Siena Richard7c2db772016-12-21 11:32:34 -08003272 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v2 from %s",
3273 __func__, LIB_ACDB_LOADER);
3274
3275 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
3276 "acdb_loader_send_audio_cal_v3");
3277 if (!my_data->acdb_send_audio_cal_v3)
3278 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07003279 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003280
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05303281 my_data->acdb_send_audio_cal_v4 = (acdb_send_audio_cal_v4_t)dlsym(my_data->acdb_handle,
3282 "acdb_loader_send_audio_cal_v4");
3283 if (!my_data->acdb_send_audio_cal_v4)
3284 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v4 from %s",
3285 __func__, LIB_ACDB_LOADER);
3286
Ben Rombergera04fabc2014-11-14 12:16:03 -08003287 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
3288 "acdb_loader_set_audio_cal_v2");
3289 if (!my_data->acdb_set_audio_cal)
3290 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
3291 __func__, LIB_ACDB_LOADER);
3292
3293 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
3294 "acdb_loader_get_audio_cal_v2");
3295 if (!my_data->acdb_get_audio_cal)
3296 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
3297 __func__, LIB_ACDB_LOADER);
3298
Eric Laurentb23d5282013-05-14 15:27:20 -07003299 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
3300 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003301 if (!my_data->acdb_send_voice_cal)
3302 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
3303 __func__, LIB_ACDB_LOADER);
3304
3305 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
3306 "acdb_loader_reload_vocvoltable");
3307 if (!my_data->acdb_reload_vocvoltable)
3308 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
3309 __func__, LIB_ACDB_LOADER);
3310
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07003311 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
3312 my_data->acdb_handle,
3313 "acdb_loader_get_default_app_type");
3314 if (!my_data->acdb_get_default_app_type)
3315 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3316 __func__, LIB_ACDB_LOADER);
3317
vivek mehtaa76401a2015-04-24 14:12:15 -07003318 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
3319 "acdb_loader_send_gain_dep_cal");
3320 if (!my_data->acdb_send_gain_dep_cal)
3321 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
3322 __func__, LIB_ACDB_LOADER);
3323
Ben Rombergerfeca4b82015-07-07 20:40:44 -07003324 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
3325 my_data->acdb_handle,
3326 "acdb_loader_send_common_custom_topology");
3327 if (!my_data->acdb_send_common_top)
3328 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3329 __func__, LIB_ACDB_LOADER);
3330
Banajit Goswami20cdd212015-09-11 01:11:30 -07003331 my_data->acdb_set_codec_data = (acdb_set_codec_data_t)dlsym(
3332 my_data->acdb_handle,
3333 "acdb_loader_set_codec_data");
3334 if (!my_data->acdb_set_codec_data)
3335 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3336 __func__, LIB_ACDB_LOADER);
3337
3338
Aditya Bavanari29bcea22017-10-03 20:10:35 +05303339 my_data->acdb_init_v4 = (acdb_init_v4_t)dlsym(my_data->acdb_handle,
3340 "acdb_loader_init_v4");
3341 if (my_data->acdb_init_v4 == NULL) {
3342 ALOGE("%s: dlsym error %s for acdb_loader_init_v4", __func__, dlerror());
3343 }
3344
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303345 my_data->acdb_init_v3 = (acdb_init_v3_t)dlsym(my_data->acdb_handle,
3346 "acdb_loader_init_v3");
3347 if (my_data->acdb_init_v3 == NULL) {
3348 ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror());
3349 }
3350
Eric Laurentb23d5282013-05-14 15:27:20 -07003351 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303352 "acdb_loader_init_v3");
Walter Yang6f800052014-07-14 16:15:38 -07003353 if (my_data->acdb_init == NULL) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303354 ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror());
Walter Yang6f800052014-07-14 16:15:38 -07003355 goto acdb_init_fail;
3356 }
3357
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303358 my_data->acdb_reload_v2 = (acdb_reload_v2_t)dlsym(my_data->acdb_handle,
3359 "acdb_loader_reload_acdb_files_v2");
3360 if (my_data->acdb_reload_v2 == NULL) {
3361 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files_v2", __func__, dlerror());
3362 }
3363
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05303364 my_data->acdb_reload = (acdb_reload_t)dlsym(my_data->acdb_handle,
3365 "acdb_loader_reload_acdb_files");
3366 if (my_data->acdb_reload == NULL) {
3367 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files", __func__, dlerror());
3368 goto acdb_init_fail;
3369 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003370
Soumya Managoli9fee7c62018-04-06 16:21:50 +05303371 int result = acdb_init_v2(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003372 if (!result) {
3373 my_data->is_acdb_initialized = true;
3374 ALOGD("ACDB initialized");
3375 audio_hwdep_send_cal(my_data);
3376 } else {
3377 my_data->is_acdb_initialized = false;
3378 ALOGD("ACDB initialization failed");
3379 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003380 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05303381 /* init keep-alive for compress passthru */
3382 audio_extn_keep_alive_init(adev);
Aalique Grahame22e49102018-12-18 14:23:57 -08003383
3384#ifdef FLICKER_SENSOR_INPUT
3385 configure_flicker_sensor_input(adev->mixer);
3386#endif
3387
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05303388#ifdef DYNAMIC_LOG_ENABLED
3389 log_utils_init();
3390#endif
Walter Yang6f800052014-07-14 16:15:38 -07003391acdb_init_fail:
3392
Ben Romberger55886882014-01-10 13:49:02 -08003393
Siena Richard7c2db772016-12-21 11:32:34 -08003394 /*
3395 * Get the be_dai_name_table from kernel which provides a mapping
3396 * between a backend string name and a backend ID
3397 */
3398 init_be_dai_name_table(adev);
3399
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08003400 if (audio_extn_can_use_ras()) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003401 if (property_get_bool("persist.vendor.audio.speaker.prot.enable", false)) {
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08003402 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED,
3403 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS]);
3404 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT,
3405 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS]);
3406 } else {
3407 ALOGD("%s: RAS Feature should be enabled with Speaker Protection", __func__);
3408 }
3409 }
3410
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07003411 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
3412 * symbols. Voice call is handled by MDM and apps processor talks to
3413 * MDM through CSD Client
3414 */
3415 property_get("ro.board.platform", platform, "");
3416 property_get("ro.baseband", baseband, "");
Josh Kirschc3894372016-03-28 15:59:48 -07003417 if ((!strncmp("apq8084", platform, sizeof("apq8084")) ||
Xiaoyu Yec494c752017-11-02 18:52:48 -07003418 !strncmp("msm8996", platform, sizeof("msm8996")) ||
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05303419 !strncmp("sm6150", platform, sizeof("sm6150")) ||
Pallavi Mishra5627c162020-02-15 19:00:40 +05303420 (!strncmp("msmnile", platform, sizeof("msmnile")) &&
Pallavi4ecf0c62020-02-26 11:58:55 +05303421 !strncmp("sm8150-hana55-snd-card", snd_card_name, sizeof("sm8150-hana55-snd-card"))) ||
Anurag Chouhand9867322020-03-09 13:26:25 +05303422 (!strncmp("msmnile", platform, sizeof("msmnile")) &&
3423 !strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) ||
Josh Kirschf20adbf2018-03-06 16:26:22 -08003424 !strncmp("sdx", platform, sizeof("sdx")) ||
3425 !strncmp("sdm845", platform, sizeof("sdm845"))) &&
3426 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
3427 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) {
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07003428 my_data->csd = open_csd_client(my_data->is_i2s_ext_modem);
3429 } else {
3430 my_data->csd = NULL;
3431 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08003432
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303433 /* obtain source mic type from max mic count*/
3434 get_source_mic_type(my_data);
3435 ALOGD("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08003436 " fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) fluence_in_hfp_call(%d)"
3437 "fluence_sb_enabled(%d)", __func__, my_data->fluence_type, my_data->max_mic_count,
3438 my_data->source_mic_type, my_data->fluence_in_voice_call,
3439 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode,
3440 my_data->fluence_in_hfp_call, my_data->fluence_sb_enabled);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303441
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07003442 /* init usb */
3443 audio_extn_usb_init(adev);
3444
Naresh Tanniru9d027a62015-03-13 01:32:10 +05303445 /*init a2dp*/
3446 audio_extn_a2dp_init(adev);
3447
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003448 /* init dap hal */
3449 audio_extn_dap_hal_init(adev->snd_card);
3450
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003451 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -08003452 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -07003453 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05303454
Aalique Grahame22e49102018-12-18 14:23:57 -08003455 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05303456
Lior Barenboim0b61bc72014-05-13 13:01:37 +03003457 /* init audio device arbitration */
3458 audio_extn_dev_arbi_init();
3459
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303460 default_rx_backend = strdup("SLIMBUS_0_RX");
3461
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08003462 /* initialize backend config */
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003463 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
3464 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3465 if (idx == HEADPHONE_44_1_BACKEND)
3466 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
3467 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jainb26edfb2016-08-25 00:10:11 +05303468 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Kuirong Wang0b947f72016-09-29 11:03:09 -07003469 if (idx > MAX_RX_CODEC_BACKENDS)
3470 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05303471 my_data->current_backend_cfg[idx].format = AUDIO_FORMAT_PCM;
Ashish Jainb26edfb2016-08-25 00:10:11 +05303472 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
3473 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
3474 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08003475 }
3476
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003477 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3478 strdup("SLIM_0_RX Format");
3479 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3480 strdup("SLIM_0_RX SampleRate");
3481
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05303482 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].bitwidth_mixer_ctl =
3483 strdup("SLIM_2_RX Format");
3484 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].samplerate_mixer_ctl =
3485 strdup("SLIM_2_RX SampleRate");
3486
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003487 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
3488 strdup("SLIM_5_RX Format");
3489 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
3490 strdup("SLIM_5_RX SampleRate");
3491
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303492 if (!my_data->is_slimbus_interface) {
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303493 //TODO:: make generic interfaceface to check Slimbus/I2S/CDC_DMA
Meng Wangef2f6e12018-10-08 13:06:05 +08003494 if (!strncmp(snd_card_name, "sm6150", strlen("sm6150")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05303495 !strncmp(snd_card_name, "kona", strlen("kona")) ||
Vatsal Bucha6339b092019-04-17 16:27:32 +05303496 !strncmp(snd_card_name, "lito", strlen("lito")) ||
Faiz Nabi Kuchay536d7b92019-08-05 20:36:31 +05303497 !strncmp(snd_card_name, "atoll", strlen("atoll")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05303498 !strncmp(snd_card_name, "trinket", strlen("trinket"))) {
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303499 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3500 strdup("WSA_CDC_DMA_RX_0 Format");
3501 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3502 strdup("WSA_CDC_DMA_RX_0 SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303503 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3504 strdup("TX_CDC_DMA_TX_3 Format");
3505 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3506 strdup("TX_CDC_DMA_TX_3 SampleRate");
3507 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3508 strdup("RX_CDC_DMA_RX_0 Format");
3509 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3510 strdup("RX_CDC_DMA_RX_0 SampleRate");
Zhou Songfa2ea2c2019-05-24 22:48:41 +08003511 /*
3512 * TODO: enable CONCURRENT_CAPTURE_ENABLED flag only if separate backend
3513 * is defined for headset-mic. This is to capture separate data from
3514 * headset-mic and handset-mic.
3515 */
3516 if(audio_extn_is_concurrent_capture_enabled()) {
3517 my_data->current_backend_cfg[HEADSET_TX_BACKEND].bitwidth_mixer_ctl =
3518 strdup("TX_CDC_DMA_TX_4 Format");
3519 my_data->current_backend_cfg[HEADSET_TX_BACKEND].samplerate_mixer_ctl =
3520 strdup("TX_CDC_DMA_TX_4 SampleRate");
3521 }
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303522
3523 if (default_rx_backend)
3524 free(default_rx_backend);
3525 default_rx_backend = strdup("WSA_CDC_DMA_RX_0");
3526 } else if (!strncmp(snd_card_name, "sdm660", strlen("sdm660")) ||
Sachin Mohan Gadageffd7562018-02-13 17:10:09 +05303527 !strncmp(snd_card_name, "sdm670", strlen("sdm670")) ||
3528 !strncmp(snd_card_name, "qcs605", strlen("qcs605"))) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303529
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303530
3531 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3532 strdup("INT4_MI2S_RX Format");
3533 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3534 strdup("INT4_MI2S_RX SampleRate");
3535
3536 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3537 strdup("INT3_MI2S_TX Format");
3538 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3539 strdup("INT3_MI2S_TX SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303540 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3541 strdup("INT0_MI2S_RX Format");
3542 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3543 strdup("INT0_MI2S_RX SampleRate");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303544
3545 if (default_rx_backend)
3546 free(default_rx_backend);
3547 default_rx_backend = strdup("INT4_MI2S_RX");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303548 } else {
3549 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3550 strdup("MI2S_RX Format");
3551 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3552 strdup("MI2S_RX SampleRate");
3553 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].channels_mixer_ctl =
3554 strdup("MI2S_RX Channels");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303555 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3556 strdup("MI2S_TX Format");
3557 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3558 strdup("MI2S_TX SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303559 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3560 strdup("INT0_MI2S_RX Format");
3561 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3562 strdup("INT0_MI2S_RX SampleRate");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303563 }
Revathi Uddaraju75843112017-11-30 14:30:47 +05303564 } else {
Dhananjay Kumar75c9a0c2018-06-07 15:59:00 +05303565 if (!strncmp(snd_card_name, "qcs405", strlen("qcs405"))) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303566
Dieter Luecking5d57def2018-09-07 14:23:37 +02003567 if (!strncmp(snd_card_name, "qcs405-csra", strlen("qcs405-csra"))) {
3568 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3569 strdup("PRIM_MI2S_RX Format");
3570 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3571 strdup("PRIM_MI2S_RX SampleRate");
3572 } else {
3573 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3574 strdup("WSA_CDC_DMA_RX_0 Format");
3575 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3576 strdup("WSA_CDC_DMA_RX_0 SampleRate");
3577 }
Dhananjay Kumar75c9a0c2018-06-07 15:59:00 +05303578 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3579 strdup("VA_CDC_DMA_TX_0 Format");
3580 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3581 strdup("VA_CDC_DMA_TX_0 SampleRate");
3582 } else {
3583 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3584 strdup("SLIM_0_TX Format");
3585 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3586 strdup("SLIM_0_TX SampleRate");
3587 }
Yung Ti Suc06f6772018-10-05 15:43:40 +08003588
3589 if (strstr(snd_card_name, "intcodec")) {
3590 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3591 strdup("INT0_MI2S_RX Format");
3592 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3593 strdup("INT0_MI2S_RX SampleRate");
3594 } else {
3595 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3596 strdup("SLIM_6_RX Format");
3597 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3598 strdup("SLIM_6_RX SampleRate");
3599 }
3600
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303601 //NOTE: enable CONCURRENT_CAPTURE_ENABLED flag only if separate backend is defined
Samyak Jainb3f3ca52019-01-02 18:24:35 +05303602 //for headset-mic. This is to capture separate data from headset-mic and handset-mic.
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303603 if(audio_extn_is_concurrent_capture_enabled()) {
Arun Mirpurie008ed22019-03-21 11:21:04 -07003604 my_data->current_backend_cfg[HEADSET_TX_BACKEND].bitwidth_mixer_ctl =
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303605 strdup("SLIM_1_TX Format");
Arun Mirpurie008ed22019-03-21 11:21:04 -07003606 my_data->current_backend_cfg[HEADSET_TX_BACKEND].samplerate_mixer_ctl =
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303607 strdup("SLIM_1_TX SampleRate");
3608 }
Revathi Uddaraju75843112017-11-30 14:30:47 +05303609 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05303610
Kuirong Wang0b947f72016-09-29 11:03:09 -07003611 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
Kuirong Wange9894162016-08-26 15:16:39 -07003612 strdup("USB_AUDIO_TX Format");
Kuirong Wang0b947f72016-09-29 11:03:09 -07003613 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
Kuirong Wange9894162016-08-26 15:16:39 -07003614 strdup("USB_AUDIO_TX SampleRate");
Kuirong Wang0b947f72016-09-29 11:03:09 -07003615 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
3616 strdup("USB_AUDIO_TX Channels");
Kuirong Wange9894162016-08-26 15:16:39 -07003617
Ralf Herzafb164f2018-07-03 07:08:07 +02003618 if (!strncmp(platform_get_snd_device_backend_interface(SND_DEVICE_IN_HDMI_MIC),
3619 "SEC_MI2S_TX", sizeof("SEC_MI2S_TX"))) {
3620 my_data->current_backend_cfg[HDMI_TX_BACKEND].bitwidth_mixer_ctl =
3621 strdup("SEC_MI2S_TX Format");
3622 my_data->current_backend_cfg[HDMI_TX_BACKEND].samplerate_mixer_ctl =
3623 strdup("SEC_MI2S_TX SampleRate");
3624 my_data->current_backend_cfg[HDMI_TX_BACKEND].channels_mixer_ctl =
3625 strdup("SEC_MI2S_TX Channels");
3626 } else {
3627 my_data->current_backend_cfg[HDMI_TX_BACKEND].bitwidth_mixer_ctl =
3628 strdup("QUAT_MI2S_TX Format");
3629 my_data->current_backend_cfg[HDMI_TX_BACKEND].samplerate_mixer_ctl =
3630 strdup("QUAT_MI2S_TX SampleRate");
3631 my_data->current_backend_cfg[HDMI_TX_BACKEND].channels_mixer_ctl =
3632 strdup("QUAT_MI2S_TX Channels");
3633 }
3634
3635 my_data->current_backend_cfg[SPDIF_TX_BACKEND].bitwidth_mixer_ctl =
3636 strdup("PRIM_SPDIF_TX Format");
3637 my_data->current_backend_cfg[SPDIF_TX_BACKEND].samplerate_mixer_ctl =
3638 strdup("PRIM_SPDIF_TX SampleRate");
3639 my_data->current_backend_cfg[SPDIF_TX_BACKEND].channels_mixer_ctl =
3640 strdup("PRIM_SPDIF_TX Channels");
3641
3642 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].bitwidth_mixer_ctl =
3643 strdup("SEC_SPDIF_TX Format");
3644 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].samplerate_mixer_ctl =
3645 strdup("SEC_SPDIF_TX SampleRate");
3646 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].channels_mixer_ctl =
3647 strdup("SEC_SPDIF_TX Channels");
Siddartha Shaik44dd7702017-06-14 12:13:25 +05303648
mpang00a03542018-11-01 17:05:19 +08003649 my_data->current_backend_cfg[HDMI_RX_BACKEND].bitwidth_mixer_ctl =
3650 strdup("HDMI_RX Bit Format");
3651 my_data->current_backend_cfg[HDMI_RX_BACKEND].samplerate_mixer_ctl =
3652 strdup("HDMI_RX SampleRate");
3653 my_data->current_backend_cfg[HDMI_RX_BACKEND].channels_mixer_ctl =
3654 strdup("HDMI_RX Channels");
3655 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].bitwidth_mixer_ctl =
3656 strdup("Display Port RX Bit Format");
3657 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].samplerate_mixer_ctl =
3658 strdup("Display Port RX SampleRate");
3659 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].channels_mixer_ctl =
3660 strdup("Display Port RX Channels");
3661
3662 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
3663 strdup("USB_AUDIO_RX Format");
3664 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
3665 strdup("USB_AUDIO_RX SampleRate");
3666 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
3667 strdup("USB_AUDIO_RX Channels");
3668
`Deeraj Soman676c2702017-09-18 19:25:53 +05303669 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
3670 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
3671 ctl = mixer_get_ctl_by_name(adev->mixer,
3672 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
3673 id_string = platform_get_mixer_control(ctl);
3674 if (id_string) {
3675 cfg_value = audio_extn_utils_get_bit_width_from_string(id_string);
3676 if (cfg_value > 0)
3677 my_data->current_backend_cfg[idx].bit_width = cfg_value;
3678 }
3679 }
3680
3681 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
3682 ctl = mixer_get_ctl_by_name(adev->mixer,
3683 my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
3684 id_string = platform_get_mixer_control(ctl);
3685 if (id_string) {
3686 cfg_value = audio_extn_utils_get_sample_rate_from_string(id_string);
3687 if (cfg_value > 0)
3688 my_data->current_backend_cfg[idx].sample_rate = cfg_value;
3689 }
3690 }
3691
3692 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
3693 ctl = mixer_get_ctl_by_name(adev->mixer,
3694 my_data->current_backend_cfg[idx].channels_mixer_ctl);
3695 id_string = platform_get_mixer_control(ctl);
3696 if (id_string) {
3697 cfg_value = audio_extn_utils_get_channels_from_string(id_string);
3698 if (cfg_value > 0)
3699 my_data->current_backend_cfg[idx].channels = cfg_value;
3700 }
3701 }
3702 }
3703
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +05303704 ret = audio_extn_utils_get_codec_variant(my_data->adev->snd_card,
3705 my_data->codec_variant);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303706 ret = audio_extn_utils_get_codec_version(snd_card_name,
3707 my_data->adev->snd_card,
3708 my_data->codec_version);
3709
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05303710 /* WCD9370 codec variant only supports Class AB power mode */
3711 if (strstr(my_data->codec_variant, "WCD9370")) {
3712 my_data->is_cls_ab_only_supported = true;
3713 }
3714
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303715 if (NATIVE_AUDIO_MODE_INVALID != platform_get_native_support()) {
3716 /*
3717 * Native playback is enabled from the UI.
3718 */
3719 if(strstr(snd_card_name, "tasha")) {
3720 if (strstr(my_data->codec_version, "WCD9335_1_0") ||
3721 strstr(my_data->codec_version, "WCD9335_1_1")) {
3722 ALOGD("%s:napb: TASHA 1.0 or 1.1 only SRC mode is supported",
3723 __func__);
3724 platform_set_native_support(NATIVE_AUDIO_MODE_SRC);
3725 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303726 }
Ashish Jain4826f6c2017-02-06 13:33:20 +05303727 if (strstr(snd_card_name, "tavil")) {
3728 ALOGD("%s:DSD playback is supported", __func__);
3729 my_data->is_dsd_supported = true;
3730 my_data->is_asrc_supported = true;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05303731 platform_set_native_support(NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC);
Ashish Jain4826f6c2017-02-06 13:33:20 +05303732 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05303733 }
3734
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05303735 if (property_get_bool("vendor.audio.apptype.multirec.enabled", false))
3736 my_data->use_generic_handset = true;
3737
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05303738 /* Initialize keep alive for HDMI/loopback silence */
3739 audio_extn_keep_alive_init(adev);
3740
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003741 my_data->edid_info = NULL;
Sudheer Papothi4e0ea9a2015-09-30 06:57:51 +05303742 free(snd_card_name);
Eric Laurentb23d5282013-05-14 15:27:20 -07003743 return my_data;
3744}
3745
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303746struct audio_custom_mtmx_params *
3747 platform_get_custom_mtmx_params(void *platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303748 struct audio_custom_mtmx_params_info *info,
3749 uint32_t *idx)
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303750{
3751 struct platform_data *my_data = (struct platform_data *)platform;
3752 struct listnode *node = NULL;
3753 struct audio_custom_mtmx_params *params = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303754 int i = 0;
3755
3756 if (!info || !idx) {
3757 ALOGE("%s: Invalid params", __func__);
3758 return NULL;
3759 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303760
3761 list_for_each(node, &my_data->custom_mtmx_params_list) {
3762 params = node_to_item(node, struct audio_custom_mtmx_params, list);
3763 if (params &&
3764 params->info.id == info->id &&
3765 params->info.ip_channels == info->ip_channels &&
3766 params->info.op_channels == info->op_channels &&
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303767 params->info.snd_device == info->snd_device) {
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303768 while (params->info.usecase_id[i] != 0) {
3769 if (params->info.usecase_id[i] == info->usecase_id[0]) {
3770 ALOGV("%s: found params with ip_ch %d op_ch %d uc_id %d snd_dev %d",
3771 __func__, info->ip_channels, info->op_channels,
3772 info->usecase_id[0], info->snd_device);
3773 *idx = i;
3774 return params;
3775 }
3776 i++;
3777 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303778 }
3779 }
3780 ALOGI("%s: no matching param with id %d ip_ch %d op_ch %d uc_id %d snd_dev %d",
3781 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303782 info->usecase_id[0], info->snd_device);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303783 return NULL;
3784}
3785
3786int platform_add_custom_mtmx_params(void *platform,
3787 struct audio_custom_mtmx_params_info *info)
3788{
3789 struct platform_data *my_data = (struct platform_data *)platform;
3790 struct audio_custom_mtmx_params *params = NULL;
3791 uint32_t size = sizeof(*params);
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303792 int i = 0;
3793
3794 if (!info) {
3795 ALOGE("%s: Invalid params", __func__);
3796 return -EINVAL;
3797 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303798
3799 if (info->ip_channels > AUDIO_CHANNEL_COUNT_MAX ||
3800 info->op_channels > AUDIO_CHANNEL_COUNT_MAX) {
3801 ALOGE("%s: unusupported channels in %d, out %d",
3802 __func__, info->ip_channels, info->op_channels);
3803 return -EINVAL;
3804 }
3805
3806 size += sizeof(params->coeffs[0]) * info->ip_channels * info->op_channels;
3807 params = (struct audio_custom_mtmx_params *) calloc(1, size);
3808 if (!params) {
3809 ALOGE("%s: failed to add custom mtmx params", __func__);
3810 return -ENOMEM;
3811 }
3812
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303813 ALOGI("%s: adding mtmx params with id %d ip_ch %d op_ch %d snd_dev %d",
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303814 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303815 info->snd_device);
3816 while (info->usecase_id[i] != 0) {
3817 ALOGI("%s: supported usecase ids for added mtmx params %d",
3818 __func__, info->usecase_id[i]);
3819 i++;
3820 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303821
3822 params->info = *info;
3823 list_add_tail(&my_data->custom_mtmx_params_list, &params->list);
3824 return 0;
3825}
3826
3827static void platform_release_custom_mtmx_params(void *platform)
3828{
3829 struct platform_data *my_data = (struct platform_data *)platform;
3830 struct listnode *node = NULL, *tempnode = NULL;
3831
3832 list_for_each_safe(node, tempnode, &my_data->custom_mtmx_params_list) {
3833 list_remove(node);
3834 free(node_to_item(node, struct audio_custom_mtmx_params, list));
3835 }
3836}
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303837
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303838struct audio_custom_mtmx_in_params *platform_get_custom_mtmx_in_params(void *platform,
3839 struct audio_custom_mtmx_in_params_info *info)
3840{
3841 struct platform_data *my_data = (struct platform_data *)platform;
3842 struct listnode *node = NULL;
3843 struct audio_custom_mtmx_in_params *params = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303844 int i = 0;
3845
3846 if (!info) {
3847 ALOGE("%s: Invalid params", __func__);
3848 return NULL;
3849 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303850
3851 list_for_each(node, &my_data->custom_mtmx_in_params_list) {
3852 params = node_to_item(node, struct audio_custom_mtmx_in_params, list);
3853 if (params &&
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303854 params->in_info.op_channels == info->op_channels) {
3855 while (params->in_info.usecase_id[i] != 0) {
3856 if (params->in_info.usecase_id[i] == info->usecase_id[0]) {
3857 ALOGV("%s: found params with op_ch %d uc_id %d",
3858 __func__, info->op_channels, info->usecase_id[0]);
3859 return params;
3860 }
3861 i++;
3862 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303863 }
3864 }
3865
3866 ALOGI("%s: no matching param with op_ch %d uc_id %d",
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303867 __func__, info->op_channels, info->usecase_id[0]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303868 return NULL;
3869}
3870
3871int platform_add_custom_mtmx_in_params(void *platform,
3872 struct audio_custom_mtmx_in_params_info *info)
3873{
3874 struct platform_data *my_data = (struct platform_data *)platform;
3875 struct audio_custom_mtmx_in_params *params = NULL;
3876 uint32_t size = sizeof(*params);
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303877 int i = 0;
3878
3879 if (!info) {
3880 ALOGE("%s: Invalid params", __func__);
3881 return -EINVAL;
3882 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303883
3884 if (info->op_channels > AUDIO_CHANNEL_COUNT_MAX) {
3885 ALOGE("%s: unusupported channels in %d", __func__, info->op_channels);
3886 return -EINVAL;
3887 }
3888
3889 params = (struct audio_custom_mtmx_in_params *)calloc(1, size);
3890 if (!params) {
3891 ALOGE("%s: failed to add custom mtmx in params", __func__);
3892 return -ENOMEM;
3893 }
3894
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303895 ALOGI("%s: adding mtmx in params with op_ch %d",
3896 __func__, info->op_channels);
3897
3898 while (info->usecase_id[i] != 0) {
3899 ALOGI("%s: supported usecase ids for added mtmx in params %d",
3900 __func__, info->usecase_id[i]);
3901 i++;
3902 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303903
3904 params->in_info = *info;
3905 list_add_tail(&my_data->custom_mtmx_in_params_list, &params->list);
3906 return 0;
3907}
3908
3909static void platform_release_custom_mtmx_in_params(void *platform)
3910{
3911 struct platform_data *my_data = (struct platform_data *)platform;
3912 struct listnode *node = NULL, *tempnode = NULL;
3913
3914 list_for_each_safe(node, tempnode, &my_data->custom_mtmx_in_params_list) {
3915 list_remove(node);
3916 free(node_to_item(node, struct audio_custom_mtmx_in_params, list));
3917 }
3918}
3919
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05303920void platform_release_acdb_metainfo_key(void *platform)
3921{
3922 struct platform_data *my_data = (struct platform_data *)platform;
3923 struct listnode *node, *tempnode;
3924
3925 list_for_each_safe(node, tempnode, &my_data->acdb_meta_key_list) {
3926 list_remove(node);
3927 free(node_to_item(node, struct meta_key_list, list));
3928 }
3929}
3930
Eric Laurentb23d5282013-05-14 15:27:20 -07003931void platform_deinit(void *platform)
3932{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003933 struct platform_data *my_data = (struct platform_data *)platform;
Aalique Grahame22e49102018-12-18 14:23:57 -08003934 struct operator_info *info_item;
3935 struct operator_specific_device *device_item;
Carter Hsu32a62362018-10-15 15:01:42 -07003936 struct external_specific_device *ext_dev;
Aalique Grahame22e49102018-12-18 14:23:57 -08003937 struct app_type_entry *ap;
3938 struct listnode *node;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003939
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05303940 audio_extn_keep_alive_deinit();
3941
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003942 if (my_data->edid_info) {
3943 free(my_data->edid_info);
3944 my_data->edid_info = NULL;
3945 }
3946
Siena Richard7c2db772016-12-21 11:32:34 -08003947 if (be_dai_name_table) {
3948 free((void *)be_dai_name_table);
3949 be_dai_name_table = NULL;
3950 }
3951
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303952 if (my_data->hw_dep_fd >= 0) {
3953 close(my_data->hw_dep_fd);
3954 my_data->hw_dep_fd = -1;
3955 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303956 if (default_rx_backend)
3957 free(default_rx_backend);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303958
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003959 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08003960 close_csd_client(my_data->csd);
3961
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003962 int32_t dev;
3963 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303964 if (backend_tag_table[dev]) {
3965 free(backend_tag_table[dev]);
3966 backend_tag_table[dev]= NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003967 }
Aalique Grahame22e49102018-12-18 14:23:57 -08003968
3969 if (hw_interface_table[dev]) {
3970 free(hw_interface_table[dev]);
3971 hw_interface_table[dev] = NULL;
3972 }
3973
3974 if (operator_specific_device_table[dev]) {
3975 while (!list_empty(operator_specific_device_table[dev])) {
3976 node = list_head(operator_specific_device_table[dev]);
3977 list_remove(node);
3978 device_item = node_to_item(node,
3979 struct operator_specific_device, list);
3980 free(device_item->operator);
3981 device_item->operator = NULL;
3982 free(device_item->mixer_path);
3983 device_item->mixer_path = NULL;
3984 free(device_item);
3985 device_item = NULL;
3986 }
3987 free(operator_specific_device_table[dev]);
3988 operator_specific_device_table[dev] = NULL;
3989 }
Carter Hsu32a62362018-10-15 15:01:42 -07003990
3991 if (external_specific_device_table[dev]) {
3992 while (!list_empty(external_specific_device_table[dev])) {
3993 node = list_head(external_specific_device_table[dev]);
3994 list_remove(node);
3995 ext_dev = node_to_item(node, struct external_specific_device, list);
3996 free(ext_dev->usbid);
3997 free(ext_dev);
3998 }
3999 free(external_specific_device_table[dev]);
4000 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004001 }
4002
Aalique Grahame22e49102018-12-18 14:23:57 -08004003 while (!list_empty(&operator_info_list)) {
4004 node = list_head(&operator_info_list);
4005 list_remove(node);
4006 info_item = node_to_item(node, struct operator_info, list);
4007 free(info_item->name);
4008 info_item->name = NULL;
4009 free(info_item->mccmnc);
4010 info_item->mccmnc = NULL;
4011 free(info_item);
4012 info_item = NULL;
4013 }
4014
4015 while (!list_empty(&app_type_entry_list)) {
4016 node = list_head(&app_type_entry_list);
4017 list_remove(node);
4018 ap = node_to_item(node, struct app_type_entry, node);
4019 if (ap->mode) {
4020 free(ap->mode);
4021 ap->mode = NULL;
4022 }
4023 free(ap);
4024 ap = NULL;
4025 }
4026
Lior Barenboim0b61bc72014-05-13 13:01:37 +03004027 /* deinit audio device arbitration */
4028 audio_extn_dev_arbi_deinit();
4029
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004030 if (my_data->edid_info) {
4031 free(my_data->edid_info);
4032 my_data->edid_info = NULL;
4033 }
4034
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05304035 if (my_data->adev->mixer) {
Soumya Managoli9fee7c62018-04-06 16:21:50 +05304036 audio_extn_utils_close_snd_mixer(my_data->adev->mixer);
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05304037 my_data->adev->mixer = NULL;
4038 }
4039
Naresh Tannirucb5b5782018-10-12 20:42:07 +05304040
4041
Surendar Karka45850ae2018-07-02 17:45:27 +05304042 if (my_data->spkr_ch_map) {
4043 free(my_data->spkr_ch_map);
4044 my_data->spkr_ch_map = NULL;
4045 }
4046
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05304047 int32_t idx;
4048
4049 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
4050 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
4051 free(my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
4052 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
4053 }
4054
4055 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
4056 free(my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
4057 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
4058 }
4059
4060 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
4061 free(my_data->current_backend_cfg[idx].channels_mixer_ctl);
4062 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
4063 }
4064 }
4065
4066 /* free acdb_meta_key_list */
4067 platform_release_acdb_metainfo_key(platform);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05304068 platform_release_custom_mtmx_params(platform);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05304069 platform_release_custom_mtmx_in_params(platform);
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05304070
Aditya Bavanaric1c1ba62018-06-08 16:33:43 +05304071 if (my_data->acdb_deallocate)
4072 my_data->acdb_deallocate();
4073
Eric Laurentb23d5282013-05-14 15:27:20 -07004074 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07004075 /* deinit usb */
4076 audio_extn_usb_deinit();
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004077 audio_extn_dap_hal_deinit();
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05304078#ifdef DYNAMIC_LOG_ENABLED
4079 log_utils_deinit();
4080#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07004081}
4082
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004083static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05304084{
4085 struct platform_data *my_data = (struct platform_data *)platform;
4086 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
4087 return my_data->is_acdb_initialized;
4088}
4089
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05304090void platform_snd_card_update(void *platform, card_status_t card_status)
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004091{
4092 struct platform_data *my_data = (struct platform_data *)platform;
4093
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05304094 if (card_status == CARD_STATUS_ONLINE) {
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004095 if (!platform_is_acdb_initialized(my_data)) {
4096 if(platform_acdb_init(my_data))
4097 ALOGE("%s: acdb initialization is failed", __func__);
4098 } else if (my_data->acdb_send_common_top() < 0) {
4099 ALOGD("%s: acdb did not set common topology", __func__);
4100 }
4101 }
4102}
4103
Eric Laurentb23d5282013-05-14 15:27:20 -07004104const char *platform_get_snd_device_name(snd_device_t snd_device)
4105{
Aalique Grahame22e49102018-12-18 14:23:57 -08004106 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
4107 if (operator_specific_device_table[snd_device] != NULL) {
4108 return get_operator_specific_device_mixer_path(snd_device);
4109 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004110 return device_table[snd_device];
Aalique Grahame22e49102018-12-18 14:23:57 -08004111 } else
Eric Laurentb23d5282013-05-14 15:27:20 -07004112 return "";
4113}
4114
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07004115int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
4116 char *device_name)
4117{
4118 struct platform_data *my_data = (struct platform_data *)platform;
4119
4120 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
Aalique Grahame22e49102018-12-18 14:23:57 -08004121 if (operator_specific_device_table[snd_device] != NULL) {
4122 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
4123 DEVICE_NAME_MAX_SIZE);
4124 } else
4125 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07004126 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
4127 } else {
4128 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
4129 return -EINVAL;
4130 }
4131
4132 return 0;
4133}
4134
Banajit Goswami20cdd212015-09-11 01:11:30 -07004135void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
4136 struct audio_usecase *usecase)
Eric Laurentb23d5282013-05-14 15:27:20 -07004137{
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004138 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4139 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4140 return;
4141 }
4142
Rohit kumarf4120402016-08-05 19:19:48 +05304143 if ((snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
4144 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07004145 !(usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)) {
4146 ALOGI("%s: Not adding vbat speaker device to non voice use cases", __func__);
4147 return;
4148 }
4149
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304150 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004151
4152 if (suffix != NULL) {
4153 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
4154 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
Aalique Grahame37659862017-12-03 22:34:26 -08004155
4156 /* if we can use display-port for voice call and usb mic
4157 * is connected, choose dp_rx, usb_tx audio route
4158 */
4159 if (usecase->type == VOICE_CALL) {
4160 struct audio_device *adev = usecase->stream.out->dev;
4161 if ((snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
4162 adev->dp_allowed_for_voice &&
4163 (usecase->in_snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)) {
4164 strlcat(mixer_path, "-and-usb-headset-mic", MIXER_PATH_MAX_LENGTH);
4165 }
4166 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08004167 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004168}
4169
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304170bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
4171{
4172 bool result = true;
4173
4174 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
4175 platform_get_snd_device_name(snd_device1),
4176 platform_get_snd_device_name(snd_device2));
4177
4178 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_OUT_END)) {
4179 ALOGE("%s: Invalid snd_device = %s", __func__,
4180 platform_get_snd_device_name(snd_device1));
4181 return false;
4182 }
4183 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_OUT_END)) {
4184 ALOGE("%s: Invalid snd_device = %s", __func__,
4185 platform_get_snd_device_name(snd_device2));
4186 return false;
4187 }
4188 const char * be_itf1 = hw_interface_table[snd_device1];
4189 const char * be_itf2 = hw_interface_table[snd_device2];
4190
4191 if (NULL != be_itf1 && NULL != be_itf2) {
Kuirong Wangb9fbb1e2016-05-03 18:36:39 -07004192 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304193 result = false;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05304194 } else if (NULL == be_itf1 && NULL != be_itf2 && (NULL == strstr(be_itf2, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304195 result = false;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05304196 } else if (NULL != be_itf1 && NULL == be_itf2 && (NULL == strstr(be_itf1, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304197 result = false;
4198 }
4199
4200 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
4201 return result;
4202}
4203
Eric Laurentb23d5282013-05-14 15:27:20 -07004204int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
4205{
Mingshu Pang1513f972019-05-24 12:43:51 +08004206 int device_id = -1;
4207
4208 if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
4209 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
4210 return device_id;
4211 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004212 if (device_type == PCM_PLAYBACK)
4213 device_id = pcm_device_table[usecase][0];
4214 else
4215 device_id = pcm_device_table[usecase][1];
4216 return device_id;
4217}
4218
Vignesh Kulothungana6927272019-02-20 15:17:07 -08004219int platform_get_haptics_pcm_device_id()
4220{
4221 return HAPTICS_PCM_DEVICE;
4222}
4223
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004224uint64_t getQtime()
4225{
4226 uint64_t qTimerCount = 0;
4227
4228#if __aarch64__
4229 asm volatile("mrs %0, cntvct_el0" : "=r" (qTimerCount));
4230#else
4231 asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (qTimerCount));
4232#endif
4233
4234 return qTimerCount;
4235}
4236
4237int platform_get_delay(void *platform, int pcm_device_id)
4238{
4239 int ctl_len = 0;
Mingshu Pang1513f972019-05-24 12:43:51 +08004240 struct audio_device *adev = NULL;
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004241 struct mixer_ctl *ctl = NULL;
4242 const char *mixer_ctl_name = "ADSP Path Latency";
4243 const char *deviceNo = "NN";
4244 char *mixer_str = NULL;
4245 int path_delay = 0;
4246
4247 if (NULL == platform) {
4248 ALOGE("%s: platform is NULL", __func__);
4249 return -EINVAL;
4250 }
4251 if (pcm_device_id <= 0) {
4252 ALOGE("%s: invalid pcm device id: %d", __func__, pcm_device_id);
4253 return -EINVAL;
4254 }
4255
Mingshu Pang1513f972019-05-24 12:43:51 +08004256 adev = ((struct platform_data *)platform)->adev;
4257
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004258 // Mixer control format: "ADSP Path Latency NN"
4259 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
4260
4261 mixer_str = (char*) calloc(ctl_len, sizeof(char));
4262 if (!mixer_str) {
4263 ALOGE("%s: Could not allocate memory", __func__);
4264 return -ENOMEM;
4265 }
4266
4267 snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, pcm_device_id);
4268
4269 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_str);
4270 if (!ctl) {
4271 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, mixer_str);
4272 free(mixer_str);
4273 return -EINVAL;
4274 }
4275
4276 path_delay = mixer_ctl_get_value(ctl, 0);
4277 if (path_delay < 0) {
4278 ALOGE("%s: Could not get val for mixer cmd - %s", __func__, mixer_str);
4279 }
4280 ALOGD("%s: Path Delay: %d", __func__, path_delay);
4281
4282 free(mixer_str);
4283 return path_delay;
4284}
4285
4286int send_qtime(void *platform, uint64_t qtime_value, int pcm_device_id)
4287{
4288 int ret = 0;
4289 int ctl_len = 0;
4290 struct audio_device *adev = ((struct platform_data *)platform)->adev;
4291 struct mixer_ctl *ctl = NULL;
4292 const char *mixer_ctl_name = "QTimer";
4293 const char *deviceNo = "NN";
4294 char *mixer_str = NULL;
4295 uint32_t set_values[2];
4296
4297 set_values[0] = (uint32_t)qtime_value;
4298 set_values[1] = (uint32_t)((qtime_value >> 16) >> 16);
4299 ALOGD("%s: Send qtime msw: %u, lsw: %u", __func__, set_values[1],
4300 set_values[0]);
4301
4302 // Mixer control format: "Qtimer NN"
4303 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
4304
4305 mixer_str = (char*) calloc(ctl_len, sizeof(char));
4306 if (!mixer_str) {
4307 ALOGE("%s: Could not allocate memory", __func__);
4308 return -ENOMEM;
4309 }
4310
4311 snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, pcm_device_id);
4312
4313 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_str);
4314 if (!ctl) {
4315 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4316 __func__, mixer_str);
4317 free(mixer_str);
4318 return -EINVAL;
4319 }
4320
4321 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4322 if (ret < 0) {
4323 ALOGE("%s: Could not set array for mixer cmd - %s",
4324 __func__, mixer_str);
4325 }
4326 free(mixer_str);
4327
4328 return ret;
4329}
4330
4331int platform_set_qtime(void *platform, int audio_pcm_device_id,
4332 int haptic_pcm_device_id)
4333{
4334 int ret = 0;
4335 uint64_t qtime_count = 0;
4336 uint64_t qtime_value = 0;
4337 uint32_t qtime_remainder = 0;
4338 int32_t audio_path_latency = 0;
4339 int32_t haptic_path_latency = 0;
4340
4341 if (NULL == platform) {
4342 ALOGE("%s: platform is NULL", __func__);
4343 return -EINVAL;
4344 }
4345 if (audio_pcm_device_id <= 0 || haptic_pcm_device_id <= 0) {
4346 ALOGE("%s: Invalid pcm device id - %d", __func__,
4347 audio_pcm_device_id <= 0 ? audio_pcm_device_id
4348 : haptic_pcm_device_id);
4349 return -EINVAL;
4350 }
4351
4352 audio_path_latency = platform_get_delay(platform, audio_pcm_device_id);
4353 if (audio_path_latency <= 0) {
4354 ALOGE("%s: error getting audio path latency: %d", __func__,
4355 audio_path_latency);
4356 return -EINVAL;
4357 }
4358 ALOGD("%s: Audio Path Latency: %d", __func__, audio_path_latency);
4359
4360 haptic_path_latency = platform_get_delay(platform, haptic_pcm_device_id);
4361 if (haptic_path_latency <= 0) {
4362 ALOGE("%s: error getting haptic path latency: %d", __func__,
4363 haptic_path_latency);
4364 return -EINVAL;
4365 }
4366 ALOGD("%s: Haptic Path Latency: %d", __func__, haptic_path_latency);
4367
4368 qtime_count = getQtime();
4369
4370 // Qtime count / Qtime freq (KHZ) = Qtime in milliseconds
4371 qtime_value = (uint64_t) (qtime_count / QTIME_FREQ_KHZ);
4372
4373 // Convert Qtime to microseconds
4374 qtime_value *= 1000;
4375
4376 // Adding max(path_latency)
4377 qtime_value += (uint32_t) max(audio_path_latency, haptic_path_latency);
4378
4379 // Adding IPC delay + error correction ~10ms
4380 qtime_value += IPC_ERROR_DELAY;
4381
4382 // Calculate remainder in microseconds
4383 qtime_remainder = ((qtime_count % QTIME_FREQ_KHZ) * 1000) / QTIME_FREQ_KHZ;
4384
4385 // Add the remainder to qtime
4386 qtime_value += qtime_remainder;
4387 ALOGD("%s: Set qtime: %llu microsecs\n", __func__,
4388 (unsigned long long int)qtime_value);
4389
4390 ret = send_qtime(platform, qtime_value, haptic_pcm_device_id);
4391 if (ret < 0) {
4392 ALOGE("%s: Could not send qtime for haptic session - %d",
4393 __func__, ret);
4394 return ret;
4395 }
4396
4397 ret = send_qtime(platform, qtime_value, audio_pcm_device_id);
4398 if (ret < 0) {
4399 ALOGE("%s: Could not send qtime for audio session - %d",
4400 __func__, ret);
4401 }
4402
4403 return ret;
4404}
4405
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004406static int find_index(struct name_to_index * table, int32_t len, const char * name)
Ben Romberger61764e32014-01-10 13:49:02 -08004407{
4408 int ret = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004409 int32_t i;
Ben Romberger61764e32014-01-10 13:49:02 -08004410
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004411 if (table == NULL) {
4412 ALOGE("%s: table is NULL", __func__);
Ben Romberger61764e32014-01-10 13:49:02 -08004413 ret = -ENODEV;
4414 goto done;
4415 }
4416
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004417 if (name == NULL) {
4418 ALOGE("null key");
4419 ret = -ENODEV;
4420 goto done;
4421 }
4422
4423 for (i=0; i < len; i++) {
4424 const char* tn = table[i].name;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07004425 size_t len = strlen(tn);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004426 if (strncmp(tn, name, len) == 0) {
4427 if (strlen(name) != len) {
4428 continue; // substring
4429 }
4430 ret = table[i].index;
Ben Romberger61764e32014-01-10 13:49:02 -08004431 goto done;
4432 }
4433 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004434 ALOGE("%s: Could not find index for name = %s",
4435 __func__, name);
Ben Romberger61764e32014-01-10 13:49:02 -08004436 ret = -ENODEV;
4437done:
4438 return ret;
4439}
4440
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05304441int platform_set_fluence_type(void *platform, char *value)
4442{
4443 int ret = 0;
4444 int fluence_type = FLUENCE_NONE;
4445 int fluence_flag = NONE_FLAG;
4446 struct platform_data *my_data = (struct platform_data *)platform;
4447 struct audio_device *adev = my_data->adev;
4448
4449 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
4450
4451 /* only dual mic turn on and off is supported as of now through setparameters */
4452 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
4453 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
4454 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
4455 ALOGV("fluence dualmic feature enabled \n");
4456 fluence_type = FLUENCE_DUAL_MIC;
4457 fluence_flag = DMIC_FLAG;
4458 } else {
4459 ALOGE("%s: Failed to set DUALMIC", __func__);
4460 ret = -1;
4461 goto done;
4462 }
4463 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
4464 ALOGV("fluence disabled");
4465 fluence_type = FLUENCE_NONE;
4466 } else {
4467 ALOGE("Invalid fluence value : %s",value);
4468 ret = -1;
4469 goto done;
4470 }
4471
4472 if (fluence_type != my_data->fluence_type) {
4473 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
4474 my_data->fluence_type = fluence_type;
4475 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
4476 }
4477done:
4478 return ret;
4479}
4480
4481int platform_get_fluence_type(void *platform, char *value, uint32_t len)
4482{
4483 int ret = 0;
4484 struct platform_data *my_data = (struct platform_data *)platform;
4485
4486 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
4487 strlcpy(value, "quadmic", len);
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004488 } else if (my_data->fluence_type == FLUENCE_TRI_MIC) {
4489 strlcpy(value, "trimic", len);
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05304490 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
4491 strlcpy(value, "dualmic", len);
4492 } else if (my_data->fluence_type == FLUENCE_NONE) {
4493 strlcpy(value, "none", len);
4494 } else
4495 ret = -1;
4496
4497 return ret;
4498}
4499
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004500int platform_get_snd_device_index(char *device_name)
4501{
4502 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
4503}
4504
4505int platform_get_usecase_index(const char *usecase_name)
4506{
4507 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
4508}
4509
Aalique Grahame22e49102018-12-18 14:23:57 -08004510void platform_add_operator_specific_device(snd_device_t snd_device,
4511 const char *operator,
4512 const char *mixer_path,
4513 unsigned int acdb_id)
4514{
4515 struct operator_specific_device *device;
4516
4517 if (operator_specific_device_table[snd_device] == NULL) {
4518 operator_specific_device_table[snd_device] =
4519 (struct listnode *)calloc(1, sizeof(struct listnode));
4520 list_init(operator_specific_device_table[snd_device]);
4521 }
4522
4523 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
Weiyin Jiang2995f662019-04-17 14:25:12 +08004524 if (device == NULL) {
4525 ALOGE("%s: memory allocation failed", __func__);
4526 return;
4527 }
Aalique Grahame22e49102018-12-18 14:23:57 -08004528
4529 device->operator = strdup(operator);
4530 device->mixer_path = strdup(mixer_path);
4531 device->acdb_id = acdb_id;
4532
4533 list_add_tail(operator_specific_device_table[snd_device], &device->list);
4534
4535 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
4536 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
4537
4538}
4539
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004540int platform_get_effect_config_data(snd_device_t snd_device,
4541 struct audio_effect_config *effect_config,
4542 effect_type_t effect_type)
4543{
4544 int ret = 0;
4545
4546 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
4547 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
4548 ALOGE("%s: Invalid snd_device = %d",
4549 __func__, snd_device);
4550 ret = -EINVAL;
4551 goto done;
4552 }
4553
Weiyin Jiang301dac62019-05-08 13:58:00 +08004554 if (effect_config == NULL) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004555 ALOGE("%s: Invalid effect_config", __func__);
4556 ret = -EINVAL;
4557 goto done;
4558 }
4559
4560 ALOGV("%s: snd_device = %d module_id = %d",
4561 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
4562 memcpy(effect_config, &effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type],
4563 sizeof(struct audio_effect_config));
4564
4565done:
4566 return ret;
4567}
4568
Carter Hsu32a62362018-10-15 15:01:42 -07004569void platform_add_external_specific_device(snd_device_t snd_device,
4570 const char *usbid,
4571 unsigned int acdb_id)
4572{
4573 struct external_specific_device *device;
4574
4575 if (external_specific_device_table[snd_device] == NULL) {
4576 external_specific_device_table[snd_device] =
4577 (struct listnode *)calloc(1, sizeof(struct listnode));
4578 list_init(external_specific_device_table[snd_device]);
4579 }
4580
4581 device = (struct external_specific_device *)calloc(1, sizeof(struct external_specific_device));
Weiyin Jiang301dac62019-05-08 13:58:00 +08004582 if (device == NULL) {
4583 ALOGE("%s: memory allocation failed", __func__);
4584 return;
4585 }
Carter Hsu32a62362018-10-15 15:01:42 -07004586
4587 device->usbid = strdup(usbid);
4588 device->acdb_id = acdb_id;
4589
4590 list_add_tail(external_specific_device_table[snd_device], &device->list);
4591
4592 ALOGD("%s: device[%s] usbid[%s] -> acdb_id[%d]", __func__,
4593 platform_get_snd_device_name(snd_device), usbid, acdb_id);
4594}
4595
Ben Romberger55886882014-01-10 13:49:02 -08004596int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
4597{
4598 int ret = 0;
4599
4600 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4601 ALOGE("%s: Invalid snd_device = %d",
4602 __func__, snd_device);
4603 ret = -EINVAL;
4604 goto done;
4605 }
4606
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304607 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
4608 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Ben Romberger55886882014-01-10 13:49:02 -08004609 acdb_device_table[snd_device] = acdb_id;
4610done:
4611 return ret;
4612}
4613
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004614int platform_set_effect_config_data(snd_device_t snd_device,
4615 struct audio_effect_config effect_config,
4616 effect_type_t effect_type)
4617{
4618 int ret = 0;
4619
4620 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
4621 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
4622 ALOGE("%s: Invalid snd_device = %d",
4623 __func__, snd_device);
4624 ret = -EINVAL;
4625 goto done;
4626 }
4627
4628 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
4629 effect_config.instance_id, effect_config.param_id,
4630 effect_config.param_value);
4631 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
4632
4633done:
4634 return ret;
4635}
4636
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05304637int platform_set_acdb_metainfo_key(void *platform, char *name, int key)
4638{
4639 struct meta_key_list *key_info;
4640 struct platform_data *pdata = (struct platform_data *)platform;
4641
4642 key_info = (struct meta_key_list *)calloc(1, sizeof(struct meta_key_list));
4643 if (!key_info) {
4644 ALOGE("%s: Could not allocate memory for key %d", __func__, key);
4645 return -ENOMEM;
4646 }
4647
4648 key_info->cal_info.nKey = key;
4649 strlcpy(key_info->name, name, sizeof(key_info->name));
4650 list_add_tail(&pdata->acdb_meta_key_list, &key_info->list);
4651
4652 ALOGD("%s: successfully added module %s and key %d to the list", __func__,
4653 key_info->name, key_info->cal_info.nKey);
4654 return 0;
4655}
4656
4657int platform_get_meta_info_key_from_list(void *platform, char *mod_name)
4658{
4659 struct listnode *node;
4660 struct meta_key_list *key_info;
4661 struct platform_data *pdata = (struct platform_data *)platform;
4662 int key = 0;
4663
4664 ALOGV("%s: for module %s", __func__, mod_name);
4665
4666 list_for_each(node, &pdata->acdb_meta_key_list) {
4667 key_info = node_to_item(node, struct meta_key_list, list);
4668 if (strcmp(key_info->name, mod_name) == 0) {
4669 key = key_info->cal_info.nKey;
4670 ALOGD("%s: Found key %d for module %s", __func__, key, mod_name);
4671 break;
4672 }
4673 }
4674 return key;
4675}
4676
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07004677int platform_get_default_app_type(void *platform)
4678{
4679 struct platform_data *my_data = (struct platform_data *)platform;
4680
4681 if (my_data->acdb_get_default_app_type)
4682 return my_data->acdb_get_default_app_type();
4683 else
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05304684 return DEFAULT_APP_TYPE_RX_PATH;
4685}
4686
4687int platform_get_default_app_type_v2(void *platform, usecase_type_t type)
4688{
Alexy Josephb1379942016-01-29 15:49:38 -08004689 ALOGV("%s: Platform: %p, type: %d", __func__, platform, type);
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05304690 if(type == PCM_CAPTURE)
4691 return DEFAULT_APP_TYPE_TX_PATH;
4692 else
4693 return DEFAULT_APP_TYPE_RX_PATH;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07004694}
4695
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07004696int platform_get_snd_device_acdb_id(snd_device_t snd_device)
4697{
4698 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4699 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4700 return -EINVAL;
4701 }
Aalique Grahame22e49102018-12-18 14:23:57 -08004702
4703 /*
4704 * If speaker protection is enabled, function returns supported
4705 * sound device for speaker. Else same sound device is returned.
4706 */
4707 snd_device = platform_get_spkr_prot_snd_device(snd_device);
4708
4709 if (operator_specific_device_table[snd_device] != NULL)
4710 return get_operator_specific_device_acdb_id(snd_device);
Carter Hsu32a62362018-10-15 15:01:42 -07004711 else if (external_specific_device_table[snd_device] != NULL)
4712 return get_external_specific_device_acdb_id(snd_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08004713 else
4714 return acdb_device_table[snd_device];
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07004715}
4716
Amit Shekhar5a39c912014-10-14 15:39:30 -07004717int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
4718{
4719 int ret = 0;
4720
4721 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4722 ALOGE("%s: Invalid snd_device = %d",
4723 __func__, snd_device);
4724 ret = -EINVAL;
4725 goto done;
4726 }
4727
4728 backend_bit_width_table[snd_device] = bit_width;
4729done:
4730 return ret;
4731}
4732
4733int platform_get_snd_device_bit_width(snd_device_t snd_device)
4734{
4735 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4736 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jain058165c2016-09-28 23:18:48 +05304737 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -07004738 }
4739 return backend_bit_width_table[snd_device];
4740}
4741
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304742int platform_set_native_support(int na_mode)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004743{
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304744 if (NATIVE_AUDIO_MODE_SRC == na_mode || NATIVE_AUDIO_MODE_TRUE_44_1 == na_mode
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304745 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode
4746 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP == na_mode) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304747 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
4748 na_props.na_mode = na_mode;
Ashish Jain6fced6e2017-01-09 14:13:22 +05304749 ALOGD("%s:napb: native audio playback enabled in (%s) mode", __func__,
4750 ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC":
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304751 (na_mode == NATIVE_AUDIO_MODE_TRUE_44_1)?"True":
4752 (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC)?"Multiple_Mix_Codec":"Multiple_Mix_DSP"));
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304753 }
4754 else {
4755 na_props.platform_na_prop_enabled = false;
4756 na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
4757 ALOGD("%s:napb: native audio playback disabled", __func__);
4758 }
4759
4760 return 0;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004761}
4762
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304763bool platform_check_codec_dsd_support(void *platform)
4764{
4765 struct platform_data *my_data = (struct platform_data *)platform;
4766 return my_data->is_dsd_supported;
4767}
4768
Preetam Singh Ranawatb0c0dd72016-08-18 00:32:06 +05304769bool platform_check_codec_asrc_support(void *platform)
4770{
4771 struct platform_data *my_data = (struct platform_data *)platform;
4772 return my_data->is_asrc_supported;
4773}
4774
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004775int platform_get_native_support()
4776{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304777 int ret = NATIVE_AUDIO_MODE_INVALID;
4778 if (na_props.platform_na_prop_enabled &&
4779 na_props.ui_na_prop_enabled) {
4780 ret = na_props.na_mode;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004781 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304782 ALOGV("%s:napb: ui Prop enabled(%d) version(%d)", __func__,
4783 na_props.ui_na_prop_enabled, na_props.na_mode);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004784 return ret;
4785}
4786
4787void native_audio_get_params(struct str_parms *query,
4788 struct str_parms *reply,
4789 char *value, int len)
4790{
4791 int ret;
4792 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4793 value, len);
4794 if (ret >= 0) {
4795 if (na_props.platform_na_prop_enabled) {
4796 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4797 na_props.ui_na_prop_enabled ? "true" : "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304798 ALOGV("%s:napb: na_props.ui_na_prop_enabled: %d", __func__,
4799 na_props.ui_na_prop_enabled);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004800 } else {
4801 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4802 "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304803 ALOGV("%s:napb: native audio not supported: %d", __func__,
4804 na_props.platform_na_prop_enabled);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004805 }
4806 }
4807}
4808
4809int native_audio_set_params(struct platform_data *platform,
4810 struct str_parms *parms, char *value, int len)
4811{
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05304812 int ret = -1;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004813 struct audio_usecase *usecase;
4814 struct listnode *node;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304815 int mode = NATIVE_AUDIO_MODE_INVALID;
4816
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05304817 if (!value || !parms)
4818 return ret;
4819
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304820 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO_MODE,
4821 value, len);
4822 if (ret >= 0) {
4823 if (value && !strncmp(value, "src", sizeof("src")))
4824 mode = NATIVE_AUDIO_MODE_SRC;
4825 else if (value && !strncmp(value, "true", sizeof("true")))
4826 mode = NATIVE_AUDIO_MODE_TRUE_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304827 else if (value && !strncmp(value, "multiple_mix_codec", sizeof("multiple_mix_codec")))
4828 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC;
4829 else if (value && !strncmp(value, "multiple_mix_dsp", sizeof("multiple_mix_dsp")))
4830 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304831 else {
4832 mode = NATIVE_AUDIO_MODE_INVALID;
4833 ALOGE("%s:napb:native_audio_mode in platform info xml,invalid mode string",
4834 __func__);
4835 }
4836 ALOGD("%s:napb updating mode (%d) from XML",__func__, mode);
4837 platform_set_native_support(mode);
4838 }
4839
4840
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004841
4842 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4843 value, len);
4844 if (ret >= 0) {
4845 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304846 if (!strncmp("true", value, sizeof("true"))) {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004847 na_props.ui_na_prop_enabled = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304848 ALOGD("%s:napb: native audio feature enabled from UI",
4849 __func__);
4850 } else {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004851 na_props.ui_na_prop_enabled = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304852 ALOGD("%s:napb: native audio feature disabled from UI",
4853 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304854 }
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004855
4856 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
4857
4858 /*
4859 * Iterate through the usecase list and trigger device switch for
4860 * all the appropriate usecases
4861 */
4862 list_for_each(node, &(platform->adev)->usecase_list) {
4863 usecase = node_to_item(node, struct audio_usecase, list);
4864
Sujin Panicker390724d2019-04-26 10:43:36 +05304865 if (usecase->stream.out && is_offload_usecase(usecase->id) &&
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004866 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4867 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
4868 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Alexy Josephb1379942016-01-29 15:49:38 -08004869 ALOGD("%s:napb: triggering dynamic device switch for usecase %d, %s"
4870 " stream %p, device (%u)", __func__, usecase->id,
4871 use_case_table[usecase->id],
4872 (void*) usecase->stream.out,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004873 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304874 select_devices(platform->adev, usecase->id);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004875 }
4876 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304877 } else
4878 ALOGD("%s:napb: native audio cannot be enabled from UI",
4879 __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004880 }
4881 return ret;
4882}
4883
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304884int check_hdset_combo_device(snd_device_t snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304885{
4886 int ret = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304887
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304888 if (SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES == snd_device ||
4889 SND_DEVICE_OUT_SPEAKER_AND_LINE == snd_device ||
4890 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1 == snd_device ||
4891 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2 == snd_device ||
Meng Wang841d6c02017-01-24 12:34:36 +08004892 SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET == snd_device ||
4893 SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET == snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304894 ret = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304895
4896 return ret;
4897}
kunleiz207afaa2016-07-22 14:26:49 +08004898
Ashish Jainb26edfb2016-08-25 00:10:11 +05304899int codec_device_supports_native_playback(audio_devices_t out_device)
kunleiz207afaa2016-07-22 14:26:49 +08004900{
Ashish Jainb26edfb2016-08-25 00:10:11 +05304901 int ret = false;
kunleiz207afaa2016-07-22 14:26:49 +08004902
4903 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4904 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
Revathi Uddaraju413a6f02018-11-09 12:57:27 +05304905 out_device & AUDIO_DEVICE_OUT_LINE ||
4906 out_device & AUDIO_DEVICE_OUT_USB_HEADSET)
Ashish Jainb26edfb2016-08-25 00:10:11 +05304907 ret = true;
kunleiz207afaa2016-07-22 14:26:49 +08004908
4909 return ret;
4910}
4911
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304912int platform_get_backend_index(snd_device_t snd_device)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004913{
4914 int32_t port = DEFAULT_CODEC_BACKEND;
4915
Kuirong Wang0b947f72016-09-29 11:03:09 -07004916 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304917 if (backend_tag_table[snd_device] != NULL) {
4918 if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
4919 sizeof("headphones-44.1")) == 0)
4920 port = HEADPHONE_44_1_BACKEND;
Ramlal Karra10d22b92019-08-08 19:02:35 +05304921 else if (strncmp(backend_tag_table[snd_device], "headphones-hifi-filter",
4922 sizeof("headphones-hifi-filter")) == 0)
4923 port = HEADPHONE_BACKEND;
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304924 else if (strncmp(backend_tag_table[snd_device], "headphones-dsd",
4925 sizeof("headphones-dsd")) == 0)
4926 port = DSD_NATIVE_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304927 else if (strncmp(backend_tag_table[snd_device], "headphones",
4928 sizeof("headphones")) == 0)
4929 port = HEADPHONE_BACKEND;
Samyak Jain541897b2019-07-01 17:15:31 +05304930 else if (strncmp(backend_tag_table[snd_device], "headset",
4931 sizeof("headset")) == 0)
4932 port = HEADPHONE_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304933 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
4934 port = HDMI_RX_BACKEND;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004935 else if (strcmp(backend_tag_table[snd_device], "display-port") == 0)
4936 port = DISP_PORT_RX_BACKEND;
Ashish Jain3e37a702016-11-25 12:27:15 +05304937 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
4938 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08004939 port = USB_AUDIO_RX_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304940 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07004941 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
4942 port = DEFAULT_CODEC_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07004943 if (backend_tag_table[snd_device] != NULL) {
4944 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
4945 port = USB_AUDIO_TX_BACKEND;
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05304946 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
4947 port = BT_SCO_TX_BACKEND;
Ralf Herzafb164f2018-07-03 07:08:07 +02004948 else if (strcmp(backend_tag_table[snd_device], "spdif-in") == 0)
4949 port = SPDIF_TX_BACKEND;
4950 else if (strcmp(backend_tag_table[snd_device], "hdmi-in") == 0)
Siddartha Shaik44dd7702017-06-14 12:13:25 +05304951 port = HDMI_TX_BACKEND;
Ralf Herzafb164f2018-07-03 07:08:07 +02004952 else if (strcmp(backend_tag_table[snd_device], "hdmi-arc-in") == 0)
4953 port = HDMI_ARC_TX_BACKEND;
Samyak Jainb3f3ca52019-01-02 18:24:35 +05304954 else if (strcmp(backend_tag_table[snd_device], "headset-mic") == 0)
4955 port = HEADSET_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07004956 }
4957 } else {
Kuirong Wang0b947f72016-09-29 11:03:09 -07004958 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07004959 }
4960
Kuirong Wang0b947f72016-09-29 11:03:09 -07004961 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07004962 return port;
4963}
4964
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304965int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Zhou Song06761dd2019-04-28 18:08:17 +08004966 int app_type)
Eric Laurentb23d5282013-05-14 15:27:20 -07004967{
4968 struct platform_data *my_data = (struct platform_data *)platform;
4969 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304970 int snd_device = SND_DEVICE_OUT_SPEAKER;
Siena Richard7c2db772016-12-21 11:32:34 -08004971 int new_snd_device[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304972 int i, num_devices = 1;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304973 bool is_incall_rec_usecase = false;
4974 snd_device_t incall_rec_device;
Zhou Song06761dd2019-04-28 18:08:17 +08004975 int sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05304976 struct audio_backend_cfg backend_cfg = {0};
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304977
4978 if (voice_is_in_call(my_data->adev))
4979 is_incall_rec_usecase = voice_is_in_call_rec_stream(usecase->stream.in);
Eric Laurentb23d5282013-05-14 15:27:20 -07004980
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304981 if (usecase->type == PCM_PLAYBACK)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304982 snd_device = usecase->out_snd_device;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304983 else if ((usecase->type == PCM_CAPTURE) && is_incall_rec_usecase)
Karthik Reddy Katta81c42612015-11-13 17:49:07 +05304984 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304985 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Vidyakumar Athotab0975c32015-07-21 14:15:03 -07004986 snd_device = usecase->in_snd_device;
Surendar Karka93cd25a2018-08-28 14:21:37 +05304987 else if (usecase->type == TRANSCODE_LOOPBACK_RX)
Siddartha Shaik343abc62017-08-08 11:15:25 +05304988 snd_device = usecase->out_snd_device;
Vidyakumar Athotab0975c32015-07-21 14:15:03 -07004989
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08004990 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07004991 if (acdb_dev_id < 0) {
4992 ALOGE("%s: Could not find acdb id for device(%d)",
4993 __func__, snd_device);
4994 return -EINVAL;
4995 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304996
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304997 if (!is_incall_rec_usecase) {
4998 if (platform_split_snd_device(my_data, snd_device,
4999 &num_devices, new_snd_device) < 0) {
5000 new_snd_device[0] = snd_device;
5001 }
5002 } else {
5003 incall_rec_device = voice_get_incall_rec_backend_device(usecase->stream.in);
5004 if (platform_split_snd_device(my_data, incall_rec_device,
5005 &num_devices, new_snd_device) < 0) {
5006 new_snd_device[0] = snd_device;
5007 }
Eric Laurentb23d5282013-05-14 15:27:20 -07005008 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305009
5010 for (i = 0; i < num_devices; i++) {
Zhou Song06761dd2019-04-28 18:08:17 +08005011 if (!is_incall_rec_usecase) {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05305012 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(new_snd_device[i])];
Zhou Song06761dd2019-04-28 18:08:17 +08005013 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
5014 new_snd_device[i]);
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305015 platform_get_codec_backend_cfg(my_data->adev, new_snd_device[i], &backend_cfg);
Zhou Song06761dd2019-04-28 18:08:17 +08005016 } else {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05305017 // Use in_call_rec snd_device to extract the ACDB device ID instead of split snd devices
5018 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Zhou Song06761dd2019-04-28 18:08:17 +08005019 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
5020 snd_device);
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305021 platform_get_codec_backend_cfg(my_data->adev, snd_device, &backend_cfg);
Zhou Song06761dd2019-04-28 18:08:17 +08005022 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05305023
5024 // Do not use Rx path default app type for TX path
5025 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
5026 ALOGD("Resetting app type for Tx path to default");
5027 app_type = DEFAULT_APP_TYPE_TX_PATH;
5028 }
5029
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305030 /* Override backend cfg sample rate in calibration for vi feedback usecase */
5031 if (usecase->id == USECASE_AUDIO_SPKR_CALIB_TX) {
5032 ALOGV("Reset backend cfg sample rate to 8KHz for spkr calib Tx use case");
5033 backend_cfg.sample_rate = sample_rate;
5034 }
5035
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305036 if (acdb_dev_id < 0) {
5037 ALOGE("%s: Could not find acdb id for device(%d)",
5038 __func__, new_snd_device[i]);
5039 return -EINVAL;
5040 }
Weiyin Jiang27dd1452019-07-12 23:46:06 +08005041
5042 /* Notify device change info to effect clients registered */
5043 if (usecase->type == PCM_PLAYBACK) {
5044 audio_extn_gef_notify_device_config(
5045 usecase->stream.out->devices,
5046 usecase->stream.out->channel_mask,
5047 sample_rate,
5048 acdb_dev_id,
5049 usecase->stream.out->app_type_cfg.app_type);
5050 }
5051
Siena Richard7c2db772016-12-21 11:32:34 -08005052 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
5053 __func__, new_snd_device[i], acdb_dev_id);
5054 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
5055 new_snd_device[i] < SND_DEVICE_OUT_END)
5056 acdb_dev_type = ACDB_DEV_TYPE_OUT;
5057 else
5058 acdb_dev_type = ACDB_DEV_TYPE_IN;
5059
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305060 if (my_data->acdb_send_audio_cal_v4) {
5061 my_data->acdb_send_audio_cal_v4(acdb_dev_id, acdb_dev_type,
5062 app_type, sample_rate, i,
5063 backend_cfg.sample_rate);
5064 } else if (my_data->acdb_send_audio_cal_v3) {
Siena Richard7c2db772016-12-21 11:32:34 -08005065 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
5066 app_type, sample_rate, i);
5067 } else if (my_data->acdb_send_audio_cal) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305068 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
5069 sample_rate);
5070 }
5071 }
5072
Eric Laurentb23d5282013-05-14 15:27:20 -07005073 return 0;
5074}
5075
5076int platform_switch_voice_call_device_pre(void *platform)
5077{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005078 struct platform_data *my_data = (struct platform_data *)platform;
5079 int ret = 0;
5080
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005081 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07005082 voice_is_in_call(my_data->adev)) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005083 /* This must be called before disabling mixer controls on APQ side */
5084 ret = my_data->csd->disable_device();
5085 if (ret < 0) {
5086 ALOGE("%s: csd_client_disable_device, failed, error %d",
5087 __func__, ret);
5088 }
5089 }
5090 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005091}
5092
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005093int platform_switch_voice_call_enable_device_config(void *platform,
5094 snd_device_t out_snd_device,
5095 snd_device_t in_snd_device)
5096{
5097 struct platform_data *my_data = (struct platform_data *)platform;
5098 int acdb_rx_id, acdb_tx_id;
5099 int ret = 0;
5100
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005101 if (my_data->csd == NULL)
5102 return ret;
5103
Banajit Goswami20cdd212015-09-11 01:11:30 -07005104 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05305105 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05305106 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
5107 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5108 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07005109 audio_extn_spkr_prot_is_enabled()) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05305110 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07005111 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
5112 else
5113 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
5114 } else
Aalique Grahame22e49102018-12-18 14:23:57 -08005115 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005116
Aalique Grahame22e49102018-12-18 14:23:57 -08005117 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005118
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005119 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
5120 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
5121 if (ret < 0) {
5122 ALOGE("%s: csd_enable_device_config, failed, error %d",
5123 __func__, ret);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005124 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005125 } else {
5126 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5127 acdb_rx_id, acdb_tx_id);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005128 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005129
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005130 return ret;
5131}
5132
Eric Laurentb23d5282013-05-14 15:27:20 -07005133int platform_switch_voice_call_device_post(void *platform,
5134 snd_device_t out_snd_device,
5135 snd_device_t in_snd_device)
5136{
5137 struct platform_data *my_data = (struct platform_data *)platform;
5138 int acdb_rx_id, acdb_tx_id;
5139
5140 if (my_data->acdb_send_voice_cal == NULL) {
5141 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
5142 } else {
Rohit kumarf4120402016-08-05 19:19:48 +05305143 if (audio_extn_spkr_prot_is_enabled()) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305144 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
5145 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA)
Rohit kumarf4120402016-08-05 19:19:48 +05305146 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07005147 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO)
5148 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +05305149 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)
5150 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305151 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
5152 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)
Rohit kumarf4120402016-08-05 19:19:48 +05305153 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
5154 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)
5155 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
5156 }
Anish Kumar46c7b872014-09-09 01:49:44 -07005157
Aalique Grahame22e49102018-12-18 14:23:57 -08005158 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
5159 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005160
Eric Laurentb23d5282013-05-14 15:27:20 -07005161 if (acdb_rx_id > 0 && acdb_tx_id > 0)
5162 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
5163 else
5164 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5165 acdb_rx_id, acdb_tx_id);
5166 }
5167
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005168 return 0;
5169}
5170
5171int platform_switch_voice_call_usecase_route_post(void *platform,
5172 snd_device_t out_snd_device,
5173 snd_device_t in_snd_device)
5174{
5175 struct platform_data *my_data = (struct platform_data *)platform;
5176 int acdb_rx_id, acdb_tx_id;
5177 int ret = 0;
5178
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005179 if (my_data->csd == NULL)
5180 return ret;
5181
Banajit Goswami20cdd212015-09-11 01:11:30 -07005182 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Rohit kumarf4120402016-08-05 19:19:48 +05305183 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05305184 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05305185 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5186 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07005187 audio_extn_spkr_prot_is_enabled()) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05305188 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07005189 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
5190 else
5191 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
5192 } else
Aalique Grahame22e49102018-12-18 14:23:57 -08005193 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005194
Aalique Grahame22e49102018-12-18 14:23:57 -08005195 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005196
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005197 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
5198 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
5199 my_data->adev->acdb_settings);
5200 if (ret < 0) {
5201 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005202 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005203 } else {
5204 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5205 acdb_rx_id, acdb_tx_id);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005206 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005207
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005208 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005209}
5210
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005211int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07005212{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005213 struct platform_data *my_data = (struct platform_data *)platform;
5214 int ret = 0;
5215
5216 if (my_data->csd != NULL) {
5217 ret = my_data->csd->start_voice(vsid);
5218 if (ret < 0) {
5219 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
5220 }
5221 }
5222 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005223}
5224
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005225int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07005226{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005227 struct platform_data *my_data = (struct platform_data *)platform;
5228 int ret = 0;
5229
5230 if (my_data->csd != NULL) {
5231 ret = my_data->csd->stop_voice(vsid);
5232 if (ret < 0) {
5233 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
5234 }
5235 }
5236 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005237}
5238
Vignesh Kulothungan7d374312018-02-21 17:12:00 -08005239int platform_set_mic_break_det(void *platform, bool enable)
5240{
5241 int ret = 0;
5242 struct platform_data *my_data = (struct platform_data *)platform;
5243 struct audio_device *adev = my_data->adev;
5244 const char *mixer_ctl_name = "Voice Mic Break Enable";
5245 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5246 if (!ctl) {
5247 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5248 __func__, mixer_ctl_name);
5249 return -EINVAL;
5250 }
5251
5252 ret = mixer_ctl_set_value(ctl, 0, enable);
5253 if(ret)
5254 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
5255
5256 return ret;
5257}
5258
Helen Zeng6a16ad72014-02-23 22:04:44 -08005259int platform_get_sample_rate(void *platform, uint32_t *rate)
5260{
5261 struct platform_data *my_data = (struct platform_data *)platform;
5262 int ret = 0;
5263
5264 if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) {
5265 ret = my_data->csd->get_sample_rate(rate);
5266 if (ret < 0) {
5267 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
5268 }
5269 }
5270 return ret;
5271}
5272
Aalique Grahame22e49102018-12-18 14:23:57 -08005273void platform_set_speaker_gain_in_combo(struct audio_device *adev,
5274 snd_device_t snd_device,
5275 bool enable)
5276{
5277 const char* name;
5278 switch (snd_device) {
5279 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
5280 if (enable)
5281 name = "spkr-gain-in-headphone-combo";
5282 else
5283 name = "speaker-gain-default";
5284 break;
5285 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
5286 if (enable)
5287 name = "spkr-gain-in-line-combo";
5288 else
5289 name = "speaker-gain-default";
5290 break;
5291 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
5292 if (enable)
5293 name = "spkr-safe-gain-in-headphone-combo";
5294 else
5295 name = "speaker-safe-gain-default";
5296 break;
5297 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
5298 if (enable)
5299 name = "spkr-safe-gain-in-line-combo";
5300 else
5301 name = "speaker-safe-gain-default";
5302 break;
5303 default:
5304 return;
5305 }
5306
5307 audio_route_apply_and_update_path(adev->audio_route, name);
5308}
5309
Eric Laurentb23d5282013-05-14 15:27:20 -07005310int platform_set_voice_volume(void *platform, int volume)
5311{
5312 struct platform_data *my_data = (struct platform_data *)platform;
5313 struct audio_device *adev = my_data->adev;
5314 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07005315 const char *mixer_ctl_name = "Voice Rx Gain";
Aalique Grahame22e49102018-12-18 14:23:57 -08005316 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005317 int vol_index = 0, ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305318 long set_values[ ] = {0,
5319 ALL_SESSION_VSID,
5320 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07005321
5322 // Voice volume levels are mapped to adsp volume levels as follows.
5323 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
5324 // But this values don't changed in kernel. So, below change is need.
Aalique Grahame22e49102018-12-18 14:23:57 -08005325 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005326 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07005327
5328 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5329 if (!ctl) {
5330 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5331 __func__, mixer_ctl_name);
Aalique Grahame22e49102018-12-18 14:23:57 -08005332 return -EINVAL;
Eric Laurentb23d5282013-05-14 15:27:20 -07005333 }
Aalique Grahame22e49102018-12-18 14:23:57 -08005334 ALOGV("%s: Setting voice volume index: %ld", __func__, set_values[0]);
5335 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5336
5337 // Send mute command in case volume index is max since indexes are inverted
5338 // for mixer controls.
5339 if (vol_index == my_data->max_vol_index)
5340 set_values[0] = 1;
5341 else
5342 set_values[0] = 0;
5343
5344 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
5345 if (!ctl) {
5346 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5347 __func__, mute_mixer_ctl_name);
5348 return -EINVAL;
5349 }
5350 ALOGV("%s: Setting RX Device Mute to: %ld", __func__, set_values[0]);
5351 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07005352
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005353 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07005354 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
5355 DEFAULT_VOLUME_RAMP_DURATION_MS);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005356 if (ret < 0) {
5357 ALOGE("%s: csd_volume error %d", __func__, ret);
5358 }
5359 }
5360 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005361}
5362
5363int platform_set_mic_mute(void *platform, bool state)
5364{
5365 struct platform_data *my_data = (struct platform_data *)platform;
5366 struct audio_device *adev = my_data->adev;
5367 struct mixer_ctl *ctl;
5368 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005369 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305370 long set_values[ ] = {0,
5371 ALL_SESSION_VSID,
5372 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07005373
Aalique Grahame22e49102018-12-18 14:23:57 -08005374 if (adev->mode != AUDIO_MODE_IN_CALL &&
5375 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
5376 return 0;
5377
5378 if (adev->enable_hfp)
5379 mixer_ctl_name = "HFP Tx Mute";
5380
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005381 set_values[0] = state;
5382 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5383 if (!ctl) {
5384 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5385 __func__, mixer_ctl_name);
Josh Kirsch5669ad92016-12-09 10:48:52 -08005386 ret = -EINVAL;
5387 } else {
5388 ALOGV("%s Setting voice mute state: %d", __func__, state);
5389 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005390 }
Eric Laurentb23d5282013-05-14 15:27:20 -07005391
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005392 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07005393 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
5394 DEFAULT_MUTE_RAMP_DURATION_MS);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005395 if (ret < 0) {
5396 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005397 }
5398 }
5399 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005400}
5401
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08005402int platform_set_device_mute(void *platform, bool state, char *dir)
5403{
5404 struct platform_data *my_data = (struct platform_data *)platform;
5405 struct audio_device *adev = my_data->adev;
5406 struct mixer_ctl *ctl;
5407 char *mixer_ctl_name = NULL;
5408 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305409 long set_values[ ] = {0,
5410 ALL_SESSION_VSID,
5411 0};
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08005412 if(dir == NULL) {
5413 ALOGE("%s: Invalid direction:%s", __func__, dir);
5414 return -EINVAL;
5415 }
5416
5417 if (!strncmp("rx", dir, sizeof("rx"))) {
5418 mixer_ctl_name = "Voice Rx Device Mute";
5419 } else if (!strncmp("tx", dir, sizeof("tx"))) {
5420 mixer_ctl_name = "Voice Tx Device Mute";
5421 } else {
5422 return -EINVAL;
5423 }
5424
5425 set_values[0] = state;
5426 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5427 if (!ctl) {
5428 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5429 __func__, mixer_ctl_name);
5430 return -EINVAL;
5431 }
5432
5433 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
5434 __func__,state, mixer_ctl_name);
5435 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5436
5437 return ret;
5438}
5439
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005440int platform_split_snd_device(void *platform,
5441 snd_device_t snd_device,
5442 int *num_devices,
5443 snd_device_t *new_snd_devices)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305444{
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005445 int ret = -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305446 struct platform_data *my_data = (struct platform_data *)platform;
5447
5448 if ( NULL == num_devices || NULL == new_snd_devices || NULL == my_data) {
5449 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005450 return -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305451 }
5452
5453 /*
5454 * If wired headset/headphones/line devices share the same backend
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005455 * with speaker/earpiece this routine returns -EINVAL.
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305456 */
5457 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
5458 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
5459 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305460 if (my_data->is_vbat_speaker)
5461 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5462 else if (my_data->is_wsa_speaker)
5463 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5464 else
5465 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305466 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005467 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005468 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
5469 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
5470 *num_devices = 2;
5471 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5472 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
5473 ret = 0;
5474 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
5475 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
5476 *num_devices = 2;
5477 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5478 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5479 ret = 0;
5480 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
5481 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
5482 *num_devices = 2;
5483 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5484 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
5485 ret = 0;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305486 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET &&
5487 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_ANC_HEADSET)) {
5488 *num_devices = 2;
5489 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5490 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5491 ret = 0;
5492 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET &&
5493 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_ANC_FB_HEADSET)) {
5494 *num_devices = 2;
5495 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5496 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5497 ret = 0;
5498 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES &&
5499 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
5500 *num_devices = 2;
5501 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5502 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
5503 ret = 0;
5504 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET &&
5505 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
5506 *num_devices = 2;
5507 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5508 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
5509 ret = 0;
5510 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET &&
5511 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)) {
5512 *num_devices = 2;
5513 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5514 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5515 ret = 0;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07005516 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES &&
5517 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
5518 *num_devices = 2;
5519 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5520 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
5521 ret = 0;
5522 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET &&
5523 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
5524 *num_devices = 2;
5525 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5526 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
5527 ret = 0;
5528 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET &&
5529 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)) {
5530 *num_devices = 2;
5531 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5532 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5533 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305534 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI &&
5535 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HDMI)) {
5536 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305537
5538 if (my_data->is_vbat_speaker)
5539 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5540 else if (my_data->is_wsa_speaker)
5541 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5542 else
5543 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305544 new_snd_devices[1] = SND_DEVICE_OUT_HDMI;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005545 ret = 0;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005546 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT &&
5547 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_DISPLAY_PORT)) {
5548 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305549 if (my_data->is_vbat_speaker)
5550 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5551 else if (my_data->is_wsa_speaker)
5552 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5553 else
5554 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005555 new_snd_devices[1] = SND_DEVICE_OUT_DISPLAY_PORT;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005556 ret = 0;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08005557 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
5558 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
5559 *num_devices = 2;
5560 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5561 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005562 ret = 0;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305563 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER &&
5564 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)) {
5565 *num_devices = 2;
5566 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5567 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
5568 ret = 0;
kunleizbe6a8442017-08-08 17:11:35 +08005569 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
5570 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO)) {
5571 *num_devices = 2;
5572 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5573 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5574 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005575 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
5576 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5577 SND_DEVICE_OUT_BT_SCO)) {
5578 *num_devices = 2;
5579 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5580 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5581 ret = 0;
kunleizbe6a8442017-08-08 17:11:35 +08005582 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
5583 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO_WB)) {
5584 *num_devices = 2;
5585 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5586 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5587 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005588 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
5589 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5590 SND_DEVICE_OUT_BT_SCO_WB)) {
5591 *num_devices = 2;
5592 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5593 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5594 ret = 0;
Zhou Song12c29502019-03-16 10:37:18 +08005595 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB &&
5596 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO_SWB)) {
5597 *num_devices = 2;
5598 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5599 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_SWB;
5600 ret = 0;
5601 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB &&
5602 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5603 SND_DEVICE_OUT_BT_SCO_SWB)) {
5604 *num_devices = 2;
5605 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5606 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_SWB;
5607 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005608 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
5609 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
5610 *num_devices = 2;
5611 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5612 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
5613 ret = 0;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305614 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO &&
5615 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO)) {
5616 *num_devices = 2;
5617 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5618 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5619 ret = 0;
5620 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB &&
5621 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO_WB)) {
5622 *num_devices = 2;
5623 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5624 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5625 ret = 0;
5626 }
5627else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) {
Naresh Tannirucd2353e2016-08-19 00:37:25 +05305628 *num_devices = 2;
5629 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5630 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005631 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005632 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
5633 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5634 SND_DEVICE_OUT_BT_A2DP)) {
5635 *num_devices = 2;
5636 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5637 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
5638 ret = 0;
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05305639 } else if (SND_DEVICE_IN_INCALL_REC_RX_TX == snd_device) {
5640 *num_devices = 2;
5641 new_snd_devices[0] = SND_DEVICE_IN_INCALL_REC_RX;
5642 new_snd_devices[1] = SND_DEVICE_IN_INCALL_REC_TX;
5643 ret = 0;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05305644 } else if (SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK == snd_device) {
5645 *num_devices = 2;
5646 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_DMIC;
5647 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5648 ret = 0;
5649 } else if (SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK == snd_device) {
5650 *num_devices = 2;
5651 new_snd_devices[0] = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
5652 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5653 ret = 0;
5654 } else if (SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK == snd_device) {
5655 *num_devices = 2;
5656 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_6MIC;
5657 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5658 ret = 0;
5659 } else if (SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK == snd_device) {
5660 *num_devices = 2;
5661 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_8MIC;
5662 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5663 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305664 }
5665
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05305666
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305667 ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
5668 snd_device, *num_devices, *new_snd_devices);
5669
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005670 return ret;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305671}
5672
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005673int platform_get_ext_disp_type(void *platform)
5674{
5675 int disp_type;
5676 struct platform_data *my_data = (struct platform_data *)platform;
5677
5678 if (my_data->ext_disp_type != EXT_DISPLAY_TYPE_NONE) {
5679 ALOGD("%s: Returning cached ext disp type:%s",
5680 __func__, (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
5681 return my_data->ext_disp_type;
5682 }
5683
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08005684 if (audio_extn_is_display_port_enabled()) {
5685 struct audio_device *adev = my_data->adev;
5686 struct mixer_ctl *ctl;
5687 char *mixer_ctl_name = "External Display Type";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005688
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08005689 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5690 if (!ctl) {
5691 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5692 __func__, mixer_ctl_name);
5693 return -EINVAL;
5694 }
5695
5696 disp_type = mixer_ctl_get_value(ctl, 0);
5697 if (disp_type == EXT_DISPLAY_TYPE_NONE) {
5698 ALOGE("%s: Invalid external display type: %d", __func__, disp_type);
5699 return -EINVAL;
5700 }
5701 } else {
5702 disp_type = EXT_DISPLAY_TYPE_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005703 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005704 my_data->ext_disp_type = disp_type;
5705 ALOGD("%s: ext disp type:%s", __func__, (disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
5706 return disp_type;
5707}
5708
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08005709snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Eric Laurentb23d5282013-05-14 15:27:20 -07005710{
5711 struct platform_data *my_data = (struct platform_data *)platform;
5712 struct audio_device *adev = my_data->adev;
5713 audio_mode_t mode = adev->mode;
5714 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08005715 audio_devices_t devices = out->devices;
5716 unsigned int sample_rate = out->sample_rate;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05305717 int na_mode = platform_get_native_support();
Eric Laurent637e2d42018-11-15 12:24:31 -08005718 struct stream_in *in = adev_get_active_input(adev);
Eric Laurentb23d5282013-05-14 15:27:20 -07005719
Eric Laurent637e2d42018-11-15 12:24:31 -08005720 audio_channel_mask_t channel_mask = (in == NULL) ?
5721 AUDIO_CHANNEL_IN_MONO : in->channel_mask;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07005722 int channel_count = popcount(channel_mask);
5723
Eric Laurentb23d5282013-05-14 15:27:20 -07005724 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
5725 if (devices == AUDIO_DEVICE_NONE ||
5726 devices & AUDIO_DEVICE_BIT_IN) {
5727 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
5728 goto exit;
5729 }
5730
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07005731 if (popcount(devices) == 2) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305732 bool is_active_voice_call = false;
5733
5734 /*
5735 * This is special case handling for combo device use case during
5736 * voice call. APM route use case to combo device if stream type is
5737 * enforced audible (e.g. Camera shutter sound).
5738 */
5739 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08005740 voice_check_voicecall_usecases_active(adev) ||
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305741 voice_extn_compress_voip_is_active(adev))
5742 is_active_voice_call = true;
5743
Mingming Yin4a72d652014-01-03 18:54:18 -08005744 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
5745 AUDIO_DEVICE_OUT_SPEAKER)) {
Tanya Finkel00130052014-07-14 04:26:56 -07005746 if (my_data->external_spk_1)
5747 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
5748 else if (my_data->external_spk_2)
5749 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305750 else if (is_active_voice_call)
5751 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305752 else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5753 my_data->codec_variant, channel_count, 1))
5754 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
Tanya Finkel00130052014-07-14 04:26:56 -07005755 else
5756 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305757 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5758 AUDIO_DEVICE_OUT_SPEAKER)) {
5759 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Mingming Yin4a72d652014-01-03 18:54:18 -08005760 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
5761 AUDIO_DEVICE_OUT_SPEAKER)) {
Meng Wang841d6c02017-01-24 12:34:36 +08005762 if (audio_extn_get_anc_enabled()) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305763 if (audio_extn_should_use_fb_anc()) {
5764 if (is_active_voice_call)
5765 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET;
5766 else
5767 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET;
5768 } else {
5769 if (is_active_voice_call)
5770 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET;
5771 else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05305772 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305773 }
Meng Wang841d6c02017-01-24 12:34:36 +08005774 } else if (my_data->external_spk_1)
Tanya Finkel00130052014-07-14 04:26:56 -07005775 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
5776 else if (my_data->external_spk_2)
5777 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305778 else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5779 my_data->codec_variant, channel_count, 1))
5780 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305781 else {
5782 if (is_active_voice_call)
5783 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
5784 else
5785 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
5786 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005787 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5788 AUDIO_DEVICE_OUT_SPEAKER)) {
5789 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Aalique Grahame22e49102018-12-18 14:23:57 -08005790 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
5791 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
5792 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
5793 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
5794 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
5795 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5796 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
5797 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
Mingming Yin4a72d652014-01-03 18:54:18 -08005798 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
5799 AUDIO_DEVICE_OUT_SPEAKER)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005800 switch(my_data->ext_disp_type) {
5801 case EXT_DISPLAY_TYPE_HDMI:
5802 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
5803 break;
5804 case EXT_DISPLAY_TYPE_DP:
5805 snd_device = SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT;
5806 break;
5807 default:
5808 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
5809 goto exit;
5810 }
Mingming Yin4a72d652014-01-03 18:54:18 -08005811 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
5812 AUDIO_DEVICE_OUT_SPEAKER)) {
5813 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05305814 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
5815 AUDIO_DEVICE_OUT_SPEAKER)) ||
5816 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
5817 AUDIO_DEVICE_OUT_SPEAKER))) {
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08005818 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05305819 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
5820 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
5821 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aalique Grahame22e49102018-12-18 14:23:57 -08005822 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
5823 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
5824 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
kunleizbe6a8442017-08-08 17:11:35 +08005825 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
5826 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
Zhou Song12c29502019-03-16 10:37:18 +08005827 if (my_data->is_wsa_speaker) {
5828 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5829 snd_device = SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB;
5830 else
5831 snd_device = adev->bt_wb_speech_enabled ?
5832 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB :
5833 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO;
5834 } else {
5835 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5836 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB;
5837 else
5838 snd_device = adev->bt_wb_speech_enabled ?
5839 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
5840 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
5841 }
Aalique Grahame22e49102018-12-18 14:23:57 -08005842 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
5843 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Zhou Song12c29502019-03-16 10:37:18 +08005844 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5845 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB;
5846 else
5847 snd_device = adev->bt_wb_speech_enabled ?
5848 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
5849 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Aalique Grahame22e49102018-12-18 14:23:57 -08005850 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
5851 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
5852 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
5853 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
5854 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Mingming Yin4a72d652014-01-03 18:54:18 -08005855 } else {
5856 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
5857 goto exit;
5858 }
5859 if (snd_device != SND_DEVICE_NONE) {
5860 goto exit;
5861 }
5862 }
5863
5864 if (popcount(devices) != 1) {
5865 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
5866 goto exit;
5867 }
5868
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05305869 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08005870 voice_check_voicecall_usecases_active(adev) ||
Aalique Grahame22e49102018-12-18 14:23:57 -08005871 voice_extn_compress_voip_is_active(adev) ||
5872 adev->enable_voicerx ||
5873 audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07005874 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005875 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
5876 devices & AUDIO_DEVICE_OUT_LINE) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005877 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
5878 !voice_extn_compress_voip_is_active(adev)) {
5879 switch (adev->voice.tty_mode) {
5880 case TTY_MODE_FULL:
Samyak Jainc9250dc2019-06-14 12:19:28 +05305881 if (audio_extn_is_concurrent_capture_enabled() &&
5882 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5883 //Separate backend is added for headset-mic as part of concurrent capture
5884 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET;
5885 } else {
5886 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
5887 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005888 break;
5889 case TTY_MODE_VCO:
Samyak Jainc9250dc2019-06-14 12:19:28 +05305890 if (audio_extn_is_concurrent_capture_enabled() &&
5891 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5892 //Separate backend is added for headset-mic as part of concurrent capture
5893 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET;
5894 } else {
5895 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
5896 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005897 break;
5898 case TTY_MODE_HCO:
5899 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
5900 break;
5901 default:
5902 ALOGE("%s: Invalid TTY mode (%#x)",
5903 __func__, adev->voice.tty_mode);
5904 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005905 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
5906 snd_device = SND_DEVICE_OUT_VOICE_LINE;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005907 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07005908 if (audio_extn_should_use_fb_anc())
5909 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5910 else
5911 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Samyak Jainfd24f1e2019-04-30 11:58:43 +05305912 } else if (audio_extn_is_concurrent_capture_enabled() &&
5913 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5914 //Separate backend is added for headset-mic as part of concurrent capture
5915 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005916 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07005917 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005918 }
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05305919 } else if (devices &
5920 (AUDIO_DEVICE_OUT_USB_DEVICE |
5921 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07005922 if (voice_is_in_call(adev)) {
5923 switch (adev->voice.tty_mode) {
5924 case TTY_MODE_FULL:
5925 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
5926 break;
5927 case TTY_MODE_VCO:
5928 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
5929 break;
5930 case TTY_MODE_HCO:
5931 // since Hearing will be on handset\speaker, use existing device
5932 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
5933 break;
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07005934 case TTY_MODE_OFF:
5935 break;
Aniket Kumar Lata91886592017-05-25 16:53:32 -07005936 default:
5937 ALOGE("%s: Invalid TTY mode (%#x)",
5938 __func__, adev->voice.tty_mode);
5939 }
5940 }
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07005941 if (snd_device == SND_DEVICE_NONE) {
5942 snd_device = audio_extn_usb_is_capture_supported() ?
5943 SND_DEVICE_OUT_VOICE_USB_HEADSET :
5944 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
5945 }
Eric Laurentb23d5282013-05-14 15:27:20 -07005946 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08005947 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5948 snd_device = SND_DEVICE_OUT_BT_SCO_SWB;
5949 else if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005950 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
5951 else
5952 snd_device = SND_DEVICE_OUT_BT_SCO;
Derek Chen25496072019-06-23 01:05:27 -07005953 } else if ((devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
5954 (devices & AUDIO_DEVICE_OUT_BUS)) {
Aalique Grahame552b0832019-03-11 10:16:38 -07005955 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker) {
5956 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
5957 if (my_data->mono_speaker == SPKR_1)
Rohit kumarf4120402016-08-05 19:19:48 +05305958 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
Aalique Grahame552b0832019-03-11 10:16:38 -07005959 else
5960 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT;
5961 } else
5962 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305963 } else if (my_data->is_wsa_speaker) {
5964 if (my_data->mono_speaker == SPKR_1)
5965 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
5966 else
5967 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA;
Aalique Grahame552b0832019-03-11 10:16:38 -07005968 } else {
5969 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
5970 if (my_data->voice_speaker_stereo)
5971 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5972 else if (adev->enable_hfp)
5973 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
5974 else {
5975 if (my_data->mono_speaker == SPKR_1)
kunleizaa6a3f12017-01-19 12:28:28 +08005976 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Aalique Grahame552b0832019-03-11 10:16:38 -07005977 else
5978 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2;
5979 }
5980 } else if (adev->enable_hfp)
5981 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
5982 else
5983 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
5984 }
Naresh Tanniru9d027a62015-03-13 01:32:10 +05305985 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
5986 snd_device = SND_DEVICE_OUT_BT_A2DP;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07005987 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
5988 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
5989 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Aalique Grahame37659862017-12-03 22:34:26 -08005990 } else if ((devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
5991 adev->dp_allowed_for_voice) {
5992 switch(my_data->ext_disp_type) {
5993 case EXT_DISPLAY_TYPE_DP:
5994 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
5995 break;
5996 default:
5997 ALOGE("%s: Invalid disp_type %d", __func__,
5998 my_data->ext_disp_type);
5999 goto exit;
6000 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07006001 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
6002 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07006003 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006004 if(adev->voice.hac)
6005 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
6006 else if (is_operator_tmus())
6007 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
6008 else if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006009 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07006010 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006011 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
juyuchen2d415992018-11-16 14:15:16 +08006012 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07006013 snd_device = SND_DEVICE_OUT_VOICE_TX;
juyuchen2d415992018-11-16 14:15:16 +08006014 } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) {
6015 snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID;
6016 }
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07006017
Eric Laurentb23d5282013-05-14 15:27:20 -07006018 if (snd_device != SND_DEVICE_NONE) {
6019 goto exit;
6020 }
6021 }
6022
Eric Laurentb23d5282013-05-14 15:27:20 -07006023 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05306024 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
6025 devices & AUDIO_DEVICE_OUT_LINE) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306026 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
6027 NATIVE_AUDIO_MODE_SRC == na_mode &&
6028 !audio_extn_get_anc_enabled()) {
6029
6030 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
6031
6032 } else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006033 && audio_extn_get_anc_enabled()) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306034 if (audio_extn_should_use_fb_anc())
6035 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
6036 else
6037 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306038 } else if (NATIVE_AUDIO_MODE_SRC == na_mode &&
6039 OUTPUT_SAMPLING_RATE_44100 == sample_rate) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08006040 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05306041 } else if (NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode &&
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05306042 (sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0) &&
6043 (out->format != AUDIO_FORMAT_DSD)) {
6044 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
6045 } else if (out->format == AUDIO_FORMAT_DSD) {
6046 snd_device = SND_DEVICE_OUT_HEADPHONES_DSD;
Ramlal Karra10d22b92019-08-08 19:02:35 +05306047 } else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
6048 my_data->codec_variant, channel_count, 1)) {
6049 snd_device = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306050 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
6051 snd_device = SND_DEVICE_OUT_LINE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306052 } else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306053 snd_device = SND_DEVICE_OUT_HEADPHONES;
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006054 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
6055 snd_device = SND_DEVICE_OUT_LINE;
Aalique Grahame22e49102018-12-18 14:23:57 -08006056 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
6057 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07006058 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Tanya Finkel00130052014-07-14 04:26:56 -07006059 if (my_data->external_spk_1)
6060 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1;
6061 else if (my_data->external_spk_2)
6062 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2;
Aalique Grahame22e49102018-12-18 14:23:57 -08006063 else if (adev->speaker_lr_swap) {
6064 /*
6065 * Perform device switch only if acdb tuning is
6066 * different between SPEAKER & SPEAKER_REVERSE,
6067 * Or there will be a small pause while performing
6068 * device switch.
6069 */
6070 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
6071 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE])
6072 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
6073 else
6074 snd_device = SND_DEVICE_OUT_SPEAKER;
6075 } else if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07006076 snd_device = SND_DEVICE_OUT_SPEAKER_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306077 else if (my_data->is_wsa_speaker)
6078 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
Eric Laurentb23d5282013-05-14 15:27:20 -07006079 else
6080 snd_device = SND_DEVICE_OUT_SPEAKER;
6081 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08006082 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
6083 snd_device = SND_DEVICE_OUT_BT_SCO_SWB;
6084 else if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006085 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
6086 else
6087 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05306088 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
6089 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07006090 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006091 switch(my_data->ext_disp_type) {
6092 case EXT_DISPLAY_TYPE_HDMI:
6093 snd_device = SND_DEVICE_OUT_HDMI;
6094 break;
6095 case EXT_DISPLAY_TYPE_DP:
6096 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
6097 break;
6098 default:
6099 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
6100 goto exit;
6101 }
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006102 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
6103 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08006104 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006105 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05306106 audio_extn_set_afe_proxy_channel_mixer(adev, 2, snd_device);
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306107 } else if (devices &
6108 (AUDIO_DEVICE_OUT_USB_DEVICE |
6109 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006110 if (audio_extn_qdsp_supported_usb())
Aalique Grahame22e49102018-12-18 14:23:57 -08006111 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
6112 else if (audio_extn_usb_is_capture_supported())
Ashish Jain3e37a702016-11-25 12:27:15 +05306113 snd_device = SND_DEVICE_OUT_USB_HEADSET;
6114 else
6115 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07006116 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
6117 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07006118 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006119 /*HAC support for voice-ish audio (eg visual voicemail)*/
6120 if(adev->voice.hac)
6121 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
6122 else
6123 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006124 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08006125 channel_count = audio_extn_get_afe_proxy_channel_count();
6126 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006127 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05306128 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count, snd_device);
Derek Chenf6318be2017-06-12 17:16:24 -04006129 } else if (devices & AUDIO_DEVICE_OUT_BUS) {
6130 snd_device = audio_extn_auto_hal_get_snd_device_for_car_audio_stream(out);
Eric Laurentb23d5282013-05-14 15:27:20 -07006131 } else {
6132 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
6133 }
6134exit:
6135 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
6136 return snd_device;
6137}
6138
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006139static snd_device_t get_snd_device_for_voice_comm_ecns_enabled(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006140 struct stream_in *in,
6141 audio_devices_t out_device __unused,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006142 audio_devices_t in_device)
6143{
6144 struct audio_device *adev = my_data->adev;
6145 snd_device_t snd_device = SND_DEVICE_NONE;
6146
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006147 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6148 if (my_data->fluence_in_spkr_mode) {
6149 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6150 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6151 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
6152 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6153 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6154 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306155 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006156 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6157 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6158 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
6159 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006160 snd_device = my_data->fluence_sb_enabled ?
6161 SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB
6162 : SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006163 }
6164 adev->acdb_settings |= DMIC_FLAG;
6165 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006166 snd_device = my_data->fluence_sb_enabled ?
6167 SND_DEVICE_IN_SPEAKER_MIC_SB
6168 : SND_DEVICE_IN_SPEAKER_MIC;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006169 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
6170 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6171 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6172 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
6173 adev->acdb_settings |= TMIC_FLAG;
6174 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6175 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006176 snd_device = my_data->fluence_sb_enabled ?
6177 SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB
6178 : SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006179 adev->acdb_settings |= DMIC_FLAG;
6180 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006181 snd_device = my_data->fluence_sb_enabled ?
6182 SND_DEVICE_IN_HANDSET_MIC_SB
6183 : SND_DEVICE_IN_HANDSET_MIC;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006184 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6185 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006186 }
Carter Hsu2e429db2019-05-14 18:50:52 +08006187 in->enable_ec_port = true;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006188
6189 return snd_device;
6190}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006191
6192static snd_device_t get_snd_device_for_voice_comm_ecns_disabled(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006193 struct stream_in *in,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006194 audio_devices_t out_device,
6195 audio_devices_t in_device)
6196{
6197 struct audio_device *adev = my_data->adev;
6198 snd_device_t snd_device = SND_DEVICE_NONE;
6199
Eric Laurent637e2d42018-11-15 12:24:31 -08006200 if (in != NULL && in->enable_aec && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006201 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6202 if (my_data->fluence_in_spkr_mode) {
6203 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6204 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6205 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006206 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6207 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6208 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006209 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006210 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6211 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006212 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6213 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
6214 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006215 snd_device = my_data->fluence_sb_enabled ?
6216 SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB
6217 : SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006218 }
6219 adev->acdb_settings |= DMIC_FLAG;
6220 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006221 snd_device = my_data->fluence_sb_enabled ?
6222 SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB
6223 : SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006224 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306225 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6226 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6227 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
6228 adev->acdb_settings |= TMIC_FLAG;
6229 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006230 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6231 my_data->fluence_in_voice_comm) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006232 snd_device = my_data->fluence_sb_enabled ?
6233 SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB
6234 : SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006235 adev->acdb_settings |= DMIC_FLAG;
6236 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006237 snd_device = my_data->fluence_sb_enabled ?
6238 SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB
6239 : SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006240 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6241 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08006242 } else if (audio_extn_usb_connected(NULL) && audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006243 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
6244 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006245 } else if (in != NULL && in->enable_aec) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006246 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6247 if (my_data->fluence_in_spkr_mode) {
6248 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6249 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6250 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006251 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6252 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6253 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006254 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006255 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6256 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006257 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6258 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
6259 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006260 snd_device = my_data->fluence_sb_enabled ?
6261 SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB
6262 : SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006263 }
6264 adev->acdb_settings |= DMIC_FLAG;
6265 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006266 snd_device = my_data->fluence_sb_enabled ?
6267 SND_DEVICE_IN_SPEAKER_MIC_AEC_SB
6268 : SND_DEVICE_IN_SPEAKER_MIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006269 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306270 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6271 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6272 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
6273 adev->acdb_settings |= TMIC_FLAG;
6274 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006275 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6276 my_data->fluence_in_voice_comm) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006277 snd_device = my_data->fluence_sb_enabled ?
6278 SND_DEVICE_IN_HANDSET_DMIC_AEC_SB
6279 : SND_DEVICE_IN_HANDSET_DMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006280 adev->acdb_settings |= DMIC_FLAG;
6281 } else
6282 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
6283 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6284 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08006285 } else if (audio_extn_usb_connected(NULL) && audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006286 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
6287 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006288 } else if (in != NULL && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006289 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6290 if (my_data->fluence_in_spkr_mode) {
6291 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6292 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6293 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006294 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6295 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6296 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006297 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006298 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6299 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006300 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6301 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
6302 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006303 snd_device = my_data->fluence_sb_enabled ?
6304 SND_DEVICE_IN_SPEAKER_DMIC_NS_SB
6305 : SND_DEVICE_IN_SPEAKER_DMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006306 }
6307 adev->acdb_settings |= DMIC_FLAG;
6308 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006309 snd_device = my_data->fluence_sb_enabled ?
6310 SND_DEVICE_IN_SPEAKER_MIC_NS_SB
6311 : SND_DEVICE_IN_SPEAKER_MIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006312 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306313 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6314 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6315 snd_device = SND_DEVICE_IN_HANDSET_TMIC_NS;
6316 adev->acdb_settings |= TMIC_FLAG;
6317 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006318 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6319 my_data->fluence_in_voice_comm) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006320 snd_device = my_data->fluence_sb_enabled ?
6321 SND_DEVICE_IN_HANDSET_DMIC_NS_SB
6322 : SND_DEVICE_IN_HANDSET_DMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006323 adev->acdb_settings |= DMIC_FLAG;
6324 } else
6325 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
6326 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6327 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
6328 }
6329 platform_set_echo_reference(adev, false, out_device);
6330 } else
6331 platform_set_echo_reference(adev, false, out_device);
6332
6333 return snd_device;
6334}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006335
6336static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006337 struct stream_in *in,
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006338 audio_devices_t out_device,
6339 audio_devices_t in_device)
6340{
6341 if(voice_extn_is_dynamic_ecns_enabled())
Carter Hsu2e429db2019-05-14 18:50:52 +08006342 return get_snd_device_for_voice_comm_ecns_enabled(my_data, in, out_device, in_device);
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006343 else
Carter Hsu2e429db2019-05-14 18:50:52 +08006344 return get_snd_device_for_voice_comm_ecns_disabled(my_data, in, out_device, in_device);
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006345}
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006346
Eric Laurent637e2d42018-11-15 12:24:31 -08006347snd_device_t platform_get_input_snd_device(void *platform,
6348 struct stream_in *in,
6349 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07006350{
6351 struct platform_data *my_data = (struct platform_data *)platform;
6352 struct audio_device *adev = my_data->adev;
Eric Laurent637e2d42018-11-15 12:24:31 -08006353 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07006354 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurent637e2d42018-11-15 12:24:31 -08006355
6356 if (in == NULL)
6357 in = adev_get_active_input(adev);
6358
6359 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
6360 audio_devices_t in_device =
6361 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
6362 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
6363 int channel_count = audio_channel_count_from_in_mask(channel_mask);
6364 int str_bitwidth = (in == NULL) ? CODEC_BACKEND_DEFAULT_BIT_WIDTH : in->bit_width;
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006365 int sample_rate = (in == NULL) ? 8000 : in->sample_rate;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306366 struct audio_usecase *usecase = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05306367 audio_usecase_t uc_id = (in == NULL) ? USECASE_AUDIO_RECORD : in->usecase;
Eric Laurentb23d5282013-05-14 15:27:20 -07006368
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306369 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
6370 __func__, out_device, in_device, channel_count, channel_mask);
Tanya Finkel00130052014-07-14 04:26:56 -07006371 if (my_data->external_mic) {
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08006372 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
6373 voice_check_voicecall_usecases_active(adev) ||
6374 voice_extn_compress_voip_is_active(adev) ||
6375 audio_extn_hfp_is_active(adev))) {
Tanya Finkel00130052014-07-14 04:26:56 -07006376 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6377 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
6378 out_device & AUDIO_DEVICE_OUT_SPEAKER )
6379 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
6380 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
6381 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6382 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
6383 }
6384 }
6385
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07006386 if (snd_device != AUDIO_DEVICE_NONE)
Tanya Finkel00130052014-07-14 04:26:56 -07006387 goto exit;
6388
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08006389 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
6390 voice_check_voicecall_usecases_active(adev) ||
6391 voice_extn_compress_voip_is_active(adev) ||
6392 audio_extn_hfp_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08006393 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
6394 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07006395 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006396 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
6397 out_device & AUDIO_DEVICE_OUT_LINE) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006398 switch (adev->voice.tty_mode) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07006399 case TTY_MODE_FULL:
6400 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
6401 break;
6402 case TTY_MODE_VCO:
6403 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
6404 break;
6405 case TTY_MODE_HCO:
6406 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
6407 break;
6408 default:
6409 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
6410 }
6411 goto exit;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306412 } else if (out_device &
6413 (AUDIO_DEVICE_OUT_USB_DEVICE |
6414 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07006415 switch (adev->voice.tty_mode) {
6416 case TTY_MODE_FULL:
6417 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
6418 break;
6419 case TTY_MODE_VCO:
6420 // since voice will be captured from handset mic, use existing device
6421 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
6422 break;
6423 case TTY_MODE_HCO:
6424 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
6425 break;
6426 default:
6427 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07006428 }
6429 goto exit;
6430 }
6431 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07006432 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006433 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6434 out_device & AUDIO_DEVICE_OUT_LINE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006435 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
6436 audio_extn_should_use_handset_anc(channel_count)) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306437 if ((my_data->fluence_type != FLUENCE_NONE) &&
6438 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -08006439 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
6440 adev->acdb_settings |= DMIC_FLAG;
6441 } else {
6442 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
6443 }
Banajit Goswamide0ea452014-04-07 12:11:47 -07006444 adev->acdb_settings |= ANC_FLAG;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006445 } else if (my_data->fluence_type == FLUENCE_NONE ||
Vikram Pandurangae7b21342017-06-05 15:57:23 -07006446 (my_data->fluence_in_voice_call == false &&
6447 my_data->fluence_in_hfp_call == false)) {
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306448 if (out_device & AUDIO_DEVICE_OUT_LINE &&
6449 audio_extn_hfp_is_active(adev)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006450 snd_device = my_data->fluence_sb_enabled ?
6451 SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB
6452 : SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306453 } else {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006454 snd_device = my_data->fluence_sb_enabled ?
6455 SND_DEVICE_IN_HANDSET_MIC_SB
6456 : SND_DEVICE_IN_HANDSET_MIC;
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306457 }
6458 if (audio_extn_hfp_is_active(adev))
6459 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006460 } else {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306461 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6462 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6463 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
6464 adev->acdb_settings |= TMIC_FLAG;
Aalique Grahame22e49102018-12-18 14:23:57 -08006465 } else if (is_operator_tmus())
6466 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
6467 else { /* for FLUENCE_DUAL_MIC and SOURCE_DUAL_MIC */
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006468 snd_device = my_data->fluence_sb_enabled ?
6469 SND_DEVICE_IN_VOICE_DMIC_SB
6470 : SND_DEVICE_IN_VOICE_DMIC;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306471 adev->acdb_settings |= DMIC_FLAG;
6472 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006473 }
6474 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
6475 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05306476 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006477 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006478 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08006479 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6480 if (adev->bluetooth_nrec)
6481 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6482 else
6483 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6484 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006485 if (adev->bluetooth_nrec)
6486 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6487 else
6488 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6489 } else {
6490 if (adev->bluetooth_nrec)
6491 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6492 else
6493 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6494 }
Aalique Grahame37659862017-12-03 22:34:26 -08006495 } else if ((out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
6496 adev->dp_allowed_for_voice) {
6497 if (audio_extn_usb_is_capture_supported())
6498 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
6499 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006500 snd_device = my_data->fluence_sb_enabled ?
6501 SND_DEVICE_IN_HANDSET_MIC_SB
6502 : SND_DEVICE_IN_HANDSET_MIC;
Aalique Grahame37659862017-12-03 22:34:26 -08006503
6504 if (voice_is_in_call(adev))
6505 platform_set_echo_reference(adev, true, out_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08006506 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
6507 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
6508 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Derek Chen25496072019-06-23 01:05:27 -07006509 out_device & AUDIO_DEVICE_OUT_LINE ||
6510 out_device & AUDIO_DEVICE_OUT_BUS) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006511 if (my_data->fluence_type != FLUENCE_NONE &&
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05306512 (my_data->fluence_in_voice_call ||
6513 my_data->fluence_in_hfp_call) &&
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006514 my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306515 if((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6516 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306517 adev->acdb_settings |= QMIC_FLAG;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006518 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006519 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6520 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6521 adev->acdb_settings |= TMIC_FLAG;
6522 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_TMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006523 } else {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306524 adev->acdb_settings |= DMIC_FLAG;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08006525 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6526 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
6527 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006528 snd_device = my_data->fluence_sb_enabled ?
6529 SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB
6530 : SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006531 }
Dhanalakshmi Siddani1eb3a352017-06-05 15:18:23 +05306532 if (audio_extn_hfp_is_active(adev))
6533 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006534 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08006535 if (adev->enable_hfp) {
6536 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006537 platform_set_echo_reference(adev, true, out_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08006538 } else {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006539 snd_device = my_data->fluence_sb_enabled ?
6540 SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB
6541 : SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006542 if (audio_extn_hfp_is_active(adev))
6543 platform_set_echo_reference(adev, true, out_device);
6544 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006545 }
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07006546 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07006547 snd_device = SND_DEVICE_IN_VOICE_RX;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306548 } else if (out_device &
6549 (AUDIO_DEVICE_OUT_USB_DEVICE |
6550 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006551 if (audio_extn_usb_is_capture_supported()) {
6552 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
6553 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
6554 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
6555 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
6556 } else {
6557 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
6558 }
Aditya Bavanari8a715322019-04-08 20:04:56 +05306559 } else {
6560 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006561 }
juyuchen2d415992018-11-16 14:15:16 +08006562 } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) {
6563 snd_device = SND_DEVICE_IN_VOICE_HEARING_AID;
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07006564 }
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05306565 } else if (my_data->use_generic_handset == true && // system prop is enabled
6566 (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available
6567 ((in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) || // AND device is buit-in mic or back mic
6568 (in_device & AUDIO_DEVICE_IN_BACK_MIC)) &&
6569 (my_data->fluence_in_audio_rec == true && // AND fluencepro is enabled
6570 my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6571 (source == AUDIO_SOURCE_CAMCORDER || // AND source is cam/mic/unprocessed
6572 source == AUDIO_SOURCE_UNPROCESSED ||
6573 source == AUDIO_SOURCE_MIC)) {
6574 snd_device = SND_DEVICE_IN_HANDSET_GENERIC_QMIC;
6575 platform_set_echo_reference(adev, true, out_device);
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306576 } else if (my_data->use_generic_handset == true && // System prop is enabled
6577 (my_data->ambisonic_capture == true) && // Enable Ambisonic capture
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05306578 (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306579 ((in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) || // AND device is Built-in
6580 (in_device & AUDIO_DEVICE_IN_BACK_MIC)) && // OR Back-mic
6581 (source == AUDIO_SOURCE_MIC || // AND source is MIC for 16bit
6582 source == AUDIO_SOURCE_UNPROCESSED || // OR unprocessed for 24bit
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006583 source == AUDIO_SOURCE_CAMCORDER) && // OR camera usecase
6584 ((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) && // AND 4mic channel mask
6585 (sample_rate == 48000)) { // AND sample rate is 48Khz
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05306586 snd_device = SND_DEVICE_IN_HANDSET_GENERIC_QMIC;
6587 /* Below check is true only in LA build to set
6588 ambisonic profile. In LE hal client will set profile
6589 */
Eric Laurent637e2d42018-11-15 12:24:31 -08006590 if (my_data->ambisonic_profile == true &&
6591 in != NULL)
6592 strlcpy(in->profile, "record_ambisonic",
6593 sizeof(in->profile));
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306594
Eric Laurent637e2d42018-11-15 12:24:31 -08006595 if (in != NULL && !strncmp(in->profile, "record_ambisonic",
6596 strlen("record_ambisonic"))) {
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306597 /* Validate input stream configuration for
6598 Ambisonic capture.
6599 */
6600 if (((int)channel_mask != (int)AUDIO_CHANNEL_INDEX_MASK_4) ||
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006601 (sample_rate != 48000)) {
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306602 snd_device = SND_DEVICE_NONE;
6603 ALOGW("Unsupported Input configuration for ambisonic capture");
6604 goto exit;
6605 }
6606 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006607 } else if (source == AUDIO_SOURCE_CAMCORDER) {
6608 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
6609 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent4b084132018-10-19 17:33:43 -07006610 switch (adev->camera_orientation) {
6611 case CAMERA_BACK_LANDSCAPE:
6612 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
6613 break;
6614 case CAMERA_BACK_INVERT_LANDSCAPE:
6615 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
6616 break;
6617 case CAMERA_BACK_PORTRAIT:
6618 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
6619 break;
6620 case CAMERA_FRONT_LANDSCAPE:
6621 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
6622 break;
6623 case CAMERA_FRONT_INVERT_LANDSCAPE:
6624 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
6625 break;
6626 case CAMERA_FRONT_PORTRAIT:
6627 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
6628 break;
6629 default:
6630 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
6631 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
6632 break;
6633 }
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306634 if (str_bitwidth == 16) {
6635 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6636 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6637 (channel_count == 2))
Aalique Grahame22e49102018-12-18 14:23:57 -08006638 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306639 else
6640 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
6641 }
6642 /*
6643 * for other bit widths
6644 */
6645 else {
6646 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6647 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6648 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6649 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
6650 }
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306651 else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306652 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6653 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306654 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306655 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6656 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
6657 } else {
6658 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
6659 }
6660 }
6661 }
6662 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
Eric Laurentb23d5282013-05-14 15:27:20 -07006663 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306664 if (my_data->fluence_in_voice_rec && channel_count == 1) {
6665 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6666 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006667 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006668 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
6669 else
6670 snd_device = SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306671 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6672 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006673 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006674 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
6675 else
6676 snd_device = SND_DEVICE_IN_VOICE_REC_TMIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306677 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6678 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006679 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006680 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
6681 else
6682 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Vidyakumar Athota78b70c02015-06-29 17:19:45 -07006683 }
Carter Hsu2e429db2019-05-14 18:50:52 +08006684 in->enable_ec_port = true;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306685 } else if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6686 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6687 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6688 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306689 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306690 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6691 snd_device = SND_DEVICE_IN_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306692 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306693 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6694 snd_device = SND_DEVICE_IN_QUAD_MIC;
6695 }
6696 if (snd_device == SND_DEVICE_NONE) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006697 if (in != NULL && in->enable_aec) {
6698 if (in->enable_ns) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006699 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
6700 } else {
6701 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
6702 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006703 } else if (in != NULL && in->enable_ns)
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306704 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
6705 else
6706 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08006707 }
Aalique Grahame22e49102018-12-18 14:23:57 -08006708 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6709 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306710 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006711 snd_device = fixup_usb_headset_mic_snd_device(platform,
6712 SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC,
6713 SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC);
Eric Laurentb23d5282013-05-14 15:27:20 -07006714 }
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306715 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
6716 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
6717 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6718 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6719 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6720 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306721 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306722 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6723 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306724 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306725 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6726 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
6727 } else {
6728 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
6729 }
6730 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306731 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306732 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006733 snd_device = fixup_usb_headset_mic_snd_device(platform,
6734 SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC,
6735 SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC);
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306736 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306737 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
6738 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006739 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
6740 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6741 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
6742 !audio_extn_usb_is_capture_supported()))
Eric Laurentb23d5282013-05-14 15:27:20 -07006743 in_device = AUDIO_DEVICE_IN_BACK_MIC;
kunleizdcf967a2018-08-07 17:09:11 +08006744 else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
6745 in_device = AUDIO_DEVICE_IN_BUILTIN_MIC;
6746 else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET)
6747 in_device = AUDIO_DEVICE_IN_WIRED_HEADSET;
6748 else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE)
6749 in_device = AUDIO_DEVICE_IN_USB_DEVICE;
6750
6751 in_device = ((out_device == AUDIO_DEVICE_NONE) ?
6752 AUDIO_DEVICE_IN_BUILTIN_MIC : in_device) & ~AUDIO_DEVICE_BIT_IN;
6753
Eric Laurent637e2d42018-11-15 12:24:31 -08006754 if (in)
Carter Hsu2e429db2019-05-14 18:50:52 +08006755 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006756 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08006757 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
6758 channel_count == 1 ) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006759 if(my_data->fluence_in_audio_rec) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306760 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306761 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006762 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006763 platform_set_echo_reference(adev, true, out_device);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306764 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6765 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306766 snd_device = SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO;
6767 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6768 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306769 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
6770 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6771 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006772 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006773 platform_set_echo_reference(adev, true, out_device);
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006774 }
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08006775 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306776 } else if (in_device & AUDIO_DEVICE_IN_LOOPBACK) {
6777 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05306778 usecase = get_usecase_from_list(adev, uc_id);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306779 if (usecase == NULL) {
6780 ALOGE("%s: Could not find the record usecase", __func__);
6781 snd_device = SND_DEVICE_NONE;
6782 goto exit;
6783 }
6784
6785 int ch_count = audio_channel_count_from_in_mask(channel_mask);
6786 snd_device = audio_extn_get_loopback_snd_device(adev, usecase,
6787 ch_count);
6788 ALOGD("%s: snd device %d", __func__, snd_device);
6789 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006790 }
Mingming Yin12125e82015-10-26 20:40:36 -07006791 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07006792 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07006793 } else if (source == AUDIO_SOURCE_DEFAULT) {
6794 goto exit;
6795 }
6796
Eric Laurent637e2d42018-11-15 12:24:31 -08006797 if (in && (audio_extn_ssr_get_stream() == in))
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07006798 snd_device = SND_DEVICE_IN_THREE_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006799
6800 if (snd_device != SND_DEVICE_NONE) {
6801 goto exit;
6802 }
6803
6804 if (in_device != AUDIO_DEVICE_NONE &&
6805 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
6806 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
6807 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006808 if ((in && (audio_extn_ssr_get_stream() == in)) ||
Aalique Grahame22e49102018-12-18 14:23:57 -08006809 ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
6810 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4))
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07006811 snd_device = SND_DEVICE_IN_QUAD_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006812 else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
6813 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3)
6814 snd_device = SND_DEVICE_IN_THREE_MIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006815 else if ((my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_TRI_MIC | FLUENCE_QUAD_MIC)) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306816 (channel_count == 2) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Aalique Grahame22e49102018-12-18 14:23:57 -08006817 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07006818 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006819 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6820 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006821 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006822 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6823 channel_count == 2)
6824 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
6825 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006826 snd_device = my_data->fluence_sb_enabled ?
6827 SND_DEVICE_IN_SPEAKER_MIC_SB
6828 : SND_DEVICE_IN_SPEAKER_MIC;
Ramu Gottipati813ae982018-07-25 14:14:48 +05306829 } else if (in_device & AUDIO_DEVICE_IN_LINE) {
6830 snd_device = SND_DEVICE_IN_LINE;
Eric Laurentb23d5282013-05-14 15:27:20 -07006831 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6832 snd_device = SND_DEVICE_IN_HEADSET_MIC;
6833 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Zhou Song12c29502019-03-16 10:37:18 +08006834 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6835 if (adev->bluetooth_nrec)
6836 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6837 else
6838 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6839 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006840 if (adev->bluetooth_nrec)
6841 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6842 else
6843 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6844 } else {
6845 if (adev->bluetooth_nrec)
6846 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6847 else
6848 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6849 }
Ralf Herzafb164f2018-07-03 07:08:07 +02006850 } else if (in_device & AUDIO_DEVICE_IN_SPDIF) {
6851 snd_device = SND_DEVICE_IN_SPDIF;
Florian Pfister1a84f312018-07-19 14:38:18 +02006852 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
6853 snd_device = SND_DEVICE_IN_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07006854 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
6855 snd_device = SND_DEVICE_IN_HDMI_MIC;
Ralf Herz76b455c2018-09-10 13:58:04 +02006856 } else if (in_device & AUDIO_DEVICE_IN_HDMI_ARC) {
Ralf Herzafb164f2018-07-03 07:08:07 +02006857 snd_device = SND_DEVICE_IN_HDMI_ARC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006858 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
6859 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
6860 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin12125e82015-10-26 20:40:36 -07006861 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07006862 snd_device = SND_DEVICE_IN_CAPTURE_FM;
kunleiz1a1d26c2018-06-14 18:48:16 +08006863 } else if (audio_extn_usb_connected(NULL) && audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006864 snd_device = fixup_usb_headset_mic_snd_device(platform,
6865 SND_DEVICE_IN_USB_HEADSET_MIC,
6866 SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC);
Eric Laurentb23d5282013-05-14 15:27:20 -07006867 } else {
6868 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
6869 ALOGW("%s: Using default handset-mic", __func__);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006870 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6871 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006872 }
6873 } else {
6874 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006875 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6876 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006877 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
6878 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006879 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
6880 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306881 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6882 (channel_count == 2)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006883 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306884 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
6885 (channel_count == 1)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006886 snd_device = my_data->fluence_sb_enabled ?
6887 SND_DEVICE_IN_SPEAKER_MIC_SB
6888 : SND_DEVICE_IN_SPEAKER_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306889 } else {
6890 ALOGE("%s: something wrong: source type (%d) channel_count (%d) .."
6891 " no combination found .. setting to mono", __func__,
6892 my_data->source_mic_type, channel_count);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006893 snd_device = my_data->fluence_sb_enabled ?
6894 SND_DEVICE_IN_SPEAKER_MIC_SB
6895 : SND_DEVICE_IN_SPEAKER_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306896 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006897 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6898 out_device & AUDIO_DEVICE_OUT_LINE) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006899 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6900 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006901 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Zhou Song12c29502019-03-16 10:37:18 +08006902 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6903 if (adev->bluetooth_nrec)
6904 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6905 else
6906 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6907 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006908 if (adev->bluetooth_nrec)
6909 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6910 else
6911 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6912 } else {
6913 if (adev->bluetooth_nrec)
6914 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6915 else
6916 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6917 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006918 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
6919 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006920 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
6921 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
6922 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306923 } else if (out_device &
6924 (AUDIO_DEVICE_OUT_USB_DEVICE |
6925 AUDIO_DEVICE_OUT_USB_HEADSET)) {
kunleiz1a1d26c2018-06-14 18:48:16 +08006926 if (audio_extn_usb_is_capture_supported() && audio_extn_usb_connected(NULL))
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006927 snd_device = fixup_usb_headset_mic_snd_device(platform,
6928 SND_DEVICE_IN_USB_HEADSET_MIC,
6929 SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC);
Ashish Jain3e37a702016-11-25 12:27:15 +05306930 else
6931 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirucb5b5782018-10-12 20:42:07 +05306932
Eric Laurentb23d5282013-05-14 15:27:20 -07006933 } else {
6934 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
6935 ALOGW("%s: Using default handset-mic", __func__);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006936 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6937 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006938 }
6939 }
6940exit:
6941 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
6942 return snd_device;
6943}
6944
6945int platform_set_hdmi_channels(void *platform, int channel_count)
6946{
6947 struct platform_data *my_data = (struct platform_data *)platform;
6948 struct audio_device *adev = my_data->adev;
6949 struct mixer_ctl *ctl;
6950 const char *channel_cnt_str = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006951 char *mixer_ctl_name;
Eric Laurentb23d5282013-05-14 15:27:20 -07006952 switch (channel_count) {
6953 case 8:
6954 channel_cnt_str = "Eight"; break;
6955 case 7:
6956 channel_cnt_str = "Seven"; break;
6957 case 6:
6958 channel_cnt_str = "Six"; break;
6959 case 5:
6960 channel_cnt_str = "Five"; break;
6961 case 4:
6962 channel_cnt_str = "Four"; break;
6963 case 3:
6964 channel_cnt_str = "Three"; break;
6965 default:
6966 channel_cnt_str = "Two"; break;
6967 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006968
6969 switch(my_data->ext_disp_type) {
6970 case EXT_DISPLAY_TYPE_HDMI:
6971 mixer_ctl_name = "HDMI_RX Channels";
6972 break;
6973 case EXT_DISPLAY_TYPE_DP:
6974 mixer_ctl_name = "Display Port RX Channels";
6975 break;
6976 default:
6977 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
6978 return -EINVAL;
6979 }
6980
Eric Laurentb23d5282013-05-14 15:27:20 -07006981 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
6982 if (!ctl) {
6983 ALOGE("%s: Could not get ctl for mixer cmd - %s",
6984 __func__, mixer_ctl_name);
6985 return -EINVAL;
6986 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006987 ALOGV("Ext disp channel count: %s", channel_cnt_str);
Eric Laurentb23d5282013-05-14 15:27:20 -07006988 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
6989 return 0;
6990}
6991
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07006992int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07006993{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07006994 int channel_count;
6995 int max_channels = 2;
6996 int i = 0, ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07006997 struct platform_data *my_data = (struct platform_data *)platform;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07006998 edid_audio_info *info = NULL;
6999 ret = platform_get_edid_info(platform);
7000 info = (edid_audio_info *)my_data->edid_info;
Eric Laurentb23d5282013-05-14 15:27:20 -07007001
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07007002 if(ret == 0 && info != NULL) {
7003 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
7004 ALOGV("%s:format %d channel %d", __func__,
7005 info->audio_blocks_array[i].format_id,
7006 info->audio_blocks_array[i].channels);
7007 if (info->audio_blocks_array[i].format_id == LPCM) {
7008 channel_count = info->audio_blocks_array[i].channels;
7009 if (channel_count > max_channels) {
7010 max_channels = channel_count;
7011 }
7012 }
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07007013 }
Eric Laurentb23d5282013-05-14 15:27:20 -07007014 }
Eric Laurentb23d5282013-05-14 15:27:20 -07007015 return max_channels;
7016}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007017
7018static int platform_set_slowtalk(struct platform_data *my_data, bool state)
7019{
7020 int ret = 0;
7021 struct audio_device *adev = my_data->adev;
7022 struct mixer_ctl *ctl;
7023 const char *mixer_ctl_name = "Slowtalk Enable";
Manish Dewangan338c50a2017-09-12 15:22:03 +05307024 long set_values[ ] = {0,
7025 ALL_SESSION_VSID};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007026
7027 set_values[0] = state;
7028 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7029 if (!ctl) {
7030 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7031 __func__, mixer_ctl_name);
7032 ret = -EINVAL;
7033 } else {
7034 ALOGV("Setting slowtalk state: %d", state);
7035 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
7036 my_data->slowtalk = state;
7037 }
7038
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08007039 if (my_data->csd != NULL) {
7040 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
7041 if (ret < 0) {
7042 ALOGE("%s: csd_client_disable_device, failed, error %d",
7043 __func__, ret);
7044 }
7045 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007046 return ret;
7047}
7048
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307049static int set_hd_voice(struct platform_data *my_data, bool state)
7050{
7051 struct audio_device *adev = my_data->adev;
7052 struct mixer_ctl *ctl;
7053 char *mixer_ctl_name = "HD Voice Enable";
7054 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05307055 long set_values[ ] = {0,
7056 ALL_SESSION_VSID};
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307057
7058 set_values[0] = state;
7059 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7060 if (!ctl) {
7061 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7062 __func__, mixer_ctl_name);
7063 return -EINVAL;
7064 } else {
7065 ALOGV("Setting HD Voice state: %d", state);
7066 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
7067 my_data->hd_voice = state;
7068 }
7069
7070 return ret;
7071}
Tanya Finkel00130052014-07-14 04:26:56 -07007072
7073static int update_external_device_status(struct platform_data *my_data,
7074 char* event_name, bool status)
7075{
7076 int ret = 0;
7077 struct audio_usecase *usecase;
7078 struct listnode *node;
7079
7080 ALOGD("Recieved external event switch %s", event_name);
7081
7082 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
7083 my_data->external_spk_1 = status;
7084 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
7085 my_data->external_spk_2 = status;
7086 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
7087 my_data->external_mic = status;
7088 else {
7089 ALOGE("The audio event type is not found");
7090 return -EINVAL;
7091 }
7092
7093 list_for_each(node, &my_data->adev->usecase_list) {
7094 usecase = node_to_item(node, struct audio_usecase, list);
7095 select_devices(my_data->adev, usecase->id);
7096 }
7097
7098 return ret;
7099}
7100
Ben Rombergera04fabc2014-11-14 12:16:03 -08007101static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
7102{
7103 int err;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007104 char value[64];
7105 int ret = 0;
7106
7107 if(parms == NULL || cal == NULL)
7108 return ret;
7109
7110 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
7111 if (err >= 0) {
7112 str_parms_del(parms, "cal_persist");
7113 cal->persist = (uint32_t) strtoul(value, NULL, 0);
7114 ret = ret | 0x1;
7115 }
7116 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
7117 if (err >= 0) {
7118 str_parms_del(parms, "cal_apptype");
7119 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
7120 ret = ret | 0x2;
7121 }
7122 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
7123 if (err >= 0) {
7124 str_parms_del(parms, "cal_caltype");
7125 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
7126 ret = ret | 0x4;
7127 }
7128 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
7129 if (err >= 0) {
7130 str_parms_del(parms, "cal_samplerate");
7131 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
7132 ret = ret | 0x8;
7133 }
7134 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
7135 if (err >= 0) {
7136 str_parms_del(parms, "cal_devid");
7137 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
7138 ret = ret | 0x10;
7139 }
7140 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
7141 if (err >= 0) {
7142 str_parms_del(parms, "cal_snddevid");
7143 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
7144 ret = ret | 0x20;
7145 }
7146 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
7147 if (err >= 0) {
7148 str_parms_del(parms, "cal_topoid");
7149 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
7150 ret = ret | 0x40;
7151 }
7152 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
7153 if (err >= 0) {
7154 str_parms_del(parms, "cal_moduleid");
7155 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
7156 ret = ret | 0x80;
7157 }
Aditya Bavanari29bcea22017-10-03 20:10:35 +05307158#ifdef INSTANCE_ID_ENABLED
7159 err = str_parms_get_str(parms, "cal_instanceid", value, sizeof(value));
7160 if (err >= 0) {
7161 str_parms_del(parms, "cal_instanceid");
7162 cal->instance_id = (uint32_t) strtoul(value, NULL, 0);
7163 ret = ret | 0x100;
7164 }
7165#endif
Ben Rombergera04fabc2014-11-14 12:16:03 -08007166 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
7167 if (err >= 0) {
7168 str_parms_del(parms, "cal_paramid");
7169 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
Aditya Bavanari29bcea22017-10-03 20:10:35 +05307170 ret = ret | 0x200;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007171 }
7172 return ret;
7173}
7174
7175static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
7176 struct platform_data *my_data = (struct platform_data *)platform;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007177 struct stream_out out;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307178 acdb_audio_cal_cfg_t cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007179 uint8_t *dptr = NULL;
7180 int32_t dlen;
7181 int err, ret;
7182 if(value == NULL || platform == NULL || parms == NULL) {
7183 ALOGE("[%s] received null pointer, failed",__func__);
7184 goto done_key_audcal;
7185 }
7186
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05307187 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007188 /* parse audio calibration keys */
7189 ret = parse_audiocal_cfg(parms, &cal);
7190
7191 /* handle audio calibration data now */
7192 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
7193 if (err >= 0) {
7194 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
7195 dlen = strlen(value);
7196 if(dlen <= 0) {
7197 ALOGE("[%s] null data received",__func__);
7198 goto done_key_audcal;
7199 }
7200 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
7201 if(dptr == NULL) {
7202 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
7203 goto done_key_audcal;
7204 }
Aalique Grahame22e49102018-12-18 14:23:57 -08007205 dlen = b64_pton(value, dptr, dlen);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007206 if(dlen<=0) {
7207 ALOGE("[%s] data decoding failed %d", __func__, dlen);
7208 goto done_key_audcal;
7209 }
7210
Eric Laurent637e2d42018-11-15 12:24:31 -08007211 if (cal.dev_id) {
7212 if (audio_is_input_device(cal.dev_id)) {
7213 // FIXME: why pass an input device whereas
7214 // platform_get_input_snd_device() expects as an output device?
7215 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007216 } else {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007217 out.devices = cal.dev_id;
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08007218 out.sample_rate = cal.sampling_rate;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007219 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007220 }
7221 }
7222 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
7223 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
7224 cal.snd_dev_id, cal.acdb_dev_id);
7225 if(cal.acdb_dev_id == -EINVAL) {
7226 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
7227 __func__, cal.acdb_dev_id, cal.snd_dev_id);
7228 goto done_key_audcal;
7229 }
7230 if(my_data->acdb_set_audio_cal) {
7231 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
7232 }
7233 }
7234done_key_audcal:
7235 if(dptr != NULL)
7236 free(dptr);
7237}
7238
Ashish Jainf1eaa582016-05-23 20:54:24 +05307239static void true_32_bit_set_params(struct str_parms *parms,
7240 char *value, int len)
7241{
7242 int ret = 0;
7243
7244 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT,
7245 value,len);
7246 if (ret >= 0) {
Ramlal Karra10d22b92019-08-08 19:02:35 +05307247 if (value && !strncmp(value, "true", sizeof("true")))
Ashish Jainf1eaa582016-05-23 20:54:24 +05307248 supports_true_32_bit = true;
7249 else
7250 supports_true_32_bit = false;
7251 str_parms_del(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT);
7252 }
7253
7254}
7255
7256bool platform_supports_true_32bit()
7257{
7258 return supports_true_32_bit;
7259}
7260
Sudheer Papothifa9d2282015-09-17 01:53:25 +05307261static void perf_lock_set_params(struct platform_data *platform,
7262 struct str_parms *parms,
7263 char *value, int len)
7264{
7265 int err = 0, i = 0, num_opts = 0;
7266 char *test_r = NULL;
7267 char *opts = NULL;
7268 char *opts_size = NULL;
7269
7270 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS,
7271 value, len);
7272 if (err >= 0) {
7273 opts_size = strtok_r(value, ", ", &test_r);
7274 if (opts_size == NULL) {
7275 ALOGE("%s: incorrect perf lock opts\n", __func__);
7276 return;
7277 }
7278 num_opts = atoi(opts_size);
7279 if (num_opts > 0) {
7280 if (num_opts > MAX_PERF_LOCK_OPTS) {
7281 ALOGD("%s: num_opts %d exceeds max %d, setting to max\n",
7282 __func__, num_opts, MAX_PERF_LOCK_OPTS);
7283 num_opts = MAX_PERF_LOCK_OPTS;
7284 }
7285 for (i = 0; i < num_opts; i++) {
7286 opts = strtok_r(NULL, ", ", &test_r);
7287 if (opts == NULL) {
7288 ALOGE("%s: incorrect perf lock opts\n", __func__);
7289 break;
7290 }
7291 platform->adev->perf_lock_opts[i] = strtoul(opts, NULL, 16);
7292 }
7293 platform->adev->perf_lock_opts_size = i;
7294 }
7295 str_parms_del(parms, AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS);
7296 }
7297}
7298
Surendar Karka45850ae2018-07-02 17:45:27 +05307299static void platform_spkr_device_set_params(struct platform_data *platform,
7300 struct str_parms *parms,
7301 char *value, int len)
7302{
7303 int err = 0, i = 0, num_ch = 0;
7304 char *test_r = NULL;
7305 char *opts = NULL;
7306 char *ch_count = NULL;
7307
7308 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP,
7309 value, len);
7310 if (err >= 0) {
7311 platform->spkr_ch_map = calloc(1, sizeof(struct spkr_device_chmap));
7312 if (!platform->spkr_ch_map) {
7313 ALOGE("%s: failed to allocate mem for adm channel map\n", __func__);
7314 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7315 return ;
7316 }
7317
7318 ch_count = strtok_r(value, ", ", &test_r);
7319 if (ch_count == NULL) {
7320 ALOGE("%s: incorrect ch_map\n", __func__);
7321 free(platform->spkr_ch_map);
7322 platform->spkr_ch_map = NULL;
7323 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7324 return;
7325 }
7326
7327 num_ch = atoi(ch_count);
7328 if ((num_ch > 0) && (num_ch <= AUDIO_CHANNEL_COUNT_MAX) ) {
7329 platform->spkr_ch_map->num_ch = num_ch;
7330 for (i = 0; i < num_ch; i++) {
7331 opts = strtok_r(NULL, ", ", &test_r);
Jhansi Konathalad72b20e2018-10-16 13:35:14 +05307332 if (opts == NULL) {
7333 ALOGE("%s: incorrect ch_map\n", __func__);
7334 free(platform->spkr_ch_map);
7335 platform->spkr_ch_map = NULL;
7336 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7337 return;
7338 } else {
7339 platform->spkr_ch_map->chmap[i] = strtoul(opts, NULL, 16);
7340 }
Surendar Karka45850ae2018-07-02 17:45:27 +05307341 }
7342 }
7343 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7344 }
7345}
7346
Jhansi Konathala170875c2018-10-11 18:34:10 +05307347static void platform_set_fluence_params(void *platform, struct str_parms *parms, char *value, int len)
7348{
7349 struct platform_data *my_data = (struct platform_data *)platform;
7350 int err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value, len);
7351
7352 if (err >= 0) {
7353 if (!strncmp("fluence", value, sizeof("fluence")))
7354 my_data->fluence_type = FLUENCE_DUAL_MIC;
7355 else if (!strncmp("fluencepro", value, sizeof("fluencepro")))
7356 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
7357 else if (!strncmp("none", value, sizeof("none")))
7358 my_data->fluence_type = FLUENCE_NONE;
7359
7360 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_TYPE);
7361 }
7362
7363 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC, value, len);
7364 if (err >= 0) {
7365 if (!strncmp("true", value, sizeof("true")))
7366 my_data->fluence_type |= FLUENCE_TRI_MIC;
7367
7368 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC);
7369 }
7370
7371 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL, value, len);
7372 if (err >= 0) {
7373 if (!strncmp("true", value, sizeof("true")))
7374 my_data->fluence_in_voice_call = true;
7375 else
7376 my_data->fluence_in_voice_call = false;
7377
7378 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL);
7379 }
7380
7381 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC, value, len);
7382 if (err >= 0) {
7383 if (!strncmp("true", value, sizeof("true")))
7384 my_data->fluence_in_voice_rec = true;
7385 else
7386 my_data->fluence_in_voice_rec = false;
7387
7388 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC);
7389 }
7390
7391 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC, value, len);
7392 if (err >= 0) {
7393 if (!strncmp("true", value, sizeof("true")))
7394 my_data->fluence_in_audio_rec = true;
7395 else
7396 my_data->fluence_in_audio_rec = false;
7397
7398 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC);
7399 }
7400
7401 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER, value, len);
7402 if (err >= 0) {
7403 if (!strncmp("true", value, sizeof("true")))
7404 my_data->fluence_in_spkr_mode = true;
7405 else
7406 my_data->fluence_in_spkr_mode = false;
7407
7408 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER);
7409 }
7410
7411 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_MODE, value, len);
7412 if (err >= 0) {
7413 if (!strncmp("broadside", value, sizeof("broadside")))
7414 my_data->fluence_mode = FLUENCE_BROADSIDE;
7415 else if (!strncmp("endfire", value, sizeof("endfire")))
7416 my_data->fluence_mode = FLUENCE_ENDFIRE;
7417
7418 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_MODE);
7419 }
7420
7421 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL, value, len);
7422 if (err >= 0) {
7423 if (!strncmp("true", value, sizeof("true")))
7424 my_data->fluence_in_hfp_call = true;
7425 else
7426 my_data->fluence_in_hfp_call = false;
7427
7428 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL);
7429 }
7430}
7431
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007432int platform_set_parameters(void *platform, struct str_parms *parms)
7433{
7434 struct platform_data *my_data = (struct platform_data *)platform;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007435 char *value=NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307436 int len;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007437 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007438 char *kv_pairs = str_parms_to_str(parms);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05307439 struct listnode *node;
7440 struct meta_key_list *key_info;
7441 int key = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007442
Mingming Yin7b762e72015-03-04 13:47:32 -08007443 if(kv_pairs == NULL) {
7444 ret = -ENOMEM;
7445 ALOGE("[%s] key-value pair is NULL",__func__);
7446 goto done;
7447 }
7448
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007449 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007450
Ben Rombergera04fabc2014-11-14 12:16:03 -08007451 len = strlen(kv_pairs);
7452 value = (char*)calloc(len, sizeof(char));
7453 if(value == NULL) {
7454 ret = -ENOMEM;
7455 ALOGE("[%s] failed to allocate memory",__func__);
7456 goto done;
7457 }
7458 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007459 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007460 bool state = false;
7461 if (!strncmp("true", value, sizeof("true"))) {
7462 state = true;
7463 }
7464
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007465 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007466 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007467 if (ret)
7468 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007469 }
7470
Ben Rombergera04fabc2014-11-14 12:16:03 -08007471 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, len);
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307472 if (err >= 0) {
7473 bool state = false;
7474 if (!strncmp("true", value, sizeof("true"))) {
7475 state = true;
7476 }
7477
7478 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
7479 if (my_data->hd_voice != state) {
7480 ret = set_hd_voice(my_data, state);
7481 if (ret)
7482 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
7483 } else {
7484 ALOGV("%s: HD Voice already set to %d", __func__, state);
7485 }
7486 }
7487
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007488 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergera04fabc2014-11-14 12:16:03 -08007489 value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007490 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08007491 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
7492
7493 if (my_data->acdb_reload_vocvoltable == NULL) {
7494 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
7495 } else if (!strcmp(value, "on")) {
7496 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
7497 my_data->voice_feature_set = 1;
7498 }
7499 } else {
7500 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
7501 my_data->voice_feature_set = 0;
7502 }
7503 }
7504 }
7505
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05307506 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB,
7507 value, len);
7508 if (err >= 0) {
7509 str_parms_del(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB);
7510
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05307511 if (my_data->acdb_reload_v2) {
7512 my_data->acdb_reload_v2(value, my_data->snd_card_name,
7513 my_data->cvd_version, &my_data->acdb_meta_key_list);
7514 } else if (my_data->acdb_reload) {
7515 node = list_head(&my_data->acdb_meta_key_list);
7516 key_info = node_to_item(node, struct meta_key_list, list);
7517 key = key_info->cal_info.nKey;
7518 my_data->acdb_reload(value, my_data->snd_card_name,
7519 my_data->cvd_version, key);
7520 }
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05307521 }
7522
Rohit kumard3c3b912016-11-15 18:50:31 +05307523 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
7524 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER, value, len);
7525 if (err >= 0) {
7526 if (!strncmp("left", value, sizeof("left")))
7527 my_data->mono_speaker = SPKR_1;
7528 else if (!strncmp("right", value, sizeof("right")))
7529 my_data->mono_speaker = SPKR_2;
Rohit kumarf4120402016-08-05 19:19:48 +05307530
Rohit kumard3c3b912016-11-15 18:50:31 +05307531 str_parms_del(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER);
7532 }
Rohit kumarf4120402016-08-05 19:19:48 +05307533 }
Tanya Finkel00130052014-07-14 04:26:56 -07007534 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE,
Ben Rombergera04fabc2014-11-14 12:16:03 -08007535 value, len);
Tanya Finkel00130052014-07-14 04:26:56 -07007536 if (err >= 0) {
7537 char *event_name, *status_str;
7538 bool status = false;
7539 str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE);
7540 event_name = strtok_r(value, ",", &status_str);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08007541 if (!event_name) {
7542 ret = -EINVAL;
7543 ALOGE("%s: event_name is NULL", __func__);
7544 goto done;
7545 }
Tanya Finkel00130052014-07-14 04:26:56 -07007546 ALOGV("%s: recieved update of external audio device %s %s",
7547 __func__,
7548 event_name, status_str);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07007549 if (!strncmp(status_str, "ON", sizeof("ON")))
Tanya Finkel00130052014-07-14 04:26:56 -07007550 status = true;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07007551 else if (!strncmp(status_str, "OFF", sizeof("OFF")))
Tanya Finkel00130052014-07-14 04:26:56 -07007552 status = false;
7553 update_external_device_status(my_data, event_name, status);
7554 }
7555
Aalique Grahame22e49102018-12-18 14:23:57 -08007556 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
7557 value, len);
7558 if (err >= 0) {
7559 struct operator_info *info;
Weiyin Jiang2995f662019-04-17 14:25:12 +08007560 char *str = value, *context = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08007561 char *name;
7562
7563 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
7564 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
Weiyin Jiang2995f662019-04-17 14:25:12 +08007565 name = strtok_r(str, ";", &context);
7566 if ((info == NULL) || (name == NULL)) {
7567 ret = -EINVAL;
7568 ALOGE("%s invalid info or name", __func__);
7569 goto done;
7570 }
7571
Aalique Grahame22e49102018-12-18 14:23:57 -08007572 info->name = strdup(name);
7573 info->mccmnc = strdup(str + strlen(name) + 1);
7574
7575 list_add_tail(&operator_info_list, &info->list);
7576 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
7577 }
7578
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05307579 err = str_parms_get_str(parms, PLATFORM_MAX_MIC_COUNT,
7580 value, sizeof(value));
7581 if (err >= 0) {
7582 str_parms_del(parms, PLATFORM_MAX_MIC_COUNT);
7583 my_data->max_mic_count = atoi(value);
7584 ALOGV("%s: max_mic_count %d", __func__, my_data->max_mic_count);
7585 }
7586
Jhansi Konathala170875c2018-10-11 18:34:10 +05307587 platform_set_fluence_params(platform, parms, value, len);
7588
Ben Rombergera04fabc2014-11-14 12:16:03 -08007589 /* handle audio calibration parameters */
7590 set_audiocal(platform, parms, value, len);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007591 native_audio_set_params(platform, parms, value, len);
Sudheer Papothi991966d2015-07-20 21:54:36 +05307592 audio_extn_spkr_prot_set_parameters(parms, value, len);
Kuirong Wang1cad7142016-05-24 15:21:56 -07007593 audio_extn_usb_set_sidetone_gain(parms, value, len);
Aalique Grahame22e49102018-12-18 14:23:57 -08007594 audio_extn_hfp_set_parameters(my_data->adev, parms);
Sudheer Papothifa9d2282015-09-17 01:53:25 +05307595 perf_lock_set_params(platform, parms, value, len);
Ashish Jainf1eaa582016-05-23 20:54:24 +05307596 true_32_bit_set_params(parms, value, len);
Ramlal Karra10d22b92019-08-08 19:02:35 +05307597 audio_extn_hifi_filter_set_params(parms, value, len);
Surendar Karka45850ae2018-07-02 17:45:27 +05307598 platform_spkr_device_set_params(platform, parms, value, len);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007599done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007600 ALOGV("%s: exit with code(%d)", __func__, ret);
Mingming Yin7b762e72015-03-04 13:47:32 -08007601 if(kv_pairs != NULL)
7602 free(kv_pairs);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007603 if(value != NULL)
7604 free(value);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007605 return ret;
7606}
7607
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007608int platform_set_incall_recording_session_id(void *platform,
7609 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07007610{
7611 int ret = 0;
7612 struct platform_data *my_data = (struct platform_data *)platform;
7613 struct audio_device *adev = my_data->adev;
7614 struct mixer_ctl *ctl;
7615 const char *mixer_ctl_name = "Voc VSID";
7616 int num_ctl_values;
7617 int i;
7618
7619 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7620 if (!ctl) {
7621 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7622 __func__, mixer_ctl_name);
7623 ret = -EINVAL;
7624 } else {
7625 num_ctl_values = mixer_ctl_get_num_values(ctl);
7626 for (i = 0; i < num_ctl_values; i++) {
7627 if (mixer_ctl_set_value(ctl, i, session_id)) {
7628 ALOGV("Error: invalid session_id: %x", session_id);
7629 ret = -EINVAL;
7630 break;
7631 }
7632 }
7633 }
7634
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007635 if (my_data->csd != NULL) {
7636 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
7637 if (ret < 0) {
7638 ALOGE("%s: csd_client_start_record failed, error %d",
7639 __func__, ret);
7640 }
7641 }
7642
7643 return ret;
7644}
7645
Aalique Grahame22e49102018-12-18 14:23:57 -08007646#ifdef INCALL_STEREO_CAPTURE_ENABLED
7647int platform_set_incall_recording_session_channels(void *platform,
7648 uint32_t channel_count)
7649{
7650 int ret = 0;
7651 struct platform_data *my_data = (struct platform_data *)platform;
7652 struct audio_device *adev = my_data->adev;
7653 const char *mixer_ctl_name = "Voc Rec Config";
7654 int num_ctl_values;
7655 int i;
7656 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7657
7658 if (!ctl) {
7659 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7660 __func__, mixer_ctl_name);
7661 ret = -EINVAL;
7662 } else {
7663 num_ctl_values = mixer_ctl_get_num_values(ctl);
7664 for (i = 0; i < num_ctl_values; i++) {
7665 if (mixer_ctl_set_value(ctl, i, channel_count)) {
7666 ALOGE("Error: invalid channel count: %x", channel_count);
7667 ret = -EINVAL;
7668 break;
7669 }
7670 }
7671 }
7672
7673 return ret;
7674}
7675#endif /* INCALL_STEREO_CAPTURE_ENABLED end */
7676
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007677int platform_stop_incall_recording_usecase(void *platform)
7678{
7679 int ret = 0;
7680 struct platform_data *my_data = (struct platform_data *)platform;
7681
7682 if (my_data->csd != NULL) {
7683 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
7684 if (ret < 0) {
7685 ALOGE("%s: csd_client_stop_record failed, error %d",
7686 __func__, ret);
7687 }
7688 }
7689
7690 return ret;
7691}
7692
7693int platform_start_incall_music_usecase(void *platform)
7694{
7695 int ret = 0;
7696 struct platform_data *my_data = (struct platform_data *)platform;
7697
7698 if (my_data->csd != NULL) {
7699 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
7700 if (ret < 0) {
7701 ALOGE("%s: csd_client_start_playback failed, error %d",
7702 __func__, ret);
7703 }
7704 }
7705
7706 return ret;
7707}
7708
7709int platform_stop_incall_music_usecase(void *platform)
7710{
7711 int ret = 0;
7712 struct platform_data *my_data = (struct platform_data *)platform;
7713
7714 if (my_data->csd != NULL) {
7715 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
7716 if (ret < 0) {
7717 ALOGE("%s: csd_client_stop_playback failed, error %d",
7718 __func__, ret);
7719 }
7720 }
7721
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07007722 return ret;
7723}
7724
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07007725int platform_update_lch(void *platform, struct voice_session *session,
7726 enum voice_lch_mode lch_mode)
7727{
7728 int ret = 0;
7729 struct platform_data *my_data = (struct platform_data *)platform;
7730
7731 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
7732 ret = my_data->csd->set_lch(session->vsid, lch_mode);
7733 else
7734 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
7735
7736 return ret;
7737}
7738
Ben Rombergera04fabc2014-11-14 12:16:03 -08007739static void get_audiocal(void *platform, void *keys, void *pReply) {
7740 struct platform_data *my_data = (struct platform_data *)platform;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007741 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007742 struct str_parms *query = (struct str_parms *)keys;
7743 struct str_parms *reply=(struct str_parms *)pReply;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307744 acdb_audio_cal_cfg_t cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007745 uint8_t *dptr = NULL;
7746 char value[512] = {0};
7747 char *rparms=NULL;
7748 int ret=0, err;
7749 uint32_t param_len;
7750
7751 if(query==NULL || platform==NULL || reply==NULL) {
7752 ALOGE("[%s] received null pointer",__func__);
7753 ret=-EINVAL;
7754 goto done;
7755 }
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05307756
7757 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007758 /* parse audiocal configuration keys */
7759 ret = parse_audiocal_cfg(query, &cal);
7760 if(ret == 0) {
7761 /* No calibration keys found */
7762 goto done;
7763 }
7764 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
7765 if (err >= 0) {
7766 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
7767 } else {
7768 goto done;
7769 }
7770
Eric Laurent637e2d42018-11-15 12:24:31 -08007771 if (cal.dev_id & AUDIO_DEVICE_BIT_IN) {
7772 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007773 } else if(cal.dev_id) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007774 out.devices = cal.dev_id;
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08007775 out.sample_rate = cal.sampling_rate;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007776 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007777 }
7778 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
7779 if (cal.acdb_dev_id < 0) {
7780 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
7781 __func__, cal.snd_dev_id);
7782 ret = -EINVAL;
7783 goto done_key_audcal;
7784 }
7785 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
7786 __func__, cal.snd_dev_id, cal.acdb_dev_id);
7787
7788 param_len = MAX_SET_CAL_BYTE_SIZE;
7789 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
7790 if(dptr == NULL) {
7791 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
7792 ret = -ENOMEM;
7793 goto done_key_audcal;
7794 }
7795 if (my_data->acdb_get_audio_cal != NULL) {
7796 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
7797 if (ret == 0) {
Ben Rombergera04fabc2014-11-14 12:16:03 -08007798 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
7799 ret = -EINVAL;
7800 goto done_key_audcal;
7801 }
7802 /* Allocate memory for encoding */
7803 rparms = (char*)calloc((param_len*2), sizeof(char));
7804 if(rparms == NULL) {
7805 ALOGE("[%s] Memory allocation failed for size %d",
7806 __func__, param_len*2);
7807 ret = -ENOMEM;
7808 goto done_key_audcal;
7809 }
7810 if(cal.persist==0 && cal.module_id && cal.param_id) {
7811 err = b64encode(dptr+12, param_len-12, rparms);
7812 } else {
7813 err = b64encode(dptr, param_len, rparms);
7814 }
7815 if(err < 0) {
7816 ALOGE("[%s] failed to convert data to string", __func__);
7817 ret = -EINVAL;
7818 goto done_key_audcal;
7819 }
7820 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
7821 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
7822 }
7823 }
7824done_key_audcal:
7825 if(ret != 0) {
7826 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
7827 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
7828 }
7829done:
7830 if(dptr != NULL)
7831 free(dptr);
7832 if(rparms != NULL)
7833 free(rparms);
7834}
7835
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007836void platform_get_parameters(void *platform,
7837 struct str_parms *query,
7838 struct str_parms *reply)
7839{
7840 struct platform_data *my_data = (struct platform_data *)platform;
Aalique Grahame37659862017-12-03 22:34:26 -08007841 struct audio_device *adev = my_data->adev;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007842 char value[512] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007843 int ret;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007844 char *kv_pairs = NULL;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307845 char propValue[PROPERTY_VALUE_MAX]={0};
7846 bool prop_playback_enabled = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007847
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08007848 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
7849 value, sizeof(value));
7850 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007851 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
7852 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08007853 }
7854
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307855 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
7856 value, sizeof(value));
7857 if (ret >= 0) {
7858 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
7859 my_data->hd_voice?"true":"false");
7860 }
7861
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08007862 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
7863 value, sizeof(value));
7864 if (ret >= 0) {
7865 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
7866 strlcpy(value, "on", sizeof(value));
7867 } else {
7868 strlcpy(value, "off", sizeof(value));
7869 }
7870
7871 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
7872 }
7873
Aalique Grahame37659862017-12-03 22:34:26 -08007874 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE,
7875 value, sizeof(value));
7876
7877 if (ret >= 0) {
7878 if (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP &&
7879 adev->dp_allowed_for_voice)
7880 strlcpy(value, "true", sizeof(value));
7881 else
7882 strlcpy(value, "false", sizeof(value));
7883
7884 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE, value);
7885 }
7886
Weiyin Jiangff72f812018-04-13 15:02:33 +08007887 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK,
7888 value, sizeof(value));
7889 if (ret >= 0) {
7890 ret = platform_get_edid_info(platform);
7891 edid_audio_info *info = (edid_audio_info *)my_data->edid_info;
7892 if (ret == 0 && info != NULL) {
7893 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK, info->channel_mask);
7894 }
7895 }
7896
Ben Rombergera04fabc2014-11-14 12:16:03 -08007897 /* Handle audio calibration keys */
7898 get_audiocal(platform, query, reply);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007899 native_audio_get_params(query, reply, value, sizeof(value));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007900
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307901 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED,
7902 value, sizeof(value));
7903 if (ret >= 0) {
7904 int isallowed = 1; /*true*/
7905
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07007906 if (property_get("vendor.voice.playback.conc.disabled", propValue, NULL)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307907 prop_playback_enabled = atoi(propValue) ||
7908 !strncmp("true", propValue, 4);
7909 }
7910
Dhanalakshmi Siddania15c6792016-08-10 15:33:53 +05307911 if ((prop_playback_enabled && (voice_is_in_call(my_data->adev))) ||
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05307912 (CARD_STATUS_OFFLINE == my_data->adev->card_status)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307913 char *decoder_mime_type = value;
7914
7915 //check if unsupported mime type or not
7916 if(decoder_mime_type) {
Alexy Josephb1379942016-01-29 15:49:38 -08007917 unsigned int i = 0;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307918 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
7919 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
7920 strlen(dsp_only_decoders_mime[i]))) {
7921 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
7922 isallowed = 0;
7923 break;
7924 }
7925 }
7926 }
7927 }
7928 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED, isallowed);
7929 }
7930
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007931 kv_pairs = str_parms_to_str(reply);
7932 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
Narsinga Rao Chellacde45d12014-02-13 11:44:31 -08007933 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007934}
7935
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307936unsigned char* platform_get_license(void *platform, int *size)
7937{
7938 struct platform_data *my_data = (struct platform_data *)platform;
7939 char value[PROPERTY_VALUE_MAX] = {0};
7940 acdb_audio_cal_cfg_t cal;
7941 unsigned char *dptr = NULL;
7942 int ret=0;
7943 uint32_t param_len;
7944
7945 if (platform == NULL) {
7946 ALOGE("[%s] received null pointer %d ",__func__, __LINE__);
7947 ret = -EINVAL;
7948 goto done;
7949 }
7950 memset(&cal, 0, sizeof(cal));
7951 cal.persist = 1;
7952 cal.cal_type = AUDIO_CORE_METAINFO_CAL_TYPE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07007953 if (!property_get("vendor.audio.qaf.acdbid", value , "") && !atoi(value)) {
7954 ALOGE("[%s] vendor.audio.qaf.acdbid is not set %d ",__func__, __LINE__);
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307955 ret = -EINVAL;
7956 goto done;
7957 }
7958 cal.acdb_dev_id = (uint32_t) atoi (value);
7959 param_len = MAX_SET_CAL_BYTE_SIZE;
Sachin Mohan Gadage64c61e2017-07-17 18:11:16 +05307960 dptr = (unsigned char*) calloc(param_len, sizeof(unsigned char));
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307961 if (dptr == NULL) {
7962 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
7963 ret = -ENOMEM;
7964 goto done;
7965 }
7966 if (my_data->acdb_get_audio_cal != NULL) {
7967 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
7968 ALOGE("%s, ret[%d], param_len[%d] line %d", __func__, ret, param_len, __LINE__);
7969 if (ret == 0) {
7970 *size = param_len;
7971 return dptr;
7972 } else {
7973 *size = 0;
7974 }
7975 }
7976done:
7977 if (dptr != NULL)
7978 free(dptr);
7979
7980 return NULL;
7981}
7982
7983/* Delay in Us */
Ashish Jain5106d362016-05-11 19:23:33 +05307984/* Delay in Us, only to be used for PCM formats */
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007985int64_t platform_render_latency(audio_usecase_t usecase)
7986{
7987 switch (usecase) {
7988 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
Derek Chenf6318be2017-06-12 17:16:24 -04007989 case USECASE_AUDIO_PLAYBACK_MEDIA:
7990 case USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007991 return DEEP_BUFFER_PLATFORM_DELAY;
7992 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungana6927272019-02-20 15:17:07 -08007993 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Derek Chenf6318be2017-06-12 17:16:24 -04007994 case USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION:
7995 case USECASE_AUDIO_PLAYBACK_PHONE:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007996 return LOW_LATENCY_PLATFORM_DELAY;
Ashish Jain5106d362016-05-11 19:23:33 +05307997 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
7998 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
7999 return PCM_OFFLOAD_PLATFORM_DELAY;
Haynes Mathew George5beddd42016-06-27 18:33:40 -07008000 case USECASE_AUDIO_PLAYBACK_ULL:
8001 return ULL_PLATFORM_DELAY;
Haynes Mathew George16081042017-05-31 17:16:49 -07008002 case USECASE_AUDIO_PLAYBACK_MMAP:
8003 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07008004 default:
8005 return 0;
8006 }
8007}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07008008
Mingming Yine62d7842013-10-25 16:26:03 -07008009int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07008010{
Mingming Yinab429782013-11-07 11:16:55 -08008011 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin12125e82015-10-26 20:40:36 -07008012 if (source == AUDIO_SOURCE_FM_TUNER)
Mingming Yine62d7842013-10-25 16:26:03 -07008013 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
8014 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07008015}
Kiran Kandide144c82013-11-20 15:58:32 -08008016
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308017bool platform_listen_device_needs_event(snd_device_t snd_device)
Kiran Kandide144c82013-11-20 15:58:32 -08008018{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308019 bool needs_event = false;
8020
Kiran Kandide144c82013-11-20 15:58:32 -08008021 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
8022 (snd_device < SND_DEVICE_IN_END) &&
8023 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
Rohit kumarf4120402016-08-05 19:19:48 +05308024 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK) &&
8025 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1) &&
8026 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308027 needs_event = true;
8028
8029 return needs_event;
8030}
8031
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07008032bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
8033{
8034 return false;
8035}
8036
8037bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
8038{
8039 bool needs_event = false;
8040
8041 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
8042 (snd_device < SND_DEVICE_IN_END) &&
8043 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
Rohit kumarf4120402016-08-05 19:19:48 +05308044 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK) &&
8045 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1) &&
8046 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2))
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07008047 needs_event = true;
8048
8049 return needs_event;
8050}
8051
Quinn Malef15123f2017-04-27 18:58:05 -07008052bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308053{
Quinn Malef15123f2017-04-27 18:58:05 -07008054 bool needs_event = false;
8055
8056 switch(uc_id){
8057 /* concurrent playback usecases needs event */
8058 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
8059 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
8060 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
8061 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
Quinn Malef15123f2017-04-27 18:58:05 -07008062 case USECASE_AUDIO_PLAYBACK_FM:
8063 needs_event = true;
8064 break;
Quinn Male70f20f32019-06-26 16:50:26 -07008065 case USECASE_AUDIO_PLAYBACK_ULL:
8066 case USECASE_AUDIO_PLAYBACK_MMAP:
8067 if (property_get_bool("persist.vendor.audio.ull_playback_bargein",
8068 false))
8069 needs_event = true;
8070 break;
8071 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
8072 if (property_get_bool("persist.vendor.audio.ll_playback_bargein",
8073 false))
8074 needs_event = true;
8075 break;
Quinn Malef15123f2017-04-27 18:58:05 -07008076
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308077 /* concurrent capture usecases which needs event */
8078 case USECASE_AUDIO_RECORD:
8079 case USECASE_AUDIO_RECORD_LOW_LATENCY:
8080 case USECASE_AUDIO_RECORD_COMPRESS:
8081 case USECASE_AUDIO_RECORD_MMAP:
8082 case USECASE_AUDIO_RECORD_HIFI:
8083 case USECASE_VOICE_CALL:
8084 case USECASE_VOICE2_CALL:
8085 case USECASE_VOLTE_CALL:
8086 case USECASE_QCHAT_CALL:
8087 case USECASE_VOWLAN_CALL:
8088 case USECASE_VOICEMMODE1_CALL:
8089 case USECASE_VOICEMMODE2_CALL:
8090 case USECASE_COMPRESS_VOIP_CALL:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308091 case USECASE_INCALL_REC_UPLINK:
8092 case USECASE_INCALL_REC_DOWNLINK:
8093 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
8094 case USECASE_INCALL_REC_UPLINK_COMPRESS:
8095 case USECASE_INCALL_REC_DOWNLINK_COMPRESS:
8096 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
8097 case USECASE_INCALL_MUSIC_UPLINK:
8098 case USECASE_INCALL_MUSIC_UPLINK2:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308099 case USECASE_AUDIO_RECORD_VOIP:
8100 needs_event = true;
8101 break;
Quinn Malef15123f2017-04-27 18:58:05 -07008102 default:
8103 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
8104 }
8105 return needs_event;
Kiran Kandide144c82013-11-20 15:58:32 -08008106}
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008107
8108/* Read offload buffer size from a property.
8109 * If value is not power of 2 round it to
8110 * power of 2.
8111 */
8112uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
8113{
8114 char value[PROPERTY_VALUE_MAX] = {0};
8115 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Deeraj Soman65358ab2019-02-07 15:40:49 +05308116 uint32_t new_fragment_size = 0;
8117 int32_t duration_ms = 0;
8118 int channel_count = 0;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07008119 if((property_get("vendor.audio.offload.buffer.size.kb", value, "")) &&
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008120 atoi(value)) {
8121 fragment_size = atoi(value) * 1024;
8122 }
8123
vivek mehta80a44292015-08-10 12:58:10 -07008124 /* Use incoming offload buffer size if default buffer size is less */
8125 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
8126 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
8127 fragment_size,
8128 info->offload_buffer_size);
8129 fragment_size = info->offload_buffer_size;
8130 }
8131
Deeraj Soman65358ab2019-02-07 15:40:49 +05308132 /* Use client specified buffer size if mentioned */
Dhananjay Kumar2483ada2019-07-24 14:28:25 +05308133 if ((info != NULL) &&
8134 (info->duration_us >= MIN_OFFLOAD_BUFFER_DURATION_MS) &&
8135 (info->duration_us <= MAX_OFFLOAD_BUFFER_DURATION_MS)) {
Deeraj Soman65358ab2019-02-07 15:40:49 +05308136 duration_ms = info->duration_us / 1000;
8137 channel_count = audio_channel_count_from_in_mask(info->channel_mask);
8138
8139 new_fragment_size = (duration_ms * info->sample_rate * channel_count * audio_bytes_per_sample(info->format)) / 1000;
8140 ALOGI("%s:: Overwriting offload buffer size with client requested size old:%d new:%d", __func__, fragment_size, new_fragment_size);
8141
8142 fragment_size = new_fragment_size;
8143 }
8144
Ramjee Singh21ffaa82017-07-28 17:47:01 +05308145 if (info != NULL) {
8146 if (info->is_streaming && info->has_video) {
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05308147 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
8148 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
8149 __func__, fragment_size);
8150 } else if (info->format == AUDIO_FORMAT_FLAC) {
8151 fragment_size = FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8152 ALOGV("FLAC fragment size %d", fragment_size);
8153 } else if (info->format == AUDIO_FORMAT_DSD) {
8154 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07008155 if((property_get("vendor.audio.native.dsd.buffer.size.kb", value, "")) &&
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05308156 atoi(value))
8157 fragment_size = atoi(value) * 1024;
8158 ALOGV("DSD fragment size %d", fragment_size);
8159 }
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008160 }
8161
8162 fragment_size = ALIGN( fragment_size, 1024);
8163
8164 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
8165 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8166 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
8167 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8168 ALOGV("%s: fragment_size %d", __func__, fragment_size);
8169 return fragment_size;
8170}
8171
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308172/*
Ashish Jainb26edfb2016-08-25 00:10:11 +05308173 * return backend_idx on which voice call is active
8174 */
8175static int platform_get_voice_call_backend(struct audio_device* adev)
8176{
8177 struct audio_usecase *uc = NULL;
8178 struct listnode *node;
8179 snd_device_t out_snd_device = SND_DEVICE_NONE;
8180
8181 int backend_idx = -1;
8182
8183 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
8184 list_for_each(node, &adev->usecase_list) {
8185 uc = node_to_item(node, struct audio_usecase, list);
kunleiz83c0b4f2019-02-28 16:53:25 +08008186 if (uc && uc->stream.out &&
8187 (uc->type == VOICE_CALL ||
8188 uc->type == VOIP_CALL ||
8189 uc->id == USECASE_AUDIO_PLAYBACK_VOIP)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05308190 out_snd_device = platform_get_output_snd_device(adev->platform, uc->stream.out);
8191 backend_idx = platform_get_backend_index(out_snd_device);
8192 break;
8193 }
8194 }
8195 }
8196 return backend_idx;
8197}
8198
8199/*
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308200 * configures afe with bit width and Sample Rate
8201 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308202static int platform_set_codec_backend_cfg(struct audio_device* adev,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308203 snd_device_t snd_device, struct audio_backend_cfg backend_cfg)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008204{
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308205 int ret = -EINVAL;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008206 int backend_idx = platform_get_backend_index(snd_device);
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008207 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308208 unsigned int bit_width = backend_cfg.bit_width;
8209 unsigned int sample_rate = backend_cfg.sample_rate;
8210 unsigned int channels = backend_cfg.channels;
8211 audio_format_t format = backend_cfg.format;
8212 bool passthrough_enabled = backend_cfg.passthrough_enabled;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308213 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
8214
8215 /* Override the config params if client has already set them */
8216 adev_device_cfg_ptr += backend_idx;
8217 if (adev_device_cfg_ptr->use_client_dev_cfg) {
8218 ALOGV("%s::: Updating with the config set by client "
8219 "bitwidth %d, samplerate %d, channels %d format %d",
8220 __func__, adev_device_cfg_ptr->dev_cfg_params.bit_width,
8221 adev_device_cfg_ptr->dev_cfg_params.sample_rate,
8222 adev_device_cfg_ptr->dev_cfg_params.channels,
8223 adev_device_cfg_ptr->dev_cfg_params.format);
8224
8225 bit_width = adev_device_cfg_ptr->dev_cfg_params.bit_width;
8226 sample_rate = adev_device_cfg_ptr->dev_cfg_params.sample_rate;
8227 channels = adev_device_cfg_ptr->dev_cfg_params.channels;
8228 format = adev_device_cfg_ptr->dev_cfg_params.format;
8229 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308230
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308231 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
Kuirong Wang0b947f72016-09-29 11:03:09 -07008232 ", backend_idx %d device (%s)", __func__, bit_width,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308233 sample_rate, channels, format, backend_idx,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308234 platform_get_snd_device_name(snd_device));
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008235
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05308236 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
8237 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008238
Kuirong Wang0b947f72016-09-29 11:03:09 -07008239 struct mixer_ctl *ctl = NULL;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008240 ctl = mixer_get_ctl_by_name(adev->mixer,
8241 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008242 if (!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308243 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8244 __func__,
8245 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008246 return -EINVAL;
8247 }
8248
8249 if (bit_width == 24) {
Ashish Jain5106d362016-05-11 19:23:33 +05308250 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
Kuirong Wang0b947f72016-09-29 11:03:09 -07008251 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
Ashish Jain5106d362016-05-11 19:23:33 +05308252 else
Kuirong Wang0b947f72016-09-29 11:03:09 -07008253 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008254 } else if (bit_width == 32) {
Ashish Jain058165c2016-09-28 23:18:48 +05308255 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07008256 } else {
Kuirong Wang0b947f72016-09-29 11:03:09 -07008257 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07008258 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07008259 if ( ret < 0) {
8260 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
8261 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
8262 } else {
8263 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
8264 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
8265 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
8266 }
8267 /* set the ret as 0 and not pass back to upper layer */
8268 ret = 0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008269 }
8270
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308271 if ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
8272 (passthrough_enabled || (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07008273 char *rate_str = NULL;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008274 struct mixer_ctl *ctl = NULL;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008275
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308276 if (backend_idx == USB_AUDIO_RX_BACKEND ||
8277 backend_idx == USB_AUDIO_TX_BACKEND) {
8278 switch (sample_rate) {
8279 case 32000:
8280 rate_str = "KHZ_32";
8281 break;
8282 case 8000:
8283 rate_str = "KHZ_8";
8284 break;
8285 case 11025:
Sharad Sangle4cd17e32018-07-16 14:37:42 +05308286 rate_str = "KHZ_11P025";
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308287 break;
8288 case 16000:
8289 rate_str = "KHZ_16";
8290 break;
8291 case 22050:
8292 rate_str = "KHZ_22P05";
8293 break;
8294 }
8295 }
8296
8297 if (rate_str == NULL) {
8298 switch (sample_rate) {
8299 case 32000:
Weiyin Jiang03b2cb22019-09-04 16:45:45 +08008300 if (passthrough_enabled || (backend_idx == SPDIF_TX_BACKEND) ||
8301 (backend_idx == HDMI_TX_BACKEND) ||
8302 (backend_idx == HDMI_ARC_TX_BACKEND) ||
8303 (backend_idx == DISP_PORT_RX_BACKEND)) {
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308304 rate_str = "KHZ_32";
8305 break;
8306 }
8307 case 48000:
8308 rate_str = "KHZ_48";
8309 break;
8310 case 44100:
8311 rate_str = "KHZ_44P1";
8312 break;
8313 case 64000:
8314 case 96000:
8315 rate_str = "KHZ_96";
8316 break;
8317 case 88200:
8318 rate_str = "KHZ_88P2";
8319 break;
8320 case 176400:
8321 rate_str = "KHZ_176P4";
8322 break;
8323 case 192000:
8324 rate_str = "KHZ_192";
8325 break;
8326 case 352800:
8327 rate_str = "KHZ_352P8";
8328 break;
8329 case 384000:
8330 rate_str = "KHZ_384";
8331 break;
8332 case 144000:
8333 if (passthrough_enabled) {
8334 rate_str = "KHZ_144";
8335 break;
8336 }
8337 default:
8338 rate_str = "KHZ_48";
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05308339 break;
8340 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008341 }
8342
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008343 ctl = mixer_get_ctl_by_name(adev->mixer,
8344 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008345 if(!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308346 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8347 __func__,
8348 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008349 return -EINVAL;
8350 }
8351
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308352 ALOGD("%s:becf: afe: %s set to %s", __func__,
8353 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008354 mixer_ctl_set_enum_by_string(ctl, rate_str);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008355 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308356 ret = 0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008357 }
Ashish Jainb26edfb2016-08-25 00:10:11 +05308358 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308359 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
Kuirong Wang0b947f72016-09-29 11:03:09 -07008360 struct mixer_ctl *ctl = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308361 char *channel_cnt_str = NULL;
8362
8363 switch (channels) {
8364 case 8:
8365 channel_cnt_str = "Eight"; break;
8366 case 7:
8367 channel_cnt_str = "Seven"; break;
8368 case 6:
8369 channel_cnt_str = "Six"; break;
8370 case 5:
8371 channel_cnt_str = "Five"; break;
8372 case 4:
8373 channel_cnt_str = "Four"; break;
8374 case 3:
8375 channel_cnt_str = "Three"; break;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008376 case 1:
8377 channel_cnt_str = "One"; break;
8378 case 2:
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308379 default:
8380 channel_cnt_str = "Two"; break;
8381 }
8382
8383 ctl = mixer_get_ctl_by_name(adev->mixer,
8384 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
8385 if (!ctl) {
8386 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8387 __func__,
8388 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
8389 return -EINVAL;
8390 }
8391 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
8392 my_data->current_backend_cfg[backend_idx].channels = channels;
Ashish Jainb26edfb2016-08-25 00:10:11 +05308393
Weiyin Jiangff72f812018-04-13 15:02:33 +08008394 if ((backend_idx == HDMI_RX_BACKEND) ||
8395 (backend_idx == DISP_PORT_RX_BACKEND))
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308396 platform_set_edid_channels_configuration(adev->platform, channels, backend_idx, snd_device);
Ashish Jainb26edfb2016-08-25 00:10:11 +05308397
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308398 ALOGD("%s:becf: afe: %s set to %s ", __func__,
Kuirong Wang0b947f72016-09-29 11:03:09 -07008399 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
8400 channel_cnt_str);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308401 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308402 }
8403
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308404 bool set_ext_disp_format = false, set_mi2s_tx_data_format = false;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008405 char *ext_disp_format = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308406
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008407 if (backend_idx == HDMI_RX_BACKEND) {
8408 ext_disp_format = "HDMI RX Format";
8409 set_ext_disp_format = true;
8410 } else if (backend_idx == DISP_PORT_RX_BACKEND) {
Garmond Leungade0f6d2017-02-03 15:56:10 -08008411 ext_disp_format = "Display Port RX Format";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008412 set_ext_disp_format = true;
Ralf Herzafb164f2018-07-03 07:08:07 +02008413 } else if (backend_idx == SPDIF_TX_BACKEND) {
8414 ext_disp_format = "PRI SPDIF TX Format";
8415 set_mi2s_tx_data_format = true;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308416 } else if (backend_idx == HDMI_TX_BACKEND) {
Ralf Herzafb164f2018-07-03 07:08:07 +02008417 if (!strncmp(platform_get_snd_device_backend_interface(snd_device),
8418 "SEC_MI2S_TX", sizeof("SEC_MI2S_TX")))
8419 ext_disp_format = "SEC MI2S TX Format";
8420 else
8421 ext_disp_format = "QUAT MI2S TX Format";
8422 set_mi2s_tx_data_format = true;
8423 } else if (backend_idx == HDMI_ARC_TX_BACKEND) {
8424 ext_disp_format = "SEC SPDIF TX Format";
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308425 set_mi2s_tx_data_format = true;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008426 } else {
8427 ALOGV("%s: Format doesnt have to be set", __func__);
8428 }
8429
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308430 /* Set data format only if there is a change from PCM to compressed
8431 and vice versa */
8432 if (set_mi2s_tx_data_format && (format ^ my_data->current_backend_cfg[backend_idx].format)) {
8433 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
8434 if (!ctl) {
8435 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8436 __func__, ext_disp_format);
8437 return -EINVAL;
8438 }
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07008439 if ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) {
Ralf Herzafb164f2018-07-03 07:08:07 +02008440 ALOGE("%s:Set %s to LPCM", __func__, ext_disp_format);
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308441 mixer_ctl_set_enum_by_string(ctl, "LPCM");
8442 } else {
Ralf Herzafb164f2018-07-03 07:08:07 +02008443 ALOGE("%s:Set %s to Compr", __func__, ext_disp_format);
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308444 mixer_ctl_set_enum_by_string(ctl, "Compr");
8445 }
8446 my_data->current_backend_cfg[backend_idx].format = format;
8447 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008448 if (set_ext_disp_format) {
8449 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308450 if (!ctl) {
8451 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008452 __func__, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308453 return -EINVAL;
8454 }
8455
8456 if (passthrough_enabled) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008457 ALOGD("%s:Ext display compress format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308458 mixer_ctl_set_enum_by_string(ctl, "Compr");
8459 } else {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008460 ALOGD("%s: Ext display PCM format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308461 mixer_ctl_set_enum_by_string(ctl, "LPCM");
8462 }
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308463 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308464 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008465 return ret;
8466}
8467
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308468/*
Satish Babu Patakokila5933e972017-08-24 12:22:08 +05308469 * Get the backend configuration for current snd device
8470 */
8471int platform_get_codec_backend_cfg(struct audio_device* adev,
8472 snd_device_t snd_device,
8473 struct audio_backend_cfg *backend_cfg)
8474{
8475 int backend_idx = platform_get_backend_index(snd_device);
8476 struct platform_data *my_data = (struct platform_data *)adev->platform;
8477
8478 backend_cfg->bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
8479 backend_cfg->sample_rate =
8480 my_data->current_backend_cfg[backend_idx].sample_rate;
8481 backend_cfg->channels =
8482 my_data->current_backend_cfg[backend_idx].channels;
8483 backend_cfg->format =
8484 my_data->current_backend_cfg[backend_idx].format;
8485
8486 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
8487 ", backend_idx %d device (%s)", __func__, backend_cfg->bit_width,
8488 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format,
8489 backend_idx, platform_get_snd_device_name(snd_device));
8490
8491 return 0;
8492}
8493
8494/*
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308495 *Validate the selected bit_width, sample_rate and channels using the edid
8496 *of the connected sink device.
8497 */
8498static void platform_check_hdmi_backend_cfg(struct audio_device* adev,
8499 struct audio_usecase* usecase,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008500 int backend_idx,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308501 struct audio_backend_cfg *hdmi_backend_cfg)
8502{
8503 unsigned int bit_width;
8504 unsigned int sample_rate;
Manish Dewangan37864bc2017-06-09 12:28:37 +05308505 int channels, max_supported_channels = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308506 struct platform_data *my_data = (struct platform_data *)adev->platform;
8507 edid_audio_info *edid_info = (edid_audio_info *)my_data->edid_info;
8508 bool passthrough_enabled = false;
8509
8510 bit_width = hdmi_backend_cfg->bit_width;
8511 sample_rate = hdmi_backend_cfg->sample_rate;
8512 channels = hdmi_backend_cfg->channels;
8513
8514
8515 ALOGI("%s:becf: HDMI: bitwidth %d, samplerate %d, channels %d"
8516 ", usecase = %d", __func__, bit_width,
8517 sample_rate, channels, usecase->id);
8518
8519 if (audio_extn_passthru_is_enabled() && audio_extn_passthru_is_active()
8520 && (usecase->stream.out->compr_config.codec->compr_passthr != 0)) {
8521 passthrough_enabled = true;
8522 ALOGI("passthrough is enabled for this stream");
8523 }
8524
8525 // For voice calls use default configuration i.e. 16b/48K, only applicable to
8526 // default backend
8527 if (!passthrough_enabled) {
8528
8529 max_supported_channels = platform_edid_get_max_channels(my_data);
8530
8531 //Check EDID info for supported samplerate
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008532 if (!audio_extn_edid_is_supported_sr(edid_info,sample_rate)) {
Garmond Leung2f78a672016-11-07 16:27:40 -08008533 //check to see if current BE sample rate is supported by EDID
8534 //else assign the highest sample rate supported by EDID
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008535 if (audio_extn_edid_is_supported_sr(edid_info,my_data->current_backend_cfg[backend_idx].sample_rate))
Garmond Leung2f78a672016-11-07 16:27:40 -08008536 sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
8537 else
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008538 sample_rate = audio_extn_edid_get_highest_supported_sr(edid_info);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308539 }
8540
8541 //Check EDID info for supported bit width
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008542 if (!audio_extn_edid_is_supported_bps(edid_info,bit_width)) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308543 //reset to current sample rate
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008544 bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308545 }
8546
8547 if (channels > max_supported_channels)
8548 channels = max_supported_channels;
8549
8550 } else {
Manish Dewangan37864bc2017-06-09 12:28:37 +05308551 channels = audio_extn_passthru_get_channel_count(usecase->stream.out);
8552 if (channels <= 0) {
8553 ALOGE("%s: becf: afe: HDMI backend using defalut channel %u",
8554 __func__, DEFAULT_HDMI_OUT_CHANNELS);
Ben Romberger1aaaf862017-04-06 17:49:46 -07008555 channels = DEFAULT_HDMI_OUT_CHANNELS;
Manish Dewangan37864bc2017-06-09 12:28:37 +05308556 }
Harsh Bansal026d97f2017-08-17 17:44:49 +05308557 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
Ben Romberger1aaaf862017-04-06 17:49:46 -07008558 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) ||
Harsh Bansal026d97f2017-08-17 17:44:49 +05308559 (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD))
8560 && (usecase->stream.out->compr_config.codec->compr_passthr == PASSTHROUGH)) {
Naresh Tanniru3a406772017-05-10 13:09:05 -07008561 sample_rate = sample_rate * 4;
8562 if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE)
8563 sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE;
8564 }
Ben Romberger1aaaf862017-04-06 17:49:46 -07008565
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308566 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8567 /* We force route so that the BE format can be set to Compr */
8568 }
8569
8570 ALOGI("%s:becf: afe: HDMI backend: passthrough %d updated bit width: %d and sample rate: %d"
8571 "channels %d", __func__, passthrough_enabled , bit_width,
8572 sample_rate, channels);
8573
8574 hdmi_backend_cfg->bit_width = bit_width;
8575 hdmi_backend_cfg->sample_rate = sample_rate;
8576 hdmi_backend_cfg->channels = channels;
8577 hdmi_backend_cfg->passthrough_enabled = passthrough_enabled;
8578}
8579
8580/*
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308581 * goes through all the current usecases and picks the highest
8582 * bitwidth & samplerate
8583 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308584static bool platform_check_codec_backend_cfg(struct audio_device* adev,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008585 struct audio_usecase* usecase,
8586 snd_device_t snd_device,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308587 struct audio_backend_cfg *backend_cfg)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008588{
8589 bool backend_change = false;
8590 struct listnode *node;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008591 unsigned int bit_width;
8592 unsigned int sample_rate;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308593 unsigned int channels;
Garmond Leung5fd0b552018-04-17 11:56:12 -07008594 unsigned long service_interval = 0;
8595 bool service_interval_update = false;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308596 bool passthrough_enabled = false;
Ashish Jain8c930292017-03-13 16:33:12 +05308597 bool voice_call_active = false;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008598 int backend_idx = DEFAULT_CODEC_BACKEND;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008599 struct platform_data *my_data = (struct platform_data *)adev->platform;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308600 int na_mode = platform_get_native_support();
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308601 bool channels_updated = false;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308602 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008603
Ashish Jainc597d102016-12-12 10:31:34 +05308604 /*BT devices backend is not configured from HAL hence skip*/
8605 if (snd_device == SND_DEVICE_OUT_BT_A2DP ||
8606 snd_device == SND_DEVICE_OUT_BT_SCO ||
Sachin Mohan Gadag2e4dcb12017-05-12 13:05:08 +05308607 snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
Zhou Song12c29502019-03-16 10:37:18 +08008608 snd_device == SND_DEVICE_OUT_BT_SCO_SWB ||
Florian Pfister1a84f312018-07-19 14:38:18 +02008609 snd_device == SND_DEVICE_IN_BT_A2DP ||
Sachin Mohan Gadag2e4dcb12017-05-12 13:05:08 +05308610 snd_device == SND_DEVICE_OUT_AFE_PROXY) {
Ashish Jainc597d102016-12-12 10:31:34 +05308611 backend_change = false;
8612 return backend_change;
8613 }
8614
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008615 backend_idx = platform_get_backend_index(snd_device);
8616
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308617 bit_width = backend_cfg->bit_width;
8618 sample_rate = backend_cfg->sample_rate;
8619 channels = backend_cfg->channels;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008620
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308621 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308622 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308623 sample_rate, channels, backend_idx, usecase->id,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308624 platform_get_snd_device_name(snd_device));
Mingming Yin3ee55c62014-08-04 14:23:35 -07008625
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07008626 // For voice calls use default configuration i.e. 16b/48K, only applicable to
8627 // default backend
Mingming Yin3ee55c62014-08-04 14:23:35 -07008628 // force routing is not required here, caller will do it anyway
Ashish Jainb26edfb2016-08-25 00:10:11 +05308629 if (backend_idx == platform_get_voice_call_backend(adev)) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308630 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
8631 __func__);
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008632 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8633 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jainb26edfb2016-08-25 00:10:11 +05308634 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Ashish Jain8c930292017-03-13 16:33:12 +05308635 voice_call_active = true;
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008636 } else {
8637 /*
8638 * The backend should be configured at highest bit width and/or
8639 * sample rate amongst all playback usecases.
8640 * If the selected sample rate and/or bit width differ with
8641 * current backend sample rate and/or bit width, then, we set the
8642 * backend re-configuration flag.
8643 *
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308644 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008645 */
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308646 int i =0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008647 list_for_each(node, &adev->usecase_list) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308648 struct audio_usecase *uc;
8649 uc = node_to_item(node, struct audio_usecase, list);
8650 struct stream_out *out = (struct stream_out*) uc->stream.out;
8651 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
Preetam Singh Ranawataa37d3f2016-08-23 12:25:23 +05308652 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008653
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308654 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308655 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308656 uc->id, out->sample_rate,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308657 out->bit_width, out_channels,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308658 platform_get_snd_device_name(uc->out_snd_device));
8659
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308660 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
Amit Shekhar278e3362014-09-08 14:08:19 -07008661 if (bit_width < out->bit_width)
8662 bit_width = out->bit_width;
8663 if (sample_rate < out->sample_rate)
8664 sample_rate = out->sample_rate;
Revathi Uddaraju869ae492018-02-09 16:27:35 +05308665 /*
8666 * TODO: Add Support for Backend configuration for devices which support
8667 * sample rate less than 44.1
8668 */
8669 if (sample_rate < OUTPUT_SAMPLING_RATE_44100)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008670 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308671 if (channels < out_channels)
8672 channels = out_channels;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008673 }
Ramlal Karra10d22b92019-08-08 19:02:35 +05308674 if ((snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) &&
8675 (usecase->id==USECASE_AUDIO_PLAYBACK_LOW_LATENCY ||
8676 usecase->id == USECASE_AUDIO_PLAYBACK_ULL)) {
8677 sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
8678 bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
8679 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008680 }
8681 }
8682 }
8683
Ashish Jainb26edfb2016-08-25 00:10:11 +05308684 /* Native playback is preferred for Headphone/HS device over 192Khz */
Ashish Jain8c930292017-03-13 16:33:12 +05308685 if (!voice_call_active && codec_device_supports_native_playback(usecase->devices)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05308686 if (audio_is_true_native_stream_active(adev)) {
8687 if (check_hdset_combo_device(snd_device)) {
8688 /*
8689 * In true native mode Tasha has a limitation that one port at 44.1 khz
8690 * cannot drive both spkr and hdset, to simiplify the solution lets
8691 * move the AFE to 48khzwhen a ring tone selects combo device.
8692 * or if NATIVE playback is not enabled.
8693 */
8694 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8695 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jain8c930292017-03-13 16:33:12 +05308696 ALOGD("%s:becf: afe: port to run at 48k if combo device or in voice call"
8697 , __func__);
Ashish Jainb26edfb2016-08-25 00:10:11 +05308698 } else {
8699 /*
8700 * in single BE mode, if native audio playback
8701 * is active then it will take priority
8702 */
8703 sample_rate = OUTPUT_SAMPLING_RATE_44100;
8704 ALOGD("%s:becf: afe: true napb active set rate to 44.1 khz",
8705 __func__);
8706 }
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05308707 } else if (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP) {
8708 struct listnode *node;
8709 list_for_each(node, &adev->usecase_list) {
8710 struct audio_usecase *uc;
8711 uc = node_to_item(node, struct audio_usecase, list);
8712 struct stream_out *curr_out =
8713 (struct stream_out*) uc->stream.out;
8714
8715 /*if native audio playback
8716 * is active then it will take priority
8717 */
8718 if (curr_out && PCM_PLAYBACK == uc->type) {
8719 if (is_offload_usecase(uc->id) &&
8720 (curr_out->sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0)) {
8721 ALOGD("%s:napb:native stream detected %d sampling rate", __func__, curr_out->sample_rate);
8722 sample_rate = curr_out->sample_rate;
8723 }
8724 }
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +05308725
8726 /* WCD9380 support SR upto 192Khz only, hence reset
8727 * SR > 192Khz to 192Khz.
8728 */
8729 if (strstr(my_data->codec_variant, "WCD9380")) {
8730 switch (sample_rate) {
8731 case 352800:
8732 case 384000:
8733 sample_rate = 192000;
8734 ALOGD("%s:Reset Sampling rate to %d", __func__, sample_rate);
8735 break;
8736 default:
8737 break;
8738 }
8739 }
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05308740 }
8741 } else if (na_mode != NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC) {
Ashish Jain7f25be32016-10-25 21:44:16 +05308742 /*
8743 * Map native sampling rates to upper limit range
8744 * if multiple of native sampling rates are not supported.
8745 * This check also indicates that this is not tavil codec
8746 * And 32bit/384kHz is only supported on tavil
8747 * Hence reset 32b/384kHz to 24b/192kHz.
8748 */
8749 switch (sample_rate) {
8750 case 44100:
8751 sample_rate = 48000;
8752 break;
8753 case 88200:
8754 sample_rate = 96000;
8755 break;
8756 case 176400:
8757 case 352800:
8758 case 384000:
8759 sample_rate = 192000;
8760 break;
8761 }
8762 if (bit_width > 24)
8763 bit_width = 24;
8764
8765 ALOGD("%s:becf: afe: napb not active - set non fractional rate",
Ashish Jainb26edfb2016-08-25 00:10:11 +05308766 __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008767 }
Mingshu Pange3d362f2019-12-13 18:00:00 +08008768 /*
8769 * reset sample rate to 48khz if sample rate less than 44.1khz, or device backend does not
8770 * support 44.1 khz and the multiple of 44.1khz
8771 */
8772 if ((sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0 &&
kunleiz72e744c2018-09-27 18:09:16 +08008773 backend_idx != HEADPHONE_44_1_BACKEND &&
8774 backend_idx != HEADPHONE_BACKEND &&
8775 backend_idx != USB_AUDIO_RX_BACKEND) ||
8776 sample_rate < OUTPUT_SAMPLING_RATE_44100) {
8777 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8778 ALOGD("%s:becf: afe: set sample rate to default Sample Rate(48k)",__func__);
kunleiz6ba62d12018-06-20 13:55:46 +08008779 }
Ashish Jain6fced6e2017-01-09 14:13:22 +05308780 }
8781
Ramlal Karra10d22b92019-08-08 19:02:35 +05308782 if (backend_idx != platform_get_voice_call_backend(adev)
8783 && usecase->type == PCM_PLAYBACK) {
8784 struct stream_out *out = (struct stream_out*) usecase->stream.out;
8785 if(audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
8786 my_data->codec_variant, channels, 0)) {
8787 switch (sample_rate) {
8788 case 48000:
8789 audio_extn_enable_hifi_filter(adev, true);
8790 if (audio_is_true_native_stream_active(adev))
8791 sample_rate = 352800;
8792 else
8793 sample_rate = 384000;
8794 bit_width = 32;
8795 break;
8796 case 44100:
8797 audio_extn_enable_hifi_filter(adev, true);
8798 sample_rate = 352800;
8799 bit_width = 32;
8800 break;
8801 default:
8802 audio_extn_enable_hifi_filter(adev, false);
8803 }
8804 }
8805 if (snd_device != SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)
8806 audio_extn_enable_hifi_filter(adev, false);
8807 ALOGD("%s:becf: updated afe: bitwidth %d, samplerate %d channels %d,"
8808 "backend_idx %d usecase = %d device (%s)", __func__, bit_width,
8809 sample_rate, channels, backend_idx, usecase->id,
8810 platform_get_snd_device_name(snd_device));
8811 }
8812
Ashish Jain6fced6e2017-01-09 14:13:22 +05308813 /*
kunleiz0a99fcf2018-06-14 16:41:21 +08008814 * Handset and speaker may have diffrent backend. Check if the device is speaker or handset,
8815 * and these devices are restricited to 48kHz.
Ashish Jain6fced6e2017-01-09 14:13:22 +05308816 */
kunleiz5c3fb9a2019-02-20 17:18:19 +08008817 if (!codec_device_supports_native_playback(usecase->devices) &&
8818 (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device) ||
8819 platform_check_backends_match(SND_DEVICE_OUT_HANDSET, snd_device))) {
Ramu Gottipati074fa4d2018-09-11 20:05:51 +05308820 int bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
8821 if ((-ENOSYS != bw) && (bit_width > (uint32_t)bw)) {
8822 bit_width = (uint32_t)bw;
Ashish Jain058165c2016-09-28 23:18:48 +05308823 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
Ramu Gottipati074fa4d2018-09-11 20:05:51 +05308824 " value for this platform)", __func__, bit_width);
8825 } else if (-ENOSYS == bw) {
8826 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8827 ALOGD("%s:becf: afe: reset to default bitwidth %d", __func__, bit_width);
Ashish Jain058165c2016-09-28 23:18:48 +05308828 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02008829 /*
8830 * In case of CSRA speaker out, all sample rates are supported, so
8831 * check platform here
8832 */
8833 if (platform_spkr_use_default_sample_rate(adev->platform)) {
8834 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8835 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308836 "default Sample Rate(48k)", __func__);
Dieter Luecking5d57def2018-09-07 14:23:37 +02008837 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308838 }
8839
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008840 if (backend_idx == USB_AUDIO_RX_BACKEND) {
Kuirong Wange9894162016-08-26 15:16:39 -07008841 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008842 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
8843 __func__, bit_width, sample_rate, channels);
Garmond Leung5fd0b552018-04-17 11:56:12 -07008844
8845 if (audio_extn_usb_get_service_interval(true,
8846 &service_interval) == 0) {
8847 /* overwrite with best altset for this service interval */
8848 int ret =
8849 audio_extn_usb_altset_for_service_interval(true /*playback*/,
8850 service_interval,
8851 &bit_width,
8852 &sample_rate,
8853 &channels);
8854 ALOGD("%s: Override USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)SI(%lu)",
8855 __func__, bit_width, sample_rate, channels, service_interval);
8856 if (ret < 0) {
8857 ALOGW("Failed to find altset for service interval %lu, skip reconfig",
8858 service_interval);
8859 return false;
8860 }
8861 service_interval_update = audio_extn_usb_is_reconfig_req();
8862 audio_extn_usb_set_reconfig(false);
8863 }
8864
Ashish Jainb26edfb2016-08-25 00:10:11 +05308865 if (channels != my_data->current_backend_cfg[backend_idx].channels)
8866 channels_updated = true;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008867 }
8868
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008869 if (backend_idx == HDMI_RX_BACKEND || backend_idx == DISP_PORT_RX_BACKEND) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308870 struct audio_backend_cfg hdmi_backend_cfg;
8871 hdmi_backend_cfg.bit_width = bit_width;
8872 hdmi_backend_cfg.sample_rate = sample_rate;
8873 hdmi_backend_cfg.channels = channels;
8874 hdmi_backend_cfg.passthrough_enabled = false;
8875
Ashish Jain058165c2016-09-28 23:18:48 +05308876 /*
8877 * HDMI does not support 384Khz/32bit playback hence configure BE to 24b/192Khz
8878 * TODO: Instead have the validation against edid return the next best match
8879 */
8880 if (bit_width > 24)
8881 hdmi_backend_cfg.bit_width = 24;
8882 if (sample_rate > 192000)
8883 hdmi_backend_cfg.sample_rate = 192000;
8884
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008885 platform_check_hdmi_backend_cfg(adev, usecase, backend_idx, &hdmi_backend_cfg);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308886
8887 bit_width = hdmi_backend_cfg.bit_width;
8888 sample_rate = hdmi_backend_cfg.sample_rate;
8889 channels = hdmi_backend_cfg.channels;
8890 passthrough_enabled = hdmi_backend_cfg.passthrough_enabled;
8891
8892 if (channels != my_data->current_backend_cfg[backend_idx].channels)
8893 channels_updated = true;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308894
8895 platform_set_edid_channels_configuration(adev->platform, channels, backend_idx, snd_device);
Mingming Yinddd610b2016-01-20 17:09:32 -08008896 }
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308897
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308898 ALOGI("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
8899 __func__, backend_idx , bit_width, sample_rate);
Mingming Yinddd610b2016-01-20 17:09:32 -08008900
Mingming Yin3ee55c62014-08-04 14:23:35 -07008901 // Force routing if the expected bitwdith or samplerate
8902 // is not same as current backend comfiguration
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008903 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308904 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
Garmond Leung5fd0b552018-04-17 11:56:12 -07008905 passthrough_enabled || channels_updated || service_interval_update ) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308906 backend_cfg->bit_width = bit_width;
8907 backend_cfg->sample_rate = sample_rate;
8908 backend_cfg->channels = channels;
8909 backend_cfg->passthrough_enabled = passthrough_enabled;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008910 backend_change = true;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308911 ALOGI("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
8912 "new sample rate: %d new channels: %d",
8913 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008914 }
8915
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308916 // Force routing if the client sends config params for this backend
8917 adev_device_cfg_ptr += backend_idx;
8918 if (adev_device_cfg_ptr->use_client_dev_cfg) {
8919 ALOGV("%s: Codec backend needs to be updated as Client provided "
8920 "config params", __func__);
8921 backend_change = true;
8922 }
8923
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308924 if (snd_device == SND_DEVICE_OUT_HEADPHONES || snd_device ==
Ramlal Karra10d22b92019-08-08 19:02:35 +05308925 SND_DEVICE_OUT_HEADPHONES_44_1 || snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) {
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05308926 if (my_data->is_cls_ab_only_supported) {
8927 ALOGI("%s: apply CLS AB HPH power mode\n", __func__);
8928 audio_route_apply_and_update_path(adev->audio_route, "hph-class-ab-mode");
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308929 } else {
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05308930 if (sample_rate > 48000 ||
8931 (bit_width >= 24 && (sample_rate == 48000 || sample_rate == 44100))) {
8932 ALOGI("%s: apply HPH HQ mode\n", __func__);
8933 audio_route_apply_and_update_path(adev->audio_route, "hph-highquality-mode");
8934 } else {
8935 ALOGI("%s: apply HPH LP mode\n", __func__);
8936 audio_route_apply_and_update_path(adev->audio_route, "hph-lowpower-mode");
8937 }
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308938 }
8939 }
8940
Mingming Yin3ee55c62014-08-04 14:23:35 -07008941 return backend_change;
8942}
8943
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008944bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
8945 struct audio_usecase *usecase, snd_device_t snd_device)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008946{
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008947 int backend_idx = DEFAULT_CODEC_BACKEND;
Siena Richard7c2db772016-12-21 11:32:34 -08008948 int new_snd_devices[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308949 int i, num_devices = 1;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308950 int device_be_idx = -1;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308951 bool ret = false;
8952 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308953 struct audio_backend_cfg backend_cfg;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008954
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008955 backend_idx = platform_get_backend_index(snd_device);
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308956 device_be_idx = platform_get_snd_device_backend_index(snd_device);
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008957
Surendar Karka93cd25a2018-08-28 14:21:37 +05308958 if (usecase->type == TRANSCODE_LOOPBACK_RX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308959 backend_cfg.bit_width = usecase->stream.inout->out_config.bit_width;
8960 backend_cfg.sample_rate = usecase->stream.inout->out_config.sample_rate;
8961 backend_cfg.format = usecase->stream.inout->out_config.format;
8962 backend_cfg.channels = audio_channel_count_from_out_mask(
8963 usecase->stream.inout->out_config.channel_mask);
8964 } else {
8965 backend_cfg.bit_width = usecase->stream.out->bit_width;
8966 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
8967 backend_cfg.format = usecase->stream.out->format;
Xiaojun Sang841cb5f2018-11-06 19:37:44 +08008968 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308969 }
Xiaojun Sang785b5da2017-08-03 15:52:29 +08008970 if (audio_extn_is_dsp_bit_width_enforce_mode_supported(usecase->stream.out->flags) &&
8971 (adev->dsp_bit_width_enforce_mode > backend_cfg.bit_width))
8972 backend_cfg.bit_width = adev->dsp_bit_width_enforce_mode;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308973
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308974 /*this is populated by check_codec_backend_cfg hence set default value to false*/
8975 backend_cfg.passthrough_enabled = false;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008976
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05308977 /* Set Backend sampling rate to 176.4 for DSD64 and
8978 * 352.8Khz for DSD128.
8979 * Set Bit Width to 16
8980 */
8981 if ((backend_idx == DSD_NATIVE_BACKEND) && (backend_cfg.format == AUDIO_FORMAT_DSD)) {
8982 backend_cfg.bit_width = 16;
8983 if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD64)
8984 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
8985 else if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD128)
8986 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
8987 }
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308988 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
8989 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
8990 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308991 platform_get_snd_device_name(snd_device));
8992
Surendar Karka45850ae2018-07-02 17:45:27 +05308993 if ((my_data->spkr_ch_map != NULL) &&
8994 (platform_get_backend_index(snd_device) == DEFAULT_CODEC_BACKEND))
8995 platform_set_channel_map(my_data, my_data->spkr_ch_map->num_ch,
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308996 my_data->spkr_ch_map->chmap, -1, device_be_idx);
Surendar Karka45850ae2018-07-02 17:45:27 +05308997
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07008998 if (platform_split_snd_device(my_data, snd_device, &num_devices,
8999 new_snd_devices) < 0)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309000 new_snd_devices[0] = snd_device;
9001
9002 for (i = 0; i < num_devices; i++) {
9003 ALOGI("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05309004 if ((platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
9005 &backend_cfg))) {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05309006 ret = platform_set_codec_backend_cfg(adev, new_snd_devices[i],
Ashish Jaind84fd6a2016-07-27 12:33:25 +05309007 backend_cfg);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05309008 if (!ret) {
9009 ret = true;
9010 } else {
9011 ret = false;
9012 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309013 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07009014 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309015 return ret;
Mingming Yin3ee55c62014-08-04 14:23:35 -07009016}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009017
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309018/*
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309019 * goes through all the current usecases and picks the highest
9020 * bitwidth & samplerate
9021 */
Kuirong Wange9894162016-08-26 15:16:39 -07009022static bool platform_check_capture_codec_backend_cfg(struct audio_device* adev,
9023 int backend_idx,
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309024 struct audio_backend_cfg *backend_cfg,
9025 snd_device_t snd_device)
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309026{
9027 bool backend_change = false;
9028 unsigned int bit_width;
9029 unsigned int sample_rate;
Kuirong Wange9894162016-08-26 15:16:39 -07009030 unsigned int channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309031 unsigned int format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309032 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurent637e2d42018-11-15 12:24:31 -08009033 struct stream_in *in = adev_get_active_input(adev);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309034
Kuirong Wange9894162016-08-26 15:16:39 -07009035 bit_width = backend_cfg->bit_width;
9036 sample_rate = backend_cfg->sample_rate;
9037 channels = backend_cfg->channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309038 format = backend_cfg->format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309039
9040 ALOGI("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309041 "sample rate: %d, channels %d format %d",__func__,backend_idx, bit_width,
9042 sample_rate, channels,format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309043
9044 // For voice calls use default configuration i.e. 16b/48K, only applicable to
9045 // default backend
9046 // force routing is not required here, caller will do it anyway
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309047 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION)) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05309048
Kuirong Wang0b947f72016-09-29 11:03:09 -07009049 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309050 "for unprocessed/camera source", __func__);
9051 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
9052 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309053 channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Samyak Jain2ab8c5a2018-11-26 19:57:47 +05309054 } else if (my_data->is_internal_codec && !audio_is_usb_in_device(snd_device)) {
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309055 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
9056 channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Eric Laurent637e2d42018-11-15 12:24:31 -08009057 if (in && in->bit_width == 24)
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309058 bit_width = platform_get_snd_device_bit_width(snd_device);
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309059 } else {
9060 struct listnode *node;
9061 struct audio_usecase *uc = NULL;
9062 unsigned int uc_channels = 0;
9063 struct stream_in *in = NULL;
9064 /* update cfg against other existing capture usecases on same backend */
9065 list_for_each(node, &adev->usecase_list) {
9066 uc = node_to_item(node, struct audio_usecase, list);
Satya Krishna Pindiproli9f566672017-02-28 11:14:01 +05309067 in = (struct stream_in *) uc->stream.in;
9068 if (in != NULL && uc->type == PCM_CAPTURE &&
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309069 backend_idx == platform_get_backend_index(uc->in_snd_device)) {
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309070 uc_channels = audio_channel_count_from_in_mask(in->channel_mask);
9071
9072 ALOGV("%s:txbecf: uc %s, id %d, sr %d, bw %d, ch %d, device %s",
9073 __func__, use_case_table[uc->id], uc->id, in->sample_rate,
9074 in->bit_width, uc_channels,
9075 platform_get_snd_device_name(uc->in_snd_device));
9076
9077 if (sample_rate < in->sample_rate)
9078 sample_rate = in->sample_rate;
9079 if (bit_width < in->bit_width)
9080 bit_width = in->bit_width;
9081 if (channels < uc_channels)
9082 channels = uc_channels;
9083 }
9084 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309085 }
Kuirong Wange9894162016-08-26 15:16:39 -07009086 if (backend_idx == USB_AUDIO_TX_BACKEND) {
9087 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
Kuirong Wang0b947f72016-09-29 11:03:09 -07009088 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
Kuirong Wange9894162016-08-26 15:16:39 -07009089 __func__, bit_width, sample_rate, channels);
9090 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309091
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009092 ALOGI("%s:txbecf: afe: current backend bit_width %d sample_rate %d channels %d, format %x",
9093 __func__,
9094 my_data->current_backend_cfg[backend_idx].bit_width,
9095 my_data->current_backend_cfg[backend_idx].sample_rate,
9096 my_data->current_backend_cfg[backend_idx].channels,
9097 my_data->current_backend_cfg[backend_idx].format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309098 // Force routing if the expected bitwdith or samplerate
9099 // is not same as current backend comfiguration
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009100 // Note that below if block would be entered even if main format is same
9101 // but subformat is different for e.g. current backend is configured for 16 bit PCM
9102 // as compared to 24 bit PCM backend requested
Kuirong Wang0b947f72016-09-29 11:03:09 -07009103 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
9104 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309105 (channels != my_data->current_backend_cfg[backend_idx].channels) ||
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009106 (format != my_data->current_backend_cfg[backend_idx].format)) {
Kuirong Wange9894162016-08-26 15:16:39 -07009107 backend_cfg->bit_width = bit_width;
9108 backend_cfg->sample_rate= sample_rate;
Kuirong Wang0b947f72016-09-29 11:03:09 -07009109 backend_cfg->channels = channels;
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009110 backend_cfg->format = format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309111 backend_change = true;
9112 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309113 "new sample rate: %d new channel: %d new format: %d",
Kuirong Wang0b947f72016-09-29 11:03:09 -07009114 __func__, backend_cfg->bit_width,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309115 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309116 }
9117
9118 return backend_change;
9119}
9120
9121bool platform_check_and_set_capture_codec_backend_cfg(struct audio_device* adev,
9122 struct audio_usecase *usecase, snd_device_t snd_device)
9123{
Kuirong Wang0b947f72016-09-29 11:03:09 -07009124 int backend_idx = platform_get_backend_index(snd_device);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309125 int ret = 0;
Kuirong Wange9894162016-08-26 15:16:39 -07009126 struct audio_backend_cfg backend_cfg;
9127
9128 backend_cfg.passthrough_enabled = false;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05309129
Surendar Karka93cd25a2018-08-28 14:21:37 +05309130 if (usecase->type == TRANSCODE_LOOPBACK_TX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05309131 backend_cfg.bit_width = usecase->stream.inout->in_config.bit_width;
9132 backend_cfg.sample_rate = usecase->stream.inout->in_config.sample_rate;
9133 backend_cfg.format = usecase->stream.inout->in_config.format;
9134 backend_cfg.channels = audio_channel_count_from_out_mask(
9135 usecase->stream.inout->in_config.channel_mask);
9136 } else if (usecase->type == PCM_CAPTURE) {
Kuirong Wange9894162016-08-26 15:16:39 -07009137 backend_cfg.sample_rate= usecase->stream.in->sample_rate;
9138 backend_cfg.bit_width= usecase->stream.in->bit_width;
9139 backend_cfg.format= usecase->stream.in->format;
9140 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05309141 if (is_loopback_input_device(usecase->stream.in->device)) {
9142 int bw = platform_get_snd_device_bit_width(snd_device);
9143 if ((-ENOSYS != bw) && (backend_cfg.bit_width > (uint32_t)bw)) {
9144 backend_cfg.bit_width = bw;
9145 ALOGD("%s:txbecf: set bitwidth to %d from platform info",
9146 __func__, bw);
9147 }
9148 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309149 } else {
Kuirong Wange9894162016-08-26 15:16:39 -07009150 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
9151 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
9152 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
9153 backend_cfg.channels = 1;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309154 }
9155
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309156 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d format %d"
Kuirong Wange9894162016-08-26 15:16:39 -07009157 ", backend_idx %d usecase = %d device (%s)", __func__,
9158 backend_cfg.bit_width,
9159 backend_cfg.sample_rate,
9160 backend_cfg.channels,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309161 backend_cfg.format,
Kuirong Wange9894162016-08-26 15:16:39 -07009162 backend_idx, usecase->id,
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309163 platform_get_snd_device_name(snd_device));
Kuirong Wange9894162016-08-26 15:16:39 -07009164 if (platform_check_capture_codec_backend_cfg(adev, backend_idx,
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309165 &backend_cfg, snd_device)) {
Kuirong Wang0b947f72016-09-29 11:03:09 -07009166 ret = platform_set_codec_backend_cfg(adev, snd_device,
9167 backend_cfg);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309168 if(!ret)
9169 return true;
9170 }
9171
9172 return false;
9173}
9174
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309175int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
9176 const char * hw_interface)
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009177{
9178 int ret = 0;
9179
9180 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
9181 ALOGE("%s: Invalid snd_device = %d",
9182 __func__, device);
9183 ret = -EINVAL;
9184 goto done;
9185 }
9186
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309187 ALOGD("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
9188 platform_get_snd_device_name(device),
9189 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null",
9190 backend_tag);
Ashish Jaind150d4c2017-02-03 18:44:34 +05309191
9192 if (backend_tag != NULL ) {
9193 if (backend_tag_table[device]) {
9194 free(backend_tag_table[device]);
9195 }
9196 backend_tag_table[device] = strdup(backend_tag);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009197 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309198
9199 if (hw_interface != NULL) {
9200 if (hw_interface_table[device])
9201 free(hw_interface_table[device]);
9202
9203 ALOGD("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
9204 hw_interface_table[device] = strdup(hw_interface);
9205 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009206done:
9207 return ret;
9208}
9209
Naresh Tanniru6160c712017-04-17 15:43:48 +05309210const char *platform_get_snd_device_backend_interface(snd_device_t device)
9211{
9212 const char *hw_interface_name = NULL;
9213
9214 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
9215 ALOGE("%s: Invalid snd_device = %d",
9216 __func__, device);
9217 goto done;
9218 }
9219
9220 /* Get string value of necessary backend for device */
9221 hw_interface_name = hw_interface_table[device];
9222 if (hw_interface_name == NULL)
9223 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
9224 else
9225 ALOGD("%s: hw_interface set for device %s\n", __func__, hw_interface_name);
9226done:
9227 return hw_interface_name;
9228}
9229
Siena Richard7c2db772016-12-21 11:32:34 -08009230int platform_get_snd_device_backend_index(snd_device_t device)
9231{
9232 int i, be_dai_id;
9233 const char * hw_interface_name = NULL;
9234
9235 ALOGV("%s: enter with device %d\n", __func__, device);
9236
Aditya Bavanari701a6992017-03-30 19:17:16 +05309237 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Siena Richard7c2db772016-12-21 11:32:34 -08009238 ALOGE("%s: Invalid snd_device = %d",
9239 __func__, device);
9240 be_dai_id = -EINVAL;
9241 goto done;
9242 }
9243
9244 /* Get string value of necessary backend for device */
9245 hw_interface_name = hw_interface_table[device];
9246 if (hw_interface_name == NULL) {
9247 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
9248 be_dai_id = -EINVAL;
9249 goto done;
9250 }
9251
9252 /* Check if be dai name table was retrieved successfully */
9253 if (be_dai_name_table == NULL) {
9254 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
9255 be_dai_id = -EFAULT;
9256 goto done;
9257 }
9258
9259 /* Get backend ID for device specified */
9260 for (i = 0; i < max_be_dai_names; i++) {
9261 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
9262 be_dai_id = be_dai_name_table[i].be_id;
9263 goto done;
9264 }
9265 }
9266 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
9267 be_dai_id = -EINVAL;
9268 goto done;
9269
9270done:
9271 return be_dai_id;
9272}
9273
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009274int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
9275{
9276 int ret = 0;
9277 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
9278 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
9279 ret = -EINVAL;
9280 goto done;
9281 }
9282
9283 if ((type != 0) && (type != 1)) {
9284 ALOGE("%s: invalid usecase type", __func__);
9285 ret = -EINVAL;
9286 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309287 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009288 pcm_device_table[usecase][type] = pcm_id;
9289done:
9290 return ret;
9291}
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07009292
9293void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
9294{
Alexy Josephb1379942016-01-29 15:49:38 -08009295 *device_to_be_id = (int*) msm_device_to_be_id;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07009296 *length = msm_be_id_array_len;
9297}
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309298
Varun Balaraje49253e2017-07-06 19:48:56 +05309299int platform_set_stream_pan_scale_params(void *platform,
9300 int snd_id,
9301 struct mix_matrix_params mm_params)
9302{
9303 struct platform_data *my_data = (struct platform_data *)platform;
9304 struct audio_device *adev = my_data->adev;
9305 struct mixer_ctl *ctl = NULL;
9306 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
9307 int ret = 0;
9308 int iter_i = 0;
9309 int iter_j = 0;
9310 int length = 0;
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309311 char *pan_scale_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05309312
9313 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
9314 "Audio Stream %d Pan Scale Control", snd_id);
9315 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9316
9317 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9318 if (!ctl) {
9319 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9320 __func__, mixer_ctl_name);
9321 ret = -EINVAL;
9322 goto end;
9323 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309324 pan_scale_data = (char *) calloc(1, sizeof(mm_params));
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309325 if (!pan_scale_data) {
9326 ret = -ENOMEM;
9327 goto end;
9328 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309329 memcpy(&pan_scale_data[length], &mm_params.num_output_channels,
9330 sizeof(mm_params.num_output_channels));
9331 length += sizeof(mm_params.num_output_channels);
9332 memcpy(&pan_scale_data[length], &mm_params.num_input_channels,
9333 sizeof(mm_params.num_input_channels));
9334 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05309335
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309336 memcpy(&pan_scale_data[length], &mm_params.has_output_channel_map,
9337 sizeof(mm_params.has_output_channel_map));
9338 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309339 if (mm_params.has_output_channel_map &&
9340 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309341 mm_params.num_output_channels > 0) {
9342 memcpy(&pan_scale_data[length], mm_params.output_channel_map,
9343 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
9344 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
9345 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309346 ret = -EINVAL;
9347 goto end;
9348 }
9349
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309350 memcpy(&pan_scale_data[length], &mm_params.has_input_channel_map,
9351 sizeof(mm_params.has_input_channel_map));
9352 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309353 if (mm_params.has_input_channel_map &&
9354 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309355 mm_params.num_input_channels > 0) {
9356 memcpy(&pan_scale_data[length], mm_params.input_channel_map,
9357 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
9358 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
9359 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309360 ret = -EINVAL;
9361 goto end;
9362 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309363 pan_scale_data[length] = mm_params.has_mixer_coeffs;
9364 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05309365 if (mm_params.has_mixer_coeffs)
9366 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309367 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
9368 memcpy(&pan_scale_data[length],
9369 &mm_params.mixer_coeffs[iter_i][iter_j],
9370 (sizeof(mm_params.mixer_coeffs[0][0])));
9371 length += (sizeof(mm_params.mixer_coeffs[0][0]));
9372 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309373
9374 ret = mixer_ctl_set_array(ctl, pan_scale_data, length);
9375end:
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309376 if (pan_scale_data)
9377 free(pan_scale_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05309378 return ret;
9379}
9380
9381int platform_set_stream_downmix_params(void *platform,
9382 int snd_id,
9383 snd_device_t snd_device,
9384 struct mix_matrix_params mm_params)
9385{
9386 struct platform_data *my_data = (struct platform_data *)platform;
9387 struct audio_device *adev = my_data->adev;
9388 struct mixer_ctl *ctl;
9389 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309390 char *downmix_param_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05309391 int ret = 0;
9392 int iter_i = 0;
9393 int iter_j = 0;
9394 int length = 0;
9395 int be_idx = 0;
9396
Varun Balaraje49253e2017-07-06 19:48:56 +05309397 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
9398 "Audio Device %d Downmix Control", snd_id);
9399 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9400
9401 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9402 if (!ctl) {
9403 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9404 __func__, mixer_ctl_name);
9405 ret = -EINVAL;
9406 }
9407
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309408 downmix_param_data = (char *) calloc(1, sizeof(mm_params) + sizeof(be_idx));
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309409 if (!downmix_param_data) {
9410 ret = -ENOMEM;
9411 goto end;
9412 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309413 be_idx = platform_get_snd_device_backend_index(snd_device);
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309414 memcpy(&downmix_param_data[length], &be_idx, sizeof(be_idx));
9415 length += sizeof(be_idx);
9416 memcpy(&downmix_param_data[length], &mm_params.num_output_channels,
9417 sizeof(mm_params.num_output_channels));
9418 length += sizeof(mm_params.num_output_channels);
9419 memcpy(&downmix_param_data[length], &mm_params.num_input_channels,
9420 sizeof(mm_params.num_input_channels));
9421 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05309422
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309423 memcpy(&downmix_param_data[length], &mm_params.has_output_channel_map,
9424 sizeof(mm_params.has_output_channel_map));
9425 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309426 if (mm_params.has_output_channel_map &&
9427 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309428 mm_params.num_output_channels > 0) {
9429 memcpy(&downmix_param_data[length], mm_params.output_channel_map,
9430 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
9431 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
9432 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309433 ret = -EINVAL;
9434 goto end;
9435 }
9436
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309437 memcpy(&downmix_param_data[length], &mm_params.has_input_channel_map,
9438 sizeof(mm_params.has_input_channel_map));
9439 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309440 if (mm_params.has_input_channel_map &&
9441 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309442 mm_params.num_input_channels > 0) {
9443 memcpy(&downmix_param_data[length], mm_params.input_channel_map,
9444 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
9445 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
9446 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309447 ret = -EINVAL;
9448 goto end;
9449 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309450 memcpy(&downmix_param_data[length], &mm_params.has_mixer_coeffs,
9451 sizeof(mm_params.has_mixer_coeffs));
9452 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05309453 if (mm_params.has_mixer_coeffs)
9454 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309455 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
9456 memcpy((uint32_t *) &downmix_param_data[length],
9457 &mm_params.mixer_coeffs[iter_i][iter_j],
9458 (sizeof(mm_params.mixer_coeffs[0][0])));
9459 length += (sizeof(mm_params.mixer_coeffs[0][0]));
9460 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309461
9462 ret = mixer_ctl_set_array(ctl, downmix_param_data, length);
9463end:
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309464 if (downmix_param_data)
9465 free(downmix_param_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05309466 return ret;
9467}
9468
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309469int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
9470 int snd_id, uint8_t *input_channel_map)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009471{
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309472 int ret = 0, i = 0;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009473 int channels = audio_channel_count_from_out_mask(channel_mask);
9474
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309475 char channel_map[AUDIO_CHANNEL_COUNT_MAX];
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009476 memset(channel_map, 0, sizeof(channel_map));
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309477 if (*input_channel_map) {
9478 for (i = 0; i < channels; i++) {
9479 ALOGV("%s:: Channel Map channel_map[%d] - %d", __func__, i, *input_channel_map);
9480 channel_map[i] = *input_channel_map;
9481 input_channel_map++;
9482 }
9483 } else {
9484 /* Following are all most common standard WAV channel layouts
9485 overridden by channel mask if its allowed and different */
9486 switch (channels) {
9487 case 1:
9488 /* AUDIO_CHANNEL_OUT_MONO */
9489 channel_map[0] = PCM_CHANNEL_FC;
9490 break;
9491 case 2:
9492 /* AUDIO_CHANNEL_OUT_STEREO */
9493 channel_map[0] = PCM_CHANNEL_FL;
9494 channel_map[1] = PCM_CHANNEL_FR;
9495 break;
9496 case 3:
9497 /* AUDIO_CHANNEL_OUT_2POINT1 */
9498 channel_map[0] = PCM_CHANNEL_FL;
9499 channel_map[1] = PCM_CHANNEL_FR;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009500 channel_map[2] = PCM_CHANNEL_FC;
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309501 break;
9502 case 4:
9503 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
9504 channel_map[0] = PCM_CHANNEL_FL;
9505 channel_map[1] = PCM_CHANNEL_FR;
9506 channel_map[2] = PCM_CHANNEL_LS;
9507 channel_map[3] = PCM_CHANNEL_RS;
9508 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK) {
9509 channel_map[2] = PCM_CHANNEL_LB;
9510 channel_map[3] = PCM_CHANNEL_RB;
9511 }
9512 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND) {
9513 channel_map[2] = PCM_CHANNEL_FC;
9514 channel_map[3] = PCM_CHANNEL_CS;
9515 }
9516 break;
9517 case 5:
9518 /* AUDIO_CHANNEL_OUT_PENTA */
9519 channel_map[0] = PCM_CHANNEL_FL;
9520 channel_map[1] = PCM_CHANNEL_FR;
9521 channel_map[2] = PCM_CHANNEL_FC;
9522 channel_map[3] = PCM_CHANNEL_LB;
9523 channel_map[4] = PCM_CHANNEL_RB;
9524 break;
9525 case 6:
9526 /* AUDIO_CHANNEL_OUT_5POINT1 */
9527 channel_map[0] = PCM_CHANNEL_FL;
9528 channel_map[1] = PCM_CHANNEL_FR;
9529 channel_map[2] = PCM_CHANNEL_FC;
9530 channel_map[3] = PCM_CHANNEL_LFE;
9531 channel_map[4] = PCM_CHANNEL_LB;
9532 channel_map[5] = PCM_CHANNEL_RB;
9533 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE) {
9534 channel_map[4] = PCM_CHANNEL_LS;
9535 channel_map[5] = PCM_CHANNEL_RS;
9536 }
9537 break;
9538 case 7:
9539 /* AUDIO_CHANNEL_OUT_6POINT1 */
9540 channel_map[0] = PCM_CHANNEL_FL;
9541 channel_map[1] = PCM_CHANNEL_FR;
9542 channel_map[2] = PCM_CHANNEL_FC;
9543 channel_map[3] = PCM_CHANNEL_LFE;
9544 channel_map[4] = PCM_CHANNEL_LB;
9545 channel_map[5] = PCM_CHANNEL_RB;
9546 channel_map[6] = PCM_CHANNEL_CS;
9547 break;
9548 case 8:
9549 /* AUDIO_CHANNEL_OUT_7POINT1 */
9550 channel_map[0] = PCM_CHANNEL_FL;
9551 channel_map[1] = PCM_CHANNEL_FR;
9552 channel_map[2] = PCM_CHANNEL_FC;
9553 channel_map[3] = PCM_CHANNEL_LFE;
9554 channel_map[4] = PCM_CHANNEL_LB;
9555 channel_map[5] = PCM_CHANNEL_RB;
Weiyin Jiangff72f812018-04-13 15:02:33 +08009556 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1POINT2) {
9557 channel_map[6] = PCM_CHANNEL_TFL;
9558 channel_map[7] = PCM_CHANNEL_TFR;
9559 } else {
9560 channel_map[6] = PCM_CHANNEL_LS;
9561 channel_map[7] = PCM_CHANNEL_RS;
9562 }
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309563 break;
Dieter Luecking5d57def2018-09-07 14:23:37 +02009564 case 12:
9565 /* AUDIO_CHANNEL_OUT_7POINT1POINT4 */
9566 channel_map[0] = PCM_CHANNEL_FL;
9567 channel_map[1] = PCM_CHANNEL_FR;
9568 channel_map[2] = PCM_CHANNEL_FC;
9569 channel_map[3] = PCM_CHANNEL_LFE;
9570 channel_map[4] = PCM_CHANNEL_LB;
9571 channel_map[5] = PCM_CHANNEL_RB;
9572 channel_map[6] = PCM_CHANNEL_LS;
9573 channel_map[7] = PCM_CHANNEL_RS;
9574 channel_map[8] = PCM_CHANNEL_TFL;
9575 channel_map[9] = PCM_CHANNEL_TFR;
9576 channel_map[10] = PCM_CHANNEL_TSL;
9577 channel_map[11] = PCM_CHANNEL_TSR;
9578 break;
9579 case 16:
9580 /* 16 channels */
9581 channel_map[0] = PCM_CHANNEL_FL;
9582 channel_map[1] = PCM_CHANNEL_FR;
9583 channel_map[2] = PCM_CHANNEL_FC;
9584 channel_map[3] = PCM_CHANNEL_LFE;
9585 channel_map[4] = PCM_CHANNEL_LB;
9586 channel_map[5] = PCM_CHANNEL_RB;
9587 channel_map[6] = PCM_CHANNEL_LS;
9588 channel_map[7] = PCM_CHANNEL_RS;
9589 channel_map[8] = PCM_CHANNEL_TFL;
9590 channel_map[9] = PCM_CHANNEL_TFR;
9591 channel_map[10] = PCM_CHANNEL_TSL;
9592 channel_map[11] = PCM_CHANNEL_TSR;
9593 channel_map[12] = PCM_CHANNEL_FLC;
9594 channel_map[13] = PCM_CHANNEL_FRC;
9595 channel_map[14] = PCM_CHANNEL_RLC;
9596 channel_map[15] = PCM_CHANNEL_RRC;
9597 break;
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309598 default:
9599 ALOGE("unsupported channels %d for setting channel map", channels);
9600 return -1;
9601 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009602 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309603 ret = platform_set_channel_map(platform, channels, channel_map, snd_id, -1);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009604 return ret;
9605}
9606
9607int platform_get_edid_info(void *platform)
9608{
9609 struct platform_data *my_data = (struct platform_data *)platform;
9610 struct audio_device *adev = my_data->adev;
9611 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05309612 int ret, count;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009613 char *mix_ctl_name;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009614 struct mixer_ctl *ctl;
9615 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
9616 edid_audio_info *info;
9617
9618 if (my_data->edid_valid) {
9619 /* use cached edid */
9620 return 0;
9621 }
9622
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009623 switch(my_data->ext_disp_type) {
9624 case EXT_DISPLAY_TYPE_HDMI:
9625 mix_ctl_name = "HDMI EDID";
9626 break;
9627 case EXT_DISPLAY_TYPE_DP:
9628 mix_ctl_name = "Display Port EDID";
9629 break;
9630 default:
9631 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
9632 return -EINVAL;
9633 }
9634
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009635 if (my_data->edid_info == NULL) {
9636 my_data->edid_info =
9637 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
9638 }
9639
9640 info = my_data->edid_info;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009641 ctl = mixer_get_ctl_by_name(adev->mixer, mix_ctl_name);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009642 if (!ctl) {
9643 ALOGE("%s: Could not get ctl for mixer cmd - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009644 __func__, mix_ctl_name);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009645 goto fail;
9646 }
9647
9648 mixer_ctl_update(ctl);
9649
9650 count = mixer_ctl_get_num_values(ctl);
9651
9652 /* Read SAD blocks, clamping the maximum size for safety */
9653 if (count > (int)sizeof(block))
9654 count = (int)sizeof(block);
9655
9656 ret = mixer_ctl_get_array(ctl, block, count);
9657 if (ret != 0) {
9658 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
9659 goto fail;
9660 }
9661 edid_data[0] = count;
9662 memcpy(&edid_data[1], block, count);
9663
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08009664 if (!audio_extn_edid_get_sink_caps(info, edid_data)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009665 ALOGE("%s: Failed to get extn disp sink capabilities", __func__);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009666 goto fail;
9667 }
9668 my_data->edid_valid = true;
9669 return 0;
9670fail:
9671 if (my_data->edid_info) {
9672 free(my_data->edid_info);
9673 my_data->edid_info = NULL;
9674 my_data->edid_valid = false;
9675 }
9676 ALOGE("%s: return -EINVAL", __func__);
9677 return -EINVAL;
9678}
9679
9680
9681int platform_set_channel_allocation(void *platform, int channel_alloc)
9682{
9683 struct mixer_ctl *ctl;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009684 char *mixer_ctl_name;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009685 int ret;
9686 struct platform_data *my_data = (struct platform_data *)platform;
9687 struct audio_device *adev = my_data->adev;
9688
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009689 switch(my_data->ext_disp_type) {
9690 case EXT_DISPLAY_TYPE_HDMI:
9691 mixer_ctl_name = "HDMI RX CA";
9692 break;
9693 case EXT_DISPLAY_TYPE_DP:
9694 mixer_ctl_name = "Display Port RX CA";
9695 break;
9696 default:
9697 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
9698 return -EINVAL;
9699 }
9700
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009701 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9702 if (!ctl) {
9703 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9704 __func__, mixer_ctl_name);
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009705 return -EINVAL;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009706 }
9707 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
9708 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
9709
9710 if (ret < 0) {
9711 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
9712 }
9713
9714 return ret;
9715}
9716
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309717int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id, int be_idx)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009718{
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309719 struct mixer_ctl *ctl, *be_ctl = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08009720 char mixer_ctl_name[44] = {0}; // max length of name is 44 as defined
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309721 char be_mixer_ctl_name[] = "Backend Device Channel Map";
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009722 int ret;
Ramu Gottipati02809682018-12-19 16:46:12 +05309723 int i=0, n=0;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309724 int be_id_count = 0;
Dieter Luecking5d57def2018-09-07 14:23:37 +02009725 long set_values[AUDIO_MAX_DSP_CHANNELS];
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309726 long be_set_values[AUDIO_MAX_DSP_CHANNELS + 1] = {0};
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009727 struct platform_data *my_data = (struct platform_data *)platform;
9728 struct audio_device *adev = my_data->adev;
9729 ALOGV("%s channel_count:%d",__func__, ch_count);
Dieter Luecking5d57def2018-09-07 14:23:37 +02009730
9731 /*
9732 * FIXME:
9733 * Currently the channel mask in audio.h is limited to 30 channels,
9734 * (=AUDIO_CHANNEL_COUNT_MAX), whereas the mixer controls already
9735 * allow up to AUDIO_MAX_DSP_CHANNELS channels as per final requirement.
9736 * Until channel mask definition is not changed from a uint32_t value
9737 * to something else, a sanity check is needed here.
9738 */
9739 if (NULL == ch_map || (ch_count < 1) || (ch_count > AUDIO_CHANNEL_COUNT_MAX)) {
Divya Narayanan Poojary21de6aa2017-01-06 12:07:19 +05309740 ALOGE("%s: Invalid channel mapping or channel count value", __func__);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009741 return -EINVAL;
9742 }
Fred Ohe0479682015-03-25 16:30:26 -07009743
9744 /*
9745 * If snd_id is greater than 0, stream channel mapping
9746 * If snd_id is below 0, typically -1, device channel mapping
9747 */
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009748 if (snd_id >= 0) {
Fred Ohe0479682015-03-25 16:30:26 -07009749 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
9750 } else {
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309751 if (be_idx >= 0) {
9752 be_ctl = mixer_get_ctl_by_name(adev->mixer, be_mixer_ctl_name);
9753 if (!be_ctl) {
9754 ALOGD("%s: Could not get ctl for mixer cmd - %s, using default control",
9755 __func__, be_mixer_ctl_name);
9756 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
9757 be_idx = -1;
9758 } else {
9759 strlcpy(mixer_ctl_name, "Backend Device Channel Map", sizeof(mixer_ctl_name));
9760 be_id_count = 1;
9761 }
9762 } else {
9763 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
9764 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009765 }
9766
9767 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9768
9769 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
Dieter Luecking5d57def2018-09-07 14:23:37 +02009770
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009771 if (!ctl) {
9772 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9773 __func__, mixer_ctl_name);
9774 return -EINVAL;
9775 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02009776
9777 /* find out how many values the control can set */
9778 n = mixer_ctl_get_num_values(ctl);
9779
9780 if (n != ch_count)
9781 ALOGV("%s chcnt %d != mixerctl elem size %d",__func__, ch_count, n);
9782
9783 if (n < ch_count) {
9784 ALOGE("%s chcnt %d > mixerctl elem size %d",__func__, ch_count, n);
9785 return -EINVAL;
9786 }
9787
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309788 if (n > (AUDIO_MAX_DSP_CHANNELS + be_id_count)) {
Dieter Luecking5d57def2018-09-07 14:23:37 +02009789 ALOGE("%s mixerctl elem size %d > AUDIO_MAX_DSP_CHANNELS %d",__func__, n, AUDIO_MAX_DSP_CHANNELS);
9790 return -EINVAL;
9791 }
9792
9793 /* initialize all set_values to zero */
9794 memset (set_values, 0, sizeof(set_values));
9795
9796 /* copy only as many values as corresponding mixer_ctrl allows */
9797 for (i = 0; i < ch_count; i++) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009798 set_values[i] = ch_map[i];
9799 }
9800
Manish Dewangan338c50a2017-09-12 15:22:03 +05309801 ALOGD("%s: set mapping(%ld %ld %ld %ld %ld %ld %ld %ld) for channel:%d", __func__,
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009802 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
9803 set_values[5], set_values[6], set_values[7], ch_count);
9804
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309805 if (be_idx >= 0) {
9806 be_set_values[0] = be_idx;
9807 memcpy(&be_set_values[1], set_values, sizeof(long) * ch_count);
9808 ret = mixer_ctl_set_array(ctl, be_set_values, ARRAY_SIZE(be_set_values));
9809 } else {
9810 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
9811 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02009812
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009813 if (ret < 0) {
9814 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
9815 __func__, ret, ch_count);
9816 }
9817 return ret;
9818}
9819
9820unsigned char platform_map_to_edid_format(int audio_format)
9821{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009822 unsigned char format;
9823 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
9824 case AUDIO_FORMAT_AC3:
9825 ALOGV("%s: AC3", __func__);
9826 format = AC3;
9827 break;
9828 case AUDIO_FORMAT_AAC:
9829 ALOGV("%s:AAC", __func__);
9830 format = AAC;
9831 break;
Manish Dewangana6fc5442015-08-24 20:30:31 +05309832 case AUDIO_FORMAT_AAC_ADTS:
9833 ALOGV("%s:AAC_ADTS", __func__);
9834 format = AAC;
9835 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009836 case AUDIO_FORMAT_E_AC3:
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05309837 case AUDIO_FORMAT_E_AC3_JOC:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009838 ALOGV("%s:E_AC3", __func__);
9839 format = DOLBY_DIGITAL_PLUS;
9840 break;
Ben Romberger1aaaf862017-04-06 17:49:46 -07009841 case AUDIO_FORMAT_DOLBY_TRUEHD:
9842 ALOGV("%s:MAT", __func__);
9843 format = MAT;
9844 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08009845 case AUDIO_FORMAT_DTS:
9846 ALOGV("%s:DTS", __func__);
9847 format = DTS;
9848 break;
9849 case AUDIO_FORMAT_DTS_HD:
9850 ALOGV("%s:DTS_HD", __func__);
9851 format = DTS_HD;
9852 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009853 case AUDIO_FORMAT_PCM_16_BIT:
Ashish Jain5106d362016-05-11 19:23:33 +05309854 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
9855 case AUDIO_FORMAT_PCM_8_24_BIT:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009856 ALOGV("%s:PCM", __func__);
Mingming Yin3a941d42016-02-17 18:08:05 -08009857 format = LPCM;
9858 break;
Naresh Tanniru928f0862017-04-07 16:44:23 -07009859 case AUDIO_FORMAT_IEC61937:
9860 ALOGV("%s:IEC61937", __func__);
9861 format = 0;
9862 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08009863 default:
Mingming Yin3a941d42016-02-17 18:08:05 -08009864 format = -1;
Naresh Tanniru928f0862017-04-07 16:44:23 -07009865 ALOGE("%s:invalid format: 0x%x", __func__, audio_format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009866 break;
9867 }
9868 return format;
9869}
9870
Ashish Jaina052e572016-11-07 16:41:07 +05309871void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
9872 unsigned int stream_sr, int* sample_rate)
9873{
9874 struct platform_data* my_data = (struct platform_data *)platform;
9875 int backend_idx = platform_get_backend_index(snd_device);
9876 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
9877 /*
9878 *Check if device SR is multiple of 8K or 11.025 Khz
9879 *check if the stream SR is multiple of same base, if yes
9880 *then have copp SR equal to stream SR, this ensures that
9881 *post processing happens at stream SR, else have
9882 *copp SR equal to device SR.
9883 */
9884 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
9885 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
9886 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
9887 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
9888 *sample_rate = device_sr;
9889 } else
9890 *sample_rate = stream_sr;
9891
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +05309892 if ((snd_device == SND_DEVICE_OUT_HDMI) || (snd_device == SND_DEVICE_OUT_DISPLAY_PORT) ||
9893 (snd_device == SND_DEVICE_OUT_USB_HEADSET))
9894 *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
Venugopal Nadipalli83134582017-09-21 22:34:50 +05309895
9896 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr, *sample_rate);
Ashish Jaina052e572016-11-07 16:41:07 +05309897
9898}
9899
Aalique Grahame22e49102018-12-18 14:23:57 -08009900// called from info parser
9901void platform_add_app_type(const char *uc_type,
9902 const char *mode,
9903 int bw,
9904 int app_type, int max_rate) {
9905 struct app_type_entry *ap =
9906 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
9907
9908 if (!ap) {
9909 ALOGE("%s failed to allocate mem for app type", __func__);
9910 return;
9911 }
9912
9913 ap->uc_type = -1;
9914 for (int i=0; i<USECASE_TYPE_MAX; i++) {
9915 if (!strcmp(uc_type, usecase_type_index[i].name)) {
9916 ap->uc_type = usecase_type_index[i].index;
9917 break;
9918 }
9919 }
9920
9921 if (ap->uc_type == -1) {
9922 free(ap);
9923 return;
9924 }
9925
9926 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
9927 __func__, uc_type, mode, bw, app_type, max_rate);
9928 ap->bit_width = bw;
9929 ap->app_type = app_type;
9930 ap->max_rate = max_rate;
9931 ap->mode = strdup(mode);
9932 list_add_tail(&app_type_entry_list, &ap->node);
9933}
9934
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009935void platform_reset_edid_info(void *platform) {
9936
9937 ALOGV("%s:", __func__);
9938 struct platform_data *my_data = (struct platform_data *)platform;
9939 if (my_data->edid_info) {
9940 ALOGV("%s :free edid", __func__);
9941 free(my_data->edid_info);
9942 my_data->edid_info = NULL;
9943 }
9944}
9945
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009946bool platform_is_edid_supported_format(void *platform, int format)
9947{
9948 struct platform_data *my_data = (struct platform_data *)platform;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009949 edid_audio_info *info = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05309950 int i, ret;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009951 unsigned char format_id = platform_map_to_edid_format(format);
9952
Naresh Tanniru928f0862017-04-07 16:44:23 -07009953 if (format == AUDIO_FORMAT_IEC61937)
9954 return true;
9955
Mingming Yin3a941d42016-02-17 18:08:05 -08009956 if (format_id <= 0) {
9957 ALOGE("%s invalid edid format mappting for :%x" ,__func__, format);
9958 return false;
9959 }
9960
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009961 ret = platform_get_edid_info(platform);
9962 info = (edid_audio_info *)my_data->edid_info;
9963 if (ret == 0 && info != NULL) {
9964 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009965 /*
9966 * To check
9967 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
9968 * & DOLBY_DIGITAL_PLUS
9969 */
9970 if (info->audio_blocks_array[i].format_id == format_id) {
Mingming Yin3a941d42016-02-17 18:08:05 -08009971 ALOGV("%s:returns true %x",
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009972 __func__, format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009973 return true;
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009974 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009975 }
9976 }
Mingming Yin3a941d42016-02-17 18:08:05 -08009977 ALOGV("%s:returns false %x",
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009978 __func__, format);
9979 return false;
9980}
9981
Mingming Yin3a941d42016-02-17 18:08:05 -08009982bool platform_is_edid_supported_sample_rate(void *platform, int sample_rate)
9983{
9984 struct platform_data *my_data = (struct platform_data *)platform;
Mingming Yin3a941d42016-02-17 18:08:05 -08009985 edid_audio_info *info = NULL;
Garmond Leung2f78a672016-11-07 16:27:40 -08009986 int ret = 0;
Mingming Yin3a941d42016-02-17 18:08:05 -08009987
9988 ret = platform_get_edid_info(platform);
9989 info = (edid_audio_info *)my_data->edid_info;
9990 if (ret == 0 && info != NULL) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08009991 return audio_extn_edid_is_supported_sr(info, sample_rate);
Mingming Yin3a941d42016-02-17 18:08:05 -08009992 }
Mingming Yin3a941d42016-02-17 18:08:05 -08009993
9994 return false;
9995}
9996
Naresh Tanniru3a406772017-05-10 13:09:05 -07009997int platform_edid_get_highest_supported_sr(void *platform)
9998{
9999 struct platform_data *my_data = (struct platform_data *)platform;
10000 edid_audio_info *info = NULL;
10001 int ret = 0;
10002
10003 ret = platform_get_edid_info(platform);
10004 info = (edid_audio_info *)my_data->edid_info;
10005 if (ret == 0 && info != NULL) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -080010006 return audio_extn_edid_get_highest_supported_sr(info);
Naresh Tanniru3a406772017-05-10 13:09:05 -070010007 }
10008
10009 return 0;
10010}
Mingming Yin3a941d42016-02-17 18:08:05 -080010011
Dieter Luecking5d57def2018-09-07 14:23:37 +020010012bool platform_spkr_use_default_sample_rate(void *platform) {
10013 struct platform_data *my_data = (struct platform_data *)platform;
10014 return my_data->use_sprk_default_sample_rate;
10015}
10016
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010017int platform_set_edid_channels_configuration(void *platform, int channels, int backend_idx, snd_device_t snd_device) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010018
10019 struct platform_data *my_data = (struct platform_data *)platform;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010020 struct audio_device *adev = my_data->adev;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010021 edid_audio_info *info = NULL;
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010022 int ret;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010023 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010024 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010025 int be_idx = -1;
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010026 int channel_alloc = 0;
10027 int max_supported_channels = 0;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010028
Weiyin Jiangff72f812018-04-13 15:02:33 +080010029 if ((backend_idx != HDMI_RX_BACKEND) &&
10030 (backend_idx != DISP_PORT_RX_BACKEND)) {
10031 ALOGE("%s: Invalid backend idx %d", __func__, backend_idx);
10032 return -EINVAL;
10033 }
10034
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010035 be_idx = platform_get_snd_device_backend_index(snd_device);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010036 ret = platform_get_edid_info(platform);
10037 info = (edid_audio_info *)my_data->edid_info;
Weiyin Jiangff72f812018-04-13 15:02:33 +080010038 adev_device_cfg_ptr += backend_idx;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010039 if(ret == 0 && info != NULL) {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010040 if ((channels > 2) && (channels <= MAX_HDMI_CHANNEL_CNT)) {
Weiyin Jiangff72f812018-04-13 15:02:33 +080010041 ALOGV("%s:able to get HDMI/DP sink capabilities multi channel playback",
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010042 __func__);
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010043 max_supported_channels = platform_edid_get_max_channels(my_data);
10044 if (channels > max_supported_channels)
10045 channels = max_supported_channels;
10046 // refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4
10047 switch (channels) {
10048 case 3:
10049 channel_alloc = 0x02; break;
10050 case 4:
10051 channel_alloc = 0x06; break;
10052 case 5:
10053 channel_alloc = 0x0A; break;
10054 case 6:
10055 channel_alloc = 0x0B; break;
10056 case 7:
10057 channel_alloc = 0x12; break;
10058 case 8:
10059 channel_alloc = 0x13; break;
10060 default:
10061 ALOGE("%s: invalid channel %d", __func__, channels);
10062 return -EINVAL;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010063 }
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010064 ALOGVV("%s:channels:%d", __func__, channels);
10065
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010066 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10067 platform_set_channel_map(platform, adev_device_cfg_ptr->dev_cfg_params.channels,
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010068 (char *)adev_device_cfg_ptr->dev_cfg_params.channel_map, -1, be_idx);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010069 } else {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010070 platform_set_channel_map(platform, channels, info->channel_map, -1, be_idx);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010071 }
10072
10073 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10074 ALOGV("%s:: Setting client selected CA %d", __func__,
10075 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
10076 platform_set_channel_allocation(platform,
10077 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
10078 } else {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010079 platform_set_channel_allocation(platform, channel_alloc);
10080 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010081 } else {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010082 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10083 default_channelMap[0] = adev_device_cfg_ptr->dev_cfg_params.channel_map[0];
10084 default_channelMap[1] = adev_device_cfg_ptr->dev_cfg_params.channel_map[1];
10085 } else {
10086 default_channelMap[0] = PCM_CHANNEL_FL;
10087 default_channelMap[1] = PCM_CHANNEL_FR;
10088 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010089 platform_set_channel_map(platform, 2, default_channelMap, -1, be_idx);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010090 platform_set_channel_allocation(platform,0);
10091 }
10092 }
10093
10094 return 0;
10095}
10096
10097void platform_cache_edid(void * platform)
10098{
10099 platform_get_edid_info(platform);
10100}
10101
Siddartha Shaik44dd7702017-06-14 12:13:25 +053010102void platform_invalidate_backend_config(void * platform,snd_device_t snd_device)
10103{
10104 struct platform_data *my_data = (struct platform_data *)platform;
10105 struct audio_device *adev = my_data->adev;
10106 struct audio_backend_cfg backend_cfg;
10107 int backend_idx;
10108
10109 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10110 backend_cfg.channels = CODEC_BACKEND_DEFAULT_CHANNELS;
10111 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10112 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
10113 backend_cfg.passthrough_enabled = false;
10114
10115 backend_idx = platform_get_backend_index(snd_device);
10116 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
10117 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10118 my_data->current_backend_cfg[backend_idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
10119 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10120 my_data->current_backend_cfg[backend_idx].format = AUDIO_FORMAT_PCM_16_BIT;
10121}
10122
Mingming Yinddd610b2016-01-20 17:09:32 -080010123void platform_invalidate_hdmi_config(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010124{
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010125 //reset ext display EDID info
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010126 struct platform_data *my_data = (struct platform_data *)platform;
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010127 struct audio_device *adev = my_data->adev;
10128 struct audio_backend_cfg backend_cfg;
10129 int backend_idx;
10130 snd_device_t snd_device;
10131
10132 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10133 backend_cfg.channels = DEFAULT_HDMI_OUT_CHANNELS;
10134 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10135 backend_cfg.format = 0;
10136 backend_cfg.passthrough_enabled = false;
10137
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010138 my_data->edid_valid = false;
10139 if (my_data->edid_info) {
10140 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
10141 }
Mingming Yinddd610b2016-01-20 17:09:32 -080010142
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010143 if (my_data->ext_disp_type == EXT_DISPLAY_TYPE_HDMI) {
10144 //reset HDMI_RX_BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010145 backend_idx = HDMI_RX_BACKEND;
10146 snd_device = SND_DEVICE_OUT_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010147 } else {
10148 //reset Display port BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010149 backend_idx = DISP_PORT_RX_BACKEND;
10150 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010151 }
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010152 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
10153 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10154 my_data->current_backend_cfg[backend_idx].channels = DEFAULT_HDMI_OUT_CHANNELS;
10155 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010156 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010157}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010158
10159int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
10160 const char *mixer_val)
10161{
10162 struct audio_device *adev = out->dev;
10163 struct mixer_ctl *ctl = NULL;
10164 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
10165 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10166 if (!ctl) {
10167 ALOGE("%s: could not get ctl for mixer cmd - %s",
10168 __func__, mixer_ctl_name);
10169 return -EINVAL;
10170 }
10171
10172 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
10173}
10174
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010175int platform_set_device_params(struct stream_out *out, int param, int value)
10176{
10177 struct audio_device *adev = out->dev;
10178 struct mixer_ctl *ctl;
10179 char *mixer_ctl_name = "Device PP Params";
10180 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +053010181 long set_values[] = {0,0};
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010182
10183 set_values[0] = param;
10184 set_values[1] = value;
10185
10186 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10187 if (!ctl) {
10188 ALOGE("%s: Could not get ctl for mixer cmd - %s",
10189 __func__, mixer_ctl_name);
10190 ret = -EINVAL;
10191 goto end;
10192 }
10193
10194 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
10195 __func__,param, value, mixer_ctl_name);
10196 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
10197
10198end:
10199 return ret;
10200}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010201
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010202bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
10203{
10204 bool ret = false;
10205
10206 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010207 snd_device == SND_DEVICE_OUT_SPEAKER_REVERSE ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010208 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010209 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
10210 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
Rohit kumarf4120402016-08-05 19:19:48 +053010211 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +053010212 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +053010213 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010214 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
10215 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
10216 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010217 ret = true;
10218 }
10219
10220 return ret;
10221}
10222
10223int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
10224{
10225 int acdb_id;
10226
10227 switch(snd_device) {
10228 case SND_DEVICE_OUT_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010229 case SND_DEVICE_OUT_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010230 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
10231 break;
10232 case SND_DEVICE_OUT_VOICE_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010233 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010234 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
10235 break;
Rohit kumarf4120402016-08-05 19:19:48 +053010236 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010237 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
Rohit kumarf4120402016-08-05 19:19:48 +053010238 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED);
10239 break;
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010240 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
10241 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED);
10242 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010243 case SND_DEVICE_OUT_SPEAKER_VBAT:
10244 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
10245 break;
10246 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
10247 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
10248 break;
Rohit kumarf4120402016-08-05 19:19:48 +053010249 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
10250 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT);
10251 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010252 default:
10253 acdb_id = -EINVAL;
10254 break;
10255 }
10256 return acdb_id;
10257}
10258
10259int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
10260{
10261 if (!audio_extn_spkr_prot_is_enabled())
10262 return snd_device;
10263
10264 switch(snd_device) {
10265 case SND_DEVICE_OUT_SPEAKER:
Aalique Grahame22e49102018-12-18 14:23:57 -080010266 case SND_DEVICE_OUT_SPEAKER_REVERSE:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010267 case SND_DEVICE_OUT_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010268 return SND_DEVICE_OUT_SPEAKER_PROTECTED;
Aalique Grahame22e49102018-12-18 14:23:57 -080010269 case SND_DEVICE_OUT_SPEAKER_SAFE:
10270 return SND_DEVICE_OUT_SPEAKER_SAFE;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010271 case SND_DEVICE_OUT_VOICE_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010272 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010273 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +053010274 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010275 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
Rohit kumarf4120402016-08-05 19:19:48 +053010276 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010277 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
10278 return SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010279 case SND_DEVICE_OUT_SPEAKER_VBAT:
10280 return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
10281 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
10282 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
Rohit kumarf4120402016-08-05 19:19:48 +053010283 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
10284 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010285 default:
10286 return snd_device;
10287 }
10288}
Rohit kumarf4120402016-08-05 19:19:48 +053010289int platform_get_vi_feedback_snd_device(snd_device_t snd_device)
10290{
10291 switch(snd_device) {
10292 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
10293 case SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT:
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010294 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED:
Rohit kumarf4120402016-08-05 19:19:48 +053010295 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
10296 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
10297 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT:
10298 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1;
10299 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED:
10300 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT:
10301 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2;
10302 default:
10303 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
10304 }
10305}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010306
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +053010307int platform_spkr_prot_is_wsa_analog_mode(void *adev __unused)
10308{
10309 return 0;
10310}
10311
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010312/*
10313 * This is a lookup table to map android audio input device to audio h/w interface (backend).
10314 * The table can be extended for other input devices by adding appropriate entries.
10315 * Also the audio interface for a particular input device can be overriden by adding
10316 * corresponding entry in audio_platform_info.xml file.
10317 */
10318struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
10319 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), "SLIMBUS_0"},
10320 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), "SLIMBUS_0"},
10321};
10322
10323int audio_device_to_interface_table_len =
10324 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
10325
Karthik Reddy Katta508eca42015-05-11 13:43:18 +053010326int platform_set_audio_device_interface(const char *device_name, const char *intf_name,
10327 const char *codec_type __unused)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010328{
10329 int ret = 0;
10330 int i;
10331
10332 if (device_name == NULL || intf_name == NULL) {
10333 ALOGE("%s: Invalid input", __func__);
10334
10335 ret = -EINVAL;
10336 goto done;
10337 }
10338
10339 ALOGD("%s: Enter, device name:%s, intf name:%s", __func__, device_name, intf_name);
10340
10341 size_t device_name_len = strlen(device_name);
10342 for (i = 0; i < audio_device_to_interface_table_len; i++) {
10343 char* name = audio_device_to_interface_table[i].device_name;
10344 size_t name_len = strlen(name);
10345 if ((name_len == device_name_len) &&
10346 (strncmp(device_name, name, name_len) == 0)) {
10347 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
10348 __func__, device_name, intf_name);
10349
10350 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
10351 sizeof(audio_device_to_interface_table[i].interface_name));
10352 goto done;
10353 }
10354 }
10355 ALOGE("%s: Could not find matching device name %s",
10356 __func__, device_name);
10357
10358 ret = -EINVAL;
10359
10360done:
10361 return ret;
10362}
Laxminath Kasam44f49402015-05-29 18:37:11 +053010363
Kuirong Wang1cad7142016-05-24 15:21:56 -070010364int platform_set_sidetone(struct audio_device *adev,
10365 snd_device_t out_snd_device,
10366 bool enable,
10367 char *str)
10368{
10369 int ret;
Ashish Jain3e37a702016-11-25 12:27:15 +053010370 if ((out_snd_device == SND_DEVICE_OUT_USB_HEADSET) ||
Aalique Grahame22e49102018-12-18 14:23:57 -080010371 (out_snd_device == SND_DEVICE_OUT_USB_HEADPHONES) ||
10372 (out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET)) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -070010373 if (property_get_bool("vendor.audio.usb.disable.sidetone", 0)) {
Haynes Mathew George492a6c42016-10-28 11:41:43 -070010374 ALOGI("Debug: Disable sidetone");
10375 } else {
Kuirong Wang1cad7142016-05-24 15:21:56 -070010376 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
Vikram Panduranga6e761cd2016-10-12 16:50:52 -070010377 if (ret) {
10378 /*fall back to AFE sidetone*/
10379 ALOGV("%s: No USB sidetone supported, switching to AFE sidetone",
10380 __func__);
10381
10382 if (enable)
10383 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10384 else
10385 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10386 }
Haynes Mathew George492a6c42016-10-28 11:41:43 -070010387 }
Kuirong Wang1cad7142016-05-24 15:21:56 -070010388 } else {
10389 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
10390 __func__, out_snd_device, str);
Laxminath Kasam44f49402015-05-29 18:37:11 +053010391
Vikram Panduranga6e761cd2016-10-12 16:50:52 -070010392 if (enable) {
10393 ret = audio_route_apply_and_update_path(adev->audio_route, str);
10394 if (ret) {
10395 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
10396 __func__);
10397 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10398 }
10399 }
10400 else {
10401 ret = audio_route_reset_and_update_path(adev->audio_route, str);
10402 if (ret) {
10403 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
10404 __func__);
10405 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10406 }
10407 }
Kuirong Wang1cad7142016-05-24 15:21:56 -070010408 }
10409 return 0;
10410}
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010411
Vidyakumar Athotaea269c62016-10-31 09:05:59 -070010412void platform_update_aanc_path(struct audio_device *adev,
10413 snd_device_t out_snd_device,
10414 bool enable,
10415 char *str)
10416{
10417 ALOGD("%s: aanc out device(%d) mixer cmd = %s, enable = %d\n",
10418 __func__, out_snd_device, str, enable);
10419
10420 if (enable)
10421 audio_route_apply_and_update_path(adev->audio_route, str);
10422 else
10423 audio_route_reset_and_update_path(adev->audio_route, str);
10424
10425 return;
10426}
10427
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010428#ifdef INSTANCE_ID_ENABLED
10429void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
10430 int acdb_device_type, int app_type, int topology_id,
10431 int sample_rate, uint32_t module_id, uint16_t instance_id,
10432 uint32_t param_id, bool persist)
10433{
10434 int persist_send_flags = 1;
10435
10436 if (!cal) {
10437 return;
10438 }
10439
10440 if (persist)
10441 persist_send_flags |= 0x2;
10442
10443 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
10444
10445 cal->persist = persist;
10446 cal->app_type = app_type;
10447 cal->acdb_dev_id = acdb_dev_id;
10448 cal->sampling_rate = sample_rate;
10449 cal->topo_id = topology_id;
10450 //if module and param id is set to 0, the whole blob will be stored
10451 //or sent to the DSP
10452 cal->module_id = module_id;
10453 cal->instance_id = instance_id;
10454 cal->param_id = param_id;
10455 cal->cal_type = acdb_device_type;
10456}
10457#else
10458void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010459 int acdb_device_type, int app_type, int topology_id,
10460 int sample_rate, uint32_t module_id, uint32_t param_id, bool persist)
10461{
10462 int persist_send_flags = 1;
10463
10464 if (!cal) {
10465 return;
10466 }
10467
10468 if (persist)
10469 persist_send_flags |= 0x2;
10470
10471 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
10472
10473 cal->persist = persist;
10474 cal->app_type = app_type;
10475 cal->acdb_dev_id = acdb_dev_id;
10476 cal->sampling_rate = sample_rate;
10477 cal->topo_id = topology_id;
10478 //if module and param id is set to 0, the whole blob will be stored
10479 //or sent to the DSP
10480 cal->module_id = module_id;
10481 cal->param_id = param_id;
10482 cal->cal_type = acdb_device_type;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010483}
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010484#endif
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010485
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010486int platform_send_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
10487 void* data, int length, bool persist)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010488{
10489 int ret = 0;
10490 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010491
10492 if (!my_data) {
10493 ret = -EINVAL;
10494 goto ERROR_RETURN;
10495 }
Gangadhar Sb0210342019-02-22 17:39:41 +053010496 if ((cal->acdb_dev_id == ACDB_ID_STEREO_SPEAKER_DEVICE) &&
10497 (cal->topo_id == TRUMPET_TOPOLOGY))
10498 audio_extn_ip_hdlr_copp_update_cal_info((void*)cal, data);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010499
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010500 if (my_data->acdb_set_audio_cal) {
10501 // persist audio cal in local cache
10502 if (persist) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010503 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010504 }
10505 // send audio cal to dsp
10506 if (ret == 0) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010507 cal->persist = false;
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010508 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010509 if (persist && (ret != 0)) {
10510 ALOGV("[%s] audio cal stored with success, ignore set cal failure", __func__);
10511 ret = 0;
10512 }
10513 }
10514 }
10515
10516ERROR_RETURN:
10517 return ret;
10518}
10519
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010520int platform_get_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010521 void* data, int* length, bool persist)
10522{
10523 int ret = 0;
10524 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010525
10526 if (!my_data) {
10527 ret = -EINVAL;
10528 goto ERROR_RETURN;
10529 }
10530
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010531 if (my_data->acdb_get_audio_cal) {
10532 // get cal from dsp
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010533 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010534 // get cached cal if prevoius attempt fails and persist flag is set
10535 if ((ret != 0) && persist) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010536 cal->persist = true;
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010537 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010538 }
10539 }
10540
10541ERROR_RETURN:
10542 return ret;
10543}
10544
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010545int platform_store_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010546 void* data, int length)
10547{
10548 int ret = 0;
10549 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010550
10551 if (!my_data) {
10552 ret = -EINVAL;
10553 goto ERROR_RETURN;
10554 }
10555
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010556 if (my_data->acdb_set_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010557 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010558 }
10559
10560ERROR_RETURN:
10561 return ret;
10562}
10563
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010564int platform_retrieve_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010565 void* data, int* length)
10566{
10567 int ret = 0;
10568 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010569
10570 if (!my_data) {
10571 ret = -EINVAL;
10572 goto ERROR_RETURN;
10573 }
10574
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010575 if (my_data->acdb_get_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010576 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010577 }
10578
10579ERROR_RETURN:
10580 return ret;
10581}
Divya Narayanan Poojary45f19192016-09-30 18:52:13 +053010582
10583int platform_get_max_mic_count(void *platform) {
10584 struct platform_data *my_data = (struct platform_data *)platform;
10585 return my_data->max_mic_count;
10586}
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070010587
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010588#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
10589int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
10590 // backup_gain: gain to try to set in case of an error during ramp
10591 int start_gain, end_gain, step, backup_gain, i;
10592 bool error = false;
10593 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
10594 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
10595 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
10596 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
10597 if (!ctl_left || !ctl_right) {
10598 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
10599 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
10600 return -EINVAL;
10601 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
10602 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
10603 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
10604 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
10605 return -EINVAL;
10606 }
10607 if (ramp_up) {
10608 start_gain = 0;
10609 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
10610 step = +1;
10611 backup_gain = end_gain;
10612 } else {
10613 // using same gain on left and right
10614 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
10615 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
10616 end_gain = 0;
10617 step = -1;
10618 backup_gain = start_gain;
10619 }
10620 for (i = start_gain ; i != (end_gain + step) ; i += step) {
10621 if (mixer_ctl_set_value(ctl_left, 0, i)) {
10622 ALOGE("%s: error setting %s to %d during gain ramp",
10623 __func__, mixer_ctl_name_gain_left, i);
10624 error = true;
10625 break;
10626 }
10627 if (mixer_ctl_set_value(ctl_right, 0, i)) {
10628 ALOGE("%s: error setting %s to %d during gain ramp",
10629 __func__, mixer_ctl_name_gain_right, i);
10630 error = true;
10631 break;
10632 }
10633 usleep(1000);
10634 }
10635 if (error) {
10636 // an error occured during the ramp, let's still try to go back to a safe volume
10637 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
10638 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
10639 }
10640 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
10641 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
10642 }
10643 }
10644 return start_gain;
10645}
10646
10647int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
10648{
10649 const char *mixer_ctl_name = "Swap channel";
10650 struct mixer_ctl *ctl;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010651 struct platform_data *my_data = (struct platform_data *)adev->platform;
10652
10653 // forced to set to swap, but device not rotated ... ignore set
10654 if (swap_channels && !my_data->speaker_lr_swap)
10655 return 0;
10656
10657 ALOGV("%s:", __func__);
10658
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010659 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10660 if (!ctl) {
10661 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
10662 return -EINVAL;
10663 }
10664
10665 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
10666 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
10667 return -EINVAL;
10668 }
10669
10670 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
10671 swap_channels?"R --> L":"L --> R");
10672
10673 return 0;
10674}
10675
10676int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
10677{
10678 // only update if there is active pcm playback on speaker
10679 struct platform_data *my_data = (struct platform_data *)adev->platform;
10680
10681 my_data->speaker_lr_swap = swap_channels;
10682
10683 return platform_set_swap_channels(adev, swap_channels);
10684}
10685
10686int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
10687{
10688 // only update if there is active pcm playback on speaker
10689 struct audio_usecase *usecase;
10690 struct listnode *node;
10691
kunleiz43c4a6a2018-05-17 18:01:24 +080010692 //swap channels only for stereo spkr
10693 struct platform_data *my_data = (struct platform_data *)adev->platform;
10694 if (my_data) {
10695 if (!hw_info_is_stereo_spkr(my_data->hw_info)) {
10696 ALOGV("%s: will not swap due to it is not stereo spkr", __func__);
10697 return 0;
10698 }
10699 } else {
10700 ALOGE("%s: failed to allocate platform data", __func__);
10701 return -EINVAL;
10702 }
10703
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010704 // do not swap channels in audio modes with concurrent capture and playback
10705 // as this may break the echo reference
10706 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
10707 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
10708 return 0;
10709 }
10710
10711 list_for_each(node, &adev->usecase_list) {
10712 usecase = node_to_item(node, struct audio_usecase, list);
Sujin Panicker390724d2019-04-26 10:43:36 +053010713 if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010714 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
10715 /*
10716 * If acdb tuning is different for SPEAKER_REVERSE, it is must
10717 * to perform device switch to disable the current backend to
10718 * enable it with new acdb data.
10719 */
kunleiz43c4a6a2018-05-17 18:01:24 +080010720 if (my_data->speaker_lr_swap &&
10721 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
10722 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE])) {
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010723 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
10724 select_devices(adev, usecase->id);
10725 if (initial_skpr_gain != -EINVAL)
10726 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
10727
10728 } else {
10729 platform_set_swap_mixer(adev, swap_channels);
10730 }
10731 break;
10732 }
10733 }
10734
10735 return 0;
10736}
10737
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070010738static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
10739static int num_gain_tbl_entry = 0;
10740
10741bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
10742
10743 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
10744 if (num_gain_tbl_entry == -1) {
10745 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
10746 __func__);
10747 return false;
10748 }
10749
10750 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
10751 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
10752 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
10753 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
10754 return false;
10755 }
10756
10757 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
10758 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
10759 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
10760 return false;
10761 }
10762
10763 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
10764 ++num_gain_tbl_entry;
10765
10766 return true;
10767}
10768
10769int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
10770 int table_size) {
10771 int itt = 0;
10772 ALOGV("platform_get_gain_level_mapping called ");
10773
10774 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
10775 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
10776 return 0;
10777 }
10778
10779 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
10780 mapping_tbl[itt] = tbl_mapping[itt];
10781 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
10782 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
10783 }
10784
10785 return num_gain_tbl_entry;
10786}
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010787
10788int platform_get_max_codec_backend() {
10789
10790 return MAX_CODEC_BACKENDS;
10791}
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +053010792int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
Venugopal Nadipalli83134582017-09-21 22:34:50 +053010793{
10794 int sample_rate;
10795 switch (stream_sr){
10796 case 8000:
10797 case 11025:
10798 case 16000:
10799 case 22050:
10800 case 32000:
10801 case 48000:
10802 sample_rate = 48000;
10803 break;
10804 case 44100:
10805 sample_rate = 44100;
10806 break;
10807 case 64000:
10808 case 96000:
10809 sample_rate = 96000;
10810 break;
10811 case 88200:
10812 sample_rate = 88200;
10813 break;
10814 case 176400:
10815 sample_rate = 176400;
10816 break;
10817 case 192000:
10818 sample_rate = 192000;
10819 break;
10820 case 352800:
10821 sample_rate = 352800;
10822 break;
10823 case 384000:
10824 sample_rate = 384000;
10825 break;
10826 case 144000:
10827 default:
10828 sample_rate = 48000;
10829 break;
10830 }
10831 return sample_rate;
10832}
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070010833
Meng Wangef2f6e12018-10-08 13:06:05 +080010834#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || \
10835 defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \
10836 defined (PLATFORM_KONA) || defined (PLATFORM_MSMSTEPPE) || \
Manisha Agarwal888e9762019-02-27 22:18:49 +053010837 defined (PLATFORM_QCS405) || defined (PLATFORM_TRINKET) || \
Manisha Agarwal13c65ae2019-05-16 10:48:28 +080010838 defined (PLATFORM_LITO) || defined (PLATFORM_MSMFALCON) || \
10839 defined (PLATFORM_ATOLL)
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070010840int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
10841 uint32_t *size)
10842{
10843 struct platform_data *my_data = (struct platform_data *)platform;
10844 struct audio_device *adev = my_data->adev;
10845 int hw_fd = -1;
10846 char dev_name[128];
10847 struct snd_pcm_mmap_fd mmap_fd;
10848 memset(&mmap_fd, 0, sizeof(mmap_fd));
10849 mmap_fd.dir = dir;
10850 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
10851 adev->snd_card, HWDEP_FE_BASE+fe_dev);
10852 hw_fd = open(dev_name, O_RDONLY);
10853 if (hw_fd < 0) {
10854 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
10855 return -1;
10856 }
10857 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
10858 ALOGE("fe hw dep node ioctl failed");
10859 close(hw_fd);
10860 return -1;
10861 }
10862 *fd = mmap_fd.fd;
10863 *size = mmap_fd.size;
10864 close(hw_fd); // mmap_fd should still be valid
10865 return 0;
10866}
10867#else
10868int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused,
10869 int dir __unused, int *fd __unused,
10870 uint32_t *size __unused)
10871{
10872 return -1;
10873}
10874#endif
`Deeraj Soman676c2702017-09-18 19:25:53 +053010875
10876static const char *platform_get_mixer_control(struct mixer_ctl *ctl)
10877{
10878 int id = -1;
10879 const char *id_string = NULL;
10880
10881 if (!ctl) {
10882 ALOGD("%s: mixer ctl not obtained", __func__);
10883 } else {
10884 id = mixer_ctl_get_value(ctl, 0);
10885 if (id >= 0) {
10886 id_string = mixer_ctl_get_enum_string(ctl, id);
10887 }
10888 }
10889
10890 return id_string;
10891}
Naresh Tannirudcb47c52018-06-25 16:23:32 +053010892
10893bool platform_set_microphone_characteristic(void *platform,
10894 struct audio_microphone_characteristic_t mic) {
10895 struct platform_data *my_data = (struct platform_data *)platform;
10896 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
10897 ALOGE("mic number is more than maximum number");
10898 return false;
10899 }
10900 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
10901 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
10902 }
10903 my_data->microphones[my_data->declared_mic_count++] = mic;
10904 return true;
10905}
10906
10907int platform_get_microphones(void *platform,
10908 struct audio_microphone_characteristic_t *mic_array,
10909 size_t *mic_count) {
10910 struct platform_data *my_data = (struct platform_data *)platform;
10911 if (mic_count == NULL) {
10912 return -EINVAL;
10913 }
10914 if (mic_array == NULL) {
10915 return -EINVAL;
10916 }
10917
10918 if (*mic_count == 0) {
10919 *mic_count = my_data->declared_mic_count;
10920 return 0;
10921 }
10922
10923 size_t max_mic_count = *mic_count;
10924 size_t actual_mic_count = 0;
10925 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
10926 mic_array[i] = my_data->microphones[i];
10927 actual_mic_count++;
10928 }
10929 *mic_count = actual_mic_count;
10930 return 0;
10931}
10932
10933bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
10934 const struct mic_info *info) {
10935 struct platform_data *my_data = (struct platform_data *)platform;
10936 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
10937 ALOGE("%s: Sound device not valid", __func__);
10938 return false;
10939 }
10940 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
10941 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
10942 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
10943 my_data->mic_map[in_snd_device].mic_count--;
10944 return false;
10945 }
10946 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
10947 return true;
10948}
10949
10950int platform_get_active_microphones(void *platform, unsigned int channels,
10951 audio_usecase_t uc_id,
10952 struct audio_microphone_characteristic_t *mic_array,
10953 size_t *mic_count) {
10954 struct platform_data *my_data = (struct platform_data *)platform;
10955 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
10956 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
10957 return -EINVAL;
10958 }
10959 size_t max_mic_count = my_data->declared_mic_count;
10960 size_t actual_mic_count = 0;
10961
10962 snd_device_t active_input_snd_device =
Eric Laurent637e2d42018-11-15 12:24:31 -080010963 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053010964 if (active_input_snd_device == SND_DEVICE_NONE) {
10965 ALOGI("%s: No active microphones found", __func__);
10966 goto end;
10967 }
10968
10969 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
10970 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
10971
10972 for (size_t i = 0; i < active_mic_count; i++) {
10973 unsigned int channels_for_active_mic = channels;
10974 if (channels_for_active_mic > m_info[i].channel_count) {
10975 channels_for_active_mic = m_info[i].channel_count;
10976 }
10977 for (size_t j = 0; j < max_mic_count; j++) {
10978 if (strcmp(my_data->microphones[j].device_id,
10979 m_info[i].device_id) == 0) {
10980 mic_array[actual_mic_count] = my_data->microphones[j];
10981 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
10982 mic_array[actual_mic_count].channel_mapping[ch] =
10983 m_info[i].channel_mapping[ch];
10984 }
10985 actual_mic_count++;
10986 break;
10987 }
10988 }
10989 }
10990end:
10991 *mic_count = actual_mic_count;
10992 return 0;
10993}
Naresh Tannirucb5b5782018-10-12 20:42:07 +053010994
10995int platform_get_license_by_product(void *platform __unused,
10996 const char* product_name __unused,
10997 int *product_id __unused,
10998 char* product_license __unused)
Surendar karka30569792018-05-08 12:02:21 +053010999{
11000 return -ENOSYS;
11001}