blob: 3de01b3155de16db5d7ebca05ba84b069b88c8f6 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2013-2019, 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"
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080074#else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +053075#define PLATFORM_INFO_XML_PATH_INTCODEC "/vendor/etc/audio_platform_info_intcodec.xml"
76#define PLATFORM_INFO_XML_PATH_SKUSH "/vendor/etc/audio_platform_info_skush.xml"
Walter Yang319c6fe2017-09-21 17:09:39 +080077#define PLATFORM_INFO_XML_PATH_SKUW "/vendor/etc/audio_platform_info_skuw.xml"
kunleiz291f3412018-09-04 16:04:44 +080078#define PLATFORM_INFO_XML_PATH_QRD "/vendor/etc/audio_platform_info_qrd.xml"
Naresh Tanniru10758b62017-06-05 21:05:53 +053079#define PLATFORM_INFO_XML_PATH "/vendor/etc/audio_platform_info.xml"
80#define MIXER_XML_PATH_AUXPCM "/vendor/etc/mixer_paths_auxpcm.xml"
81#define MIXER_XML_PATH_I2S "/vendor/etc/mixer_paths_i2s.xml"
82#define PLATFORM_INFO_XML_PATH_I2S "/vendor/etc/audio_platform_info_i2s.xml"
Ramu Gottipati54ed9482018-08-21 16:00:22 +053083#define PLATFORM_INFO_XML_PATH_WSA "/vendor/etc/audio_platform_info_wsa.xml"
Dhananjay Kumarb34c5c12018-09-25 16:04:26 +053084#define PLATFORM_INFO_XML_PATH_TDM "/vendor/etc/audio_platform_info_tdm.xml"
Kuirong Wang0b73b3f2016-12-04 12:59:43 -080085#endif
Helen Zeng6a16ad72014-02-23 22:04:44 -080086
vivek mehtaa76401a2015-04-24 14:12:15 -070087#include <linux/msm_audio.h>
Meng Wangef2f6e12018-10-08 13:06:05 +080088#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || \
89 defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \
90 defined (PLATFORM_KONA) || defined (PLATFORM_MSMSTEPPE) || \
Manisha Agarwal888e9762019-02-27 22:18:49 +053091 defined (PLATFORM_QCS405) || defined (PLATFORM_TRINKET) || \
Manisha Agarwal13c65ae2019-05-16 10:48:28 +080092 defined (PLATFORM_LITO) || defined (PLATFORM_MSMFALCON) || \
93 defined (PLATFORM_ATOLL)
94
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070095#include <sound/devdep_params.h>
96#endif
Helen Zeng6a16ad72014-02-23 22:04:44 -080097
Aalique Grahame22e49102018-12-18 14:23:57 -080098#include <resolv.h>
99
Vignesh Kulothungane4039c12019-05-07 15:51:39 -0700100#define QTIME_FREQ_KHZ 19200
101#define IPC_ERROR_DELAY 10000
102
103#define max(a, b) ((a) > (b) ? (a) : (b))
Aalique Grahame22e49102018-12-18 14:23:57 -0800104#define min(a, b) ((a) < (b) ? (a) : (b))
105
106#define TOSTRING_(x) #x
107#define TOSTRING(x) TOSTRING_(x)
108
Eric Laurentb23d5282013-05-14 15:27:20 -0700109#define LIB_ACDB_LOADER "libacdbloader.so"
Walter Yang6f800052014-07-14 16:15:38 -0700110#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -0700111
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +0530112#define FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
113#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024 * 1024)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -0800114#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
115#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
116#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
117
Vikram Panduranga7e784962016-10-27 12:32:30 -0700118
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700119/*
Eric Laurentb23d5282013-05-14 15:27:20 -0700120 * This file will have a maximum of 38 bytes:
121 *
122 * 4 bytes: number of audio blocks
123 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
124 * Maximum 10 * 3 bytes: SAD blocks
125 */
126#define MAX_SAD_BLOCKS 10
127#define SAD_BLOCK_SIZE 3
128
Walter Yang6f800052014-07-14 16:15:38 -0700129#define MAX_CVD_VERSION_STRING_SIZE 100
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530130#define MAX_SND_CARD_STRING_SIZE 100
Walter Yang6f800052014-07-14 16:15:38 -0700131
Eric Laurentb23d5282013-05-14 15:27:20 -0700132/* EDID format ID for LPCM audio */
133#define EDID_FORMAT_LPCM 1
134
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700135/* fallback app type if the default app type from acdb loader fails */
Aalique Grahame22e49102018-12-18 14:23:57 -0800136#define DEFAULT_APP_TYPE_RX_PATH 69936
137#define DEFAULT_APP_TYPE_TX_PATH 69938
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700138
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700139#define SAMPLE_RATE_8KHZ 8000
140#define SAMPLE_RATE_16KHZ 16000
141
Ben Rombergera04fabc2014-11-14 12:16:03 -0800142#define MAX_SET_CAL_BYTE_SIZE 65536
143
Vikram Panduranga6e761cd2016-10-12 16:50:52 -0700144/* Mixer path names */
145#define AFE_SIDETONE_MIXER_PATH "afe-sidetone"
146
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700147#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530148#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800149#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800150#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
151#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
152
Rohit kumarf4120402016-08-05 19:19:48 +0530153#define AUDIO_PARAMETER_KEY_MONO_SPEAKER "mono_speaker"
154
Jhansi Konathala170875c2018-10-11 18:34:10 +0530155#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence_type"
156#define AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL "fluence_voice"
157#define AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC "fluence_voice_rec"
158#define AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC "fluence_audio_rec"
159#define AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER "fluence_speaker"
160#define AUDIO_PARAMETER_KEY_FLUENCE_MODE "fluence_mode"
161#define AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL "fluence_hfp"
162#define AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC "fluence_tri_mic"
163
Sudheer Papothifa9d2282015-09-17 01:53:25 +0530164#define AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS "perf_lock_opts"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800165
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530166/* Reload ACDB files from specified path */
167#define AUDIO_PARAMETER_KEY_RELOAD_ACDB "reload_acdb"
168
Tanya Finkel00130052014-07-14 04:26:56 -0700169/* Query external audio device connection status */
170#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
171
Aalique Grahame37659862017-12-03 22:34:26 -0800172/* Query whether it is ok to select display-port as output
173 * device for voice usecase
174 */
175#define AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE "dp_for_voice"
Weiyin Jiangff72f812018-04-13 15:02:33 +0800176#define AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK "dp_channel_mask"
Surendar Karka45850ae2018-07-02 17:45:27 +0530177#define AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP "spkr_device_chmap"
Aalique Grahame37659862017-12-03 22:34:26 -0800178
Tanya Finkel00130052014-07-14 04:26:56 -0700179#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
180#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
181#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Anish Kumar55e6df22014-08-26 17:38:05 -0700182#define MAX_CAL_NAME 20
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530183#define MAX_MIME_TYPE_LENGTH 30
Aditya Bavanari4875a262019-01-17 19:39:59 +0530184#define MAX_SND_CARD_NAME_LENGTH 100
Anish Kumar55e6df22014-08-26 17:38:05 -0700185
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700186#define GET_IN_DEVICE_INDEX(SND_DEVICE) ((SND_DEVICE) - (SND_DEVICE_IN_BEGIN))
187
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +0530188#ifdef DYNAMIC_LOG_ENABLED
189extern void log_utils_init(void);
190extern void log_utils_deinit(void);
191#endif
192
Anish Kumar55e6df22014-08-26 17:38:05 -0700193char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
194 [WCD9XXX_ANC_CAL] = "anc_cal",
195 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700196 [WCD9XXX_VBAT_CAL] = "vbat_cal",
Anish Kumar55e6df22014-08-26 17:38:05 -0700197};
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530198static char *default_rx_backend = NULL;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800199
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530200#define AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED "is_hw_dec_session_allowed"
201
Naresh Tanniru34a303c2016-01-27 17:26:41 +0530202char dsp_only_decoders_mime[][MAX_MIME_TYPE_LENGTH] = {
Sidipotu Ashok42483b62015-09-08 10:21:44 +0530203 "audio/x-ms-wma" /* wma*/ ,
204 "audio/x-ms-wma-lossless" /* wma lossless */ ,
205 "audio/x-ms-wma-pro" /* wma prop */ ,
206 "audio/amr-wb-plus" /* amr wb plus */ ,
207 "audio/alac" /*alac */ ,
208 "audio/x-ape" /*ape */,
209};
210
211
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800212enum {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530213 VOICE_FEATURE_SET_DEFAULT,
214 VOICE_FEATURE_SET_VOLUME_BOOST
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800215};
sangwoo53b2cf02013-07-25 19:18:44 -0700216
Eric Laurentb23d5282013-05-14 15:27:20 -0700217struct audio_block_header
218{
219 int reserved;
220 int length;
221};
222
vivek mehtaa76401a2015-04-24 14:12:15 -0700223enum {
224 CAL_MODE_SEND = 0x1,
225 CAL_MODE_PERSIST = 0x2,
226 CAL_MODE_RTAC = 0x4
227};
228
Aalique Grahame22e49102018-12-18 14:23:57 -0800229#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
230
231struct operator_info {
232 struct listnode list;
233 char *name;
234 char *mccmnc;
235};
236
237struct operator_specific_device {
238 struct listnode list;
239 char *operator;
240 char *mixer_path;
241 int acdb_id;
242};
243
Carter Hsu32a62362018-10-15 15:01:42 -0700244struct external_specific_device {
245 struct listnode list;
246 char *usbid;
247 int acdb_id;
248};
249
Aalique Grahame22e49102018-12-18 14:23:57 -0800250static struct listnode operator_info_list;
251static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
252
Anish Kumar55e6df22014-08-26 17:38:05 -0700253acdb_loader_get_calibration_t acdb_loader_get_calibration;
Eric Laurentb23d5282013-05-14 15:27:20 -0700254
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800255typedef struct codec_backend_cfg {
256 uint32_t sample_rate;
257 uint32_t bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530258 uint32_t channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +0530259 uint32_t format;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800260 char *bitwidth_mixer_ctl;
261 char *samplerate_mixer_ctl;
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530262 char *channels_mixer_ctl;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800263} codec_backend_cfg_t;
264
Ashish Jain4826f6c2017-02-06 13:33:20 +0530265static native_audio_prop na_props = {0, 0, NATIVE_AUDIO_MODE_INVALID};
Ashish Jainf1eaa582016-05-23 20:54:24 +0530266static bool supports_true_32_bit = false;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530267
Siena Richard7c2db772016-12-21 11:32:34 -0800268static int max_be_dai_names = 0;
269static const struct be_dai_name_struct *be_dai_name_table;
270
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530271struct snd_device_to_mic_map {
272 struct mic_info microphones[AUDIO_MICROPHONE_MAX_COUNT];
273 size_t mic_count;
274};
275
Carter Hsu32a62362018-10-15 15:01:42 -0700276static struct listnode *external_specific_device_table[SND_DEVICE_MAX];
277
Eric Laurentb23d5282013-05-14 15:27:20 -0700278struct platform_data {
279 struct audio_device *adev;
280 bool fluence_in_spkr_mode;
281 bool fluence_in_voice_call;
Aalique Grahame22e49102018-12-18 14:23:57 -0800282 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800284 bool fluence_in_audio_rec;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +0530285 bool fluence_in_hfp_call;
Tanya Finkel00130052014-07-14 04:26:56 -0700286 bool external_spk_1;
287 bool external_spk_2;
288 bool external_mic;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -0700289 bool speaker_lr_swap;
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800290 bool fluence_sb_enabled;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700291 int fluence_type;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800292 int fluence_mode;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530293 char fluence_cap[PROPERTY_VALUE_MAX];
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +0530294 bool ambisonic_capture;
295 bool ambisonic_profile;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700296 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530297 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530298 bool ec_ref_enabled;
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530299 bool is_wsa_speaker;
300 bool hifi_audio;
Aditya Bavanarif2be3c92019-10-11 19:46:43 +0530301 bool is_cls_ab_only_supported;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800302 bool is_i2s_ext_modem;
Ramjee Singh203473b2015-06-09 15:18:42 +0530303 bool is_acdb_initialized;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700304 /* Vbat monitor related flags */
305 bool is_vbat_speaker;
Aditya Bavanari9b589022018-09-20 08:47:55 +0530306 bool is_bcl_speaker;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700307 bool gsm_mode_enabled;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +0530308 bool is_slimbus_interface;
309 bool is_internal_codec;
Rohit kumarf4120402016-08-05 19:19:48 +0530310 int mono_speaker;
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700311 bool voice_speaker_stereo;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700312 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800313 void *acdb_handle;
314 int voice_feature_set;
315 acdb_init_t acdb_init;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530316 acdb_init_v3_t acdb_init_v3;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530317 acdb_init_v4_t acdb_init_v4;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800318 acdb_deallocate_t acdb_deallocate;
319 acdb_send_audio_cal_t acdb_send_audio_cal;
Siena Richard7c2db772016-12-21 11:32:34 -0800320 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +0530321 acdb_send_audio_cal_v4_t acdb_send_audio_cal_v4;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800322 acdb_set_audio_cal_t acdb_set_audio_cal;
323 acdb_get_audio_cal_t acdb_get_audio_cal;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800324 acdb_send_voice_cal_t acdb_send_voice_cal;
325 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700326 acdb_get_default_app_type_t acdb_get_default_app_type;
Ben Rombergerfeca4b82015-07-07 20:40:44 -0700327 acdb_send_common_top_t acdb_send_common_top;
Banajit Goswami20cdd212015-09-11 01:11:30 -0700328 acdb_set_codec_data_t acdb_set_codec_data;
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530329 acdb_reload_t acdb_reload;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530330 acdb_reload_v2_t acdb_reload_v2;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700331 void *hw_info;
vivek mehtaa76401a2015-04-24 14:12:15 -0700332 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800333 struct csd_data *csd;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700334 void *edid_info;
335 bool edid_valid;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700336 int ext_disp_type;
kunleize96916e2018-07-16 16:25:59 +0800337 char ec_ref_mixer_path[MIXER_PATH_MAX_LENGTH];
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800338 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530339 char codec_version[CODEC_VERSION_MAX_LENGTH];
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +0530340 char codec_variant[CODEC_VARIANT_MAX_LENGTH];
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +0530341 int hw_dep_fd;
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +0530342 char cvd_version[MAX_CVD_VERSION_STRING_SIZE];
343 char snd_card_name[MAX_SND_CARD_STRING_SIZE];
Aalique Grahame22e49102018-12-18 14:23:57 -0800344 int max_vol_index;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530345 int source_mic_type;
346 int max_mic_count;
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530347 bool is_dsd_supported;
Preetam Singh Ranawatb0c0dd72016-08-18 00:32:06 +0530348 bool is_asrc_supported;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530349 struct listnode acdb_meta_key_list;
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530350 bool use_generic_handset;
Aditya Bavanari29bcea22017-10-03 20:10:35 +0530351 struct acdb_init_data_v4 acdb_init_data;
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530352 uint32_t declared_mic_count;
353 struct audio_microphone_characteristic_t microphones[AUDIO_MICROPHONE_MAX_COUNT];
354 struct snd_device_to_mic_map mic_map[SND_DEVICE_MAX];
Surendar Karka45850ae2018-07-02 17:45:27 +0530355 struct spkr_device_chmap *spkr_ch_map;
Dieter Luecking5d57def2018-09-07 14:23:37 +0200356 bool use_sprk_default_sample_rate;
Dhananjay Kumar429eb452018-12-10 22:26:53 +0530357 struct listnode custom_mtmx_params_list;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530358 struct listnode custom_mtmx_in_params_list;
Surendar Karka45850ae2018-07-02 17:45:27 +0530359};
Naresh Tannirudcb47c52018-06-25 16:23:32 +0530360
Surendar Karka45850ae2018-07-02 17:45:27 +0530361struct spkr_device_chmap {
362 int num_ch;
363 char chmap[AUDIO_CHANNEL_COUNT_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -0700364};
365
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700366static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700367 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
368 DEEP_BUFFER_PCM_DEVICE},
Vignesh Kulothungana6927272019-02-20 15:17:07 -0800369 [USECASE_AUDIO_PLAYBACK_WITH_HAPTICS] = {AUDIO_HAPTICS_PCM_DEVICE,
370 AUDIO_HAPTICS_PCM_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700371 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700372 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -0700373 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
374 MULTIMEDIA3_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700375 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -0700376 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700377 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
378 MULTIMEDIA2_PCM_DEVICE},
Aalique Grahame22e49102018-12-18 14:23:57 -0800379 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
380 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700381 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
382 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700383 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =
384 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
385 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =
386 {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3},
387 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] =
388 {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4},
389 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] =
390 {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5},
391 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] =
392 {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6},
393 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] =
394 {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7},
395 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] =
396 {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8},
397 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] =
398 {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9},
vivek mehta0ea887a2015-08-26 14:01:20 -0700399
vivek mehta0ea887a2015-08-26 14:01:20 -0700400
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700401 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700402 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530403 [USECASE_AUDIO_RECORD_COMPRESS2] = {-1, -1},
404 [USECASE_AUDIO_RECORD_COMPRESS3] = {-1, -1},
405 [USECASE_AUDIO_RECORD_COMPRESS4] = {-1, -1},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +0530406 [USECASE_AUDIO_RECORD_COMPRESS5] = {-1, -1},
407 [USECASE_AUDIO_RECORD_COMPRESS6] = {-1, -1},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700408 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
409 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700410 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
411 MULTIMEDIA2_PCM_DEVICE},
Haynes Mathew George484e8d22017-07-31 18:55:17 -0700412 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
413 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700414 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800415 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800416 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700417 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
Haynes Mathew George16081042017-05-31 17:16:49 -0700418 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
419 MMAP_PLAYBACK_PCM_DEVICE},
420 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
421 MMAP_RECORD_PCM_DEVICE},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700422 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
423 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
424 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800425 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Vidyakumar Athota0e109352015-02-12 17:38:22 -0800426 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
427 VOICEMMODE1_CALL_PCM_DEVICE},
428 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
429 VOICEMMODE2_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800430 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700431 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
432 AUDIO_RECORD_PCM_DEVICE},
433 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
434 AUDIO_RECORD_PCM_DEVICE},
435 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
436 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800437 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
438 COMPRESS_CAPTURE_DEVICE},
439 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
440 COMPRESS_CAPTURE_DEVICE},
441 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
442 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700443 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
444 INCALL_MUSIC_UPLINK_PCM_DEVICE},
445 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
446 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700447 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
448 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700449
450 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
451 AFE_PROXY_RECORD_PCM_DEVICE},
452 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
453 AFE_PROXY_RECORD_PCM_DEVICE},
Aalique Grahame22e49102018-12-18 14:23:57 -0800454 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530455 [USECASE_AUDIO_PLAYBACK_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
Surendar Karka93cd25a2018-08-28 14:21:37 +0530456 [USECASE_AUDIO_TRANSCODE_LOOPBACK_RX] = {TRANSCODE_LOOPBACK_RX_DEV_ID, -1},
457 [USECASE_AUDIO_TRANSCODE_LOOPBACK_TX] = {-1, TRANSCODE_LOOPBACK_TX_DEV_ID},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700458
Vikram Panduranga93f080e2017-06-07 18:16:14 -0700459 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
460 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, AUDIO_RECORD_VOIP_PCM_DEVICE},
Varun Balaraje49253e2017-07-06 19:48:56 +0530461 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM1] =
462 {PLAYBACK_INTERACTIVE_STRM_DEVICE1, PLAYBACK_INTERACTIVE_STRM_DEVICE1},
463 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM2] =
464 {PLAYBACK_INTERACTIVE_STRM_DEVICE2, PLAYBACK_INTERACTIVE_STRM_DEVICE2},
465 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM3] =
466 {PLAYBACK_INTERACTIVE_STRM_DEVICE3, PLAYBACK_INTERACTIVE_STRM_DEVICE3},
467 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM4] =
468 {PLAYBACK_INTERACTIVE_STRM_DEVICE4, PLAYBACK_INTERACTIVE_STRM_DEVICE4},
469 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM5] =
470 {PLAYBACK_INTERACTIVE_STRM_DEVICE5, PLAYBACK_INTERACTIVE_STRM_DEVICE5},
471 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM6] =
472 {PLAYBACK_INTERACTIVE_STRM_DEVICE6, PLAYBACK_INTERACTIVE_STRM_DEVICE6},
473 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM7] =
474 {PLAYBACK_INTERACTIVE_STRM_DEVICE7, PLAYBACK_INTERACTIVE_STRM_DEVICE7},
475 [USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM8] =
476 {PLAYBACK_INTERACTIVE_STRM_DEVICE8, PLAYBACK_INTERACTIVE_STRM_DEVICE8},
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530477 [USECASE_AUDIO_EC_REF_LOOPBACK] = {-1, -1}, /* pcm id updated from platform info file */
Derek Chenf6318be2017-06-12 17:16:24 -0400478 [USECASE_AUDIO_PLAYBACK_MEDIA] = {MEDIA_PCM_DEVICE,
479 MEDIA_PCM_DEVICE},
480 [USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION] = {SYS_NOTIFICATION_PCM_DEVICE,
481 SYS_NOTIFICATION_PCM_DEVICE},
482 [USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE] = {NAV_GUIDANCE_PCM_DEVICE,
483 NAV_GUIDANCE_PCM_DEVICE},
484 [USECASE_AUDIO_PLAYBACK_PHONE] = {PHONE_PCM_DEVICE,
485 PHONE_PCM_DEVICE},
Rahul Sharma99770982019-03-06 17:05:26 +0530486 [USECASE_AUDIO_FM_TUNER_EXT] = {-1, -1},
Eric Laurentb23d5282013-05-14 15:27:20 -0700487};
488
489/* Array to store sound devices */
490static const char * const device_table[SND_DEVICE_MAX] = {
491 [SND_DEVICE_NONE] = "none",
492 /* Playback sound devices */
493 [SND_DEVICE_OUT_HANDSET] = "handset",
494 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Tanya Finkel00130052014-07-14 04:26:56 -0700495 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
496 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530497 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700498 [SND_DEVICE_OUT_SPEAKER_VBAT] = "speaker-vbat",
Eric Laurentb23d5282013-05-14 15:27:20 -0700499 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Aalique Grahame22e49102018-12-18 14:23:57 -0800500 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700501 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530502 [SND_DEVICE_OUT_HEADPHONES_DSD] = "headphones-dsd",
Ramlal Karra10d22b92019-08-08 19:02:35 +0530503 [SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = "headphones-hifi-filter",
504 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = "speaker-and-headphones-hifi-filter",
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800505 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700506 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700507 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800508 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700509 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Aalique Grahame22e49102018-12-18 14:23:57 -0800510 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Tanya Finkel00130052014-07-14 04:26:56 -0700511 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
512 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700513 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Aalique Grahame22e49102018-12-18 14:23:57 -0800514 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700515 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700516 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = "voice-speaker-stereo",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530517 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700518 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = "voice-speaker-vbat",
Rohit kumarf4120402016-08-05 19:19:48 +0530519 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = "voice-speaker-2",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530520 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = "wsa-voice-speaker-2",
Rohit kumarf4120402016-08-05 19:19:48 +0530521 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = "voice-speaker-2-vbat",
Eric Laurentb23d5282013-05-14 15:27:20 -0700522 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530523 [SND_DEVICE_OUT_VOICE_HEADSET] = "voice-headset",
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700524 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700525 [SND_DEVICE_OUT_HDMI] = "hdmi",
526 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700527 [SND_DEVICE_OUT_DISPLAY_PORT] = "display-port",
528 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = "speaker-and-display-port",
Eric Laurentb23d5282013-05-14 15:27:20 -0700529 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700530 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800531 [SND_DEVICE_OUT_BT_SCO_SWB] = "bt-sco-headset-swb",
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530532 [SND_DEVICE_OUT_BT_A2DP] = "bt-a2dp",
533 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = "speaker-and-bt-a2dp",
Aalique Grahame22e49102018-12-18 14:23:57 -0800534 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = "speaker-safe-and-bt-a2dp",
535 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
Eric Laurentb23d5282013-05-14 15:27:20 -0700536 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
Samyak Jainc9250dc2019-06-14 12:19:28 +0530537 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = "voice-tty-full-headset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700538 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
Samyak Jainc9250dc2019-06-14 12:19:28 +0530539 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = "voice-tty-vco-headset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700540 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700541 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
542 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700543 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Aalique Grahame22e49102018-12-18 14:23:57 -0800544 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700545 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
Ashish Jain3e37a702016-11-25 12:27:15 +0530546 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700547 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
Ashish Jain3e37a702016-11-25 12:27:15 +0530548 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800549 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = "usb-headset",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700550 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700551 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Aalique Grahame22e49102018-12-18 14:23:57 -0800552 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700553 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700554 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
555 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
556 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
557 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530558 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = "voice-speaker-and-voice-headphones",
559 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = "voice-speaker-and-voice-anc-headphones",
560 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = "voice-speaker-and-voice-anc-fb-headphones",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700561 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = "voice-speaker-stereo-and-voice-headphones",
562 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = "voice-speaker-stereo-and-voice-anc-headphones",
563 [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 -0700564 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
Meng Wang841d6c02017-01-24 12:34:36 +0800565 [SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = "speaker-and-anc-fb-headphones",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700566 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700567 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Anish Kumar46c7b872014-09-09 01:49:44 -0700568 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Aalique Grahame22e49102018-12-18 14:23:57 -0800569 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700570 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = "voice-speaker-stereo-protected",
Rohit kumarf4120402016-08-05 19:19:48 +0530571 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = "voice-speaker-2-protected",
Banajit Goswami20cdd212015-09-11 01:11:30 -0700572 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = "speaker-protected-vbat",
573 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = "voice-speaker-protected-vbat",
Rohit kumarf4120402016-08-05 19:19:48 +0530574 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = "voice-speaker-2-protected-vbat",
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -0800575 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = "speaker-protected",
576 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = "speaker-protected-vbat",
kunleizbe6a8442017-08-08 17:11:35 +0800577 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
Aalique Grahame22e49102018-12-18 14:23:57 -0800578 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = "speaker-safe-and-bt-sco",
kunleizbe6a8442017-08-08 17:11:35 +0800579 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800580 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB] = "speaker-and-bt-sco-swb",
Aalique Grahame22e49102018-12-18 14:23:57 -0800581 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = "speaker-safe-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800582 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] = "speaker-safe-and-bt-sco-swb",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530583 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO] = "wsa-speaker-and-bt-sco",
584 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB] = "wsa-speaker-and-bt-sco-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800585 [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB] = "wsa-speaker-and-bt-sco-wb",
juyuchen2d415992018-11-16 14:15:16 +0800586 [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid",
Derek Chenf6318be2017-06-12 17:16:24 -0400587 [SND_DEVICE_OUT_BUS_MEDIA] = "bus-speaker",
588 [SND_DEVICE_OUT_BUS_SYS] = "bus-speaker",
589 [SND_DEVICE_OUT_BUS_NAV] = "bus-speaker",
590 [SND_DEVICE_OUT_BUS_PHN] = "bus-speaker",
Eric Laurentb23d5282013-05-14 15:27:20 -0700591
592 /* Capture sound devices */
593 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800594 [SND_DEVICE_IN_HANDSET_MIC_SB] = "handset-mic",
Tanya Finkel00130052014-07-14 04:26:56 -0700595 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Eric Laurentb23d5282013-05-14 15:27:20 -0700596 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800597 [SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800598 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800599 [SND_DEVICE_IN_HANDSET_MIC_NS_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800600 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800601 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800602 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800603 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800604 [SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800605 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800606 [SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800607 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800608 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800609 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800610 [SND_DEVICE_IN_SPEAKER_MIC_SB] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800611 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800612 [SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800613 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800614 [SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800615 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800616 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800617 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800618 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800619 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800620 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800621 [SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800622 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800623 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800624 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800625 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800626 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700627 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800628 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = "voice-speaker-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700629 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Ralf Herzafb164f2018-07-03 07:08:07 +0200630 [SND_DEVICE_IN_SPDIF] = "spdif-in",
631 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-in",
632 [SND_DEVICE_IN_HDMI_ARC] = "hdmi-arc-in",
Eric Laurentb23d5282013-05-14 15:27:20 -0700633 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700634 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700635 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700636 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Zhou Song12c29502019-03-16 10:37:18 +0800637 [SND_DEVICE_IN_BT_SCO_MIC_SWB] = "bt-sco-mic-swb",
638 [SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = "bt-sco-mic-swb",
Florian Pfister1a84f312018-07-19 14:38:18 +0200639 [SND_DEVICE_IN_BT_A2DP] = "bt-a2dp-cap",
Eric Laurent4b084132018-10-19 17:33:43 -0700640 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700641 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800642 [SND_DEVICE_IN_VOICE_DMIC_SB] = "voice-dmic-ef",
Aalique Grahame22e49102018-12-18 14:23:57 -0800643 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700644 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800645 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = "voice-speaker-dmic-ef",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700646 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = "voice-speaker-tmic",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800647 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800648 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700649 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
650 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
651 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700652 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
653 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700654 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
655
Eric Laurentb23d5282013-05-14 15:27:20 -0700656 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800657 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800658 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
659 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800660 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700661 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700662 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700663 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
664 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
665 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
666 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800667 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Karthikeyan Mani07faa602018-08-20 11:01:32 -0700668 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
669 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
670 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = "usb-headset-mic",
671 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700672 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700673 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -0800674 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700675 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800676 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "handset-stereo-dmic-ef",
677 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700678 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Rohit kumarf4120402016-08-05 19:19:48 +0530679 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = "vi-feedback-mono-1",
680 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = "vi-feedback-mono-2",
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800681 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
682 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
683 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
684 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
685 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700686 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
687 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
688 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
689 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Aalique Grahame22e49102018-12-18 14:23:57 -0800690 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Ben Romberger182c8252016-07-18 16:54:54 -0700691 [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = "quad-mic",
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -0700692 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530693 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = "three-mic",
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530694 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530695 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
696 [SND_DEVICE_IN_HANDSET_TMIC_NS] = "three-mic",
697 [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = "three-mic",
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700698 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = "speaker-tmic",
699 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = "speaker-tmic",
700 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = "speaker-tmic",
Ben Rombergera4d76db2016-10-13 15:26:02 -0700701 [SND_DEVICE_IN_VOICE_REC_TMIC] = "three-mic",
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530702 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
Aalique Grahame97748be2017-10-10 14:32:29 -0700703 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
704 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
705 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
706 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530707 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = "quad-mic",
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +0530708 [SND_DEVICE_IN_INCALL_REC_RX] = "incall-rec-rx",
709 [SND_DEVICE_IN_INCALL_REC_TX] = "incall-rec-tx",
710 [SND_DEVICE_IN_INCALL_REC_RX_TX] = "incall-rec-rx-tx",
Ramu Gottipati813ae982018-07-25 14:14:48 +0530711 [SND_DEVICE_IN_LINE] = "line-in",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530712 [SND_DEVICE_IN_HANDSET_6MIC] = "handset-6mic",
713 [SND_DEVICE_IN_HANDSET_8MIC] = "handset-8mic",
Eric Laurent4b084132018-10-19 17:33:43 -0700714 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = "camcorder-mic",
715 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = "camcorder-mic",
716 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = "camcorder-mic",
717 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = "camcorder-mic",
718 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = "camcorder-mic",
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530719 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
720 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
721 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
juyuchen2d415992018-11-16 14:15:16 +0800722 [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic",
Derek Chenf6318be2017-06-12 17:16:24 -0400723 [SND_DEVICE_IN_BUS] = "bus-mic",
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +0530724 [SND_DEVICE_IN_EC_REF_LOOPBACK] = "ec-ref-loopback",
725 [SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK] = "handset-dmic-and-ec-ref-loopback",
726 [SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK] = "handset-qmic-and-ec-ref-loopback",
727 [SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK] = "handset-6mic-and-ec-ref-loopback",
728 [SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK] = "handset-8mic-and-ec-ref-loopback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700729};
730
Amit Shekhar5a39c912014-10-14 15:39:30 -0700731// Platform specific backend bit width table
732static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
733
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700734static struct audio_effect_config effect_config_table[GET_IN_DEVICE_INDEX(SND_DEVICE_MAX)][EFFECT_MAX] = {
735 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FLUENCE_PROV2, 0x0, 0x10EAF, 0x01},
736 [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 -0700737 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_TM_FLUENCE_PRO_VC, 0x0, 0x10EAF, 0x01},
738 [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 -0700739 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_AEC] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
740 0x10EAF, 0x01},
741 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)][EFFECT_NS] = {TX_VOICE_DM_FV5_BROADSIDE, 0x0,
742 0x10EAF, 0x02},
743 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
744 [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 -0700745 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
746 [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 -0700747 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_TM_FLUENCE_EF, 0x8000, 0x10EAF, 0x01},
748 [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 -0700749 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)][EFFECT_AEC] = {TX_VOICE_FV5ECNS_DM, 0x0, 0x10EAF, 0x01},
750 [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 -0700751 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC)][EFFECT_AEC] = {TX_VOICE_SMECNS_V2, 0x0, 0x10EAF, 0x01},
752 [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 -0800753
Vignesh Kulothungan033fd432019-04-16 18:43:38 -0700754 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
755 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x02},
756 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
757 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x02},
758 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
759 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)][EFFECT_NS] = {TX_VOICE_FLUENCE_MM_SB, 0x8000, 0x10EAF, 0x02},
760 [GET_IN_DEVICE_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)][EFFECT_AEC] = {TX_VOICE_FLUENCE_SM_SB, 0x8000, 0x10EAF, 0x01},
761 [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 -0700762};
763
Eric Laurentb23d5282013-05-14 15:27:20 -0700764/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800765static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700766 [SND_DEVICE_NONE] = -1,
767 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800768 [SND_DEVICE_OUT_SPEAKER] = 14,
Tanya Finkel87af1a52015-03-27 14:54:23 -0700769 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 130,
770 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 130,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530771 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700772 [SND_DEVICE_OUT_SPEAKER_VBAT] = 14,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800773 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800774 [SND_DEVICE_OUT_SPEAKER_SAFE] = 14,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700775 [SND_DEVICE_OUT_LINE] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700776 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530777 [SND_DEVICE_OUT_HEADPHONES_DSD] = 10,
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800778 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700779 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Aalique Grahame22e49102018-12-18 14:23:57 -0800780 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700781 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 10,
Aalique Grahame22e49102018-12-18 14:23:57 -0800782 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 10,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800783 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 130,
784 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 130,
Eric Laurentb23d5282013-05-14 15:27:20 -0700785 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800786 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700787 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = 15,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700788 [SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = 14,
Rohit kumarf4120402016-08-05 19:19:48 +0530789 [SND_DEVICE_OUT_VOICE_SPEAKER_2] = 14,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530790 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
791 [SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = 135,
Rohit kumarf4120402016-08-05 19:19:48 +0530792 [SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800793 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700794 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Samyak Jainfd24f1e2019-04-30 11:58:43 +0530795 [SND_DEVICE_OUT_VOICE_HEADSET] = 10,
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -0700796 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Preetam Singh Ranawat91132162017-03-13 20:32:03 +0530797 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = 10,
798 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = 10,
799 [SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = 10,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700800 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = 10,
801 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = 10,
802 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700803 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800804 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -0700805 [SND_DEVICE_OUT_DISPLAY_PORT] = 18,
806 [SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700807 [SND_DEVICE_OUT_BT_SCO] = 22,
Aalique Grahame22e49102018-12-18 14:23:57 -0800808 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = 14,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700809 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Zhou Song12c29502019-03-16 10:37:18 +0800810 [SND_DEVICE_OUT_BT_SCO_SWB] = 39,
Aalique Grahame22e49102018-12-18 14:23:57 -0800811 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] = 14,
Zhou Song12c29502019-03-16 10:37:18 +0800812 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] = 14,
Naresh Tanniru9d027a62015-03-13 01:32:10 +0530813 [SND_DEVICE_OUT_BT_A2DP] = 20,
814 [SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800815 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = 14,
816 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
Eric Laurentb23d5282013-05-14 15:27:20 -0700817 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
Samyak Jainc9250dc2019-06-14 12:19:28 +0530818 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = 17,
Eric Laurentb23d5282013-05-14 15:27:20 -0700819 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
Samyak Jainc9250dc2019-06-14 12:19:28 +0530820 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = 17,
Eric Laurentb23d5282013-05-14 15:27:20 -0700821 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700822 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
823 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700824 [SND_DEVICE_OUT_VOICE_TX] = 45,
Aalique Grahame22e49102018-12-18 14:23:57 -0800825 [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700826 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800827 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700828 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
Ashish Jain3e37a702016-11-25 12:27:15 +0530829 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Aalique Grahame22e49102018-12-18 14:23:57 -0800830 [SND_DEVICE_OUT_USB_HEADSET_SPEC] = 45,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700831 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700832 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Aalique Grahame22e49102018-12-18 14:23:57 -0800833 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700834 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700835 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700836 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Ramlal Karra10d22b92019-08-08 19:02:35 +0530837 [SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = 188,
838 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] = 188,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700839 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700840 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700841 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
Meng Wang841d6c02017-01-24 12:34:36 +0800842 [SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700843 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Anish Kumar46c7b872014-09-09 01:49:44 -0700844 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
Aalique Grahame22e49102018-12-18 14:23:57 -0800845 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = 14,
Anish Kumar46c7b872014-09-09 01:49:44 -0700846 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530847 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = 101,
Banajit Goswami20cdd212015-09-11 01:11:30 -0700848 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = 124,
849 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = 101,
Rohit kumarf4120402016-08-05 19:19:48 +0530850 [SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = 101,
Vikram Panduranga8c68e862018-04-27 12:59:42 -0700851 [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = 124,
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -0800852 [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = 134,
853 [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = 134,
juyuchen2d415992018-11-16 14:15:16 +0800854 [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45,
Derek Chenf6318be2017-06-12 17:16:24 -0400855 [SND_DEVICE_OUT_BUS_MEDIA] = 78,
856 [SND_DEVICE_OUT_BUS_SYS] = 78,
857 [SND_DEVICE_OUT_BUS_NAV] = 14,
858 [SND_DEVICE_OUT_BUS_PHN] = 94,
Eric Laurentb23d5282013-05-14 15:27:20 -0700859 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800860 [SND_DEVICE_IN_HANDSET_MIC_SB] = 163,
Tanya Finkel00130052014-07-14 04:26:56 -0700861 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800862 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800863 [SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = 164,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800864 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800865 [SND_DEVICE_IN_HANDSET_MIC_NS_SB] = 165,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800866 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800867 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = 166,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800868 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800869 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800870 [SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = 168,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800871 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800872 [SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = 169,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800873 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800874 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = 170,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800875 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800876 [SND_DEVICE_IN_SPEAKER_MIC_SB] = 171,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800877 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800878 [SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = 172,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800879 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800880 [SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = 173,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800881 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800882 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = 174,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800883 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800884 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800885 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = 176,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800886 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800887 [SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = 177,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800888 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800889 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = 178,
Eric Laurentb23d5282013-05-14 15:27:20 -0700890 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Aalique Grahame22e49102018-12-18 14:23:57 -0800891 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800892 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700893 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800894 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = 171,
Aalique Grahame22e49102018-12-18 14:23:57 -0800895 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Eric Laurentb23d5282013-05-14 15:27:20 -0700896 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
Ralf Herz76b455c2018-09-10 13:58:04 +0200897 [SND_DEVICE_IN_SPDIF] = 143,
898 [SND_DEVICE_IN_HDMI_MIC] = 143,
899 [SND_DEVICE_IN_HDMI_ARC] = 143,
Eric Laurentb23d5282013-05-14 15:27:20 -0700900 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700901 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700902 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700903 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Zhou Song12c29502019-03-16 10:37:18 +0800904 [SND_DEVICE_IN_BT_SCO_MIC_SWB] = 38,
905 [SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = 123,
Florian Pfister1a84f312018-07-19 14:38:18 +0200906 [SND_DEVICE_IN_BT_A2DP] = 21,
Eric Laurent4b084132018-10-19 17:33:43 -0700907 [SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700908 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800909 [SND_DEVICE_IN_VOICE_DMIC_SB] = 167,
Aalique Grahame22e49102018-12-18 14:23:57 -0800910 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700911 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -0800912 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = 175,
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700913 [SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = 161,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800914 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700915 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
916 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
917 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Aniket Kumar Lata91886592017-05-25 16:53:32 -0700918 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
919 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700920 [SND_DEVICE_IN_VOICE_RX] = 44,
921
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800922 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800923 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Aalique Grahame22e49102018-12-18 14:23:57 -0800924 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
925 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800926 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
927 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Aalique Grahame22e49102018-12-18 14:23:57 -0800928 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = 8,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700929 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -0700930 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
931 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
932 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
933 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Karthikeyan Mani07faa602018-08-20 11:01:32 -0700934 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
935 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
936 [SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = 162,
937 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = 162,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700938 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700939 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -0800940 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700941 [SND_DEVICE_IN_QUAD_MIC] = 46,
Aalique Grahame22e49102018-12-18 14:23:57 -0800942 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
943 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700944 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Rohit kumarf4120402016-08-05 19:19:48 +0530945 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = 102,
946 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = 102,
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800947 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
948 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
949 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
950 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
951 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700952 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Aalique Grahame22e49102018-12-18 14:23:57 -0800953 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700954 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
955 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
956 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Ben Romberger182c8252016-07-18 16:54:54 -0700957 [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = 125,
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +0530958 [SND_DEVICE_IN_THREE_MIC] = 46, /* for APSS Surround Sound Recording */
Vikram Pandurangab1e26aa2018-06-21 17:28:20 -0700959 [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = 138,
Aditya Bavanari4051c8d2017-12-13 13:31:26 +0530960 [SND_DEVICE_IN_HANDSET_TMIC] = 153,
961 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 154,
962 [SND_DEVICE_IN_HANDSET_TMIC_NS] = 155,
963 [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = 156,
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -0700964 [SND_DEVICE_IN_SPEAKER_TMIC_AEC] = 158,
965 [SND_DEVICE_IN_SPEAKER_TMIC_NS] = 159,
966 [SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = 160,
Ben Rombergera4d76db2016-10-13 15:26:02 -0700967 [SND_DEVICE_IN_VOICE_REC_TMIC] = 125,
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +0530968 [SND_DEVICE_IN_UNPROCESSED_MIC] = 143,
969 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 144,
970 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 145,
971 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 146,
972 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = 147,
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +0530973 [SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = 150,
Ramu Gottipati813ae982018-07-25 14:14:48 +0530974 [SND_DEVICE_IN_LINE] = 4,
Sujin Panickerb904fbe2019-04-04 13:28:07 +0530975 [SND_DEVICE_IN_HANDSET_6MIC] = 4,
976 [SND_DEVICE_IN_HANDSET_8MIC] = 4,
977 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
978 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
979 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
Eric Laurent4b084132018-10-19 17:33:43 -0700980 [SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = 4,
981 [SND_DEVICE_IN_CAMCORDER_PORTRAIT] = 4,
982 [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 4,
983 [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 4,
984 [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 4,
juyuchen2d415992018-11-16 14:15:16 +0800985 [SND_DEVICE_IN_VOICE_HEARING_AID] = 44,
Derek Chenf6318be2017-06-12 17:16:24 -0400986 [SND_DEVICE_IN_BUS] = 11,
Eric Laurentb23d5282013-05-14 15:27:20 -0700987};
988
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700989struct name_to_index {
Ben Romberger61764e32014-01-10 13:49:02 -0800990 char name[100];
991 unsigned int index;
992};
993
994#define TO_NAME_INDEX(X) #X, X
995
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800996/* Used to get index from parsed string */
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700997static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Ben Romberger61764e32014-01-10 13:49:02 -0800998 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
999 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Tanya Finkel00130052014-07-14 04:26:56 -07001000 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
1001 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301002 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001003 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_VBAT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001004 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001005 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001006 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05301007 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_DSD)},
Ramlal Karra10d22b92019-08-08 19:02:35 +05301008 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)},
1009 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER)},
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08001010 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001011 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001012 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001013 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001014 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001015 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Tanya Finkel00130052014-07-14 04:26:56 -07001016 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
1017 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -08001018 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
1019 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05301020 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301021 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001022 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001023 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +05301024 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301025 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)},
Rohit kumarf4120402016-08-05 19:19:48 +05301026 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001027 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Samyak Jainfd24f1e2019-04-30 11:58:43 +05301028 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADSET)},
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07001029 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001030 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
1031 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07001032 {TO_NAME_INDEX(SND_DEVICE_OUT_DISPLAY_PORT)},
1033 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT)},
Ben Romberger61764e32014-01-10 13:49:02 -08001034 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001035 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001036 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001037 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_SWB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001038 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001039 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB)},
Naresh Tanniru9d027a62015-03-13 01:32:10 +05301040 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_A2DP)},
1041 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001042 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)},
1043 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
1044 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001045 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
Samyak Jainc9250dc2019-06-14 12:19:28 +05301046 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001047 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
Samyak Jainc9250dc2019-06-14 12:19:28 +05301048 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001049 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
kunleizbe6a8442017-08-08 17:11:35 +08001050 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
1051 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001052 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301053 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO)},
1054 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB)},
Zhou Song12c29502019-03-16 10:37:18 +08001055 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB)},
Aniket Kumar Lata91886592017-05-25 16:53:32 -07001056 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
1057 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301058 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Ben Romberger61764e32014-01-10 13:49:02 -08001059 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
1060 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001061 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
Ashish Jain3e37a702016-11-25 12:27:15 +05301062 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001063 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
Ben Romberger61764e32014-01-10 13:49:02 -08001064 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001065 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
1066 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET_SPEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001067 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
1068 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
1069 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
1070 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
1071 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
1072 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
Meng Wang841d6c02017-01-24 12:34:36 +08001073 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET)},
Ben Romberger61764e32014-01-10 13:49:02 -08001074 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
1075 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Anish Kumar46c7b872014-09-09 01:49:44 -07001076 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Rohit kumarf4120402016-08-05 19:19:48 +05301077 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED)},
Vikram Panduranga8c68e862018-04-27 12:59:42 -07001078 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED)},
Banajit Goswami20cdd212015-09-11 01:11:30 -07001079 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT)},
1080 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT)},
Rohit kumarf4120402016-08-05 19:19:48 +05301081 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT)},
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08001082 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS)},
1083 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301084 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
1085 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
1086 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
juyuchen2d415992018-11-16 14:15:16 +08001087 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)},
Derek Chenf6318be2017-06-12 17:16:24 -04001088 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_MEDIA)},
1089 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_SYS)},
1090 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_NAV)},
1091 {TO_NAME_INDEX(SND_DEVICE_OUT_BUS_PHN)},
Ben Romberger61764e32014-01-10 13:49:02 -08001092 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001093 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)},
Tanya Finkel00130052014-07-14 04:26:56 -07001094 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Ben Romberger61764e32014-01-10 13:49:02 -08001095 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001096 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001097 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001098 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001099 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001100 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001101 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
1102 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001103 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001104 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001105 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001106 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001107 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001108 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001109 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001110 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001111 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001112 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001113 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001114 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001115 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001116 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
1117 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001118 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001119 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001120 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_SB)},
Ben Romberger61764e32014-01-10 13:49:02 -08001121 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001122 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001123 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001124 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001125 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001126 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
1127 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001128 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001129 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ben Romberger61764e32014-01-10 13:49:02 -08001130 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Ralf Herzafb164f2018-07-03 07:08:07 +02001131 {TO_NAME_INDEX(SND_DEVICE_IN_SPDIF)},
Ben Romberger61764e32014-01-10 13:49:02 -08001132 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
Ralf Herzafb164f2018-07-03 07:08:07 +02001133 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_ARC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001134 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001135 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001136 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07001137 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Zhou Song12c29502019-03-16 10:37:18 +08001138 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB)},
1139 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC)},
Florian Pfister1a84f312018-07-19 14:38:18 +02001140 {TO_NAME_INDEX(SND_DEVICE_IN_BT_A2DP)},
Eric Laurent4b084132018-10-19 17:33:43 -07001141 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_LANDSCAPE)},
Ben Romberger61764e32014-01-10 13:49:02 -08001142 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001143 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_SB)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001144 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
Ben Romberger61764e32014-01-10 13:49:02 -08001145 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08001146 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001147 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_TMIC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001148 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
1149 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
1150 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
1151 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Aniket Kumar Lata91886592017-05-25 16:53:32 -07001152 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
1153 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001154 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
1155 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001156 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
1157 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ben Romberger61764e32014-01-10 13:49:02 -08001158 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
1159 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001160 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301161 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Ben Romberger61764e32014-01-10 13:49:02 -08001162 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07001163 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
1164 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
1165 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
1166 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001167 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC)},
1168 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC)},
1169 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC)},
1170 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001171 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
1172 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -08001173 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Ben Romberger61764e32014-01-10 13:49:02 -08001174 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001175 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
1176 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
Ben Romberger61764e32014-01-10 13:49:02 -08001177 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Rohit kumarf4120402016-08-05 19:19:48 +05301178 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1)},
1179 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2)},
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001180 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
1181 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
1182 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
1183 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
1184 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001185 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001186 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001187 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
juyuchen2d415992018-11-16 14:15:16 +08001188 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07001189 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
1190 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Ben Romberger182c8252016-07-18 16:54:54 -07001191 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301192 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05301193 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO)},
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05301194 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05301195 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
1196 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_NS)},
1197 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)},
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07001198 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC)},
1199 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_NS)},
1200 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS)},
Ben Rombergera4d76db2016-10-13 15:26:02 -07001201 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_TMIC)},
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05301202 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
1203 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
1204 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
1205 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
1206 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301207 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC)},
1208 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC)},
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05301209 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_GENERIC_QMIC)},
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05301210 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX)},
1211 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_TX)},
1212 {TO_NAME_INDEX(SND_DEVICE_IN_INCALL_REC_RX_TX)},
Ramu Gottipati813ae982018-07-25 14:14:48 +05301213 {TO_NAME_INDEX(SND_DEVICE_IN_LINE)},
Eric Laurent4b084132018-10-19 17:33:43 -07001214 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE)},
1215 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_PORTRAIT)},
1216 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE)},
1217 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE)},
1218 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT)},
1219 /* For legacy xml file parsing */
1220 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Derek Chenf6318be2017-06-12 17:16:24 -04001221 {TO_NAME_INDEX(SND_DEVICE_IN_BUS)},
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05301222 {TO_NAME_INDEX(SND_DEVICE_IN_EC_REF_LOOPBACK)},
1223 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK)},
1224 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK)},
1225 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK)},
1226 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK)},
Ben Romberger61764e32014-01-10 13:49:02 -08001227};
1228
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05301229static char * backend_tag_table[SND_DEVICE_MAX] = {0};
1230static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001231
1232static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
1233 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
Vignesh Kulothungana6927272019-02-20 15:17:07 -08001234 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_WITH_HAPTICS)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001235 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001236 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
1237 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
Ravi Kumar Alamanda474de5a2015-06-25 20:08:01 -07001238 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001239 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
1240 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Alexy Joseph2f89cfa2014-10-06 12:15:01 -07001241 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
1242 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
1243 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
1244 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
1245 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
1246 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
1247 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
1248 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
Haynes Mathew George16081042017-05-31 17:16:49 -07001249 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001250 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301251 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS)},
1252 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS2)},
1253 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS3)},
1254 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS4)},
Dhananjay Kumar376e38b2017-09-28 22:26:23 +05301255 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS5)},
1256 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_COMPRESS6)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001257 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Haynes Mathew George16081042017-05-31 17:16:49 -07001258 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001259 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001260 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
1261 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
1262 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
1263 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
1264 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
Shiv Maliyappanahallif2d2a492016-05-11 22:03:47 -07001265 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
1266 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001267 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
1268 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
1269 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
1270 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +05301271 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO_WB)},
Shiv Maliyappanahallie236ff02016-05-26 11:47:48 -07001272 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_FM)},
1273 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_FM_VIRTUAL)},
Stephen Oglesbyf8a7bf92016-05-11 14:23:16 -07001274 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
1275 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
Garmond Leunge1e8c762016-06-27 16:35:15 -07001276 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
1277 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
Aalique Grahame22e49102018-12-18 14:23:57 -08001278 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05301279 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SILENCE)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301280 {TO_NAME_INDEX(USECASE_AUDIO_EC_REF_LOOPBACK)},
Arun Mirpurie5c697c2018-07-17 17:58:17 -07001281 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301282 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK2)},
Aniket Kumar Lata7fd86e12018-02-20 19:26:10 -08001283 {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
kunleiz6f796ac2018-07-16 17:03:59 +08001284 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
1285 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Surendar Karka93cd25a2018-08-28 14:21:37 +05301286 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_RX)},
1287 {TO_NAME_INDEX(USECASE_AUDIO_TRANSCODE_LOOPBACK_TX)},
Derek Chenf6318be2017-06-12 17:16:24 -04001288 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MEDIA)},
1289 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION)},
1290 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE)},
1291 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_PHONE)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001292};
1293
Aalique Grahame22e49102018-12-18 14:23:57 -08001294static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
1295 {TO_NAME_INDEX(PCM_PLAYBACK)},
1296 {TO_NAME_INDEX(PCM_CAPTURE)},
1297 {TO_NAME_INDEX(VOICE_CALL)},
1298 {TO_NAME_INDEX(PCM_HFP_CALL)},
1299};
1300
1301struct app_type_entry {
1302 int uc_type;
1303 int bit_width;
1304 int app_type;
1305 int max_rate;
1306 char *mode;
1307 struct listnode node; // membership in app_type_entry_list;
1308};
1309
1310static struct listnode app_type_entry_list;
1311
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001312#define NO_COLS 2
1313#ifdef PLATFORM_APQ8084
1314static int msm_device_to_be_id [][NO_COLS] = {
1315 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1316 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1317 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
1318 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
1319 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1320 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1321 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1322 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1323 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1324 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1325 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1326 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1327 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1328 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1329 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301330 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001331 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1332 {AUDIO_DEVICE_OUT_PROXY , 9},
1333 {AUDIO_DEVICE_OUT_FM , 7},
1334 {AUDIO_DEVICE_OUT_FM_TX , 8},
1335 {AUDIO_DEVICE_OUT_ALL , -1},
1336 {AUDIO_DEVICE_NONE , -1},
1337 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1338};
1339#elif PLATFORM_MSM8994
1340static int msm_device_to_be_id [][NO_COLS] = {
1341 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1342 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1343 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
1344 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
1345 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 38},
1346 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 38},
1347 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 38},
1348 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1349 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1350 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1351 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1352 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1353 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1354 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1355 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301356 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001357 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1358 {AUDIO_DEVICE_OUT_PROXY , 9},
1359/* Add the correct be ids */
1360 {AUDIO_DEVICE_OUT_FM , 7},
1361 {AUDIO_DEVICE_OUT_FM_TX , 8},
1362 {AUDIO_DEVICE_OUT_ALL , -1},
1363 {AUDIO_DEVICE_NONE , -1},
1364 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1365};
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001366#elif PLATFORM_MSM8996
1367static int msm_device_to_be_id [][NO_COLS] = {
1368 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1369 {AUDIO_DEVICE_OUT_SPEAKER , 2},
Sharad Sangle1f705a72016-10-05 20:01:39 +05301370 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1371 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001372 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1373 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1374 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1375 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1376 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1377 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1378 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1379 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1380 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1381 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1382 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301383 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -07001384 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1385 {AUDIO_DEVICE_OUT_PROXY , 9},
1386/* Add the correct be ids */
1387 {AUDIO_DEVICE_OUT_FM , 7},
1388 {AUDIO_DEVICE_OUT_FM_TX , 8},
1389 {AUDIO_DEVICE_OUT_ALL , -1},
1390 {AUDIO_DEVICE_NONE , -1},
1391 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1392};
Weiyin Jiang6f4c8062016-11-23 15:30:29 +08001393#elif PLATFORM_MSM8998
1394static int msm_device_to_be_id [][NO_COLS] = {
1395 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1396 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1397 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1398 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
1399 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1400 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1401 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1402 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1403 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1404 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1405 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1406 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1407 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1408 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1409 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05301410 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
Weiyin Jiang6f4c8062016-11-23 15:30:29 +08001411 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1412 {AUDIO_DEVICE_OUT_PROXY , 9},
1413/* Add the correct be ids */
1414 {AUDIO_DEVICE_OUT_FM , 7},
1415 {AUDIO_DEVICE_OUT_FM_TX , 8},
1416 {AUDIO_DEVICE_OUT_ALL , -1},
1417 {AUDIO_DEVICE_NONE , -1},
1418 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1419};
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301420#elif defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1421static int (*msm_device_to_be_id)[];
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001422#else
1423static int msm_device_to_be_id [][NO_COLS] = {
1424 {AUDIO_DEVICE_NONE, -1},
1425};
1426#endif
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301427
1428#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1429static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
1430 {AUDIO_DEVICE_OUT_EARPIECE , 34},
1431 {AUDIO_DEVICE_OUT_SPEAKER , 34},
1432 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
1433 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
1434 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1435 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1436 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1437 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1438 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1439 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1440 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1441 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1442 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1443 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1444 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
1445 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
1446 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1447 {AUDIO_DEVICE_OUT_PROXY , 9},
1448 {AUDIO_DEVICE_OUT_FM , 7},
1449 {AUDIO_DEVICE_OUT_FM_TX , 8},
1450 {AUDIO_DEVICE_OUT_ALL , -1},
1451 {AUDIO_DEVICE_NONE , -1},
1452 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1453};
1454
1455static int msm_device_to_be_id_external_codec [][NO_COLS] = {
1456 {AUDIO_DEVICE_OUT_EARPIECE , 2},
1457 {AUDIO_DEVICE_OUT_SPEAKER , 2},
1458 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 41},
1459 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 41},
1460 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
1461 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
1462 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
1463 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
1464 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
1465 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
1466 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
1467 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
1468 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
1469 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
1470 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
1471 {AUDIO_DEVICE_OUT_USB_HEADSET , -1},
1472 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
1473 {AUDIO_DEVICE_OUT_PROXY , 9},
1474 {AUDIO_DEVICE_OUT_FM , 7},
1475 {AUDIO_DEVICE_OUT_FM_TX , 8},
1476 {AUDIO_DEVICE_OUT_ALL , -1},
1477 {AUDIO_DEVICE_NONE , -1},
1478 {AUDIO_DEVICE_OUT_DEFAULT , -1},
1479};
1480#endif
1481
1482#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
1483static int msm_be_id_array_len;
1484#else
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001485static int msm_be_id_array_len =
1486 sizeof(msm_device_to_be_id) / sizeof(msm_device_to_be_id[0]);
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301487#endif
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001488
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001489#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
Ashish Jain5106d362016-05-11 19:23:33 +05301490#define PCM_OFFLOAD_PLATFORM_DELAY (30*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001491#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Aalique Grahame22e49102018-12-18 14:23:57 -08001492#define ULL_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George16081042017-05-31 17:16:49 -07001493#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001494
Aalique Grahame22e49102018-12-18 14:23:57 -08001495static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
1496static bool is_tmus = false;
1497
Carter Hsu32a62362018-10-15 15:01:42 -07001498static bool is_usb_snd_dev(snd_device_t snd_device)
1499{
1500 if (snd_device < SND_DEVICE_IN_BEGIN) {
1501 if (snd_device == SND_DEVICE_OUT_USB_HEADSET ||\
1502 snd_device == SND_DEVICE_OUT_USB_HEADPHONES ||\
1503 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADPHONES ||\
1504 snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET ||\
1505 snd_device == SND_DEVICE_OUT_VOICE_TTY_FULL_USB ||\
1506 snd_device == SND_DEVICE_OUT_VOICE_TTY_VCO_USB)
1507 return true;
1508 } else {
1509 if (snd_device == SND_DEVICE_IN_USB_HEADSET_MIC ||\
1510 snd_device == SND_DEVICE_IN_USB_HEADSET_MIC_AEC ||\
1511 snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC ||\
1512 snd_device == SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC ||\
1513 snd_device == SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)
1514 return true;
1515 }
1516 return false;
1517}
1518
Aalique Grahame22e49102018-12-18 14:23:57 -08001519static void check_operator()
1520{
1521 char value[PROPERTY_VALUE_MAX];
1522 int mccmnc;
1523 property_get("gsm.sim.operator.numeric",value,"0");
1524 mccmnc = atoi(value);
1525 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
1526 switch(mccmnc) {
1527 /* TMUS MCC(310), MNC(490, 260, 026) */
1528 case 310490:
1529 case 310260:
1530 case 310026:
1531 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
1532 case 310800:
1533 case 310660:
1534 case 310580:
1535 case 310310:
1536 case 310270:
1537 case 310250:
1538 case 310240:
1539 case 310230:
1540 case 310220:
1541 case 310210:
1542 case 310200:
1543 case 310160:
1544 is_tmus = true;
1545 break;
1546 }
1547}
1548
1549bool is_operator_tmus()
1550{
1551 pthread_once(&check_op_once_ctl, check_operator);
1552 return is_tmus;
1553}
1554
1555static char *get_current_operator()
1556{
1557 struct listnode *node;
1558 struct operator_info *info_item;
1559 char mccmnc[PROPERTY_VALUE_MAX];
1560 char *ret = NULL;
1561
1562 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
1563
1564 list_for_each(node, &operator_info_list) {
1565 info_item = node_to_item(node, struct operator_info, list);
1566 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
1567 ret = info_item->name;
1568 }
1569 }
1570
1571 return ret;
1572}
1573
1574static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
1575{
1576 struct listnode *node;
1577 struct operator_specific_device *ret = NULL;
1578 struct operator_specific_device *device_item;
1579 char *operator_name;
1580
1581 operator_name = get_current_operator();
1582 if (operator_name == NULL)
1583 return ret;
1584
1585 list_for_each(node, operator_specific_device_table[snd_device]) {
1586 device_item = node_to_item(node, struct operator_specific_device, list);
1587 if (strcmp(operator_name, device_item->operator) == 0) {
1588 ret = device_item;
1589 }
1590 }
1591
1592 return ret;
1593}
1594
1595static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
1596{
1597 struct operator_specific_device *device;
1598 int ret = acdb_device_table[snd_device];
1599
1600 device = get_operator_specific_device(snd_device);
1601 if (device != NULL)
1602 ret = device->acdb_id;
1603
1604 return ret;
1605}
1606
Carter Hsu32a62362018-10-15 15:01:42 -07001607static int get_external_specific_device_acdb_id(snd_device_t snd_device)
1608{
1609 struct external_specific_device *ext_dev;
1610 int ret = acdb_device_table[snd_device];
1611 char *usbid = NULL;
1612 struct listnode *node;
1613
1614 if (is_usb_snd_dev(snd_device))
1615 usbid = audio_extn_usb_usbid();
1616
1617 if (usbid) {
1618 list_for_each(node, external_specific_device_table[snd_device]) {
1619 ext_dev = node_to_item(node, struct external_specific_device, list);
1620 if (ext_dev->usbid && !strcmp(usbid, ext_dev->usbid)) {
1621 ret = ext_dev->acdb_id;
1622 break;
1623 }
1624 }
1625
1626 free(usbid);
1627 }
1628 return ret;
1629}
1630
Aalique Grahame22e49102018-12-18 14:23:57 -08001631static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
1632{
1633 struct operator_specific_device *device;
1634 const char *ret = device_table[snd_device];
1635
1636 device = get_operator_specific_device(snd_device);
1637 if (device != NULL)
1638 ret = device->mixer_path;
1639
1640 return ret;
1641}
1642
Meng Wangef2f6e12018-10-08 13:06:05 +08001643static void update_codec_type_and_interface(struct platform_data * my_data,
1644 const char *snd_card_name)
1645{
Walter Yang319c6fe2017-09-21 17:09:39 +08001646 if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
1647 sizeof("sdm670-skuw-snd-card")) ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301648 !strncmp(snd_card_name, "sdm660-snd-card",
1649 sizeof("sdm660-snd-card")) ||
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301650 !strncmp(snd_card_name, "sdm660-snd-card-skush",
Walter Yang319c6fe2017-09-21 17:09:39 +08001651 sizeof("sdm660-snd-card-skush")) ||
Walter Yang725a57f2017-11-03 14:32:49 +08001652 !strncmp(snd_card_name, "sdm670-360cam-snd-card",
1653 sizeof("sdm670-360cam-snd-card")) ||
Walter Yang319c6fe2017-09-21 17:09:39 +08001654 !strncmp(snd_card_name, "sdm660-snd-card-mtp",
1655 sizeof("sdm660-snd-card-mtp")) ||
Sharad Sangle999cf722017-10-18 18:25:47 +05301656 !strncmp(snd_card_name, "sdm670-mtp-snd-card",
Naresh Tanniruc21e2022018-08-13 21:58:06 +05301657 sizeof("sdm670-mtp-snd-card")) ||
Xiaojun Sangfcddd672018-08-15 17:53:48 +08001658 !strncmp(snd_card_name, "sm6150-qrd-snd-card",
1659 sizeof("sm6150-qrd-snd-card")) ||
Naresh Tanniruc21e2022018-08-13 21:58:06 +05301660 !strncmp(snd_card_name, "sm6150-idp-snd-card",
Naresh Tannirucb5b5782018-10-12 20:42:07 +05301661 sizeof("sm6150-idp-snd-card")) ||
Sachin Mohan Gadageffd7562018-02-13 17:10:09 +05301662 !strncmp(snd_card_name, "qcs605-lc-snd-card",
Meng Wangef2f6e12018-10-08 13:06:05 +08001663 sizeof("qcs605-lc-snd-card")) ||
1664 !strncmp(snd_card_name, "kona-mtp-snd-card",
1665 sizeof("kona-mtp-snd-card")) ||
1666 !strncmp(snd_card_name, "kona-qrd-snd-card",
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05301667 sizeof("kona-qrd-snd-card")) ||
Vatsal Bucha6339b092019-04-17 16:27:32 +05301668 !strncmp(snd_card_name, "lito-mtp-snd-card",
1669 sizeof("lito-mtp-snd-card")) ||
1670 !strncmp(snd_card_name, "lito-qrd-snd-card",
1671 sizeof("lito-qrd-snd-card")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05301672 !strncmp(snd_card_name, "trinket-idp-snd-card",
Sujin Panickerb904fbe2019-04-04 13:28:07 +05301673 sizeof("trinket-idp-snd-card")) ||
1674 !strncmp(snd_card_name, "sdm439-sku1-snd-card",
1675 sizeof("sdm439-sku1-snd-card")) ||
1676 !strncmp(snd_card_name, "sdm439-snd-card-mtp",
kunleiz3ae92e52019-04-28 15:35:31 +08001677 sizeof("sdm439-snd-card-mtp")) ||
1678 !strncmp(snd_card_name, "sm6150-wcd9375qrd-snd-card",
Aditya Bavanari4dbceed2018-10-11 18:31:55 +05301679 sizeof("sm6150-wcd9375qrd-snd-card")) ||
1680 !strncmp(snd_card_name, "sm6150-wcd9375-snd-card",
Faiz Nabi Kuchay536d7b92019-08-05 20:36:31 +05301681 sizeof("sm6150-wcd9375-snd-card")) ||
1682 !strncmp(snd_card_name, "atoll-wcd937x-snd-card",
1683 sizeof("atoll-wcd937x-snd-card")) ||
1684 !strncmp(snd_card_name, "atoll-idp-snd-card",
Kunlei Zhangb526fb02019-08-16 16:41:28 +08001685 sizeof("atoll-idp-snd-card")) ||
1686 !strncmp(snd_card_name, "atoll-qrd-snd-card",
1687 sizeof("atoll-qrd-snd-card"))) {
Aditya Bavanari4dbceed2018-10-11 18:31:55 +05301688 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05301689 my_data->is_internal_codec = true;
1690 my_data->is_slimbus_interface = false;
1691 }
1692}
1693
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301694static bool can_enable_mbdrc_on_device(snd_device_t snd_device)
1695{
1696 bool ret = false;
1697
1698 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
1699 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
1700 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
1701 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
1702 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
1703 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
1704 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05301705 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301706 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
1707 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
1708 ret = true;
1709 }
1710 return ret;
1711}
1712
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001713static snd_device_t fixup_usb_headset_mic_snd_device(void *platform,
1714 snd_device_t base,
1715 snd_device_t other)
1716{
1717 struct platform_data *my_data = (struct platform_data *)platform;
1718 struct audio_device *adev = my_data->adev;
Eric Laurent637e2d42018-11-15 12:24:31 -08001719 struct stream_in *in = adev_get_active_input(adev);
1720 if (in == NULL)
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001721 return base;
Eric Laurent637e2d42018-11-15 12:24:31 -08001722 unsigned int sr = in->sample_rate;
1723 unsigned int ch = popcount(in->channel_mask);
1724 unsigned int bit_width = in->bit_width;
Karthikeyan Mani07faa602018-08-20 11:01:32 -07001725 if (audio_extn_usb_is_config_supported(&bit_width, &sr, &ch, false)
1726 && ((ch == 6) || (ch == 8))) {
1727 return other;
1728 } else {
1729 return base;
1730 }
1731}
1732
`Deeraj Soman676c2702017-09-18 19:25:53 +05301733static const char *platform_get_mixer_control(struct mixer_ctl *);
1734
vivek mehtaa76401a2015-04-24 14:12:15 -07001735bool platform_send_gain_dep_cal(void *platform, int level) {
1736 bool ret_val = false;
1737 struct platform_data *my_data = (struct platform_data *)platform;
1738 struct audio_device *adev = my_data->adev;
1739 int acdb_dev_id, app_type;
1740 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
1741 int mode = CAL_MODE_RTAC;
1742 struct listnode *node;
1743 struct audio_usecase *usecase;
1744
1745 if (my_data->acdb_send_gain_dep_cal == NULL) {
1746 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
1747 return ret_val;
1748 }
1749
1750 if (!voice_is_in_call(adev)) {
1751 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
1752 __func__, level);
1753
1754 // find the current active sound device
1755 list_for_each(node, &adev->usecase_list) {
1756 usecase = node_to_item(node, struct audio_usecase, list);
1757
Sujin Panicker390724d2019-04-26 10:43:36 +05301758 if (usecase != NULL && usecase->stream.out &&
1759 usecase->type == PCM_PLAYBACK) {
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301760 int new_snd_device[2] = {0};
1761 int i, num_devices = 1;
vivek mehtaa76401a2015-04-24 14:12:15 -07001762
1763 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
1764 app_type = usecase->stream.out->app_type_cfg.app_type;
Aalique Grahame22e49102018-12-18 14:23:57 -08001765 acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device);
vivek mehta0b8ea6f2015-07-23 17:27:26 -07001766
Preetam Singh Ranawatbfec31e2017-05-04 11:51:50 +05301767 if (platform_split_snd_device(my_data, usecase->out_snd_device,
1768 &num_devices, new_snd_device) < 0)
1769 new_snd_device[0] = usecase->out_snd_device;
1770
1771 for (i = 0; i < num_devices; i++)
1772 if (can_enable_mbdrc_on_device(new_snd_device[i])) {
1773 if (audio_extn_spkr_prot_is_enabled())
1774 acdb_dev_id = platform_get_spkr_prot_acdb_id(new_snd_device[i]);
1775 else
1776 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1777 }
vivek mehta0b8ea6f2015-07-23 17:27:26 -07001778
vivek mehtaa76401a2015-04-24 14:12:15 -07001779 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
1780 acdb_dev_type, mode, level)) {
1781 // set ret_val true if at least one calibration is set successfully
1782 ret_val = true;
1783 } else {
1784 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
1785 }
1786 } else {
1787 ALOGW("%s: Usecase list is empty", __func__);
1788 }
1789 }
1790 } else {
1791 ALOGW("%s: Voice call in progress .. ignore setting new cal",
1792 __func__);
1793 }
1794 return ret_val;
1795}
1796
Banajit Goswami20cdd212015-09-11 01:11:30 -07001797void platform_set_gsm_mode(void *platform, bool enable)
1798{
1799 struct platform_data *my_data = (struct platform_data *)platform;
1800 struct audio_device *adev = my_data->adev;
1801
1802 if (my_data->gsm_mode_enabled) {
1803 my_data->gsm_mode_enabled = false;
1804 ALOGV("%s: disabling gsm mode", __func__);
1805 audio_route_reset_and_update_path(adev->audio_route, "gsm-mode");
1806 }
1807
1808 if (enable) {
1809 my_data->gsm_mode_enabled = true;
1810 ALOGD("%s: enabling gsm mode", __func__);
1811 audio_route_apply_and_update_path(adev->audio_route, "gsm-mode");
1812 }
1813}
1814
1815void platform_set_echo_reference(struct audio_device *adev, bool enable,
kunleizceb286c2018-12-21 16:01:32 +08001816 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001817{
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001818 struct platform_data *my_data = (struct platform_data *)adev->platform;
kunleize96916e2018-07-16 16:25:59 +08001819 char ec_ref_mixer_path[MIXER_PATH_MAX_LENGTH] = "echo-reference";
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001820
kunleiz70e57612018-12-28 17:50:23 +08001821 audio_extn_sound_trigger_update_ec_ref_status(enable);
1822
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001823 if (strcmp(my_data->ec_ref_mixer_path, "")) {
1824 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
Banajit Goswami20cdd212015-09-11 01:11:30 -07001825 audio_route_reset_and_update_path(adev->audio_route,
1826 my_data->ec_ref_mixer_path);
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05301827 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001828
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -08001829 if (enable) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08001830 if (!voice_extn_is_compress_voip_supported()) {
Gangadhar Sb0210342019-02-22 17:39:41 +05301831 if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
1832 strlcat(ec_ref_mixer_path, "-voip", MIXER_PATH_MAX_LENGTH);
1833 }
kunleizceb286c2018-12-21 16:01:32 +08001834 strlcpy(my_data->ec_ref_mixer_path, ec_ref_mixer_path,
1835 MIXER_PATH_MAX_LENGTH);
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001836 /*
1837 * If native audio device reference count > 0, then apply codec EC otherwise
kunleizceb286c2018-12-21 16:01:32 +08001838 * apply EC based on output device.
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001839 */
1840 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
kunleize96916e2018-07-16 16:25:59 +08001841 strlcat(ec_ref_mixer_path, " headphones-44.1",
1842 MIXER_PATH_MAX_LENGTH);
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08001843 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
kunleize96916e2018-07-16 16:25:59 +08001844 strlcat(ec_ref_mixer_path, " speaker-vbat",
1845 MIXER_PATH_MAX_LENGTH);
Aalique Grahame37659862017-12-03 22:34:26 -08001846 else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_DISPLAY_PORT] > 0)
kunleize96916e2018-07-16 16:25:59 +08001847 strlcat(ec_ref_mixer_path, " display-port",
1848 MIXER_PATH_MAX_LENGTH);
kunleizceb286c2018-12-21 16:01:32 +08001849 else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
1850 strlcat(ec_ref_mixer_path, " handset",
1851 MIXER_PATH_MAX_LENGTH);
1852 else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
1853 strlcat(ec_ref_mixer_path, " headphones",
1854 MIXER_PATH_MAX_LENGTH);
1855 else if (out_device & AUDIO_DEVICE_OUT_USB_HEADSET)
1856 strlcat(ec_ref_mixer_path, " usb-headphones",
1857 MIXER_PATH_MAX_LENGTH);
kunleize96916e2018-07-16 16:25:59 +08001858
kunleizceb286c2018-12-21 16:01:32 +08001859 if (audio_route_apply_and_update_path(adev->audio_route,
1860 ec_ref_mixer_path) == 0)
1861 strlcpy(my_data->ec_ref_mixer_path, ec_ref_mixer_path,
1862 MIXER_PATH_MAX_LENGTH);
1863 else
1864 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -08001865
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001866 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07001867 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001868}
1869
Helen Zeng6a16ad72014-02-23 22:04:44 -08001870static struct csd_data *open_csd_client(bool i2s_ext_modem)
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001871{
1872 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
1873
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001874 if (!csd) {
1875 ALOGE("failed to allocate csd_data mem");
1876 return NULL;
1877 }
1878
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001879 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
1880 if (csd->csd_client == NULL) {
1881 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
1882 goto error;
1883 } else {
1884 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
1885
1886 csd->deinit = (deinit_t)dlsym(csd->csd_client,
1887 "csd_client_deinit");
1888 if (csd->deinit == NULL) {
1889 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
1890 dlerror());
1891 goto error;
1892 }
1893 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
1894 "csd_client_disable_device");
1895 if (csd->disable_device == NULL) {
1896 ALOGE("%s: dlsym error %s for csd_client_disable_device",
1897 __func__, dlerror());
1898 goto error;
1899 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001900 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
1901 "csd_client_enable_device_config");
1902 if (csd->enable_device_config == NULL) {
1903 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
1904 __func__, dlerror());
1905 goto error;
1906 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001907 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
1908 "csd_client_enable_device");
1909 if (csd->enable_device == NULL) {
1910 ALOGE("%s: dlsym error %s for csd_client_enable_device",
1911 __func__, dlerror());
1912 goto error;
1913 }
1914 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
1915 "csd_client_start_voice");
1916 if (csd->start_voice == NULL) {
1917 ALOGE("%s: dlsym error %s for csd_client_start_voice",
1918 __func__, dlerror());
1919 goto error;
1920 }
1921 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
1922 "csd_client_stop_voice");
1923 if (csd->stop_voice == NULL) {
1924 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
1925 __func__, dlerror());
1926 goto error;
1927 }
1928 csd->volume = (volume_t)dlsym(csd->csd_client,
1929 "csd_client_volume");
1930 if (csd->volume == NULL) {
1931 ALOGE("%s: dlsym error %s for csd_client_volume",
1932 __func__, dlerror());
1933 goto error;
1934 }
1935 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
1936 "csd_client_mic_mute");
1937 if (csd->mic_mute == NULL) {
1938 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
1939 __func__, dlerror());
1940 goto error;
1941 }
1942 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
1943 "csd_client_slow_talk");
1944 if (csd->slow_talk == NULL) {
1945 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
1946 __func__, dlerror());
1947 goto error;
1948 }
1949 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
1950 "csd_client_start_playback");
1951 if (csd->start_playback == NULL) {
1952 ALOGE("%s: dlsym error %s for csd_client_start_playback",
1953 __func__, dlerror());
1954 goto error;
1955 }
1956 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
1957 "csd_client_stop_playback");
1958 if (csd->stop_playback == NULL) {
1959 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
1960 __func__, dlerror());
1961 goto error;
1962 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07001963 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
1964 if (csd->set_lch == NULL) {
1965 ALOGE("%s: dlsym error %s for csd_client_set_lch",
1966 __func__, dlerror());
1967 /* Ignore the error as this is not mandatory function for
1968 * basic voice call to work.
1969 */
1970 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001971 csd->start_record = (start_record_t)dlsym(csd->csd_client,
1972 "csd_client_start_record");
1973 if (csd->start_record == NULL) {
1974 ALOGE("%s: dlsym error %s for csd_client_start_record",
1975 __func__, dlerror());
1976 goto error;
1977 }
1978 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
1979 "csd_client_stop_record");
1980 if (csd->stop_record == NULL) {
1981 ALOGE("%s: dlsym error %s for csd_client_stop_record",
1982 __func__, dlerror());
1983 goto error;
1984 }
Helen Zeng6a16ad72014-02-23 22:04:44 -08001985
1986 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
1987 "csd_client_get_sample_rate");
1988 if (csd->get_sample_rate == NULL) {
1989 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
1990 __func__, dlerror());
1991
1992 goto error;
1993 }
1994
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001995 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1996
1997 if (csd->init == NULL) {
1998 ALOGE("%s: dlsym error %s for csd_client_init",
1999 __func__, dlerror());
2000 goto error;
2001 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -08002002 csd->init(i2s_ext_modem);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002003 }
2004 }
2005 return csd;
2006
2007error:
2008 free(csd);
2009 csd = NULL;
2010 return csd;
2011}
2012
2013void close_csd_client(struct csd_data *csd)
2014{
2015 if (csd != NULL) {
2016 csd->deinit();
2017 dlclose(csd->csd_client);
2018 free(csd);
2019 csd = NULL;
2020 }
2021}
2022
Helen Zeng6a16ad72014-02-23 22:04:44 -08002023static bool platform_is_i2s_ext_modem(const char *snd_card_name,
2024 struct platform_data *plat_data)
2025{
2026 plat_data->is_i2s_ext_modem = false;
2027
2028 if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card",
2029 sizeof("apq8084-taiko-i2s-mtp-snd-card")) ||
2030 !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card",
Josh Kirschc3894372016-03-28 15:59:48 -07002031 sizeof("apq8084-taiko-i2s-cdp-snd-card")) ||
2032 !strncmp(snd_card_name, "apq8096-tasha-i2c-snd-card",
Xiaoyu Yec494c752017-11-02 18:52:48 -07002033 sizeof("apq8096-tasha-i2c-snd-card")) ||
2034 !strncmp(snd_card_name, "sdx-tavil-i2s-snd-card",
Josh Kirschf20adbf2018-03-06 16:26:22 -08002035 sizeof("sdx-tavil-i2s-snd-card")) ||
2036 !strncmp(snd_card_name, "sda845-tavil-i2s-snd-card",
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302037 sizeof("sda845-tavil-i2s-snd-card")) ||
2038 !strncmp(snd_card_name, "sa6155-adp-star-snd-card",
2039 sizeof("sa6155-adp-star-snd-card"))) {
Helen Zeng6a16ad72014-02-23 22:04:44 -08002040 plat_data->is_i2s_ext_modem = true;
2041 }
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302042 ALOGV("%s, is_i2s_ext_modem:%d soundcard name is %s",__func__,
2043 plat_data->is_i2s_ext_modem, snd_card_name);
Helen Zeng6a16ad72014-02-23 22:04:44 -08002044
2045 return plat_data->is_i2s_ext_modem;
Helen Zeng008aebd2014-02-23 19:13:12 -08002046}
2047
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302048static bool is_auto_snd_card(const char *snd_card_name)
2049{
2050 bool is_auto_snd_card = false;
2051
2052 if (!strncmp(snd_card_name, "sa6155-adp-star-snd-card",
2053 sizeof("sa6155-adp-star-snd-card"))) {
2054 is_auto_snd_card = true;
2055 ALOGV("%s : Auto snd card detected: soundcard name is %s",__func__,
2056 snd_card_name);
2057 }
2058
2059 return is_auto_snd_card;
2060}
2061
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302062static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002063{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05302064 int32_t dev;
2065 unsigned int count = 0;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302066 const char *MEDIA_MIMETYPE_AUDIO_ALAC = "audio/alac";
2067 const char *MEDIA_MIMETYPE_AUDIO_APE = "audio/x-ape";
2068
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002069 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302070 backend_tag_table[dev] = NULL;
2071 hw_interface_table[dev] = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08002072 operator_specific_device_table[dev] = NULL;
Carter Hsu32a62362018-10-15 15:01:42 -07002073 external_specific_device_table[dev] = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002074 }
Amit Shekhar5a39c912014-10-14 15:39:30 -07002075 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08002076 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -07002077 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002078
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302079 // To overwrite these go to the audio_platform_info.xml file.
2080 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
2081 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
2082 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
2083 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002084 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_SWB] = strdup("bt-sco-swb");
2085 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = strdup("bt-sco-swb");
Ralf Herzafb164f2018-07-03 07:08:07 +02002086 backend_tag_table[SND_DEVICE_IN_SPDIF] = strdup("spdif-in");
2087 backend_tag_table[SND_DEVICE_IN_HDMI_MIC] = strdup("hdmi-in");
2088 backend_tag_table[SND_DEVICE_IN_HDMI_ARC] = strdup("hdmi-arc-in");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302089 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
2090 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002091 backend_tag_table[SND_DEVICE_OUT_BT_SCO_SWB] = strdup("bt-sco-swb");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302092 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
2093 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07002094 backend_tag_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("display-port");
2095 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("speaker-and-display-port");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302096 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
2097 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
2098 backend_tag_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
Ashish Jain3e37a702016-11-25 12:27:15 +05302099 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002100 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
Ashish Jain3e37a702016-11-25 12:27:15 +05302101 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002102 backend_tag_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("usb-headset");
2103 backend_tag_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("usb-headphones");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002104 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302105 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
Sidipotu Ashokeaec6392016-04-19 09:37:57 +05302106 strdup("speaker-and-usb-headphones");
Aalique Grahame22e49102018-12-18 14:23:57 -08002107 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
2108 strdup("speaker-safe-and-usb-headphones");
2109 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] =
2110 strdup("speaker-safe-and-bt-sco");
2111 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB] =
2112 strdup("speaker-safe-and-bt-sco-wb");
Zhou Song12c29502019-03-16 10:37:18 +08002113 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB] =
2114 strdup("speaker-safe-and-bt-sco-swb");
Aniket Kumar Lata6bbd3bb2017-07-21 11:09:21 -07002115 backend_tag_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("usb-headset-mic");
2116 backend_tag_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("usb-headset-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302117 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002118 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2119 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2120 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
2121 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Karthikeyan Mani07faa602018-08-20 11:01:32 -07002122 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2123 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2124 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("usb-headset-mic");
2125 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC_AEC] = strdup("usb-headset-mic");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302126 backend_tag_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
2127 backend_tag_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05302128 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("headphones-dsd");
Ramlal Karra10d22b92019-08-08 19:02:35 +05302129 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER] = strdup("headphones-hifi-filter");
2130 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER] =
2131 strdup("speaker-and-headphones-hifi-filter");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302132 backend_tag_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
2133 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("voice-speaker-vbat");
Rohit kumarf4120402016-08-05 19:19:48 +05302134 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("voice-speaker-2-vbat");
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302135 backend_tag_table[SND_DEVICE_OUT_BT_A2DP] = strdup("bt-a2dp");
Florian Pfister1a84f312018-07-19 14:38:18 +02002136 backend_tag_table[SND_DEVICE_IN_BT_A2DP] = strdup("bt-a2dp-cap");
Naresh Tanniru9d027a62015-03-13 01:32:10 +05302137 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP] = strdup("speaker-and-bt-a2dp");
Aalique Grahame22e49102018-12-18 14:23:57 -08002138 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] = strdup("speaker-safe-and-bt-a2dp");
2139 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("usb-headset");
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05302140 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
2141 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
2142 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002143 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones");
2144 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones");
2145 backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones");
juyuchen2d415992018-11-16 14:15:16 +08002146 backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302147
Siena Richard7c2db772016-12-21 11:32:34 -08002148 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
2149 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
2150 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = strdup("SLIMBUS_0_RX");
2151 hw_interface_table[SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = strdup("SLIMBUS_0_RX");
2152 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002153 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002154 hw_interface_table[SND_DEVICE_OUT_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
2155 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_6_RX");
2156 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_6_RX");
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05302157 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_DSD] = strdup("SLIMBUS_2_RX");
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05302158 hw_interface_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("SLIMBUS_5_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002159 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002160 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 +05302161 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2162 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2163 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 -07002164 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2165 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2166 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 -08002167 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002168 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 -08002169 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2170 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2171 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002172 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002173 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05302174 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002175 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("SLIMBUS_0_RX");
2176 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2] = strdup("SLIMBUS_0_RX");
2177 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT] = strdup("SLIMBUS_0_RX");
2178 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainfd24f1e2019-04-30 11:58:43 +05302179 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADSET] = strdup("SLIMBUS_6_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002180 hw_interface_table[SND_DEVICE_OUT_VOICE_MUSIC_TX] = strdup("VOICE_PLAYBACK_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002181 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_6_RX");
2182 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI");
2183 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI");
2184 hw_interface_table[SND_DEVICE_OUT_DISPLAY_PORT] = strdup("DISPLAY_PORT");
2185 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT] = strdup("SLIMBUS_0_RX-and-DISPLAY_PORT");
2186 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SLIMBUS_7_RX");
2187 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SLIMBUS_7_RX");
Zhou Song12c29502019-03-16 10:37:18 +08002188 hw_interface_table[SND_DEVICE_OUT_BT_SCO_SWB] = strdup("SLIMBUS_7_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002189 hw_interface_table[SND_DEVICE_OUT_BT_A2DP] = strdup("SLIMBUS_7_RX");
2190 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 -08002191 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP] =
2192 strdup("SLIMBUS_0_RX-and-SLIMBUS_7_RX");
2193 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002194 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainc9250dc2019-06-14 12:19:28 +05302195 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET] = strdup("SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002196 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_6_RX");
Samyak Jainc9250dc2019-06-14 12:19:28 +05302197 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET] = strdup("SLIMBUS_6_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002198 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002199 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
2200 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002201 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("RT_PROXY_DAI_001_RX");
2202 hw_interface_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("RT_PROXY_DAI_001_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05302203 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002204 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
Ashish Jain3e37a702016-11-25 12:27:15 +05302205 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002206 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET_SPEC] = strdup("USB_AUDIO_RX");
2207 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
2208 strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07002209 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Ashish Jainb26edfb2016-08-25 00:10:11 +05302210 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 -08002211 hw_interface_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("SLIMBUS_8_TX");
2212 hw_interface_table[SND_DEVICE_OUT_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
2213 hw_interface_table[SND_DEVICE_OUT_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
2214 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_HEADSET] = strdup("SLIMBUS_6_RX");
2215 hw_interface_table[SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = strdup("SLIMBUS_6_RX");
2216 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2217 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET] = strdup("SLIMBUS_0_RX-and-SLIMBUS_6_RX");
2218 hw_interface_table[SND_DEVICE_OUT_ANC_HANDSET] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05302219 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
2220 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002221 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = strdup("SLIMBUS_0_RX");
2222 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = strdup("SLIMBUS_0_RX-and-SEC_AUX_PCM_RX");
2223 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 +08002224 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 -08002225 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO] = strdup("QUAT_TDM_RX_0-and-SLIMBUS_7_RX");
2226 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 +08002227 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 +05302228 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED] = strdup("SLIMBUS_0_RX");
Vikram Panduranga8c68e862018-04-27 12:59:42 -07002229 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = strdup("SLIMBUS_0_RX");
Aditya Bavanari701a6992017-03-30 19:17:16 +05302230 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
2231 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
2232 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT] = strdup("SLIMBUS_0_RX");
Siena Richard7c2db772016-12-21 11:32:34 -08002233 hw_interface_table[SND_DEVICE_OUT_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
2234 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = strdup("SLIMBUS_0_RX");
2235 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = strdup("SLIMBUS_0_RX");
juyuchen2d415992018-11-16 14:15:16 +08002236 /* So far, primary hal doesn't support hearing aid device.
2237 Need snd_device to route voice call and use specific acdb tuning.
2238 Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */
2239 hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"),
Derek Chenf6318be2017-06-12 17:16:24 -04002240 hw_interface_table[SND_DEVICE_OUT_BUS_MEDIA] = strdup("TERT_TDM_RX_0");
2241 hw_interface_table[SND_DEVICE_OUT_BUS_SYS] = strdup("TERT_TDM_RX_0");
2242 hw_interface_table[SND_DEVICE_OUT_BUS_NAV] = strdup("TERT_TDM_RX_1");
2243 hw_interface_table[SND_DEVICE_OUT_BUS_PHN] = strdup("TERT_TDM_RX_2");
Siena Richard7c2db772016-12-21 11:32:34 -08002244 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002245 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002246 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = strdup("SLIMBUS_0_TX");
2247 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002248 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002249 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002250 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002251 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002252 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002253 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC] = strdup("SLIMBUS_0_TX");
2254 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002255 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002256 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002257 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002258 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002259 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002260 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2261 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_AEC] = strdup("SLIMBUS_0_TX");
Eric Laurent4b084132018-10-19 17:33:43 -07002262 hw_interface_table[SND_DEVICE_IN_CAMCORDER_LANDSCAPE] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002263 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002264 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002265 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002266 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002267 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002268 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002269 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002270 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002271 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
2272 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002273 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002274 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002275 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002276 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002277 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002278 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002279 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
2280 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2281 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002282 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002283 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Ralf Herzafb164f2018-07-03 07:08:07 +02002284 hw_interface_table[SND_DEVICE_IN_SPDIF] = strdup("PRI_SPDIF_TX");
2285 hw_interface_table[SND_DEVICE_IN_HDMI_MIC] = strdup("SEC_MI2S_TX");
2286 hw_interface_table[SND_DEVICE_IN_HDMI_ARC] = strdup("SEC_SPDIF_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002287 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("SLIMBUS_7_TX");
2288 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("SLIMBUS_7_TX");
2289 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("SLIMBUS_7_TX");
2290 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("SLIMBUS_7_TX");
Zhou Song12c29502019-03-16 10:37:18 +08002291 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_SWB] = strdup("SLIMBUS_7_TX");
2292 hw_interface_table[SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC] = strdup("SLIMBUS_7_TX");
Florian Pfister1a84f312018-07-19 14:38:18 +02002293 hw_interface_table[SND_DEVICE_IN_BT_A2DP] = strdup("SLIMBUS_7_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002294 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
2295 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002296 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002297 hw_interface_table[SND_DEVICE_IN_VOICE_DMIC_TMUS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002298 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08002299 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002300 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07002301 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_TMIC] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002302 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = strdup("SLIMBUS_0_TX");
2303 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
2304 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
2305 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002306 hw_interface_table[SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Aniket Kumar Latab26135f2017-06-16 12:20:04 -07002307 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
2308 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002309 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
2310 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002311 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC] = strdup("SLIMBUS_0_TX");
2312 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002313 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2314 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2315 hw_interface_table[SND_DEVICE_IN_VOICE_RX] = strdup("RT_PROXY_DAI_002_TX");
2316 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002317 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
2318 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
2319 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
2320 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
Karthikeyan Mani07faa602018-08-20 11:01:32 -07002321 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC] = strdup("USB_AUDIO_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002322 hw_interface_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("SLIMBUS_8_TX");
2323 hw_interface_table[SND_DEVICE_IN_AANC_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
2324 hw_interface_table[SND_DEVICE_IN_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002325 hw_interface_table[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
2326 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002327 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = strdup("SLIMBUS_4_TX");
2328 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1] = strdup("SLIMBUS_4_TX");
2329 hw_interface_table[SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2] = strdup("SLIMBUS_4_TX");
2330 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2331 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2332 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = strdup("SLIMBUS_0_TX");
2333 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
2334 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = strdup("SLIMBUS_0_TX");
2335 hw_interface_table[SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = strdup("SLIMBUS_0_TX");
2336 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC] = strdup("SLIMBUS_0_TX");
Aalique Grahame22e49102018-12-18 14:23:57 -08002337 hw_interface_table[SND_DEVICE_IN_HANDSET_QMIC_AEC] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002338 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC] = strdup("SLIMBUS_0_TX");
2339 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_NS] = strdup("SLIMBUS_0_TX");
2340 hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
2341 hw_interface_table[SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
2342 hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05302343 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002344 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05302345 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
2346 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_NS] = strdup("SLIMBUS_0_TX");
2347 hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07002348 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC] = strdup("SLIMBUS_0_TX");
2349 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_NS] = strdup("SLIMBUS_0_TX");
2350 hw_interface_table[SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
Siena Richard7c2db772016-12-21 11:32:34 -08002351 hw_interface_table[SND_DEVICE_IN_VOICE_REC_TMIC] = strdup("SLIMBUS_0_TX");
2352 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
2353 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
2354 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
2355 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
2356 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05302357 hw_interface_table[SND_DEVICE_IN_HANDSET_GENERIC_QMIC] = strdup("SLIMBUS_0_TX");
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05302358 hw_interface_table[SND_DEVICE_IN_INCALL_REC_RX] = strdup("INCALL_RECORD_RX");
2359 hw_interface_table[SND_DEVICE_IN_INCALL_REC_TX] = strdup("INCALL_RECORD_TX");
Ramu Gottipati813ae982018-07-25 14:14:48 +05302360 hw_interface_table[SND_DEVICE_IN_LINE] = strdup("SLIMBUS_0_TX");
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302361 hw_interface_table[SND_DEVICE_OUT_VOIP_HANDSET] = strdup("SLIMBUS_0_RX");
2362 hw_interface_table[SND_DEVICE_OUT_VOIP_SPEAKER] = strdup("SLIMBUS_0_RX");
2363 hw_interface_table[SND_DEVICE_OUT_VOIP_HEADPHONES] = strdup("SLIMBUS_6_RX");
Eric Laurent4b084132018-10-19 17:33:43 -07002364 hw_interface_table[SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2365 hw_interface_table[SND_DEVICE_IN_CAMCORDER_PORTRAIT] = strdup("SLIMBUS_0_TX");
2366 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2367 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX");
2368 hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX");
juyuchen2d415992018-11-16 14:15:16 +08002369 hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX");
Derek Chenf6318be2017-06-12 17:16:24 -04002370 hw_interface_table[SND_DEVICE_IN_BUS] = strdup("TERT_TDM_TX_0");
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302371 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302372
2373 /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
Alexy Josephb1379942016-01-29 15:49:38 -08002374 for (count = 0; count < (int32_t)(sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302375 count++) {
2376
2377 if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
2378 strlen(dsp_only_decoders_mime[count]))) {
2379
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002380 if(property_get_bool("vendor.audio.use.sw.alac.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302381 ALOGD("Alac software decoder is available...removing alac from DSP decoder list");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302382 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302383 }
2384 } else if (!strncmp(MEDIA_MIMETYPE_AUDIO_APE, dsp_only_decoders_mime[count],
2385 strlen(dsp_only_decoders_mime[count]))) {
2386
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07002387 if(property_get_bool("vendor.audio.use.sw.ape.decoder", false)) {
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302388 ALOGD("APE software decoder is available...removing ape from DSP decoder list");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302389 strlcpy(dsp_only_decoders_mime[count],"none",5);
Naresh Tanniru34a303c2016-01-27 17:26:41 +05302390 }
2391 }
2392 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07002393}
2394
Walter Yang6f800052014-07-14 16:15:38 -07002395void get_cvd_version(char *cvd_version, struct audio_device *adev)
2396{
2397 struct mixer_ctl *ctl;
2398 int count;
2399 int ret = 0;
2400
2401 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
2402 if (!ctl) {
2403 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
2404 goto done;
2405 }
2406 mixer_ctl_update(ctl);
2407
2408 count = mixer_ctl_get_num_values(ctl);
2409 if (count > MAX_CVD_VERSION_STRING_SIZE)
Aalique Grahame22e49102018-12-18 14:23:57 -08002410 count = MAX_CVD_VERSION_STRING_SIZE - 1;
Walter Yang6f800052014-07-14 16:15:38 -07002411
2412 ret = mixer_ctl_get_array(ctl, cvd_version, count);
2413 if (ret != 0) {
2414 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
2415 goto done;
2416 }
2417
2418done:
2419 return;
2420}
2421
Anish Kumar55e6df22014-08-26 17:38:05 -07002422static int hw_util_open(int card_no)
2423{
2424 int fd = -1;
2425 char dev_name[256];
2426
2427 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
2428 card_no, WCD9XXX_CODEC_HWDEP_NODE);
2429 ALOGD("%s Opening device %s\n", __func__, dev_name);
2430 fd = open(dev_name, O_WRONLY);
2431 if (fd < 0) {
2432 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
2433 return fd;
2434 }
2435 ALOGD("%s success", __func__);
2436 return fd;
2437}
2438
2439struct param_data {
2440 int use_case;
2441 int acdb_id;
2442 int get_size;
2443 int buff_size;
2444 int data_size;
2445 void *buff;
2446};
2447
Banajit Goswami20cdd212015-09-11 01:11:30 -07002448static int send_vbat_adc_data_to_acdb(struct platform_data *plat_data, char *cal_type)
2449{
2450 int ret = 0;
2451 struct mixer_ctl *ctl;
2452 uint16_t vbat_adc_data[2];
2453 struct platform_data *my_data = plat_data;
2454 struct audio_device *adev = my_data->adev;
2455
2456 const char *mixer_ctl_name = "Vbat ADC data";
2457
2458 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2459 if (!ctl) {
2460 ALOGE("%s: Could not get ctl for mixer ctl name - %s",
2461 __func__, mixer_ctl_name);
2462 ret = -EINVAL;
2463 goto done;
2464 }
2465
2466 vbat_adc_data[0] = mixer_ctl_get_value(ctl, 0);
2467 vbat_adc_data[1] = mixer_ctl_get_value(ctl, 1);
2468
2469 ALOGD("%s: Vbat ADC output values: Dcp1: %d , Dcp2: %d",
2470 __func__, vbat_adc_data[0], vbat_adc_data[1]);
2471
2472 ret = my_data->acdb_set_codec_data(&vbat_adc_data[0], cal_type);
2473
2474done:
2475 return ret;
2476}
2477
2478static void send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration,
2479 struct platform_data *plat_data, int fd)
Anish Kumar55e6df22014-08-26 17:38:05 -07002480{
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002481 int type;
Anish Kumar55e6df22014-08-26 17:38:05 -07002482
2483 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
2484 struct wcdcal_ioctl_buffer codec_buffer;
2485 struct param_data calib;
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002486 int ret;
Anish Kumar55e6df22014-08-26 17:38:05 -07002487
Bharath Ramachandramurthy63a47ef2015-08-31 17:41:46 -07002488 /* MAD calibration is handled by sound trigger HAL, skip here */
2489 if (type == WCD9XXX_MAD_CAL)
2490 continue;
2491
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002492 ret = 0;
Banajit Goswami20cdd212015-09-11 01:11:30 -07002493
Banajit Goswami4dc87fb2015-10-11 21:46:07 -07002494 if ((plat_data->is_vbat_speaker) && (WCD9XXX_VBAT_CAL == type)) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05302495 /* VBAT BCL speaker does not need tuning data */
2496 if (!plat_data->is_bcl_speaker)
2497 return;
Banajit Goswami20cdd212015-09-11 01:11:30 -07002498 ret = send_vbat_adc_data_to_acdb(plat_data, cal_name_info[type]);
2499 if (ret < 0)
2500 ALOGE("%s error in sending vbat adc data to acdb", __func__);
2501 }
2502
Anish Kumar55e6df22014-08-26 17:38:05 -07002503 calib.get_size = 1;
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002504 ret = acdb_loader_get_calibration(cal_name_info[type],
2505 sizeof(struct param_data),
2506 &calib);
Anish Kumar55e6df22014-08-26 17:38:05 -07002507 if (ret < 0) {
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002508 ALOGE("%s: %s get_calibration size failed, err = %d\n",
2509 __func__, cal_name_info[type], ret);
2510 continue;
Anish Kumar55e6df22014-08-26 17:38:05 -07002511 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002512
Anish Kumar55e6df22014-08-26 17:38:05 -07002513 calib.get_size = 0;
2514 calib.buff = malloc(calib.buff_size);
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002515 if (!calib.buff) {
2516 ALOGE("%s: %s: No Memory for size = %d\n",
2517 __func__, cal_name_info[type], calib.buff_size);
2518 continue;
2519 }
2520
Anish Kumar55e6df22014-08-26 17:38:05 -07002521 ret = acdb_loader_get_calibration(cal_name_info[type],
2522 sizeof(struct param_data), &calib);
2523 if (ret < 0) {
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002524 ALOGE("%s: %s get_calibration failed, err = %d\n",
2525 __func__, cal_name_info[type], ret);
Anish Kumar55e6df22014-08-26 17:38:05 -07002526 free(calib.buff);
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002527 continue;
Anish Kumar55e6df22014-08-26 17:38:05 -07002528 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002529
Anish Kumar55e6df22014-08-26 17:38:05 -07002530 codec_buffer.buffer = calib.buff;
2531 codec_buffer.size = calib.data_size;
2532 codec_buffer.cal_type = type;
2533 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002534 ALOGE("%s: %s Failed to call ioctl, err=%d",
2535 __func__, cal_name_info[type], errno);
2536 else
2537 ALOGD("%s: %s cal sent successfully\n",
2538 __func__, cal_name_info[type]);
2539
Anish Kumar55e6df22014-08-26 17:38:05 -07002540 free(calib.buff);
2541 }
Anish Kumar55e6df22014-08-26 17:38:05 -07002542}
2543
2544static void audio_hwdep_send_cal(struct platform_data *plat_data)
2545{
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302546 int fd = plat_data->hw_dep_fd;
Anish Kumar55e6df22014-08-26 17:38:05 -07002547
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302548 if (fd < 0)
2549 fd = hw_util_open(plat_data->adev->snd_card);
Anish Kumar55e6df22014-08-26 17:38:05 -07002550 if (fd == -1) {
2551 ALOGE("%s error open\n", __func__);
2552 return;
2553 }
2554
2555 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
2556 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
2557
2558 if (acdb_loader_get_calibration == NULL) {
2559 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
2560 dlerror());
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302561 if (fd >= 0) {
2562 close(fd);
2563 plat_data->hw_dep_fd = -1;
2564 }
Anish Kumar55e6df22014-08-26 17:38:05 -07002565 return;
2566 }
Bhalchandra Gajare7c1ad7c2015-07-17 17:12:09 -07002567
Banajit Goswami20cdd212015-09-11 01:11:30 -07002568 send_codec_cal(acdb_loader_get_calibration, plat_data, fd);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05302569 plat_data->hw_dep_fd = fd;
Anish Kumar55e6df22014-08-26 17:38:05 -07002570}
2571
Aditya Bavanari4875a262019-01-17 19:39:59 +05302572const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name)
2573{
2574 const char *acdb_card_name = NULL;
2575 char *substring = NULL;
2576 char string[MAX_SND_CARD_NAME_LENGTH] = {0};
2577 int length = 0;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302578
Aditya Bavanari4875a262019-01-17 19:39:59 +05302579 if (snd_card_name == NULL)
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302580 return NULL;
2581
Aditya Bavanari4875a262019-01-17 19:39:59 +05302582 /* Both tasha & tasha-lite uses tasha ACDB files
2583 simulate sound card name for tasha lite, so that
2584 ACDB module loads tasha ACDB files for tasha lite */
2585 if ((substring = strstr(snd_card_name, "tashalite")) ||
2586 (substring = strstr(snd_card_name, "tasha9326"))) {
2587 ALOGD("%s: using tasha ACDB files for tasha-lite", __func__);
2588 length = substring - snd_card_name + 1;
2589 snprintf(string, length, "%s", snd_card_name);
2590 strlcat(string, "tasha-snd-card", sizeof(string));
2591 acdb_card_name = strdup(string);
2592 return acdb_card_name;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302593 }
Aditya Bavanari4875a262019-01-17 19:39:59 +05302594 acdb_card_name = strdup(snd_card_name);
2595 return acdb_card_name;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302596}
2597
Ben Rombergerfeca4b82015-07-07 20:40:44 -07002598static int platform_acdb_init(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05302599{
2600 struct platform_data *my_data = (struct platform_data *)platform;
2601 char *cvd_version = NULL;
Ramjee Singh203473b2015-06-09 15:18:42 +05302602 const char *snd_card_name;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302603 int result = -1;
2604 struct listnode *node;
2605 struct meta_key_list *key_info;
2606 int key = 0;
2607
Ramjee Singh203473b2015-06-09 15:18:42 +05302608 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302609 if (!cvd_version) {
Ramjee Singh203473b2015-06-09 15:18:42 +05302610 ALOGE("Failed to allocate cvd version");
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302611 return -1;
2612 } else {
Ramjee Singh203473b2015-06-09 15:18:42 +05302613 get_cvd_version(cvd_version, my_data->adev);
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05302614 }
Ramjee Singh203473b2015-06-09 15:18:42 +05302615
Ramjee Singh203473b2015-06-09 15:18:42 +05302616 snd_card_name = mixer_get_name(my_data->adev->mixer);
Weiyin Jiang29c08a42019-04-30 17:11:10 +08002617 snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
Aditya Bavanari6e4faec2019-02-15 18:17:44 +05302618 if (!snd_card_name) {
2619 ALOGE("Failed to get snd_card_name");
2620 goto cleanup;
2621 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302622
Aditya Bavanari29bcea22017-10-03 20:10:35 +05302623 my_data->acdb_init_data.cvd_version = cvd_version;
2624 my_data->acdb_init_data.snd_card_name = strdup(snd_card_name);
2625 my_data->acdb_init_data.meta_key_list = &my_data->acdb_meta_key_list;
2626 if (my_data->acdb_init_v4) {
2627 result = my_data->acdb_init_v4(&my_data->acdb_init_data, ACDB_LOADER_INIT_V4);
2628 } else if (my_data->acdb_init_v3) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302629 result = my_data->acdb_init_v3(snd_card_name, cvd_version,
2630 &my_data->acdb_meta_key_list);
2631 } else if (my_data->acdb_init) {
2632 node = list_head(&my_data->acdb_meta_key_list);
2633 key_info = node_to_item(node, struct meta_key_list, list);
2634 key = key_info->cal_info.nKey;
2635 result = my_data->acdb_init(snd_card_name, cvd_version, key);
2636 }
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05302637
2638 /* Save these variables in platform_data. These will be used
2639 while reloading ACDB files during run time. */
2640 strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
2641 strlcpy(my_data->snd_card_name, snd_card_name,
2642 MAX_SND_CARD_STRING_SIZE);
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05302643
Aditya Bavanari6e4faec2019-02-15 18:17:44 +05302644cleanup:
Ramjee Singh203473b2015-06-09 15:18:42 +05302645 if (cvd_version)
2646 free(cvd_version);
2647 if (!result) {
2648 my_data->is_acdb_initialized = true;
2649 ALOGD("ACDB initialized");
2650 audio_hwdep_send_cal(my_data);
2651 } else {
2652 my_data->is_acdb_initialized = false;
2653 ALOGD("ACDB initialization failed");
2654 }
2655 return result;
2656}
2657
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302658#define MAX_PATH (256)
2659#define THERMAL_SYSFS "/sys/class/thermal"
2660#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
2661#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
2662
2663static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
2664 bool *is_wsa_combo_supported)
2665{
2666 DIR *tdir = NULL;
2667 struct dirent *tdirent = NULL;
2668 int tzn = 0;
2669 char name[MAX_PATH] = {0};
2670 char cwd[MAX_PATH] = {0};
2671 char file[10] = "wsa";
2672 bool found = false;
2673 int wsa_count = 0;
2674
2675 if (!getcwd(cwd, sizeof(cwd)))
2676 return false;
2677
2678 chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
2679 otherwise */
2680 tdir = opendir(THERMAL_SYSFS);
2681 if (!tdir) {
2682 ALOGE("Unable to open %s\n", THERMAL_SYSFS);
2683 return false;
2684 }
2685
2686 while ((tdirent = readdir(tdir))) {
2687 char buf[50];
2688 struct dirent *tzdirent;
2689 DIR *tzdir = NULL;
2690
2691 tzdir = opendir(tdirent->d_name);
2692 if (!tzdir)
2693 continue;
2694 while ((tzdirent = readdir(tzdir))) {
2695 if (strcmp(tzdirent->d_name, "type"))
2696 continue;
2697 snprintf(name, MAX_PATH, TZ_TYPE, tzn);
2698 ALOGD("Opening %s\n", name);
2699 read_line_from_file(name, buf, sizeof(buf));
2700 if (strstr(buf, file)) {
2701 wsa_count++;
2702 /*We support max only two WSA speakers*/
2703 if (wsa_count == 2)
2704 break;
2705 }
2706 tzn++;
2707 }
2708 closedir(tzdir);
2709 }
2710 if (wsa_count > 0){
2711 ALOGD("Found %d WSA present on the platform", wsa_count);
2712 found = true;
2713 *wsaCount = wsa_count;
2714
2715 /* update wsa combo supported flag based on sound card name */
2716 /* wsa combo flag needs to be set to true only for hardware
2717 combinations which has support for both wsa and non-wsa speaker */
2718 *is_wsa_combo_supported = false;
2719 if(snd_card_name) {
2720 if (((!strncmp(snd_card_name, "sdm439-sku1-snd-card",
2721 sizeof("sdm439-sku1-snd-card"))) ||
2722 (!strncmp(snd_card_name, "sdm439-snd-card-mtp",
2723 sizeof("sdm439-snd-card-mtp"))))) {
2724 *is_wsa_combo_supported = true;
2725 }
2726 }
2727 }
2728 closedir(tdir);
2729 chdir(cwd); /* Restore current working dir */
2730 return found;
2731}
2732
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302733static void get_source_mic_type(struct platform_data * my_data)
2734{
2735 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
2736 switch (my_data->max_mic_count) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302737 case 6:
2738 my_data->source_mic_type |= SOURCE_HEX_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05302739 case 4:
2740 my_data->source_mic_type |= SOURCE_QUAD_MIC;
2741 case 3:
2742 my_data->source_mic_type |= SOURCE_THREE_MIC;
2743 case 2:
2744 my_data->source_mic_type |= SOURCE_DUAL_MIC;
2745 case 1:
2746 my_data->source_mic_type |= SOURCE_MONO_MIC;
2747 break;
2748 default:
2749 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
2750 __func__, my_data->max_mic_count);
2751 my_data->source_mic_type = SOURCE_MONO_MIC | SOURCE_DUAL_MIC;
2752 break;
2753 }
2754}
2755
Siena Richard7c2db772016-12-21 11:32:34 -08002756/*
2757 * Retrieves the be_dai_name_table from kernel to enable a mapping
2758 * between sound device hw interfaces and backend IDs. This allows HAL to
2759 * specify the backend a specific calibration is needed for.
2760 */
2761static int init_be_dai_name_table(struct audio_device *adev)
2762{
2763 const char *mixer_ctl_name = "Backend DAI Name Table";
2764 struct mixer_ctl *ctl;
2765 int i, j, ret, size;
2766 bool valid_hw_interface;
2767
2768 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2769 if (!ctl) {
2770 ALOGE("%s: Could not get ctl for mixer name %s\n",
2771 __func__, mixer_ctl_name);
2772 ret = -EINVAL;
2773 goto done;
2774 }
2775
2776 mixer_ctl_update(ctl);
2777
2778 size = mixer_ctl_get_num_values(ctl);
2779 if (size <= 0){
2780 ALOGE("%s: Failed to get %s size %d\n",
2781 __func__, mixer_ctl_name, size);
2782 ret = -EFAULT;
2783 goto done;
2784 }
2785
2786 be_dai_name_table =
2787 (const struct be_dai_name_struct *)calloc(1, size);
2788 if (be_dai_name_table == NULL) {
2789 ALOGE("%s: Failed to allocate memory for %s\n",
2790 __func__, mixer_ctl_name);
2791 ret = -ENOMEM;
2792 goto freeMem;
2793 }
2794
2795 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
2796 if (ret) {
2797 ALOGE("%s: Failed to get %s, ret %d\n",
2798 __func__, mixer_ctl_name, ret);
2799 ret = -EFAULT;
2800 goto freeMem;
2801 }
2802
2803 if (be_dai_name_table != NULL) {
2804 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
2805 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
2806 __func__, mixer_ctl_name, max_be_dai_names);
2807 ret = 0;
2808 } else {
2809 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
2810 ret = -EFAULT;
2811 goto freeMem;
2812 }
2813
2814 /*
2815 * Validate all sound devices have a valid backend set to catch
2816 * errors for uncommon sound devices
2817 */
2818 for (i = 0; i < SND_DEVICE_MAX; i++) {
2819 valid_hw_interface = false;
2820
2821 if (hw_interface_table[i] == NULL) {
2822 ALOGW("%s: sound device %s has no hw interface set\n",
2823 __func__, platform_get_snd_device_name(i));
2824 continue;
2825 }
2826
2827 for (j = 0; j < max_be_dai_names; j++) {
2828 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
2829 == 0) {
2830 valid_hw_interface = true;
2831 break;
2832 }
2833 }
2834 if (!valid_hw_interface)
2835 ALOGD("%s: sound device %s does not have a valid hw interface set (disregard for combo devices) %s\n",
2836 __func__, platform_get_snd_device_name(i), hw_interface_table[i]);
2837 }
2838
2839 goto done;
2840
2841freeMem:
2842 if (be_dai_name_table) {
2843 free((void *)be_dai_name_table);
2844 be_dai_name_table = NULL;
2845 }
2846
2847done:
2848 return ret;
2849}
2850
Aalique Grahame22e49102018-12-18 14:23:57 -08002851#ifdef FLICKER_SENSOR_INPUT
2852static void configure_flicker_sensor_input(struct mixer *mixer)
2853{
2854 struct mixer_ctl *ctl;
2855 const char* ctl1 = "AIF3_CAP Mixer SLIM TX2";
2856 int setting1 = 1;
2857 const char* ctl2 = "CDC_IF TX2 MUX";
2858 const char* setting2 = "DEC2";
2859 const char* ctl3 = "SLIM_1_TX Channels";
2860 const char* setting3 = "One";
2861 const char* ctl4 = "ADC MUX2";
2862 const char* setting4 = "AMIC";
2863 const char* ctl5 = "AMIC MUX2";
2864 const char* setting5 = "ADC1";
2865 const char* ctl6 = "DEC2 Volume";
2866 int setting6 = 84;
2867 const char* ctl7 = "MultiMedia9 Mixer SLIM_1_TX";
2868 int setting7 = 1;
2869 const char* ctl8 = "SLIM_1_TX SampleRate";
2870 const char* setting8 = "KHZ_8";
2871
2872 ctl = mixer_get_ctl_by_name(mixer, ctl1);
2873 mixer_ctl_set_value(ctl, 0, setting1);
2874 ctl = mixer_get_ctl_by_name(mixer, ctl2);
2875 mixer_ctl_set_enum_by_string(ctl, setting2);
2876 ctl = mixer_get_ctl_by_name(mixer, ctl3);
2877 mixer_ctl_set_enum_by_string(ctl, setting3);
2878 ctl = mixer_get_ctl_by_name(mixer, ctl4);
2879 mixer_ctl_set_enum_by_string(ctl, setting4);
2880 ctl = mixer_get_ctl_by_name(mixer, ctl5);
2881 mixer_ctl_set_enum_by_string(ctl, setting5);
2882 ctl = mixer_get_ctl_by_name(mixer, ctl6);
2883 mixer_ctl_set_value(ctl, 0, setting6);
2884 ctl = mixer_get_ctl_by_name(mixer, ctl7);
2885 mixer_ctl_set_value(ctl, 0, setting7);
2886 ctl = mixer_get_ctl_by_name(mixer, ctl8);
2887 mixer_ctl_set_enum_by_string(ctl, setting8);
2888}
2889#endif
2890
Eric Laurentb23d5282013-05-14 15:27:20 -07002891void *platform_init(struct audio_device *adev)
2892{
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07002893 char platform[PROPERTY_VALUE_MAX];
2894 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -07002895 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08002896 struct platform_data *my_data = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08002897 char *snd_card_name = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07002898 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
Aalique Grahame22e49102018-12-18 14:23:57 -08002899 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302900 char ffspEnable[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08002901 int idx;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302902 int wsaCount =0;
2903 bool is_wsa_combo_supported = false;
`Deeraj Soman676c2702017-09-18 19:25:53 +05302904 struct mixer_ctl *ctl = NULL;
2905 const char *id_string = NULL;
2906 int cfg_value = -1;
Aalique Grahame22e49102018-12-18 14:23:57 -08002907 bool dual_mic_config = false;
2908 struct snd_card_split *snd_split_handle = NULL;
2909
2910 list_init(&operator_info_list);
2911 list_init(&app_type_entry_list);
sangwoo1b9f4b32013-06-21 18:22:55 -07002912
Arun Mirpurie008ed22019-03-21 11:21:04 -07002913 if(audio_extn_is_concurrent_capture_enabled())
2914 AUDIO_DEVICE_IN_ALL_CODEC_BACKEND = (AUDIO_DEVICE_IN_BUILTIN_MIC | \
2915 AUDIO_DEVICE_IN_BACK_MIC | AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN;
2916 else
2917 AUDIO_DEVICE_IN_ALL_CODEC_BACKEND = (AUDIO_DEVICE_IN_BUILTIN_MIC | \
2918 AUDIO_DEVICE_IN_BACK_MIC | AUDIO_DEVICE_IN_WIRED_HEADSET | \
2919 AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN;
2920
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302921 adev->snd_card = audio_extn_utils_open_snd_mixer(&adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002922 if (adev->snd_card < 0) {
2923 ALOGE("%s: Unable to find correct sound card", __func__);
2924 return NULL;
2925 }
2926 ALOGD("%s: Opened sound card:%d", __func__, adev->snd_card);
Eric Laurentb23d5282013-05-14 15:27:20 -07002927
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002928 snd_card_name = strdup(mixer_get_name(adev->mixer));
2929 if (!snd_card_name) {
2930 ALOGE("failed to allocate memory for snd_card_name\n");
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302931 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002932 return NULL;
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08002933 }
2934
Aalique Grahame22e49102018-12-18 14:23:57 -08002935 audio_extn_set_snd_card_split(snd_card_name);
2936 snd_split_handle = audio_extn_get_snd_card_split();
2937
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002938 my_data = calloc(1, sizeof(struct platform_data));
2939 if (!my_data) {
2940 ALOGE("failed to allocate platform data");
2941 if (snd_card_name)
2942 free(snd_card_name);
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302943 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002944 return NULL;
2945 }
2946
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05302947 my_data->is_slimbus_interface = true;
2948 my_data->is_internal_codec = false;
2949
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002950 my_data->hw_info = hw_info_init(snd_card_name);
2951 if (!my_data->hw_info) {
2952 ALOGE("failed to init hw_info");
Soumya Managoli9fee7c62018-04-06 16:21:50 +05302953 audio_extn_utils_close_snd_mixer(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002954 if (my_data)
2955 free(my_data);
2956
2957 if (snd_card_name)
2958 free(snd_card_name);
2959 return NULL;
2960 }
2961
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05302962 if (platform_is_i2s_ext_modem(snd_card_name, my_data) &&
2963 !is_auto_snd_card(snd_card_name)) {
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002964 ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
2965
2966 adev->audio_route = audio_route_init(adev->snd_card,
2967 MIXER_XML_PATH_I2S);
2968 } else {
2969 /* Get the codec internal name from the sound card name
2970 * and form the mixer paths file name dynamically. This
2971 * is generic way of picking any codec name based mixer
2972 * files in future with no code change. This code
2973 * assumes mixer files are formed with format as
2974 * mixer_paths_internalcodecname.xml
2975
2976 * If this dynamically read mixer files fails to open then it
2977 * falls back to default mixer file i.e mixer_paths.xml. This is
2978 * done to preserve backward compatibility but not mandatory as
2979 * long as the mixer files are named as per above assumption.
2980 */
Aalique Grahame22e49102018-12-18 14:23:57 -08002981 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
2982 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
2983 snd_split_handle->form_factor);
2984 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
2985 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
2986 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302987 MIXER_XML_BASE_STRING, snd_split_handle->variant);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002988
Aalique Grahame22e49102018-12-18 14:23:57 -08002989 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
2990 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
Sujin Panickerb904fbe2019-04-04 13:28:07 +05302991 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
2992 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
2993
2994 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
2995 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
2996 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
2997 audio_extn_utils_resolve_config_file(mixer_xml_file);
2998 }
Aalique Grahame22e49102018-12-18 14:23:57 -08002999 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003000 }
3001
Aalique Grahame22e49102018-12-18 14:23:57 -08003002 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
3003 if (audio_extn_read_xml(adev, adev->snd_card, mixer_xml_file,
3004 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
3005 adev->audio_route = audio_route_init(adev->snd_card, mixer_xml_file);
3006 update_codec_type_and_interface(my_data, snd_card_name);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003007 }
3008 }
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303009
3010#if defined (PLATFORM_MSMFALCON) || defined (PLATFORM_MSM8937)
3011 if (my_data->is_internal_codec == true) {
3012 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
3013 msm_be_id_array_len =
3014 sizeof(msm_device_to_be_id_internal_codec) /
3015 sizeof(msm_device_to_be_id_internal_codec[0]);
3016 } else {
3017 msm_device_to_be_id = msm_device_to_be_id_external_codec;
3018 msm_be_id_array_len =
3019 sizeof(msm_device_to_be_id_external_codec) /
3020 sizeof(msm_device_to_be_id_external_codec[0]);
3021 }
3022#endif
3023
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003024 if (!adev->audio_route) {
3025 ALOGE("%s: Failed to init audio route controls, aborting.",
3026 __func__);
Alexy Josephb1379942016-01-29 15:49:38 -08003027 if (my_data)
3028 free(my_data);
Ravi Kumar Alamanda31c90df2015-10-16 10:06:59 -07003029 if (snd_card_name)
3030 free(snd_card_name);
Soumya Managoli9fee7c62018-04-06 16:21:50 +05303031 audio_extn_utils_close_snd_mixer(adev->mixer);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08003032 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003033 }
3034
Aalique Grahame37659862017-12-03 22:34:26 -08003035 adev->dp_allowed_for_voice =
3036 property_get_bool("vendor.audio.enable.dp.for.voice", false);
3037
Eric Laurentb23d5282013-05-14 15:27:20 -07003038 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07003039 my_data->fluence_in_spkr_mode = false;
3040 my_data->fluence_in_voice_call = false;
3041 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08003042 my_data->fluence_in_audio_rec = false;
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303043 my_data->fluence_in_hfp_call = false;
Tanya Finkel00130052014-07-14 04:26:56 -07003044 my_data->external_spk_1 = false;
3045 my_data->external_spk_2 = false;
3046 my_data->external_mic = false;
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08003047 my_data->fluence_sb_enabled = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003048 my_data->fluence_type = FLUENCE_NONE;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003049 my_data->fluence_mode = FLUENCE_ENDFIRE;
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303050 my_data->ambisonic_capture = false;
3051 my_data->ambisonic_profile = false;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303052 my_data->slowtalk = false;
3053 my_data->hd_voice = false;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003054 my_data->edid_info = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07003055 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303056 my_data->is_wsa_speaker = false;
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303057 my_data->hw_dep_fd = -1;
Rohit kumarf4120402016-08-05 19:19:48 +05303058 my_data->mono_speaker = SPKR_1;
Aalique Grahame5f596f32018-01-09 12:56:35 -08003059 my_data->speaker_lr_swap = false;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07003060 my_data->voice_speaker_stereo = false;
Naresh Tannirudcb47c52018-06-25 16:23:32 +05303061 my_data->declared_mic_count = 0;
Surendar Karka45850ae2018-07-02 17:45:27 +05303062 my_data->spkr_ch_map = NULL;
Dieter Luecking5d57def2018-09-07 14:23:37 +02003063 my_data->use_sprk_default_sample_rate = true;
Aalique Grahame22e49102018-12-18 14:23:57 -08003064 my_data->fluence_in_voice_comm = false;
3065
3066 //set max volume step for voice call
3067 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
3068 my_data->max_vol_index = atoi(value);
3069
Siena Richard7c2db772016-12-21 11:32:34 -08003070 be_dai_name_table = NULL;
3071
Dhananjay Kumardf511452019-08-06 16:31:51 +05303072 property_get("persist.vendor.audio.dualmic.config",value,"");
Aalique Grahame22e49102018-12-18 14:23:57 -08003073 if (!strcmp("endfire", value)) {
3074 dual_mic_config = true;
3075 }
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303076
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08003077 /* Check for Fluence Sub Band Enablement */
3078 if (property_get_bool("ro.vendor.audio.sdk.fluence.subband.enabled",false))
3079 my_data->fluence_sb_enabled = true;
3080
Aalique Grahame22e49102018-12-18 14:23:57 -08003081 my_data->fluence_type = FLUENCE_NONE;
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303082 if (property_get("ro.vendor.audio.sdk.fluencetype",
3083 my_data->fluence_cap, NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003084 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
3085 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303086
Aalique Grahame22e49102018-12-18 14:23:57 -08003087 if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
3088 my_data->fluence_type |= FLUENCE_TRI_MIC;
3089 }
3090 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence")) ||
3091 dual_mic_config) {
3092 my_data->fluence_type = FLUENCE_DUAL_MIC;
3093
3094 if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
3095 my_data->fluence_type |= FLUENCE_TRI_MIC;
3096 }
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05303097 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003098 }
3099
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003100 if (my_data->fluence_type != FLUENCE_NONE) {
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303101 if (property_get("persist.vendor.audio.fluence.voicecall",
3102 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003103 if (!strncmp("true", value, sizeof("true")))
3104 my_data->fluence_in_voice_call = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003105 }
3106
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303107 if (property_get("persist.vendor.audio.fluence.voicerec",
3108 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003109 if (!strncmp("true", value, sizeof("true")))
3110 my_data->fluence_in_voice_rec = true;
3111 }
3112
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303113 property_get("persist.vendor.audio.fluence.voicecomm",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07003114 if (!strncmp("true", value, sizeof("true"))) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003115 my_data->fluence_in_voice_comm = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003116 }
3117
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003118 property_get("persist.vendor.audio.fluence.audiorec",value,"");
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08003119 if (!strncmp("true", value, sizeof("true"))) {
3120 my_data->fluence_in_audio_rec = true;
3121 }
3122
Manisha Agarwalbce6f6a2019-12-06 18:48:25 +05303123 if (property_get("persist.vendor.audio.fluence.speaker",
3124 value,NULL) > 0) {
Aalique Grahame22e49102018-12-18 14:23:57 -08003125 if (!strncmp("true", value, sizeof("true"))) {
3126 my_data->fluence_in_spkr_mode = true;
3127 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003128 }
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003129
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003130 property_get("persist.vendor.audio.fluence.mode",value,"");
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08003131 if (!strncmp("broadside", value, sizeof("broadside"))) {
3132 my_data->fluence_mode = FLUENCE_BROADSIDE;
3133 }
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303134
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003135 property_get("persist.vendor.audio.fluence.hfpcall",value,"");
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05303136 if (!strncmp("true", value, sizeof("true"))) {
3137 my_data->fluence_in_hfp_call = true;
3138 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003139 }
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303140 /* Check for Ambisonic Capture Enablement */
Fawad Shaukat42d38e92019-05-08 22:40:54 -07003141 if (property_get_bool("vendor.audio.ambisonic.capture",false))
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303142 my_data->ambisonic_capture = true;
3143
3144 /* Check for Ambisonic Profile Assignment*/
Fawad Shaukat42d38e92019-05-08 22:40:54 -07003145 if (property_get_bool("vendor.audio.ambisonic.auto.profile",false))
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05303146 my_data->ambisonic_profile = true;
Eric Laurentb23d5282013-05-14 15:27:20 -07003147
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303148 if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)
3149 && audio_extn_is_wsa_enabled()) {
3150 /*Set ACDB ID of Stereo speaker if two WSAs are present*/
3151 /*Default ACDB ID for wsa speaker is that for mono*/
3152 if (wsaCount == 2) {
3153 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
3154 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
3155 }
3156
3157 my_data->is_wsa_speaker = true;
3158
3159 if (is_wsa_combo_supported)
3160 hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
3161
3162 }
Vikram Panduranga8c68e862018-04-27 12:59:42 -07003163 my_data->voice_speaker_stereo =
3164 property_get_bool("persist.vendor.audio.voicecall.speaker.stereo", false);
3165
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303166 property_get("persist.vendor.audio.FFSP.enable", ffspEnable, "");
3167 if (!strncmp("true", ffspEnable, sizeof("true"))) {
3168 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
3169 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
3170 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
3171 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
3172 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
3173 }
3174
Banajit Goswami20cdd212015-09-11 01:11:30 -07003175 /* Check if Vbat speaker enabled property is set, this should be done before acdb init */
3176 bool ret = false;
3177 ret = audio_extn_can_use_vbat();
3178 if (ret)
3179 my_data->is_vbat_speaker = true;
3180
Aditya Bavanari9b589022018-09-20 08:47:55 +05303181 ret = audio_extn_can_use_bcl();
3182 if (ret)
3183 my_data->is_bcl_speaker = true;
3184
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303185 list_init(&my_data->acdb_meta_key_list);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303186 list_init(&my_data->custom_mtmx_params_list);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303187 list_init(&my_data->custom_mtmx_in_params_list);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303188
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303189 ret = audio_extn_is_hifi_audio_supported();
3190 if (ret || !my_data->is_internal_codec)
3191 my_data->hifi_audio = true;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303192 set_platform_defaults(my_data);
3193
3194 /* Initialize ACDB ID's */
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05303195 if (my_data->is_i2s_ext_modem && !is_auto_snd_card(snd_card_name))
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003196 platform_info_init(PLATFORM_INFO_XML_PATH_I2S, my_data, PLATFORM);
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303197 else if (!strncmp(snd_card_name, "sdm660-snd-card-skush",
3198 sizeof("sdm660-snd-card-skush")))
3199 platform_info_init(PLATFORM_INFO_XML_PATH_SKUSH, my_data, PLATFORM);
Walter Yang319c6fe2017-09-21 17:09:39 +08003200 else if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
3201 sizeof("sdm670-skuw-snd-card")))
3202 platform_info_init(PLATFORM_INFO_XML_PATH_SKUW, my_data, PLATFORM);
kunleiz291f3412018-09-04 16:04:44 +08003203 else if (!strncmp(snd_card_name, "sm6150-qrd-snd-card",
3204 sizeof("sm6150-qrd-snd-card")))
3205 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
kunleiz3ae92e52019-04-28 15:35:31 +08003206 else if (!strncmp(snd_card_name, "sm6150-wcd9375qrd-snd-card",
3207 sizeof("sm6150-wcd9375qrd-snd-card")))
3208 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Meng Wangef2f6e12018-10-08 13:06:05 +08003209 else if (!strncmp(snd_card_name, "kona-qrd-snd-card",
3210 sizeof("kona-qrd-snd-card")))
3211 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Vatsal Bucha6339b092019-04-17 16:27:32 +05303212 else if (!strncmp(snd_card_name, "lito-qrd-snd-card",
3213 sizeof("lito-qrd-snd-card")))
3214 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Kunlei Zhang9ea4e4f2019-08-28 15:39:27 +08003215 else if (!strncmp(snd_card_name, "atoll-qrd-snd-card",
3216 sizeof("atoll-qrd-snd-card")))
3217 platform_info_init(PLATFORM_INFO_XML_PATH_QRD, my_data, PLATFORM);
Ramu Gottipati54ed9482018-08-21 16:00:22 +05303218 else if (!strncmp(snd_card_name, "qcs405-wsa-snd-card",
3219 sizeof("qcs405-wsa-snd-card")))
3220 platform_info_init(PLATFORM_INFO_XML_PATH_WSA, my_data, PLATFORM);
Dhananjay Kumarb34c5c12018-09-25 16:04:26 +05303221 else if (!strncmp(snd_card_name, "qcs405-tdm-snd-card",
3222 sizeof("qcs405-tdm-snd-card")))
3223 platform_info_init(PLATFORM_INFO_XML_PATH_TDM, my_data, PLATFORM);
Walter Yang319c6fe2017-09-21 17:09:39 +08003224 else if (my_data->is_internal_codec)
3225 platform_info_init(PLATFORM_INFO_XML_PATH_INTCODEC, my_data, PLATFORM);
Aalique Grahame22e49102018-12-18 14:23:57 -08003226 else {
3227 // Try to load pixel or default
3228 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
3229 platform_info_init(platform_info_file, my_data, PLATFORM);
3230 }
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303231
Dieter Luecking5d57def2018-09-07 14:23:37 +02003232 /* CSRA devices support multiple sample rates via I2S at spkr out */
3233 if (!strncmp(snd_card_name, "qcs405-csra", strlen("qcs405-csra"))) {
3234 ALOGE("%s: soundcard: %s supports multiple sample rates", __func__, snd_card_name);
3235 my_data->use_sprk_default_sample_rate = false;
3236 } else {
3237 my_data->use_sprk_default_sample_rate = true;
3238 ALOGE("%s: soundcard: %s supports only default sample rate", __func__, snd_card_name);
3239 }
3240
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003241 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -07003242 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
3243 if (my_data->acdb_handle == NULL) {
3244 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
3245 } else {
3246 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
3247 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
3248 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003249 if (!my_data->acdb_deallocate)
3250 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
3251 __func__, LIB_ACDB_LOADER);
3252
Eric Laurentb23d5282013-05-14 15:27:20 -07003253 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 -07003254 "acdb_loader_send_audio_cal_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -07003255 if (!my_data->acdb_send_audio_cal)
Siena Richard7c2db772016-12-21 11:32:34 -08003256 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v2 from %s",
3257 __func__, LIB_ACDB_LOADER);
3258
3259 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
3260 "acdb_loader_send_audio_cal_v3");
3261 if (!my_data->acdb_send_audio_cal_v3)
3262 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07003263 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003264
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05303265 my_data->acdb_send_audio_cal_v4 = (acdb_send_audio_cal_v4_t)dlsym(my_data->acdb_handle,
3266 "acdb_loader_send_audio_cal_v4");
3267 if (!my_data->acdb_send_audio_cal_v4)
3268 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v4 from %s",
3269 __func__, LIB_ACDB_LOADER);
3270
Ben Rombergera04fabc2014-11-14 12:16:03 -08003271 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
3272 "acdb_loader_set_audio_cal_v2");
3273 if (!my_data->acdb_set_audio_cal)
3274 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
3275 __func__, LIB_ACDB_LOADER);
3276
3277 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
3278 "acdb_loader_get_audio_cal_v2");
3279 if (!my_data->acdb_get_audio_cal)
3280 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
3281 __func__, LIB_ACDB_LOADER);
3282
Eric Laurentb23d5282013-05-14 15:27:20 -07003283 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
3284 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003285 if (!my_data->acdb_send_voice_cal)
3286 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
3287 __func__, LIB_ACDB_LOADER);
3288
3289 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
3290 "acdb_loader_reload_vocvoltable");
3291 if (!my_data->acdb_reload_vocvoltable)
3292 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
3293 __func__, LIB_ACDB_LOADER);
3294
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07003295 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
3296 my_data->acdb_handle,
3297 "acdb_loader_get_default_app_type");
3298 if (!my_data->acdb_get_default_app_type)
3299 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3300 __func__, LIB_ACDB_LOADER);
3301
vivek mehtaa76401a2015-04-24 14:12:15 -07003302 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
3303 "acdb_loader_send_gain_dep_cal");
3304 if (!my_data->acdb_send_gain_dep_cal)
3305 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
3306 __func__, LIB_ACDB_LOADER);
3307
Ben Rombergerfeca4b82015-07-07 20:40:44 -07003308 my_data->acdb_send_common_top = (acdb_send_common_top_t)dlsym(
3309 my_data->acdb_handle,
3310 "acdb_loader_send_common_custom_topology");
3311 if (!my_data->acdb_send_common_top)
3312 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3313 __func__, LIB_ACDB_LOADER);
3314
Banajit Goswami20cdd212015-09-11 01:11:30 -07003315 my_data->acdb_set_codec_data = (acdb_set_codec_data_t)dlsym(
3316 my_data->acdb_handle,
3317 "acdb_loader_set_codec_data");
3318 if (!my_data->acdb_set_codec_data)
3319 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
3320 __func__, LIB_ACDB_LOADER);
3321
3322
Aditya Bavanari29bcea22017-10-03 20:10:35 +05303323 my_data->acdb_init_v4 = (acdb_init_v4_t)dlsym(my_data->acdb_handle,
3324 "acdb_loader_init_v4");
3325 if (my_data->acdb_init_v4 == NULL) {
3326 ALOGE("%s: dlsym error %s for acdb_loader_init_v4", __func__, dlerror());
3327 }
3328
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303329 my_data->acdb_init_v3 = (acdb_init_v3_t)dlsym(my_data->acdb_handle,
3330 "acdb_loader_init_v3");
3331 if (my_data->acdb_init_v3 == NULL) {
3332 ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror());
3333 }
3334
Eric Laurentb23d5282013-05-14 15:27:20 -07003335 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303336 "acdb_loader_init_v3");
Walter Yang6f800052014-07-14 16:15:38 -07003337 if (my_data->acdb_init == NULL) {
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303338 ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror());
Walter Yang6f800052014-07-14 16:15:38 -07003339 goto acdb_init_fail;
3340 }
3341
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05303342 my_data->acdb_reload_v2 = (acdb_reload_v2_t)dlsym(my_data->acdb_handle,
3343 "acdb_loader_reload_acdb_files_v2");
3344 if (my_data->acdb_reload_v2 == NULL) {
3345 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files_v2", __func__, dlerror());
3346 }
3347
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05303348 my_data->acdb_reload = (acdb_reload_t)dlsym(my_data->acdb_handle,
3349 "acdb_loader_reload_acdb_files");
3350 if (my_data->acdb_reload == NULL) {
3351 ALOGE("%s: dlsym error %s for acdb_loader_reload_acdb_files", __func__, dlerror());
3352 goto acdb_init_fail;
3353 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003354
Soumya Managoli9fee7c62018-04-06 16:21:50 +05303355 int result = acdb_init_v2(adev->mixer);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07003356 if (!result) {
3357 my_data->is_acdb_initialized = true;
3358 ALOGD("ACDB initialized");
3359 audio_hwdep_send_cal(my_data);
3360 } else {
3361 my_data->is_acdb_initialized = false;
3362 ALOGD("ACDB initialization failed");
3363 }
Eric Laurentb23d5282013-05-14 15:27:20 -07003364 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05303365 /* init keep-alive for compress passthru */
3366 audio_extn_keep_alive_init(adev);
Aalique Grahame22e49102018-12-18 14:23:57 -08003367
3368#ifdef FLICKER_SENSOR_INPUT
3369 configure_flicker_sensor_input(adev->mixer);
3370#endif
3371
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05303372#ifdef DYNAMIC_LOG_ENABLED
3373 log_utils_init();
3374#endif
Walter Yang6f800052014-07-14 16:15:38 -07003375acdb_init_fail:
3376
Ben Romberger55886882014-01-10 13:49:02 -08003377
Siena Richard7c2db772016-12-21 11:32:34 -08003378 /*
3379 * Get the be_dai_name_table from kernel which provides a mapping
3380 * between a backend string name and a backend ID
3381 */
3382 init_be_dai_name_table(adev);
3383
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08003384 if (audio_extn_can_use_ras()) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07003385 if (property_get_bool("persist.vendor.audio.speaker.prot.enable", false)) {
Srinivas Julakanti1ca769a2017-01-04 23:18:08 -08003386 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED,
3387 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS]);
3388 platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT,
3389 acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS]);
3390 } else {
3391 ALOGD("%s: RAS Feature should be enabled with Speaker Protection", __func__);
3392 }
3393 }
3394
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07003395 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
3396 * symbols. Voice call is handled by MDM and apps processor talks to
3397 * MDM through CSD Client
3398 */
3399 property_get("ro.board.platform", platform, "");
3400 property_get("ro.baseband", baseband, "");
Josh Kirschc3894372016-03-28 15:59:48 -07003401 if ((!strncmp("apq8084", platform, sizeof("apq8084")) ||
Xiaoyu Yec494c752017-11-02 18:52:48 -07003402 !strncmp("msm8996", platform, sizeof("msm8996")) ||
Suprith Malligere Shankaregowda7400b212019-03-22 19:48:44 +05303403 !strncmp("sm6150", platform, sizeof("sm6150")) ||
Josh Kirschf20adbf2018-03-06 16:26:22 -08003404 !strncmp("sdx", platform, sizeof("sdx")) ||
3405 !strncmp("sdm845", platform, sizeof("sdm845"))) &&
3406 ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) ||
3407 !strncmp("sdx", baseband, (sizeof("sdx")-1)))) {
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07003408 my_data->csd = open_csd_client(my_data->is_i2s_ext_modem);
3409 } else {
3410 my_data->csd = NULL;
3411 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08003412
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303413 /* obtain source mic type from max mic count*/
3414 get_source_mic_type(my_data);
3415 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 -08003416 " fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) fluence_in_hfp_call(%d)"
3417 "fluence_sb_enabled(%d)", __func__, my_data->fluence_type, my_data->max_mic_count,
3418 my_data->source_mic_type, my_data->fluence_in_voice_call,
3419 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode,
3420 my_data->fluence_in_hfp_call, my_data->fluence_sb_enabled);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05303421
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07003422 /* init usb */
3423 audio_extn_usb_init(adev);
3424
Naresh Tanniru9d027a62015-03-13 01:32:10 +05303425 /*init a2dp*/
3426 audio_extn_a2dp_init(adev);
3427
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003428 /* init dap hal */
3429 audio_extn_dap_hal_init(adev->snd_card);
3430
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003431 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -08003432 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -07003433 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05303434
Aalique Grahame22e49102018-12-18 14:23:57 -08003435 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05303436
Lior Barenboim0b61bc72014-05-13 13:01:37 +03003437 /* init audio device arbitration */
3438 audio_extn_dev_arbi_init();
3439
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303440 default_rx_backend = strdup("SLIMBUS_0_RX");
3441
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08003442 /* initialize backend config */
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003443 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
3444 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3445 if (idx == HEADPHONE_44_1_BACKEND)
3446 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
3447 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jainb26edfb2016-08-25 00:10:11 +05303448 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Kuirong Wang0b947f72016-09-29 11:03:09 -07003449 if (idx > MAX_RX_CODEC_BACKENDS)
3450 my_data->current_backend_cfg[idx].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05303451 my_data->current_backend_cfg[idx].format = AUDIO_FORMAT_PCM;
Ashish Jainb26edfb2016-08-25 00:10:11 +05303452 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
3453 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
3454 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08003455 }
3456
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003457 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3458 strdup("SLIM_0_RX Format");
3459 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3460 strdup("SLIM_0_RX SampleRate");
3461
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05303462 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].bitwidth_mixer_ctl =
3463 strdup("SLIM_2_RX Format");
3464 my_data->current_backend_cfg[DSD_NATIVE_BACKEND].samplerate_mixer_ctl =
3465 strdup("SLIM_2_RX SampleRate");
3466
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003467 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
3468 strdup("SLIM_5_RX Format");
3469 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
3470 strdup("SLIM_5_RX SampleRate");
3471
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303472 if (!my_data->is_slimbus_interface) {
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303473 //TODO:: make generic interfaceface to check Slimbus/I2S/CDC_DMA
Meng Wangef2f6e12018-10-08 13:06:05 +08003474 if (!strncmp(snd_card_name, "sm6150", strlen("sm6150")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05303475 !strncmp(snd_card_name, "kona", strlen("kona")) ||
Vatsal Bucha6339b092019-04-17 16:27:32 +05303476 !strncmp(snd_card_name, "lito", strlen("lito")) ||
Faiz Nabi Kuchay536d7b92019-08-05 20:36:31 +05303477 !strncmp(snd_card_name, "atoll", strlen("atoll")) ||
Aditya Bavanari3c8e3572018-12-18 16:44:16 +05303478 !strncmp(snd_card_name, "trinket", strlen("trinket"))) {
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303479 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3480 strdup("WSA_CDC_DMA_RX_0 Format");
3481 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3482 strdup("WSA_CDC_DMA_RX_0 SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303483 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3484 strdup("TX_CDC_DMA_TX_3 Format");
3485 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3486 strdup("TX_CDC_DMA_TX_3 SampleRate");
3487 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3488 strdup("RX_CDC_DMA_RX_0 Format");
3489 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3490 strdup("RX_CDC_DMA_RX_0 SampleRate");
Zhou Songfa2ea2c2019-05-24 22:48:41 +08003491 /*
3492 * TODO: enable CONCURRENT_CAPTURE_ENABLED flag only if separate backend
3493 * is defined for headset-mic. This is to capture separate data from
3494 * headset-mic and handset-mic.
3495 */
3496 if(audio_extn_is_concurrent_capture_enabled()) {
3497 my_data->current_backend_cfg[HEADSET_TX_BACKEND].bitwidth_mixer_ctl =
3498 strdup("TX_CDC_DMA_TX_4 Format");
3499 my_data->current_backend_cfg[HEADSET_TX_BACKEND].samplerate_mixer_ctl =
3500 strdup("TX_CDC_DMA_TX_4 SampleRate");
3501 }
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303502
3503 if (default_rx_backend)
3504 free(default_rx_backend);
3505 default_rx_backend = strdup("WSA_CDC_DMA_RX_0");
3506 } else if (!strncmp(snd_card_name, "sdm660", strlen("sdm660")) ||
Sachin Mohan Gadageffd7562018-02-13 17:10:09 +05303507 !strncmp(snd_card_name, "sdm670", strlen("sdm670")) ||
3508 !strncmp(snd_card_name, "qcs605", strlen("qcs605"))) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303509
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303510
3511 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3512 strdup("INT4_MI2S_RX Format");
3513 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3514 strdup("INT4_MI2S_RX SampleRate");
3515
3516 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3517 strdup("INT3_MI2S_TX Format");
3518 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3519 strdup("INT3_MI2S_TX SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303520 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3521 strdup("INT0_MI2S_RX Format");
3522 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3523 strdup("INT0_MI2S_RX SampleRate");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303524
3525 if (default_rx_backend)
3526 free(default_rx_backend);
3527 default_rx_backend = strdup("INT4_MI2S_RX");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303528 } else {
3529 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3530 strdup("MI2S_RX Format");
3531 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3532 strdup("MI2S_RX SampleRate");
3533 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].channels_mixer_ctl =
3534 strdup("MI2S_RX Channels");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303535 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3536 strdup("MI2S_TX Format");
3537 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3538 strdup("MI2S_TX SampleRate");
Naresh Tanniruc21e2022018-08-13 21:58:06 +05303539 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3540 strdup("INT0_MI2S_RX Format");
3541 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3542 strdup("INT0_MI2S_RX SampleRate");
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303543 }
Revathi Uddaraju75843112017-11-30 14:30:47 +05303544 } else {
Dhananjay Kumar75c9a0c2018-06-07 15:59:00 +05303545 if (!strncmp(snd_card_name, "qcs405", strlen("qcs405"))) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303546
Dieter Luecking5d57def2018-09-07 14:23:37 +02003547 if (!strncmp(snd_card_name, "qcs405-csra", strlen("qcs405-csra"))) {
3548 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3549 strdup("PRIM_MI2S_RX Format");
3550 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3551 strdup("PRIM_MI2S_RX SampleRate");
3552 } else {
3553 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
3554 strdup("WSA_CDC_DMA_RX_0 Format");
3555 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
3556 strdup("WSA_CDC_DMA_RX_0 SampleRate");
3557 }
Dhananjay Kumar75c9a0c2018-06-07 15:59:00 +05303558 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3559 strdup("VA_CDC_DMA_TX_0 Format");
3560 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3561 strdup("VA_CDC_DMA_TX_0 SampleRate");
3562 } else {
3563 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
3564 strdup("SLIM_0_TX Format");
3565 my_data->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
3566 strdup("SLIM_0_TX SampleRate");
3567 }
Yung Ti Suc06f6772018-10-05 15:43:40 +08003568
3569 if (strstr(snd_card_name, "intcodec")) {
3570 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3571 strdup("INT0_MI2S_RX Format");
3572 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3573 strdup("INT0_MI2S_RX SampleRate");
3574 } else {
3575 my_data->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
3576 strdup("SLIM_6_RX Format");
3577 my_data->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
3578 strdup("SLIM_6_RX SampleRate");
3579 }
3580
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303581 //NOTE: enable CONCURRENT_CAPTURE_ENABLED flag only if separate backend is defined
Samyak Jainb3f3ca52019-01-02 18:24:35 +05303582 //for headset-mic. This is to capture separate data from headset-mic and handset-mic.
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303583 if(audio_extn_is_concurrent_capture_enabled()) {
Arun Mirpurie008ed22019-03-21 11:21:04 -07003584 my_data->current_backend_cfg[HEADSET_TX_BACKEND].bitwidth_mixer_ctl =
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303585 strdup("SLIM_1_TX Format");
Arun Mirpurie008ed22019-03-21 11:21:04 -07003586 my_data->current_backend_cfg[HEADSET_TX_BACKEND].samplerate_mixer_ctl =
Samyak Jainfd24f1e2019-04-30 11:58:43 +05303587 strdup("SLIM_1_TX SampleRate");
3588 }
Revathi Uddaraju75843112017-11-30 14:30:47 +05303589 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05303590
Kuirong Wang0b947f72016-09-29 11:03:09 -07003591 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
Kuirong Wange9894162016-08-26 15:16:39 -07003592 strdup("USB_AUDIO_TX Format");
Kuirong Wang0b947f72016-09-29 11:03:09 -07003593 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
Kuirong Wange9894162016-08-26 15:16:39 -07003594 strdup("USB_AUDIO_TX SampleRate");
Kuirong Wang0b947f72016-09-29 11:03:09 -07003595 my_data->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
3596 strdup("USB_AUDIO_TX Channels");
Kuirong Wange9894162016-08-26 15:16:39 -07003597
Ralf Herzafb164f2018-07-03 07:08:07 +02003598 if (!strncmp(platform_get_snd_device_backend_interface(SND_DEVICE_IN_HDMI_MIC),
3599 "SEC_MI2S_TX", sizeof("SEC_MI2S_TX"))) {
3600 my_data->current_backend_cfg[HDMI_TX_BACKEND].bitwidth_mixer_ctl =
3601 strdup("SEC_MI2S_TX Format");
3602 my_data->current_backend_cfg[HDMI_TX_BACKEND].samplerate_mixer_ctl =
3603 strdup("SEC_MI2S_TX SampleRate");
3604 my_data->current_backend_cfg[HDMI_TX_BACKEND].channels_mixer_ctl =
3605 strdup("SEC_MI2S_TX Channels");
3606 } else {
3607 my_data->current_backend_cfg[HDMI_TX_BACKEND].bitwidth_mixer_ctl =
3608 strdup("QUAT_MI2S_TX Format");
3609 my_data->current_backend_cfg[HDMI_TX_BACKEND].samplerate_mixer_ctl =
3610 strdup("QUAT_MI2S_TX SampleRate");
3611 my_data->current_backend_cfg[HDMI_TX_BACKEND].channels_mixer_ctl =
3612 strdup("QUAT_MI2S_TX Channels");
3613 }
3614
3615 my_data->current_backend_cfg[SPDIF_TX_BACKEND].bitwidth_mixer_ctl =
3616 strdup("PRIM_SPDIF_TX Format");
3617 my_data->current_backend_cfg[SPDIF_TX_BACKEND].samplerate_mixer_ctl =
3618 strdup("PRIM_SPDIF_TX SampleRate");
3619 my_data->current_backend_cfg[SPDIF_TX_BACKEND].channels_mixer_ctl =
3620 strdup("PRIM_SPDIF_TX Channels");
3621
3622 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].bitwidth_mixer_ctl =
3623 strdup("SEC_SPDIF_TX Format");
3624 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].samplerate_mixer_ctl =
3625 strdup("SEC_SPDIF_TX SampleRate");
3626 my_data->current_backend_cfg[HDMI_ARC_TX_BACKEND].channels_mixer_ctl =
3627 strdup("SEC_SPDIF_TX Channels");
Siddartha Shaik44dd7702017-06-14 12:13:25 +05303628
mpang00a03542018-11-01 17:05:19 +08003629 my_data->current_backend_cfg[HDMI_RX_BACKEND].bitwidth_mixer_ctl =
3630 strdup("HDMI_RX Bit Format");
3631 my_data->current_backend_cfg[HDMI_RX_BACKEND].samplerate_mixer_ctl =
3632 strdup("HDMI_RX SampleRate");
3633 my_data->current_backend_cfg[HDMI_RX_BACKEND].channels_mixer_ctl =
3634 strdup("HDMI_RX Channels");
3635 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].bitwidth_mixer_ctl =
3636 strdup("Display Port RX Bit Format");
3637 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].samplerate_mixer_ctl =
3638 strdup("Display Port RX SampleRate");
3639 my_data->current_backend_cfg[DISP_PORT_RX_BACKEND].channels_mixer_ctl =
3640 strdup("Display Port RX Channels");
3641
3642 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
3643 strdup("USB_AUDIO_RX Format");
3644 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
3645 strdup("USB_AUDIO_RX SampleRate");
3646 my_data->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
3647 strdup("USB_AUDIO_RX Channels");
3648
`Deeraj Soman676c2702017-09-18 19:25:53 +05303649 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
3650 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
3651 ctl = mixer_get_ctl_by_name(adev->mixer,
3652 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
3653 id_string = platform_get_mixer_control(ctl);
3654 if (id_string) {
3655 cfg_value = audio_extn_utils_get_bit_width_from_string(id_string);
3656 if (cfg_value > 0)
3657 my_data->current_backend_cfg[idx].bit_width = cfg_value;
3658 }
3659 }
3660
3661 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
3662 ctl = mixer_get_ctl_by_name(adev->mixer,
3663 my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
3664 id_string = platform_get_mixer_control(ctl);
3665 if (id_string) {
3666 cfg_value = audio_extn_utils_get_sample_rate_from_string(id_string);
3667 if (cfg_value > 0)
3668 my_data->current_backend_cfg[idx].sample_rate = cfg_value;
3669 }
3670 }
3671
3672 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
3673 ctl = mixer_get_ctl_by_name(adev->mixer,
3674 my_data->current_backend_cfg[idx].channels_mixer_ctl);
3675 id_string = platform_get_mixer_control(ctl);
3676 if (id_string) {
3677 cfg_value = audio_extn_utils_get_channels_from_string(id_string);
3678 if (cfg_value > 0)
3679 my_data->current_backend_cfg[idx].channels = cfg_value;
3680 }
3681 }
3682 }
3683
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +05303684 ret = audio_extn_utils_get_codec_variant(my_data->adev->snd_card,
3685 my_data->codec_variant);
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303686 ret = audio_extn_utils_get_codec_version(snd_card_name,
3687 my_data->adev->snd_card,
3688 my_data->codec_version);
3689
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05303690 /* WCD9370 codec variant only supports Class AB power mode */
3691 if (strstr(my_data->codec_variant, "WCD9370")) {
3692 my_data->is_cls_ab_only_supported = true;
3693 }
3694
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303695 if (NATIVE_AUDIO_MODE_INVALID != platform_get_native_support()) {
3696 /*
3697 * Native playback is enabled from the UI.
3698 */
3699 if(strstr(snd_card_name, "tasha")) {
3700 if (strstr(my_data->codec_version, "WCD9335_1_0") ||
3701 strstr(my_data->codec_version, "WCD9335_1_1")) {
3702 ALOGD("%s:napb: TASHA 1.0 or 1.1 only SRC mode is supported",
3703 __func__);
3704 platform_set_native_support(NATIVE_AUDIO_MODE_SRC);
3705 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05303706 }
Ashish Jain4826f6c2017-02-06 13:33:20 +05303707 if (strstr(snd_card_name, "tavil")) {
3708 ALOGD("%s:DSD playback is supported", __func__);
3709 my_data->is_dsd_supported = true;
3710 my_data->is_asrc_supported = true;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05303711 platform_set_native_support(NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC);
Ashish Jain4826f6c2017-02-06 13:33:20 +05303712 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05303713 }
3714
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05303715 if (property_get_bool("vendor.audio.apptype.multirec.enabled", false))
3716 my_data->use_generic_handset = true;
3717
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05303718 /* Initialize keep alive for HDMI/loopback silence */
3719 audio_extn_keep_alive_init(adev);
3720
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003721 my_data->edid_info = NULL;
Sudheer Papothi4e0ea9a2015-09-30 06:57:51 +05303722 free(snd_card_name);
Eric Laurentb23d5282013-05-14 15:27:20 -07003723 return my_data;
3724}
3725
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303726struct audio_custom_mtmx_params *
3727 platform_get_custom_mtmx_params(void *platform,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303728 struct audio_custom_mtmx_params_info *info,
3729 uint32_t *idx)
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303730{
3731 struct platform_data *my_data = (struct platform_data *)platform;
3732 struct listnode *node = NULL;
3733 struct audio_custom_mtmx_params *params = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303734 int i = 0;
3735
3736 if (!info || !idx) {
3737 ALOGE("%s: Invalid params", __func__);
3738 return NULL;
3739 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303740
3741 list_for_each(node, &my_data->custom_mtmx_params_list) {
3742 params = node_to_item(node, struct audio_custom_mtmx_params, list);
3743 if (params &&
3744 params->info.id == info->id &&
3745 params->info.ip_channels == info->ip_channels &&
3746 params->info.op_channels == info->op_channels &&
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303747 params->info.snd_device == info->snd_device) {
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303748 while (params->info.usecase_id[i] != 0) {
3749 if (params->info.usecase_id[i] == info->usecase_id[0]) {
3750 ALOGV("%s: found params with ip_ch %d op_ch %d uc_id %d snd_dev %d",
3751 __func__, info->ip_channels, info->op_channels,
3752 info->usecase_id[0], info->snd_device);
3753 *idx = i;
3754 return params;
3755 }
3756 i++;
3757 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303758 }
3759 }
3760 ALOGI("%s: no matching param with id %d ip_ch %d op_ch %d uc_id %d snd_dev %d",
3761 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303762 info->usecase_id[0], info->snd_device);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303763 return NULL;
3764}
3765
3766int platform_add_custom_mtmx_params(void *platform,
3767 struct audio_custom_mtmx_params_info *info)
3768{
3769 struct platform_data *my_data = (struct platform_data *)platform;
3770 struct audio_custom_mtmx_params *params = NULL;
3771 uint32_t size = sizeof(*params);
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303772 int i = 0;
3773
3774 if (!info) {
3775 ALOGE("%s: Invalid params", __func__);
3776 return -EINVAL;
3777 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303778
3779 if (info->ip_channels > AUDIO_CHANNEL_COUNT_MAX ||
3780 info->op_channels > AUDIO_CHANNEL_COUNT_MAX) {
3781 ALOGE("%s: unusupported channels in %d, out %d",
3782 __func__, info->ip_channels, info->op_channels);
3783 return -EINVAL;
3784 }
3785
3786 size += sizeof(params->coeffs[0]) * info->ip_channels * info->op_channels;
3787 params = (struct audio_custom_mtmx_params *) calloc(1, size);
3788 if (!params) {
3789 ALOGE("%s: failed to add custom mtmx params", __func__);
3790 return -ENOMEM;
3791 }
3792
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303793 ALOGI("%s: adding mtmx params with id %d ip_ch %d op_ch %d snd_dev %d",
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303794 __func__, info->id, info->ip_channels, info->op_channels,
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303795 info->snd_device);
3796 while (info->usecase_id[i] != 0) {
3797 ALOGI("%s: supported usecase ids for added mtmx params %d",
3798 __func__, info->usecase_id[i]);
3799 i++;
3800 }
Dhananjay Kumar429eb452018-12-10 22:26:53 +05303801
3802 params->info = *info;
3803 list_add_tail(&my_data->custom_mtmx_params_list, &params->list);
3804 return 0;
3805}
3806
3807static void platform_release_custom_mtmx_params(void *platform)
3808{
3809 struct platform_data *my_data = (struct platform_data *)platform;
3810 struct listnode *node = NULL, *tempnode = NULL;
3811
3812 list_for_each_safe(node, tempnode, &my_data->custom_mtmx_params_list) {
3813 list_remove(node);
3814 free(node_to_item(node, struct audio_custom_mtmx_params, list));
3815 }
3816}
Sujin Panickerb904fbe2019-04-04 13:28:07 +05303817
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303818struct audio_custom_mtmx_in_params *platform_get_custom_mtmx_in_params(void *platform,
3819 struct audio_custom_mtmx_in_params_info *info)
3820{
3821 struct platform_data *my_data = (struct platform_data *)platform;
3822 struct listnode *node = NULL;
3823 struct audio_custom_mtmx_in_params *params = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303824 int i = 0;
3825
3826 if (!info) {
3827 ALOGE("%s: Invalid params", __func__);
3828 return NULL;
3829 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303830
3831 list_for_each(node, &my_data->custom_mtmx_in_params_list) {
3832 params = node_to_item(node, struct audio_custom_mtmx_in_params, list);
3833 if (params &&
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303834 params->in_info.op_channels == info->op_channels) {
3835 while (params->in_info.usecase_id[i] != 0) {
3836 if (params->in_info.usecase_id[i] == info->usecase_id[0]) {
3837 ALOGV("%s: found params with op_ch %d uc_id %d",
3838 __func__, info->op_channels, info->usecase_id[0]);
3839 return params;
3840 }
3841 i++;
3842 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303843 }
3844 }
3845
3846 ALOGI("%s: no matching param with op_ch %d uc_id %d",
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303847 __func__, info->op_channels, info->usecase_id[0]);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303848 return NULL;
3849}
3850
3851int platform_add_custom_mtmx_in_params(void *platform,
3852 struct audio_custom_mtmx_in_params_info *info)
3853{
3854 struct platform_data *my_data = (struct platform_data *)platform;
3855 struct audio_custom_mtmx_in_params *params = NULL;
3856 uint32_t size = sizeof(*params);
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303857 int i = 0;
3858
3859 if (!info) {
3860 ALOGE("%s: Invalid params", __func__);
3861 return -EINVAL;
3862 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303863
3864 if (info->op_channels > AUDIO_CHANNEL_COUNT_MAX) {
3865 ALOGE("%s: unusupported channels in %d", __func__, info->op_channels);
3866 return -EINVAL;
3867 }
3868
3869 params = (struct audio_custom_mtmx_in_params *)calloc(1, size);
3870 if (!params) {
3871 ALOGE("%s: failed to add custom mtmx in params", __func__);
3872 return -ENOMEM;
3873 }
3874
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05303875 ALOGI("%s: adding mtmx in params with op_ch %d",
3876 __func__, info->op_channels);
3877
3878 while (info->usecase_id[i] != 0) {
3879 ALOGI("%s: supported usecase ids for added mtmx in params %d",
3880 __func__, info->usecase_id[i]);
3881 i++;
3882 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05303883
3884 params->in_info = *info;
3885 list_add_tail(&my_data->custom_mtmx_in_params_list, &params->list);
3886 return 0;
3887}
3888
3889static void platform_release_custom_mtmx_in_params(void *platform)
3890{
3891 struct platform_data *my_data = (struct platform_data *)platform;
3892 struct listnode *node = NULL, *tempnode = NULL;
3893
3894 list_for_each_safe(node, tempnode, &my_data->custom_mtmx_in_params_list) {
3895 list_remove(node);
3896 free(node_to_item(node, struct audio_custom_mtmx_in_params, list));
3897 }
3898}
3899
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05303900void platform_release_acdb_metainfo_key(void *platform)
3901{
3902 struct platform_data *my_data = (struct platform_data *)platform;
3903 struct listnode *node, *tempnode;
3904
3905 list_for_each_safe(node, tempnode, &my_data->acdb_meta_key_list) {
3906 list_remove(node);
3907 free(node_to_item(node, struct meta_key_list, list));
3908 }
3909}
3910
Eric Laurentb23d5282013-05-14 15:27:20 -07003911void platform_deinit(void *platform)
3912{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003913 struct platform_data *my_data = (struct platform_data *)platform;
Aalique Grahame22e49102018-12-18 14:23:57 -08003914 struct operator_info *info_item;
3915 struct operator_specific_device *device_item;
Carter Hsu32a62362018-10-15 15:01:42 -07003916 struct external_specific_device *ext_dev;
Aalique Grahame22e49102018-12-18 14:23:57 -08003917 struct app_type_entry *ap;
3918 struct listnode *node;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003919
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05303920 audio_extn_keep_alive_deinit();
3921
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003922 if (my_data->edid_info) {
3923 free(my_data->edid_info);
3924 my_data->edid_info = NULL;
3925 }
3926
Siena Richard7c2db772016-12-21 11:32:34 -08003927 if (be_dai_name_table) {
3928 free((void *)be_dai_name_table);
3929 be_dai_name_table = NULL;
3930 }
3931
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303932 if (my_data->hw_dep_fd >= 0) {
3933 close(my_data->hw_dep_fd);
3934 my_data->hw_dep_fd = -1;
3935 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05303936 if (default_rx_backend)
3937 free(default_rx_backend);
Venkata Narendra Kumar Guttae071e5a2016-01-11 18:08:26 +05303938
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07003939 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08003940 close_csd_client(my_data->csd);
3941
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003942 int32_t dev;
3943 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05303944 if (backend_tag_table[dev]) {
3945 free(backend_tag_table[dev]);
3946 backend_tag_table[dev]= NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003947 }
Aalique Grahame22e49102018-12-18 14:23:57 -08003948
3949 if (hw_interface_table[dev]) {
3950 free(hw_interface_table[dev]);
3951 hw_interface_table[dev] = NULL;
3952 }
3953
3954 if (operator_specific_device_table[dev]) {
3955 while (!list_empty(operator_specific_device_table[dev])) {
3956 node = list_head(operator_specific_device_table[dev]);
3957 list_remove(node);
3958 device_item = node_to_item(node,
3959 struct operator_specific_device, list);
3960 free(device_item->operator);
3961 device_item->operator = NULL;
3962 free(device_item->mixer_path);
3963 device_item->mixer_path = NULL;
3964 free(device_item);
3965 device_item = NULL;
3966 }
3967 free(operator_specific_device_table[dev]);
3968 operator_specific_device_table[dev] = NULL;
3969 }
Carter Hsu32a62362018-10-15 15:01:42 -07003970
3971 if (external_specific_device_table[dev]) {
3972 while (!list_empty(external_specific_device_table[dev])) {
3973 node = list_head(external_specific_device_table[dev]);
3974 list_remove(node);
3975 ext_dev = node_to_item(node, struct external_specific_device, list);
3976 free(ext_dev->usbid);
3977 free(ext_dev);
3978 }
3979 free(external_specific_device_table[dev]);
3980 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003981 }
3982
Aalique Grahame22e49102018-12-18 14:23:57 -08003983 while (!list_empty(&operator_info_list)) {
3984 node = list_head(&operator_info_list);
3985 list_remove(node);
3986 info_item = node_to_item(node, struct operator_info, list);
3987 free(info_item->name);
3988 info_item->name = NULL;
3989 free(info_item->mccmnc);
3990 info_item->mccmnc = NULL;
3991 free(info_item);
3992 info_item = NULL;
3993 }
3994
3995 while (!list_empty(&app_type_entry_list)) {
3996 node = list_head(&app_type_entry_list);
3997 list_remove(node);
3998 ap = node_to_item(node, struct app_type_entry, node);
3999 if (ap->mode) {
4000 free(ap->mode);
4001 ap->mode = NULL;
4002 }
4003 free(ap);
4004 ap = NULL;
4005 }
4006
Lior Barenboim0b61bc72014-05-13 13:01:37 +03004007 /* deinit audio device arbitration */
4008 audio_extn_dev_arbi_deinit();
4009
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07004010 if (my_data->edid_info) {
4011 free(my_data->edid_info);
4012 my_data->edid_info = NULL;
4013 }
4014
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05304015 if (my_data->adev->mixer) {
Soumya Managoli9fee7c62018-04-06 16:21:50 +05304016 audio_extn_utils_close_snd_mixer(my_data->adev->mixer);
Dhananjay Kumara5ba5f22016-11-30 16:01:29 +05304017 my_data->adev->mixer = NULL;
4018 }
4019
Naresh Tannirucb5b5782018-10-12 20:42:07 +05304020
4021
Surendar Karka45850ae2018-07-02 17:45:27 +05304022 if (my_data->spkr_ch_map) {
4023 free(my_data->spkr_ch_map);
4024 my_data->spkr_ch_map = NULL;
4025 }
4026
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05304027 int32_t idx;
4028
4029 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
4030 if (my_data->current_backend_cfg[idx].bitwidth_mixer_ctl) {
4031 free(my_data->current_backend_cfg[idx].bitwidth_mixer_ctl);
4032 my_data->current_backend_cfg[idx].bitwidth_mixer_ctl = NULL;
4033 }
4034
4035 if (my_data->current_backend_cfg[idx].samplerate_mixer_ctl) {
4036 free(my_data->current_backend_cfg[idx].samplerate_mixer_ctl);
4037 my_data->current_backend_cfg[idx].samplerate_mixer_ctl = NULL;
4038 }
4039
4040 if (my_data->current_backend_cfg[idx].channels_mixer_ctl) {
4041 free(my_data->current_backend_cfg[idx].channels_mixer_ctl);
4042 my_data->current_backend_cfg[idx].channels_mixer_ctl = NULL;
4043 }
4044 }
4045
4046 /* free acdb_meta_key_list */
4047 platform_release_acdb_metainfo_key(platform);
Dhananjay Kumar429eb452018-12-10 22:26:53 +05304048 platform_release_custom_mtmx_params(platform);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05304049 platform_release_custom_mtmx_in_params(platform);
Ramu Gottipati62f6d9b2018-05-01 15:21:38 +05304050
Aditya Bavanaric1c1ba62018-06-08 16:33:43 +05304051 if (my_data->acdb_deallocate)
4052 my_data->acdb_deallocate();
4053
Eric Laurentb23d5282013-05-14 15:27:20 -07004054 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07004055 /* deinit usb */
4056 audio_extn_usb_deinit();
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07004057 audio_extn_dap_hal_deinit();
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +05304058#ifdef DYNAMIC_LOG_ENABLED
4059 log_utils_deinit();
4060#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07004061}
4062
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004063static int platform_is_acdb_initialized(void *platform)
Ramjee Singh203473b2015-06-09 15:18:42 +05304064{
4065 struct platform_data *my_data = (struct platform_data *)platform;
4066 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
4067 return my_data->is_acdb_initialized;
4068}
4069
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05304070void platform_snd_card_update(void *platform, card_status_t card_status)
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004071{
4072 struct platform_data *my_data = (struct platform_data *)platform;
4073
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05304074 if (card_status == CARD_STATUS_ONLINE) {
Ben Rombergerfeca4b82015-07-07 20:40:44 -07004075 if (!platform_is_acdb_initialized(my_data)) {
4076 if(platform_acdb_init(my_data))
4077 ALOGE("%s: acdb initialization is failed", __func__);
4078 } else if (my_data->acdb_send_common_top() < 0) {
4079 ALOGD("%s: acdb did not set common topology", __func__);
4080 }
4081 }
4082}
4083
Eric Laurentb23d5282013-05-14 15:27:20 -07004084const char *platform_get_snd_device_name(snd_device_t snd_device)
4085{
Aalique Grahame22e49102018-12-18 14:23:57 -08004086 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
4087 if (operator_specific_device_table[snd_device] != NULL) {
4088 return get_operator_specific_device_mixer_path(snd_device);
4089 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004090 return device_table[snd_device];
Aalique Grahame22e49102018-12-18 14:23:57 -08004091 } else
Eric Laurentb23d5282013-05-14 15:27:20 -07004092 return "";
4093}
4094
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07004095int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
4096 char *device_name)
4097{
4098 struct platform_data *my_data = (struct platform_data *)platform;
4099
4100 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
Aalique Grahame22e49102018-12-18 14:23:57 -08004101 if (operator_specific_device_table[snd_device] != NULL) {
4102 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
4103 DEVICE_NAME_MAX_SIZE);
4104 } else
4105 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07004106 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
4107 } else {
4108 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
4109 return -EINVAL;
4110 }
4111
4112 return 0;
4113}
4114
Banajit Goswami20cdd212015-09-11 01:11:30 -07004115void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,
4116 struct audio_usecase *usecase)
Eric Laurentb23d5282013-05-14 15:27:20 -07004117{
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004118 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4119 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4120 return;
4121 }
4122
Rohit kumarf4120402016-08-05 19:19:48 +05304123 if ((snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
4124 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07004125 !(usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)) {
4126 ALOGI("%s: Not adding vbat speaker device to non voice use cases", __func__);
4127 return;
4128 }
4129
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304130 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004131
4132 if (suffix != NULL) {
4133 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
4134 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
Aalique Grahame37659862017-12-03 22:34:26 -08004135
4136 /* if we can use display-port for voice call and usb mic
4137 * is connected, choose dp_rx, usb_tx audio route
4138 */
4139 if (usecase->type == VOICE_CALL) {
4140 struct audio_device *adev = usecase->stream.out->dev;
4141 if ((snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
4142 adev->dp_allowed_for_voice &&
4143 (usecase->in_snd_device == SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)) {
4144 strlcat(mixer_path, "-and-usb-headset-mic", MIXER_PATH_MAX_LENGTH);
4145 }
4146 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08004147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004148}
4149
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304150bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
4151{
4152 bool result = true;
4153
4154 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
4155 platform_get_snd_device_name(snd_device1),
4156 platform_get_snd_device_name(snd_device2));
4157
4158 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_OUT_END)) {
4159 ALOGE("%s: Invalid snd_device = %s", __func__,
4160 platform_get_snd_device_name(snd_device1));
4161 return false;
4162 }
4163 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_OUT_END)) {
4164 ALOGE("%s: Invalid snd_device = %s", __func__,
4165 platform_get_snd_device_name(snd_device2));
4166 return false;
4167 }
4168 const char * be_itf1 = hw_interface_table[snd_device1];
4169 const char * be_itf2 = hw_interface_table[snd_device2];
4170
4171 if (NULL != be_itf1 && NULL != be_itf2) {
Kuirong Wangb9fbb1e2016-05-03 18:36:39 -07004172 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304173 result = false;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05304174 } else if (NULL == be_itf1 && NULL != be_itf2 && (NULL == strstr(be_itf2, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304175 result = false;
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05304176 } else if (NULL != be_itf1 && NULL == be_itf2 && (NULL == strstr(be_itf1, default_rx_backend))) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304177 result = false;
4178 }
4179
4180 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
4181 return result;
4182}
4183
Eric Laurentb23d5282013-05-14 15:27:20 -07004184int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
4185{
Mingshu Pang1513f972019-05-24 12:43:51 +08004186 int device_id = -1;
4187
4188 if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
4189 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
4190 return device_id;
4191 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004192 if (device_type == PCM_PLAYBACK)
4193 device_id = pcm_device_table[usecase][0];
4194 else
4195 device_id = pcm_device_table[usecase][1];
4196 return device_id;
4197}
4198
Vignesh Kulothungana6927272019-02-20 15:17:07 -08004199int platform_get_haptics_pcm_device_id()
4200{
4201 return HAPTICS_PCM_DEVICE;
4202}
4203
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004204uint64_t getQtime()
4205{
4206 uint64_t qTimerCount = 0;
4207
4208#if __aarch64__
4209 asm volatile("mrs %0, cntvct_el0" : "=r" (qTimerCount));
4210#else
4211 asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (qTimerCount));
4212#endif
4213
4214 return qTimerCount;
4215}
4216
4217int platform_get_delay(void *platform, int pcm_device_id)
4218{
4219 int ctl_len = 0;
Mingshu Pang1513f972019-05-24 12:43:51 +08004220 struct audio_device *adev = NULL;
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004221 struct mixer_ctl *ctl = NULL;
4222 const char *mixer_ctl_name = "ADSP Path Latency";
4223 const char *deviceNo = "NN";
4224 char *mixer_str = NULL;
4225 int path_delay = 0;
4226
4227 if (NULL == platform) {
4228 ALOGE("%s: platform is NULL", __func__);
4229 return -EINVAL;
4230 }
4231 if (pcm_device_id <= 0) {
4232 ALOGE("%s: invalid pcm device id: %d", __func__, pcm_device_id);
4233 return -EINVAL;
4234 }
4235
Mingshu Pang1513f972019-05-24 12:43:51 +08004236 adev = ((struct platform_data *)platform)->adev;
4237
Vignesh Kulothungane4039c12019-05-07 15:51:39 -07004238 // Mixer control format: "ADSP Path Latency NN"
4239 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
4240
4241 mixer_str = (char*) calloc(ctl_len, sizeof(char));
4242 if (!mixer_str) {
4243 ALOGE("%s: Could not allocate memory", __func__);
4244 return -ENOMEM;
4245 }
4246
4247 snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, pcm_device_id);
4248
4249 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_str);
4250 if (!ctl) {
4251 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, mixer_str);
4252 free(mixer_str);
4253 return -EINVAL;
4254 }
4255
4256 path_delay = mixer_ctl_get_value(ctl, 0);
4257 if (path_delay < 0) {
4258 ALOGE("%s: Could not get val for mixer cmd - %s", __func__, mixer_str);
4259 }
4260 ALOGD("%s: Path Delay: %d", __func__, path_delay);
4261
4262 free(mixer_str);
4263 return path_delay;
4264}
4265
4266int send_qtime(void *platform, uint64_t qtime_value, int pcm_device_id)
4267{
4268 int ret = 0;
4269 int ctl_len = 0;
4270 struct audio_device *adev = ((struct platform_data *)platform)->adev;
4271 struct mixer_ctl *ctl = NULL;
4272 const char *mixer_ctl_name = "QTimer";
4273 const char *deviceNo = "NN";
4274 char *mixer_str = NULL;
4275 uint32_t set_values[2];
4276
4277 set_values[0] = (uint32_t)qtime_value;
4278 set_values[1] = (uint32_t)((qtime_value >> 16) >> 16);
4279 ALOGD("%s: Send qtime msw: %u, lsw: %u", __func__, set_values[1],
4280 set_values[0]);
4281
4282 // Mixer control format: "Qtimer NN"
4283 ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
4284
4285 mixer_str = (char*) calloc(ctl_len, sizeof(char));
4286 if (!mixer_str) {
4287 ALOGE("%s: Could not allocate memory", __func__);
4288 return -ENOMEM;
4289 }
4290
4291 snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, pcm_device_id);
4292
4293 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_str);
4294 if (!ctl) {
4295 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4296 __func__, mixer_str);
4297 free(mixer_str);
4298 return -EINVAL;
4299 }
4300
4301 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4302 if (ret < 0) {
4303 ALOGE("%s: Could not set array for mixer cmd - %s",
4304 __func__, mixer_str);
4305 }
4306 free(mixer_str);
4307
4308 return ret;
4309}
4310
4311int platform_set_qtime(void *platform, int audio_pcm_device_id,
4312 int haptic_pcm_device_id)
4313{
4314 int ret = 0;
4315 uint64_t qtime_count = 0;
4316 uint64_t qtime_value = 0;
4317 uint32_t qtime_remainder = 0;
4318 int32_t audio_path_latency = 0;
4319 int32_t haptic_path_latency = 0;
4320
4321 if (NULL == platform) {
4322 ALOGE("%s: platform is NULL", __func__);
4323 return -EINVAL;
4324 }
4325 if (audio_pcm_device_id <= 0 || haptic_pcm_device_id <= 0) {
4326 ALOGE("%s: Invalid pcm device id - %d", __func__,
4327 audio_pcm_device_id <= 0 ? audio_pcm_device_id
4328 : haptic_pcm_device_id);
4329 return -EINVAL;
4330 }
4331
4332 audio_path_latency = platform_get_delay(platform, audio_pcm_device_id);
4333 if (audio_path_latency <= 0) {
4334 ALOGE("%s: error getting audio path latency: %d", __func__,
4335 audio_path_latency);
4336 return -EINVAL;
4337 }
4338 ALOGD("%s: Audio Path Latency: %d", __func__, audio_path_latency);
4339
4340 haptic_path_latency = platform_get_delay(platform, haptic_pcm_device_id);
4341 if (haptic_path_latency <= 0) {
4342 ALOGE("%s: error getting haptic path latency: %d", __func__,
4343 haptic_path_latency);
4344 return -EINVAL;
4345 }
4346 ALOGD("%s: Haptic Path Latency: %d", __func__, haptic_path_latency);
4347
4348 qtime_count = getQtime();
4349
4350 // Qtime count / Qtime freq (KHZ) = Qtime in milliseconds
4351 qtime_value = (uint64_t) (qtime_count / QTIME_FREQ_KHZ);
4352
4353 // Convert Qtime to microseconds
4354 qtime_value *= 1000;
4355
4356 // Adding max(path_latency)
4357 qtime_value += (uint32_t) max(audio_path_latency, haptic_path_latency);
4358
4359 // Adding IPC delay + error correction ~10ms
4360 qtime_value += IPC_ERROR_DELAY;
4361
4362 // Calculate remainder in microseconds
4363 qtime_remainder = ((qtime_count % QTIME_FREQ_KHZ) * 1000) / QTIME_FREQ_KHZ;
4364
4365 // Add the remainder to qtime
4366 qtime_value += qtime_remainder;
4367 ALOGD("%s: Set qtime: %llu microsecs\n", __func__,
4368 (unsigned long long int)qtime_value);
4369
4370 ret = send_qtime(platform, qtime_value, haptic_pcm_device_id);
4371 if (ret < 0) {
4372 ALOGE("%s: Could not send qtime for haptic session - %d",
4373 __func__, ret);
4374 return ret;
4375 }
4376
4377 ret = send_qtime(platform, qtime_value, audio_pcm_device_id);
4378 if (ret < 0) {
4379 ALOGE("%s: Could not send qtime for audio session - %d",
4380 __func__, ret);
4381 }
4382
4383 return ret;
4384}
4385
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004386static int find_index(struct name_to_index * table, int32_t len, const char * name)
Ben Romberger61764e32014-01-10 13:49:02 -08004387{
4388 int ret = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004389 int32_t i;
Ben Romberger61764e32014-01-10 13:49:02 -08004390
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004391 if (table == NULL) {
4392 ALOGE("%s: table is NULL", __func__);
Ben Romberger61764e32014-01-10 13:49:02 -08004393 ret = -ENODEV;
4394 goto done;
4395 }
4396
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004397 if (name == NULL) {
4398 ALOGE("null key");
4399 ret = -ENODEV;
4400 goto done;
4401 }
4402
4403 for (i=0; i < len; i++) {
4404 const char* tn = table[i].name;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07004405 size_t len = strlen(tn);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004406 if (strncmp(tn, name, len) == 0) {
4407 if (strlen(name) != len) {
4408 continue; // substring
4409 }
4410 ret = table[i].index;
Ben Romberger61764e32014-01-10 13:49:02 -08004411 goto done;
4412 }
4413 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004414 ALOGE("%s: Could not find index for name = %s",
4415 __func__, name);
Ben Romberger61764e32014-01-10 13:49:02 -08004416 ret = -ENODEV;
4417done:
4418 return ret;
4419}
4420
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05304421int platform_set_fluence_type(void *platform, char *value)
4422{
4423 int ret = 0;
4424 int fluence_type = FLUENCE_NONE;
4425 int fluence_flag = NONE_FLAG;
4426 struct platform_data *my_data = (struct platform_data *)platform;
4427 struct audio_device *adev = my_data->adev;
4428
4429 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
4430
4431 /* only dual mic turn on and off is supported as of now through setparameters */
4432 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
4433 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
4434 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
4435 ALOGV("fluence dualmic feature enabled \n");
4436 fluence_type = FLUENCE_DUAL_MIC;
4437 fluence_flag = DMIC_FLAG;
4438 } else {
4439 ALOGE("%s: Failed to set DUALMIC", __func__);
4440 ret = -1;
4441 goto done;
4442 }
4443 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
4444 ALOGV("fluence disabled");
4445 fluence_type = FLUENCE_NONE;
4446 } else {
4447 ALOGE("Invalid fluence value : %s",value);
4448 ret = -1;
4449 goto done;
4450 }
4451
4452 if (fluence_type != my_data->fluence_type) {
4453 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
4454 my_data->fluence_type = fluence_type;
4455 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
4456 }
4457done:
4458 return ret;
4459}
4460
4461int platform_get_fluence_type(void *platform, char *value, uint32_t len)
4462{
4463 int ret = 0;
4464 struct platform_data *my_data = (struct platform_data *)platform;
4465
4466 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
4467 strlcpy(value, "quadmic", len);
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07004468 } else if (my_data->fluence_type == FLUENCE_TRI_MIC) {
4469 strlcpy(value, "trimic", len);
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05304470 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
4471 strlcpy(value, "dualmic", len);
4472 } else if (my_data->fluence_type == FLUENCE_NONE) {
4473 strlcpy(value, "none", len);
4474 } else
4475 ret = -1;
4476
4477 return ret;
4478}
4479
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07004480int platform_get_snd_device_index(char *device_name)
4481{
4482 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
4483}
4484
4485int platform_get_usecase_index(const char *usecase_name)
4486{
4487 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
4488}
4489
Aalique Grahame22e49102018-12-18 14:23:57 -08004490void platform_add_operator_specific_device(snd_device_t snd_device,
4491 const char *operator,
4492 const char *mixer_path,
4493 unsigned int acdb_id)
4494{
4495 struct operator_specific_device *device;
4496
4497 if (operator_specific_device_table[snd_device] == NULL) {
4498 operator_specific_device_table[snd_device] =
4499 (struct listnode *)calloc(1, sizeof(struct listnode));
4500 list_init(operator_specific_device_table[snd_device]);
4501 }
4502
4503 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
Weiyin Jiang2995f662019-04-17 14:25:12 +08004504 if (device == NULL) {
4505 ALOGE("%s: memory allocation failed", __func__);
4506 return;
4507 }
Aalique Grahame22e49102018-12-18 14:23:57 -08004508
4509 device->operator = strdup(operator);
4510 device->mixer_path = strdup(mixer_path);
4511 device->acdb_id = acdb_id;
4512
4513 list_add_tail(operator_specific_device_table[snd_device], &device->list);
4514
4515 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
4516 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
4517
4518}
4519
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004520int platform_get_effect_config_data(snd_device_t snd_device,
4521 struct audio_effect_config *effect_config,
4522 effect_type_t effect_type)
4523{
4524 int ret = 0;
4525
4526 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
4527 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
4528 ALOGE("%s: Invalid snd_device = %d",
4529 __func__, snd_device);
4530 ret = -EINVAL;
4531 goto done;
4532 }
4533
Weiyin Jiang301dac62019-05-08 13:58:00 +08004534 if (effect_config == NULL) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004535 ALOGE("%s: Invalid effect_config", __func__);
4536 ret = -EINVAL;
4537 goto done;
4538 }
4539
4540 ALOGV("%s: snd_device = %d module_id = %d",
4541 __func__, snd_device, effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type].module_id);
4542 memcpy(effect_config, &effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type],
4543 sizeof(struct audio_effect_config));
4544
4545done:
4546 return ret;
4547}
4548
Carter Hsu32a62362018-10-15 15:01:42 -07004549void platform_add_external_specific_device(snd_device_t snd_device,
4550 const char *usbid,
4551 unsigned int acdb_id)
4552{
4553 struct external_specific_device *device;
4554
4555 if (external_specific_device_table[snd_device] == NULL) {
4556 external_specific_device_table[snd_device] =
4557 (struct listnode *)calloc(1, sizeof(struct listnode));
4558 list_init(external_specific_device_table[snd_device]);
4559 }
4560
4561 device = (struct external_specific_device *)calloc(1, sizeof(struct external_specific_device));
Weiyin Jiang301dac62019-05-08 13:58:00 +08004562 if (device == NULL) {
4563 ALOGE("%s: memory allocation failed", __func__);
4564 return;
4565 }
Carter Hsu32a62362018-10-15 15:01:42 -07004566
4567 device->usbid = strdup(usbid);
4568 device->acdb_id = acdb_id;
4569
4570 list_add_tail(external_specific_device_table[snd_device], &device->list);
4571
4572 ALOGD("%s: device[%s] usbid[%s] -> acdb_id[%d]", __func__,
4573 platform_get_snd_device_name(snd_device), usbid, acdb_id);
4574}
4575
Ben Romberger55886882014-01-10 13:49:02 -08004576int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
4577{
4578 int ret = 0;
4579
4580 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4581 ALOGE("%s: Invalid snd_device = %d",
4582 __func__, snd_device);
4583 ret = -EINVAL;
4584 goto done;
4585 }
4586
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304587 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
4588 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Ben Romberger55886882014-01-10 13:49:02 -08004589 acdb_device_table[snd_device] = acdb_id;
4590done:
4591 return ret;
4592}
4593
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07004594int platform_set_effect_config_data(snd_device_t snd_device,
4595 struct audio_effect_config effect_config,
4596 effect_type_t effect_type)
4597{
4598 int ret = 0;
4599
4600 if ((snd_device < SND_DEVICE_IN_BEGIN) || (snd_device >= SND_DEVICE_MAX) ||
4601 (effect_type <= EFFECT_NONE) || (effect_type >= EFFECT_MAX)) {
4602 ALOGE("%s: Invalid snd_device = %d",
4603 __func__, snd_device);
4604 ret = -EINVAL;
4605 goto done;
4606 }
4607
4608 ALOGV("%s 0x%x 0x%x 0x%x 0x%x", __func__, effect_config.module_id,
4609 effect_config.instance_id, effect_config.param_id,
4610 effect_config.param_value);
4611 effect_config_table[GET_IN_DEVICE_INDEX(snd_device)][effect_type] = effect_config;
4612
4613done:
4614 return ret;
4615}
4616
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05304617int platform_set_acdb_metainfo_key(void *platform, char *name, int key)
4618{
4619 struct meta_key_list *key_info;
4620 struct platform_data *pdata = (struct platform_data *)platform;
4621
4622 key_info = (struct meta_key_list *)calloc(1, sizeof(struct meta_key_list));
4623 if (!key_info) {
4624 ALOGE("%s: Could not allocate memory for key %d", __func__, key);
4625 return -ENOMEM;
4626 }
4627
4628 key_info->cal_info.nKey = key;
4629 strlcpy(key_info->name, name, sizeof(key_info->name));
4630 list_add_tail(&pdata->acdb_meta_key_list, &key_info->list);
4631
4632 ALOGD("%s: successfully added module %s and key %d to the list", __func__,
4633 key_info->name, key_info->cal_info.nKey);
4634 return 0;
4635}
4636
4637int platform_get_meta_info_key_from_list(void *platform, char *mod_name)
4638{
4639 struct listnode *node;
4640 struct meta_key_list *key_info;
4641 struct platform_data *pdata = (struct platform_data *)platform;
4642 int key = 0;
4643
4644 ALOGV("%s: for module %s", __func__, mod_name);
4645
4646 list_for_each(node, &pdata->acdb_meta_key_list) {
4647 key_info = node_to_item(node, struct meta_key_list, list);
4648 if (strcmp(key_info->name, mod_name) == 0) {
4649 key = key_info->cal_info.nKey;
4650 ALOGD("%s: Found key %d for module %s", __func__, key, mod_name);
4651 break;
4652 }
4653 }
4654 return key;
4655}
4656
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07004657int platform_get_default_app_type(void *platform)
4658{
4659 struct platform_data *my_data = (struct platform_data *)platform;
4660
4661 if (my_data->acdb_get_default_app_type)
4662 return my_data->acdb_get_default_app_type();
4663 else
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05304664 return DEFAULT_APP_TYPE_RX_PATH;
4665}
4666
4667int platform_get_default_app_type_v2(void *platform, usecase_type_t type)
4668{
Alexy Josephb1379942016-01-29 15:49:38 -08004669 ALOGV("%s: Platform: %p, type: %d", __func__, platform, type);
Srikanth Uyyalaa1e32352015-10-09 14:48:04 +05304670 if(type == PCM_CAPTURE)
4671 return DEFAULT_APP_TYPE_TX_PATH;
4672 else
4673 return DEFAULT_APP_TYPE_RX_PATH;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07004674}
4675
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07004676int platform_get_snd_device_acdb_id(snd_device_t snd_device)
4677{
4678 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4679 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
4680 return -EINVAL;
4681 }
Aalique Grahame22e49102018-12-18 14:23:57 -08004682
4683 /*
4684 * If speaker protection is enabled, function returns supported
4685 * sound device for speaker. Else same sound device is returned.
4686 */
4687 snd_device = platform_get_spkr_prot_snd_device(snd_device);
4688
4689 if (operator_specific_device_table[snd_device] != NULL)
4690 return get_operator_specific_device_acdb_id(snd_device);
Carter Hsu32a62362018-10-15 15:01:42 -07004691 else if (external_specific_device_table[snd_device] != NULL)
4692 return get_external_specific_device_acdb_id(snd_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08004693 else
4694 return acdb_device_table[snd_device];
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07004695}
4696
Amit Shekhar5a39c912014-10-14 15:39:30 -07004697int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
4698{
4699 int ret = 0;
4700
4701 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4702 ALOGE("%s: Invalid snd_device = %d",
4703 __func__, snd_device);
4704 ret = -EINVAL;
4705 goto done;
4706 }
4707
4708 backend_bit_width_table[snd_device] = bit_width;
4709done:
4710 return ret;
4711}
4712
4713int platform_get_snd_device_bit_width(snd_device_t snd_device)
4714{
4715 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
4716 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
Ashish Jain058165c2016-09-28 23:18:48 +05304717 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -07004718 }
4719 return backend_bit_width_table[snd_device];
4720}
4721
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304722int platform_set_native_support(int na_mode)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004723{
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304724 if (NATIVE_AUDIO_MODE_SRC == na_mode || NATIVE_AUDIO_MODE_TRUE_44_1 == na_mode
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304725 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode
4726 || NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP == na_mode) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304727 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
4728 na_props.na_mode = na_mode;
Ashish Jain6fced6e2017-01-09 14:13:22 +05304729 ALOGD("%s:napb: native audio playback enabled in (%s) mode", __func__,
4730 ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC":
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304731 (na_mode == NATIVE_AUDIO_MODE_TRUE_44_1)?"True":
4732 (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC)?"Multiple_Mix_Codec":"Multiple_Mix_DSP"));
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304733 }
4734 else {
4735 na_props.platform_na_prop_enabled = false;
4736 na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
4737 ALOGD("%s:napb: native audio playback disabled", __func__);
4738 }
4739
4740 return 0;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004741}
4742
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304743bool platform_check_codec_dsd_support(void *platform)
4744{
4745 struct platform_data *my_data = (struct platform_data *)platform;
4746 return my_data->is_dsd_supported;
4747}
4748
Preetam Singh Ranawatb0c0dd72016-08-18 00:32:06 +05304749bool platform_check_codec_asrc_support(void *platform)
4750{
4751 struct platform_data *my_data = (struct platform_data *)platform;
4752 return my_data->is_asrc_supported;
4753}
4754
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004755int platform_get_native_support()
4756{
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304757 int ret = NATIVE_AUDIO_MODE_INVALID;
4758 if (na_props.platform_na_prop_enabled &&
4759 na_props.ui_na_prop_enabled) {
4760 ret = na_props.na_mode;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004761 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304762 ALOGV("%s:napb: ui Prop enabled(%d) version(%d)", __func__,
4763 na_props.ui_na_prop_enabled, na_props.na_mode);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004764 return ret;
4765}
4766
4767void native_audio_get_params(struct str_parms *query,
4768 struct str_parms *reply,
4769 char *value, int len)
4770{
4771 int ret;
4772 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4773 value, len);
4774 if (ret >= 0) {
4775 if (na_props.platform_na_prop_enabled) {
4776 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4777 na_props.ui_na_prop_enabled ? "true" : "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304778 ALOGV("%s:napb: na_props.ui_na_prop_enabled: %d", __func__,
4779 na_props.ui_na_prop_enabled);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004780 } else {
4781 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4782 "false");
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304783 ALOGV("%s:napb: native audio not supported: %d", __func__,
4784 na_props.platform_na_prop_enabled);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004785 }
4786 }
4787}
4788
4789int native_audio_set_params(struct platform_data *platform,
4790 struct str_parms *parms, char *value, int len)
4791{
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05304792 int ret = -1;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004793 struct audio_usecase *usecase;
4794 struct listnode *node;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304795 int mode = NATIVE_AUDIO_MODE_INVALID;
4796
Preetam Singh Ranawat6746b7a2016-07-18 16:40:24 +05304797 if (!value || !parms)
4798 return ret;
4799
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304800 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO_MODE,
4801 value, len);
4802 if (ret >= 0) {
4803 if (value && !strncmp(value, "src", sizeof("src")))
4804 mode = NATIVE_AUDIO_MODE_SRC;
4805 else if (value && !strncmp(value, "true", sizeof("true")))
4806 mode = NATIVE_AUDIO_MODE_TRUE_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05304807 else if (value && !strncmp(value, "multiple_mix_codec", sizeof("multiple_mix_codec")))
4808 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC;
4809 else if (value && !strncmp(value, "multiple_mix_dsp", sizeof("multiple_mix_dsp")))
4810 mode = NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304811 else {
4812 mode = NATIVE_AUDIO_MODE_INVALID;
4813 ALOGE("%s:napb:native_audio_mode in platform info xml,invalid mode string",
4814 __func__);
4815 }
4816 ALOGD("%s:napb updating mode (%d) from XML",__func__, mode);
4817 platform_set_native_support(mode);
4818 }
4819
4820
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004821
4822 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
4823 value, len);
4824 if (ret >= 0) {
4825 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304826 if (!strncmp("true", value, sizeof("true"))) {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004827 na_props.ui_na_prop_enabled = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304828 ALOGD("%s:napb: native audio feature enabled from UI",
4829 __func__);
4830 } else {
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004831 na_props.ui_na_prop_enabled = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304832 ALOGD("%s:napb: native audio feature disabled from UI",
4833 __func__);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304834 }
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004835
4836 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
4837
4838 /*
4839 * Iterate through the usecase list and trigger device switch for
4840 * all the appropriate usecases
4841 */
4842 list_for_each(node, &(platform->adev)->usecase_list) {
4843 usecase = node_to_item(node, struct audio_usecase, list);
4844
Sujin Panicker390724d2019-04-26 10:43:36 +05304845 if (usecase->stream.out && is_offload_usecase(usecase->id) &&
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004846 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4847 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
4848 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Alexy Josephb1379942016-01-29 15:49:38 -08004849 ALOGD("%s:napb: triggering dynamic device switch for usecase %d, %s"
4850 " stream %p, device (%u)", __func__, usecase->id,
4851 use_case_table[usecase->id],
4852 (void*) usecase->stream.out,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004853 usecase->stream.out->devices);
Sidipotu Ashok894644d2015-07-06 18:35:03 +05304854 select_devices(platform->adev, usecase->id);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004855 }
4856 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304857 } else
4858 ALOGD("%s:napb: native audio cannot be enabled from UI",
4859 __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004860 }
4861 return ret;
4862}
4863
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304864int check_hdset_combo_device(snd_device_t snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304865{
4866 int ret = false;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304867
Sidipotu Ashokad8fff82016-02-02 10:48:42 +05304868 if (SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES == snd_device ||
4869 SND_DEVICE_OUT_SPEAKER_AND_LINE == snd_device ||
4870 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1 == snd_device ||
4871 SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2 == snd_device ||
Meng Wang841d6c02017-01-24 12:34:36 +08004872 SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET == snd_device ||
4873 SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET == snd_device)
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304874 ret = true;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05304875
4876 return ret;
4877}
kunleiz207afaa2016-07-22 14:26:49 +08004878
Ashish Jainb26edfb2016-08-25 00:10:11 +05304879int codec_device_supports_native_playback(audio_devices_t out_device)
kunleiz207afaa2016-07-22 14:26:49 +08004880{
Ashish Jainb26edfb2016-08-25 00:10:11 +05304881 int ret = false;
kunleiz207afaa2016-07-22 14:26:49 +08004882
4883 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
4884 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
Revathi Uddaraju413a6f02018-11-09 12:57:27 +05304885 out_device & AUDIO_DEVICE_OUT_LINE ||
4886 out_device & AUDIO_DEVICE_OUT_USB_HEADSET)
Ashish Jainb26edfb2016-08-25 00:10:11 +05304887 ret = true;
kunleiz207afaa2016-07-22 14:26:49 +08004888
4889 return ret;
4890}
4891
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304892int platform_get_backend_index(snd_device_t snd_device)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08004893{
4894 int32_t port = DEFAULT_CODEC_BACKEND;
4895
Kuirong Wang0b947f72016-09-29 11:03:09 -07004896 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304897 if (backend_tag_table[snd_device] != NULL) {
4898 if (strncmp(backend_tag_table[snd_device], "headphones-44.1",
4899 sizeof("headphones-44.1")) == 0)
4900 port = HEADPHONE_44_1_BACKEND;
Ramlal Karra10d22b92019-08-08 19:02:35 +05304901 else if (strncmp(backend_tag_table[snd_device], "headphones-hifi-filter",
4902 sizeof("headphones-hifi-filter")) == 0)
4903 port = HEADPHONE_BACKEND;
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05304904 else if (strncmp(backend_tag_table[snd_device], "headphones-dsd",
4905 sizeof("headphones-dsd")) == 0)
4906 port = DSD_NATIVE_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304907 else if (strncmp(backend_tag_table[snd_device], "headphones",
4908 sizeof("headphones")) == 0)
4909 port = HEADPHONE_BACKEND;
Samyak Jain541897b2019-07-01 17:15:31 +05304910 else if (strncmp(backend_tag_table[snd_device], "headset",
4911 sizeof("headset")) == 0)
4912 port = HEADPHONE_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304913 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
4914 port = HDMI_RX_BACKEND;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07004915 else if (strcmp(backend_tag_table[snd_device], "display-port") == 0)
4916 port = DISP_PORT_RX_BACKEND;
Ashish Jain3e37a702016-11-25 12:27:15 +05304917 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
4918 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08004919 port = USB_AUDIO_RX_BACKEND;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304920 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07004921 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
4922 port = DEFAULT_CODEC_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07004923 if (backend_tag_table[snd_device] != NULL) {
4924 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
4925 port = USB_AUDIO_TX_BACKEND;
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05304926 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
4927 port = BT_SCO_TX_BACKEND;
Ralf Herzafb164f2018-07-03 07:08:07 +02004928 else if (strcmp(backend_tag_table[snd_device], "spdif-in") == 0)
4929 port = SPDIF_TX_BACKEND;
4930 else if (strcmp(backend_tag_table[snd_device], "hdmi-in") == 0)
Siddartha Shaik44dd7702017-06-14 12:13:25 +05304931 port = HDMI_TX_BACKEND;
Ralf Herzafb164f2018-07-03 07:08:07 +02004932 else if (strcmp(backend_tag_table[snd_device], "hdmi-arc-in") == 0)
4933 port = HDMI_ARC_TX_BACKEND;
Samyak Jainb3f3ca52019-01-02 18:24:35 +05304934 else if (strcmp(backend_tag_table[snd_device], "headset-mic") == 0)
4935 port = HEADSET_TX_BACKEND;
Kuirong Wange9894162016-08-26 15:16:39 -07004936 }
4937 } else {
Kuirong Wang0b947f72016-09-29 11:03:09 -07004938 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07004939 }
4940
Kuirong Wang0b947f72016-09-29 11:03:09 -07004941 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
Kuirong Wange9894162016-08-26 15:16:39 -07004942 return port;
4943}
4944
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304945int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Zhou Song06761dd2019-04-28 18:08:17 +08004946 int app_type)
Eric Laurentb23d5282013-05-14 15:27:20 -07004947{
4948 struct platform_data *my_data = (struct platform_data *)platform;
4949 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304950 int snd_device = SND_DEVICE_OUT_SPEAKER;
Siena Richard7c2db772016-12-21 11:32:34 -08004951 int new_snd_device[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304952 int i, num_devices = 1;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304953 bool is_incall_rec_usecase = false;
4954 snd_device_t incall_rec_device;
Zhou Song06761dd2019-04-28 18:08:17 +08004955 int sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05304956 struct audio_backend_cfg backend_cfg = {0};
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304957
4958 if (voice_is_in_call(my_data->adev))
4959 is_incall_rec_usecase = voice_is_in_call_rec_stream(usecase->stream.in);
Eric Laurentb23d5282013-05-14 15:27:20 -07004960
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304961 if (usecase->type == PCM_PLAYBACK)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304962 snd_device = usecase->out_snd_device;
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304963 else if ((usecase->type == PCM_CAPTURE) && is_incall_rec_usecase)
Karthik Reddy Katta81c42612015-11-13 17:49:07 +05304964 snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304965 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Vidyakumar Athotab0975c32015-07-21 14:15:03 -07004966 snd_device = usecase->in_snd_device;
Surendar Karka93cd25a2018-08-28 14:21:37 +05304967 else if (usecase->type == TRANSCODE_LOOPBACK_RX)
Siddartha Shaik343abc62017-08-08 11:15:25 +05304968 snd_device = usecase->out_snd_device;
Vidyakumar Athotab0975c32015-07-21 14:15:03 -07004969
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08004970 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07004971 if (acdb_dev_id < 0) {
4972 ALOGE("%s: Could not find acdb id for device(%d)",
4973 __func__, snd_device);
4974 return -EINVAL;
4975 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304976
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304977 if (!is_incall_rec_usecase) {
4978 if (platform_split_snd_device(my_data, snd_device,
4979 &num_devices, new_snd_device) < 0) {
4980 new_snd_device[0] = snd_device;
4981 }
4982 } else {
4983 incall_rec_device = voice_get_incall_rec_backend_device(usecase->stream.in);
4984 if (platform_split_snd_device(my_data, incall_rec_device,
4985 &num_devices, new_snd_device) < 0) {
4986 new_snd_device[0] = snd_device;
4987 }
Eric Laurentb23d5282013-05-14 15:27:20 -07004988 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05304989
4990 for (i = 0; i < num_devices; i++) {
Zhou Song06761dd2019-04-28 18:08:17 +08004991 if (!is_incall_rec_usecase) {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304992 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(new_snd_device[i])];
Zhou Song06761dd2019-04-28 18:08:17 +08004993 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
4994 new_snd_device[i]);
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05304995 platform_get_codec_backend_cfg(my_data->adev, new_snd_device[i], &backend_cfg);
Zhou Song06761dd2019-04-28 18:08:17 +08004996 } else {
Aditya Bavanari9e957d82019-01-29 17:47:13 +05304997 // Use in_call_rec snd_device to extract the ACDB device ID instead of split snd devices
4998 acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
Zhou Song06761dd2019-04-28 18:08:17 +08004999 sample_rate = audio_extn_utils_get_app_sample_rate_for_device(my_data->adev, usecase,
5000 snd_device);
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305001 platform_get_codec_backend_cfg(my_data->adev, snd_device, &backend_cfg);
Zhou Song06761dd2019-04-28 18:08:17 +08005002 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05305003
5004 // Do not use Rx path default app type for TX path
5005 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
5006 ALOGD("Resetting app type for Tx path to default");
5007 app_type = DEFAULT_APP_TYPE_TX_PATH;
5008 }
5009
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305010 /* Override backend cfg sample rate in calibration for vi feedback usecase */
5011 if (usecase->id == USECASE_AUDIO_SPKR_CALIB_TX) {
5012 ALOGV("Reset backend cfg sample rate to 8KHz for spkr calib Tx use case");
5013 backend_cfg.sample_rate = sample_rate;
5014 }
5015
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305016 if (acdb_dev_id < 0) {
5017 ALOGE("%s: Could not find acdb id for device(%d)",
5018 __func__, new_snd_device[i]);
5019 return -EINVAL;
5020 }
Weiyin Jiang27dd1452019-07-12 23:46:06 +08005021
5022 /* Notify device change info to effect clients registered */
5023 if (usecase->type == PCM_PLAYBACK) {
5024 audio_extn_gef_notify_device_config(
5025 usecase->stream.out->devices,
5026 usecase->stream.out->channel_mask,
5027 sample_rate,
5028 acdb_dev_id,
5029 usecase->stream.out->app_type_cfg.app_type);
5030 }
5031
Siena Richard7c2db772016-12-21 11:32:34 -08005032 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
5033 __func__, new_snd_device[i], acdb_dev_id);
5034 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
5035 new_snd_device[i] < SND_DEVICE_OUT_END)
5036 acdb_dev_type = ACDB_DEV_TYPE_OUT;
5037 else
5038 acdb_dev_type = ACDB_DEV_TYPE_IN;
5039
Aditya Bavanariafa4d3a2019-08-13 18:56:10 +05305040 if (my_data->acdb_send_audio_cal_v4) {
5041 my_data->acdb_send_audio_cal_v4(acdb_dev_id, acdb_dev_type,
5042 app_type, sample_rate, i,
5043 backend_cfg.sample_rate);
5044 } else if (my_data->acdb_send_audio_cal_v3) {
Siena Richard7c2db772016-12-21 11:32:34 -08005045 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
5046 app_type, sample_rate, i);
5047 } else if (my_data->acdb_send_audio_cal) {
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305048 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
5049 sample_rate);
5050 }
5051 }
5052
Eric Laurentb23d5282013-05-14 15:27:20 -07005053 return 0;
5054}
5055
5056int platform_switch_voice_call_device_pre(void *platform)
5057{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005058 struct platform_data *my_data = (struct platform_data *)platform;
5059 int ret = 0;
5060
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005061 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07005062 voice_is_in_call(my_data->adev)) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005063 /* This must be called before disabling mixer controls on APQ side */
5064 ret = my_data->csd->disable_device();
5065 if (ret < 0) {
5066 ALOGE("%s: csd_client_disable_device, failed, error %d",
5067 __func__, ret);
5068 }
5069 }
5070 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005071}
5072
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005073int platform_switch_voice_call_enable_device_config(void *platform,
5074 snd_device_t out_snd_device,
5075 snd_device_t in_snd_device)
5076{
5077 struct platform_data *my_data = (struct platform_data *)platform;
5078 int acdb_rx_id, acdb_tx_id;
5079 int ret = 0;
5080
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005081 if (my_data->csd == NULL)
5082 return ret;
5083
Banajit Goswami20cdd212015-09-11 01:11:30 -07005084 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Aditya Bavanarif934f3a2019-06-17 18:40:52 +05305085 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05305086 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
5087 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5088 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07005089 audio_extn_spkr_prot_is_enabled()) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05305090 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07005091 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
5092 else
5093 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
5094 } else
Aalique Grahame22e49102018-12-18 14:23:57 -08005095 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005096
Aalique Grahame22e49102018-12-18 14:23:57 -08005097 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005098
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005099 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
5100 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
5101 if (ret < 0) {
5102 ALOGE("%s: csd_enable_device_config, failed, error %d",
5103 __func__, ret);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005104 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005105 } else {
5106 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5107 acdb_rx_id, acdb_tx_id);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005108 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005109
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08005110 return ret;
5111}
5112
Eric Laurentb23d5282013-05-14 15:27:20 -07005113int platform_switch_voice_call_device_post(void *platform,
5114 snd_device_t out_snd_device,
5115 snd_device_t in_snd_device)
5116{
5117 struct platform_data *my_data = (struct platform_data *)platform;
5118 int acdb_rx_id, acdb_tx_id;
5119
5120 if (my_data->acdb_send_voice_cal == NULL) {
5121 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
5122 } else {
Rohit kumarf4120402016-08-05 19:19:48 +05305123 if (audio_extn_spkr_prot_is_enabled()) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305124 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
5125 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA)
Rohit kumarf4120402016-08-05 19:19:48 +05305126 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07005127 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO)
5128 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +05305129 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT)
5130 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305131 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
5132 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA)
Rohit kumarf4120402016-08-05 19:19:48 +05305133 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
5134 else if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT)
5135 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
5136 }
Anish Kumar46c7b872014-09-09 01:49:44 -07005137
Aalique Grahame22e49102018-12-18 14:23:57 -08005138 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
5139 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005140
Eric Laurentb23d5282013-05-14 15:27:20 -07005141 if (acdb_rx_id > 0 && acdb_tx_id > 0)
5142 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
5143 else
5144 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5145 acdb_rx_id, acdb_tx_id);
5146 }
5147
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005148 return 0;
5149}
5150
5151int platform_switch_voice_call_usecase_route_post(void *platform,
5152 snd_device_t out_snd_device,
5153 snd_device_t in_snd_device)
5154{
5155 struct platform_data *my_data = (struct platform_data *)platform;
5156 int acdb_rx_id, acdb_tx_id;
5157 int ret = 0;
5158
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005159 if (my_data->csd == NULL)
5160 return ret;
5161
Banajit Goswami20cdd212015-09-11 01:11:30 -07005162 if ((out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Rohit kumarf4120402016-08-05 19:19:48 +05305163 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +05305164 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +05305165 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
5166 out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT) &&
Banajit Goswami20cdd212015-09-11 01:11:30 -07005167 audio_extn_spkr_prot_is_enabled()) {
Aditya Bavanari9b589022018-09-20 08:47:55 +05305168 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07005169 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT];
5170 else
5171 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
5172 } else
Aalique Grahame22e49102018-12-18 14:23:57 -08005173 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005174
Aalique Grahame22e49102018-12-18 14:23:57 -08005175 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08005176
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005177 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
5178 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
5179 my_data->adev->acdb_settings);
5180 if (ret < 0) {
5181 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005182 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005183 } else {
5184 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
5185 acdb_rx_id, acdb_tx_id);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005186 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08005187
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005188 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005189}
5190
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005191int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07005192{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005193 struct platform_data *my_data = (struct platform_data *)platform;
5194 int ret = 0;
5195
5196 if (my_data->csd != NULL) {
5197 ret = my_data->csd->start_voice(vsid);
5198 if (ret < 0) {
5199 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
5200 }
5201 }
5202 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005203}
5204
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005205int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07005206{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005207 struct platform_data *my_data = (struct platform_data *)platform;
5208 int ret = 0;
5209
5210 if (my_data->csd != NULL) {
5211 ret = my_data->csd->stop_voice(vsid);
5212 if (ret < 0) {
5213 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
5214 }
5215 }
5216 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005217}
5218
Vignesh Kulothungan7d374312018-02-21 17:12:00 -08005219int platform_set_mic_break_det(void *platform, bool enable)
5220{
5221 int ret = 0;
5222 struct platform_data *my_data = (struct platform_data *)platform;
5223 struct audio_device *adev = my_data->adev;
5224 const char *mixer_ctl_name = "Voice Mic Break Enable";
5225 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5226 if (!ctl) {
5227 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5228 __func__, mixer_ctl_name);
5229 return -EINVAL;
5230 }
5231
5232 ret = mixer_ctl_set_value(ctl, 0, enable);
5233 if(ret)
5234 ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
5235
5236 return ret;
5237}
5238
Helen Zeng6a16ad72014-02-23 22:04:44 -08005239int platform_get_sample_rate(void *platform, uint32_t *rate)
5240{
5241 struct platform_data *my_data = (struct platform_data *)platform;
5242 int ret = 0;
5243
5244 if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) {
5245 ret = my_data->csd->get_sample_rate(rate);
5246 if (ret < 0) {
5247 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
5248 }
5249 }
5250 return ret;
5251}
5252
Aalique Grahame22e49102018-12-18 14:23:57 -08005253void platform_set_speaker_gain_in_combo(struct audio_device *adev,
5254 snd_device_t snd_device,
5255 bool enable)
5256{
5257 const char* name;
5258 switch (snd_device) {
5259 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
5260 if (enable)
5261 name = "spkr-gain-in-headphone-combo";
5262 else
5263 name = "speaker-gain-default";
5264 break;
5265 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
5266 if (enable)
5267 name = "spkr-gain-in-line-combo";
5268 else
5269 name = "speaker-gain-default";
5270 break;
5271 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
5272 if (enable)
5273 name = "spkr-safe-gain-in-headphone-combo";
5274 else
5275 name = "speaker-safe-gain-default";
5276 break;
5277 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
5278 if (enable)
5279 name = "spkr-safe-gain-in-line-combo";
5280 else
5281 name = "speaker-safe-gain-default";
5282 break;
5283 default:
5284 return;
5285 }
5286
5287 audio_route_apply_and_update_path(adev->audio_route, name);
5288}
5289
Eric Laurentb23d5282013-05-14 15:27:20 -07005290int platform_set_voice_volume(void *platform, int volume)
5291{
5292 struct platform_data *my_data = (struct platform_data *)platform;
5293 struct audio_device *adev = my_data->adev;
5294 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07005295 const char *mixer_ctl_name = "Voice Rx Gain";
Aalique Grahame22e49102018-12-18 14:23:57 -08005296 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005297 int vol_index = 0, ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305298 long set_values[ ] = {0,
5299 ALL_SESSION_VSID,
5300 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07005301
5302 // Voice volume levels are mapped to adsp volume levels as follows.
5303 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
5304 // But this values don't changed in kernel. So, below change is need.
Aalique Grahame22e49102018-12-18 14:23:57 -08005305 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005306 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07005307
5308 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5309 if (!ctl) {
5310 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5311 __func__, mixer_ctl_name);
Aalique Grahame22e49102018-12-18 14:23:57 -08005312 return -EINVAL;
Eric Laurentb23d5282013-05-14 15:27:20 -07005313 }
Aalique Grahame22e49102018-12-18 14:23:57 -08005314 ALOGV("%s: Setting voice volume index: %ld", __func__, set_values[0]);
5315 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5316
5317 // Send mute command in case volume index is max since indexes are inverted
5318 // for mixer controls.
5319 if (vol_index == my_data->max_vol_index)
5320 set_values[0] = 1;
5321 else
5322 set_values[0] = 0;
5323
5324 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
5325 if (!ctl) {
5326 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5327 __func__, mute_mixer_ctl_name);
5328 return -EINVAL;
5329 }
5330 ALOGV("%s: Setting RX Device Mute to: %ld", __func__, set_values[0]);
5331 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07005332
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005333 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07005334 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
5335 DEFAULT_VOLUME_RAMP_DURATION_MS);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005336 if (ret < 0) {
5337 ALOGE("%s: csd_volume error %d", __func__, ret);
5338 }
5339 }
5340 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005341}
5342
5343int platform_set_mic_mute(void *platform, bool state)
5344{
5345 struct platform_data *my_data = (struct platform_data *)platform;
5346 struct audio_device *adev = my_data->adev;
5347 struct mixer_ctl *ctl;
5348 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005349 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305350 long set_values[ ] = {0,
5351 ALL_SESSION_VSID,
5352 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07005353
Aalique Grahame22e49102018-12-18 14:23:57 -08005354 if (adev->mode != AUDIO_MODE_IN_CALL &&
5355 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
5356 return 0;
5357
5358 if (adev->enable_hfp)
5359 mixer_ctl_name = "HFP Tx Mute";
5360
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005361 set_values[0] = state;
5362 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5363 if (!ctl) {
5364 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5365 __func__, mixer_ctl_name);
Josh Kirsch5669ad92016-12-09 10:48:52 -08005366 ret = -EINVAL;
5367 } else {
5368 ALOGV("%s Setting voice mute state: %d", __func__, state);
5369 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005370 }
Eric Laurentb23d5282013-05-14 15:27:20 -07005371
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005372 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07005373 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
5374 DEFAULT_MUTE_RAMP_DURATION_MS);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005375 if (ret < 0) {
5376 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08005377 }
5378 }
5379 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07005380}
5381
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08005382int platform_set_device_mute(void *platform, bool state, char *dir)
5383{
5384 struct platform_data *my_data = (struct platform_data *)platform;
5385 struct audio_device *adev = my_data->adev;
5386 struct mixer_ctl *ctl;
5387 char *mixer_ctl_name = NULL;
5388 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05305389 long set_values[ ] = {0,
5390 ALL_SESSION_VSID,
5391 0};
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08005392 if(dir == NULL) {
5393 ALOGE("%s: Invalid direction:%s", __func__, dir);
5394 return -EINVAL;
5395 }
5396
5397 if (!strncmp("rx", dir, sizeof("rx"))) {
5398 mixer_ctl_name = "Voice Rx Device Mute";
5399 } else if (!strncmp("tx", dir, sizeof("tx"))) {
5400 mixer_ctl_name = "Voice Tx Device Mute";
5401 } else {
5402 return -EINVAL;
5403 }
5404
5405 set_values[0] = state;
5406 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5407 if (!ctl) {
5408 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5409 __func__, mixer_ctl_name);
5410 return -EINVAL;
5411 }
5412
5413 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
5414 __func__,state, mixer_ctl_name);
5415 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
5416
5417 return ret;
5418}
5419
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005420int platform_split_snd_device(void *platform,
5421 snd_device_t snd_device,
5422 int *num_devices,
5423 snd_device_t *new_snd_devices)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305424{
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005425 int ret = -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305426 struct platform_data *my_data = (struct platform_data *)platform;
5427
5428 if ( NULL == num_devices || NULL == new_snd_devices || NULL == my_data) {
5429 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005430 return -EINVAL;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305431 }
5432
5433 /*
5434 * If wired headset/headphones/line devices share the same backend
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005435 * with speaker/earpiece this routine returns -EINVAL.
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305436 */
5437 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
5438 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
5439 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305440 if (my_data->is_vbat_speaker)
5441 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5442 else if (my_data->is_wsa_speaker)
5443 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5444 else
5445 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305446 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005447 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005448 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
5449 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
5450 *num_devices = 2;
5451 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5452 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
5453 ret = 0;
5454 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
5455 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
5456 *num_devices = 2;
5457 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5458 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5459 ret = 0;
5460 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
5461 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
5462 *num_devices = 2;
5463 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5464 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
5465 ret = 0;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305466 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET &&
5467 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_ANC_HEADSET)) {
5468 *num_devices = 2;
5469 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5470 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5471 ret = 0;
5472 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET &&
5473 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_ANC_FB_HEADSET)) {
5474 *num_devices = 2;
5475 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5476 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
5477 ret = 0;
5478 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES &&
5479 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
5480 *num_devices = 2;
5481 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5482 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
5483 ret = 0;
5484 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET &&
5485 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
5486 *num_devices = 2;
5487 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5488 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
5489 ret = 0;
5490 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET &&
5491 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER, SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)) {
5492 *num_devices = 2;
5493 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER;
5494 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5495 ret = 0;
Vikram Panduranga8c68e862018-04-27 12:59:42 -07005496 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES &&
5497 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_HEADPHONES)) {
5498 *num_devices = 2;
5499 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5500 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_HEADPHONES;
5501 ret = 0;
5502 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET &&
5503 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_ANC_HEADSET)) {
5504 *num_devices = 2;
5505 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5506 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
5507 ret = 0;
5508 } else if (snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET &&
5509 !platform_check_backends_match(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO, SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)) {
5510 *num_devices = 2;
5511 new_snd_devices[0] = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5512 new_snd_devices[1] = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5513 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305514 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI &&
5515 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HDMI)) {
5516 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305517
5518 if (my_data->is_vbat_speaker)
5519 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5520 else if (my_data->is_wsa_speaker)
5521 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5522 else
5523 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305524 new_snd_devices[1] = SND_DEVICE_OUT_HDMI;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005525 ret = 0;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005526 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT &&
5527 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_DISPLAY_PORT)) {
5528 *num_devices = 2;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305529 if (my_data->is_vbat_speaker)
5530 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_VBAT;
5531 else if (my_data->is_wsa_speaker)
5532 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5533 else
5534 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005535 new_snd_devices[1] = SND_DEVICE_OUT_DISPLAY_PORT;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005536 ret = 0;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08005537 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
5538 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
5539 *num_devices = 2;
5540 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5541 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005542 ret = 0;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305543 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER &&
5544 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)) {
5545 *num_devices = 2;
5546 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5547 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
5548 ret = 0;
kunleizbe6a8442017-08-08 17:11:35 +08005549 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
5550 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO)) {
5551 *num_devices = 2;
5552 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5553 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5554 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005555 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO &&
5556 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5557 SND_DEVICE_OUT_BT_SCO)) {
5558 *num_devices = 2;
5559 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5560 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5561 ret = 0;
kunleizbe6a8442017-08-08 17:11:35 +08005562 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
5563 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO_WB)) {
5564 *num_devices = 2;
5565 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5566 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5567 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005568 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB &&
5569 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5570 SND_DEVICE_OUT_BT_SCO_WB)) {
5571 *num_devices = 2;
5572 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5573 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5574 ret = 0;
Zhou Song12c29502019-03-16 10:37:18 +08005575 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB &&
5576 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_BT_SCO_SWB)) {
5577 *num_devices = 2;
5578 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5579 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_SWB;
5580 ret = 0;
5581 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB &&
5582 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5583 SND_DEVICE_OUT_BT_SCO_SWB)) {
5584 *num_devices = 2;
5585 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5586 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_SWB;
5587 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005588 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
5589 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
5590 *num_devices = 2;
5591 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5592 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
5593 ret = 0;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305594 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO &&
5595 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO)) {
5596 *num_devices = 2;
5597 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5598 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
5599 ret = 0;
5600 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB &&
5601 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_WSA, SND_DEVICE_OUT_BT_SCO_WB)) {
5602 *num_devices = 2;
5603 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_WSA;
5604 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
5605 ret = 0;
5606 }
5607else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) {
Naresh Tannirucd2353e2016-08-19 00:37:25 +05305608 *num_devices = 2;
5609 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
5610 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005611 ret = 0;
Aalique Grahame22e49102018-12-18 14:23:57 -08005612 } else if (SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP == snd_device &&
5613 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE,
5614 SND_DEVICE_OUT_BT_A2DP)) {
5615 *num_devices = 2;
5616 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
5617 new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
5618 ret = 0;
Divya Narayanan Poojary85d0a592018-02-06 14:25:16 +05305619 } else if (SND_DEVICE_IN_INCALL_REC_RX_TX == snd_device) {
5620 *num_devices = 2;
5621 new_snd_devices[0] = SND_DEVICE_IN_INCALL_REC_RX;
5622 new_snd_devices[1] = SND_DEVICE_IN_INCALL_REC_TX;
5623 ret = 0;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05305624 } else if (SND_DEVICE_IN_HANDSET_DMIC_AND_EC_REF_LOOPBACK == snd_device) {
5625 *num_devices = 2;
5626 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_DMIC;
5627 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5628 ret = 0;
5629 } else if (SND_DEVICE_IN_HANDSET_QMIC_AND_EC_REF_LOOPBACK == snd_device) {
5630 *num_devices = 2;
5631 new_snd_devices[0] = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
5632 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5633 ret = 0;
5634 } else if (SND_DEVICE_IN_HANDSET_6MIC_AND_EC_REF_LOOPBACK == snd_device) {
5635 *num_devices = 2;
5636 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_6MIC;
5637 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5638 ret = 0;
5639 } else if (SND_DEVICE_IN_HANDSET_8MIC_AND_EC_REF_LOOPBACK == snd_device) {
5640 *num_devices = 2;
5641 new_snd_devices[0] = SND_DEVICE_IN_HANDSET_8MIC;
5642 new_snd_devices[1] = SND_DEVICE_IN_EC_REF_LOOPBACK;
5643 ret = 0;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305644 }
5645
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05305646
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305647 ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
5648 snd_device, *num_devices, *new_snd_devices);
5649
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07005650 return ret;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05305651}
5652
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005653int platform_get_ext_disp_type(void *platform)
5654{
5655 int disp_type;
5656 struct platform_data *my_data = (struct platform_data *)platform;
5657
5658 if (my_data->ext_disp_type != EXT_DISPLAY_TYPE_NONE) {
5659 ALOGD("%s: Returning cached ext disp type:%s",
5660 __func__, (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
5661 return my_data->ext_disp_type;
5662 }
5663
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08005664 if (audio_extn_is_display_port_enabled()) {
5665 struct audio_device *adev = my_data->adev;
5666 struct mixer_ctl *ctl;
5667 char *mixer_ctl_name = "External Display Type";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005668
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08005669 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
5670 if (!ctl) {
5671 ALOGE("%s: Could not get ctl for mixer cmd - %s",
5672 __func__, mixer_ctl_name);
5673 return -EINVAL;
5674 }
5675
5676 disp_type = mixer_ctl_get_value(ctl, 0);
5677 if (disp_type == EXT_DISPLAY_TYPE_NONE) {
5678 ALOGE("%s: Invalid external display type: %d", __func__, disp_type);
5679 return -EINVAL;
5680 }
5681 } else {
5682 disp_type = EXT_DISPLAY_TYPE_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005683 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005684 my_data->ext_disp_type = disp_type;
5685 ALOGD("%s: ext disp type:%s", __func__, (disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
5686 return disp_type;
5687}
5688
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08005689snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Eric Laurentb23d5282013-05-14 15:27:20 -07005690{
5691 struct platform_data *my_data = (struct platform_data *)platform;
5692 struct audio_device *adev = my_data->adev;
5693 audio_mode_t mode = adev->mode;
5694 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08005695 audio_devices_t devices = out->devices;
5696 unsigned int sample_rate = out->sample_rate;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05305697 int na_mode = platform_get_native_support();
Eric Laurent637e2d42018-11-15 12:24:31 -08005698 struct stream_in *in = adev_get_active_input(adev);
Eric Laurentb23d5282013-05-14 15:27:20 -07005699
Eric Laurent637e2d42018-11-15 12:24:31 -08005700 audio_channel_mask_t channel_mask = (in == NULL) ?
5701 AUDIO_CHANNEL_IN_MONO : in->channel_mask;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07005702 int channel_count = popcount(channel_mask);
5703
Eric Laurentb23d5282013-05-14 15:27:20 -07005704 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
5705 if (devices == AUDIO_DEVICE_NONE ||
5706 devices & AUDIO_DEVICE_BIT_IN) {
5707 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
5708 goto exit;
5709 }
5710
Shiv Maliyappanahallibd401262015-08-17 11:02:21 -07005711 if (popcount(devices) == 2) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305712 bool is_active_voice_call = false;
5713
5714 /*
5715 * This is special case handling for combo device use case during
5716 * voice call. APM route use case to combo device if stream type is
5717 * enforced audible (e.g. Camera shutter sound).
5718 */
5719 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08005720 voice_check_voicecall_usecases_active(adev) ||
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305721 voice_extn_compress_voip_is_active(adev))
5722 is_active_voice_call = true;
5723
Mingming Yin4a72d652014-01-03 18:54:18 -08005724 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
5725 AUDIO_DEVICE_OUT_SPEAKER)) {
Tanya Finkel00130052014-07-14 04:26:56 -07005726 if (my_data->external_spk_1)
5727 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
5728 else if (my_data->external_spk_2)
5729 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305730 else if (is_active_voice_call)
5731 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305732 else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5733 my_data->codec_variant, channel_count, 1))
5734 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
Tanya Finkel00130052014-07-14 04:26:56 -07005735 else
5736 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305737 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5738 AUDIO_DEVICE_OUT_SPEAKER)) {
5739 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Mingming Yin4a72d652014-01-03 18:54:18 -08005740 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
5741 AUDIO_DEVICE_OUT_SPEAKER)) {
Meng Wang841d6c02017-01-24 12:34:36 +08005742 if (audio_extn_get_anc_enabled()) {
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305743 if (audio_extn_should_use_fb_anc()) {
5744 if (is_active_voice_call)
5745 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_FB_HEADSET;
5746 else
5747 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_FB_HEADSET;
5748 } else {
5749 if (is_active_voice_call)
5750 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_ANC_HEADSET;
5751 else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05305752 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305753 }
Meng Wang841d6c02017-01-24 12:34:36 +08005754 } else if (my_data->external_spk_1)
Tanya Finkel00130052014-07-14 04:26:56 -07005755 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
5756 else if (my_data->external_spk_2)
5757 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Ramlal Karra10d22b92019-08-08 19:02:35 +05305758 else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
5759 my_data->codec_variant, channel_count, 1))
5760 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_HIFI_FILTER;
Preetam Singh Ranawat91132162017-03-13 20:32:03 +05305761 else {
5762 if (is_active_voice_call)
5763 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_AND_VOICE_HEADPHONES;
5764 else
5765 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
5766 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005767 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5768 AUDIO_DEVICE_OUT_SPEAKER)) {
5769 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Aalique Grahame22e49102018-12-18 14:23:57 -08005770 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
5771 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
5772 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
5773 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
5774 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
5775 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
5776 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
5777 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
Mingming Yin4a72d652014-01-03 18:54:18 -08005778 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
5779 AUDIO_DEVICE_OUT_SPEAKER)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07005780 switch(my_data->ext_disp_type) {
5781 case EXT_DISPLAY_TYPE_HDMI:
5782 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
5783 break;
5784 case EXT_DISPLAY_TYPE_DP:
5785 snd_device = SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT;
5786 break;
5787 default:
5788 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
5789 goto exit;
5790 }
Mingming Yin4a72d652014-01-03 18:54:18 -08005791 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
5792 AUDIO_DEVICE_OUT_SPEAKER)) {
5793 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05305794 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
5795 AUDIO_DEVICE_OUT_SPEAKER)) ||
5796 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
5797 AUDIO_DEVICE_OUT_SPEAKER))) {
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08005798 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05305799 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
5800 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
5801 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP;
Aalique Grahame22e49102018-12-18 14:23:57 -08005802 } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) &&
5803 (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
5804 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP;
kunleizbe6a8442017-08-08 17:11:35 +08005805 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
5806 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
Zhou Song12c29502019-03-16 10:37:18 +08005807 if (my_data->is_wsa_speaker) {
5808 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5809 snd_device = SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB;
5810 else
5811 snd_device = adev->bt_wb_speech_enabled ?
5812 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB :
5813 SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO;
5814 } else {
5815 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5816 snd_device = SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_SWB;
5817 else
5818 snd_device = adev->bt_wb_speech_enabled ?
5819 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
5820 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
5821 }
Aalique Grahame22e49102018-12-18 14:23:57 -08005822 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
5823 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Zhou Song12c29502019-03-16 10:37:18 +08005824 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5825 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_SWB;
5826 else
5827 snd_device = adev->bt_wb_speech_enabled ?
5828 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB :
5829 SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO;
Aalique Grahame22e49102018-12-18 14:23:57 -08005830 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
5831 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
5832 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
5833 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
5834 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Mingming Yin4a72d652014-01-03 18:54:18 -08005835 } else {
5836 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
5837 goto exit;
5838 }
5839 if (snd_device != SND_DEVICE_NONE) {
5840 goto exit;
5841 }
5842 }
5843
5844 if (popcount(devices) != 1) {
5845 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
5846 goto exit;
5847 }
5848
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05305849 if ((mode == AUDIO_MODE_IN_CALL) ||
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08005850 voice_check_voicecall_usecases_active(adev) ||
Aalique Grahame22e49102018-12-18 14:23:57 -08005851 voice_extn_compress_voip_is_active(adev) ||
5852 adev->enable_voicerx ||
5853 audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07005854 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005855 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
5856 devices & AUDIO_DEVICE_OUT_LINE) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005857 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
5858 !voice_extn_compress_voip_is_active(adev)) {
5859 switch (adev->voice.tty_mode) {
5860 case TTY_MODE_FULL:
Samyak Jainc9250dc2019-06-14 12:19:28 +05305861 if (audio_extn_is_concurrent_capture_enabled() &&
5862 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5863 //Separate backend is added for headset-mic as part of concurrent capture
5864 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADSET;
5865 } else {
5866 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
5867 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005868 break;
5869 case TTY_MODE_VCO:
Samyak Jainc9250dc2019-06-14 12:19:28 +05305870 if (audio_extn_is_concurrent_capture_enabled() &&
5871 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5872 //Separate backend is added for headset-mic as part of concurrent capture
5873 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADSET;
5874 } else {
5875 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
5876 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08005877 break;
5878 case TTY_MODE_HCO:
5879 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
5880 break;
5881 default:
5882 ALOGE("%s: Invalid TTY mode (%#x)",
5883 __func__, adev->voice.tty_mode);
5884 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07005885 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
5886 snd_device = SND_DEVICE_OUT_VOICE_LINE;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005887 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07005888 if (audio_extn_should_use_fb_anc())
5889 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
5890 else
5891 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Samyak Jainfd24f1e2019-04-30 11:58:43 +05305892 } else if (audio_extn_is_concurrent_capture_enabled() &&
5893 (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET)) {
5894 //Separate backend is added for headset-mic as part of concurrent capture
5895 snd_device = SND_DEVICE_OUT_VOICE_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005896 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07005897 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005898 }
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05305899 } else if (devices &
5900 (AUDIO_DEVICE_OUT_USB_DEVICE |
5901 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07005902 if (voice_is_in_call(adev)) {
5903 switch (adev->voice.tty_mode) {
5904 case TTY_MODE_FULL:
5905 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
5906 break;
5907 case TTY_MODE_VCO:
5908 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
5909 break;
5910 case TTY_MODE_HCO:
5911 // since Hearing will be on handset\speaker, use existing device
5912 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
5913 break;
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07005914 case TTY_MODE_OFF:
5915 break;
Aniket Kumar Lata91886592017-05-25 16:53:32 -07005916 default:
5917 ALOGE("%s: Invalid TTY mode (%#x)",
5918 __func__, adev->voice.tty_mode);
5919 }
5920 }
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07005921 if (snd_device == SND_DEVICE_NONE) {
5922 snd_device = audio_extn_usb_is_capture_supported() ?
5923 SND_DEVICE_OUT_VOICE_USB_HEADSET :
5924 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
5925 }
Eric Laurentb23d5282013-05-14 15:27:20 -07005926 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08005927 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
5928 snd_device = SND_DEVICE_OUT_BT_SCO_SWB;
5929 else if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07005930 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
5931 else
5932 snd_device = SND_DEVICE_OUT_BT_SCO;
Derek Chen25496072019-06-23 01:05:27 -07005933 } else if ((devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
5934 (devices & AUDIO_DEVICE_OUT_BUS)) {
Aalique Grahame552b0832019-03-11 10:16:38 -07005935 if (my_data->is_vbat_speaker || my_data->is_bcl_speaker) {
5936 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
5937 if (my_data->mono_speaker == SPKR_1)
Rohit kumarf4120402016-08-05 19:19:48 +05305938 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
Aalique Grahame552b0832019-03-11 10:16:38 -07005939 else
5940 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT;
5941 } else
5942 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05305943 } else if (my_data->is_wsa_speaker) {
5944 if (my_data->mono_speaker == SPKR_1)
5945 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
5946 else
5947 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA;
Aalique Grahame552b0832019-03-11 10:16:38 -07005948 } else {
5949 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
5950 if (my_data->voice_speaker_stereo)
5951 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_STEREO;
5952 else if (adev->enable_hfp)
5953 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
5954 else {
5955 if (my_data->mono_speaker == SPKR_1)
kunleizaa6a3f12017-01-19 12:28:28 +08005956 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Aalique Grahame552b0832019-03-11 10:16:38 -07005957 else
5958 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_2;
5959 }
5960 } else if (adev->enable_hfp)
5961 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
5962 else
5963 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
5964 }
Naresh Tanniru9d027a62015-03-13 01:32:10 +05305965 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
5966 snd_device = SND_DEVICE_OUT_BT_A2DP;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07005967 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
5968 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
5969 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Aalique Grahame37659862017-12-03 22:34:26 -08005970 } else if ((devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
5971 adev->dp_allowed_for_voice) {
5972 switch(my_data->ext_disp_type) {
5973 case EXT_DISPLAY_TYPE_DP:
5974 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
5975 break;
5976 default:
5977 ALOGE("%s: Invalid disp_type %d", __func__,
5978 my_data->ext_disp_type);
5979 goto exit;
5980 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07005981 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
5982 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07005983 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Aalique Grahame22e49102018-12-18 14:23:57 -08005984 if(adev->voice.hac)
5985 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
5986 else if (is_operator_tmus())
5987 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
5988 else if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07005989 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07005990 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07005991 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
juyuchen2d415992018-11-16 14:15:16 +08005992 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07005993 snd_device = SND_DEVICE_OUT_VOICE_TX;
juyuchen2d415992018-11-16 14:15:16 +08005994 } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) {
5995 snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID;
5996 }
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07005997
Eric Laurentb23d5282013-05-14 15:27:20 -07005998 if (snd_device != SND_DEVICE_NONE) {
5999 goto exit;
6000 }
6001 }
6002
Eric Laurentb23d5282013-05-14 15:27:20 -07006003 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05306004 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
6005 devices & AUDIO_DEVICE_OUT_LINE) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306006 if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
6007 NATIVE_AUDIO_MODE_SRC == na_mode &&
6008 !audio_extn_get_anc_enabled()) {
6009
6010 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
6011
6012 } else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006013 && audio_extn_get_anc_enabled()) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306014 if (audio_extn_should_use_fb_anc())
6015 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
6016 else
6017 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306018 } else if (NATIVE_AUDIO_MODE_SRC == na_mode &&
6019 OUTPUT_SAMPLING_RATE_44100 == sample_rate) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08006020 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05306021 } else if (NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC == na_mode &&
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05306022 (sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0) &&
6023 (out->format != AUDIO_FORMAT_DSD)) {
6024 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
6025 } else if (out->format == AUDIO_FORMAT_DSD) {
6026 snd_device = SND_DEVICE_OUT_HEADPHONES_DSD;
Ramlal Karra10d22b92019-08-08 19:02:35 +05306027 } else if (audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
6028 my_data->codec_variant, channel_count, 1)) {
6029 snd_device = SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306030 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
6031 snd_device = SND_DEVICE_OUT_LINE;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05306032 } else
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306033 snd_device = SND_DEVICE_OUT_HEADPHONES;
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006034 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
6035 snd_device = SND_DEVICE_OUT_LINE;
Aalique Grahame22e49102018-12-18 14:23:57 -08006036 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
6037 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07006038 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Tanya Finkel00130052014-07-14 04:26:56 -07006039 if (my_data->external_spk_1)
6040 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1;
6041 else if (my_data->external_spk_2)
6042 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2;
Aalique Grahame22e49102018-12-18 14:23:57 -08006043 else if (adev->speaker_lr_swap) {
6044 /*
6045 * Perform device switch only if acdb tuning is
6046 * different between SPEAKER & SPEAKER_REVERSE,
6047 * Or there will be a small pause while performing
6048 * device switch.
6049 */
6050 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
6051 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE])
6052 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
6053 else
6054 snd_device = SND_DEVICE_OUT_SPEAKER;
6055 } else if (my_data->is_vbat_speaker || my_data->is_bcl_speaker)
Banajit Goswami20cdd212015-09-11 01:11:30 -07006056 snd_device = SND_DEVICE_OUT_SPEAKER_VBAT;
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306057 else if (my_data->is_wsa_speaker)
6058 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
Eric Laurentb23d5282013-05-14 15:27:20 -07006059 else
6060 snd_device = SND_DEVICE_OUT_SPEAKER;
6061 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08006062 if (adev->swb_speech_mode != SPEECH_MODE_INVALID)
6063 snd_device = SND_DEVICE_OUT_BT_SCO_SWB;
6064 else if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006065 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
6066 else
6067 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tanniru9d027a62015-03-13 01:32:10 +05306068 } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
6069 snd_device = SND_DEVICE_OUT_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07006070 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006071 switch(my_data->ext_disp_type) {
6072 case EXT_DISPLAY_TYPE_HDMI:
6073 snd_device = SND_DEVICE_OUT_HDMI;
6074 break;
6075 case EXT_DISPLAY_TYPE_DP:
6076 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
6077 break;
6078 default:
6079 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
6080 goto exit;
6081 }
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006082 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
6083 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08006084 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006085 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05306086 audio_extn_set_afe_proxy_channel_mixer(adev, 2, snd_device);
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306087 } else if (devices &
6088 (AUDIO_DEVICE_OUT_USB_DEVICE |
6089 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006090 if (audio_extn_qdsp_supported_usb())
Aalique Grahame22e49102018-12-18 14:23:57 -08006091 snd_device = SND_DEVICE_OUT_USB_HEADSET_SPEC;
6092 else if (audio_extn_usb_is_capture_supported())
Ashish Jain3e37a702016-11-25 12:27:15 +05306093 snd_device = SND_DEVICE_OUT_USB_HEADSET;
6094 else
6095 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07006096 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
6097 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07006098 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006099 /*HAC support for voice-ish audio (eg visual voicemail)*/
6100 if(adev->voice.hac)
6101 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
6102 else
6103 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006104 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08006105 channel_count = audio_extn_get_afe_proxy_channel_count();
6106 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006107 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Sachin Mohan Gadag3e6e3fd2019-03-14 17:37:05 +05306108 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count, snd_device);
Derek Chenf6318be2017-06-12 17:16:24 -04006109 } else if (devices & AUDIO_DEVICE_OUT_BUS) {
6110 snd_device = audio_extn_auto_hal_get_snd_device_for_car_audio_stream(out);
Eric Laurentb23d5282013-05-14 15:27:20 -07006111 } else {
6112 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
6113 }
6114exit:
6115 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
6116 return snd_device;
6117}
6118
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006119static snd_device_t get_snd_device_for_voice_comm_ecns_enabled(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006120 struct stream_in *in,
6121 audio_devices_t out_device __unused,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006122 audio_devices_t in_device)
6123{
6124 struct audio_device *adev = my_data->adev;
6125 snd_device_t snd_device = SND_DEVICE_NONE;
6126
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006127 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6128 if (my_data->fluence_in_spkr_mode) {
6129 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6130 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6131 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
6132 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6133 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6134 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306135 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006136 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6137 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6138 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
6139 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006140 snd_device = my_data->fluence_sb_enabled ?
6141 SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB
6142 : SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006143 }
6144 adev->acdb_settings |= DMIC_FLAG;
6145 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006146 snd_device = my_data->fluence_sb_enabled ?
6147 SND_DEVICE_IN_SPEAKER_MIC_SB
6148 : SND_DEVICE_IN_SPEAKER_MIC;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006149 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
6150 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6151 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6152 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
6153 adev->acdb_settings |= TMIC_FLAG;
6154 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6155 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006156 snd_device = my_data->fluence_sb_enabled ?
6157 SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB
6158 : SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006159 adev->acdb_settings |= DMIC_FLAG;
6160 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006161 snd_device = my_data->fluence_sb_enabled ?
6162 SND_DEVICE_IN_HANDSET_MIC_SB
6163 : SND_DEVICE_IN_HANDSET_MIC;
Vignesh Kulothungan033c7cb2018-07-12 11:35:57 -07006164 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6165 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006166 }
Carter Hsu2e429db2019-05-14 18:50:52 +08006167 in->enable_ec_port = true;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006168
6169 return snd_device;
6170}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006171
6172static snd_device_t get_snd_device_for_voice_comm_ecns_disabled(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006173 struct stream_in *in,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006174 audio_devices_t out_device,
6175 audio_devices_t in_device)
6176{
6177 struct audio_device *adev = my_data->adev;
6178 snd_device_t snd_device = SND_DEVICE_NONE;
6179
Eric Laurent637e2d42018-11-15 12:24:31 -08006180 if (in != NULL && in->enable_aec && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006181 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6182 if (my_data->fluence_in_spkr_mode) {
6183 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6184 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6185 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006186 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6187 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6188 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006189 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006190 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6191 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006192 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6193 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
6194 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006195 snd_device = my_data->fluence_sb_enabled ?
6196 SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_SB
6197 : SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006198 }
6199 adev->acdb_settings |= DMIC_FLAG;
6200 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006201 snd_device = my_data->fluence_sb_enabled ?
6202 SND_DEVICE_IN_SPEAKER_MIC_AEC_NS_SB
6203 : SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006204 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306205 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6206 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6207 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
6208 adev->acdb_settings |= TMIC_FLAG;
6209 } 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) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006212 snd_device = my_data->fluence_sb_enabled ?
6213 SND_DEVICE_IN_HANDSET_DMIC_AEC_NS_SB
6214 : SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006215 adev->acdb_settings |= DMIC_FLAG;
6216 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006217 snd_device = my_data->fluence_sb_enabled ?
6218 SND_DEVICE_IN_HANDSET_MIC_AEC_NS_SB
6219 : SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006220 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6221 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08006222 } 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 -07006223 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
6224 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006225 } else if (in != NULL && in->enable_aec) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006226 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6227 if (my_data->fluence_in_spkr_mode) {
6228 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6229 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6230 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006231 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6232 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6233 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006234 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006235 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6236 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006237 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6238 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
6239 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006240 snd_device = my_data->fluence_sb_enabled ?
6241 SND_DEVICE_IN_SPEAKER_DMIC_AEC_SB
6242 : SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006243 }
6244 adev->acdb_settings |= DMIC_FLAG;
6245 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006246 snd_device = my_data->fluence_sb_enabled ?
6247 SND_DEVICE_IN_SPEAKER_MIC_AEC_SB
6248 : SND_DEVICE_IN_SPEAKER_MIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006249 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306250 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6251 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6252 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
6253 adev->acdb_settings |= TMIC_FLAG;
6254 } 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) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006257 snd_device = my_data->fluence_sb_enabled ?
6258 SND_DEVICE_IN_HANDSET_DMIC_AEC_SB
6259 : SND_DEVICE_IN_HANDSET_DMIC_AEC;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006260 adev->acdb_settings |= DMIC_FLAG;
6261 } else
6262 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
6263 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6264 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
kunleiz1a1d26c2018-06-14 18:48:16 +08006265 } 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 -07006266 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
6267 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006268 } else if (in != NULL && in->enable_ns) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006269 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6270 if (my_data->fluence_in_spkr_mode) {
6271 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6272 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6273 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006274 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6275 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6276 snd_device = SND_DEVICE_IN_SPEAKER_TMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006277 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
Aalique Grahame22e49102018-12-18 14:23:57 -08006278 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6279 my_data->fluence_in_voice_comm) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006280 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6281 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
6282 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006283 snd_device = my_data->fluence_sb_enabled ?
6284 SND_DEVICE_IN_SPEAKER_DMIC_NS_SB
6285 : SND_DEVICE_IN_SPEAKER_DMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006286 }
6287 adev->acdb_settings |= DMIC_FLAG;
6288 } else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006289 snd_device = my_data->fluence_sb_enabled ?
6290 SND_DEVICE_IN_SPEAKER_MIC_NS_SB
6291 : SND_DEVICE_IN_SPEAKER_MIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006292 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306293 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6294 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6295 snd_device = SND_DEVICE_IN_HANDSET_TMIC_NS;
6296 adev->acdb_settings |= TMIC_FLAG;
6297 } 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) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006300 snd_device = my_data->fluence_sb_enabled ?
6301 SND_DEVICE_IN_HANDSET_DMIC_NS_SB
6302 : SND_DEVICE_IN_HANDSET_DMIC_NS;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006303 adev->acdb_settings |= DMIC_FLAG;
6304 } else
6305 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
6306 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6307 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
6308 }
6309 platform_set_echo_reference(adev, false, out_device);
6310 } else
6311 platform_set_echo_reference(adev, false, out_device);
6312
6313 return snd_device;
6314}
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006315
6316static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
Carter Hsu2e429db2019-05-14 18:50:52 +08006317 struct stream_in *in,
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006318 audio_devices_t out_device,
6319 audio_devices_t in_device)
6320{
6321 if(voice_extn_is_dynamic_ecns_enabled())
Carter Hsu2e429db2019-05-14 18:50:52 +08006322 return get_snd_device_for_voice_comm_ecns_enabled(my_data, in, out_device, in_device);
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006323 else
Carter Hsu2e429db2019-05-14 18:50:52 +08006324 return get_snd_device_for_voice_comm_ecns_disabled(my_data, in, out_device, in_device);
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08006325}
Vikram Pandurangadf59cae2017-08-03 18:04:55 -07006326
Eric Laurent637e2d42018-11-15 12:24:31 -08006327snd_device_t platform_get_input_snd_device(void *platform,
6328 struct stream_in *in,
6329 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07006330{
6331 struct platform_data *my_data = (struct platform_data *)platform;
6332 struct audio_device *adev = my_data->adev;
Eric Laurent637e2d42018-11-15 12:24:31 -08006333 audio_mode_t mode = adev->mode;
Eric Laurentb23d5282013-05-14 15:27:20 -07006334 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurent637e2d42018-11-15 12:24:31 -08006335
6336 if (in == NULL)
6337 in = adev_get_active_input(adev);
6338
6339 audio_source_t source = (in == NULL) ? AUDIO_SOURCE_DEFAULT : in->source;
6340 audio_devices_t in_device =
6341 ((in == NULL) ? AUDIO_DEVICE_NONE : in->device) & ~AUDIO_DEVICE_BIT_IN;
6342 audio_channel_mask_t channel_mask = (in == NULL) ? AUDIO_CHANNEL_IN_MONO : in->channel_mask;
6343 int channel_count = audio_channel_count_from_in_mask(channel_mask);
6344 int str_bitwidth = (in == NULL) ? CODEC_BACKEND_DEFAULT_BIT_WIDTH : in->bit_width;
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006345 int sample_rate = (in == NULL) ? 8000 : in->sample_rate;
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306346 struct audio_usecase *usecase = NULL;
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05306347 audio_usecase_t uc_id = (in == NULL) ? USECASE_AUDIO_RECORD : in->usecase;
Eric Laurentb23d5282013-05-14 15:27:20 -07006348
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306349 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
6350 __func__, out_device, in_device, channel_count, channel_mask);
Tanya Finkel00130052014-07-14 04:26:56 -07006351 if (my_data->external_mic) {
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08006352 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
6353 voice_check_voicecall_usecases_active(adev) ||
6354 voice_extn_compress_voip_is_active(adev) ||
6355 audio_extn_hfp_is_active(adev))) {
Tanya Finkel00130052014-07-14 04:26:56 -07006356 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6357 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
6358 out_device & AUDIO_DEVICE_OUT_SPEAKER )
6359 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
6360 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
6361 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
6362 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
6363 }
6364 }
6365
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07006366 if (snd_device != AUDIO_DEVICE_NONE)
Tanya Finkel00130052014-07-14 04:26:56 -07006367 goto exit;
6368
Kunlei Zhanga3b3abf2019-06-25 15:42:21 +08006369 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
6370 voice_check_voicecall_usecases_active(adev) ||
6371 voice_extn_compress_voip_is_active(adev) ||
6372 audio_extn_hfp_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08006373 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
6374 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07006375 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006376 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
6377 out_device & AUDIO_DEVICE_OUT_LINE) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006378 switch (adev->voice.tty_mode) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07006379 case TTY_MODE_FULL:
6380 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
6381 break;
6382 case TTY_MODE_VCO:
6383 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
6384 break;
6385 case TTY_MODE_HCO:
6386 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
6387 break;
6388 default:
6389 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
6390 }
6391 goto exit;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306392 } else if (out_device &
6393 (AUDIO_DEVICE_OUT_USB_DEVICE |
6394 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aniket Kumar Lata91886592017-05-25 16:53:32 -07006395 switch (adev->voice.tty_mode) {
6396 case TTY_MODE_FULL:
6397 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
6398 break;
6399 case TTY_MODE_VCO:
6400 // since voice will be captured from handset mic, use existing device
6401 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
6402 break;
6403 case TTY_MODE_HCO:
6404 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
6405 break;
6406 default:
6407 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07006408 }
6409 goto exit;
6410 }
6411 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07006412 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006413 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6414 out_device & AUDIO_DEVICE_OUT_LINE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006415 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
6416 audio_extn_should_use_handset_anc(channel_count)) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306417 if ((my_data->fluence_type != FLUENCE_NONE) &&
6418 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Shiv Maliyappanahallidd287262016-01-08 15:57:07 -08006419 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
6420 adev->acdb_settings |= DMIC_FLAG;
6421 } else {
6422 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
6423 }
Banajit Goswamide0ea452014-04-07 12:11:47 -07006424 adev->acdb_settings |= ANC_FLAG;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07006425 } else if (my_data->fluence_type == FLUENCE_NONE ||
Vikram Pandurangae7b21342017-06-05 15:57:23 -07006426 (my_data->fluence_in_voice_call == false &&
6427 my_data->fluence_in_hfp_call == false)) {
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306428 if (out_device & AUDIO_DEVICE_OUT_LINE &&
6429 audio_extn_hfp_is_active(adev)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006430 snd_device = my_data->fluence_sb_enabled ?
6431 SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB
6432 : SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306433 } else {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006434 snd_device = my_data->fluence_sb_enabled ?
6435 SND_DEVICE_IN_HANDSET_MIC_SB
6436 : SND_DEVICE_IN_HANDSET_MIC;
Ramu Gottipati97a89a42018-12-03 16:41:09 +05306437 }
6438 if (audio_extn_hfp_is_active(adev))
6439 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006440 } else {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306441 if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6442 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6443 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
6444 adev->acdb_settings |= TMIC_FLAG;
Aalique Grahame22e49102018-12-18 14:23:57 -08006445 } else if (is_operator_tmus())
6446 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
6447 else { /* for FLUENCE_DUAL_MIC and SOURCE_DUAL_MIC */
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006448 snd_device = my_data->fluence_sb_enabled ?
6449 SND_DEVICE_IN_VOICE_DMIC_SB
6450 : SND_DEVICE_IN_VOICE_DMIC;
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306451 adev->acdb_settings |= DMIC_FLAG;
6452 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006453 }
6454 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
6455 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05306456 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006457 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006458 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Zhou Song12c29502019-03-16 10:37:18 +08006459 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6460 if (adev->bluetooth_nrec)
6461 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6462 else
6463 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6464 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006465 if (adev->bluetooth_nrec)
6466 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6467 else
6468 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6469 } else {
6470 if (adev->bluetooth_nrec)
6471 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6472 else
6473 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6474 }
Aalique Grahame37659862017-12-03 22:34:26 -08006475 } else if ((out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
6476 adev->dp_allowed_for_voice) {
6477 if (audio_extn_usb_is_capture_supported())
6478 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
6479 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006480 snd_device = my_data->fluence_sb_enabled ?
6481 SND_DEVICE_IN_HANDSET_MIC_SB
6482 : SND_DEVICE_IN_HANDSET_MIC;
Aalique Grahame37659862017-12-03 22:34:26 -08006483
6484 if (voice_is_in_call(adev))
6485 platform_set_echo_reference(adev, true, out_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08006486 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
6487 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
6488 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Derek Chen25496072019-06-23 01:05:27 -07006489 out_device & AUDIO_DEVICE_OUT_LINE ||
6490 out_device & AUDIO_DEVICE_OUT_BUS) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006491 if (my_data->fluence_type != FLUENCE_NONE &&
Dhanalakshmi Siddani3dbfc382017-03-21 15:15:03 +05306492 (my_data->fluence_in_voice_call ||
6493 my_data->fluence_in_hfp_call) &&
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006494 my_data->fluence_in_spkr_mode) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306495 if((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6496 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306497 adev->acdb_settings |= QMIC_FLAG;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006498 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006499 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6500 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6501 adev->acdb_settings |= TMIC_FLAG;
6502 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_TMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006503 } else {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306504 adev->acdb_settings |= DMIC_FLAG;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08006505 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
6506 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
6507 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006508 snd_device = my_data->fluence_sb_enabled ?
6509 SND_DEVICE_IN_VOICE_SPEAKER_DMIC_SB
6510 : SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07006511 }
Dhanalakshmi Siddani1eb3a352017-06-05 15:18:23 +05306512 if (audio_extn_hfp_is_active(adev))
6513 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07006514 } else {
Aalique Grahame22e49102018-12-18 14:23:57 -08006515 if (adev->enable_hfp) {
6516 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006517 platform_set_echo_reference(adev, true, out_device);
Aalique Grahame22e49102018-12-18 14:23:57 -08006518 } else {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006519 snd_device = my_data->fluence_sb_enabled ?
6520 SND_DEVICE_IN_VOICE_SPEAKER_MIC_SB
6521 : SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006522 if (audio_extn_hfp_is_active(adev))
6523 platform_set_echo_reference(adev, true, out_device);
6524 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006525 }
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07006526 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07006527 snd_device = SND_DEVICE_IN_VOICE_RX;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306528 } else if (out_device &
6529 (AUDIO_DEVICE_OUT_USB_DEVICE |
6530 AUDIO_DEVICE_OUT_USB_HEADSET)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006531 if (audio_extn_usb_is_capture_supported()) {
6532 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
6533 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
6534 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
6535 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
6536 } else {
6537 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
6538 }
Aditya Bavanari8a715322019-04-08 20:04:56 +05306539 } else {
6540 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006541 }
juyuchen2d415992018-11-16 14:15:16 +08006542 } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) {
6543 snd_device = SND_DEVICE_IN_VOICE_HEARING_AID;
Aniket Kumar Lata3e2e1232017-06-16 17:25:07 -07006544 }
Dhananjay Kumar704ce6f2017-09-28 22:08:00 +05306545 } else if (my_data->use_generic_handset == true && // system prop is enabled
6546 (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available
6547 ((in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) || // AND device is buit-in mic or back mic
6548 (in_device & AUDIO_DEVICE_IN_BACK_MIC)) &&
6549 (my_data->fluence_in_audio_rec == true && // AND fluencepro is enabled
6550 my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6551 (source == AUDIO_SOURCE_CAMCORDER || // AND source is cam/mic/unprocessed
6552 source == AUDIO_SOURCE_UNPROCESSED ||
6553 source == AUDIO_SOURCE_MIC)) {
6554 snd_device = SND_DEVICE_IN_HANDSET_GENERIC_QMIC;
6555 platform_set_echo_reference(adev, true, out_device);
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306556 } else if (my_data->use_generic_handset == true && // System prop is enabled
6557 (my_data->ambisonic_capture == true) && // Enable Ambisonic capture
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05306558 (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306559 ((in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) || // AND device is Built-in
6560 (in_device & AUDIO_DEVICE_IN_BACK_MIC)) && // OR Back-mic
6561 (source == AUDIO_SOURCE_MIC || // AND source is MIC for 16bit
6562 source == AUDIO_SOURCE_UNPROCESSED || // OR unprocessed for 24bit
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006563 source == AUDIO_SOURCE_CAMCORDER) && // OR camera usecase
6564 ((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) && // AND 4mic channel mask
6565 (sample_rate == 48000)) { // AND sample rate is 48Khz
Sachin Mohan Gadagbe2054d2018-01-29 16:05:05 +05306566 snd_device = SND_DEVICE_IN_HANDSET_GENERIC_QMIC;
6567 /* Below check is true only in LA build to set
6568 ambisonic profile. In LE hal client will set profile
6569 */
Eric Laurent637e2d42018-11-15 12:24:31 -08006570 if (my_data->ambisonic_profile == true &&
6571 in != NULL)
6572 strlcpy(in->profile, "record_ambisonic",
6573 sizeof(in->profile));
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306574
Eric Laurent637e2d42018-11-15 12:24:31 -08006575 if (in != NULL && !strncmp(in->profile, "record_ambisonic",
6576 strlen("record_ambisonic"))) {
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306577 /* Validate input stream configuration for
6578 Ambisonic capture.
6579 */
6580 if (((int)channel_mask != (int)AUDIO_CHANNEL_INDEX_MASK_4) ||
Fawad Shaukat42d38e92019-05-08 22:40:54 -07006581 (sample_rate != 48000)) {
Sachin Mohan Gadage6aa1952018-03-05 17:50:02 +05306582 snd_device = SND_DEVICE_NONE;
6583 ALOGW("Unsupported Input configuration for ambisonic capture");
6584 goto exit;
6585 }
6586 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006587 } else if (source == AUDIO_SOURCE_CAMCORDER) {
6588 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
6589 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Eric Laurent4b084132018-10-19 17:33:43 -07006590 switch (adev->camera_orientation) {
6591 case CAMERA_BACK_LANDSCAPE:
6592 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
6593 break;
6594 case CAMERA_BACK_INVERT_LANDSCAPE:
6595 snd_device = SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE;
6596 break;
6597 case CAMERA_BACK_PORTRAIT:
6598 snd_device = SND_DEVICE_IN_CAMCORDER_PORTRAIT;
6599 break;
6600 case CAMERA_FRONT_LANDSCAPE:
6601 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE;
6602 break;
6603 case CAMERA_FRONT_INVERT_LANDSCAPE:
6604 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE;
6605 break;
6606 case CAMERA_FRONT_PORTRAIT:
6607 snd_device = SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT;
6608 break;
6609 default:
6610 ALOGW("%s: invalid camera orientation %08x", __func__, adev->camera_orientation);
6611 snd_device = SND_DEVICE_IN_CAMCORDER_LANDSCAPE;
6612 break;
6613 }
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306614 if (str_bitwidth == 16) {
6615 if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6616 (my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6617 (channel_count == 2))
Aalique Grahame22e49102018-12-18 14:23:57 -08006618 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306619 else
6620 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
6621 }
6622 /*
6623 * for other bit widths
6624 */
6625 else {
6626 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6627 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6628 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6629 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
6630 }
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306631 else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306632 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6633 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306634 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306635 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6636 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
6637 } else {
6638 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
6639 }
6640 }
6641 }
6642 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
Eric Laurentb23d5282013-05-14 15:27:20 -07006643 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306644 if (my_data->fluence_in_voice_rec && channel_count == 1) {
6645 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6646 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006647 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006648 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
6649 else
6650 snd_device = SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306651 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6652 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006653 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006654 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
6655 else
6656 snd_device = SND_DEVICE_IN_VOICE_REC_TMIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306657 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6658 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006659 if (in != NULL && in->enable_aec)
Aalique Grahame22e49102018-12-18 14:23:57 -08006660 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
6661 else
6662 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Vidyakumar Athota78b70c02015-06-29 17:19:45 -07006663 }
Carter Hsu2e429db2019-05-14 18:50:52 +08006664 in->enable_ec_port = true;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306665 } else if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6666 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6667 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6668 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306669 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306670 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6671 snd_device = SND_DEVICE_IN_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306672 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306673 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6674 snd_device = SND_DEVICE_IN_QUAD_MIC;
6675 }
6676 if (snd_device == SND_DEVICE_NONE) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006677 if (in != NULL && in->enable_aec) {
6678 if (in->enable_ns) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006679 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
6680 } else {
6681 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
6682 }
Eric Laurent637e2d42018-11-15 12:24:31 -08006683 } else if (in != NULL && in->enable_ns)
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306684 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
6685 else
6686 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08006687 }
Aalique Grahame22e49102018-12-18 14:23:57 -08006688 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6689 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306690 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006691 snd_device = fixup_usb_headset_mic_snd_device(platform,
6692 SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC,
6693 SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MULTI_CHANNEL_MIC);
Eric Laurentb23d5282013-05-14 15:27:20 -07006694 }
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306695 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
6696 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
6697 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
6698 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
6699 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
6700 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306701 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_3) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306702 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
6703 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Dhananjay Kumara5d42b32017-01-11 21:22:16 +05306704 } else if (((int)channel_mask == (int)AUDIO_CHANNEL_INDEX_MASK_4) &&
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306705 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
6706 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
6707 } else {
6708 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
6709 }
6710 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Arun Tom Abrahamf888ae82016-12-10 04:51:49 +05306711 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306712 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006713 snd_device = fixup_usb_headset_mic_snd_device(platform,
6714 SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC,
6715 SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MULTI_CHANNEL_MIC);
Chaithanya Krishna Bacharaju24f86f32016-05-26 16:34:53 +05306716 }
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05306717 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
6718 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006719 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
6720 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6721 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
6722 !audio_extn_usb_is_capture_supported()))
Eric Laurentb23d5282013-05-14 15:27:20 -07006723 in_device = AUDIO_DEVICE_IN_BACK_MIC;
kunleizdcf967a2018-08-07 17:09:11 +08006724 else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
6725 in_device = AUDIO_DEVICE_IN_BUILTIN_MIC;
6726 else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET)
6727 in_device = AUDIO_DEVICE_IN_WIRED_HEADSET;
6728 else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE)
6729 in_device = AUDIO_DEVICE_IN_USB_DEVICE;
6730
6731 in_device = ((out_device == AUDIO_DEVICE_NONE) ?
6732 AUDIO_DEVICE_IN_BUILTIN_MIC : in_device) & ~AUDIO_DEVICE_BIT_IN;
6733
Eric Laurent637e2d42018-11-15 12:24:31 -08006734 if (in)
Carter Hsu2e429db2019-05-14 18:50:52 +08006735 snd_device = get_snd_device_for_voice_comm(my_data, in, out_device, in_device);
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006736 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08006737 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
6738 channel_count == 1 ) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006739 if(my_data->fluence_in_audio_rec) {
Sujin Panickerb904fbe2019-04-04 13:28:07 +05306740 if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306741 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006742 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006743 platform_set_echo_reference(adev, true, out_device);
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306744 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
6745 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Aditya Bavanari4051c8d2017-12-13 13:31:26 +05306746 snd_device = SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO;
6747 } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
6748 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306749 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
6750 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
6751 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006752 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07006753 platform_set_echo_reference(adev, true, out_device);
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07006754 }
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08006755 }
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306756 } else if (in_device & AUDIO_DEVICE_IN_LOOPBACK) {
6757 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Chaithanya Krishna Bacharaju3e94c912019-05-27 11:25:44 +05306758 usecase = get_usecase_from_list(adev, uc_id);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05306759 if (usecase == NULL) {
6760 ALOGE("%s: Could not find the record usecase", __func__);
6761 snd_device = SND_DEVICE_NONE;
6762 goto exit;
6763 }
6764
6765 int ch_count = audio_channel_count_from_in_mask(channel_mask);
6766 snd_device = audio_extn_get_loopback_snd_device(adev, usecase,
6767 ch_count);
6768 ALOGD("%s: snd device %d", __func__, snd_device);
6769 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08006770 }
Mingming Yin12125e82015-10-26 20:40:36 -07006771 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07006772 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07006773 } else if (source == AUDIO_SOURCE_DEFAULT) {
6774 goto exit;
6775 }
6776
Eric Laurent637e2d42018-11-15 12:24:31 -08006777 if (in && (audio_extn_ssr_get_stream() == in))
Shiv Maliyappanahalli5a10aea2015-07-02 10:36:23 -07006778 snd_device = SND_DEVICE_IN_THREE_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006779
6780 if (snd_device != SND_DEVICE_NONE) {
6781 goto exit;
6782 }
6783
6784 if (in_device != AUDIO_DEVICE_NONE &&
6785 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
6786 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
6787 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Eric Laurent637e2d42018-11-15 12:24:31 -08006788 if ((in && (audio_extn_ssr_get_stream() == in)) ||
Aalique Grahame22e49102018-12-18 14:23:57 -08006789 ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
6790 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4))
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07006791 snd_device = SND_DEVICE_IN_QUAD_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006792 else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
6793 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3)
6794 snd_device = SND_DEVICE_IN_THREE_MIC;
Vikram Pandurangaf0ca0b12018-05-04 16:00:07 -07006795 else if ((my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_TRI_MIC | FLUENCE_QUAD_MIC)) &&
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306796 (channel_count == 2) && (my_data->source_mic_type & SOURCE_DUAL_MIC))
Aalique Grahame22e49102018-12-18 14:23:57 -08006797 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07006798 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006799 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6800 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006801 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006802 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6803 channel_count == 2)
6804 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
6805 else
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006806 snd_device = my_data->fluence_sb_enabled ?
6807 SND_DEVICE_IN_SPEAKER_MIC_SB
6808 : SND_DEVICE_IN_SPEAKER_MIC;
Ramu Gottipati813ae982018-07-25 14:14:48 +05306809 } else if (in_device & AUDIO_DEVICE_IN_LINE) {
6810 snd_device = SND_DEVICE_IN_LINE;
Eric Laurentb23d5282013-05-14 15:27:20 -07006811 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
6812 snd_device = SND_DEVICE_IN_HEADSET_MIC;
6813 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Zhou Song12c29502019-03-16 10:37:18 +08006814 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6815 if (adev->bluetooth_nrec)
6816 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6817 else
6818 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6819 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006820 if (adev->bluetooth_nrec)
6821 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6822 else
6823 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6824 } else {
6825 if (adev->bluetooth_nrec)
6826 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6827 else
6828 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6829 }
Ralf Herzafb164f2018-07-03 07:08:07 +02006830 } else if (in_device & AUDIO_DEVICE_IN_SPDIF) {
6831 snd_device = SND_DEVICE_IN_SPDIF;
Florian Pfister1a84f312018-07-19 14:38:18 +02006832 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
6833 snd_device = SND_DEVICE_IN_BT_A2DP;
Eric Laurentb23d5282013-05-14 15:27:20 -07006834 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
6835 snd_device = SND_DEVICE_IN_HDMI_MIC;
Ralf Herz76b455c2018-09-10 13:58:04 +02006836 } else if (in_device & AUDIO_DEVICE_IN_HDMI_ARC) {
Ralf Herzafb164f2018-07-03 07:08:07 +02006837 snd_device = SND_DEVICE_IN_HDMI_ARC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006838 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
6839 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
6840 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Mingming Yin12125e82015-10-26 20:40:36 -07006841 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07006842 snd_device = SND_DEVICE_IN_CAPTURE_FM;
kunleiz1a1d26c2018-06-14 18:48:16 +08006843 } 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 -07006844 snd_device = fixup_usb_headset_mic_snd_device(platform,
6845 SND_DEVICE_IN_USB_HEADSET_MIC,
6846 SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC);
Eric Laurentb23d5282013-05-14 15:27:20 -07006847 } else {
6848 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
6849 ALOGW("%s: Using default handset-mic", __func__);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006850 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6851 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006852 }
6853 } else {
6854 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006855 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6856 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006857 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
6858 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Aalique Grahame22e49102018-12-18 14:23:57 -08006859 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
6860 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306861 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
6862 (channel_count == 2)) {
Aalique Grahame22e49102018-12-18 14:23:57 -08006863 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306864 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
6865 (channel_count == 1)) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006866 snd_device = my_data->fluence_sb_enabled ?
6867 SND_DEVICE_IN_SPEAKER_MIC_SB
6868 : SND_DEVICE_IN_SPEAKER_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306869 } else {
6870 ALOGE("%s: something wrong: source type (%d) channel_count (%d) .."
6871 " no combination found .. setting to mono", __func__,
6872 my_data->source_mic_type, channel_count);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006873 snd_device = my_data->fluence_sb_enabled ?
6874 SND_DEVICE_IN_SPEAKER_MIC_SB
6875 : SND_DEVICE_IN_SPEAKER_MIC;
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05306876 }
Ravi Kumar Alamanda52de13c2015-10-17 22:21:52 -07006877 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
6878 out_device & AUDIO_DEVICE_OUT_LINE) {
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006879 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6880 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006881 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Zhou Song12c29502019-03-16 10:37:18 +08006882 if (adev->swb_speech_mode != SPEECH_MODE_INVALID) {
6883 if (adev->bluetooth_nrec)
6884 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB_NREC;
6885 else
6886 snd_device = SND_DEVICE_IN_BT_SCO_MIC_SWB;
6887 } else if (adev->bt_wb_speech_enabled) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07006888 if (adev->bluetooth_nrec)
6889 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
6890 else
6891 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
6892 } else {
6893 if (adev->bluetooth_nrec)
6894 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
6895 else
6896 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
6897 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006898 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
6899 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07006900 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
6901 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
6902 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Satya Krishna Pindiprolice227962017-12-13 16:07:14 +05306903 } else if (out_device &
6904 (AUDIO_DEVICE_OUT_USB_DEVICE |
6905 AUDIO_DEVICE_OUT_USB_HEADSET)) {
kunleiz1a1d26c2018-06-14 18:48:16 +08006906 if (audio_extn_usb_is_capture_supported() && audio_extn_usb_connected(NULL))
Karthikeyan Mani07faa602018-08-20 11:01:32 -07006907 snd_device = fixup_usb_headset_mic_snd_device(platform,
6908 SND_DEVICE_IN_USB_HEADSET_MIC,
6909 SND_DEVICE_IN_USB_HEADSET_MULTI_CHANNEL_MIC);
Ashish Jain3e37a702016-11-25 12:27:15 +05306910 else
6911 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirucb5b5782018-10-12 20:42:07 +05306912
Eric Laurentb23d5282013-05-14 15:27:20 -07006913 } else {
6914 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
6915 ALOGW("%s: Using default handset-mic", __func__);
Vignesh Kulothungandf9ed3c2019-01-23 17:44:01 -08006916 snd_device = my_data->fluence_sb_enabled ? SND_DEVICE_IN_HANDSET_MIC_SB
6917 : SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07006918 }
6919 }
6920exit:
6921 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
6922 return snd_device;
6923}
6924
6925int platform_set_hdmi_channels(void *platform, int channel_count)
6926{
6927 struct platform_data *my_data = (struct platform_data *)platform;
6928 struct audio_device *adev = my_data->adev;
6929 struct mixer_ctl *ctl;
6930 const char *channel_cnt_str = NULL;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006931 char *mixer_ctl_name;
Eric Laurentb23d5282013-05-14 15:27:20 -07006932 switch (channel_count) {
6933 case 8:
6934 channel_cnt_str = "Eight"; break;
6935 case 7:
6936 channel_cnt_str = "Seven"; break;
6937 case 6:
6938 channel_cnt_str = "Six"; break;
6939 case 5:
6940 channel_cnt_str = "Five"; break;
6941 case 4:
6942 channel_cnt_str = "Four"; break;
6943 case 3:
6944 channel_cnt_str = "Three"; break;
6945 default:
6946 channel_cnt_str = "Two"; break;
6947 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006948
6949 switch(my_data->ext_disp_type) {
6950 case EXT_DISPLAY_TYPE_HDMI:
6951 mixer_ctl_name = "HDMI_RX Channels";
6952 break;
6953 case EXT_DISPLAY_TYPE_DP:
6954 mixer_ctl_name = "Display Port RX Channels";
6955 break;
6956 default:
6957 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
6958 return -EINVAL;
6959 }
6960
Eric Laurentb23d5282013-05-14 15:27:20 -07006961 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
6962 if (!ctl) {
6963 ALOGE("%s: Could not get ctl for mixer cmd - %s",
6964 __func__, mixer_ctl_name);
6965 return -EINVAL;
6966 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07006967 ALOGV("Ext disp channel count: %s", channel_cnt_str);
Eric Laurentb23d5282013-05-14 15:27:20 -07006968 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
6969 return 0;
6970}
6971
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07006972int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07006973{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07006974 int channel_count;
6975 int max_channels = 2;
6976 int i = 0, ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07006977 struct platform_data *my_data = (struct platform_data *)platform;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07006978 edid_audio_info *info = NULL;
6979 ret = platform_get_edid_info(platform);
6980 info = (edid_audio_info *)my_data->edid_info;
Eric Laurentb23d5282013-05-14 15:27:20 -07006981
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07006982 if(ret == 0 && info != NULL) {
6983 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
6984 ALOGV("%s:format %d channel %d", __func__,
6985 info->audio_blocks_array[i].format_id,
6986 info->audio_blocks_array[i].channels);
6987 if (info->audio_blocks_array[i].format_id == LPCM) {
6988 channel_count = info->audio_blocks_array[i].channels;
6989 if (channel_count > max_channels) {
6990 max_channels = channel_count;
6991 }
6992 }
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07006993 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006994 }
Eric Laurentb23d5282013-05-14 15:27:20 -07006995 return max_channels;
6996}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07006997
6998static int platform_set_slowtalk(struct platform_data *my_data, bool state)
6999{
7000 int ret = 0;
7001 struct audio_device *adev = my_data->adev;
7002 struct mixer_ctl *ctl;
7003 const char *mixer_ctl_name = "Slowtalk Enable";
Manish Dewangan338c50a2017-09-12 15:22:03 +05307004 long set_values[ ] = {0,
7005 ALL_SESSION_VSID};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007006
7007 set_values[0] = state;
7008 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7009 if (!ctl) {
7010 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7011 __func__, mixer_ctl_name);
7012 ret = -EINVAL;
7013 } else {
7014 ALOGV("Setting slowtalk state: %d", state);
7015 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
7016 my_data->slowtalk = state;
7017 }
7018
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08007019 if (my_data->csd != NULL) {
7020 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
7021 if (ret < 0) {
7022 ALOGE("%s: csd_client_disable_device, failed, error %d",
7023 __func__, ret);
7024 }
7025 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007026 return ret;
7027}
7028
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307029static int set_hd_voice(struct platform_data *my_data, bool state)
7030{
7031 struct audio_device *adev = my_data->adev;
7032 struct mixer_ctl *ctl;
7033 char *mixer_ctl_name = "HD Voice Enable";
7034 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +05307035 long set_values[ ] = {0,
7036 ALL_SESSION_VSID};
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307037
7038 set_values[0] = state;
7039 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7040 if (!ctl) {
7041 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7042 __func__, mixer_ctl_name);
7043 return -EINVAL;
7044 } else {
7045 ALOGV("Setting HD Voice state: %d", state);
7046 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
7047 my_data->hd_voice = state;
7048 }
7049
7050 return ret;
7051}
Tanya Finkel00130052014-07-14 04:26:56 -07007052
7053static int update_external_device_status(struct platform_data *my_data,
7054 char* event_name, bool status)
7055{
7056 int ret = 0;
7057 struct audio_usecase *usecase;
7058 struct listnode *node;
7059
7060 ALOGD("Recieved external event switch %s", event_name);
7061
7062 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
7063 my_data->external_spk_1 = status;
7064 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
7065 my_data->external_spk_2 = status;
7066 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
7067 my_data->external_mic = status;
7068 else {
7069 ALOGE("The audio event type is not found");
7070 return -EINVAL;
7071 }
7072
7073 list_for_each(node, &my_data->adev->usecase_list) {
7074 usecase = node_to_item(node, struct audio_usecase, list);
7075 select_devices(my_data->adev, usecase->id);
7076 }
7077
7078 return ret;
7079}
7080
Ben Rombergera04fabc2014-11-14 12:16:03 -08007081static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
7082{
7083 int err;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007084 char value[64];
7085 int ret = 0;
7086
7087 if(parms == NULL || cal == NULL)
7088 return ret;
7089
7090 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
7091 if (err >= 0) {
7092 str_parms_del(parms, "cal_persist");
7093 cal->persist = (uint32_t) strtoul(value, NULL, 0);
7094 ret = ret | 0x1;
7095 }
7096 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
7097 if (err >= 0) {
7098 str_parms_del(parms, "cal_apptype");
7099 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
7100 ret = ret | 0x2;
7101 }
7102 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
7103 if (err >= 0) {
7104 str_parms_del(parms, "cal_caltype");
7105 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
7106 ret = ret | 0x4;
7107 }
7108 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
7109 if (err >= 0) {
7110 str_parms_del(parms, "cal_samplerate");
7111 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
7112 ret = ret | 0x8;
7113 }
7114 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
7115 if (err >= 0) {
7116 str_parms_del(parms, "cal_devid");
7117 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
7118 ret = ret | 0x10;
7119 }
7120 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
7121 if (err >= 0) {
7122 str_parms_del(parms, "cal_snddevid");
7123 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
7124 ret = ret | 0x20;
7125 }
7126 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
7127 if (err >= 0) {
7128 str_parms_del(parms, "cal_topoid");
7129 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
7130 ret = ret | 0x40;
7131 }
7132 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
7133 if (err >= 0) {
7134 str_parms_del(parms, "cal_moduleid");
7135 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
7136 ret = ret | 0x80;
7137 }
Aditya Bavanari29bcea22017-10-03 20:10:35 +05307138#ifdef INSTANCE_ID_ENABLED
7139 err = str_parms_get_str(parms, "cal_instanceid", value, sizeof(value));
7140 if (err >= 0) {
7141 str_parms_del(parms, "cal_instanceid");
7142 cal->instance_id = (uint32_t) strtoul(value, NULL, 0);
7143 ret = ret | 0x100;
7144 }
7145#endif
Ben Rombergera04fabc2014-11-14 12:16:03 -08007146 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
7147 if (err >= 0) {
7148 str_parms_del(parms, "cal_paramid");
7149 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
Aditya Bavanari29bcea22017-10-03 20:10:35 +05307150 ret = ret | 0x200;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007151 }
7152 return ret;
7153}
7154
7155static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
7156 struct platform_data *my_data = (struct platform_data *)platform;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007157 struct stream_out out;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307158 acdb_audio_cal_cfg_t cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007159 uint8_t *dptr = NULL;
7160 int32_t dlen;
7161 int err, ret;
7162 if(value == NULL || platform == NULL || parms == NULL) {
7163 ALOGE("[%s] received null pointer, failed",__func__);
7164 goto done_key_audcal;
7165 }
7166
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05307167 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007168 /* parse audio calibration keys */
7169 ret = parse_audiocal_cfg(parms, &cal);
7170
7171 /* handle audio calibration data now */
7172 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
7173 if (err >= 0) {
7174 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
7175 dlen = strlen(value);
7176 if(dlen <= 0) {
7177 ALOGE("[%s] null data received",__func__);
7178 goto done_key_audcal;
7179 }
7180 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
7181 if(dptr == NULL) {
7182 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
7183 goto done_key_audcal;
7184 }
Aalique Grahame22e49102018-12-18 14:23:57 -08007185 dlen = b64_pton(value, dptr, dlen);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007186 if(dlen<=0) {
7187 ALOGE("[%s] data decoding failed %d", __func__, dlen);
7188 goto done_key_audcal;
7189 }
7190
Eric Laurent637e2d42018-11-15 12:24:31 -08007191 if (cal.dev_id) {
7192 if (audio_is_input_device(cal.dev_id)) {
7193 // FIXME: why pass an input device whereas
7194 // platform_get_input_snd_device() expects as an output device?
7195 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007196 } else {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007197 out.devices = cal.dev_id;
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08007198 out.sample_rate = cal.sampling_rate;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007199 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007200 }
7201 }
7202 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
7203 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
7204 cal.snd_dev_id, cal.acdb_dev_id);
7205 if(cal.acdb_dev_id == -EINVAL) {
7206 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
7207 __func__, cal.acdb_dev_id, cal.snd_dev_id);
7208 goto done_key_audcal;
7209 }
7210 if(my_data->acdb_set_audio_cal) {
7211 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
7212 }
7213 }
7214done_key_audcal:
7215 if(dptr != NULL)
7216 free(dptr);
7217}
7218
Ashish Jainf1eaa582016-05-23 20:54:24 +05307219static void true_32_bit_set_params(struct str_parms *parms,
7220 char *value, int len)
7221{
7222 int ret = 0;
7223
7224 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT,
7225 value,len);
7226 if (ret >= 0) {
Ramlal Karra10d22b92019-08-08 19:02:35 +05307227 if (value && !strncmp(value, "true", sizeof("true")))
Ashish Jainf1eaa582016-05-23 20:54:24 +05307228 supports_true_32_bit = true;
7229 else
7230 supports_true_32_bit = false;
7231 str_parms_del(parms, AUDIO_PARAMETER_KEY_TRUE_32_BIT);
7232 }
7233
7234}
7235
7236bool platform_supports_true_32bit()
7237{
7238 return supports_true_32_bit;
7239}
7240
Sudheer Papothifa9d2282015-09-17 01:53:25 +05307241static void perf_lock_set_params(struct platform_data *platform,
7242 struct str_parms *parms,
7243 char *value, int len)
7244{
7245 int err = 0, i = 0, num_opts = 0;
7246 char *test_r = NULL;
7247 char *opts = NULL;
7248 char *opts_size = NULL;
7249
7250 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS,
7251 value, len);
7252 if (err >= 0) {
7253 opts_size = strtok_r(value, ", ", &test_r);
7254 if (opts_size == NULL) {
7255 ALOGE("%s: incorrect perf lock opts\n", __func__);
7256 return;
7257 }
7258 num_opts = atoi(opts_size);
7259 if (num_opts > 0) {
7260 if (num_opts > MAX_PERF_LOCK_OPTS) {
7261 ALOGD("%s: num_opts %d exceeds max %d, setting to max\n",
7262 __func__, num_opts, MAX_PERF_LOCK_OPTS);
7263 num_opts = MAX_PERF_LOCK_OPTS;
7264 }
7265 for (i = 0; i < num_opts; i++) {
7266 opts = strtok_r(NULL, ", ", &test_r);
7267 if (opts == NULL) {
7268 ALOGE("%s: incorrect perf lock opts\n", __func__);
7269 break;
7270 }
7271 platform->adev->perf_lock_opts[i] = strtoul(opts, NULL, 16);
7272 }
7273 platform->adev->perf_lock_opts_size = i;
7274 }
7275 str_parms_del(parms, AUDIO_PARAMETER_KEY_PERF_LOCK_OPTS);
7276 }
7277}
7278
Surendar Karka45850ae2018-07-02 17:45:27 +05307279static void platform_spkr_device_set_params(struct platform_data *platform,
7280 struct str_parms *parms,
7281 char *value, int len)
7282{
7283 int err = 0, i = 0, num_ch = 0;
7284 char *test_r = NULL;
7285 char *opts = NULL;
7286 char *ch_count = NULL;
7287
7288 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP,
7289 value, len);
7290 if (err >= 0) {
7291 platform->spkr_ch_map = calloc(1, sizeof(struct spkr_device_chmap));
7292 if (!platform->spkr_ch_map) {
7293 ALOGE("%s: failed to allocate mem for adm channel map\n", __func__);
7294 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7295 return ;
7296 }
7297
7298 ch_count = strtok_r(value, ", ", &test_r);
7299 if (ch_count == NULL) {
7300 ALOGE("%s: incorrect ch_map\n", __func__);
7301 free(platform->spkr_ch_map);
7302 platform->spkr_ch_map = NULL;
7303 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7304 return;
7305 }
7306
7307 num_ch = atoi(ch_count);
7308 if ((num_ch > 0) && (num_ch <= AUDIO_CHANNEL_COUNT_MAX) ) {
7309 platform->spkr_ch_map->num_ch = num_ch;
7310 for (i = 0; i < num_ch; i++) {
7311 opts = strtok_r(NULL, ", ", &test_r);
Jhansi Konathalad72b20e2018-10-16 13:35:14 +05307312 if (opts == NULL) {
7313 ALOGE("%s: incorrect ch_map\n", __func__);
7314 free(platform->spkr_ch_map);
7315 platform->spkr_ch_map = NULL;
7316 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7317 return;
7318 } else {
7319 platform->spkr_ch_map->chmap[i] = strtoul(opts, NULL, 16);
7320 }
Surendar Karka45850ae2018-07-02 17:45:27 +05307321 }
7322 }
7323 str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
7324 }
7325}
7326
Jhansi Konathala170875c2018-10-11 18:34:10 +05307327static void platform_set_fluence_params(void *platform, struct str_parms *parms, char *value, int len)
7328{
7329 struct platform_data *my_data = (struct platform_data *)platform;
7330 int err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value, len);
7331
7332 if (err >= 0) {
7333 if (!strncmp("fluence", value, sizeof("fluence")))
7334 my_data->fluence_type = FLUENCE_DUAL_MIC;
7335 else if (!strncmp("fluencepro", value, sizeof("fluencepro")))
7336 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
7337 else if (!strncmp("none", value, sizeof("none")))
7338 my_data->fluence_type = FLUENCE_NONE;
7339
7340 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_TYPE);
7341 }
7342
7343 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC, value, len);
7344 if (err >= 0) {
7345 if (!strncmp("true", value, sizeof("true")))
7346 my_data->fluence_type |= FLUENCE_TRI_MIC;
7347
7348 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_TRI_MIC);
7349 }
7350
7351 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL, value, len);
7352 if (err >= 0) {
7353 if (!strncmp("true", value, sizeof("true")))
7354 my_data->fluence_in_voice_call = true;
7355 else
7356 my_data->fluence_in_voice_call = false;
7357
7358 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_CALL);
7359 }
7360
7361 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC, value, len);
7362 if (err >= 0) {
7363 if (!strncmp("true", value, sizeof("true")))
7364 my_data->fluence_in_voice_rec = true;
7365 else
7366 my_data->fluence_in_voice_rec = false;
7367
7368 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_VOICE_REC);
7369 }
7370
7371 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC, value, len);
7372 if (err >= 0) {
7373 if (!strncmp("true", value, sizeof("true")))
7374 my_data->fluence_in_audio_rec = true;
7375 else
7376 my_data->fluence_in_audio_rec = false;
7377
7378 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_AUDIO_REC);
7379 }
7380
7381 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER, value, len);
7382 if (err >= 0) {
7383 if (!strncmp("true", value, sizeof("true")))
7384 my_data->fluence_in_spkr_mode = true;
7385 else
7386 my_data->fluence_in_spkr_mode = false;
7387
7388 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_SPEAKER);
7389 }
7390
7391 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_MODE, value, len);
7392 if (err >= 0) {
7393 if (!strncmp("broadside", value, sizeof("broadside")))
7394 my_data->fluence_mode = FLUENCE_BROADSIDE;
7395 else if (!strncmp("endfire", value, sizeof("endfire")))
7396 my_data->fluence_mode = FLUENCE_ENDFIRE;
7397
7398 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_MODE);
7399 }
7400
7401 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL, value, len);
7402 if (err >= 0) {
7403 if (!strncmp("true", value, sizeof("true")))
7404 my_data->fluence_in_hfp_call = true;
7405 else
7406 my_data->fluence_in_hfp_call = false;
7407
7408 str_parms_del(parms, AUDIO_PARAMETER_KEY_FLUENCE_HFPCALL);
7409 }
7410}
7411
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007412int platform_set_parameters(void *platform, struct str_parms *parms)
7413{
7414 struct platform_data *my_data = (struct platform_data *)platform;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007415 char *value=NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307416 int len;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007417 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007418 char *kv_pairs = str_parms_to_str(parms);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05307419 struct listnode *node;
7420 struct meta_key_list *key_info;
7421 int key = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007422
Mingming Yin7b762e72015-03-04 13:47:32 -08007423 if(kv_pairs == NULL) {
7424 ret = -ENOMEM;
7425 ALOGE("[%s] key-value pair is NULL",__func__);
7426 goto done;
7427 }
7428
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007429 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007430
Ben Rombergera04fabc2014-11-14 12:16:03 -08007431 len = strlen(kv_pairs);
7432 value = (char*)calloc(len, sizeof(char));
7433 if(value == NULL) {
7434 ret = -ENOMEM;
7435 ALOGE("[%s] failed to allocate memory",__func__);
7436 goto done;
7437 }
7438 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007439 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007440 bool state = false;
7441 if (!strncmp("true", value, sizeof("true"))) {
7442 state = true;
7443 }
7444
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007445 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007446 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007447 if (ret)
7448 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007449 }
7450
Ben Rombergera04fabc2014-11-14 12:16:03 -08007451 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, len);
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307452 if (err >= 0) {
7453 bool state = false;
7454 if (!strncmp("true", value, sizeof("true"))) {
7455 state = true;
7456 }
7457
7458 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
7459 if (my_data->hd_voice != state) {
7460 ret = set_hd_voice(my_data, state);
7461 if (ret)
7462 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
7463 } else {
7464 ALOGV("%s: HD Voice already set to %d", __func__, state);
7465 }
7466 }
7467
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007468 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergera04fabc2014-11-14 12:16:03 -08007469 value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08007470 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08007471 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
7472
7473 if (my_data->acdb_reload_vocvoltable == NULL) {
7474 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
7475 } else if (!strcmp(value, "on")) {
7476 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
7477 my_data->voice_feature_set = 1;
7478 }
7479 } else {
7480 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
7481 my_data->voice_feature_set = 0;
7482 }
7483 }
7484 }
7485
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05307486 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB,
7487 value, len);
7488 if (err >= 0) {
7489 str_parms_del(parms, AUDIO_PARAMETER_KEY_RELOAD_ACDB);
7490
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05307491 if (my_data->acdb_reload_v2) {
7492 my_data->acdb_reload_v2(value, my_data->snd_card_name,
7493 my_data->cvd_version, &my_data->acdb_meta_key_list);
7494 } else if (my_data->acdb_reload) {
7495 node = list_head(&my_data->acdb_meta_key_list);
7496 key_info = node_to_item(node, struct meta_key_list, list);
7497 key = key_info->cal_info.nKey;
7498 my_data->acdb_reload(value, my_data->snd_card_name,
7499 my_data->cvd_version, key);
7500 }
Karthik Reddy Kattaeda85aa2016-05-25 12:42:39 +05307501 }
7502
Rohit kumard3c3b912016-11-15 18:50:31 +05307503 if (hw_info_is_stereo_spkr(my_data->hw_info)) {
7504 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER, value, len);
7505 if (err >= 0) {
7506 if (!strncmp("left", value, sizeof("left")))
7507 my_data->mono_speaker = SPKR_1;
7508 else if (!strncmp("right", value, sizeof("right")))
7509 my_data->mono_speaker = SPKR_2;
Rohit kumarf4120402016-08-05 19:19:48 +05307510
Rohit kumard3c3b912016-11-15 18:50:31 +05307511 str_parms_del(parms, AUDIO_PARAMETER_KEY_MONO_SPEAKER);
7512 }
Rohit kumarf4120402016-08-05 19:19:48 +05307513 }
Tanya Finkel00130052014-07-14 04:26:56 -07007514 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE,
Ben Rombergera04fabc2014-11-14 12:16:03 -08007515 value, len);
Tanya Finkel00130052014-07-14 04:26:56 -07007516 if (err >= 0) {
7517 char *event_name, *status_str;
7518 bool status = false;
7519 str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE);
7520 event_name = strtok_r(value, ",", &status_str);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08007521 if (!event_name) {
7522 ret = -EINVAL;
7523 ALOGE("%s: event_name is NULL", __func__);
7524 goto done;
7525 }
Tanya Finkel00130052014-07-14 04:26:56 -07007526 ALOGV("%s: recieved update of external audio device %s %s",
7527 __func__,
7528 event_name, status_str);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07007529 if (!strncmp(status_str, "ON", sizeof("ON")))
Tanya Finkel00130052014-07-14 04:26:56 -07007530 status = true;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07007531 else if (!strncmp(status_str, "OFF", sizeof("OFF")))
Tanya Finkel00130052014-07-14 04:26:56 -07007532 status = false;
7533 update_external_device_status(my_data, event_name, status);
7534 }
7535
Aalique Grahame22e49102018-12-18 14:23:57 -08007536 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
7537 value, len);
7538 if (err >= 0) {
7539 struct operator_info *info;
Weiyin Jiang2995f662019-04-17 14:25:12 +08007540 char *str = value, *context = NULL;
Aalique Grahame22e49102018-12-18 14:23:57 -08007541 char *name;
7542
7543 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
7544 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
Weiyin Jiang2995f662019-04-17 14:25:12 +08007545 name = strtok_r(str, ";", &context);
7546 if ((info == NULL) || (name == NULL)) {
7547 ret = -EINVAL;
7548 ALOGE("%s invalid info or name", __func__);
7549 goto done;
7550 }
7551
Aalique Grahame22e49102018-12-18 14:23:57 -08007552 info->name = strdup(name);
7553 info->mccmnc = strdup(str + strlen(name) + 1);
7554
7555 list_add_tail(&operator_info_list, &info->list);
7556 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
7557 }
7558
Chaithanya Krishna Bacharaju9955b162016-05-25 16:25:53 +05307559 err = str_parms_get_str(parms, PLATFORM_MAX_MIC_COUNT,
7560 value, sizeof(value));
7561 if (err >= 0) {
7562 str_parms_del(parms, PLATFORM_MAX_MIC_COUNT);
7563 my_data->max_mic_count = atoi(value);
7564 ALOGV("%s: max_mic_count %d", __func__, my_data->max_mic_count);
7565 }
7566
Jhansi Konathala170875c2018-10-11 18:34:10 +05307567 platform_set_fluence_params(platform, parms, value, len);
7568
Ben Rombergera04fabc2014-11-14 12:16:03 -08007569 /* handle audio calibration parameters */
7570 set_audiocal(platform, parms, value, len);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007571 native_audio_set_params(platform, parms, value, len);
Sudheer Papothi991966d2015-07-20 21:54:36 +05307572 audio_extn_spkr_prot_set_parameters(parms, value, len);
Kuirong Wang1cad7142016-05-24 15:21:56 -07007573 audio_extn_usb_set_sidetone_gain(parms, value, len);
Aalique Grahame22e49102018-12-18 14:23:57 -08007574 audio_extn_hfp_set_parameters(my_data->adev, parms);
Sudheer Papothifa9d2282015-09-17 01:53:25 +05307575 perf_lock_set_params(platform, parms, value, len);
Ashish Jainf1eaa582016-05-23 20:54:24 +05307576 true_32_bit_set_params(parms, value, len);
Ramlal Karra10d22b92019-08-08 19:02:35 +05307577 audio_extn_hifi_filter_set_params(parms, value, len);
Surendar Karka45850ae2018-07-02 17:45:27 +05307578 platform_spkr_device_set_params(platform, parms, value, len);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007579done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007580 ALOGV("%s: exit with code(%d)", __func__, ret);
Mingming Yin7b762e72015-03-04 13:47:32 -08007581 if(kv_pairs != NULL)
7582 free(kv_pairs);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007583 if(value != NULL)
7584 free(value);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007585 return ret;
7586}
7587
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007588int platform_set_incall_recording_session_id(void *platform,
7589 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07007590{
7591 int ret = 0;
7592 struct platform_data *my_data = (struct platform_data *)platform;
7593 struct audio_device *adev = my_data->adev;
7594 struct mixer_ctl *ctl;
7595 const char *mixer_ctl_name = "Voc VSID";
7596 int num_ctl_values;
7597 int i;
7598
7599 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7600 if (!ctl) {
7601 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7602 __func__, mixer_ctl_name);
7603 ret = -EINVAL;
7604 } else {
7605 num_ctl_values = mixer_ctl_get_num_values(ctl);
7606 for (i = 0; i < num_ctl_values; i++) {
7607 if (mixer_ctl_set_value(ctl, i, session_id)) {
7608 ALOGV("Error: invalid session_id: %x", session_id);
7609 ret = -EINVAL;
7610 break;
7611 }
7612 }
7613 }
7614
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007615 if (my_data->csd != NULL) {
7616 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
7617 if (ret < 0) {
7618 ALOGE("%s: csd_client_start_record failed, error %d",
7619 __func__, ret);
7620 }
7621 }
7622
7623 return ret;
7624}
7625
Aalique Grahame22e49102018-12-18 14:23:57 -08007626#ifdef INCALL_STEREO_CAPTURE_ENABLED
7627int platform_set_incall_recording_session_channels(void *platform,
7628 uint32_t channel_count)
7629{
7630 int ret = 0;
7631 struct platform_data *my_data = (struct platform_data *)platform;
7632 struct audio_device *adev = my_data->adev;
7633 const char *mixer_ctl_name = "Voc Rec Config";
7634 int num_ctl_values;
7635 int i;
7636 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
7637
7638 if (!ctl) {
7639 ALOGE("%s: Could not get ctl for mixer cmd - %s",
7640 __func__, mixer_ctl_name);
7641 ret = -EINVAL;
7642 } else {
7643 num_ctl_values = mixer_ctl_get_num_values(ctl);
7644 for (i = 0; i < num_ctl_values; i++) {
7645 if (mixer_ctl_set_value(ctl, i, channel_count)) {
7646 ALOGE("Error: invalid channel count: %x", channel_count);
7647 ret = -EINVAL;
7648 break;
7649 }
7650 }
7651 }
7652
7653 return ret;
7654}
7655#endif /* INCALL_STEREO_CAPTURE_ENABLED end */
7656
Vidyakumar Athota2850d532013-11-19 16:02:12 -08007657int platform_stop_incall_recording_usecase(void *platform)
7658{
7659 int ret = 0;
7660 struct platform_data *my_data = (struct platform_data *)platform;
7661
7662 if (my_data->csd != NULL) {
7663 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
7664 if (ret < 0) {
7665 ALOGE("%s: csd_client_stop_record failed, error %d",
7666 __func__, ret);
7667 }
7668 }
7669
7670 return ret;
7671}
7672
7673int platform_start_incall_music_usecase(void *platform)
7674{
7675 int ret = 0;
7676 struct platform_data *my_data = (struct platform_data *)platform;
7677
7678 if (my_data->csd != NULL) {
7679 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
7680 if (ret < 0) {
7681 ALOGE("%s: csd_client_start_playback failed, error %d",
7682 __func__, ret);
7683 }
7684 }
7685
7686 return ret;
7687}
7688
7689int platform_stop_incall_music_usecase(void *platform)
7690{
7691 int ret = 0;
7692 struct platform_data *my_data = (struct platform_data *)platform;
7693
7694 if (my_data->csd != NULL) {
7695 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
7696 if (ret < 0) {
7697 ALOGE("%s: csd_client_stop_playback failed, error %d",
7698 __func__, ret);
7699 }
7700 }
7701
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07007702 return ret;
7703}
7704
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07007705int platform_update_lch(void *platform, struct voice_session *session,
7706 enum voice_lch_mode lch_mode)
7707{
7708 int ret = 0;
7709 struct platform_data *my_data = (struct platform_data *)platform;
7710
7711 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
7712 ret = my_data->csd->set_lch(session->vsid, lch_mode);
7713 else
7714 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
7715
7716 return ret;
7717}
7718
Ben Rombergera04fabc2014-11-14 12:16:03 -08007719static void get_audiocal(void *platform, void *keys, void *pReply) {
7720 struct platform_data *my_data = (struct platform_data *)platform;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007721 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007722 struct str_parms *query = (struct str_parms *)keys;
7723 struct str_parms *reply=(struct str_parms *)pReply;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05307724 acdb_audio_cal_cfg_t cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007725 uint8_t *dptr = NULL;
7726 char value[512] = {0};
7727 char *rparms=NULL;
7728 int ret=0, err;
7729 uint32_t param_len;
7730
7731 if(query==NULL || platform==NULL || reply==NULL) {
7732 ALOGE("[%s] received null pointer",__func__);
7733 ret=-EINVAL;
7734 goto done;
7735 }
Aditya Bavanarie293d5b2017-11-15 12:48:36 +05307736
7737 memset(&cal, 0, sizeof(acdb_audio_cal_cfg_t));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007738 /* parse audiocal configuration keys */
7739 ret = parse_audiocal_cfg(query, &cal);
7740 if(ret == 0) {
7741 /* No calibration keys found */
7742 goto done;
7743 }
7744 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
7745 if (err >= 0) {
7746 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
7747 } else {
7748 goto done;
7749 }
7750
Eric Laurent637e2d42018-11-15 12:24:31 -08007751 if (cal.dev_id & AUDIO_DEVICE_BIT_IN) {
7752 cal.snd_dev_id = platform_get_input_snd_device(platform, NULL, cal.dev_id);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007753 } else if(cal.dev_id) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007754 out.devices = cal.dev_id;
Leena Winterrowdd7a04cd2016-01-07 11:50:02 -08007755 out.sample_rate = cal.sampling_rate;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08007756 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08007757 }
7758 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
7759 if (cal.acdb_dev_id < 0) {
7760 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
7761 __func__, cal.snd_dev_id);
7762 ret = -EINVAL;
7763 goto done_key_audcal;
7764 }
7765 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
7766 __func__, cal.snd_dev_id, cal.acdb_dev_id);
7767
7768 param_len = MAX_SET_CAL_BYTE_SIZE;
7769 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
7770 if(dptr == NULL) {
7771 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
7772 ret = -ENOMEM;
7773 goto done_key_audcal;
7774 }
7775 if (my_data->acdb_get_audio_cal != NULL) {
7776 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
7777 if (ret == 0) {
Ben Rombergera04fabc2014-11-14 12:16:03 -08007778 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
7779 ret = -EINVAL;
7780 goto done_key_audcal;
7781 }
7782 /* Allocate memory for encoding */
7783 rparms = (char*)calloc((param_len*2), sizeof(char));
7784 if(rparms == NULL) {
7785 ALOGE("[%s] Memory allocation failed for size %d",
7786 __func__, param_len*2);
7787 ret = -ENOMEM;
7788 goto done_key_audcal;
7789 }
7790 if(cal.persist==0 && cal.module_id && cal.param_id) {
7791 err = b64encode(dptr+12, param_len-12, rparms);
7792 } else {
7793 err = b64encode(dptr, param_len, rparms);
7794 }
7795 if(err < 0) {
7796 ALOGE("[%s] failed to convert data to string", __func__);
7797 ret = -EINVAL;
7798 goto done_key_audcal;
7799 }
7800 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
7801 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
7802 }
7803 }
7804done_key_audcal:
7805 if(ret != 0) {
7806 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
7807 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
7808 }
7809done:
7810 if(dptr != NULL)
7811 free(dptr);
7812 if(rparms != NULL)
7813 free(rparms);
7814}
7815
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007816void platform_get_parameters(void *platform,
7817 struct str_parms *query,
7818 struct str_parms *reply)
7819{
7820 struct platform_data *my_data = (struct platform_data *)platform;
Aalique Grahame37659862017-12-03 22:34:26 -08007821 struct audio_device *adev = my_data->adev;
Ben Rombergera04fabc2014-11-14 12:16:03 -08007822 char value[512] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007823 int ret;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007824 char *kv_pairs = NULL;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307825 char propValue[PROPERTY_VALUE_MAX]={0};
7826 bool prop_playback_enabled = false;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007827
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08007828 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
7829 value, sizeof(value));
7830 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08007831 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
7832 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08007833 }
7834
Avinash Vaishd5fa4572014-09-15 14:41:14 +05307835 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
7836 value, sizeof(value));
7837 if (ret >= 0) {
7838 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
7839 my_data->hd_voice?"true":"false");
7840 }
7841
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08007842 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
7843 value, sizeof(value));
7844 if (ret >= 0) {
7845 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
7846 strlcpy(value, "on", sizeof(value));
7847 } else {
7848 strlcpy(value, "off", sizeof(value));
7849 }
7850
7851 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
7852 }
7853
Aalique Grahame37659862017-12-03 22:34:26 -08007854 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE,
7855 value, sizeof(value));
7856
7857 if (ret >= 0) {
7858 if (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP &&
7859 adev->dp_allowed_for_voice)
7860 strlcpy(value, "true", sizeof(value));
7861 else
7862 strlcpy(value, "false", sizeof(value));
7863
7864 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_DP_FOR_VOICE_USECASE, value);
7865 }
7866
Weiyin Jiangff72f812018-04-13 15:02:33 +08007867 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK,
7868 value, sizeof(value));
7869 if (ret >= 0) {
7870 ret = platform_get_edid_info(platform);
7871 edid_audio_info *info = (edid_audio_info *)my_data->edid_info;
7872 if (ret == 0 && info != NULL) {
7873 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_DP_CHANNEL_MASK, info->channel_mask);
7874 }
7875 }
7876
Ben Rombergera04fabc2014-11-14 12:16:03 -08007877 /* Handle audio calibration keys */
7878 get_audiocal(platform, query, reply);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08007879 native_audio_get_params(query, reply, value, sizeof(value));
Ben Rombergera04fabc2014-11-14 12:16:03 -08007880
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307881 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED,
7882 value, sizeof(value));
7883 if (ret >= 0) {
7884 int isallowed = 1; /*true*/
7885
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07007886 if (property_get("vendor.voice.playback.conc.disabled", propValue, NULL)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307887 prop_playback_enabled = atoi(propValue) ||
7888 !strncmp("true", propValue, 4);
7889 }
7890
Dhanalakshmi Siddania15c6792016-08-10 15:33:53 +05307891 if ((prop_playback_enabled && (voice_is_in_call(my_data->adev))) ||
Dhananjay Kumare6293dd2017-05-25 17:25:30 +05307892 (CARD_STATUS_OFFLINE == my_data->adev->card_status)) {
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307893 char *decoder_mime_type = value;
7894
7895 //check if unsupported mime type or not
7896 if(decoder_mime_type) {
Alexy Josephb1379942016-01-29 15:49:38 -08007897 unsigned int i = 0;
Sidipotu Ashok42483b62015-09-08 10:21:44 +05307898 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
7899 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
7900 strlen(dsp_only_decoders_mime[i]))) {
7901 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
7902 isallowed = 0;
7903 break;
7904 }
7905 }
7906 }
7907 }
7908 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED, isallowed);
7909 }
7910
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08007911 kv_pairs = str_parms_to_str(reply);
7912 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
Narsinga Rao Chellacde45d12014-02-13 11:44:31 -08007913 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07007914}
7915
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307916unsigned char* platform_get_license(void *platform, int *size)
7917{
7918 struct platform_data *my_data = (struct platform_data *)platform;
7919 char value[PROPERTY_VALUE_MAX] = {0};
7920 acdb_audio_cal_cfg_t cal;
7921 unsigned char *dptr = NULL;
7922 int ret=0;
7923 uint32_t param_len;
7924
7925 if (platform == NULL) {
7926 ALOGE("[%s] received null pointer %d ",__func__, __LINE__);
7927 ret = -EINVAL;
7928 goto done;
7929 }
7930 memset(&cal, 0, sizeof(cal));
7931 cal.persist = 1;
7932 cal.cal_type = AUDIO_CORE_METAINFO_CAL_TYPE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07007933 if (!property_get("vendor.audio.qaf.acdbid", value , "") && !atoi(value)) {
7934 ALOGE("[%s] vendor.audio.qaf.acdbid is not set %d ",__func__, __LINE__);
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307935 ret = -EINVAL;
7936 goto done;
7937 }
7938 cal.acdb_dev_id = (uint32_t) atoi (value);
7939 param_len = MAX_SET_CAL_BYTE_SIZE;
Sachin Mohan Gadage64c61e2017-07-17 18:11:16 +05307940 dptr = (unsigned char*) calloc(param_len, sizeof(unsigned char));
Lakshman Chaluvaraju22ba9f12016-09-12 11:42:10 +05307941 if (dptr == NULL) {
7942 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
7943 ret = -ENOMEM;
7944 goto done;
7945 }
7946 if (my_data->acdb_get_audio_cal != NULL) {
7947 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
7948 ALOGE("%s, ret[%d], param_len[%d] line %d", __func__, ret, param_len, __LINE__);
7949 if (ret == 0) {
7950 *size = param_len;
7951 return dptr;
7952 } else {
7953 *size = 0;
7954 }
7955 }
7956done:
7957 if (dptr != NULL)
7958 free(dptr);
7959
7960 return NULL;
7961}
7962
7963/* Delay in Us */
Ashish Jain5106d362016-05-11 19:23:33 +05307964/* Delay in Us, only to be used for PCM formats */
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007965int64_t platform_render_latency(audio_usecase_t usecase)
7966{
7967 switch (usecase) {
7968 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
Derek Chenf6318be2017-06-12 17:16:24 -04007969 case USECASE_AUDIO_PLAYBACK_MEDIA:
7970 case USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007971 return DEEP_BUFFER_PLATFORM_DELAY;
7972 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
Vignesh Kulothungana6927272019-02-20 15:17:07 -08007973 case USECASE_AUDIO_PLAYBACK_WITH_HAPTICS:
Derek Chenf6318be2017-06-12 17:16:24 -04007974 case USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION:
7975 case USECASE_AUDIO_PLAYBACK_PHONE:
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007976 return LOW_LATENCY_PLATFORM_DELAY;
Ashish Jain5106d362016-05-11 19:23:33 +05307977 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
7978 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
7979 return PCM_OFFLOAD_PLATFORM_DELAY;
Haynes Mathew George5beddd42016-06-27 18:33:40 -07007980 case USECASE_AUDIO_PLAYBACK_ULL:
7981 return ULL_PLATFORM_DELAY;
Haynes Mathew George16081042017-05-31 17:16:49 -07007982 case USECASE_AUDIO_PLAYBACK_MMAP:
7983 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07007984 default:
7985 return 0;
7986 }
7987}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07007988
Mingming Yine62d7842013-10-25 16:26:03 -07007989int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07007990{
Mingming Yinab429782013-11-07 11:16:55 -08007991 ALOGV("%s: input source :%d", __func__, source);
Mingming Yin12125e82015-10-26 20:40:36 -07007992 if (source == AUDIO_SOURCE_FM_TUNER)
Mingming Yine62d7842013-10-25 16:26:03 -07007993 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
7994 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07007995}
Kiran Kandide144c82013-11-20 15:58:32 -08007996
Dhananjay Kumar45b71742014-05-29 21:47:27 +05307997bool platform_listen_device_needs_event(snd_device_t snd_device)
Kiran Kandide144c82013-11-20 15:58:32 -08007998{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05307999 bool needs_event = false;
8000
Kiran Kandide144c82013-11-20 15:58:32 -08008001 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
8002 (snd_device < SND_DEVICE_IN_END) &&
8003 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
Rohit kumarf4120402016-08-05 19:19:48 +05308004 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK) &&
8005 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1) &&
8006 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308007 needs_event = true;
8008
8009 return needs_event;
8010}
8011
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07008012bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
8013{
8014 return false;
8015}
8016
8017bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
8018{
8019 bool needs_event = false;
8020
8021 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))
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07008027 needs_event = true;
8028
8029 return needs_event;
8030}
8031
Quinn Malef15123f2017-04-27 18:58:05 -07008032bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05308033{
Quinn Malef15123f2017-04-27 18:58:05 -07008034 bool needs_event = false;
8035
8036 switch(uc_id){
8037 /* concurrent playback usecases needs event */
8038 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
8039 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
8040 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
8041 case USECASE_AUDIO_PLAYBACK_OFFLOAD2:
Quinn Malef15123f2017-04-27 18:58:05 -07008042 case USECASE_AUDIO_PLAYBACK_FM:
8043 needs_event = true;
8044 break;
Quinn Male70f20f32019-06-26 16:50:26 -07008045 case USECASE_AUDIO_PLAYBACK_ULL:
8046 case USECASE_AUDIO_PLAYBACK_MMAP:
8047 if (property_get_bool("persist.vendor.audio.ull_playback_bargein",
8048 false))
8049 needs_event = true;
8050 break;
8051 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
8052 if (property_get_bool("persist.vendor.audio.ll_playback_bargein",
8053 false))
8054 needs_event = true;
8055 break;
Quinn Malef15123f2017-04-27 18:58:05 -07008056
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308057 /* concurrent capture usecases which needs event */
8058 case USECASE_AUDIO_RECORD:
8059 case USECASE_AUDIO_RECORD_LOW_LATENCY:
8060 case USECASE_AUDIO_RECORD_COMPRESS:
8061 case USECASE_AUDIO_RECORD_MMAP:
8062 case USECASE_AUDIO_RECORD_HIFI:
8063 case USECASE_VOICE_CALL:
8064 case USECASE_VOICE2_CALL:
8065 case USECASE_VOLTE_CALL:
8066 case USECASE_QCHAT_CALL:
8067 case USECASE_VOWLAN_CALL:
8068 case USECASE_VOICEMMODE1_CALL:
8069 case USECASE_VOICEMMODE2_CALL:
8070 case USECASE_COMPRESS_VOIP_CALL:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308071 case USECASE_INCALL_REC_UPLINK:
8072 case USECASE_INCALL_REC_DOWNLINK:
8073 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
8074 case USECASE_INCALL_REC_UPLINK_COMPRESS:
8075 case USECASE_INCALL_REC_DOWNLINK_COMPRESS:
8076 case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
8077 case USECASE_INCALL_MUSIC_UPLINK:
8078 case USECASE_INCALL_MUSIC_UPLINK2:
Dhanalakshmi Siddanif133cc52018-02-08 14:34:51 +05308079 case USECASE_AUDIO_RECORD_VOIP:
8080 needs_event = true;
8081 break;
Quinn Malef15123f2017-04-27 18:58:05 -07008082 default:
8083 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
8084 }
8085 return needs_event;
Kiran Kandide144c82013-11-20 15:58:32 -08008086}
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008087
8088/* Read offload buffer size from a property.
8089 * If value is not power of 2 round it to
8090 * power of 2.
8091 */
8092uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
8093{
8094 char value[PROPERTY_VALUE_MAX] = {0};
8095 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Deeraj Soman65358ab2019-02-07 15:40:49 +05308096 uint32_t new_fragment_size = 0;
8097 int32_t duration_ms = 0;
8098 int channel_count = 0;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07008099 if((property_get("vendor.audio.offload.buffer.size.kb", value, "")) &&
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008100 atoi(value)) {
8101 fragment_size = atoi(value) * 1024;
8102 }
8103
vivek mehta80a44292015-08-10 12:58:10 -07008104 /* Use incoming offload buffer size if default buffer size is less */
8105 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
8106 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
8107 fragment_size,
8108 info->offload_buffer_size);
8109 fragment_size = info->offload_buffer_size;
8110 }
8111
Deeraj Soman65358ab2019-02-07 15:40:49 +05308112 /* Use client specified buffer size if mentioned */
Dhananjay Kumar2483ada2019-07-24 14:28:25 +05308113 if ((info != NULL) &&
8114 (info->duration_us >= MIN_OFFLOAD_BUFFER_DURATION_MS) &&
8115 (info->duration_us <= MAX_OFFLOAD_BUFFER_DURATION_MS)) {
Deeraj Soman65358ab2019-02-07 15:40:49 +05308116 duration_ms = info->duration_us / 1000;
8117 channel_count = audio_channel_count_from_in_mask(info->channel_mask);
8118
8119 new_fragment_size = (duration_ms * info->sample_rate * channel_count * audio_bytes_per_sample(info->format)) / 1000;
8120 ALOGI("%s:: Overwriting offload buffer size with client requested size old:%d new:%d", __func__, fragment_size, new_fragment_size);
8121
8122 fragment_size = new_fragment_size;
8123 }
8124
Ramjee Singh21ffaa82017-07-28 17:47:01 +05308125 if (info != NULL) {
8126 if (info->is_streaming && info->has_video) {
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05308127 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
8128 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
8129 __func__, fragment_size);
8130 } else if (info->format == AUDIO_FORMAT_FLAC) {
8131 fragment_size = FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8132 ALOGV("FLAC fragment size %d", fragment_size);
8133 } else if (info->format == AUDIO_FORMAT_DSD) {
8134 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07008135 if((property_get("vendor.audio.native.dsd.buffer.size.kb", value, "")) &&
Preetam Singh Ranawatf5fbdd62016-09-29 18:38:31 +05308136 atoi(value))
8137 fragment_size = atoi(value) * 1024;
8138 ALOGV("DSD fragment size %d", fragment_size);
8139 }
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08008140 }
8141
8142 fragment_size = ALIGN( fragment_size, 1024);
8143
8144 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
8145 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8146 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
8147 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
8148 ALOGV("%s: fragment_size %d", __func__, fragment_size);
8149 return fragment_size;
8150}
8151
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308152/*
Ashish Jainb26edfb2016-08-25 00:10:11 +05308153 * return backend_idx on which voice call is active
8154 */
8155static int platform_get_voice_call_backend(struct audio_device* adev)
8156{
8157 struct audio_usecase *uc = NULL;
8158 struct listnode *node;
8159 snd_device_t out_snd_device = SND_DEVICE_NONE;
8160
8161 int backend_idx = -1;
8162
8163 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
8164 list_for_each(node, &adev->usecase_list) {
8165 uc = node_to_item(node, struct audio_usecase, list);
kunleiz83c0b4f2019-02-28 16:53:25 +08008166 if (uc && uc->stream.out &&
8167 (uc->type == VOICE_CALL ||
8168 uc->type == VOIP_CALL ||
8169 uc->id == USECASE_AUDIO_PLAYBACK_VOIP)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05308170 out_snd_device = platform_get_output_snd_device(adev->platform, uc->stream.out);
8171 backend_idx = platform_get_backend_index(out_snd_device);
8172 break;
8173 }
8174 }
8175 }
8176 return backend_idx;
8177}
8178
8179/*
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308180 * configures afe with bit width and Sample Rate
8181 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308182static int platform_set_codec_backend_cfg(struct audio_device* adev,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308183 snd_device_t snd_device, struct audio_backend_cfg backend_cfg)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008184{
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308185 int ret = -EINVAL;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008186 int backend_idx = platform_get_backend_index(snd_device);
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008187 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308188 unsigned int bit_width = backend_cfg.bit_width;
8189 unsigned int sample_rate = backend_cfg.sample_rate;
8190 unsigned int channels = backend_cfg.channels;
8191 audio_format_t format = backend_cfg.format;
8192 bool passthrough_enabled = backend_cfg.passthrough_enabled;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308193 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
8194
8195 /* Override the config params if client has already set them */
8196 adev_device_cfg_ptr += backend_idx;
8197 if (adev_device_cfg_ptr->use_client_dev_cfg) {
8198 ALOGV("%s::: Updating with the config set by client "
8199 "bitwidth %d, samplerate %d, channels %d format %d",
8200 __func__, adev_device_cfg_ptr->dev_cfg_params.bit_width,
8201 adev_device_cfg_ptr->dev_cfg_params.sample_rate,
8202 adev_device_cfg_ptr->dev_cfg_params.channels,
8203 adev_device_cfg_ptr->dev_cfg_params.format);
8204
8205 bit_width = adev_device_cfg_ptr->dev_cfg_params.bit_width;
8206 sample_rate = adev_device_cfg_ptr->dev_cfg_params.sample_rate;
8207 channels = adev_device_cfg_ptr->dev_cfg_params.channels;
8208 format = adev_device_cfg_ptr->dev_cfg_params.format;
8209 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308210
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308211 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
Kuirong Wang0b947f72016-09-29 11:03:09 -07008212 ", backend_idx %d device (%s)", __func__, bit_width,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308213 sample_rate, channels, format, backend_idx,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308214 platform_get_snd_device_name(snd_device));
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008215
Dhanalakshmi Siddanib678a802016-12-03 11:51:41 +05308216 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
8217 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008218
Kuirong Wang0b947f72016-09-29 11:03:09 -07008219 struct mixer_ctl *ctl = NULL;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008220 ctl = mixer_get_ctl_by_name(adev->mixer,
8221 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008222 if (!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308223 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8224 __func__,
8225 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008226 return -EINVAL;
8227 }
8228
8229 if (bit_width == 24) {
Ashish Jain5106d362016-05-11 19:23:33 +05308230 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
Kuirong Wang0b947f72016-09-29 11:03:09 -07008231 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
Ashish Jain5106d362016-05-11 19:23:33 +05308232 else
Kuirong Wang0b947f72016-09-29 11:03:09 -07008233 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008234 } else if (bit_width == 32) {
Ashish Jain058165c2016-09-28 23:18:48 +05308235 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07008236 } else {
Kuirong Wang0b947f72016-09-29 11:03:09 -07008237 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07008238 }
Kuirong Wang0b947f72016-09-29 11:03:09 -07008239 if ( ret < 0) {
8240 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
8241 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
8242 } else {
8243 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
8244 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
8245 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
8246 }
8247 /* set the ret as 0 and not pass back to upper layer */
8248 ret = 0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008249 }
8250
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308251 if ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
8252 (passthrough_enabled || (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07008253 char *rate_str = NULL;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008254 struct mixer_ctl *ctl = NULL;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008255
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308256 if (backend_idx == USB_AUDIO_RX_BACKEND ||
8257 backend_idx == USB_AUDIO_TX_BACKEND) {
8258 switch (sample_rate) {
8259 case 32000:
8260 rate_str = "KHZ_32";
8261 break;
8262 case 8000:
8263 rate_str = "KHZ_8";
8264 break;
8265 case 11025:
Sharad Sangle4cd17e32018-07-16 14:37:42 +05308266 rate_str = "KHZ_11P025";
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308267 break;
8268 case 16000:
8269 rate_str = "KHZ_16";
8270 break;
8271 case 22050:
8272 rate_str = "KHZ_22P05";
8273 break;
8274 }
8275 }
8276
8277 if (rate_str == NULL) {
8278 switch (sample_rate) {
8279 case 32000:
Weiyin Jiang03b2cb22019-09-04 16:45:45 +08008280 if (passthrough_enabled || (backend_idx == SPDIF_TX_BACKEND) ||
8281 (backend_idx == HDMI_TX_BACKEND) ||
8282 (backend_idx == HDMI_ARC_TX_BACKEND) ||
8283 (backend_idx == DISP_PORT_RX_BACKEND)) {
Preetam Singh Ranawat63c02ea2017-08-10 11:53:30 +05308284 rate_str = "KHZ_32";
8285 break;
8286 }
8287 case 48000:
8288 rate_str = "KHZ_48";
8289 break;
8290 case 44100:
8291 rate_str = "KHZ_44P1";
8292 break;
8293 case 64000:
8294 case 96000:
8295 rate_str = "KHZ_96";
8296 break;
8297 case 88200:
8298 rate_str = "KHZ_88P2";
8299 break;
8300 case 176400:
8301 rate_str = "KHZ_176P4";
8302 break;
8303 case 192000:
8304 rate_str = "KHZ_192";
8305 break;
8306 case 352800:
8307 rate_str = "KHZ_352P8";
8308 break;
8309 case 384000:
8310 rate_str = "KHZ_384";
8311 break;
8312 case 144000:
8313 if (passthrough_enabled) {
8314 rate_str = "KHZ_144";
8315 break;
8316 }
8317 default:
8318 rate_str = "KHZ_48";
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05308319 break;
8320 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008321 }
8322
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008323 ctl = mixer_get_ctl_by_name(adev->mixer,
8324 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008325 if(!ctl) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308326 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8327 __func__,
8328 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008329 return -EINVAL;
8330 }
8331
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308332 ALOGD("%s:becf: afe: %s set to %s", __func__,
8333 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008334 mixer_ctl_set_enum_by_string(ctl, rate_str);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008335 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308336 ret = 0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008337 }
Ashish Jainb26edfb2016-08-25 00:10:11 +05308338 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308339 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
Kuirong Wang0b947f72016-09-29 11:03:09 -07008340 struct mixer_ctl *ctl = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308341 char *channel_cnt_str = NULL;
8342
8343 switch (channels) {
8344 case 8:
8345 channel_cnt_str = "Eight"; break;
8346 case 7:
8347 channel_cnt_str = "Seven"; break;
8348 case 6:
8349 channel_cnt_str = "Six"; break;
8350 case 5:
8351 channel_cnt_str = "Five"; break;
8352 case 4:
8353 channel_cnt_str = "Four"; break;
8354 case 3:
8355 channel_cnt_str = "Three"; break;
Kuirong Wang0b947f72016-09-29 11:03:09 -07008356 case 1:
8357 channel_cnt_str = "One"; break;
8358 case 2:
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308359 default:
8360 channel_cnt_str = "Two"; break;
8361 }
8362
8363 ctl = mixer_get_ctl_by_name(adev->mixer,
8364 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
8365 if (!ctl) {
8366 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8367 __func__,
8368 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
8369 return -EINVAL;
8370 }
8371 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
8372 my_data->current_backend_cfg[backend_idx].channels = channels;
Ashish Jainb26edfb2016-08-25 00:10:11 +05308373
Weiyin Jiangff72f812018-04-13 15:02:33 +08008374 if ((backend_idx == HDMI_RX_BACKEND) ||
8375 (backend_idx == DISP_PORT_RX_BACKEND))
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308376 platform_set_edid_channels_configuration(adev->platform, channels, backend_idx, snd_device);
Ashish Jainb26edfb2016-08-25 00:10:11 +05308377
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308378 ALOGD("%s:becf: afe: %s set to %s ", __func__,
Kuirong Wang0b947f72016-09-29 11:03:09 -07008379 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
8380 channel_cnt_str);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308381 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308382 }
8383
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308384 bool set_ext_disp_format = false, set_mi2s_tx_data_format = false;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008385 char *ext_disp_format = NULL;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308386
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008387 if (backend_idx == HDMI_RX_BACKEND) {
8388 ext_disp_format = "HDMI RX Format";
8389 set_ext_disp_format = true;
8390 } else if (backend_idx == DISP_PORT_RX_BACKEND) {
Garmond Leungade0f6d2017-02-03 15:56:10 -08008391 ext_disp_format = "Display Port RX Format";
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008392 set_ext_disp_format = true;
Ralf Herzafb164f2018-07-03 07:08:07 +02008393 } else if (backend_idx == SPDIF_TX_BACKEND) {
8394 ext_disp_format = "PRI SPDIF TX Format";
8395 set_mi2s_tx_data_format = true;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308396 } else if (backend_idx == HDMI_TX_BACKEND) {
Ralf Herzafb164f2018-07-03 07:08:07 +02008397 if (!strncmp(platform_get_snd_device_backend_interface(snd_device),
8398 "SEC_MI2S_TX", sizeof("SEC_MI2S_TX")))
8399 ext_disp_format = "SEC MI2S TX Format";
8400 else
8401 ext_disp_format = "QUAT MI2S TX Format";
8402 set_mi2s_tx_data_format = true;
8403 } else if (backend_idx == HDMI_ARC_TX_BACKEND) {
8404 ext_disp_format = "SEC SPDIF TX Format";
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308405 set_mi2s_tx_data_format = true;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008406 } else {
8407 ALOGV("%s: Format doesnt have to be set", __func__);
8408 }
8409
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308410 /* Set data format only if there is a change from PCM to compressed
8411 and vice versa */
8412 if (set_mi2s_tx_data_format && (format ^ my_data->current_backend_cfg[backend_idx].format)) {
8413 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
8414 if (!ctl) {
8415 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
8416 __func__, ext_disp_format);
8417 return -EINVAL;
8418 }
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07008419 if ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) {
Ralf Herzafb164f2018-07-03 07:08:07 +02008420 ALOGE("%s:Set %s to LPCM", __func__, ext_disp_format);
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308421 mixer_ctl_set_enum_by_string(ctl, "LPCM");
8422 } else {
Ralf Herzafb164f2018-07-03 07:08:07 +02008423 ALOGE("%s:Set %s to Compr", __func__, ext_disp_format);
Siddartha Shaik44dd7702017-06-14 12:13:25 +05308424 mixer_ctl_set_enum_by_string(ctl, "Compr");
8425 }
8426 my_data->current_backend_cfg[backend_idx].format = format;
8427 }
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008428 if (set_ext_disp_format) {
8429 struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308430 if (!ctl) {
8431 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008432 __func__, ext_disp_format);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308433 return -EINVAL;
8434 }
8435
8436 if (passthrough_enabled) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008437 ALOGD("%s:Ext display compress format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308438 mixer_ctl_set_enum_by_string(ctl, "Compr");
8439 } else {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008440 ALOGD("%s: Ext display PCM format", __func__);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308441 mixer_ctl_set_enum_by_string(ctl, "LPCM");
8442 }
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308443 ret = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308444 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008445 return ret;
8446}
8447
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308448/*
Satish Babu Patakokila5933e972017-08-24 12:22:08 +05308449 * Get the backend configuration for current snd device
8450 */
8451int platform_get_codec_backend_cfg(struct audio_device* adev,
8452 snd_device_t snd_device,
8453 struct audio_backend_cfg *backend_cfg)
8454{
8455 int backend_idx = platform_get_backend_index(snd_device);
8456 struct platform_data *my_data = (struct platform_data *)adev->platform;
8457
8458 backend_cfg->bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
8459 backend_cfg->sample_rate =
8460 my_data->current_backend_cfg[backend_idx].sample_rate;
8461 backend_cfg->channels =
8462 my_data->current_backend_cfg[backend_idx].channels;
8463 backend_cfg->format =
8464 my_data->current_backend_cfg[backend_idx].format;
8465
8466 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
8467 ", backend_idx %d device (%s)", __func__, backend_cfg->bit_width,
8468 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format,
8469 backend_idx, platform_get_snd_device_name(snd_device));
8470
8471 return 0;
8472}
8473
8474/*
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308475 *Validate the selected bit_width, sample_rate and channels using the edid
8476 *of the connected sink device.
8477 */
8478static void platform_check_hdmi_backend_cfg(struct audio_device* adev,
8479 struct audio_usecase* usecase,
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008480 int backend_idx,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308481 struct audio_backend_cfg *hdmi_backend_cfg)
8482{
8483 unsigned int bit_width;
8484 unsigned int sample_rate;
Manish Dewangan37864bc2017-06-09 12:28:37 +05308485 int channels, max_supported_channels = 0;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308486 struct platform_data *my_data = (struct platform_data *)adev->platform;
8487 edid_audio_info *edid_info = (edid_audio_info *)my_data->edid_info;
8488 bool passthrough_enabled = false;
8489
8490 bit_width = hdmi_backend_cfg->bit_width;
8491 sample_rate = hdmi_backend_cfg->sample_rate;
8492 channels = hdmi_backend_cfg->channels;
8493
8494
8495 ALOGI("%s:becf: HDMI: bitwidth %d, samplerate %d, channels %d"
8496 ", usecase = %d", __func__, bit_width,
8497 sample_rate, channels, usecase->id);
8498
8499 if (audio_extn_passthru_is_enabled() && audio_extn_passthru_is_active()
8500 && (usecase->stream.out->compr_config.codec->compr_passthr != 0)) {
8501 passthrough_enabled = true;
8502 ALOGI("passthrough is enabled for this stream");
8503 }
8504
8505 // For voice calls use default configuration i.e. 16b/48K, only applicable to
8506 // default backend
8507 if (!passthrough_enabled) {
8508
8509 max_supported_channels = platform_edid_get_max_channels(my_data);
8510
8511 //Check EDID info for supported samplerate
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008512 if (!audio_extn_edid_is_supported_sr(edid_info,sample_rate)) {
Garmond Leung2f78a672016-11-07 16:27:40 -08008513 //check to see if current BE sample rate is supported by EDID
8514 //else assign the highest sample rate supported by EDID
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008515 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 -08008516 sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
8517 else
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008518 sample_rate = audio_extn_edid_get_highest_supported_sr(edid_info);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308519 }
8520
8521 //Check EDID info for supported bit width
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08008522 if (!audio_extn_edid_is_supported_bps(edid_info,bit_width)) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308523 //reset to current sample rate
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008524 bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308525 }
8526
8527 if (channels > max_supported_channels)
8528 channels = max_supported_channels;
8529
8530 } else {
Manish Dewangan37864bc2017-06-09 12:28:37 +05308531 channels = audio_extn_passthru_get_channel_count(usecase->stream.out);
8532 if (channels <= 0) {
8533 ALOGE("%s: becf: afe: HDMI backend using defalut channel %u",
8534 __func__, DEFAULT_HDMI_OUT_CHANNELS);
Ben Romberger1aaaf862017-04-06 17:49:46 -07008535 channels = DEFAULT_HDMI_OUT_CHANNELS;
Manish Dewangan37864bc2017-06-09 12:28:37 +05308536 }
Harsh Bansal026d97f2017-08-17 17:44:49 +05308537 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
Ben Romberger1aaaf862017-04-06 17:49:46 -07008538 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) ||
Harsh Bansal026d97f2017-08-17 17:44:49 +05308539 (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD))
8540 && (usecase->stream.out->compr_config.codec->compr_passthr == PASSTHROUGH)) {
Naresh Tanniru3a406772017-05-10 13:09:05 -07008541 sample_rate = sample_rate * 4;
8542 if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE)
8543 sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE;
8544 }
Ben Romberger1aaaf862017-04-06 17:49:46 -07008545
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308546 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8547 /* We force route so that the BE format can be set to Compr */
8548 }
8549
8550 ALOGI("%s:becf: afe: HDMI backend: passthrough %d updated bit width: %d and sample rate: %d"
8551 "channels %d", __func__, passthrough_enabled , bit_width,
8552 sample_rate, channels);
8553
8554 hdmi_backend_cfg->bit_width = bit_width;
8555 hdmi_backend_cfg->sample_rate = sample_rate;
8556 hdmi_backend_cfg->channels = channels;
8557 hdmi_backend_cfg->passthrough_enabled = passthrough_enabled;
8558}
8559
8560/*
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308561 * goes through all the current usecases and picks the highest
8562 * bitwidth & samplerate
8563 */
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308564static bool platform_check_codec_backend_cfg(struct audio_device* adev,
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008565 struct audio_usecase* usecase,
8566 snd_device_t snd_device,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308567 struct audio_backend_cfg *backend_cfg)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008568{
8569 bool backend_change = false;
8570 struct listnode *node;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008571 unsigned int bit_width;
8572 unsigned int sample_rate;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308573 unsigned int channels;
Garmond Leung5fd0b552018-04-17 11:56:12 -07008574 unsigned long service_interval = 0;
8575 bool service_interval_update = false;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308576 bool passthrough_enabled = false;
Ashish Jain8c930292017-03-13 16:33:12 +05308577 bool voice_call_active = false;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008578 int backend_idx = DEFAULT_CODEC_BACKEND;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008579 struct platform_data *my_data = (struct platform_data *)adev->platform;
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308580 int na_mode = platform_get_native_support();
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308581 bool channels_updated = false;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308582 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008583
Ashish Jainc597d102016-12-12 10:31:34 +05308584 /*BT devices backend is not configured from HAL hence skip*/
8585 if (snd_device == SND_DEVICE_OUT_BT_A2DP ||
8586 snd_device == SND_DEVICE_OUT_BT_SCO ||
Sachin Mohan Gadag2e4dcb12017-05-12 13:05:08 +05308587 snd_device == SND_DEVICE_OUT_BT_SCO_WB ||
Zhou Song12c29502019-03-16 10:37:18 +08008588 snd_device == SND_DEVICE_OUT_BT_SCO_SWB ||
Florian Pfister1a84f312018-07-19 14:38:18 +02008589 snd_device == SND_DEVICE_IN_BT_A2DP ||
Sachin Mohan Gadag2e4dcb12017-05-12 13:05:08 +05308590 snd_device == SND_DEVICE_OUT_AFE_PROXY) {
Ashish Jainc597d102016-12-12 10:31:34 +05308591 backend_change = false;
8592 return backend_change;
8593 }
8594
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008595 backend_idx = platform_get_backend_index(snd_device);
8596
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308597 bit_width = backend_cfg->bit_width;
8598 sample_rate = backend_cfg->sample_rate;
8599 channels = backend_cfg->channels;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008600
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308601 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308602 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308603 sample_rate, channels, backend_idx, usecase->id,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308604 platform_get_snd_device_name(snd_device));
Mingming Yin3ee55c62014-08-04 14:23:35 -07008605
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -07008606 // For voice calls use default configuration i.e. 16b/48K, only applicable to
8607 // default backend
Mingming Yin3ee55c62014-08-04 14:23:35 -07008608 // force routing is not required here, caller will do it anyway
Ashish Jainb26edfb2016-08-25 00:10:11 +05308609 if (backend_idx == platform_get_voice_call_backend(adev)) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308610 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
8611 __func__);
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008612 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8613 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jainb26edfb2016-08-25 00:10:11 +05308614 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
Ashish Jain8c930292017-03-13 16:33:12 +05308615 voice_call_active = true;
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008616 } else {
8617 /*
8618 * The backend should be configured at highest bit width and/or
8619 * sample rate amongst all playback usecases.
8620 * If the selected sample rate and/or bit width differ with
8621 * current backend sample rate and/or bit width, then, we set the
8622 * backend re-configuration flag.
8623 *
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308624 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07008625 */
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308626 int i =0;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008627 list_for_each(node, &adev->usecase_list) {
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308628 struct audio_usecase *uc;
8629 uc = node_to_item(node, struct audio_usecase, list);
8630 struct stream_out *out = (struct stream_out*) uc->stream.out;
8631 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
Preetam Singh Ranawataa37d3f2016-08-23 12:25:23 +05308632 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008633
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308634 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308635 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308636 uc->id, out->sample_rate,
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308637 out->bit_width, out_channels,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308638 platform_get_snd_device_name(uc->out_snd_device));
8639
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308640 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
Amit Shekhar278e3362014-09-08 14:08:19 -07008641 if (bit_width < out->bit_width)
8642 bit_width = out->bit_width;
8643 if (sample_rate < out->sample_rate)
8644 sample_rate = out->sample_rate;
Revathi Uddaraju869ae492018-02-09 16:27:35 +05308645 /*
8646 * TODO: Add Support for Backend configuration for devices which support
8647 * sample rate less than 44.1
8648 */
8649 if (sample_rate < OUTPUT_SAMPLING_RATE_44100)
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008650 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308651 if (channels < out_channels)
8652 channels = out_channels;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008653 }
Ramlal Karra10d22b92019-08-08 19:02:35 +05308654 if ((snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) &&
8655 (usecase->id==USECASE_AUDIO_PLAYBACK_LOW_LATENCY ||
8656 usecase->id == USECASE_AUDIO_PLAYBACK_ULL)) {
8657 sample_rate = my_data->current_backend_cfg[backend_idx].sample_rate;
8658 bit_width = my_data->current_backend_cfg[backend_idx].bit_width;
8659 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008660 }
8661 }
8662 }
8663
Ashish Jainb26edfb2016-08-25 00:10:11 +05308664 /* Native playback is preferred for Headphone/HS device over 192Khz */
Ashish Jain8c930292017-03-13 16:33:12 +05308665 if (!voice_call_active && codec_device_supports_native_playback(usecase->devices)) {
Ashish Jainb26edfb2016-08-25 00:10:11 +05308666 if (audio_is_true_native_stream_active(adev)) {
8667 if (check_hdset_combo_device(snd_device)) {
8668 /*
8669 * In true native mode Tasha has a limitation that one port at 44.1 khz
8670 * cannot drive both spkr and hdset, to simiplify the solution lets
8671 * move the AFE to 48khzwhen a ring tone selects combo device.
8672 * or if NATIVE playback is not enabled.
8673 */
8674 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8675 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ashish Jain8c930292017-03-13 16:33:12 +05308676 ALOGD("%s:becf: afe: port to run at 48k if combo device or in voice call"
8677 , __func__);
Ashish Jainb26edfb2016-08-25 00:10:11 +05308678 } else {
8679 /*
8680 * in single BE mode, if native audio playback
8681 * is active then it will take priority
8682 */
8683 sample_rate = OUTPUT_SAMPLING_RATE_44100;
8684 ALOGD("%s:becf: afe: true napb active set rate to 44.1 khz",
8685 __func__);
8686 }
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05308687 } else if (na_mode == NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP) {
8688 struct listnode *node;
8689 list_for_each(node, &adev->usecase_list) {
8690 struct audio_usecase *uc;
8691 uc = node_to_item(node, struct audio_usecase, list);
8692 struct stream_out *curr_out =
8693 (struct stream_out*) uc->stream.out;
8694
8695 /*if native audio playback
8696 * is active then it will take priority
8697 */
8698 if (curr_out && PCM_PLAYBACK == uc->type) {
8699 if (is_offload_usecase(uc->id) &&
8700 (curr_out->sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0)) {
8701 ALOGD("%s:napb:native stream detected %d sampling rate", __func__, curr_out->sample_rate);
8702 sample_rate = curr_out->sample_rate;
8703 }
8704 }
Preetam Singh Ranawat9d0d8e42019-07-15 12:27:25 +05308705
8706 /* WCD9380 support SR upto 192Khz only, hence reset
8707 * SR > 192Khz to 192Khz.
8708 */
8709 if (strstr(my_data->codec_variant, "WCD9380")) {
8710 switch (sample_rate) {
8711 case 352800:
8712 case 384000:
8713 sample_rate = 192000;
8714 ALOGD("%s:Reset Sampling rate to %d", __func__, sample_rate);
8715 break;
8716 default:
8717 break;
8718 }
8719 }
Preetam Singh Ranawatb1c73232019-04-22 13:59:51 +05308720 }
8721 } else if (na_mode != NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_CODEC) {
Ashish Jain7f25be32016-10-25 21:44:16 +05308722 /*
8723 * Map native sampling rates to upper limit range
8724 * if multiple of native sampling rates are not supported.
8725 * This check also indicates that this is not tavil codec
8726 * And 32bit/384kHz is only supported on tavil
8727 * Hence reset 32b/384kHz to 24b/192kHz.
8728 */
8729 switch (sample_rate) {
8730 case 44100:
8731 sample_rate = 48000;
8732 break;
8733 case 88200:
8734 sample_rate = 96000;
8735 break;
8736 case 176400:
8737 case 352800:
8738 case 384000:
8739 sample_rate = 192000;
8740 break;
8741 }
8742 if (bit_width > 24)
8743 bit_width = 24;
8744
8745 ALOGD("%s:becf: afe: napb not active - set non fractional rate",
Ashish Jainb26edfb2016-08-25 00:10:11 +05308746 __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008747 }
Mingshu Pange3d362f2019-12-13 18:00:00 +08008748 /*
8749 * reset sample rate to 48khz if sample rate less than 44.1khz, or device backend does not
8750 * support 44.1 khz and the multiple of 44.1khz
8751 */
8752 if ((sample_rate % OUTPUT_SAMPLING_RATE_44100 == 0 &&
kunleiz72e744c2018-09-27 18:09:16 +08008753 backend_idx != HEADPHONE_44_1_BACKEND &&
8754 backend_idx != HEADPHONE_BACKEND &&
8755 backend_idx != USB_AUDIO_RX_BACKEND) ||
8756 sample_rate < OUTPUT_SAMPLING_RATE_44100) {
8757 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8758 ALOGD("%s:becf: afe: set sample rate to default Sample Rate(48k)",__func__);
kunleiz6ba62d12018-06-20 13:55:46 +08008759 }
Ashish Jain6fced6e2017-01-09 14:13:22 +05308760 }
8761
Ramlal Karra10d22b92019-08-08 19:02:35 +05308762 if (backend_idx != platform_get_voice_call_backend(adev)
8763 && usecase->type == PCM_PLAYBACK) {
8764 struct stream_out *out = (struct stream_out*) usecase->stream.out;
8765 if(audio_extn_is_hifi_filter_enabled(adev, out, snd_device,
8766 my_data->codec_variant, channels, 0)) {
8767 switch (sample_rate) {
8768 case 48000:
8769 audio_extn_enable_hifi_filter(adev, true);
8770 if (audio_is_true_native_stream_active(adev))
8771 sample_rate = 352800;
8772 else
8773 sample_rate = 384000;
8774 bit_width = 32;
8775 break;
8776 case 44100:
8777 audio_extn_enable_hifi_filter(adev, true);
8778 sample_rate = 352800;
8779 bit_width = 32;
8780 break;
8781 default:
8782 audio_extn_enable_hifi_filter(adev, false);
8783 }
8784 }
8785 if (snd_device != SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER)
8786 audio_extn_enable_hifi_filter(adev, false);
8787 ALOGD("%s:becf: updated afe: bitwidth %d, samplerate %d channels %d,"
8788 "backend_idx %d usecase = %d device (%s)", __func__, bit_width,
8789 sample_rate, channels, backend_idx, usecase->id,
8790 platform_get_snd_device_name(snd_device));
8791 }
8792
Ashish Jain6fced6e2017-01-09 14:13:22 +05308793 /*
kunleiz0a99fcf2018-06-14 16:41:21 +08008794 * Handset and speaker may have diffrent backend. Check if the device is speaker or handset,
8795 * and these devices are restricited to 48kHz.
Ashish Jain6fced6e2017-01-09 14:13:22 +05308796 */
kunleiz5c3fb9a2019-02-20 17:18:19 +08008797 if (!codec_device_supports_native_playback(usecase->devices) &&
8798 (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device) ||
8799 platform_check_backends_match(SND_DEVICE_OUT_HANDSET, snd_device))) {
Ramu Gottipati074fa4d2018-09-11 20:05:51 +05308800 int bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
8801 if ((-ENOSYS != bw) && (bit_width > (uint32_t)bw)) {
8802 bit_width = (uint32_t)bw;
Ashish Jain058165c2016-09-28 23:18:48 +05308803 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
Ramu Gottipati074fa4d2018-09-11 20:05:51 +05308804 " value for this platform)", __func__, bit_width);
8805 } else if (-ENOSYS == bw) {
8806 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
8807 ALOGD("%s:becf: afe: reset to default bitwidth %d", __func__, bit_width);
Ashish Jain058165c2016-09-28 23:18:48 +05308808 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02008809 /*
8810 * In case of CSRA speaker out, all sample rates are supported, so
8811 * check platform here
8812 */
8813 if (platform_spkr_use_default_sample_rate(adev->platform)) {
8814 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
8815 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308816 "default Sample Rate(48k)", __func__);
Dieter Luecking5d57def2018-09-07 14:23:37 +02008817 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308818 }
8819
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008820 if (backend_idx == USB_AUDIO_RX_BACKEND) {
Kuirong Wange9894162016-08-26 15:16:39 -07008821 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008822 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
8823 __func__, bit_width, sample_rate, channels);
Garmond Leung5fd0b552018-04-17 11:56:12 -07008824
8825 if (audio_extn_usb_get_service_interval(true,
8826 &service_interval) == 0) {
8827 /* overwrite with best altset for this service interval */
8828 int ret =
8829 audio_extn_usb_altset_for_service_interval(true /*playback*/,
8830 service_interval,
8831 &bit_width,
8832 &sample_rate,
8833 &channels);
8834 ALOGD("%s: Override USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)SI(%lu)",
8835 __func__, bit_width, sample_rate, channels, service_interval);
8836 if (ret < 0) {
8837 ALOGW("Failed to find altset for service interval %lu, skip reconfig",
8838 service_interval);
8839 return false;
8840 }
8841 service_interval_update = audio_extn_usb_is_reconfig_req();
8842 audio_extn_usb_set_reconfig(false);
8843 }
8844
Ashish Jainb26edfb2016-08-25 00:10:11 +05308845 if (channels != my_data->current_backend_cfg[backend_idx].channels)
8846 channels_updated = true;
Kuirong Wanga9f7cee2016-03-07 11:21:52 -08008847 }
8848
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008849 if (backend_idx == HDMI_RX_BACKEND || backend_idx == DISP_PORT_RX_BACKEND) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308850 struct audio_backend_cfg hdmi_backend_cfg;
8851 hdmi_backend_cfg.bit_width = bit_width;
8852 hdmi_backend_cfg.sample_rate = sample_rate;
8853 hdmi_backend_cfg.channels = channels;
8854 hdmi_backend_cfg.passthrough_enabled = false;
8855
Ashish Jain058165c2016-09-28 23:18:48 +05308856 /*
8857 * HDMI does not support 384Khz/32bit playback hence configure BE to 24b/192Khz
8858 * TODO: Instead have the validation against edid return the next best match
8859 */
8860 if (bit_width > 24)
8861 hdmi_backend_cfg.bit_width = 24;
8862 if (sample_rate > 192000)
8863 hdmi_backend_cfg.sample_rate = 192000;
8864
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07008865 platform_check_hdmi_backend_cfg(adev, usecase, backend_idx, &hdmi_backend_cfg);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308866
8867 bit_width = hdmi_backend_cfg.bit_width;
8868 sample_rate = hdmi_backend_cfg.sample_rate;
8869 channels = hdmi_backend_cfg.channels;
8870 passthrough_enabled = hdmi_backend_cfg.passthrough_enabled;
8871
8872 if (channels != my_data->current_backend_cfg[backend_idx].channels)
8873 channels_updated = true;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308874
8875 platform_set_edid_channels_configuration(adev->platform, channels, backend_idx, snd_device);
Mingming Yinddd610b2016-01-20 17:09:32 -08008876 }
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308877
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308878 ALOGI("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
8879 __func__, backend_idx , bit_width, sample_rate);
Mingming Yinddd610b2016-01-20 17:09:32 -08008880
Mingming Yin3ee55c62014-08-04 14:23:35 -07008881 // Force routing if the expected bitwdith or samplerate
8882 // is not same as current backend comfiguration
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008883 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308884 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
Garmond Leung5fd0b552018-04-17 11:56:12 -07008885 passthrough_enabled || channels_updated || service_interval_update ) {
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308886 backend_cfg->bit_width = bit_width;
8887 backend_cfg->sample_rate = sample_rate;
8888 backend_cfg->channels = channels;
8889 backend_cfg->passthrough_enabled = passthrough_enabled;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008890 backend_change = true;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308891 ALOGI("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
8892 "new sample rate: %d new channels: %d",
8893 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
Mingming Yin3ee55c62014-08-04 14:23:35 -07008894 }
8895
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308896 // Force routing if the client sends config params for this backend
8897 adev_device_cfg_ptr += backend_idx;
8898 if (adev_device_cfg_ptr->use_client_dev_cfg) {
8899 ALOGV("%s: Codec backend needs to be updated as Client provided "
8900 "config params", __func__);
8901 backend_change = true;
8902 }
8903
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308904 if (snd_device == SND_DEVICE_OUT_HEADPHONES || snd_device ==
Ramlal Karra10d22b92019-08-08 19:02:35 +05308905 SND_DEVICE_OUT_HEADPHONES_44_1 || snd_device == SND_DEVICE_OUT_HEADPHONES_HIFI_FILTER) {
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05308906 if (my_data->is_cls_ab_only_supported) {
8907 ALOGI("%s: apply CLS AB HPH power mode\n", __func__);
8908 audio_route_apply_and_update_path(adev->audio_route, "hph-class-ab-mode");
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308909 } else {
Aditya Bavanarif2be3c92019-10-11 19:46:43 +05308910 if (sample_rate > 48000 ||
8911 (bit_width >= 24 && (sample_rate == 48000 || sample_rate == 44100))) {
8912 ALOGI("%s: apply HPH HQ mode\n", __func__);
8913 audio_route_apply_and_update_path(adev->audio_route, "hph-highquality-mode");
8914 } else {
8915 ALOGI("%s: apply HPH LP mode\n", __func__);
8916 audio_route_apply_and_update_path(adev->audio_route, "hph-lowpower-mode");
8917 }
Preetam Singh Ranawatdc1a3952016-11-24 17:35:51 +05308918 }
8919 }
8920
Mingming Yin3ee55c62014-08-04 14:23:35 -07008921 return backend_change;
8922}
8923
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008924bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
8925 struct audio_usecase *usecase, snd_device_t snd_device)
Mingming Yin3ee55c62014-08-04 14:23:35 -07008926{
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008927 int backend_idx = DEFAULT_CODEC_BACKEND;
Siena Richard7c2db772016-12-21 11:32:34 -08008928 int new_snd_devices[SND_DEVICE_OUT_END] = {0};
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308929 int i, num_devices = 1;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308930 int device_be_idx = -1;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308931 bool ret = false;
8932 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308933 struct audio_backend_cfg backend_cfg;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008934
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08008935 backend_idx = platform_get_backend_index(snd_device);
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308936 device_be_idx = platform_get_snd_device_backend_index(snd_device);
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -08008937
Surendar Karka93cd25a2018-08-28 14:21:37 +05308938 if (usecase->type == TRANSCODE_LOOPBACK_RX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308939 backend_cfg.bit_width = usecase->stream.inout->out_config.bit_width;
8940 backend_cfg.sample_rate = usecase->stream.inout->out_config.sample_rate;
8941 backend_cfg.format = usecase->stream.inout->out_config.format;
8942 backend_cfg.channels = audio_channel_count_from_out_mask(
8943 usecase->stream.inout->out_config.channel_mask);
8944 } else {
8945 backend_cfg.bit_width = usecase->stream.out->bit_width;
8946 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
8947 backend_cfg.format = usecase->stream.out->format;
Xiaojun Sang841cb5f2018-11-06 19:37:44 +08008948 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308949 }
Xiaojun Sang785b5da2017-08-03 15:52:29 +08008950 if (audio_extn_is_dsp_bit_width_enforce_mode_supported(usecase->stream.out->flags) &&
8951 (adev->dsp_bit_width_enforce_mode > backend_cfg.bit_width))
8952 backend_cfg.bit_width = adev->dsp_bit_width_enforce_mode;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05308953
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308954 /*this is populated by check_codec_backend_cfg hence set default value to false*/
8955 backend_cfg.passthrough_enabled = false;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008956
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +05308957 /* Set Backend sampling rate to 176.4 for DSD64 and
8958 * 352.8Khz for DSD128.
8959 * Set Bit Width to 16
8960 */
8961 if ((backend_idx == DSD_NATIVE_BACKEND) && (backend_cfg.format == AUDIO_FORMAT_DSD)) {
8962 backend_cfg.bit_width = 16;
8963 if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD64)
8964 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
8965 else if (backend_cfg.sample_rate == INPUT_SAMPLING_RATE_DSD128)
8966 backend_cfg.sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
8967 }
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308968 ALOGI("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
8969 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
8970 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05308971 platform_get_snd_device_name(snd_device));
8972
Surendar Karka45850ae2018-07-02 17:45:27 +05308973 if ((my_data->spkr_ch_map != NULL) &&
8974 (platform_get_backend_index(snd_device) == DEFAULT_CODEC_BACKEND))
8975 platform_set_channel_map(my_data, my_data->spkr_ch_map->num_ch,
Rohit kumar4dbd2c02019-02-04 16:26:33 +05308976 my_data->spkr_ch_map->chmap, -1, device_be_idx);
Surendar Karka45850ae2018-07-02 17:45:27 +05308977
Haynes Mathew Georgebfe8ff42016-09-22 17:38:16 -07008978 if (platform_split_snd_device(my_data, snd_device, &num_devices,
8979 new_snd_devices) < 0)
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308980 new_snd_devices[0] = snd_device;
8981
8982 for (i = 0; i < num_devices; i++) {
8983 ALOGI("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308984 if ((platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
8985 &backend_cfg))) {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308986 ret = platform_set_codec_backend_cfg(adev, new_snd_devices[i],
Ashish Jaind84fd6a2016-07-27 12:33:25 +05308987 backend_cfg);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +05308988 if (!ret) {
8989 ret = true;
8990 } else {
8991 ret = false;
8992 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308993 }
Mingming Yin3ee55c62014-08-04 14:23:35 -07008994 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05308995 return ret;
Mingming Yin3ee55c62014-08-04 14:23:35 -07008996}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07008997
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05308998/*
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05308999 * goes through all the current usecases and picks the highest
9000 * bitwidth & samplerate
9001 */
Kuirong Wange9894162016-08-26 15:16:39 -07009002static bool platform_check_capture_codec_backend_cfg(struct audio_device* adev,
9003 int backend_idx,
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309004 struct audio_backend_cfg *backend_cfg,
9005 snd_device_t snd_device)
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309006{
9007 bool backend_change = false;
9008 unsigned int bit_width;
9009 unsigned int sample_rate;
Kuirong Wange9894162016-08-26 15:16:39 -07009010 unsigned int channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309011 unsigned int format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309012 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurent637e2d42018-11-15 12:24:31 -08009013 struct stream_in *in = adev_get_active_input(adev);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309014
Kuirong Wange9894162016-08-26 15:16:39 -07009015 bit_width = backend_cfg->bit_width;
9016 sample_rate = backend_cfg->sample_rate;
9017 channels = backend_cfg->channels;
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309018 format = backend_cfg->format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309019
9020 ALOGI("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309021 "sample rate: %d, channels %d format %d",__func__,backend_idx, bit_width,
9022 sample_rate, channels,format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309023
9024 // For voice calls use default configuration i.e. 16b/48K, only applicable to
9025 // default backend
9026 // force routing is not required here, caller will do it anyway
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309027 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION)) {
Preetam Singh Ranawatd770a362017-05-24 19:07:15 +05309028
Kuirong Wang0b947f72016-09-29 11:03:09 -07009029 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309030 "for unprocessed/camera source", __func__);
9031 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
9032 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309033 channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Samyak Jain2ab8c5a2018-11-26 19:57:47 +05309034 } else if (my_data->is_internal_codec && !audio_is_usb_in_device(snd_device)) {
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309035 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
9036 channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
Eric Laurent637e2d42018-11-15 12:24:31 -08009037 if (in && in->bit_width == 24)
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309038 bit_width = platform_get_snd_device_bit_width(snd_device);
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309039 } else {
9040 struct listnode *node;
9041 struct audio_usecase *uc = NULL;
9042 unsigned int uc_channels = 0;
9043 struct stream_in *in = NULL;
9044 /* update cfg against other existing capture usecases on same backend */
9045 list_for_each(node, &adev->usecase_list) {
9046 uc = node_to_item(node, struct audio_usecase, list);
Satya Krishna Pindiproli9f566672017-02-28 11:14:01 +05309047 in = (struct stream_in *) uc->stream.in;
9048 if (in != NULL && uc->type == PCM_CAPTURE &&
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309049 backend_idx == platform_get_backend_index(uc->in_snd_device)) {
Dhananjay Kumar9983c372016-12-09 22:00:40 +05309050 uc_channels = audio_channel_count_from_in_mask(in->channel_mask);
9051
9052 ALOGV("%s:txbecf: uc %s, id %d, sr %d, bw %d, ch %d, device %s",
9053 __func__, use_case_table[uc->id], uc->id, in->sample_rate,
9054 in->bit_width, uc_channels,
9055 platform_get_snd_device_name(uc->in_snd_device));
9056
9057 if (sample_rate < in->sample_rate)
9058 sample_rate = in->sample_rate;
9059 if (bit_width < in->bit_width)
9060 bit_width = in->bit_width;
9061 if (channels < uc_channels)
9062 channels = uc_channels;
9063 }
9064 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309065 }
Kuirong Wange9894162016-08-26 15:16:39 -07009066 if (backend_idx == USB_AUDIO_TX_BACKEND) {
9067 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
Kuirong Wang0b947f72016-09-29 11:03:09 -07009068 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
Kuirong Wange9894162016-08-26 15:16:39 -07009069 __func__, bit_width, sample_rate, channels);
9070 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309071
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009072 ALOGI("%s:txbecf: afe: current backend bit_width %d sample_rate %d channels %d, format %x",
9073 __func__,
9074 my_data->current_backend_cfg[backend_idx].bit_width,
9075 my_data->current_backend_cfg[backend_idx].sample_rate,
9076 my_data->current_backend_cfg[backend_idx].channels,
9077 my_data->current_backend_cfg[backend_idx].format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309078 // Force routing if the expected bitwdith or samplerate
9079 // is not same as current backend comfiguration
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009080 // Note that below if block would be entered even if main format is same
9081 // but subformat is different for e.g. current backend is configured for 16 bit PCM
9082 // as compared to 24 bit PCM backend requested
Kuirong Wang0b947f72016-09-29 11:03:09 -07009083 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
9084 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309085 (channels != my_data->current_backend_cfg[backend_idx].channels) ||
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009086 (format != my_data->current_backend_cfg[backend_idx].format)) {
Kuirong Wange9894162016-08-26 15:16:39 -07009087 backend_cfg->bit_width = bit_width;
9088 backend_cfg->sample_rate= sample_rate;
Kuirong Wang0b947f72016-09-29 11:03:09 -07009089 backend_cfg->channels = channels;
Arun Mirpuri3b5fcfb2019-04-11 16:44:06 -07009090 backend_cfg->format = format;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309091 backend_change = true;
9092 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309093 "new sample rate: %d new channel: %d new format: %d",
Kuirong Wang0b947f72016-09-29 11:03:09 -07009094 __func__, backend_cfg->bit_width,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309095 backend_cfg->sample_rate, backend_cfg->channels, backend_cfg->format);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309096 }
9097
9098 return backend_change;
9099}
9100
9101bool platform_check_and_set_capture_codec_backend_cfg(struct audio_device* adev,
9102 struct audio_usecase *usecase, snd_device_t snd_device)
9103{
Kuirong Wang0b947f72016-09-29 11:03:09 -07009104 int backend_idx = platform_get_backend_index(snd_device);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309105 int ret = 0;
Kuirong Wange9894162016-08-26 15:16:39 -07009106 struct audio_backend_cfg backend_cfg;
9107
9108 backend_cfg.passthrough_enabled = false;
Siddartha Shaik31b530e2017-05-19 15:26:33 +05309109
Surendar Karka93cd25a2018-08-28 14:21:37 +05309110 if (usecase->type == TRANSCODE_LOOPBACK_TX) {
Siddartha Shaik31b530e2017-05-19 15:26:33 +05309111 backend_cfg.bit_width = usecase->stream.inout->in_config.bit_width;
9112 backend_cfg.sample_rate = usecase->stream.inout->in_config.sample_rate;
9113 backend_cfg.format = usecase->stream.inout->in_config.format;
9114 backend_cfg.channels = audio_channel_count_from_out_mask(
9115 usecase->stream.inout->in_config.channel_mask);
9116 } else if (usecase->type == PCM_CAPTURE) {
Kuirong Wange9894162016-08-26 15:16:39 -07009117 backend_cfg.sample_rate= usecase->stream.in->sample_rate;
9118 backend_cfg.bit_width= usecase->stream.in->bit_width;
9119 backend_cfg.format= usecase->stream.in->format;
9120 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
Chaithanya Krishna Bacharajuc9f99712019-04-16 15:32:52 +05309121 if (is_loopback_input_device(usecase->stream.in->device)) {
9122 int bw = platform_get_snd_device_bit_width(snd_device);
9123 if ((-ENOSYS != bw) && (backend_cfg.bit_width > (uint32_t)bw)) {
9124 backend_cfg.bit_width = bw;
9125 ALOGD("%s:txbecf: set bitwidth to %d from platform info",
9126 __func__, bw);
9127 }
9128 }
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309129 } else {
Kuirong Wange9894162016-08-26 15:16:39 -07009130 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
9131 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
9132 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
9133 backend_cfg.channels = 1;
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309134 }
9135
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309136 ALOGI("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d format %d"
Kuirong Wange9894162016-08-26 15:16:39 -07009137 ", backend_idx %d usecase = %d device (%s)", __func__,
9138 backend_cfg.bit_width,
9139 backend_cfg.sample_rate,
9140 backend_cfg.channels,
Siddartha Shaik44dd7702017-06-14 12:13:25 +05309141 backend_cfg.format,
Kuirong Wange9894162016-08-26 15:16:39 -07009142 backend_idx, usecase->id,
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309143 platform_get_snd_device_name(snd_device));
Kuirong Wange9894162016-08-26 15:16:39 -07009144 if (platform_check_capture_codec_backend_cfg(adev, backend_idx,
Sachin Mohan Gadag4d7e5b82018-11-02 17:10:58 +05309145 &backend_cfg, snd_device)) {
Kuirong Wang0b947f72016-09-29 11:03:09 -07009146 ret = platform_set_codec_backend_cfg(adev, snd_device,
9147 backend_cfg);
Manish Dewanganba9fcfa2016-03-24 16:20:06 +05309148 if(!ret)
9149 return true;
9150 }
9151
9152 return false;
9153}
9154
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309155int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
9156 const char * hw_interface)
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009157{
9158 int ret = 0;
9159
9160 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
9161 ALOGE("%s: Invalid snd_device = %d",
9162 __func__, device);
9163 ret = -EINVAL;
9164 goto done;
9165 }
9166
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309167 ALOGD("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
9168 platform_get_snd_device_name(device),
9169 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null",
9170 backend_tag);
Ashish Jaind150d4c2017-02-03 18:44:34 +05309171
9172 if (backend_tag != NULL ) {
9173 if (backend_tag_table[device]) {
9174 free(backend_tag_table[device]);
9175 }
9176 backend_tag_table[device] = strdup(backend_tag);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009177 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309178
9179 if (hw_interface != NULL) {
9180 if (hw_interface_table[device])
9181 free(hw_interface_table[device]);
9182
9183 ALOGD("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
9184 hw_interface_table[device] = strdup(hw_interface);
9185 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009186done:
9187 return ret;
9188}
9189
Naresh Tanniru6160c712017-04-17 15:43:48 +05309190const char *platform_get_snd_device_backend_interface(snd_device_t device)
9191{
9192 const char *hw_interface_name = NULL;
9193
9194 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
9195 ALOGE("%s: Invalid snd_device = %d",
9196 __func__, device);
9197 goto done;
9198 }
9199
9200 /* Get string value of necessary backend for device */
9201 hw_interface_name = hw_interface_table[device];
9202 if (hw_interface_name == NULL)
9203 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
9204 else
9205 ALOGD("%s: hw_interface set for device %s\n", __func__, hw_interface_name);
9206done:
9207 return hw_interface_name;
9208}
9209
Siena Richard7c2db772016-12-21 11:32:34 -08009210int platform_get_snd_device_backend_index(snd_device_t device)
9211{
9212 int i, be_dai_id;
9213 const char * hw_interface_name = NULL;
9214
9215 ALOGV("%s: enter with device %d\n", __func__, device);
9216
Aditya Bavanari701a6992017-03-30 19:17:16 +05309217 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Siena Richard7c2db772016-12-21 11:32:34 -08009218 ALOGE("%s: Invalid snd_device = %d",
9219 __func__, device);
9220 be_dai_id = -EINVAL;
9221 goto done;
9222 }
9223
9224 /* Get string value of necessary backend for device */
9225 hw_interface_name = hw_interface_table[device];
9226 if (hw_interface_name == NULL) {
9227 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
9228 be_dai_id = -EINVAL;
9229 goto done;
9230 }
9231
9232 /* Check if be dai name table was retrieved successfully */
9233 if (be_dai_name_table == NULL) {
9234 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
9235 be_dai_id = -EFAULT;
9236 goto done;
9237 }
9238
9239 /* Get backend ID for device specified */
9240 for (i = 0; i < max_be_dai_names; i++) {
9241 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
9242 be_dai_id = be_dai_name_table[i].be_id;
9243 goto done;
9244 }
9245 }
9246 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
9247 be_dai_id = -EINVAL;
9248 goto done;
9249
9250done:
9251 return be_dai_id;
9252}
9253
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009254int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
9255{
9256 int ret = 0;
9257 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
9258 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
9259 ret = -EINVAL;
9260 goto done;
9261 }
9262
9263 if ((type != 0) && (type != 1)) {
9264 ALOGE("%s: invalid usecase type", __func__);
9265 ret = -EINVAL;
9266 }
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +05309267 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07009268 pcm_device_table[usecase][type] = pcm_id;
9269done:
9270 return ret;
9271}
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07009272
9273void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
9274{
Alexy Josephb1379942016-01-29 15:49:38 -08009275 *device_to_be_id = (int*) msm_device_to_be_id;
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07009276 *length = msm_be_id_array_len;
9277}
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309278
Varun Balaraje49253e2017-07-06 19:48:56 +05309279int platform_set_stream_pan_scale_params(void *platform,
9280 int snd_id,
9281 struct mix_matrix_params mm_params)
9282{
9283 struct platform_data *my_data = (struct platform_data *)platform;
9284 struct audio_device *adev = my_data->adev;
9285 struct mixer_ctl *ctl = NULL;
9286 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
9287 int ret = 0;
9288 int iter_i = 0;
9289 int iter_j = 0;
9290 int length = 0;
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309291 char *pan_scale_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05309292
9293 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
9294 "Audio Stream %d Pan Scale Control", snd_id);
9295 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9296
9297 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9298 if (!ctl) {
9299 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9300 __func__, mixer_ctl_name);
9301 ret = -EINVAL;
9302 goto end;
9303 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309304 pan_scale_data = (char *) calloc(1, sizeof(mm_params));
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309305 if (!pan_scale_data) {
9306 ret = -ENOMEM;
9307 goto end;
9308 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309309 memcpy(&pan_scale_data[length], &mm_params.num_output_channels,
9310 sizeof(mm_params.num_output_channels));
9311 length += sizeof(mm_params.num_output_channels);
9312 memcpy(&pan_scale_data[length], &mm_params.num_input_channels,
9313 sizeof(mm_params.num_input_channels));
9314 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05309315
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309316 memcpy(&pan_scale_data[length], &mm_params.has_output_channel_map,
9317 sizeof(mm_params.has_output_channel_map));
9318 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309319 if (mm_params.has_output_channel_map &&
9320 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309321 mm_params.num_output_channels > 0) {
9322 memcpy(&pan_scale_data[length], mm_params.output_channel_map,
9323 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
9324 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
9325 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309326 ret = -EINVAL;
9327 goto end;
9328 }
9329
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309330 memcpy(&pan_scale_data[length], &mm_params.has_input_channel_map,
9331 sizeof(mm_params.has_input_channel_map));
9332 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309333 if (mm_params.has_input_channel_map &&
9334 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309335 mm_params.num_input_channels > 0) {
9336 memcpy(&pan_scale_data[length], mm_params.input_channel_map,
9337 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
9338 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
9339 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309340 ret = -EINVAL;
9341 goto end;
9342 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309343 pan_scale_data[length] = mm_params.has_mixer_coeffs;
9344 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05309345 if (mm_params.has_mixer_coeffs)
9346 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309347 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
9348 memcpy(&pan_scale_data[length],
9349 &mm_params.mixer_coeffs[iter_i][iter_j],
9350 (sizeof(mm_params.mixer_coeffs[0][0])));
9351 length += (sizeof(mm_params.mixer_coeffs[0][0]));
9352 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309353
9354 ret = mixer_ctl_set_array(ctl, pan_scale_data, length);
9355end:
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309356 if (pan_scale_data)
9357 free(pan_scale_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05309358 return ret;
9359}
9360
9361int platform_set_stream_downmix_params(void *platform,
9362 int snd_id,
9363 snd_device_t snd_device,
9364 struct mix_matrix_params mm_params)
9365{
9366 struct platform_data *my_data = (struct platform_data *)platform;
9367 struct audio_device *adev = my_data->adev;
9368 struct mixer_ctl *ctl;
9369 char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309370 char *downmix_param_data = NULL;
Varun Balaraje49253e2017-07-06 19:48:56 +05309371 int ret = 0;
9372 int iter_i = 0;
9373 int iter_j = 0;
9374 int length = 0;
9375 int be_idx = 0;
9376
Varun Balaraje49253e2017-07-06 19:48:56 +05309377 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
9378 "Audio Device %d Downmix Control", snd_id);
9379 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9380
9381 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9382 if (!ctl) {
9383 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9384 __func__, mixer_ctl_name);
9385 ret = -EINVAL;
9386 }
9387
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309388 downmix_param_data = (char *) calloc(1, sizeof(mm_params) + sizeof(be_idx));
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309389 if (!downmix_param_data) {
9390 ret = -ENOMEM;
9391 goto end;
9392 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309393 be_idx = platform_get_snd_device_backend_index(snd_device);
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309394 memcpy(&downmix_param_data[length], &be_idx, sizeof(be_idx));
9395 length += sizeof(be_idx);
9396 memcpy(&downmix_param_data[length], &mm_params.num_output_channels,
9397 sizeof(mm_params.num_output_channels));
9398 length += sizeof(mm_params.num_output_channels);
9399 memcpy(&downmix_param_data[length], &mm_params.num_input_channels,
9400 sizeof(mm_params.num_input_channels));
9401 length += sizeof(mm_params.num_input_channels);
Varun Balaraje49253e2017-07-06 19:48:56 +05309402
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309403 memcpy(&downmix_param_data[length], &mm_params.has_output_channel_map,
9404 sizeof(mm_params.has_output_channel_map));
9405 length += sizeof(mm_params.has_output_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309406 if (mm_params.has_output_channel_map &&
9407 mm_params.num_output_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309408 mm_params.num_output_channels > 0) {
9409 memcpy(&downmix_param_data[length], mm_params.output_channel_map,
9410 (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0])));
9411 length += (mm_params.num_output_channels * sizeof(mm_params.output_channel_map[0]));
9412 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309413 ret = -EINVAL;
9414 goto end;
9415 }
9416
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309417 memcpy(&downmix_param_data[length], &mm_params.has_input_channel_map,
9418 sizeof(mm_params.has_input_channel_map));
9419 length += sizeof(mm_params.has_input_channel_map);
Varun Balaraje49253e2017-07-06 19:48:56 +05309420 if (mm_params.has_input_channel_map &&
9421 mm_params.num_input_channels <= MAX_CHANNELS_SUPPORTED &&
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309422 mm_params.num_input_channels > 0) {
9423 memcpy(&downmix_param_data[length], mm_params.input_channel_map,
9424 (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0])));
9425 length += (mm_params.num_input_channels * sizeof(mm_params.input_channel_map[0]));
9426 } else {
Varun Balaraje49253e2017-07-06 19:48:56 +05309427 ret = -EINVAL;
9428 goto end;
9429 }
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309430 memcpy(&downmix_param_data[length], &mm_params.has_mixer_coeffs,
9431 sizeof(mm_params.has_mixer_coeffs));
9432 length += sizeof(mm_params.has_mixer_coeffs);
Varun Balaraje49253e2017-07-06 19:48:56 +05309433 if (mm_params.has_mixer_coeffs)
9434 for (iter_i = 0; iter_i < mm_params.num_output_channels; iter_i++)
Varun Balarajf3cc95c2017-09-13 16:36:32 +05309435 for (iter_j = 0; iter_j < mm_params.num_input_channels; iter_j++) {
9436 memcpy((uint32_t *) &downmix_param_data[length],
9437 &mm_params.mixer_coeffs[iter_i][iter_j],
9438 (sizeof(mm_params.mixer_coeffs[0][0])));
9439 length += (sizeof(mm_params.mixer_coeffs[0][0]));
9440 }
Varun Balaraje49253e2017-07-06 19:48:56 +05309441
9442 ret = mixer_ctl_set_array(ctl, downmix_param_data, length);
9443end:
Nikhil Latukar2e6f6242017-08-15 13:37:07 +05309444 if (downmix_param_data)
9445 free(downmix_param_data);
Varun Balaraje49253e2017-07-06 19:48:56 +05309446 return ret;
9447}
9448
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309449int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
9450 int snd_id, uint8_t *input_channel_map)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009451{
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309452 int ret = 0, i = 0;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009453 int channels = audio_channel_count_from_out_mask(channel_mask);
9454
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309455 char channel_map[AUDIO_CHANNEL_COUNT_MAX];
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009456 memset(channel_map, 0, sizeof(channel_map));
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309457 if (*input_channel_map) {
9458 for (i = 0; i < channels; i++) {
9459 ALOGV("%s:: Channel Map channel_map[%d] - %d", __func__, i, *input_channel_map);
9460 channel_map[i] = *input_channel_map;
9461 input_channel_map++;
9462 }
9463 } else {
9464 /* Following are all most common standard WAV channel layouts
9465 overridden by channel mask if its allowed and different */
9466 switch (channels) {
9467 case 1:
9468 /* AUDIO_CHANNEL_OUT_MONO */
9469 channel_map[0] = PCM_CHANNEL_FC;
9470 break;
9471 case 2:
9472 /* AUDIO_CHANNEL_OUT_STEREO */
9473 channel_map[0] = PCM_CHANNEL_FL;
9474 channel_map[1] = PCM_CHANNEL_FR;
9475 break;
9476 case 3:
9477 /* AUDIO_CHANNEL_OUT_2POINT1 */
9478 channel_map[0] = PCM_CHANNEL_FL;
9479 channel_map[1] = PCM_CHANNEL_FR;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009480 channel_map[2] = PCM_CHANNEL_FC;
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309481 break;
9482 case 4:
9483 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
9484 channel_map[0] = PCM_CHANNEL_FL;
9485 channel_map[1] = PCM_CHANNEL_FR;
9486 channel_map[2] = PCM_CHANNEL_LS;
9487 channel_map[3] = PCM_CHANNEL_RS;
9488 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK) {
9489 channel_map[2] = PCM_CHANNEL_LB;
9490 channel_map[3] = PCM_CHANNEL_RB;
9491 }
9492 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND) {
9493 channel_map[2] = PCM_CHANNEL_FC;
9494 channel_map[3] = PCM_CHANNEL_CS;
9495 }
9496 break;
9497 case 5:
9498 /* AUDIO_CHANNEL_OUT_PENTA */
9499 channel_map[0] = PCM_CHANNEL_FL;
9500 channel_map[1] = PCM_CHANNEL_FR;
9501 channel_map[2] = PCM_CHANNEL_FC;
9502 channel_map[3] = PCM_CHANNEL_LB;
9503 channel_map[4] = PCM_CHANNEL_RB;
9504 break;
9505 case 6:
9506 /* AUDIO_CHANNEL_OUT_5POINT1 */
9507 channel_map[0] = PCM_CHANNEL_FL;
9508 channel_map[1] = PCM_CHANNEL_FR;
9509 channel_map[2] = PCM_CHANNEL_FC;
9510 channel_map[3] = PCM_CHANNEL_LFE;
9511 channel_map[4] = PCM_CHANNEL_LB;
9512 channel_map[5] = PCM_CHANNEL_RB;
9513 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE) {
9514 channel_map[4] = PCM_CHANNEL_LS;
9515 channel_map[5] = PCM_CHANNEL_RS;
9516 }
9517 break;
9518 case 7:
9519 /* AUDIO_CHANNEL_OUT_6POINT1 */
9520 channel_map[0] = PCM_CHANNEL_FL;
9521 channel_map[1] = PCM_CHANNEL_FR;
9522 channel_map[2] = PCM_CHANNEL_FC;
9523 channel_map[3] = PCM_CHANNEL_LFE;
9524 channel_map[4] = PCM_CHANNEL_LB;
9525 channel_map[5] = PCM_CHANNEL_RB;
9526 channel_map[6] = PCM_CHANNEL_CS;
9527 break;
9528 case 8:
9529 /* AUDIO_CHANNEL_OUT_7POINT1 */
9530 channel_map[0] = PCM_CHANNEL_FL;
9531 channel_map[1] = PCM_CHANNEL_FR;
9532 channel_map[2] = PCM_CHANNEL_FC;
9533 channel_map[3] = PCM_CHANNEL_LFE;
9534 channel_map[4] = PCM_CHANNEL_LB;
9535 channel_map[5] = PCM_CHANNEL_RB;
Weiyin Jiangff72f812018-04-13 15:02:33 +08009536 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1POINT2) {
9537 channel_map[6] = PCM_CHANNEL_TFL;
9538 channel_map[7] = PCM_CHANNEL_TFR;
9539 } else {
9540 channel_map[6] = PCM_CHANNEL_LS;
9541 channel_map[7] = PCM_CHANNEL_RS;
9542 }
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309543 break;
Dieter Luecking5d57def2018-09-07 14:23:37 +02009544 case 12:
9545 /* AUDIO_CHANNEL_OUT_7POINT1POINT4 */
9546 channel_map[0] = PCM_CHANNEL_FL;
9547 channel_map[1] = PCM_CHANNEL_FR;
9548 channel_map[2] = PCM_CHANNEL_FC;
9549 channel_map[3] = PCM_CHANNEL_LFE;
9550 channel_map[4] = PCM_CHANNEL_LB;
9551 channel_map[5] = PCM_CHANNEL_RB;
9552 channel_map[6] = PCM_CHANNEL_LS;
9553 channel_map[7] = PCM_CHANNEL_RS;
9554 channel_map[8] = PCM_CHANNEL_TFL;
9555 channel_map[9] = PCM_CHANNEL_TFR;
9556 channel_map[10] = PCM_CHANNEL_TSL;
9557 channel_map[11] = PCM_CHANNEL_TSR;
9558 break;
9559 case 16:
9560 /* 16 channels */
9561 channel_map[0] = PCM_CHANNEL_FL;
9562 channel_map[1] = PCM_CHANNEL_FR;
9563 channel_map[2] = PCM_CHANNEL_FC;
9564 channel_map[3] = PCM_CHANNEL_LFE;
9565 channel_map[4] = PCM_CHANNEL_LB;
9566 channel_map[5] = PCM_CHANNEL_RB;
9567 channel_map[6] = PCM_CHANNEL_LS;
9568 channel_map[7] = PCM_CHANNEL_RS;
9569 channel_map[8] = PCM_CHANNEL_TFL;
9570 channel_map[9] = PCM_CHANNEL_TFR;
9571 channel_map[10] = PCM_CHANNEL_TSL;
9572 channel_map[11] = PCM_CHANNEL_TSR;
9573 channel_map[12] = PCM_CHANNEL_FLC;
9574 channel_map[13] = PCM_CHANNEL_FRC;
9575 channel_map[14] = PCM_CHANNEL_RLC;
9576 channel_map[15] = PCM_CHANNEL_RRC;
9577 break;
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05309578 default:
9579 ALOGE("unsupported channels %d for setting channel map", channels);
9580 return -1;
9581 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009582 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309583 ret = platform_set_channel_map(platform, channels, channel_map, snd_id, -1);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009584 return ret;
9585}
9586
9587int platform_get_edid_info(void *platform)
9588{
9589 struct platform_data *my_data = (struct platform_data *)platform;
9590 struct audio_device *adev = my_data->adev;
9591 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05309592 int ret, count;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009593 char *mix_ctl_name;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009594 struct mixer_ctl *ctl;
9595 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
9596 edid_audio_info *info;
9597
9598 if (my_data->edid_valid) {
9599 /* use cached edid */
9600 return 0;
9601 }
9602
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009603 switch(my_data->ext_disp_type) {
9604 case EXT_DISPLAY_TYPE_HDMI:
9605 mix_ctl_name = "HDMI EDID";
9606 break;
9607 case EXT_DISPLAY_TYPE_DP:
9608 mix_ctl_name = "Display Port EDID";
9609 break;
9610 default:
9611 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
9612 return -EINVAL;
9613 }
9614
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009615 if (my_data->edid_info == NULL) {
9616 my_data->edid_info =
9617 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
9618 }
9619
9620 info = my_data->edid_info;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009621 ctl = mixer_get_ctl_by_name(adev->mixer, mix_ctl_name);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009622 if (!ctl) {
9623 ALOGE("%s: Could not get ctl for mixer cmd - %s",
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009624 __func__, mix_ctl_name);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009625 goto fail;
9626 }
9627
9628 mixer_ctl_update(ctl);
9629
9630 count = mixer_ctl_get_num_values(ctl);
9631
9632 /* Read SAD blocks, clamping the maximum size for safety */
9633 if (count > (int)sizeof(block))
9634 count = (int)sizeof(block);
9635
9636 ret = mixer_ctl_get_array(ctl, block, count);
9637 if (ret != 0) {
9638 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
9639 goto fail;
9640 }
9641 edid_data[0] = count;
9642 memcpy(&edid_data[1], block, count);
9643
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08009644 if (!audio_extn_edid_get_sink_caps(info, edid_data)) {
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009645 ALOGE("%s: Failed to get extn disp sink capabilities", __func__);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009646 goto fail;
9647 }
9648 my_data->edid_valid = true;
9649 return 0;
9650fail:
9651 if (my_data->edid_info) {
9652 free(my_data->edid_info);
9653 my_data->edid_info = NULL;
9654 my_data->edid_valid = false;
9655 }
9656 ALOGE("%s: return -EINVAL", __func__);
9657 return -EINVAL;
9658}
9659
9660
9661int platform_set_channel_allocation(void *platform, int channel_alloc)
9662{
9663 struct mixer_ctl *ctl;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009664 char *mixer_ctl_name;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009665 int ret;
9666 struct platform_data *my_data = (struct platform_data *)platform;
9667 struct audio_device *adev = my_data->adev;
9668
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009669 switch(my_data->ext_disp_type) {
9670 case EXT_DISPLAY_TYPE_HDMI:
9671 mixer_ctl_name = "HDMI RX CA";
9672 break;
9673 case EXT_DISPLAY_TYPE_DP:
9674 mixer_ctl_name = "Display Port RX CA";
9675 break;
9676 default:
9677 ALOGE("%s: Invalid disp_type %d", __func__, my_data->ext_disp_type);
9678 return -EINVAL;
9679 }
9680
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009681 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
9682 if (!ctl) {
9683 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9684 __func__, mixer_ctl_name);
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -07009685 return -EINVAL;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009686 }
9687 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
9688 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
9689
9690 if (ret < 0) {
9691 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
9692 }
9693
9694 return ret;
9695}
9696
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309697int 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 -07009698{
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309699 struct mixer_ctl *ctl, *be_ctl = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08009700 char mixer_ctl_name[44] = {0}; // max length of name is 44 as defined
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309701 char be_mixer_ctl_name[] = "Backend Device Channel Map";
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009702 int ret;
Ramu Gottipati02809682018-12-19 16:46:12 +05309703 int i=0, n=0;
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309704 int be_id_count = 0;
Dieter Luecking5d57def2018-09-07 14:23:37 +02009705 long set_values[AUDIO_MAX_DSP_CHANNELS];
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309706 long be_set_values[AUDIO_MAX_DSP_CHANNELS + 1] = {0};
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009707 struct platform_data *my_data = (struct platform_data *)platform;
9708 struct audio_device *adev = my_data->adev;
9709 ALOGV("%s channel_count:%d",__func__, ch_count);
Dieter Luecking5d57def2018-09-07 14:23:37 +02009710
9711 /*
9712 * FIXME:
9713 * Currently the channel mask in audio.h is limited to 30 channels,
9714 * (=AUDIO_CHANNEL_COUNT_MAX), whereas the mixer controls already
9715 * allow up to AUDIO_MAX_DSP_CHANNELS channels as per final requirement.
9716 * Until channel mask definition is not changed from a uint32_t value
9717 * to something else, a sanity check is needed here.
9718 */
9719 if (NULL == ch_map || (ch_count < 1) || (ch_count > AUDIO_CHANNEL_COUNT_MAX)) {
Divya Narayanan Poojary21de6aa2017-01-06 12:07:19 +05309720 ALOGE("%s: Invalid channel mapping or channel count value", __func__);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009721 return -EINVAL;
9722 }
Fred Ohe0479682015-03-25 16:30:26 -07009723
9724 /*
9725 * If snd_id is greater than 0, stream channel mapping
9726 * If snd_id is below 0, typically -1, device channel mapping
9727 */
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009728 if (snd_id >= 0) {
Fred Ohe0479682015-03-25 16:30:26 -07009729 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
9730 } else {
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309731 if (be_idx >= 0) {
9732 be_ctl = mixer_get_ctl_by_name(adev->mixer, be_mixer_ctl_name);
9733 if (!be_ctl) {
9734 ALOGD("%s: Could not get ctl for mixer cmd - %s, using default control",
9735 __func__, be_mixer_ctl_name);
9736 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
9737 be_idx = -1;
9738 } else {
9739 strlcpy(mixer_ctl_name, "Backend Device Channel Map", sizeof(mixer_ctl_name));
9740 be_id_count = 1;
9741 }
9742 } else {
9743 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
9744 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009745 }
9746
9747 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
9748
9749 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
Dieter Luecking5d57def2018-09-07 14:23:37 +02009750
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009751 if (!ctl) {
9752 ALOGE("%s: Could not get ctl for mixer cmd - %s",
9753 __func__, mixer_ctl_name);
9754 return -EINVAL;
9755 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02009756
9757 /* find out how many values the control can set */
9758 n = mixer_ctl_get_num_values(ctl);
9759
9760 if (n != ch_count)
9761 ALOGV("%s chcnt %d != mixerctl elem size %d",__func__, ch_count, n);
9762
9763 if (n < ch_count) {
9764 ALOGE("%s chcnt %d > mixerctl elem size %d",__func__, ch_count, n);
9765 return -EINVAL;
9766 }
9767
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309768 if (n > (AUDIO_MAX_DSP_CHANNELS + be_id_count)) {
Dieter Luecking5d57def2018-09-07 14:23:37 +02009769 ALOGE("%s mixerctl elem size %d > AUDIO_MAX_DSP_CHANNELS %d",__func__, n, AUDIO_MAX_DSP_CHANNELS);
9770 return -EINVAL;
9771 }
9772
9773 /* initialize all set_values to zero */
9774 memset (set_values, 0, sizeof(set_values));
9775
9776 /* copy only as many values as corresponding mixer_ctrl allows */
9777 for (i = 0; i < ch_count; i++) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009778 set_values[i] = ch_map[i];
9779 }
9780
Manish Dewangan338c50a2017-09-12 15:22:03 +05309781 ALOGD("%s: set mapping(%ld %ld %ld %ld %ld %ld %ld %ld) for channel:%d", __func__,
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009782 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
9783 set_values[5], set_values[6], set_values[7], ch_count);
9784
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309785 if (be_idx >= 0) {
9786 be_set_values[0] = be_idx;
9787 memcpy(&be_set_values[1], set_values, sizeof(long) * ch_count);
9788 ret = mixer_ctl_set_array(ctl, be_set_values, ARRAY_SIZE(be_set_values));
9789 } else {
9790 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
9791 }
Dieter Luecking5d57def2018-09-07 14:23:37 +02009792
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009793 if (ret < 0) {
9794 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
9795 __func__, ret, ch_count);
9796 }
9797 return ret;
9798}
9799
9800unsigned char platform_map_to_edid_format(int audio_format)
9801{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009802 unsigned char format;
9803 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
9804 case AUDIO_FORMAT_AC3:
9805 ALOGV("%s: AC3", __func__);
9806 format = AC3;
9807 break;
9808 case AUDIO_FORMAT_AAC:
9809 ALOGV("%s:AAC", __func__);
9810 format = AAC;
9811 break;
Manish Dewangana6fc5442015-08-24 20:30:31 +05309812 case AUDIO_FORMAT_AAC_ADTS:
9813 ALOGV("%s:AAC_ADTS", __func__);
9814 format = AAC;
9815 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009816 case AUDIO_FORMAT_E_AC3:
Satish Babu Patakokilaa395a9e2016-11-01 12:18:49 +05309817 case AUDIO_FORMAT_E_AC3_JOC:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009818 ALOGV("%s:E_AC3", __func__);
9819 format = DOLBY_DIGITAL_PLUS;
9820 break;
Ben Romberger1aaaf862017-04-06 17:49:46 -07009821 case AUDIO_FORMAT_DOLBY_TRUEHD:
9822 ALOGV("%s:MAT", __func__);
9823 format = MAT;
9824 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08009825 case AUDIO_FORMAT_DTS:
9826 ALOGV("%s:DTS", __func__);
9827 format = DTS;
9828 break;
9829 case AUDIO_FORMAT_DTS_HD:
9830 ALOGV("%s:DTS_HD", __func__);
9831 format = DTS_HD;
9832 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009833 case AUDIO_FORMAT_PCM_16_BIT:
Ashish Jain5106d362016-05-11 19:23:33 +05309834 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
9835 case AUDIO_FORMAT_PCM_8_24_BIT:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009836 ALOGV("%s:PCM", __func__);
Mingming Yin3a941d42016-02-17 18:08:05 -08009837 format = LPCM;
9838 break;
Naresh Tanniru928f0862017-04-07 16:44:23 -07009839 case AUDIO_FORMAT_IEC61937:
9840 ALOGV("%s:IEC61937", __func__);
9841 format = 0;
9842 break;
Mingming Yin3a941d42016-02-17 18:08:05 -08009843 default:
Mingming Yin3a941d42016-02-17 18:08:05 -08009844 format = -1;
Naresh Tanniru928f0862017-04-07 16:44:23 -07009845 ALOGE("%s:invalid format: 0x%x", __func__, audio_format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009846 break;
9847 }
9848 return format;
9849}
9850
Ashish Jaina052e572016-11-07 16:41:07 +05309851void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
9852 unsigned int stream_sr, int* sample_rate)
9853{
9854 struct platform_data* my_data = (struct platform_data *)platform;
9855 int backend_idx = platform_get_backend_index(snd_device);
9856 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
9857 /*
9858 *Check if device SR is multiple of 8K or 11.025 Khz
9859 *check if the stream SR is multiple of same base, if yes
9860 *then have copp SR equal to stream SR, this ensures that
9861 *post processing happens at stream SR, else have
9862 *copp SR equal to device SR.
9863 */
9864 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
9865 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
9866 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
9867 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
9868 *sample_rate = device_sr;
9869 } else
9870 *sample_rate = stream_sr;
9871
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +05309872 if ((snd_device == SND_DEVICE_OUT_HDMI) || (snd_device == SND_DEVICE_OUT_DISPLAY_PORT) ||
9873 (snd_device == SND_DEVICE_OUT_USB_HEADSET))
9874 *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
Venugopal Nadipalli83134582017-09-21 22:34:50 +05309875
9876 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 +05309877
9878}
9879
Aalique Grahame22e49102018-12-18 14:23:57 -08009880// called from info parser
9881void platform_add_app_type(const char *uc_type,
9882 const char *mode,
9883 int bw,
9884 int app_type, int max_rate) {
9885 struct app_type_entry *ap =
9886 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
9887
9888 if (!ap) {
9889 ALOGE("%s failed to allocate mem for app type", __func__);
9890 return;
9891 }
9892
9893 ap->uc_type = -1;
9894 for (int i=0; i<USECASE_TYPE_MAX; i++) {
9895 if (!strcmp(uc_type, usecase_type_index[i].name)) {
9896 ap->uc_type = usecase_type_index[i].index;
9897 break;
9898 }
9899 }
9900
9901 if (ap->uc_type == -1) {
9902 free(ap);
9903 return;
9904 }
9905
9906 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
9907 __func__, uc_type, mode, bw, app_type, max_rate);
9908 ap->bit_width = bw;
9909 ap->app_type = app_type;
9910 ap->max_rate = max_rate;
9911 ap->mode = strdup(mode);
9912 list_add_tail(&app_type_entry_list, &ap->node);
9913}
9914
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009915void platform_reset_edid_info(void *platform) {
9916
9917 ALOGV("%s:", __func__);
9918 struct platform_data *my_data = (struct platform_data *)platform;
9919 if (my_data->edid_info) {
9920 ALOGV("%s :free edid", __func__);
9921 free(my_data->edid_info);
9922 my_data->edid_info = NULL;
9923 }
9924}
9925
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009926bool platform_is_edid_supported_format(void *platform, int format)
9927{
9928 struct platform_data *my_data = (struct platform_data *)platform;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009929 edid_audio_info *info = NULL;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05309930 int i, ret;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009931 unsigned char format_id = platform_map_to_edid_format(format);
9932
Naresh Tanniru928f0862017-04-07 16:44:23 -07009933 if (format == AUDIO_FORMAT_IEC61937)
9934 return true;
9935
Mingming Yin3a941d42016-02-17 18:08:05 -08009936 if (format_id <= 0) {
9937 ALOGE("%s invalid edid format mappting for :%x" ,__func__, format);
9938 return false;
9939 }
9940
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009941 ret = platform_get_edid_info(platform);
9942 info = (edid_audio_info *)my_data->edid_info;
9943 if (ret == 0 && info != NULL) {
9944 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009945 /*
9946 * To check
9947 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
9948 * & DOLBY_DIGITAL_PLUS
9949 */
9950 if (info->audio_blocks_array[i].format_id == format_id) {
Mingming Yin3a941d42016-02-17 18:08:05 -08009951 ALOGV("%s:returns true %x",
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009952 __func__, format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009953 return true;
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07009954 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009955 }
9956 }
Mingming Yin3a941d42016-02-17 18:08:05 -08009957 ALOGV("%s:returns false %x",
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009958 __func__, format);
9959 return false;
9960}
9961
Mingming Yin3a941d42016-02-17 18:08:05 -08009962bool platform_is_edid_supported_sample_rate(void *platform, int sample_rate)
9963{
9964 struct platform_data *my_data = (struct platform_data *)platform;
Mingming Yin3a941d42016-02-17 18:08:05 -08009965 edid_audio_info *info = NULL;
Garmond Leung2f78a672016-11-07 16:27:40 -08009966 int ret = 0;
Mingming Yin3a941d42016-02-17 18:08:05 -08009967
9968 ret = platform_get_edid_info(platform);
9969 info = (edid_audio_info *)my_data->edid_info;
9970 if (ret == 0 && info != NULL) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08009971 return audio_extn_edid_is_supported_sr(info, sample_rate);
Mingming Yin3a941d42016-02-17 18:08:05 -08009972 }
Mingming Yin3a941d42016-02-17 18:08:05 -08009973
9974 return false;
9975}
9976
Naresh Tanniru3a406772017-05-10 13:09:05 -07009977int platform_edid_get_highest_supported_sr(void *platform)
9978{
9979 struct platform_data *my_data = (struct platform_data *)platform;
9980 edid_audio_info *info = NULL;
9981 int ret = 0;
9982
9983 ret = platform_get_edid_info(platform);
9984 info = (edid_audio_info *)my_data->edid_info;
9985 if (ret == 0 && info != NULL) {
Arun Mirpurib1bec9c2019-01-29 16:42:45 -08009986 return audio_extn_edid_get_highest_supported_sr(info);
Naresh Tanniru3a406772017-05-10 13:09:05 -07009987 }
9988
9989 return 0;
9990}
Mingming Yin3a941d42016-02-17 18:08:05 -08009991
Dieter Luecking5d57def2018-09-07 14:23:37 +02009992bool platform_spkr_use_default_sample_rate(void *platform) {
9993 struct platform_data *my_data = (struct platform_data *)platform;
9994 return my_data->use_sprk_default_sample_rate;
9995}
9996
Rohit kumar4dbd2c02019-02-04 16:26:33 +05309997int platform_set_edid_channels_configuration(void *platform, int channels, int backend_idx, snd_device_t snd_device) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07009998
9999 struct platform_data *my_data = (struct platform_data *)platform;
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010000 struct audio_device *adev = my_data->adev;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010001 edid_audio_info *info = NULL;
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010002 int ret;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010003 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010004 struct audio_device_config_param *adev_device_cfg_ptr = adev->device_cfg_params;
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010005 int be_idx = -1;
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010006 int channel_alloc = 0;
10007 int max_supported_channels = 0;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010008
Weiyin Jiangff72f812018-04-13 15:02:33 +080010009 if ((backend_idx != HDMI_RX_BACKEND) &&
10010 (backend_idx != DISP_PORT_RX_BACKEND)) {
10011 ALOGE("%s: Invalid backend idx %d", __func__, backend_idx);
10012 return -EINVAL;
10013 }
10014
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010015 be_idx = platform_get_snd_device_backend_index(snd_device);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010016 ret = platform_get_edid_info(platform);
10017 info = (edid_audio_info *)my_data->edid_info;
Weiyin Jiangff72f812018-04-13 15:02:33 +080010018 adev_device_cfg_ptr += backend_idx;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010019 if(ret == 0 && info != NULL) {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010020 if ((channels > 2) && (channels <= MAX_HDMI_CHANNEL_CNT)) {
Weiyin Jiangff72f812018-04-13 15:02:33 +080010021 ALOGV("%s:able to get HDMI/DP sink capabilities multi channel playback",
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010022 __func__);
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010023 max_supported_channels = platform_edid_get_max_channels(my_data);
10024 if (channels > max_supported_channels)
10025 channels = max_supported_channels;
10026 // refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4
10027 switch (channels) {
10028 case 3:
10029 channel_alloc = 0x02; break;
10030 case 4:
10031 channel_alloc = 0x06; break;
10032 case 5:
10033 channel_alloc = 0x0A; break;
10034 case 6:
10035 channel_alloc = 0x0B; break;
10036 case 7:
10037 channel_alloc = 0x12; break;
10038 case 8:
10039 channel_alloc = 0x13; break;
10040 default:
10041 ALOGE("%s: invalid channel %d", __func__, channels);
10042 return -EINVAL;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010043 }
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010044 ALOGVV("%s:channels:%d", __func__, channels);
10045
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010046 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10047 platform_set_channel_map(platform, adev_device_cfg_ptr->dev_cfg_params.channels,
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010048 (char *)adev_device_cfg_ptr->dev_cfg_params.channel_map, -1, be_idx);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010049 } else {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010050 platform_set_channel_map(platform, channels, info->channel_map, -1, be_idx);
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010051 }
10052
10053 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10054 ALOGV("%s:: Setting client selected CA %d", __func__,
10055 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
10056 platform_set_channel_allocation(platform,
10057 adev_device_cfg_ptr->dev_cfg_params.channel_allocation);
10058 } else {
Weiyin Jiang03b2cb22019-09-04 16:45:45 +080010059 platform_set_channel_allocation(platform, channel_alloc);
10060 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010061 } else {
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010062 if (adev_device_cfg_ptr->use_client_dev_cfg) {
10063 default_channelMap[0] = adev_device_cfg_ptr->dev_cfg_params.channel_map[0];
10064 default_channelMap[1] = adev_device_cfg_ptr->dev_cfg_params.channel_map[1];
10065 } else {
10066 default_channelMap[0] = PCM_CHANNEL_FL;
10067 default_channelMap[1] = PCM_CHANNEL_FR;
10068 }
Rohit kumar4dbd2c02019-02-04 16:26:33 +053010069 platform_set_channel_map(platform, 2, default_channelMap, -1, be_idx);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010070 platform_set_channel_allocation(platform,0);
10071 }
10072 }
10073
10074 return 0;
10075}
10076
10077void platform_cache_edid(void * platform)
10078{
10079 platform_get_edid_info(platform);
10080}
10081
Siddartha Shaik44dd7702017-06-14 12:13:25 +053010082void platform_invalidate_backend_config(void * platform,snd_device_t snd_device)
10083{
10084 struct platform_data *my_data = (struct platform_data *)platform;
10085 struct audio_device *adev = my_data->adev;
10086 struct audio_backend_cfg backend_cfg;
10087 int backend_idx;
10088
10089 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10090 backend_cfg.channels = CODEC_BACKEND_DEFAULT_CHANNELS;
10091 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10092 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
10093 backend_cfg.passthrough_enabled = false;
10094
10095 backend_idx = platform_get_backend_index(snd_device);
10096 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
10097 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10098 my_data->current_backend_cfg[backend_idx].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
10099 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10100 my_data->current_backend_cfg[backend_idx].format = AUDIO_FORMAT_PCM_16_BIT;
10101}
10102
Mingming Yinddd610b2016-01-20 17:09:32 -080010103void platform_invalidate_hdmi_config(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010104{
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010105 //reset ext display EDID info
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010106 struct platform_data *my_data = (struct platform_data *)platform;
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010107 struct audio_device *adev = my_data->adev;
10108 struct audio_backend_cfg backend_cfg;
10109 int backend_idx;
10110 snd_device_t snd_device;
10111
10112 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10113 backend_cfg.channels = DEFAULT_HDMI_OUT_CHANNELS;
10114 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
10115 backend_cfg.format = 0;
10116 backend_cfg.passthrough_enabled = false;
10117
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010118 my_data->edid_valid = false;
10119 if (my_data->edid_info) {
10120 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
10121 }
Mingming Yinddd610b2016-01-20 17:09:32 -080010122
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010123 if (my_data->ext_disp_type == EXT_DISPLAY_TYPE_HDMI) {
10124 //reset HDMI_RX_BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010125 backend_idx = HDMI_RX_BACKEND;
10126 snd_device = SND_DEVICE_OUT_HDMI;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010127 } else {
10128 //reset Display port BACKEND to default values
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010129 backend_idx = DISP_PORT_RX_BACKEND;
10130 snd_device = SND_DEVICE_OUT_DISPLAY_PORT;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010131 }
Ben Rombergere9e80ee2017-04-26 16:00:10 -070010132 platform_set_codec_backend_cfg(adev, snd_device, backend_cfg);
10133 my_data->current_backend_cfg[backend_idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
10134 my_data->current_backend_cfg[backend_idx].channels = DEFAULT_HDMI_OUT_CHANNELS;
10135 my_data->current_backend_cfg[backend_idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Shiv Maliyappanahallic0656402016-09-03 14:13:26 -070010136 my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070010137}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010138
10139int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
10140 const char *mixer_val)
10141{
10142 struct audio_device *adev = out->dev;
10143 struct mixer_ctl *ctl = NULL;
10144 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
10145 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10146 if (!ctl) {
10147 ALOGE("%s: could not get ctl for mixer cmd - %s",
10148 __func__, mixer_ctl_name);
10149 return -EINVAL;
10150 }
10151
10152 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
10153}
10154
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010155int platform_set_device_params(struct stream_out *out, int param, int value)
10156{
10157 struct audio_device *adev = out->dev;
10158 struct mixer_ctl *ctl;
10159 char *mixer_ctl_name = "Device PP Params";
10160 int ret = 0;
Manish Dewangan338c50a2017-09-12 15:22:03 +053010161 long set_values[] = {0,0};
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070010162
10163 set_values[0] = param;
10164 set_values[1] = value;
10165
10166 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10167 if (!ctl) {
10168 ALOGE("%s: Could not get ctl for mixer cmd - %s",
10169 __func__, mixer_ctl_name);
10170 ret = -EINVAL;
10171 goto end;
10172 }
10173
10174 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
10175 __func__,param, value, mixer_ctl_name);
10176 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
10177
10178end:
10179 return ret;
10180}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010181
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010182bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
10183{
10184 bool ret = false;
10185
10186 if (snd_device == SND_DEVICE_OUT_SPEAKER ||
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010187 snd_device == SND_DEVICE_OUT_SPEAKER_REVERSE ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010188 snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010189 snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
10190 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
Rohit kumarf4120402016-08-05 19:19:48 +053010191 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT ||
Manisha Agarwaled9c4542019-02-08 14:58:48 +053010192 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_STEREO ||
Rohit kumarf4120402016-08-05 19:19:48 +053010193 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010194 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2 ||
10195 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA ||
10196 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA) {
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010197 ret = true;
10198 }
10199
10200 return ret;
10201}
10202
10203int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
10204{
10205 int acdb_id;
10206
10207 switch(snd_device) {
10208 case SND_DEVICE_OUT_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010209 case SND_DEVICE_OUT_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010210 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
10211 break;
10212 case SND_DEVICE_OUT_VOICE_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010213 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010214 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
10215 break;
Rohit kumarf4120402016-08-05 19:19:48 +053010216 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010217 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
Rohit kumarf4120402016-08-05 19:19:48 +053010218 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED);
10219 break;
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010220 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
10221 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED);
10222 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010223 case SND_DEVICE_OUT_SPEAKER_VBAT:
10224 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
10225 break;
10226 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
10227 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
10228 break;
Rohit kumarf4120402016-08-05 19:19:48 +053010229 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
10230 acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT);
10231 break;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010232 default:
10233 acdb_id = -EINVAL;
10234 break;
10235 }
10236 return acdb_id;
10237}
10238
10239int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
10240{
10241 if (!audio_extn_spkr_prot_is_enabled())
10242 return snd_device;
10243
10244 switch(snd_device) {
10245 case SND_DEVICE_OUT_SPEAKER:
Aalique Grahame22e49102018-12-18 14:23:57 -080010246 case SND_DEVICE_OUT_SPEAKER_REVERSE:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010247 case SND_DEVICE_OUT_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010248 return SND_DEVICE_OUT_SPEAKER_PROTECTED;
Aalique Grahame22e49102018-12-18 14:23:57 -080010249 case SND_DEVICE_OUT_SPEAKER_SAFE:
10250 return SND_DEVICE_OUT_SPEAKER_SAFE;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010251 case SND_DEVICE_OUT_VOICE_SPEAKER:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010252 case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010253 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
Rohit kumarf4120402016-08-05 19:19:48 +053010254 case SND_DEVICE_OUT_VOICE_SPEAKER_2:
Sujin Panickerb904fbe2019-04-04 13:28:07 +053010255 case SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA:
Rohit kumarf4120402016-08-05 19:19:48 +053010256 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED;
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010257 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO:
10258 return SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010259 case SND_DEVICE_OUT_SPEAKER_VBAT:
10260 return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
10261 case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
10262 return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
Rohit kumarf4120402016-08-05 19:19:48 +053010263 case SND_DEVICE_OUT_VOICE_SPEAKER_2_VBAT:
10264 return SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT;
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010265 default:
10266 return snd_device;
10267 }
10268}
Rohit kumarf4120402016-08-05 19:19:48 +053010269int platform_get_vi_feedback_snd_device(snd_device_t snd_device)
10270{
10271 switch(snd_device) {
10272 case SND_DEVICE_OUT_SPEAKER_PROTECTED:
10273 case SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT:
Vikram Panduranga8c68e862018-04-27 12:59:42 -070010274 case SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED:
Rohit kumarf4120402016-08-05 19:19:48 +053010275 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
10276 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED:
10277 case SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT:
10278 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_1;
10279 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED:
10280 case SND_DEVICE_OUT_VOICE_SPEAKER_2_PROTECTED_VBAT:
10281 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK_MONO_2;
10282 default:
10283 return SND_DEVICE_IN_CAPTURE_VI_FEEDBACK;
10284 }
10285}
Xiaojun Sang040cc9f2015-08-03 19:38:28 +080010286
Venkata Narendra Kumar Gutta7f4817f2016-01-29 14:15:53 +053010287int platform_spkr_prot_is_wsa_analog_mode(void *adev __unused)
10288{
10289 return 0;
10290}
10291
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010292/*
10293 * This is a lookup table to map android audio input device to audio h/w interface (backend).
10294 * The table can be extended for other input devices by adding appropriate entries.
10295 * Also the audio interface for a particular input device can be overriden by adding
10296 * corresponding entry in audio_platform_info.xml file.
10297 */
10298struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
10299 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), "SLIMBUS_0"},
10300 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), "SLIMBUS_0"},
10301};
10302
10303int audio_device_to_interface_table_len =
10304 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
10305
Karthik Reddy Katta508eca42015-05-11 13:43:18 +053010306int platform_set_audio_device_interface(const char *device_name, const char *intf_name,
10307 const char *codec_type __unused)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080010308{
10309 int ret = 0;
10310 int i;
10311
10312 if (device_name == NULL || intf_name == NULL) {
10313 ALOGE("%s: Invalid input", __func__);
10314
10315 ret = -EINVAL;
10316 goto done;
10317 }
10318
10319 ALOGD("%s: Enter, device name:%s, intf name:%s", __func__, device_name, intf_name);
10320
10321 size_t device_name_len = strlen(device_name);
10322 for (i = 0; i < audio_device_to_interface_table_len; i++) {
10323 char* name = audio_device_to_interface_table[i].device_name;
10324 size_t name_len = strlen(name);
10325 if ((name_len == device_name_len) &&
10326 (strncmp(device_name, name, name_len) == 0)) {
10327 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
10328 __func__, device_name, intf_name);
10329
10330 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
10331 sizeof(audio_device_to_interface_table[i].interface_name));
10332 goto done;
10333 }
10334 }
10335 ALOGE("%s: Could not find matching device name %s",
10336 __func__, device_name);
10337
10338 ret = -EINVAL;
10339
10340done:
10341 return ret;
10342}
Laxminath Kasam44f49402015-05-29 18:37:11 +053010343
Kuirong Wang1cad7142016-05-24 15:21:56 -070010344int platform_set_sidetone(struct audio_device *adev,
10345 snd_device_t out_snd_device,
10346 bool enable,
10347 char *str)
10348{
10349 int ret;
Ashish Jain3e37a702016-11-25 12:27:15 +053010350 if ((out_snd_device == SND_DEVICE_OUT_USB_HEADSET) ||
Aalique Grahame22e49102018-12-18 14:23:57 -080010351 (out_snd_device == SND_DEVICE_OUT_USB_HEADPHONES) ||
10352 (out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET)) {
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -070010353 if (property_get_bool("vendor.audio.usb.disable.sidetone", 0)) {
Haynes Mathew George492a6c42016-10-28 11:41:43 -070010354 ALOGI("Debug: Disable sidetone");
10355 } else {
Kuirong Wang1cad7142016-05-24 15:21:56 -070010356 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
Vikram Panduranga6e761cd2016-10-12 16:50:52 -070010357 if (ret) {
10358 /*fall back to AFE sidetone*/
10359 ALOGV("%s: No USB sidetone supported, switching to AFE sidetone",
10360 __func__);
10361
10362 if (enable)
10363 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10364 else
10365 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10366 }
Haynes Mathew George492a6c42016-10-28 11:41:43 -070010367 }
Kuirong Wang1cad7142016-05-24 15:21:56 -070010368 } else {
10369 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
10370 __func__, out_snd_device, str);
Laxminath Kasam44f49402015-05-29 18:37:11 +053010371
Vikram Panduranga6e761cd2016-10-12 16:50:52 -070010372 if (enable) {
10373 ret = audio_route_apply_and_update_path(adev->audio_route, str);
10374 if (ret) {
10375 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
10376 __func__);
10377 audio_route_apply_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10378 }
10379 }
10380 else {
10381 ret = audio_route_reset_and_update_path(adev->audio_route, str);
10382 if (ret) {
10383 ALOGV("%s: No device sidetone supported, switching to AFE sidetone",
10384 __func__);
10385 audio_route_reset_and_update_path(adev->audio_route, AFE_SIDETONE_MIXER_PATH);
10386 }
10387 }
Kuirong Wang1cad7142016-05-24 15:21:56 -070010388 }
10389 return 0;
10390}
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010391
Vidyakumar Athotaea269c62016-10-31 09:05:59 -070010392void platform_update_aanc_path(struct audio_device *adev,
10393 snd_device_t out_snd_device,
10394 bool enable,
10395 char *str)
10396{
10397 ALOGD("%s: aanc out device(%d) mixer cmd = %s, enable = %d\n",
10398 __func__, out_snd_device, str, enable);
10399
10400 if (enable)
10401 audio_route_apply_and_update_path(adev->audio_route, str);
10402 else
10403 audio_route_reset_and_update_path(adev->audio_route, str);
10404
10405 return;
10406}
10407
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010408#ifdef INSTANCE_ID_ENABLED
10409void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
10410 int acdb_device_type, int app_type, int topology_id,
10411 int sample_rate, uint32_t module_id, uint16_t instance_id,
10412 uint32_t param_id, bool persist)
10413{
10414 int persist_send_flags = 1;
10415
10416 if (!cal) {
10417 return;
10418 }
10419
10420 if (persist)
10421 persist_send_flags |= 0x2;
10422
10423 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
10424
10425 cal->persist = persist;
10426 cal->app_type = app_type;
10427 cal->acdb_dev_id = acdb_dev_id;
10428 cal->sampling_rate = sample_rate;
10429 cal->topo_id = topology_id;
10430 //if module and param id is set to 0, the whole blob will be stored
10431 //or sent to the DSP
10432 cal->module_id = module_id;
10433 cal->instance_id = instance_id;
10434 cal->param_id = param_id;
10435 cal->cal_type = acdb_device_type;
10436}
10437#else
10438void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010439 int acdb_device_type, int app_type, int topology_id,
10440 int sample_rate, uint32_t module_id, uint32_t param_id, bool persist)
10441{
10442 int persist_send_flags = 1;
10443
10444 if (!cal) {
10445 return;
10446 }
10447
10448 if (persist)
10449 persist_send_flags |= 0x2;
10450
10451 memset(cal, 0, sizeof(acdb_audio_cal_cfg_t));
10452
10453 cal->persist = persist;
10454 cal->app_type = app_type;
10455 cal->acdb_dev_id = acdb_dev_id;
10456 cal->sampling_rate = sample_rate;
10457 cal->topo_id = topology_id;
10458 //if module and param id is set to 0, the whole blob will be stored
10459 //or sent to the DSP
10460 cal->module_id = module_id;
10461 cal->param_id = param_id;
10462 cal->cal_type = acdb_device_type;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010463}
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010464#endif
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010465
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010466int platform_send_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
10467 void* data, int length, bool persist)
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010468{
10469 int ret = 0;
10470 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010471
10472 if (!my_data) {
10473 ret = -EINVAL;
10474 goto ERROR_RETURN;
10475 }
Gangadhar Sb0210342019-02-22 17:39:41 +053010476 if ((cal->acdb_dev_id == ACDB_ID_STEREO_SPEAKER_DEVICE) &&
10477 (cal->topo_id == TRUMPET_TOPOLOGY))
10478 audio_extn_ip_hdlr_copp_update_cal_info((void*)cal, data);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010479
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010480 if (my_data->acdb_set_audio_cal) {
10481 // persist audio cal in local cache
10482 if (persist) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010483 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010484 }
10485 // send audio cal to dsp
10486 if (ret == 0) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010487 cal->persist = false;
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010488 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010489 if (persist && (ret != 0)) {
10490 ALOGV("[%s] audio cal stored with success, ignore set cal failure", __func__);
10491 ret = 0;
10492 }
10493 }
10494 }
10495
10496ERROR_RETURN:
10497 return ret;
10498}
10499
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010500int platform_get_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010501 void* data, int* length, bool persist)
10502{
10503 int ret = 0;
10504 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010505
10506 if (!my_data) {
10507 ret = -EINVAL;
10508 goto ERROR_RETURN;
10509 }
10510
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010511 if (my_data->acdb_get_audio_cal) {
10512 // get cal from dsp
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010513 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010514 // get cached cal if prevoius attempt fails and persist flag is set
10515 if ((ret != 0) && persist) {
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010516 cal->persist = true;
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010517 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010518 }
10519 }
10520
10521ERROR_RETURN:
10522 return ret;
10523}
10524
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010525int platform_store_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010526 void* data, int length)
10527{
10528 int ret = 0;
10529 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010530
10531 if (!my_data) {
10532 ret = -EINVAL;
10533 goto ERROR_RETURN;
10534 }
10535
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010536 if (my_data->acdb_set_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010537 ret = my_data->acdb_set_audio_cal((void*)cal, data, (uint32_t)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010538 }
10539
10540ERROR_RETURN:
10541 return ret;
10542}
10543
Aditya Bavanari29bcea22017-10-03 20:10:35 +053010544int platform_retrieve_audio_cal(void* platform, acdb_audio_cal_cfg_t* cal,
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010545 void* data, int* length)
10546{
10547 int ret = 0;
10548 struct platform_data *my_data = (struct platform_data *)platform;
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010549
10550 if (!my_data) {
10551 ret = -EINVAL;
10552 goto ERROR_RETURN;
10553 }
10554
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010555 if (my_data->acdb_get_audio_cal) {
Vignesh Kulothungand477f692018-05-29 14:33:24 -070010556 ret = my_data->acdb_get_audio_cal((void*)cal, data, (uint32_t*)length);
Weiyin Jiangaa80acd2016-09-21 16:42:11 +080010557 }
10558
10559ERROR_RETURN:
10560 return ret;
10561}
Divya Narayanan Poojary45f19192016-09-30 18:52:13 +053010562
10563int platform_get_max_mic_count(void *platform) {
10564 struct platform_data *my_data = (struct platform_data *)platform;
10565 return my_data->max_mic_count;
10566}
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070010567
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010568#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
10569int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
10570 // backup_gain: gain to try to set in case of an error during ramp
10571 int start_gain, end_gain, step, backup_gain, i;
10572 bool error = false;
10573 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
10574 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
10575 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
10576 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
10577 if (!ctl_left || !ctl_right) {
10578 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
10579 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
10580 return -EINVAL;
10581 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
10582 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
10583 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
10584 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
10585 return -EINVAL;
10586 }
10587 if (ramp_up) {
10588 start_gain = 0;
10589 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
10590 step = +1;
10591 backup_gain = end_gain;
10592 } else {
10593 // using same gain on left and right
10594 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
10595 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
10596 end_gain = 0;
10597 step = -1;
10598 backup_gain = start_gain;
10599 }
10600 for (i = start_gain ; i != (end_gain + step) ; i += step) {
10601 if (mixer_ctl_set_value(ctl_left, 0, i)) {
10602 ALOGE("%s: error setting %s to %d during gain ramp",
10603 __func__, mixer_ctl_name_gain_left, i);
10604 error = true;
10605 break;
10606 }
10607 if (mixer_ctl_set_value(ctl_right, 0, i)) {
10608 ALOGE("%s: error setting %s to %d during gain ramp",
10609 __func__, mixer_ctl_name_gain_right, i);
10610 error = true;
10611 break;
10612 }
10613 usleep(1000);
10614 }
10615 if (error) {
10616 // an error occured during the ramp, let's still try to go back to a safe volume
10617 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
10618 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
10619 }
10620 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
10621 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
10622 }
10623 }
10624 return start_gain;
10625}
10626
10627int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
10628{
10629 const char *mixer_ctl_name = "Swap channel";
10630 struct mixer_ctl *ctl;
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010631 struct platform_data *my_data = (struct platform_data *)adev->platform;
10632
10633 // forced to set to swap, but device not rotated ... ignore set
10634 if (swap_channels && !my_data->speaker_lr_swap)
10635 return 0;
10636
10637 ALOGV("%s:", __func__);
10638
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010639 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
10640 if (!ctl) {
10641 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
10642 return -EINVAL;
10643 }
10644
10645 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
10646 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
10647 return -EINVAL;
10648 }
10649
10650 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
10651 swap_channels?"R --> L":"L --> R");
10652
10653 return 0;
10654}
10655
10656int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
10657{
10658 // only update if there is active pcm playback on speaker
10659 struct platform_data *my_data = (struct platform_data *)adev->platform;
10660
10661 my_data->speaker_lr_swap = swap_channels;
10662
10663 return platform_set_swap_channels(adev, swap_channels);
10664}
10665
10666int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
10667{
10668 // only update if there is active pcm playback on speaker
10669 struct audio_usecase *usecase;
10670 struct listnode *node;
10671
kunleiz43c4a6a2018-05-17 18:01:24 +080010672 //swap channels only for stereo spkr
10673 struct platform_data *my_data = (struct platform_data *)adev->platform;
10674 if (my_data) {
10675 if (!hw_info_is_stereo_spkr(my_data->hw_info)) {
10676 ALOGV("%s: will not swap due to it is not stereo spkr", __func__);
10677 return 0;
10678 }
10679 } else {
10680 ALOGE("%s: failed to allocate platform data", __func__);
10681 return -EINVAL;
10682 }
10683
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010684 // do not swap channels in audio modes with concurrent capture and playback
10685 // as this may break the echo reference
10686 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
10687 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
10688 return 0;
10689 }
10690
10691 list_for_each(node, &adev->usecase_list) {
10692 usecase = node_to_item(node, struct audio_usecase, list);
Sujin Panicker390724d2019-04-26 10:43:36 +053010693 if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010694 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
10695 /*
10696 * If acdb tuning is different for SPEAKER_REVERSE, it is must
10697 * to perform device switch to disable the current backend to
10698 * enable it with new acdb data.
10699 */
kunleiz43c4a6a2018-05-17 18:01:24 +080010700 if (my_data->speaker_lr_swap &&
10701 (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
10702 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE])) {
Vignesh Kulothungan3b5fae52017-09-25 12:16:30 -070010703 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
10704 select_devices(adev, usecase->id);
10705 if (initial_skpr_gain != -EINVAL)
10706 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
10707
10708 } else {
10709 platform_set_swap_mixer(adev, swap_channels);
10710 }
10711 break;
10712 }
10713 }
10714
10715 return 0;
10716}
10717
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070010718static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
10719static int num_gain_tbl_entry = 0;
10720
10721bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
10722
10723 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
10724 if (num_gain_tbl_entry == -1) {
10725 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
10726 __func__);
10727 return false;
10728 }
10729
10730 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
10731 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
10732 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
10733 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
10734 return false;
10735 }
10736
10737 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
10738 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
10739 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
10740 return false;
10741 }
10742
10743 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
10744 ++num_gain_tbl_entry;
10745
10746 return true;
10747}
10748
10749int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
10750 int table_size) {
10751 int itt = 0;
10752 ALOGV("platform_get_gain_level_mapping called ");
10753
10754 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
10755 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
10756 return 0;
10757 }
10758
10759 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
10760 mapping_tbl[itt] = tbl_mapping[itt];
10761 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
10762 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
10763 }
10764
10765 return num_gain_tbl_entry;
10766}
Satish Babu Patakokilac3c5d432017-07-04 22:48:59 +053010767
10768int platform_get_max_codec_backend() {
10769
10770 return MAX_CODEC_BACKENDS;
10771}
Revathi Uddaraju0553e8f2017-11-30 14:56:11 +053010772int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
Venugopal Nadipalli83134582017-09-21 22:34:50 +053010773{
10774 int sample_rate;
10775 switch (stream_sr){
10776 case 8000:
10777 case 11025:
10778 case 16000:
10779 case 22050:
10780 case 32000:
10781 case 48000:
10782 sample_rate = 48000;
10783 break;
10784 case 44100:
10785 sample_rate = 44100;
10786 break;
10787 case 64000:
10788 case 96000:
10789 sample_rate = 96000;
10790 break;
10791 case 88200:
10792 sample_rate = 88200;
10793 break;
10794 case 176400:
10795 sample_rate = 176400;
10796 break;
10797 case 192000:
10798 sample_rate = 192000;
10799 break;
10800 case 352800:
10801 sample_rate = 352800;
10802 break;
10803 case 384000:
10804 sample_rate = 384000;
10805 break;
10806 case 144000:
10807 default:
10808 sample_rate = 48000;
10809 break;
10810 }
10811 return sample_rate;
10812}
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070010813
Meng Wangef2f6e12018-10-08 13:06:05 +080010814#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845) || (PLATFORM_SDM710) || \
10815 defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \
10816 defined (PLATFORM_KONA) || defined (PLATFORM_MSMSTEPPE) || \
Manisha Agarwal888e9762019-02-27 22:18:49 +053010817 defined (PLATFORM_QCS405) || defined (PLATFORM_TRINKET) || \
Manisha Agarwal13c65ae2019-05-16 10:48:28 +080010818 defined (PLATFORM_LITO) || defined (PLATFORM_MSMFALCON) || \
10819 defined (PLATFORM_ATOLL)
Haynes Mathew Georgeef514882017-05-01 17:46:23 -070010820int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
10821 uint32_t *size)
10822{
10823 struct platform_data *my_data = (struct platform_data *)platform;
10824 struct audio_device *adev = my_data->adev;
10825 int hw_fd = -1;
10826 char dev_name[128];
10827 struct snd_pcm_mmap_fd mmap_fd;
10828 memset(&mmap_fd, 0, sizeof(mmap_fd));
10829 mmap_fd.dir = dir;
10830 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
10831 adev->snd_card, HWDEP_FE_BASE+fe_dev);
10832 hw_fd = open(dev_name, O_RDONLY);
10833 if (hw_fd < 0) {
10834 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
10835 return -1;
10836 }
10837 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
10838 ALOGE("fe hw dep node ioctl failed");
10839 close(hw_fd);
10840 return -1;
10841 }
10842 *fd = mmap_fd.fd;
10843 *size = mmap_fd.size;
10844 close(hw_fd); // mmap_fd should still be valid
10845 return 0;
10846}
10847#else
10848int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused,
10849 int dir __unused, int *fd __unused,
10850 uint32_t *size __unused)
10851{
10852 return -1;
10853}
10854#endif
`Deeraj Soman676c2702017-09-18 19:25:53 +053010855
10856static const char *platform_get_mixer_control(struct mixer_ctl *ctl)
10857{
10858 int id = -1;
10859 const char *id_string = NULL;
10860
10861 if (!ctl) {
10862 ALOGD("%s: mixer ctl not obtained", __func__);
10863 } else {
10864 id = mixer_ctl_get_value(ctl, 0);
10865 if (id >= 0) {
10866 id_string = mixer_ctl_get_enum_string(ctl, id);
10867 }
10868 }
10869
10870 return id_string;
10871}
Naresh Tannirudcb47c52018-06-25 16:23:32 +053010872
10873bool platform_set_microphone_characteristic(void *platform,
10874 struct audio_microphone_characteristic_t mic) {
10875 struct platform_data *my_data = (struct platform_data *)platform;
10876 if (my_data->declared_mic_count >= AUDIO_MICROPHONE_MAX_COUNT) {
10877 ALOGE("mic number is more than maximum number");
10878 return false;
10879 }
10880 for (size_t ch = 0; ch < AUDIO_CHANNEL_COUNT_MAX; ch++) {
10881 mic.channel_mapping[ch] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
10882 }
10883 my_data->microphones[my_data->declared_mic_count++] = mic;
10884 return true;
10885}
10886
10887int platform_get_microphones(void *platform,
10888 struct audio_microphone_characteristic_t *mic_array,
10889 size_t *mic_count) {
10890 struct platform_data *my_data = (struct platform_data *)platform;
10891 if (mic_count == NULL) {
10892 return -EINVAL;
10893 }
10894 if (mic_array == NULL) {
10895 return -EINVAL;
10896 }
10897
10898 if (*mic_count == 0) {
10899 *mic_count = my_data->declared_mic_count;
10900 return 0;
10901 }
10902
10903 size_t max_mic_count = *mic_count;
10904 size_t actual_mic_count = 0;
10905 for (size_t i = 0; i < max_mic_count && i < my_data->declared_mic_count; i++) {
10906 mic_array[i] = my_data->microphones[i];
10907 actual_mic_count++;
10908 }
10909 *mic_count = actual_mic_count;
10910 return 0;
10911}
10912
10913bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
10914 const struct mic_info *info) {
10915 struct platform_data *my_data = (struct platform_data *)platform;
10916 if (in_snd_device < SND_DEVICE_IN_BEGIN || in_snd_device >= SND_DEVICE_IN_END) {
10917 ALOGE("%s: Sound device not valid", __func__);
10918 return false;
10919 }
10920 size_t m_count = my_data->mic_map[in_snd_device].mic_count++;
10921 if (m_count >= AUDIO_MICROPHONE_MAX_COUNT) {
10922 ALOGE("%s: Microphone count is greater than max allowed value", __func__);
10923 my_data->mic_map[in_snd_device].mic_count--;
10924 return false;
10925 }
10926 my_data->mic_map[in_snd_device].microphones[m_count] = *info;
10927 return true;
10928}
10929
10930int platform_get_active_microphones(void *platform, unsigned int channels,
10931 audio_usecase_t uc_id,
10932 struct audio_microphone_characteristic_t *mic_array,
10933 size_t *mic_count) {
10934 struct platform_data *my_data = (struct platform_data *)platform;
10935 struct audio_usecase *usecase = get_usecase_from_list(my_data->adev, uc_id);
10936 if (mic_count == NULL || mic_array == NULL || usecase == NULL) {
10937 return -EINVAL;
10938 }
10939 size_t max_mic_count = my_data->declared_mic_count;
10940 size_t actual_mic_count = 0;
10941
10942 snd_device_t active_input_snd_device =
Eric Laurent637e2d42018-11-15 12:24:31 -080010943 platform_get_input_snd_device(platform, usecase->stream.in, AUDIO_DEVICE_NONE);
Naresh Tannirudcb47c52018-06-25 16:23:32 +053010944 if (active_input_snd_device == SND_DEVICE_NONE) {
10945 ALOGI("%s: No active microphones found", __func__);
10946 goto end;
10947 }
10948
10949 size_t active_mic_count = my_data->mic_map[active_input_snd_device].mic_count;
10950 struct mic_info *m_info = my_data->mic_map[active_input_snd_device].microphones;
10951
10952 for (size_t i = 0; i < active_mic_count; i++) {
10953 unsigned int channels_for_active_mic = channels;
10954 if (channels_for_active_mic > m_info[i].channel_count) {
10955 channels_for_active_mic = m_info[i].channel_count;
10956 }
10957 for (size_t j = 0; j < max_mic_count; j++) {
10958 if (strcmp(my_data->microphones[j].device_id,
10959 m_info[i].device_id) == 0) {
10960 mic_array[actual_mic_count] = my_data->microphones[j];
10961 for (size_t ch = 0; ch < channels_for_active_mic; ch++) {
10962 mic_array[actual_mic_count].channel_mapping[ch] =
10963 m_info[i].channel_mapping[ch];
10964 }
10965 actual_mic_count++;
10966 break;
10967 }
10968 }
10969 }
10970end:
10971 *mic_count = actual_mic_count;
10972 return 0;
10973}
Naresh Tannirucb5b5782018-10-12 20:42:07 +053010974
10975int platform_get_license_by_product(void *platform __unused,
10976 const char* product_name __unused,
10977 int *product_id __unused,
10978 char* product_license __unused)
Surendar karka30569792018-05-08 12:02:21 +053010979{
10980 return -ENOSYS;
10981}